<?php
-
/**
+ *
+ *
* Created on Oct 31, 2007
- * API for MediaWiki 1.8+
*
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
*
* 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
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( "ApiBase.php" );
-}
-
/**
* API Module to move pages
* @ingroup API
}
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
- if ( is_null( $params['reason'] ) ) {
- $params['reason'] = '';
- }
$this->requireOnlyOneParameter( $params, 'from', 'fromid' );
- if ( !isset( $params['to'] ) ) {
- $this->dieUsageMsg( array( 'missingparam', 'to' ) );
- }
if ( isset( $params['from'] ) ) {
$fromTitle = Title::newFromText( $params['from'] );
}
if ( !$fromTitle->exists() ) {
- $this->dieUsageMsg( array( 'notanarticle' ) );
+ $this->dieUsageMsg( 'notanarticle' );
}
$fromTalk = $fromTitle->getTalkPage();
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
&& wfFindFile( $toTitle ) )
{
- if ( !$params['ignorewarnings'] && $wgUser->isAllowed( 'reupload-shared' ) ) {
- $this->dieUsageMsg( array( 'sharedfile-exists' ) );
- } elseif ( !$wgUser->isAllowed( 'reupload-shared' ) ) {
- $this->dieUsageMsg( array( 'cantoverwrite-sharedfile' ) );
+ if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) {
+ $this->dieUsageMsg( 'sharedfile-exists' );
+ } elseif ( !$user->isAllowed( 'reupload-shared' ) ) {
+ $this->dieUsageMsg( 'cantoverwrite-sharedfile' );
}
}
// Move the page
- $hookErr = null;
$retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
if ( $retval !== true ) {
$this->dieUsageMsg( reset( $retval ) );
}
$r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
- if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) )
- {
+ if ( !$params['noredirect'] || !$user->isAllowed( 'suppressredirect' ) ) {
$r['redirectcreated'] = '';
}
// Move the talk page
- if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() )
- {
+ if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
$retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
if ( $retval === true ) {
$r['talkfrom'] = $fromTalk->getPrefixedText();
}
}
+ $result = $this->getResult();
+
// Move subpages
if ( $params['movesubpages'] ) {
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
$params['reason'], $params['noredirect'] );
- $this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
+ $result->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' );
+ $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
}
}
$this->setWatch( $watch, $fromTitle, 'watchmoves' );
$this->setWatch( $watch, $toTitle, 'watchmoves' );
- $this->getResult()->addValue( null, $this->getModuleName(), $r );
+ $result->addValue( null, $this->getModuleName(), $r );
}
+ /**
+ * @param Title $fromTitle
+ * @param Title $toTitle
+ * @param $reason
+ * @param $noredirect
+ * @return array
+ */
public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) {
$retval = array();
$success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
'fromid' => array(
ApiBase::PARAM_TYPE => 'integer'
),
- 'to' => null,
- 'token' => null,
- 'reason' => null,
+ 'to' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'token' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ ),
+ 'reason' => '',
'movetalk' => false,
'movesubpages' => false,
'noredirect' => false,
'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',
'token' => 'A move token previously retrieved through prop=info',
- 'reason' => 'Reason for the move (optional)',
+ 'reason' => 'Reason for the move',
'movetalk' => 'Move the talk page, if it exists',
'movesubpages' => 'Move subpages, if applicable',
'noredirect' => 'Don\'t create a redirect',
);
}
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'from' => 'string',
+ 'to' => 'string',
+ 'reason' => 'string',
+ 'redirectcreated' => 'boolean',
+ 'talkfrom' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'talkto' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'talkmove-error-code' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ ),
+ 'talkmove-error-info' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ )
+ );
+ }
+
public function getDescription() {
return 'Move a page';
}
public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'missingparam', 'to' ),
- array( 'invalidtitle', 'from' ),
- array( 'nosuchpageid', 'fromid' ),
- array( 'notanarticle' ),
- array( 'invalidtitle', 'to' ),
- array( 'sharedfile-exists' ),
- ) );
+ return array_merge( parent::getPossibleErrors(),
+ $this->getRequireOnlyOneParameterErrorMessages( array( 'from', 'fromid' ) ),
+ array(
+ array( 'invalidtitle', 'from' ),
+ array( 'nosuchpageid', 'fromid' ),
+ array( 'notanarticle' ),
+ array( 'invalidtitle', 'to' ),
+ array( 'sharedfile-exists' ),
+ )
+ );
+ }
+
+ public function needsToken() {
+ return true;
}
public function getTokenSalt() {
return '';
}
- protected function getExamples() {
+ public function getExamples() {
return array(
- 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect'
+ 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk=&noredirect='
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Move';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}