2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Oct 31, 2007
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
|
|
|
|
*
|
|
|
|
|
* 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' ) ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-01-11 15:55:52 +00:00
|
|
|
require_once ( "ApiBase.php" );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
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
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
class ApiMove extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
|
|
|
|
parent :: __construct( $main, $action );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$params = $this->extractRequestParams();
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( is_null( $params['reason'] ) )
|
2007-12-06 16:06:22 +00:00
|
|
|
$params['reason'] = '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->requireOnlyOneParameter( $params, 'from', 'fromid' );
|
|
|
|
|
if ( !isset( $params['to'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'to' ) );
|
|
|
|
|
if ( !isset( $params['token'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
|
|
|
|
|
if ( !$wgUser->matchEditToken( $params['token'] ) )
|
|
|
|
|
$this->dieUsageMsg( array( 'sessionfailure' ) );
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $params['from'] ) )
|
2008-10-07 14:57:59 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$fromTitle = Title::newFromText( $params['from'] );
|
|
|
|
|
if ( !$fromTitle )
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
|
2008-10-07 14:57:59 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
else if ( isset( $params['fromid'] ) )
|
2008-10-07 14:57:59 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$fromTitle = Title::newFromID( $params['fromid'] );
|
|
|
|
|
if ( !$fromTitle )
|
|
|
|
|
$this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
|
2008-10-07 14:57:59 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !$fromTitle->exists() )
|
|
|
|
|
$this->dieUsageMsg( array( 'notanarticle' ) );
|
2007-12-06 16:06:22 +00:00
|
|
|
$fromTalk = $fromTitle->getTalkPage();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$toTitle = Title::newFromText( $params['to'] );
|
|
|
|
|
if ( !$toTitle )
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
|
2007-12-06 16:06:22 +00:00
|
|
|
$toTalk = $toTitle->getTalkPage();
|
2009-10-24 04:36:11 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $toTitle->getNamespace() == NS_FILE
|
|
|
|
|
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
|
2009-10-24 04:36:11 +00:00
|
|
|
&& wfFindFile( $toTitle ) )
|
|
|
|
|
{
|
|
|
|
|
if ( !$params['ignorewarnings'] && $wgUser->isAllowed( 'reupload-shared' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'sharedfile-exists' ) );
|
2009-10-24 04:36:11 +00:00
|
|
|
} elseif ( !$wgUser->isAllowed( 'reupload-shared' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'cantoverwrite-sharedfile' ) );
|
2009-10-24 04:36:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-09 14:16:51 +00:00
|
|
|
# Move the page
|
2008-05-24 20:44:49 +00:00
|
|
|
$hookErr = null;
|
2010-01-11 15:55:52 +00:00
|
|
|
$retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
|
|
|
|
|
if ( $retval !== true )
|
|
|
|
|
$this->dieUsageMsg( reset( $retval ) );
|
2008-01-18 15:52:40 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
|
|
|
|
|
if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) )
|
2007-12-06 16:06:22 +00:00
|
|
|
$r['redirectcreated'] = '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-02-09 14:16:51 +00:00
|
|
|
# Move the talk page
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() )
|
2007-12-06 16:06:22 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
|
|
|
|
|
if ( $retval === true )
|
2007-12-06 16:06:22 +00:00
|
|
|
{
|
|
|
|
|
$r['talkfrom'] = $fromTalk->getPrefixedText();
|
|
|
|
|
$r['talkto'] = $toTalk->getPrefixedText();
|
|
|
|
|
}
|
|
|
|
|
// We're not gonna dieUsage() on failure, since we already changed something
|
|
|
|
|
else
|
2008-01-18 15:52:40 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$parsed = $this->parseMsg( reset( $retval ) );
|
2009-02-09 14:16:51 +00:00
|
|
|
$r['talkmove-error-code'] = $parsed['code'];
|
|
|
|
|
$r['talkmove-error-info'] = $parsed['info'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Move subpages
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['movesubpages'] )
|
2009-02-09 14:16:51 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
|
|
|
|
|
$params['reason'], $params['noredirect'] );
|
|
|
|
|
$this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
|
|
|
|
|
if ( $params['movetalk'] )
|
2009-02-09 14:16:51 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
|
|
|
|
|
$params['reason'], $params['noredirect'] );
|
|
|
|
|
$this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-03-02 19:00:50 +00:00
|
|
|
# Watch pages
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) )
|
2008-03-02 19:00:50 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$wgUser->addWatch( $fromTitle );
|
|
|
|
|
$wgUser->addWatch( $toTitle );
|
2008-03-02 19:00:50 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
else if ( $params['unwatch'] )
|
2008-03-02 19:00:50 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$wgUser->removeWatch( $fromTitle );
|
|
|
|
|
$wgUser->removeWatch( $toTitle );
|
2008-03-02 19:00:50 +00:00
|
|
|
}
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2009-02-09 14:16:51 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect )
|
2009-02-09 14:16:51 +00:00
|
|
|
{
|
|
|
|
|
$retval = array();
|
2010-01-11 15:55:52 +00:00
|
|
|
$success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
|
|
|
|
|
if ( isset( $success[0] ) )
|
|
|
|
|
return array( 'error' => $this->parseMsg( $success ) );
|
2009-02-09 14:16:51 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// At least some pages could be moved
|
|
|
|
|
// Report each of them separately
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $success as $oldTitle => $newTitle )
|
2009-02-09 14:16:51 +00:00
|
|
|
{
|
2010-01-11 15:55:52 +00:00
|
|
|
$r = array( 'from' => $oldTitle );
|
|
|
|
|
if ( is_array( $newTitle ) )
|
|
|
|
|
$r['error'] = $this->parseMsg( reset( $newTitle ) );
|
2009-02-09 14:16:51 +00:00
|
|
|
else
|
|
|
|
|
// Success
|
|
|
|
|
$r['to'] = $newTitle;
|
|
|
|
|
$retval[] = $r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $retval;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-01-18 20:43:59 +00:00
|
|
|
public function mustBePosted() { return true; }
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2007-12-06 16:06:22 +00:00
|
|
|
return array (
|
|
|
|
|
'from' => null,
|
2008-10-07 14:57:59 +00:00
|
|
|
'fromid' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
'to' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'reason' => null,
|
|
|
|
|
'movetalk' => false,
|
2009-02-09 14:16:51 +00:00
|
|
|
'movesubpages' => false,
|
2008-03-02 19:00:50 +00:00
|
|
|
'noredirect' => false,
|
|
|
|
|
'watch' => false,
|
2009-10-24 04:36:11 +00:00
|
|
|
'unwatch' => false,
|
|
|
|
|
'ignorewarnings' => false
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2007-12-06 16:06:22 +00:00
|
|
|
return array (
|
2008-10-07 14:57:59 +00:00
|
|
|
'from' => 'Title of the page you want to move. Cannot be used together with fromid.',
|
|
|
|
|
'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.',
|
2007-12-06 16:06:22 +00:00
|
|
|
'to' => 'Title you want to rename the page to.',
|
|
|
|
|
'token' => 'A move token previously retrieved through prop=info',
|
|
|
|
|
'reason' => 'Reason for the move (optional).',
|
|
|
|
|
'movetalk' => 'Move the talk page, if it exists.',
|
2009-02-09 14:16:51 +00:00
|
|
|
'movesubpages' => 'Move subpages, if applicable',
|
2008-03-02 19:00:50 +00:00
|
|
|
'noredirect' => 'Don\'t create a redirect',
|
|
|
|
|
'watch' => 'Add the page and the redirect to your watchlist',
|
2009-10-24 04:36:11 +00:00
|
|
|
'unwatch' => 'Remove the page and the redirect from your watchlist',
|
|
|
|
|
'ignorewarnings' => 'Ignore any warnings'
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2007-12-06 16:06:22 +00:00
|
|
|
return array(
|
2008-09-07 19:12:41 +00:00
|
|
|
'Move a page.'
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getExamples() {
|
|
|
|
|
return array (
|
|
|
|
|
'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
}
|