2008-03-03 18:19:52 +00:00
|
|
|
<?php
|
2010-02-22 12:18:42 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2008-03-03 18:19:52 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on August 16, 2007
|
|
|
|
|
*
|
2010-02-22 12:18:42 +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
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2010-02-22 12:18:42 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
|
|
|
|
require_once( "ApiBase.php" );
|
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,
|
|
|
|
|
* EditPage.php should be rewritten to provide a cleaner interface
|
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 {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $query, $moduleName ) {
|
2010-02-22 12:18:42 +00:00
|
|
|
parent::__construct( $query, $moduleName );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$params = $this->extractRequestParams();
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
|
|
|
|
|
is_null( $params['prependtext'] ) &&
|
|
|
|
|
$params['undo'] == 0 )
|
2010-02-22 12:18:42 +00:00
|
|
|
{
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'missingtext' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$titleObj = Title::newFromText( $params['title'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !$titleObj || $titleObj->isExternal() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
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'] ) {
|
|
|
|
|
if ( $titleObj->isRedirect() ) {
|
2010-10-23 17:48:08 +00:00
|
|
|
$oldTitle = $titleObj;
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2010-10-23 17:48:08 +00:00
|
|
|
$titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
|
2010-12-30 17:06:09 +00:00
|
|
|
// array_shift( $titles );
|
|
|
|
|
|
2010-10-23 17:48:08 +00:00
|
|
|
$redirValues = array();
|
|
|
|
|
foreach ( $titles as $id => $newTitle ) {
|
2010-12-30 17:06:09 +00:00
|
|
|
|
|
|
|
|
if ( !isset( $titles[ $id - 1 ] ) ) {
|
2010-10-23 17:48:08 +00:00
|
|
|
$titles[ $id - 1 ] = $oldTitle;
|
|
|
|
|
}
|
2010-12-30 17:06:09 +00:00
|
|
|
|
2010-10-23 17:48:08 +00:00
|
|
|
$redirValues[] = array(
|
|
|
|
|
'from' => $titles[ $id - 1 ]->getPrefixedText(),
|
|
|
|
|
'to' => $newTitle->getPrefixedText()
|
|
|
|
|
);
|
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
|
|
|
|
2011-06-20 22:18:11 +00:00
|
|
|
$apiResult->setIndexedTagName( $redirValues, 'r' );
|
|
|
|
|
$apiResult->addValue( null, 'redirects', $redirValues );
|
2010-08-08 01:14:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2009-05-02 14:47:26 +00:00
|
|
|
// Some functions depend on $wgTitle == $ep->mTitle
|
|
|
|
|
global $wgTitle;
|
2009-05-02 15:03:02 +00:00
|
|
|
$wgTitle = $titleObj;
|
2008-03-25 20:41:55 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $params['createonly'] && $titleObj->exists() ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'createonly-exists' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['nocreate'] && !$titleObj->exists() ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'nocreate-missing' );
|
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
|
2010-01-11 15:55:52 +00:00
|
|
|
$errors = $titleObj->getUserPermissionsErrors( 'edit', $wgUser );
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !$titleObj->exists() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $wgUser ) );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
if ( count( $errors ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( $errors[0] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$articleObj = new Article( $titleObj );
|
2008-06-15 19:59:55 +00:00
|
|
|
$toMD5 = $params['text'];
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['appendtext'] ) || !is_null( $params['prependtext'] ) )
|
2008-06-12 13:05:07 +00:00
|
|
|
{
|
2009-03-24 16:15:43 +00:00
|
|
|
// For non-existent pages, Article::getContent()
|
|
|
|
|
// returns an interface message rather than ''
|
|
|
|
|
// We do want getContent()'s behavior for non-existent
|
|
|
|
|
// MediaWiki: pages, though
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $articleObj->getID() == 0 && $titleObj->getNamespace() != NS_MEDIAWIKI ) {
|
2009-03-24 16:15:43 +00:00
|
|
|
$content = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2009-03-24 16:15:43 +00:00
|
|
|
$content = $articleObj->getContent();
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !is_null( $params['section'] ) ) {
|
2009-07-14 20:14:47 +00:00
|
|
|
// Process the content for section edits
|
|
|
|
|
global $wgParser;
|
2010-01-11 15:55:52 +00:00
|
|
|
$section = intval( $params['section'] );
|
|
|
|
|
$content = $wgParser->getSection( $content, $section, false );
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $content === false ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2009-07-14 20:14:47 +00:00
|
|
|
}
|
2008-06-12 13:05:07 +00:00
|
|
|
$params['text'] = $params['prependtext'] . $content . $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'] ) =
|
|
|
|
|
array( $params['undoafter'], $params['undo'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$undoafterRev = Revision::newFromID( $params['undoafter'] );
|
2009-01-26 13:51:03 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$undoRev = Revision::newFromID( $params['undo'] );
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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
|
|
|
}
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'nosuchrevid', $params['undoafter'] ) );
|
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 ( $undoRev->getPage() != $articleObj->getID() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText() ) );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
if ( $undoafterRev->getPage() != $articleObj->getID() ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$newtext = $articleObj->getUndoText( $undoRev, $undoafterRev );
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $newtext === false ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'undo-failure' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2009-01-26 13:51:03 +00:00
|
|
|
$params['text'] = $newtext;
|
|
|
|
|
// If no summary was given and we only undid one rev,
|
|
|
|
|
// use an autosummary
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( is_null( $params['summary'] ) && $titleObj->getNextRevisionID( $undoafterRev->getID() ) == $params['undo'] ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$params['summary'] = wfMsgForContent( 'undo-summary', $params['undo'], $undoRev->getUserText() );
|
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'] ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'hashcheckfailed' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$ep = new EditPage( $articleObj );
|
2011-02-10 17:08:37 +00:00
|
|
|
$ep->setContextTitle( $titleObj );
|
|
|
|
|
|
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
|
2010-02-22 12:18:42 +00:00
|
|
|
$reqArr = array(
|
|
|
|
|
'wpTextbox1' => $params['text'],
|
|
|
|
|
'wpEditToken' => $params['token'],
|
|
|
|
|
'wpIgnoreBlankSummary' => ''
|
2008-03-03 18:19:52 +00:00
|
|
|
);
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['summary'] ) ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpSummary'] = $params['summary'];
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// Watch out for basetimestamp == ''
|
|
|
|
|
// wfTimestamp() treats it as NOW, almost certainly causing an edit conflict
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( !is_null( $params['basetimestamp'] ) && $params['basetimestamp'] != '' ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$reqArr['wpEdittime'] = wfTimestamp( TS_MW, $params['basetimestamp'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpEdittime'] = $articleObj->getTimestamp();
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-03-25 22:15:08 +00:00
|
|
|
if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$reqArr['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2010-08-06 12:15:23 +00:00
|
|
|
$reqArr['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-11-01 18:58:24 +00:00
|
|
|
if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['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'] ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['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'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$section = intval( $params['section'] );
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( $section == 0 && $params['section'] != '0' && $params['section'] != 'new' ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsage( "The section parameter must be set to an integer or 'new'", "invalidsection" );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-03-12 13:25:12 +00:00
|
|
|
$reqArr['wpSection'] = $params['section'];
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2008-12-10 14:12:54 +00:00
|
|
|
$reqArr['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 ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpWatchthis'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$req = new FauxRequest( $reqArr, true );
|
|
|
|
|
$ep->importFormData( $req );
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// Run hooks
|
|
|
|
|
// Handle CAPTCHA parameters
|
2008-03-03 18:19:52 +00:00
|
|
|
global $wgRequest;
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( !is_null( $params['captchaid'] ) ) {
|
2008-09-30 16:08:39 +00:00
|
|
|
$wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
|
|
|
|
if ( !is_null( $params['captchaword'] ) ) {
|
2008-09-30 16:08:39 +00:00
|
|
|
$wgRequest->setVal( 'wpCaptchaWord', $params['captchaword'] );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
$r = array();
|
2010-06-27 19:22:46 +00:00
|
|
|
if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) {
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( count( $r ) ) {
|
|
|
|
|
$r['result'] = 'Failure';
|
2011-06-20 22:18:11 +00:00
|
|
|
$apiResult->addValue( null, $this->getModuleName(), $r );
|
2008-04-14 07:45:50 +00:00
|
|
|
return;
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'hookaborted' );
|
2010-02-22 12:18:42 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// Do the actual save
|
2008-03-03 18:19:52 +00:00
|
|
|
$oldRevId = $articleObj->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;
|
|
|
|
|
|
2011-08-26 16:26:17 +00:00
|
|
|
$status = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
|
2008-05-28 09:14:35 +00:00
|
|
|
$wgRequest = $oldRequest;
|
2010-08-12 14:25:07 +00:00
|
|
|
global $wgMaxArticleSize;
|
|
|
|
|
|
2011-08-26 16:26:17 +00:00
|
|
|
switch( $status->value ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_HOOK_ERROR:
|
|
|
|
|
case EditPage::AS_HOOK_ERROR_EXPECTED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'hookaborted' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_IMAGE_REDIRECT_ANON:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'noimageredirect-anon' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_IMAGE_REDIRECT_LOGGED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'noimageredirect-logged' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_SPAM_ERROR:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_FILTERING:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'filtered' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'blockedtext' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
|
|
|
|
|
case EditPage::AS_CONTENT_TOO_BIG:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_READ_ONLY_PAGE_ANON:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'noedit-anon' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_READ_ONLY_PAGE_LOGGED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'noedit' );
|
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();
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_RATE_LIMITED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'actionthrottledtext' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_ARTICLE_WAS_DELETED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'wasdeleted' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_NO_CREATE_PERMISSION:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'nocreate-loggedin' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_BLANK_ARTICLE:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'blankpage' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_CONFLICT_DETECTED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'editconflict' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-23 22:52:40 +00:00
|
|
|
// case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
|
2008-08-26 20:40:44 +00:00
|
|
|
case EditPage::AS_TEXTBOX_EMPTY:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'emptynewsection' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_SUCCESS_NEW_ARTICLE:
|
|
|
|
|
$r['new'] = '';
|
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';
|
2010-01-11 15:55:52 +00:00
|
|
|
$r['pageid'] = intval( $titleObj->getArticleID() );
|
2008-03-03 18:19:52 +00:00
|
|
|
$r['title'] = $titleObj->getPrefixedText();
|
2010-01-23 22:52:40 +00:00
|
|
|
// HACK: We create a new Article object here because getRevIdFetched()
|
|
|
|
|
// refuses to be run twice, and because Title::getLatestRevId()
|
|
|
|
|
// won't fetch from the master unless we select for update, which we
|
|
|
|
|
// don't want to do.
|
2010-01-11 15:55:52 +00:00
|
|
|
$newArticle = new Article( $titleObj );
|
2008-08-26 20:49:52 +00:00
|
|
|
$newRevId = $newArticle->getRevIdFetched();
|
2010-02-22 12:18:42 +00:00
|
|
|
if ( $newRevId == $oldRevId ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
$r['nochange'] = '';
|
2010-02-22 12:18:42 +00:00
|
|
|
} else {
|
2010-01-11 15:55:52 +00:00
|
|
|
$r['oldrevid'] = intval( $oldRevId );
|
|
|
|
|
$r['newrevid'] = intval( $newRevId );
|
|
|
|
|
$r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
|
|
|
|
|
$newArticle->getTimestamp() );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-06-27 19:22:46 +00:00
|
|
|
case EditPage::AS_SUMMARY_NEEDED:
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'summaryrequired' );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2009-10-28 13:35:39 +00:00
|
|
|
case EditPage::AS_END:
|
2011-08-26 16:26:17 +00:00
|
|
|
// $status came from WikiPage::doEdit()
|
|
|
|
|
$errors = $status->getErrorsArray();
|
|
|
|
|
$this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
|
|
|
|
|
break;
|
2008-03-03 18:19:52 +00:00
|
|
|
default:
|
2011-08-26 16:26:17 +00:00
|
|
|
$this->dieUsageMsg( array( 'unknownerror', $status->value ) );
|
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-26 22:56:31 +00:00
|
|
|
public function getDescription() {
|
2008-03-03 18:19:52 +00:00
|
|
|
return 'Create and edit pages.';
|
|
|
|
|
}
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2010-02-14 14:29:24 +00:00
|
|
|
public function getPossibleErrors() {
|
2010-02-16 22:01:38 +00:00
|
|
|
global $wgMaxArticleSize;
|
2010-02-22 12:18:42 +00:00
|
|
|
|
2010-02-13 00:28:27 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'missingtext' ),
|
|
|
|
|
array( 'invalidtitle', 'title' ),
|
|
|
|
|
array( 'createonly-exists' ),
|
|
|
|
|
array( 'nocreate-missing' ),
|
|
|
|
|
array( 'nosuchrevid', 'undo' ),
|
|
|
|
|
array( 'nosuchrevid', 'undoafter' ),
|
|
|
|
|
array( 'revwrongpage', 'id', 'text' ),
|
|
|
|
|
array( 'undo-failure' ),
|
|
|
|
|
array( 'hashcheckfailed' ),
|
|
|
|
|
array( 'hookaborted' ),
|
|
|
|
|
array( 'noimageredirect-anon' ),
|
|
|
|
|
array( 'noimageredirect-logged' ),
|
|
|
|
|
array( 'spamdetected', 'spam' ),
|
2010-06-27 20:30:43 +00:00
|
|
|
array( 'summaryrequired' ),
|
2010-02-13 00:28:27 +00:00
|
|
|
array( 'filtered' ),
|
|
|
|
|
array( 'blockedtext' ),
|
2010-02-16 22:01:38 +00:00
|
|
|
array( 'contenttoobig', $wgMaxArticleSize ),
|
2010-02-13 00:28:27 +00:00
|
|
|
array( 'noedit-anon' ),
|
|
|
|
|
array( 'noedit' ),
|
|
|
|
|
array( 'actionthrottledtext' ),
|
|
|
|
|
array( 'wasdeleted' ),
|
|
|
|
|
array( 'nocreate-loggedin' ),
|
|
|
|
|
array( 'blankpage' ),
|
|
|
|
|
array( 'editconflict' ),
|
|
|
|
|
array( 'emptynewsection' ),
|
|
|
|
|
array( 'unknownerror', 'retval' ),
|
2010-02-13 01:24:00 +00:00
|
|
|
array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
|
2010-02-13 01:05:14 +00:00
|
|
|
array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
|
2011-06-05 18:34:26 +00:00
|
|
|
array( 'customcssprotected' ),
|
|
|
|
|
array( 'customjsprotected' ),
|
2010-02-14 14:29:24 +00:00
|
|
|
) );
|
2010-02-13 00:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-22 12:18:42 +00:00
|
|
|
return array(
|
2010-08-04 14:15:33 +00:00
|
|
|
'title' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2010-08-04 14:29:39 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true
|
2010-08-04 14:15:33 +00:00
|
|
|
),
|
2008-03-12 13:25:12 +00:00
|
|
|
'section' => null,
|
2008-03-03 18:19:52 +00:00
|
|
|
'text' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'summary' => null,
|
|
|
|
|
'minor' => false,
|
|
|
|
|
'notminor' => false,
|
|
|
|
|
'bot' => false,
|
|
|
|
|
'basetimestamp' => null,
|
2008-10-04 13:43:17 +00:00
|
|
|
'starttimestamp' => null,
|
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,
|
2008-03-03 18:19:52 +00:00
|
|
|
'captchaword' => null,
|
|
|
|
|
'captchaid' => null,
|
2009-10-28 00:56:07 +00:00
|
|
|
'watch' => array(
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2009-10-28 00:56:07 +00:00
|
|
|
),
|
|
|
|
|
'unwatch' => array(
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2009-10-28 00:56:07 +00:00
|
|
|
),
|
2009-07-14 20:48:00 +00:00
|
|
|
'watchlist' => array(
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'preferences',
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
2010-01-11 15:55:52 +00:00
|
|
|
'watch',
|
|
|
|
|
'unwatch',
|
|
|
|
|
'preferences',
|
2009-07-14 20:48:00 +00:00
|
|
|
'nochange'
|
|
|
|
|
),
|
|
|
|
|
),
|
2008-05-28 09:22:40 +00:00
|
|
|
'md5' => null,
|
2008-06-12 13:05:07 +00:00
|
|
|
'prependtext' => null,
|
|
|
|
|
'appendtext' => null,
|
2009-01-26 13:51:03 +00:00
|
|
|
'undo' => array(
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2009-01-26 13:51:03 +00:00
|
|
|
),
|
|
|
|
|
'undoafter' => array(
|
2010-02-22 12:18:42 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2009-01-26 13:51:03 +00:00
|
|
|
),
|
2010-08-08 01:14:48 +00:00
|
|
|
'redirect' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'boolean',
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
),
|
2008-03-03 18:19:52 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getParamDescription() {
|
2010-05-11 22:30:18 +00:00
|
|
|
$p = $this->getModulePrefix();
|
2010-02-22 12:18:42 +00:00
|
|
|
return array(
|
2008-03-03 18:19:52 +00:00
|
|
|
'title' => 'Page title',
|
2008-03-12 13:25:12 +00:00
|
|
|
'section' => 'Section number. 0 for the top section, \'new\' for a new section',
|
2008-03-03 18:19:52 +00:00
|
|
|
'text' => 'Page content',
|
2011-06-17 14:55:03 +00:00
|
|
|
'token' => array( 'Edit token. You can get one of these through prop=info.',
|
|
|
|
|
'The token should always be sent as the last parameter, or at least, after the text parameter'
|
|
|
|
|
),
|
2008-05-22 21:33:25 +00:00
|
|
|
'summary' => 'Edit summary. Also section title when section=new',
|
2008-03-03 18:19:52 +00:00
|
|
|
'minor' => 'Minor edit',
|
|
|
|
|
'notminor' => 'Non-minor edit',
|
|
|
|
|
'bot' => 'Mark this edit as bot',
|
2011-06-17 16:03:52 +00:00
|
|
|
'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
|
2008-03-03 18:19:52 +00:00
|
|
|
'Used to detect edit conflicts; leave unset to ignore conflicts.'
|
|
|
|
|
),
|
2010-01-11 15:55:52 +00:00
|
|
|
'starttimestamp' => array( 'Timestamp when you obtained the edit token.',
|
2010-05-11 22:30:18 +00:00
|
|
|
'Used to detect edit conflicts; leave unset to ignore conflicts'
|
2008-10-04 13:43:17 +00:00
|
|
|
),
|
2008-03-03 18:19:52 +00:00
|
|
|
'recreate' => 'Override any errors about the article having been deleted in the meantime',
|
2008-06-15 20:37:28 +00:00
|
|
|
'createonly' => 'Don\'t edit the page if it exists already',
|
|
|
|
|
'nocreate' => 'Throw an error if the page doesn\'t exist',
|
2009-10-28 00:56:07 +00:00
|
|
|
'watch' => 'Add the page to your watchlist',
|
|
|
|
|
'unwatch' => 'Remove the page from your watchlist',
|
2009-07-14 20:48:00 +00:00
|
|
|
'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
|
2008-03-03 18:19:52 +00:00
|
|
|
'captchaid' => 'CAPTCHA ID from previous request',
|
|
|
|
|
'captchaword' => 'Answer to the CAPTCHA',
|
2010-05-11 22:30:18 +00:00
|
|
|
'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
|
2011-07-28 19:13:58 +00:00
|
|
|
'If set, the edit won\'t be done unless the hash is correct' ),
|
2010-05-11 22:30:18 +00:00
|
|
|
'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
|
|
|
|
|
'appendtext' => "Add this text to the end of the page. Overrides {$p}text",
|
|
|
|
|
'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
|
2009-01-26 13:51:03 +00:00
|
|
|
'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
|
2010-08-08 01:14:48 +00:00
|
|
|
'redirect' => 'Automatically resolve redirects',
|
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() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 23:53:43 +00:00
|
|
|
public function getTokenSalt() {
|
2010-02-16 21:59:16 +00:00
|
|
|
return '';
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public function getExamples() {
|
2010-02-22 12:18:42 +00:00
|
|
|
return array(
|
|
|
|
|
'Edit a page (anonymous user):',
|
|
|
|
|
' api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\',
|
|
|
|
|
'Prepend __NOTOC__ to a page (anonymous user):',
|
2010-11-23 22:05:27 +00:00
|
|
|
' api.php?action=edit&title=Test&summary=NOTOC&minor=&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\',
|
2010-02-22 12:18:42 +00:00
|
|
|
'Undo r13579 through r13585 with autosummary (anonymous user):',
|
|
|
|
|
' api.php?action=edit&title=Test&undo=13585&undoafter=13579&basetimestamp=20070824123454&token=%2B\\',
|
2008-03-03 18:19:52 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
|
|
|
|
return 'http://www.mediawiki.org/wiki/API:Edit';
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
public function getVersion() {
|
2008-03-03 19:34:11 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2008-03-12 13:25:12 +00:00
|
|
|
}
|