r62826 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62825‎ | r62826 | r62827 >
Date:12:25, 22 February 2010
Author:ashley
Status:ok
Tags:
Comment:
ApiMove.php: fix copyright symbol, spacing & coding style tweaks, more braces
Modified paths:
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMove.php
@@ -1,10 +1,10 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Oct 31, 2007
66 * API for MediaWiki 1.8+
77 *
8 - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
 8+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
99 *
1010 * This program is free software; you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License as published by
@@ -24,49 +24,51 @@
2525
2626 if ( !defined( 'MEDIAWIKI' ) ) {
2727 // Eclipse helper - will be ignored in production
28 - require_once ( "ApiBase.php" );
 28+ require_once( "ApiBase.php" );
2929 }
3030
31 -
3231 /**
3332 * @ingroup API
3433 */
3534 class ApiMove extends ApiBase {
3635
3736 public function __construct( $main, $action ) {
38 - parent :: __construct( $main, $action );
 37+ parent::__construct( $main, $action );
3938 }
4039
4140 public function execute() {
4241 global $wgUser;
4342 $params = $this->extractRequestParams();
44 - if ( is_null( $params['reason'] ) )
 43+ if ( is_null( $params['reason'] ) ) {
4544 $params['reason'] = '';
 45+ }
4646
4747 $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
48 - if ( !isset( $params['to'] ) )
 48+ if ( !isset( $params['to'] ) ) {
4949 $this->dieUsageMsg( array( 'missingparam', 'to' ) );
 50+ }
5051
51 - if ( isset( $params['from'] ) )
52 - {
 52+ if ( isset( $params['from'] ) ) {
5353 $fromTitle = Title::newFromText( $params['from'] );
54 - if ( !$fromTitle )
 54+ if ( !$fromTitle ) {
5555 $this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
56 - }
57 - else if ( isset( $params['fromid'] ) )
58 - {
 56+ }
 57+ } elseif ( isset( $params['fromid'] ) ) {
5958 $fromTitle = Title::newFromID( $params['fromid'] );
60 - if ( !$fromTitle )
 59+ if ( !$fromTitle ) {
6160 $this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
 61+ }
6262 }
6363
64 - if ( !$fromTitle->exists() )
 64+ if ( !$fromTitle->exists() ) {
6565 $this->dieUsageMsg( array( 'notanarticle' ) );
 66+ }
6667 $fromTalk = $fromTitle->getTalkPage();
6768
6869 $toTitle = Title::newFromText( $params['to'] );
69 - if ( !$toTitle )
 70+ if ( !$toTitle ) {
7071 $this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
 72+ }
7173 $toTalk = $toTitle->getTalkPage();
7274
7375 if ( $toTitle->getNamespace() == NS_FILE
@@ -83,25 +85,25 @@
8486 // Move the page
8587 $hookErr = null;
8688 $retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
87 - if ( $retval !== true )
 89+ if ( $retval !== true ) {
8890 $this->dieUsageMsg( reset( $retval ) );
 91+ }
8992
9093 $r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
9194 if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) )
 95+ {
9296 $r['redirectcreated'] = '';
 97+ }
9398
9499 // Move the talk page
95100 if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() )
96101 {
97102 $retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
98 - if ( $retval === true )
99 - {
 103+ if ( $retval === true ) {
100104 $r['talkfrom'] = $fromTalk->getPrefixedText();
101105 $r['talkto'] = $toTalk->getPrefixedText();
102 - }
103 - // We're not gonna dieUsage() on failure, since we already changed something
104 - else
105 - {
 106+ } else {
 107+ // We're not gonna dieUsage() on failure, since we already changed something
106108 $parsed = $this->parseMsg( reset( $retval ) );
107109 $r['talkmove-error-code'] = $parsed['code'];
108110 $r['talkmove-error-info'] = $parsed['info'];
@@ -109,13 +111,11 @@
110112 }
111113
112114 // Move subpages
113 - if ( $params['movesubpages'] )
114 - {
 115+ if ( $params['movesubpages'] ) {
115116 $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
116117 $params['reason'], $params['noredirect'] );
117118 $this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' );
118 - if ( $params['movetalk'] )
119 - {
 119+ if ( $params['movetalk'] ) {
120120 $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
121121 $params['reason'], $params['noredirect'] );
122122 $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
@@ -123,37 +123,32 @@
124124 }
125125
126126 // Watch pages
127 - if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) )
128 - {
 127+ if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) {
129128 $wgUser->addWatch( $fromTitle );
130129 $wgUser->addWatch( $toTitle );
131 - }
132 - else if ( $params['unwatch'] )
133 - {
 130+ } elseif ( $params['unwatch'] ) {
134131 $wgUser->removeWatch( $fromTitle );
135132 $wgUser->removeWatch( $toTitle );
136133 }
137134 $this->getResult()->addValue( null, $this->getModuleName(), $r );
138135 }
139136
140 - public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect )
141 - {
 137+ public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) {
142138 $retval = array();
143139 $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
144 - if ( isset( $success[0] ) )
 140+ if ( isset( $success[0] ) ) {
145141 return array( 'error' => $this->parseMsg( $success ) );
146 - else
147 - {
 142+ } else {
148143 // At least some pages could be moved
149144 // Report each of them separately
150 - foreach ( $success as $oldTitle => $newTitle )
151 - {
 145+ foreach ( $success as $oldTitle => $newTitle ) {
152146 $r = array( 'from' => $oldTitle );
153 - if ( is_array( $newTitle ) )
 147+ if ( is_array( $newTitle ) ) {
154148 $r['error'] = $this->parseMsg( reset( $newTitle ) );
155 - else
 149+ } else {
156150 // Success
157151 $r['to'] = $newTitle;
 152+ }
158153 $retval[] = $r;
159154 }
160155 }
@@ -169,7 +164,7 @@
170165 }
171166
172167 public function getAllowedParams() {
173 - return array (
 168+ return array(
174169 'from' => null,
175170 'fromid' => array(
176171 ApiBase::PARAM_TYPE => 'integer'
@@ -187,7 +182,7 @@
188183 }
189184
190185 public function getParamDescription() {
191 - return array (
 186+ return array(
192187 'from' => 'Title of the page you want to move. Cannot be used together with fromid.',
193188 'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.',
194189 'to' => 'Title you want to rename the page to.',
@@ -207,7 +202,7 @@
208203 'Move a page.'
209204 );
210205 }
211 -
 206+
212207 public function getPossibleErrors() {
213208 return array_merge( parent::getPossibleErrors(), array(
214209 array( 'missingparam', 'to' ),
@@ -224,7 +219,7 @@
225220 }
226221
227222 protected function getExamples() {
228 - return array (
 223+ return array(
229224 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect'
230225 );
231226 }

Status & tagging log