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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('MEDIAWIKI')) {
|
|
|
|
|
// Eclipse helper - will be ignored in production
|
|
|
|
|
require_once ("ApiBase.php");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @addtogroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiMove extends ApiBase {
|
|
|
|
|
|
|
|
|
|
public function __construct($main, $action) {
|
|
|
|
|
parent :: __construct($main, $action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$this->getMain()->requestWriteMode();
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
if(is_null($params['reason']))
|
|
|
|
|
$params['reason'] = '';
|
|
|
|
|
|
|
|
|
|
$titleObj = NULL;
|
|
|
|
|
if(!isset($params['from']))
|
2008-01-18 16:01:31 +00:00
|
|
|
$this->dieUsageMsg(array('missingparam', 'from'));
|
2007-12-06 16:06:22 +00:00
|
|
|
if(!isset($params['to']))
|
2008-01-18 16:01:31 +00:00
|
|
|
$this->dieUsageMsg(array('missingparam', 'to'));
|
2007-12-06 16:06:22 +00:00
|
|
|
if(!isset($params['token']))
|
2008-01-18 16:01:31 +00:00
|
|
|
$this->dieUsageMsg(array('missingparam', 'token'));
|
2007-12-06 16:06:22 +00:00
|
|
|
if(!$wgUser->matchEditToken($params['token']))
|
2008-01-18 15:52:40 +00:00
|
|
|
$this->dieUsageMsg(array('sessionfailure'));
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
$fromTitle = Title::newFromText($params['from']);
|
|
|
|
|
if(!$fromTitle)
|
2008-01-18 15:52:40 +00:00
|
|
|
$this->dieUsageMsg(array('invalidtitle', $params['from']));
|
2007-12-06 16:06:22 +00:00
|
|
|
if(!$fromTitle->exists())
|
2008-01-18 15:52:40 +00:00
|
|
|
$this->dieUsageMsg(array('notanarticle'));
|
2007-12-06 16:06:22 +00:00
|
|
|
$fromTalk = $fromTitle->getTalkPage();
|
|
|
|
|
|
|
|
|
|
$toTitle = Title::newFromText($params['to']);
|
|
|
|
|
if(!$toTitle)
|
2008-01-18 15:52:40 +00:00
|
|
|
$this->dieUsageMsg(array('invalidtitle', $params['to']));
|
2007-12-06 16:06:22 +00:00
|
|
|
$toTalk = $toTitle->getTalkPage();
|
|
|
|
|
|
2008-01-18 16:34:40 +00:00
|
|
|
// Run getUserPermissionsErrors() here so we get message arguments too,
|
|
|
|
|
// rather than just a message key. The latter is troublesome for messages
|
|
|
|
|
// that use arguments.
|
|
|
|
|
// FIXME: moveTo() should really return an array, requires some
|
|
|
|
|
// refactoring of other code, though (mainly SpecialMovepage.php)
|
|
|
|
|
$errors = array_merge($fromTitle->getUserPermissionsErrors('move', $wgUser),
|
|
|
|
|
$fromTitle->getUserPermissionsErrors('edit', $wgUser),
|
|
|
|
|
$toTitle->getUserPermissionsErrors('move', $wgUser),
|
|
|
|
|
$toTitle->getUserPermissionsErrors('edit', $wgUser));
|
|
|
|
|
if(!empty($errors))
|
|
|
|
|
// We don't care about multiple errors, just report one of them
|
|
|
|
|
$this->dieUsageMsg(current($errors));
|
|
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
$dbw = wfGetDB(DB_MASTER);
|
|
|
|
|
$dbw->begin();
|
|
|
|
|
$retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
|
|
|
|
|
if($retval !== true)
|
2008-01-18 15:52:40 +00:00
|
|
|
$this->dieUsageMsg(array($retval));
|
|
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
$r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']);
|
2008-03-02 19:00:50 +00:00
|
|
|
if(!$params['noredirect'] || !$wgUser->isAllowed('suppressredirect'))
|
2007-12-06 16:06:22 +00:00
|
|
|
$r['redirectcreated'] = '';
|
|
|
|
|
|
|
|
|
|
if($params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage())
|
|
|
|
|
{
|
|
|
|
|
// We need to move the talk page as well
|
|
|
|
|
$toTalk = $toTitle->getTalkPage();
|
|
|
|
|
$retval = $fromTalk->moveTo($toTalk, true, $params['reason'], !$params['noredirect']);
|
|
|
|
|
if($retval === true)
|
|
|
|
|
{
|
|
|
|
|
$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
|
|
|
{
|
|
|
|
|
$r['talkmove-error-code'] = ApiBase::$messageMap[$retval]['code'];
|
|
|
|
|
$r['talkmove-error-info'] = ApiBase::$messageMap[$retval]['info'];
|
|
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-03-02 19:00:50 +00:00
|
|
|
|
|
|
|
|
# Watch pages
|
|
|
|
|
if($params['watch'] || $wgUser->getOption('watchmoves'))
|
|
|
|
|
{
|
|
|
|
|
$wgUser->addWatch($fromTitle);
|
|
|
|
|
$wgUser->addWatch($toTitle);
|
|
|
|
|
}
|
|
|
|
|
else if($params['unwatch'])
|
|
|
|
|
{
|
|
|
|
|
$wgUser->removeWatch($fromTitle);
|
|
|
|
|
$wgUser->removeWatch($toTitle);
|
|
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
$dbw->commit(); // Make sure all changes are really written to the DB
|
|
|
|
|
$this->getResult()->addValue(null, $this->getModuleName(), $r);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-18 20:43:59 +00:00
|
|
|
public function mustBePosted() { 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,
|
|
|
|
|
'to' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'reason' => null,
|
|
|
|
|
'movetalk' => false,
|
2008-03-02 19:00:50 +00:00
|
|
|
'noredirect' => false,
|
|
|
|
|
'watch' => false,
|
|
|
|
|
'unwatch' => 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 (
|
|
|
|
|
'from' => 'Title of the page you want to move.',
|
|
|
|
|
'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.',
|
2008-03-02 19:00:50 +00:00
|
|
|
'noredirect' => 'Don\'t create a redirect',
|
|
|
|
|
'watch' => 'Add the page and the redirect to your watchlist',
|
|
|
|
|
'unwatch' => 'Remove the page and the redirect from your watchlist'
|
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(
|
|
|
|
|
'Moves a page.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|