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.php97
1 files changed, 48 insertions, 49 deletions
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index 04e931d2..e42958bf 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -72,9 +72,9 @@ class ApiMove extends ApiBase {
// Move the page
$toTitleExists = $toTitle->exists();
- $retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
- if ( $retval !== true ) {
- $this->dieUsageMsg( reset( $retval ) );
+ $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'] );
+ if ( !$status->isOK() ) {
+ $this->dieStatus( $status );
}
$r = array(
@@ -83,34 +83,28 @@ class ApiMove extends ApiBase {
'reason' => $params['reason']
);
- if ( $fromTitle->exists() ) {
- //NOTE: we assume that if the old title exists, it's because it was re-created as
- // a redirect to the new title. This is not safe, but what we did before was
- // even worse: we just determined whether a redirect should have been created,
- // and reported that it was created if it should have, without any checks.
- // Also note that isRedirect() is unreliable because of bug 37209.
- $r['redirectcreated'] = '';
- }
+ //NOTE: we assume that if the old title exists, it's because it was re-created as
+ // a redirect to the new title. This is not safe, but what we did before was
+ // even worse: we just determined whether a redirect should have been created,
+ // and reported that it was created if it should have, without any checks.
+ // Also note that isRedirect() is unreliable because of bug 37209.
+ $r['redirectcreated'] = $fromTitle->exists();
- if ( $toTitleExists ) {
- $r['moveoverredirect'] = '';
- }
+ $r['moveoverredirect'] = $toTitleExists;
// Move the talk page
if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
$toTalkExists = $toTalk->exists();
- $retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
- if ( $retval === true ) {
+ $status = $this->movePage( $fromTalk, $toTalk, $params['reason'], !$params['noredirect'] );
+ if ( $status->isOK() ) {
$r['talkfrom'] = $fromTalk->getPrefixedText();
$r['talkto'] = $toTalk->getPrefixedText();
- if ( $toTalkExists ) {
- $r['talkmoveoverredirect'] = '';
- }
+ $r['talkmoveoverredirect'] = $toTalkExists;
} else {
// We're not gonna dieUsage() on failure, since we already changed something
- $parsed = $this->parseMsg( reset( $retval ) );
- $r['talkmove-error-code'] = $parsed['code'];
- $r['talkmove-error-info'] = $parsed['info'];
+ $error = $this->getErrorFromStatus( $status );
+ $r['talkmove-error-code'] = $error[0];
+ $r['talkmove-error-info'] = $error[1];
}
}
@@ -120,12 +114,12 @@ class ApiMove extends ApiBase {
if ( $params['movesubpages'] ) {
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
$params['reason'], $params['noredirect'] );
- $result->setIndexedTagName( $r['subpages'], 'subpage' );
+ ApiResult::setIndexedTagName( $r['subpages'], 'subpage' );
if ( $params['movetalk'] ) {
$r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
$params['reason'], $params['noredirect'] );
- $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
+ ApiResult::setIndexedTagName( $r['subpages-talk'], 'subpage' );
}
}
@@ -148,6 +142,33 @@ class ApiMove extends ApiBase {
}
/**
+ * @param Title $from
+ * @param Title $to
+ * @param string $reason
+ * @param bool $createRedirect
+ * @return Status
+ */
+ protected function movePage( Title $from, Title $to, $reason, $createRedirect ) {
+ $mp = new MovePage( $from, $to );
+ $valid = $mp->isValidMove();
+ if ( !$valid->isOK() ) {
+ return $valid;
+ }
+
+ $permStatus = $mp->checkPermissions( $this->getUser(), $reason );
+ if ( !$permStatus->isOK() ) {
+ return $permStatus;
+ }
+
+ // Check suppressredirect permission
+ if ( !$this->getUser()->isAllowed( 'suppressredirect' ) ) {
+ $createRedirect = true;
+ }
+
+ return $mp->move( $this->getUser(), $reason, $createRedirect );
+ }
+
+ /**
* @param Title $fromTitle
* @param Title $toTitle
* @param string $reason
@@ -220,37 +241,15 @@ class ApiMove extends ApiBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'from' => "Title of the page you want to move. Cannot be used together with {$p}fromid",
- 'fromid' => "Page ID of the page you want to move. Cannot be used together with {$p}from",
- 'to' => 'Title you want to rename the page to',
- 'reason' => 'Reason for the move',
- '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',
- 'watchlist' => 'Unconditionally add or remove the page from your ' .
- 'watchlist, use preferences or do not change watch',
- 'ignorewarnings' => 'Ignore any warnings'
- );
- }
-
- public function getDescription() {
- return 'Move a page.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
+ 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
'reason=Misspelled%20title&movetalk=&noredirect='
+ => 'apihelp-move-example-move',
);
}