(bug 10323) Special:Undelete should have "inverse selection" button
[mediawiki.git] / includes / api / ApiMove.php
blobe0c321d20e3d9318fe5cd932bb590cd0f71012eb
1 <?php
3 /*
4 * Created on Oct 31, 2007
5 * API for MediaWiki 1.8+
7 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 if (!defined('MEDIAWIKI')) {
26 // Eclipse helper - will be ignored in production
27 require_once ("ApiBase.php");
31 /**
32 * @ingroup API
34 class ApiMove extends ApiBase {
36 public function __construct($main, $action) {
37 parent :: __construct($main, $action);
40 public function execute() {
41 global $wgUser;
42 $this->getMain()->requestWriteMode();
43 $params = $this->extractRequestParams();
44 if(is_null($params['reason']))
45 $params['reason'] = '';
47 $titleObj = NULL;
48 if(!isset($params['from']))
49 $this->dieUsageMsg(array('missingparam', 'from'));
50 if(!isset($params['to']))
51 $this->dieUsageMsg(array('missingparam', 'to'));
52 if(!isset($params['token']))
53 $this->dieUsageMsg(array('missingparam', 'token'));
54 if(!$wgUser->matchEditToken($params['token']))
55 $this->dieUsageMsg(array('sessionfailure'));
57 $fromTitle = Title::newFromText($params['from']);
58 if(!$fromTitle)
59 $this->dieUsageMsg(array('invalidtitle', $params['from']));
60 if(!$fromTitle->exists())
61 $this->dieUsageMsg(array('notanarticle'));
62 $fromTalk = $fromTitle->getTalkPage();
64 $toTitle = Title::newFromText($params['to']);
65 if(!$toTitle)
66 $this->dieUsageMsg(array('invalidtitle', $params['to']));
67 $toTalk = $toTitle->getTalkPage();
69 $hookErr = null;
70 $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
71 if($retval !== true)
72 $this->dieUsageMsg(reset($retval));
74 $r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']);
75 if(!$params['noredirect'] || !$wgUser->isAllowed('suppressredirect'))
76 $r['redirectcreated'] = '';
78 if($params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage())
80 // We need to move the talk page as well
81 $toTalk = $toTitle->getTalkPage();
82 $retval = $fromTalk->moveTo($toTalk, true, $params['reason'], !$params['noredirect']);
83 if($retval === true)
85 $r['talkfrom'] = $fromTalk->getPrefixedText();
86 $r['talkto'] = $toTalk->getPrefixedText();
88 // We're not gonna dieUsage() on failure, since we already changed something
89 else
91 $r['talkmove-error-code'] = ApiBase::$messageMap[reset($retval)]['code'];
92 $r['talkmove-error-info'] = ApiBase::$messageMap[reset($retval)]['info'];
96 # Watch pages
97 if($params['watch'] || $wgUser->getOption('watchmoves'))
99 $wgUser->addWatch($fromTitle);
100 $wgUser->addWatch($toTitle);
102 else if($params['unwatch'])
104 $wgUser->removeWatch($fromTitle);
105 $wgUser->removeWatch($toTitle);
107 $this->getResult()->addValue(null, $this->getModuleName(), $r);
110 public function mustBePosted() { return true; }
112 public function getAllowedParams() {
113 return array (
114 'from' => null,
115 'to' => null,
116 'token' => null,
117 'reason' => null,
118 'movetalk' => false,
119 'noredirect' => false,
120 'watch' => false,
121 'unwatch' => false
125 public function getParamDescription() {
126 return array (
127 'from' => 'Title of the page you want to move.',
128 'to' => 'Title you want to rename the page to.',
129 'token' => 'A move token previously retrieved through prop=info',
130 'reason' => 'Reason for the move (optional).',
131 'movetalk' => 'Move the talk page, if it exists.',
132 'noredirect' => 'Don\'t create a redirect',
133 'watch' => 'Add the page and the redirect to your watchlist',
134 'unwatch' => 'Remove the page and the redirect from your watchlist'
138 public function getDescription() {
139 return array(
140 'Move a page.'
144 protected function getExamples() {
145 return array (
146 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect'
150 public function getVersion() {
151 return __CLASS__ . ': $Id$';