ApiMove.php: fix copyright symbol, spacing & coding style tweaks, more braces
This commit is contained in:
parent
534c142450
commit
a675c23a11
1 changed files with 40 additions and 45 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Created on Oct 31, 2007
|
* Created on Oct 31, 2007
|
||||||
* API for MediaWiki 1.8+
|
* API for MediaWiki 1.8+
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
* Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -24,49 +24,51 @@
|
||||||
|
|
||||||
if ( !defined( 'MEDIAWIKI' ) ) {
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
||||||
// Eclipse helper - will be ignored in production
|
// Eclipse helper - will be ignored in production
|
||||||
require_once ( "ApiBase.php" );
|
require_once( "ApiBase.php" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup API
|
* @ingroup API
|
||||||
*/
|
*/
|
||||||
class ApiMove extends ApiBase {
|
class ApiMove extends ApiBase {
|
||||||
|
|
||||||
public function __construct( $main, $action ) {
|
public function __construct( $main, $action ) {
|
||||||
parent :: __construct( $main, $action );
|
parent::__construct( $main, $action );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
global $wgUser;
|
global $wgUser;
|
||||||
$params = $this->extractRequestParams();
|
$params = $this->extractRequestParams();
|
||||||
if ( is_null( $params['reason'] ) )
|
if ( is_null( $params['reason'] ) ) {
|
||||||
$params['reason'] = '';
|
$params['reason'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$this->requireOnlyOneParameter( $params, 'from', 'fromid' );
|
$this->requireOnlyOneParameter( $params, 'from', 'fromid' );
|
||||||
if ( !isset( $params['to'] ) )
|
if ( !isset( $params['to'] ) ) {
|
||||||
$this->dieUsageMsg( array( 'missingparam', 'to' ) );
|
$this->dieUsageMsg( array( 'missingparam', 'to' ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $params['from'] ) )
|
if ( isset( $params['from'] ) ) {
|
||||||
{
|
|
||||||
$fromTitle = Title::newFromText( $params['from'] );
|
$fromTitle = Title::newFromText( $params['from'] );
|
||||||
if ( !$fromTitle )
|
if ( !$fromTitle ) {
|
||||||
$this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
|
$this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
|
||||||
}
|
}
|
||||||
else if ( isset( $params['fromid'] ) )
|
} elseif ( isset( $params['fromid'] ) ) {
|
||||||
{
|
|
||||||
$fromTitle = Title::newFromID( $params['fromid'] );
|
$fromTitle = Title::newFromID( $params['fromid'] );
|
||||||
if ( !$fromTitle )
|
if ( !$fromTitle ) {
|
||||||
$this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
|
$this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$fromTitle->exists() )
|
if ( !$fromTitle->exists() ) {
|
||||||
$this->dieUsageMsg( array( 'notanarticle' ) );
|
$this->dieUsageMsg( array( 'notanarticle' ) );
|
||||||
|
}
|
||||||
$fromTalk = $fromTitle->getTalkPage();
|
$fromTalk = $fromTitle->getTalkPage();
|
||||||
|
|
||||||
$toTitle = Title::newFromText( $params['to'] );
|
$toTitle = Title::newFromText( $params['to'] );
|
||||||
if ( !$toTitle )
|
if ( !$toTitle ) {
|
||||||
$this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
|
$this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
|
||||||
|
}
|
||||||
$toTalk = $toTitle->getTalkPage();
|
$toTalk = $toTitle->getTalkPage();
|
||||||
|
|
||||||
if ( $toTitle->getNamespace() == NS_FILE
|
if ( $toTitle->getNamespace() == NS_FILE
|
||||||
|
|
@ -83,25 +85,25 @@ class ApiMove extends ApiBase {
|
||||||
// Move the page
|
// Move the page
|
||||||
$hookErr = null;
|
$hookErr = null;
|
||||||
$retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
|
$retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
|
||||||
if ( $retval !== true )
|
if ( $retval !== true ) {
|
||||||
$this->dieUsageMsg( reset( $retval ) );
|
$this->dieUsageMsg( reset( $retval ) );
|
||||||
|
}
|
||||||
|
|
||||||
$r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
|
$r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
|
||||||
if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) )
|
if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) )
|
||||||
|
{
|
||||||
$r['redirectcreated'] = '';
|
$r['redirectcreated'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
// Move the talk page
|
// 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'] );
|
$retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
|
||||||
if ( $retval === true )
|
if ( $retval === true ) {
|
||||||
{
|
|
||||||
$r['talkfrom'] = $fromTalk->getPrefixedText();
|
$r['talkfrom'] = $fromTalk->getPrefixedText();
|
||||||
$r['talkto'] = $toTalk->getPrefixedText();
|
$r['talkto'] = $toTalk->getPrefixedText();
|
||||||
}
|
} else {
|
||||||
// We're not gonna dieUsage() on failure, since we already changed something
|
// We're not gonna dieUsage() on failure, since we already changed something
|
||||||
else
|
|
||||||
{
|
|
||||||
$parsed = $this->parseMsg( reset( $retval ) );
|
$parsed = $this->parseMsg( reset( $retval ) );
|
||||||
$r['talkmove-error-code'] = $parsed['code'];
|
$r['talkmove-error-code'] = $parsed['code'];
|
||||||
$r['talkmove-error-info'] = $parsed['info'];
|
$r['talkmove-error-info'] = $parsed['info'];
|
||||||
|
|
@ -109,13 +111,11 @@ class ApiMove extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move subpages
|
// Move subpages
|
||||||
if ( $params['movesubpages'] )
|
if ( $params['movesubpages'] ) {
|
||||||
{
|
|
||||||
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
|
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
|
||||||
$params['reason'], $params['noredirect'] );
|
$params['reason'], $params['noredirect'] );
|
||||||
$this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
|
$this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
|
||||||
if ( $params['movetalk'] )
|
if ( $params['movetalk'] ) {
|
||||||
{
|
|
||||||
$r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
|
$r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
|
||||||
$params['reason'], $params['noredirect'] );
|
$params['reason'], $params['noredirect'] );
|
||||||
$this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
|
$this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
|
||||||
|
|
@ -123,37 +123,32 @@ class ApiMove extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch pages
|
// Watch pages
|
||||||
if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) )
|
if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) {
|
||||||
{
|
|
||||||
$wgUser->addWatch( $fromTitle );
|
$wgUser->addWatch( $fromTitle );
|
||||||
$wgUser->addWatch( $toTitle );
|
$wgUser->addWatch( $toTitle );
|
||||||
}
|
} elseif ( $params['unwatch'] ) {
|
||||||
else if ( $params['unwatch'] )
|
|
||||||
{
|
|
||||||
$wgUser->removeWatch( $fromTitle );
|
$wgUser->removeWatch( $fromTitle );
|
||||||
$wgUser->removeWatch( $toTitle );
|
$wgUser->removeWatch( $toTitle );
|
||||||
}
|
}
|
||||||
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
$this->getResult()->addValue( null, $this->getModuleName(), $r );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect )
|
public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) {
|
||||||
{
|
|
||||||
$retval = array();
|
$retval = array();
|
||||||
$success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
|
$success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
|
||||||
if ( isset( $success[0] ) )
|
if ( isset( $success[0] ) ) {
|
||||||
return array( 'error' => $this->parseMsg( $success ) );
|
return array( 'error' => $this->parseMsg( $success ) );
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
// At least some pages could be moved
|
// At least some pages could be moved
|
||||||
// Report each of them separately
|
// Report each of them separately
|
||||||
foreach ( $success as $oldTitle => $newTitle )
|
foreach ( $success as $oldTitle => $newTitle ) {
|
||||||
{
|
|
||||||
$r = array( 'from' => $oldTitle );
|
$r = array( 'from' => $oldTitle );
|
||||||
if ( is_array( $newTitle ) )
|
if ( is_array( $newTitle ) ) {
|
||||||
$r['error'] = $this->parseMsg( reset( $newTitle ) );
|
$r['error'] = $this->parseMsg( reset( $newTitle ) );
|
||||||
else
|
} else {
|
||||||
// Success
|
// Success
|
||||||
$r['to'] = $newTitle;
|
$r['to'] = $newTitle;
|
||||||
|
}
|
||||||
$retval[] = $r;
|
$retval[] = $r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +164,7 @@ class ApiMove extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllowedParams() {
|
public function getAllowedParams() {
|
||||||
return array (
|
return array(
|
||||||
'from' => null,
|
'from' => null,
|
||||||
'fromid' => array(
|
'fromid' => array(
|
||||||
ApiBase::PARAM_TYPE => 'integer'
|
ApiBase::PARAM_TYPE => 'integer'
|
||||||
|
|
@ -187,7 +182,7 @@ class ApiMove extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParamDescription() {
|
public function getParamDescription() {
|
||||||
return array (
|
return array(
|
||||||
'from' => 'Title of the page you want to move. Cannot be used together with fromid.',
|
'from' => 'Title of the page you want to move. Cannot be used together with fromid.',
|
||||||
'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.',
|
'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.',
|
||||||
'to' => 'Title you want to rename the page to.',
|
'to' => 'Title you want to rename the page to.',
|
||||||
|
|
@ -207,7 +202,7 @@ class ApiMove extends ApiBase {
|
||||||
'Move a page.'
|
'Move a page.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPossibleErrors() {
|
public function getPossibleErrors() {
|
||||||
return array_merge( parent::getPossibleErrors(), array(
|
return array_merge( parent::getPossibleErrors(), array(
|
||||||
array( 'missingparam', 'to' ),
|
array( 'missingparam', 'to' ),
|
||||||
|
|
@ -224,7 +219,7 @@ class ApiMove extends ApiBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExamples() {
|
protected function getExamples() {
|
||||||
return array (
|
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'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue