2008-03-03 18:19:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on August 16, 2007
|
|
|
|
|
*
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2007 Iker Labarga <Firstname><Lastname>@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* 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.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2008-03-03 18:19:52 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-01-11 15:55:52 +00:00
|
|
|
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 ) {
|
|
|
|
|
parent :: __construct( $query, $moduleName );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$params = $this->extractRequestParams();
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $params['title'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'title' ) );
|
2010-01-23 22:26:40 +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 )
|
|
|
|
|
$this->dieUsageMsg( array( 'missingtext' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $params['token'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !$wgUser->matchEditToken( $params['token'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'sessionfailure' ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$titleObj = Title::newFromText( $params['title'] );
|
|
|
|
|
if ( !$titleObj || $titleObj->isExternal() )
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
2009-11-06 14:44:04 +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-01-11 15:55:52 +00:00
|
|
|
if ( $params['createonly'] && $titleObj->exists() )
|
|
|
|
|
$this->dieUsageMsg( array( 'createonly-exists' ) );
|
|
|
|
|
if ( $params['nocreate'] && !$titleObj->exists() )
|
|
|
|
|
$this->dieUsageMsg( array( 'nocreate-missing' ) );
|
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 );
|
|
|
|
|
if ( !$titleObj->exists() )
|
|
|
|
|
$errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $wgUser ) );
|
|
|
|
|
if ( count( $errors ) )
|
|
|
|
|
$this->dieUsageMsg( $errors[0] );
|
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-01-11 15:55:52 +00:00
|
|
|
if ( $articleObj->getID() == 0 && $titleObj->getNamespace() != NS_MEDIAWIKI )
|
2009-03-24 16:15:43 +00:00
|
|
|
$content = '';
|
|
|
|
|
else
|
|
|
|
|
$content = $articleObj->getContent();
|
2009-07-14 20:14:47 +00:00
|
|
|
|
2010-01-11 15:55:52 +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 );
|
|
|
|
|
if ( $content === false )
|
|
|
|
|
$this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
|
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
|
|
|
}
|
2009-01-26 13:51:03 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['undo'] > 0 )
|
2009-01-26 13:51:03 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['undoafter'] > 0 )
|
2009-01-26 13:51:03 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['undo'] < $params['undoafter'] )
|
|
|
|
|
list( $params['undo'], $params['undoafter'] ) =
|
|
|
|
|
array( $params['undoafter'], $params['undo'] );
|
|
|
|
|
$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'] );
|
|
|
|
|
if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['undoafter'] == 0 )
|
2009-01-26 13:51:03 +00:00
|
|
|
$undoafterRev = $undoRev->getPrevious();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $undoafterRev ) || $undoafterRev->isDeleted( Revision::DELETED_TEXT ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'nosuchrevid', $params['undoafter'] ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $undoRev->getPage() != $articleObj->getID() )
|
|
|
|
|
$this->dieUsageMsg( array( 'revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText() ) );
|
|
|
|
|
if ( $undoafterRev->getPage() != $articleObj->getID() )
|
|
|
|
|
$this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$newtext = $articleObj->getUndoText( $undoRev, $undoafterRev );
|
|
|
|
|
if ( $newtext === false )
|
|
|
|
|
$this->dieUsageMsg( array( 'undo-failure' ) );
|
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-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $params['summary'] ) && $titleObj->getNextRevisionID( $undoafterRev->getID() ) == $params['undo'] )
|
|
|
|
|
$params['summary'] = wfMsgForContent( 'undo-summary', $params['undo'], $undoRev->getUserText() );
|
2009-01-26 13:51:03 +00:00
|
|
|
}
|
2008-06-12 13:05:07 +00:00
|
|
|
|
2008-05-28 09:22:40 +00:00
|
|
|
# See if the MD5 hash checks out
|
2010-01-23 22:26:40 +00:00
|
|
|
if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] )
|
|
|
|
|
$this->dieUsageMsg( array( 'hashcheckfailed' ) );
|
2008-05-28 09:22:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$ep = new EditPage( $articleObj );
|
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-01-11 15:55:52 +00:00
|
|
|
$reqArr = array( 'wpTextbox1' => $params['text'],
|
2010-01-22 10:48:57 +00:00
|
|
|
'wpEditToken' => $params['token'],
|
2008-03-03 18:19:52 +00:00
|
|
|
'wpIgnoreBlankSummary' => ''
|
|
|
|
|
);
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['summary'] ) )
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpSummary'] = $params['summary'];
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
# Watch out for basetimestamp == ''
|
|
|
|
|
# wfTimestamp() treats it as NOW, almost certainly causing an edit conflict
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['basetimestamp'] ) && $params['basetimestamp'] != '' )
|
|
|
|
|
$reqArr['wpEdittime'] = wfTimestamp( TS_MW, $params['basetimestamp'] );
|
2008-03-03 18:19:52 +00:00
|
|
|
else
|
|
|
|
|
$reqArr['wpEdittime'] = $articleObj->getTimestamp();
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' )
|
|
|
|
|
$reqArr['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] );
|
2008-10-04 13:43:17 +00:00
|
|
|
else
|
2010-01-23 22:26:40 +00:00
|
|
|
$reqArr['wpStarttime'] = $reqArr['wpEdittime']; # Fake wpStartime
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) )
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpMinoredit'] = '';
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['recreate'] )
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpRecreate'] = '';
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['section'] ) )
|
2008-03-12 13:25:12 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$section = intval( $params['section'] );
|
|
|
|
|
if ( $section == 0 && $params['section'] != '0' && $params['section'] != 'new' )
|
|
|
|
|
$this->dieUsage( "The section parameter must be set to an integer or 'new'", "invalidsection" );
|
2008-03-12 13:25:12 +00:00
|
|
|
$reqArr['wpSection'] = $params['section'];
|
|
|
|
|
}
|
2008-12-10 14:12:54 +00:00
|
|
|
else
|
|
|
|
|
$reqArr['wpSection'] = '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-07-14 20:48:00 +00:00
|
|
|
// Handle watchlist settings
|
2010-01-11 15:55:52 +00:00
|
|
|
switch ( $params['watchlist'] )
|
2009-07-14 20:48:00 +00:00
|
|
|
{
|
|
|
|
|
case 'watch':
|
|
|
|
|
$watch = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'unwatch':
|
|
|
|
|
$watch = false;
|
|
|
|
|
break;
|
|
|
|
|
case 'preferences':
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $titleObj->exists() )
|
|
|
|
|
$watch = $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching();
|
2009-07-14 20:48:00 +00:00
|
|
|
else
|
2010-01-11 15:55:52 +00:00
|
|
|
$watch = $wgUser->getOption( 'watchcreations' );
|
2009-07-14 20:48:00 +00:00
|
|
|
break;
|
|
|
|
|
case 'nochange':
|
|
|
|
|
default:
|
|
|
|
|
$watch = $titleObj->userIsWatching();
|
|
|
|
|
}
|
|
|
|
|
// Deprecated parameters
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['watch'] )
|
2008-03-03 18:19:52 +00:00
|
|
|
$watch = true;
|
2010-01-11 15:55:52 +00:00
|
|
|
elseif ( $params['unwatch'] )
|
2008-03-03 18:19:52 +00:00
|
|
|
$watch = false;
|
2009-07-14 20:48:00 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $watch )
|
2008-03-03 18:19:52 +00:00
|
|
|
$reqArr['wpWatchthis'] = '';
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$req = new FauxRequest( $reqArr, true );
|
|
|
|
|
$ep->importFormData( $req );
|
2008-03-03 18:19:52 +00:00
|
|
|
|
|
|
|
|
# Run hooks
|
2008-05-28 09:14:35 +00:00
|
|
|
# Handle CAPTCHA parameters
|
2008-03-03 18:19:52 +00:00
|
|
|
global $wgRequest;
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['captchaid'] ) )
|
2008-09-30 16:08:39 +00:00
|
|
|
$wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] );
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !is_null( $params['captchaword'] ) )
|
2008-09-30 16:08:39 +00:00
|
|
|
$wgRequest->setVal( 'wpCaptchaWord', $params['captchaword'] );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
$r = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) )
|
2008-03-03 18:19:52 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( count( $r ) )
|
2008-03-03 18:19:52 +00:00
|
|
|
{
|
|
|
|
|
$r['result'] = "Failure";
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
2008-04-14 07:45:50 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2008-03-03 18:19:52 +00:00
|
|
|
else
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'hookaborted' ) );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
# Do the actual save
|
|
|
|
|
$oldRevId = $articleObj->getRevIdFetched();
|
|
|
|
|
$result = null;
|
2008-05-28 09:14:35 +00:00
|
|
|
# Fake $wgRequest for some hooks inside EditPage
|
|
|
|
|
# FIXME: This interface SUCKS
|
|
|
|
|
$oldRequest = $wgRequest;
|
|
|
|
|
$wgRequest = $req;
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$retval = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
|
2008-05-28 09:14:35 +00:00
|
|
|
$wgRequest = $oldRequest;
|
2010-01-11 15:55:52 +00:00
|
|
|
switch( $retval )
|
2008-03-03 18:19:52 +00:00
|
|
|
{
|
|
|
|
|
case EditPage::AS_HOOK_ERROR:
|
|
|
|
|
case EditPage::AS_HOOK_ERROR_EXPECTED:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'hookaborted' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_IMAGE_REDIRECT_ANON:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'noimageredirect-anon' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_IMAGE_REDIRECT_LOGGED:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'filtered' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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:
|
|
|
|
|
global $wgMaxArticleSize;
|
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:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'actionthrottledtext' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_ARTICLE_WAS_DELETED:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'wasdeleted' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_NO_CREATE_PERMISSION:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'nocreate-loggedin' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_BLANK_ARTICLE:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'blankpage' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
case EditPage::AS_CONFLICT_DETECTED:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'editconflict' ) );
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +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:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( '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'] = '';
|
|
|
|
|
case EditPage::AS_SUCCESS_UPDATE:
|
|
|
|
|
$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();
|
2008-08-26 20:49:52 +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-01-11 15:55:52 +00:00
|
|
|
if ( $newRevId == $oldRevId )
|
2008-03-03 18:19:52 +00:00
|
|
|
$r['nochange'] = '';
|
|
|
|
|
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-01-23 22:26:40 +00:00
|
|
|
|
2009-10-28 13:35:39 +00:00
|
|
|
case EditPage::AS_END:
|
|
|
|
|
# This usually means some kind of race condition
|
|
|
|
|
# or DB weirdness occurred. Fall through to throw an unknown
|
|
|
|
|
# error.
|
2010-01-11 15:55:52 +00:00
|
|
|
|
2009-10-28 13:35:39 +00:00
|
|
|
# This needs fixing higher up, as Article::doEdit should be
|
|
|
|
|
# used rather than Article::updateArticle, so that specific
|
|
|
|
|
# error conditions can be returned
|
2008-03-03 18:19:52 +00:00
|
|
|
default:
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'unknownerror', $retval ) );
|
2008-03-03 18:19:52 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-03 18:19:52 +00:00
|
|
|
protected function getDescription() {
|
|
|
|
|
return 'Create and edit pages.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getAllowedParams() {
|
|
|
|
|
return array (
|
|
|
|
|
'title' => null,
|
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(
|
|
|
|
|
ApiBase :: PARAM_DFLT => false,
|
|
|
|
|
ApiBase :: PARAM_DEPRECATED => true,
|
|
|
|
|
),
|
|
|
|
|
'unwatch' => array(
|
|
|
|
|
ApiBase :: PARAM_DFLT => false,
|
|
|
|
|
ApiBase :: PARAM_DEPRECATED => true,
|
|
|
|
|
),
|
2009-07-14 20:48:00 +00:00
|
|
|
'watchlist' => array(
|
|
|
|
|
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(
|
|
|
|
|
ApiBase :: PARAM_TYPE => 'integer'
|
|
|
|
|
),
|
|
|
|
|
'undoafter' => array(
|
|
|
|
|
ApiBase :: PARAM_TYPE => 'integer'
|
|
|
|
|
),
|
2008-03-03 18:19:52 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getParamDescription() {
|
|
|
|
|
return array (
|
|
|
|
|
'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',
|
|
|
|
|
'token' => 'Edit token. You can get one of these through prop=info',
|
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',
|
2010-01-11 15:55:52 +00:00
|
|
|
'basetimestamp' => array( 'Timestamp of the base revision (gotten 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.',
|
2008-10-04 13:43:17 +00:00
|
|
|
'Used to detect edit conflicts; leave unset to ignore conflicts.'
|
|
|
|
|
),
|
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',
|
2008-06-15 19:59:55 +00:00
|
|
|
'md5' => array( 'The MD5 hash of the text parameter, or the prependtext and appendtext parameters concatenated.',
|
2010-01-11 15:55:52 +00:00
|
|
|
'If set, the edit won\'t be done unless the hash is correct' ),
|
2009-07-14 20:14:47 +00:00
|
|
|
'prependtext' => 'Add this text to the beginning of the page. Overrides text.',
|
2008-06-12 13:05:07 +00:00
|
|
|
'appendtext' => 'Add this text to the end of the page. Overrides text',
|
2009-01-26 13:51:03 +00:00
|
|
|
'undo' => 'Undo this revision. Overrides text, prependtext and appendtext',
|
|
|
|
|
'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
|
2008-03-03 18:19:52 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getExamples() {
|
|
|
|
|
return array (
|
|
|
|
|
"Edit a page (anonymous user):",
|
2009-01-26 13:51:03 +00:00
|
|
|
" api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\",
|
|
|
|
|
"Prepend __NOTOC__ to a page (anonymous user):",
|
|
|
|
|
" api.php?action=edit&title=Test&summary=NOTOC&minor&prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\",
|
|
|
|
|
"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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|