summaryrefslogtreecommitdiff
path: root/includes/api/ApiMove.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiMove.php')
-rw-r--r--includes/api/ApiMove.php51
1 files changed, 47 insertions, 4 deletions
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index 13b058c9..e22d0294 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -39,7 +39,6 @@ class ApiMove extends ApiBase {
public function execute() {
global $wgUser;
- $this->getMain()->requestWriteMode();
$params = $this->extractRequestParams();
if(is_null($params['reason']))
$params['reason'] = '';
@@ -73,6 +72,7 @@ class ApiMove extends ApiBase {
$this->dieUsageMsg(array('invalidtitle', $params['to']));
$toTalk = $toTitle->getTalkPage();
+ # Move the page
$hookErr = null;
$retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
if($retval !== true)
@@ -82,10 +82,9 @@ class ApiMove extends ApiBase {
if(!$params['noredirect'] || !$wgUser->isAllowed('suppressredirect'))
$r['redirectcreated'] = '';
+ # Move the talk page
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)
{
@@ -101,6 +100,20 @@ class ApiMove extends ApiBase {
}
}
+ # Move subpages
+ if($params['movesubpages'])
+ {
+ $r['subpages'] = $this->moveSubpages($fromTitle, $toTitle,
+ $params['reason'], $params['noredirect']);
+ $this->getResult()->setIndexedTagName($r['subpages'], 'subpage');
+ if($params['movetalk'])
+ {
+ $r['subpages-talk'] = $this->moveSubpages($fromTalk, $toTalk,
+ $params['reason'], $params['noredirect']);
+ $this->getResult()->setIndexedTagName($r['subpages-talk'], 'subpage');
+ }
+ }
+
# Watch pages
if($params['watch'] || $wgUser->getOption('watchmoves'))
{
@@ -114,9 +127,37 @@ class ApiMove extends ApiBase {
}
$this->getResult()->addValue(null, $this->getModuleName(), $r);
}
+
+ public function moveSubpages($fromTitle, $toTitle, $reason, $noredirect)
+ {
+ $retval = array();
+ $success = $fromTitle->moveSubpages($toTitle, true, $reason, !$noredirect);
+ if(isset($success[0]))
+ return array('error' => $this->parseMsg($success));
+ else
+ {
+ // At least some pages could be moved
+ // Report each of them separately
+ foreach($success as $oldTitle => $newTitle)
+ {
+ $r = array('from' => $oldTitle);
+ if(is_array($newTitle))
+ $r['error'] = $this->parseMsg(reset($newTitle));
+ else
+ // Success
+ $r['to'] = $newTitle;
+ $retval[] = $r;
+ }
+ }
+ return $retval;
+ }
public function mustBePosted() { return true; }
+ public function isWriteMode() {
+ return true;
+ }
+
public function getAllowedParams() {
return array (
'from' => null,
@@ -127,6 +168,7 @@ class ApiMove extends ApiBase {
'token' => null,
'reason' => null,
'movetalk' => false,
+ 'movesubpages' => false,
'noredirect' => false,
'watch' => false,
'unwatch' => false
@@ -141,6 +183,7 @@ class ApiMove extends ApiBase {
'token' => 'A move token previously retrieved through prop=info',
'reason' => 'Reason for the move (optional).',
'movetalk' => 'Move the talk page, if it exists.',
+ 'movesubpages' => 'Move subpages, if applicable',
'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'
@@ -160,6 +203,6 @@ class ApiMove extends ApiBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiMove.php 47041 2009-02-09 14:39:41Z catrope $';
+ return __CLASS__ . ': $Id: ApiMove.php 48091 2009-03-06 13:49:44Z catrope $';
}
}