2008-03-03 18:19:52 +00:00
|
|
|
<?php
|
2010-02-22 12:18:42 +00:00
|
|
|
/**
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Iker Labarga "<Firstname><Lastname>@gmail.com"
|
2008-03-03 18:19:52 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-03-03 18:19:52 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2008-03-03 18:19:52 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-07-21 13:18:14 +00:00
|
|
|
use MediaWiki\Storage\RevisionRecord;
|
|
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
/**
|
2008-09-04 13:40:33 +00:00
|
|
|
* A module that allows for editing and creating pages.
|
2008-03-03 18:19:52 +00:00
|
|
|
*
|
2008-09-04 13:40:33 +00:00
|
|
|
* Currently, this wraps around the EditPage class in an ugly way,
|
2015-04-05 06:48:02 +00:00
|
|
|
* EditPage.php should be rewritten to provide a cleaner interface,
|
|
|
|
|
* see T20654 if you're inspired to fix this.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2008-03-03 18:19:52 +00:00
|
|
|
*/
|
|
|
|
|
class ApiEditPage extends ApiBase {
|
|
|
|
|
public function execute() {
|
2015-08-08 00:08:33 +00:00
|
|
|
$this->useTransactionalTimeLimit();
|
|
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
$user = $this->getUser();
|
2008-03-03 18:19:52 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->requireAtLeastOneParameter( $params, 'text', 'appendtext', 'prependtext', 'undo' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2012-04-28 13:45:37 +00:00
|
|
|
$pageObj = $this->getTitleOrPageId( $params );
|
|
|
|
|
$titleObj = $pageObj->getTitle();
|
2011-06-20 22:18:11 +00:00
|
|
|
$apiResult = $this->getResult();
|
2011-06-20 22:13:45 +00:00
|
|
|
|
2010-12-30 17:06:09 +00:00
|
|
|
if ( $params['redirect'] ) {
|
2015-03-14 08:35:54 +00:00
|
|
|
if ( $params['prependtext'] === null && $params['appendtext'] === null
|
|
|
|
|
&& $params['section'] !== 'new'
|
|
|
|
|
) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-redirect-appendonly' );
|
2014-05-18 07:04:36 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
if ( $titleObj->isRedirect() ) {
|
2010-10-23 17:48:08 +00:00
|
|
|
$oldTitle = $titleObj;
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2012-09-05 15:50:13 +00:00
|
|
|
$titles = Revision::newFromTitle( $oldTitle, false, Revision::READ_LATEST )
|
2019-07-21 14:18:51 +00:00
|
|
|
->getContent( RevisionRecord::FOR_THIS_USER, $user )
|
2013-11-14 12:40:22 +00:00
|
|
|
->getRedirectChain();
|
2010-12-30 17:06:09 +00:00
|
|
|
// array_shift( $titles );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$redirValues = [];
|
2013-03-11 03:45:51 +00:00
|
|
|
|
2017-09-04 18:05:26 +00:00
|
|
|
/** @var Title $newTitle */
|
2010-10-23 17:48:08 +00:00
|
|
|
foreach ( $titles as $id => $newTitle ) {
|
2019-08-30 16:01:28 +00:00
|
|
|
$titles[ $id - 1 ] = $titles[ $id - 1 ] ?? $oldTitle;
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$redirValues[] = [
|
2013-01-12 06:50:48 +00:00
|
|
|
'from' => $titles[$id - 1]->getPrefixedText(),
|
2010-10-23 17:48:08 +00:00
|
|
|
'to' => $newTitle->getPrefixedText()
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2010-10-23 17:48:08 +00:00
|
|
|
$titleObj = $newTitle;
|
|
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $redirValues, 'r' );
|
2011-06-20 22:18:11 +00:00
|
|
|
$apiResult->addValue( null, 'redirects', $redirValues );
|
2012-11-12 05:42:26 +00:00
|
|
|
|
|
|
|
|
// Since the page changed, update $pageObj
|
|
|
|
|
$pageObj = WikiPage::factory( $titleObj );
|
2010-08-08 01:14:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2012-11-12 05:42:26 +00:00
|
|
|
if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
|
|
|
|
|
$contentHandler = $pageObj->getContentHandler();
|
|
|
|
|
} else {
|
|
|
|
|
$contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
|
|
|
|
|
}
|
2016-09-08 23:43:36 +00:00
|
|
|
$contentModel = $contentHandler->getModelID();
|
2012-11-12 05:42:26 +00:00
|
|
|
|
2015-06-19 22:39:48 +00:00
|
|
|
$name = $titleObj->getPrefixedDBkey();
|
|
|
|
|
$model = $contentHandler->getModelID();
|
2015-08-13 20:34:45 +00:00
|
|
|
|
2019-08-19 14:49:30 +00:00
|
|
|
if ( $params['undo'] > 0 ) {
|
|
|
|
|
// allow undo via api
|
|
|
|
|
} elseif ( $contentHandler->supportsDirectApiEditing() === false ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-no-direct-editing', $model, $name ] );
|
2015-04-15 08:26:22 +00:00
|
|
|
}
|
2012-11-12 05:42:26 +00:00
|
|
|
|
|
|
|
|
if ( !isset( $params['contentformat'] ) || $params['contentformat'] == '' ) {
|
2016-09-08 23:43:36 +00:00
|
|
|
$contentFormat = $contentHandler->getDefaultFormat();
|
|
|
|
|
} else {
|
|
|
|
|
$contentFormat = $params['contentformat'];
|
2012-11-12 05:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$contentHandler->isSupportedFormat( $contentFormat ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-badformat', $contentFormat, $model, $name ] );
|
2012-11-12 05:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $params['createonly'] && $titleObj->exists() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-articleexists' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['nocreate'] && !$titleObj->exists() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-missingtitle' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
// Now let's check whether we're even allowed to do this
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->checkTitleUserPermissions(
|
|
|
|
|
$titleObj,
|
2019-02-18 19:46:05 +00:00
|
|
|
$titleObj->exists() ? 'edit' : [ 'edit', 'create' ],
|
|
|
|
|
[ 'autoblock' => true ]
|
2016-10-19 16:54:25 +00:00
|
|
|
);
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2008-06-15 19:59:55 +00:00
|
|
|
$toMD5 = $params['text'];
|
2013-11-14 12:40:22 +00:00
|
|
|
if ( !is_null( $params['appendtext'] ) || !is_null( $params['prependtext'] ) ) {
|
2012-06-25 14:09:08 +00:00
|
|
|
$content = $pageObj->getContent();
|
|
|
|
|
|
|
|
|
|
if ( !$content ) {
|
|
|
|
|
if ( $titleObj->getNamespace() == NS_MEDIAWIKI ) {
|
2012-10-10 19:30:40 +00:00
|
|
|
# If this is a MediaWiki:x message, then load the messages
|
|
|
|
|
# and return the message value for x.
|
2012-06-25 14:09:08 +00:00
|
|
|
$text = $titleObj->getDefaultMessageText();
|
|
|
|
|
if ( $text === false ) {
|
|
|
|
|
$text = '';
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 14:14:18 +00:00
|
|
|
try {
|
2018-03-20 13:25:26 +00:00
|
|
|
$content = ContentHandler::makeContent( $text, $titleObj );
|
2012-08-21 14:14:18 +00:00
|
|
|
} catch ( MWContentSerializationException $ex ) {
|
2016-12-08 18:38:45 +00:00
|
|
|
$this->dieWithException( $ex, [
|
|
|
|
|
'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
|
|
|
|
|
] );
|
2012-08-21 14:14:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2012-10-10 19:30:40 +00:00
|
|
|
} else {
|
|
|
|
|
# Otherwise, make a new empty content.
|
|
|
|
|
$content = $contentHandler->makeEmptyContent();
|
2012-06-25 14:09:08 +00:00
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo Add support for appending/prepending to the Content interface
|
2012-10-10 19:30:40 +00:00
|
|
|
|
|
|
|
|
if ( !( $content instanceof TextContent ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$modelName = $contentHandler->getModelID();
|
|
|
|
|
$this->dieWithError( [ 'apierror-appendnotsupported', $modelName ] );
|
2012-10-10 19:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['section'] ) ) {
|
2012-06-25 14:09:08 +00:00
|
|
|
if ( !$contentHandler->supportsSections() ) {
|
2012-06-25 21:30:51 +00:00
|
|
|
$modelName = $contentHandler->getModelID();
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-sectionsnotsupported', $modelName ] );
|
2012-06-25 14:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-05 15:26:49 +00:00
|
|
|
if ( $params['section'] == 'new' ) {
|
|
|
|
|
// DWIM if they're trying to prepend/append to a new section.
|
|
|
|
|
$content = null;
|
|
|
|
|
} else {
|
|
|
|
|
// Process the content for section edits
|
2014-05-01 00:10:43 +00:00
|
|
|
$section = $params['section'];
|
2013-08-05 15:26:49 +00:00
|
|
|
$content = $content->getSection( $section );
|
2012-06-25 14:09:08 +00:00
|
|
|
|
2013-08-05 15:26:49 +00:00
|
|
|
if ( !$content ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchsection', wfEscapeWikiText( $section ) ] );
|
2013-08-05 15:26:49 +00:00
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2009-07-14 20:14:47 +00:00
|
|
|
}
|
2012-06-25 14:09:08 +00:00
|
|
|
|
|
|
|
|
if ( !$content ) {
|
|
|
|
|
$text = '';
|
|
|
|
|
} else {
|
|
|
|
|
$text = $content->serialize( $contentFormat );
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-05 17:09:41 +00:00
|
|
|
$params['text'] = $params['prependtext'] . $text . $params['appendtext'];
|
2008-06-15 19:59:55 +00:00
|
|
|
$toMD5 = $params['prependtext'] . $params['appendtext'];
|
2008-06-12 13:05:07 +00:00
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
|
|
|
|
|
if ( $params['undo'] > 0 ) {
|
|
|
|
|
if ( $params['undoafter'] > 0 ) {
|
|
|
|
|
if ( $params['undo'] < $params['undoafter'] ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
list( $params['undo'], $params['undoafter'] ) =
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $params['undoafter'], $params['undo'] ];
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2014-12-02 18:13:06 +00:00
|
|
|
$undoafterRev = Revision::newFromId( $params['undoafter'] );
|
2009-01-26 13:51:03 +00:00
|
|
|
}
|
2014-12-02 18:13:06 +00:00
|
|
|
$undoRev = Revision::newFromId( $params['undo'] );
|
2019-07-21 13:18:14 +00:00
|
|
|
if ( is_null( $undoRev ) || $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchrevid', $params['undo'] ] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $params['undoafter'] == 0 ) {
|
2009-01-26 13:51:03 +00:00
|
|
|
$undoafterRev = $undoRev->getPrevious();
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2019-07-21 13:18:14 +00:00
|
|
|
if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchrevid', $params['undoafter'] ] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2015-11-07 21:10:23 +00:00
|
|
|
if ( $undoRev->getPage() != $pageObj->getId() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-revwrongpage', $undoRev->getId(),
|
2016-02-17 09:09:32 +00:00
|
|
|
$titleObj->getPrefixedText() ] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2015-11-07 21:10:23 +00:00
|
|
|
if ( $undoafterRev->getPage() != $pageObj->getId() ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-revwrongpage', $undoafterRev->getId(),
|
2016-02-17 09:09:32 +00:00
|
|
|
$titleObj->getPrefixedText() ] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-16 19:09:17 +00:00
|
|
|
$newContent = $contentHandler->getUndoContent(
|
|
|
|
|
$pageObj->getRevision(),
|
|
|
|
|
$undoRev,
|
|
|
|
|
$undoafterRev
|
|
|
|
|
);
|
2012-08-21 14:14:18 +00:00
|
|
|
|
2012-06-25 14:09:08 +00:00
|
|
|
if ( !$newContent ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'undo-failure', 'undofailure' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2016-09-08 23:43:36 +00:00
|
|
|
if ( empty( $params['contentmodel'] )
|
|
|
|
|
&& empty( $params['contentformat'] )
|
|
|
|
|
) {
|
|
|
|
|
// If we are reverting content model, the new content model
|
|
|
|
|
// might not support the current serialization format, in
|
|
|
|
|
// which case go back to the old serialization format,
|
|
|
|
|
// but only if the user hasn't specified a format/model
|
|
|
|
|
// parameter.
|
|
|
|
|
if ( !$newContent->isSupportedFormat( $contentFormat ) ) {
|
|
|
|
|
$contentFormat = $undoafterRev->getContentFormat();
|
|
|
|
|
}
|
|
|
|
|
// Override content model with model of undid revision.
|
|
|
|
|
$contentModel = $newContent->getModel();
|
|
|
|
|
}
|
|
|
|
|
$params['text'] = $newContent->serialize( $contentFormat );
|
2009-01-26 13:51:03 +00:00
|
|
|
// If no summary was given and we only undid one rev,
|
|
|
|
|
// use an autosummary
|
2013-11-16 19:09:17 +00:00
|
|
|
if ( is_null( $params['summary'] ) &&
|
2015-11-07 21:10:23 +00:00
|
|
|
$titleObj->getNextRevisionID( $undoafterRev->getId() ) == $params['undo']
|
2013-11-16 19:09:17 +00:00
|
|
|
) {
|
|
|
|
|
$params['summary'] = wfMessage( 'undo-summary' )
|
2015-06-16 19:06:19 +00:00
|
|
|
->params( $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text();
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2009-01-26 13:51:03 +00:00
|
|
|
}
|
2008-06-12 13:05:07 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// See if the MD5 hash checks out
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-badmd5' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
// EditPage wants to parse its stuff from a WebRequest
|
|
|
|
|
// That interface kind of sucks, but it's workable
|
2016-02-17 09:09:32 +00:00
|
|
|
$requestArray = [
|
2010-02-22 12:18:42 +00:00
|
|
|
'wpTextbox1' => $params['text'],
|
2012-06-25 14:09:08 +00:00
|
|
|
'format' => $contentFormat,
|
2016-09-08 23:43:36 +00:00
|
|
|
'model' => $contentModel,
|
2010-02-22 12:18:42 +00:00
|
|
|
'wpEditToken' => $params['token'],
|
2015-01-20 21:15:36 +00:00
|
|
|
'wpIgnoreBlankSummary' => true,
|
2014-12-10 11:48:13 +00:00
|
|
|
'wpIgnoreBlankArticle' => true,
|
|
|
|
|
'wpIgnoreSelfRedirect' => true,
|
2015-02-06 19:51:09 +00:00
|
|
|
'bot' => $params['bot'],
|
2017-08-28 21:14:44 +00:00
|
|
|
'wpUnicodeCheck' => EditPage::UNICODE_CHECK,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['summary'] ) ) {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpSummary'] = $params['summary'];
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2012-09-05 15:50:13 +00:00
|
|
|
|
2011-12-20 04:15:21 +00:00
|
|
|
if ( !is_null( $params['sectiontitle'] ) ) {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpSectionTitle'] = $params['sectiontitle'];
|
2011-12-20 04:15:21 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2012-10-28 23:05:40 +00:00
|
|
|
// TODO: Pass along information from 'undoafter' as well
|
|
|
|
|
if ( $params['undo'] > 0 ) {
|
|
|
|
|
$requestArray['wpUndidRevision'] = $params['undo'];
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 16:39:55 +00:00
|
|
|
// Watch out for basetimestamp == '' or '0'
|
|
|
|
|
// It gets treated as NOW, almost certainly causing an edit conflict
|
|
|
|
|
if ( $params['basetimestamp'] !== null && (bool)$this->getMain()->getVal( 'basetimestamp' ) ) {
|
|
|
|
|
$requestArray['wpEdittime'] = $params['basetimestamp'];
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2012-06-25 14:09:08 +00:00
|
|
|
$requestArray['wpEdittime'] = $pageObj->getTimestamp();
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2015-05-07 16:39:55 +00:00
|
|
|
if ( $params['starttimestamp'] !== null ) {
|
|
|
|
|
$requestArray['wpStarttime'] = $params['starttimestamp'];
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2013-03-07 16:50:43 +00:00
|
|
|
$requestArray['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2013-04-26 14:42:31 +00:00
|
|
|
if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpMinoredit'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $params['recreate'] ) {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpRecreate'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['section'] ) ) {
|
2014-05-01 00:10:43 +00:00
|
|
|
$section = $params['section'];
|
|
|
|
|
if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-invalidsection' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2013-09-11 17:54:22 +00:00
|
|
|
$content = $pageObj->getContent();
|
2015-03-14 08:35:54 +00:00
|
|
|
if ( $section !== '0' && $section != 'new'
|
|
|
|
|
&& ( !$content || !$content->getSection( $section ) )
|
|
|
|
|
) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( [ 'apierror-nosuchsection', $section ] );
|
2013-09-11 17:54:22 +00:00
|
|
|
}
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpSection'] = $params['section'];
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpSection'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-04-12 10:44:45 +00:00
|
|
|
$watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
|
2010-03-25 22:15:08 +00:00
|
|
|
|
2009-07-14 20:48:00 +00:00
|
|
|
// Deprecated parameters
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $params['watch'] ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$watch = true;
|
2010-02-22 12:18:42 +00:00
|
|
|
} elseif ( $params['unwatch'] ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$watch = false;
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2010-04-14 12:17:39 +00:00
|
|
|
if ( $watch ) {
|
2011-12-20 04:22:06 +00:00
|
|
|
$requestArray['wpWatchthis'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2015-04-15 01:33:08 +00:00
|
|
|
// Apply change tags
|
2017-12-04 18:36:48 +00:00
|
|
|
if ( $params['tags'] ) {
|
2016-01-20 09:51:01 +00:00
|
|
|
$tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
|
2016-02-20 20:20:37 +00:00
|
|
|
if ( $tagStatus->isOK() ) {
|
2015-04-15 01:33:08 +00:00
|
|
|
$requestArray['wpChangeTags'] = implode( ',', $params['tags'] );
|
|
|
|
|
} else {
|
2016-01-20 09:51:01 +00:00
|
|
|
$this->dieStatus( $tagStatus );
|
2015-04-15 01:33:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 06:26:37 +00:00
|
|
|
// Pass through anything else we might have been given, to support extensions
|
|
|
|
|
// This is kind of a hack but it's the best we can do to make extensions work
|
|
|
|
|
$requestArray += $this->getRequest()->getValues();
|
|
|
|
|
|
2011-11-17 10:33:20 +00:00
|
|
|
global $wgTitle, $wgRequest;
|
|
|
|
|
|
2011-12-20 04:22:06 +00:00
|
|
|
$req = new DerivativeRequest( $this->getRequest(), $requestArray, true );
|
2011-11-17 10:33:20 +00:00
|
|
|
|
|
|
|
|
// Some functions depend on $wgTitle == $ep->mTitle
|
|
|
|
|
// TODO: Make them not or check if they still do
|
|
|
|
|
$wgTitle = $titleObj;
|
|
|
|
|
|
2013-02-17 10:59:41 +00:00
|
|
|
$articleContext = new RequestContext;
|
|
|
|
|
$articleContext->setRequest( $req );
|
2013-02-24 10:34:50 +00:00
|
|
|
$articleContext->setWikiPage( $pageObj );
|
|
|
|
|
$articleContext->setUser( $this->getUser() );
|
|
|
|
|
|
2017-09-04 18:05:26 +00:00
|
|
|
/** @var Article $articleObject */
|
2013-02-24 10:34:50 +00:00
|
|
|
$articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
|
2013-02-17 10:59:41 +00:00
|
|
|
|
2012-06-25 14:09:08 +00:00
|
|
|
$ep = new EditPage( $articleObject );
|
2012-03-09 17:23:05 +00:00
|
|
|
|
2015-04-15 08:26:22 +00:00
|
|
|
$ep->setApiEditOverride( true );
|
2011-11-17 10:33:20 +00:00
|
|
|
$ep->setContextTitle( $titleObj );
|
2010-01-11 15:55:52 +00:00
|
|
|
$ep->importFormData( $req );
|
2013-07-26 11:43:08 +00:00
|
|
|
$content = $ep->textbox1;
|
|
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// Do the actual save
|
2012-06-25 14:09:08 +00:00
|
|
|
$oldRevId = $articleObject->getRevIdFetched();
|
2011-06-20 22:18:11 +00:00
|
|
|
$result = null;
|
2010-01-23 22:52:40 +00:00
|
|
|
// Fake $wgRequest for some hooks inside EditPage
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: This interface SUCKS
|
2008-05-28 09:14:35 +00:00
|
|
|
$oldRequest = $wgRequest;
|
|
|
|
|
$wgRequest = $req;
|
|
|
|
|
|
2015-02-06 19:51:09 +00:00
|
|
|
$status = $ep->attemptSave( $result );
|
2008-05-28 09:14:35 +00:00
|
|
|
$wgRequest = $oldRequest;
|
2010-08-12 14:25:07 +00:00
|
|
|
|
2019-08-30 17:56:27 +00:00
|
|
|
$r = [];
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $status->value ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_HOOK_ERROR:
|
|
|
|
|
case EditPage::AS_HOOK_ERROR_EXPECTED:
|
API edit: allow ConfirmEdit to use the merged parse
ConfirmEdit was tripling the amount of time it took to save a typical
page via the API, since it was assuming that the APIEditBeforeSave hook
was giving unmerged wikitext, requiring a full parse of the content
before and after the edit in order to check the addurl trigger.
Apparently nobody bothered to update it after Ia59fb6bb.
APIEditBeforeSave is unusable anyway, because it is given the serialized
content, without any information about the content model. It really
needs the Content object in order to do it properly. So instead, adapt
EditFilterMergedContent for the purpose. Incidentally, that avoids the
inelegant defined('MW_API') check in ConfirmEdit's
EditFilterMergedContent handler, since both API and normal edits are
handled by EditFilterMergedContent in the same way.
Unfortunately the interpretation of the 'value' member in the Status
object passed to EditFilterMergedContent is not extensible, being an
integer instead of an associative array. So we add a custom member in
order to get the result array back down the stack.
Another obstacle to this design was the lack of an EditPage object
passed to EditFilterMergedContent. ConfirmEdit was previously directly
calling EditPage::showEditForm() with a $formCallback which outputs the
necessary HTML. Instead, I hacked up runPostMergeFilters() a bit, to
allow the hook to request that the edit page be shown again even if
hookError is not set. Then a new EditPage::showEditForm:fields hook does
the necessary HTML output, instead of $formCallback.
Marked $formCallback as deprecated, since I think it is now unused.
Change-Id: I4b4270dd868a643512d4717927858b6ef0556d8a
2014-12-05 04:25:18 +00:00
|
|
|
if ( isset( $status->apiHookResult ) ) {
|
|
|
|
|
$r = $status->apiHookResult;
|
|
|
|
|
$r['result'] = 'Failure';
|
|
|
|
|
$apiResult->addValue( null, $this->getModuleName(), $r );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-19 16:54:25 +00:00
|
|
|
if ( !$status->getErrors() ) {
|
2018-03-20 13:25:26 +00:00
|
|
|
// This appears to be unreachable right now, because all
|
|
|
|
|
// code paths will set an error. Could change, though.
|
|
|
|
|
$status->fatal( 'hookaborted' ); //@codeCoverageIgnore
|
2016-10-19 16:54:25 +00:00
|
|
|
}
|
|
|
|
|
$this->dieStatus( $status );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2018-03-20 13:25:26 +00:00
|
|
|
// These two cases will normally have been caught earlier, and will
|
|
|
|
|
// only occur if something blocks the user between the earlier
|
|
|
|
|
// check and the check in EditPage (presumably a hook). It's not
|
|
|
|
|
// obvious that this is even possible.
|
|
|
|
|
// @codeCoverageIgnoreStart
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
|
2018-08-27 01:45:18 +00:00
|
|
|
$this->dieBlocked( $user->getBlock() );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_READ_ONLY_PAGE:
|
2009-07-12 12:38:03 +00:00
|
|
|
$this->dieReadOnly();
|
2018-03-20 13:25:26 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_SUCCESS_NEW_ARTICLE:
|
2015-01-16 19:00:07 +00:00
|
|
|
$r['new'] = true;
|
2013-03-11 03:45:51 +00:00
|
|
|
// fall-through
|
2010-07-06 13:15:59 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_SUCCESS_UPDATE:
|
2010-02-22 12:18:42 +00:00
|
|
|
$r['result'] = 'Success';
|
2019-02-25 00:38:33 +00:00
|
|
|
$r['pageid'] = (int)$titleObj->getArticleID();
|
2008-03-03 18:19:52 +00:00
|
|
|
$r['title'] = $titleObj->getPrefixedText();
|
2015-04-23 14:21:11 +00:00
|
|
|
$r['contentmodel'] = $articleObject->getContentModel();
|
2012-06-25 14:09:08 +00:00
|
|
|
$newRevId = $articleObject->getLatest();
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $newRevId == $oldRevId ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
$r['nochange'] = true;
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2019-02-25 00:38:33 +00:00
|
|
|
$r['oldrevid'] = (int)$oldRevId;
|
|
|
|
|
$r['newrevid'] = (int)$newRevId;
|
2010-01-11 15:55:52 +00:00
|
|
|
$r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
|
2012-06-25 14:09:08 +00:00
|
|
|
$pageObj->getTimestamp() );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2012-05-10 04:48:16 +00:00
|
|
|
default:
|
2016-10-19 16:54:25 +00:00
|
|
|
if ( !$status->getErrors() ) {
|
2016-12-19 14:49:59 +00:00
|
|
|
// EditPage sometimes only sets the status code without setting
|
|
|
|
|
// any actual error messages. Supply defaults for those cases.
|
|
|
|
|
switch ( $status->value ) {
|
|
|
|
|
// Currently needed
|
|
|
|
|
case EditPage::AS_IMAGE_REDIRECT_ANON:
|
|
|
|
|
$status->fatal( 'apierror-noimageredirect-anon' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_IMAGE_REDIRECT_LOGGED:
|
2018-03-20 13:25:26 +00:00
|
|
|
$status->fatal( 'apierror-noimageredirect' );
|
2016-12-19 14:49:59 +00:00
|
|
|
break;
|
|
|
|
|
case EditPage::AS_CONTENT_TOO_BIG:
|
|
|
|
|
case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
|
|
|
|
|
$status->fatal( 'apierror-contenttoobig', $this->getConfig()->get( 'MaxArticleSize' ) );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_READ_ONLY_PAGE_ANON:
|
|
|
|
|
$status->fatal( 'apierror-noedit-anon' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_NO_CHANGE_CONTENT_MODEL:
|
|
|
|
|
$status->fatal( 'apierror-cantchangecontentmodel' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_ARTICLE_WAS_DELETED:
|
|
|
|
|
$status->fatal( 'apierror-pagedeleted' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_CONFLICT_DETECTED:
|
|
|
|
|
$status->fatal( 'editconflict' );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Currently shouldn't be needed, but here in case
|
|
|
|
|
// hooks use them without setting appropriate
|
|
|
|
|
// errors on the status.
|
2018-03-20 13:25:26 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2016-12-19 14:49:59 +00:00
|
|
|
case EditPage::AS_SPAM_ERROR:
|
|
|
|
|
$status->fatal( 'apierror-spamdetected', $result['spam'] );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_READ_ONLY_PAGE_LOGGED:
|
|
|
|
|
$status->fatal( 'apierror-noedit' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_RATE_LIMITED:
|
|
|
|
|
$status->fatal( 'apierror-ratelimited' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_NO_CREATE_PERMISSION:
|
|
|
|
|
$status->fatal( 'nocreate-loggedin' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_BLANK_ARTICLE:
|
|
|
|
|
$status->fatal( 'apierror-emptypage' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_TEXTBOX_EMPTY:
|
|
|
|
|
$status->fatal( 'apierror-emptynewsection' );
|
|
|
|
|
break;
|
|
|
|
|
case EditPage::AS_SUMMARY_NEEDED:
|
|
|
|
|
$status->fatal( 'apierror-summaryrequired' );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
wfWarn( __METHOD__ . ": Unknown EditPage code {$status->value} with no message" );
|
|
|
|
|
$status->fatal( 'apierror-unknownerror-editpage', $status->value );
|
|
|
|
|
break;
|
2018-03-20 13:25:26 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2016-10-19 16:54:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->dieStatus( $status );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2011-06-20 22:18:11 +00:00
|
|
|
$apiResult->addValue( null, $this->getModuleName(), $r );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-23 22:02:23 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getAllowedParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'title' => [
|
2010-08-04 14:15:33 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'pageid' => [
|
2012-04-05 20:54:18 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2008-03-12 13:25:12 +00:00
|
|
|
'section' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'sectiontitle' => [
|
2011-12-20 04:15:21 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'text' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2008-03-03 18:19:52 +00:00
|
|
|
'summary' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'tags' => [
|
2016-01-20 09:51:01 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'tags',
|
2015-04-15 01:33:08 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2008-03-03 18:19:52 +00:00
|
|
|
'minor' => false,
|
|
|
|
|
'notminor' => false,
|
|
|
|
|
'bot' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'basetimestamp' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'starttimestamp' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2008-03-03 18:19:52 +00:00
|
|
|
'recreate' => false,
|
2008-03-25 21:12:01 +00:00
|
|
|
'createonly' => false,
|
2008-06-15 20:37:28 +00:00
|
|
|
'nocreate' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'watch' => [
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'unwatch' => [
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'watchlist' => [
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'preferences',
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2010-01-11 15:55:52 +00:00
|
|
|
'watch',
|
|
|
|
|
'unwatch',
|
|
|
|
|
'preferences',
|
2009-07-14 20:48:00 +00:00
|
|
|
'nochange'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2008-05-28 09:22:40 +00:00
|
|
|
'md5' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'prependtext' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'appendtext' => [
|
2015-05-07 16:39:55 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'undo' => [
|
2018-03-20 13:25:26 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_MIN => 0,
|
|
|
|
|
ApiBase::PARAM_RANGE_ENFORCE => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'undoafter' => [
|
2018-03-20 13:25:26 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer',
|
|
|
|
|
ApiBase::PARAM_MIN => 0,
|
|
|
|
|
ApiBase::PARAM_RANGE_ENFORCE => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'redirect' => [
|
2010-08-08 01:14:48 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'boolean',
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'contentformat' => [
|
2012-08-21 14:14:18 +00:00
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'contentmodel' => [
|
2012-08-21 14:14:18 +00:00
|
|
|
ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'token' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
// Standard definition automatically inserted
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_APPEND => [ 'apihelp-edit-param-token' ],
|
|
|
|
|
],
|
|
|
|
|
];
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
2014-08-08 16:56:07 +00:00
|
|
|
return 'csrf';
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=edit&title=Test&summary=test%20summary&' .
|
|
|
|
|
'text=article%20content&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
|
|
|
|
|
=> 'apihelp-edit-example-edit',
|
|
|
|
|
'action=edit&title=Test&summary=NOTOC&minor=&' .
|
|
|
|
|
'prependtext=__NOTOC__%0A&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
|
|
|
|
|
=> 'apihelp-edit-example-prepend',
|
|
|
|
|
'action=edit&title=Test&undo=13585&undoafter=13579&' .
|
|
|
|
|
'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
|
|
|
|
|
=> 'apihelp-edit-example-undo',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2017-04-04 22:52:57 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Edit';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
2008-03-12 13:25:12 +00:00
|
|
|
}
|