Index: trunk/phase3/includes/api/ApiMove.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Oct 31, 2007 |
6 | 6 | * API for MediaWiki 1.8+ |
7 | 7 | * |
8 | | - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 8 | + * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
9 | 9 | * |
10 | 10 | * This program is free software; you can redistribute it and/or modify |
11 | 11 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -24,49 +24,51 @@ |
25 | 25 | |
26 | 26 | if ( !defined( 'MEDIAWIKI' ) ) { |
27 | 27 | // Eclipse helper - will be ignored in production |
28 | | - require_once ( "ApiBase.php" ); |
| 28 | + require_once( "ApiBase.php" ); |
29 | 29 | } |
30 | 30 | |
31 | | - |
32 | 31 | /** |
33 | 32 | * @ingroup API |
34 | 33 | */ |
35 | 34 | class ApiMove extends ApiBase { |
36 | 35 | |
37 | 36 | public function __construct( $main, $action ) { |
38 | | - parent :: __construct( $main, $action ); |
| 37 | + parent::__construct( $main, $action ); |
39 | 38 | } |
40 | 39 | |
41 | 40 | public function execute() { |
42 | 41 | global $wgUser; |
43 | 42 | $params = $this->extractRequestParams(); |
44 | | - if ( is_null( $params['reason'] ) ) |
| 43 | + if ( is_null( $params['reason'] ) ) { |
45 | 44 | $params['reason'] = ''; |
| 45 | + } |
46 | 46 | |
47 | 47 | $this->requireOnlyOneParameter( $params, 'from', 'fromid' ); |
48 | | - if ( !isset( $params['to'] ) ) |
| 48 | + if ( !isset( $params['to'] ) ) { |
49 | 49 | $this->dieUsageMsg( array( 'missingparam', 'to' ) ); |
| 50 | + } |
50 | 51 | |
51 | | - if ( isset( $params['from'] ) ) |
52 | | - { |
| 52 | + if ( isset( $params['from'] ) ) { |
53 | 53 | $fromTitle = Title::newFromText( $params['from'] ); |
54 | | - if ( !$fromTitle ) |
| 54 | + if ( !$fromTitle ) { |
55 | 55 | $this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) ); |
56 | | - } |
57 | | - else if ( isset( $params['fromid'] ) ) |
58 | | - { |
| 56 | + } |
| 57 | + } elseif ( isset( $params['fromid'] ) ) { |
59 | 58 | $fromTitle = Title::newFromID( $params['fromid'] ); |
60 | | - if ( !$fromTitle ) |
| 59 | + if ( !$fromTitle ) { |
61 | 60 | $this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) ); |
| 61 | + } |
62 | 62 | } |
63 | 63 | |
64 | | - if ( !$fromTitle->exists() ) |
| 64 | + if ( !$fromTitle->exists() ) { |
65 | 65 | $this->dieUsageMsg( array( 'notanarticle' ) ); |
| 66 | + } |
66 | 67 | $fromTalk = $fromTitle->getTalkPage(); |
67 | 68 | |
68 | 69 | $toTitle = Title::newFromText( $params['to'] ); |
69 | | - if ( !$toTitle ) |
| 70 | + if ( !$toTitle ) { |
70 | 71 | $this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) ); |
| 72 | + } |
71 | 73 | $toTalk = $toTitle->getTalkPage(); |
72 | 74 | |
73 | 75 | if ( $toTitle->getNamespace() == NS_FILE |
— | — | @@ -83,25 +85,25 @@ |
84 | 86 | // Move the page |
85 | 87 | $hookErr = null; |
86 | 88 | $retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] ); |
87 | | - if ( $retval !== true ) |
| 89 | + if ( $retval !== true ) { |
88 | 90 | $this->dieUsageMsg( reset( $retval ) ); |
| 91 | + } |
89 | 92 | |
90 | 93 | $r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] ); |
91 | 94 | if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) ) |
| 95 | + { |
92 | 96 | $r['redirectcreated'] = ''; |
| 97 | + } |
93 | 98 | |
94 | 99 | // Move the talk page |
95 | 100 | if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) |
96 | 101 | { |
97 | 102 | $retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] ); |
98 | | - if ( $retval === true ) |
99 | | - { |
| 103 | + if ( $retval === true ) { |
100 | 104 | $r['talkfrom'] = $fromTalk->getPrefixedText(); |
101 | 105 | $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 |
106 | 108 | $parsed = $this->parseMsg( reset( $retval ) ); |
107 | 109 | $r['talkmove-error-code'] = $parsed['code']; |
108 | 110 | $r['talkmove-error-info'] = $parsed['info']; |
— | — | @@ -109,13 +111,11 @@ |
110 | 112 | } |
111 | 113 | |
112 | 114 | // Move subpages |
113 | | - if ( $params['movesubpages'] ) |
114 | | - { |
| 115 | + if ( $params['movesubpages'] ) { |
115 | 116 | $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle, |
116 | 117 | $params['reason'], $params['noredirect'] ); |
117 | 118 | $this->getResult()->setIndexedTagName( $r['subpages'], 'subpage' ); |
118 | | - if ( $params['movetalk'] ) |
119 | | - { |
| 119 | + if ( $params['movetalk'] ) { |
120 | 120 | $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk, |
121 | 121 | $params['reason'], $params['noredirect'] ); |
122 | 122 | $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' ); |
— | — | @@ -123,37 +123,32 @@ |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Watch pages |
127 | | - if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) |
128 | | - { |
| 127 | + if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) { |
129 | 128 | $wgUser->addWatch( $fromTitle ); |
130 | 129 | $wgUser->addWatch( $toTitle ); |
131 | | - } |
132 | | - else if ( $params['unwatch'] ) |
133 | | - { |
| 130 | + } elseif ( $params['unwatch'] ) { |
134 | 131 | $wgUser->removeWatch( $fromTitle ); |
135 | 132 | $wgUser->removeWatch( $toTitle ); |
136 | 133 | } |
137 | 134 | $this->getResult()->addValue( null, $this->getModuleName(), $r ); |
138 | 135 | } |
139 | 136 | |
140 | | - public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) |
141 | | - { |
| 137 | + public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) { |
142 | 138 | $retval = array(); |
143 | 139 | $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect ); |
144 | | - if ( isset( $success[0] ) ) |
| 140 | + if ( isset( $success[0] ) ) { |
145 | 141 | return array( 'error' => $this->parseMsg( $success ) ); |
146 | | - else |
147 | | - { |
| 142 | + } else { |
148 | 143 | // At least some pages could be moved |
149 | 144 | // Report each of them separately |
150 | | - foreach ( $success as $oldTitle => $newTitle ) |
151 | | - { |
| 145 | + foreach ( $success as $oldTitle => $newTitle ) { |
152 | 146 | $r = array( 'from' => $oldTitle ); |
153 | | - if ( is_array( $newTitle ) ) |
| 147 | + if ( is_array( $newTitle ) ) { |
154 | 148 | $r['error'] = $this->parseMsg( reset( $newTitle ) ); |
155 | | - else |
| 149 | + } else { |
156 | 150 | // Success |
157 | 151 | $r['to'] = $newTitle; |
| 152 | + } |
158 | 153 | $retval[] = $r; |
159 | 154 | } |
160 | 155 | } |
— | — | @@ -169,7 +164,7 @@ |
170 | 165 | } |
171 | 166 | |
172 | 167 | public function getAllowedParams() { |
173 | | - return array ( |
| 168 | + return array( |
174 | 169 | 'from' => null, |
175 | 170 | 'fromid' => array( |
176 | 171 | ApiBase::PARAM_TYPE => 'integer' |
— | — | @@ -187,7 +182,7 @@ |
188 | 183 | } |
189 | 184 | |
190 | 185 | public function getParamDescription() { |
191 | | - return array ( |
| 186 | + return array( |
192 | 187 | 'from' => 'Title of the page you want to move. Cannot be used together with fromid.', |
193 | 188 | 'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.', |
194 | 189 | 'to' => 'Title you want to rename the page to.', |
— | — | @@ -207,7 +202,7 @@ |
208 | 203 | 'Move a page.' |
209 | 204 | ); |
210 | 205 | } |
211 | | - |
| 206 | + |
212 | 207 | public function getPossibleErrors() { |
213 | 208 | return array_merge( parent::getPossibleErrors(), array( |
214 | 209 | array( 'missingparam', 'to' ), |
— | — | @@ -224,7 +219,7 @@ |
225 | 220 | } |
226 | 221 | |
227 | 222 | protected function getExamples() { |
228 | | - return array ( |
| 223 | + return array( |
229 | 224 | 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect' |
230 | 225 | ); |
231 | 226 | } |