Index: trunk/phase3/includes/api/ApiLogout.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Jan 4, 2008 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com, |
| 9 | + * Copyright © 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com, |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiBase.php' ); |
| 29 | + require_once( 'ApiBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -37,14 +37,14 @@ |
38 | 38 | class ApiLogout extends ApiBase { |
39 | 39 | |
40 | 40 | public function __construct( $main, $action ) { |
41 | | - parent :: __construct( $main, $action ); |
| 41 | + parent::__construct( $main, $action ); |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function execute() { |
45 | 45 | global $wgUser; |
46 | 46 | $oldName = $wgUser->getName(); |
47 | 47 | $wgUser->logout(); |
48 | | - |
| 48 | + |
49 | 49 | // Give extensions to do something after user logout |
50 | 50 | $injected_html = ''; |
51 | 51 | wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) ); |
— | — | @@ -55,15 +55,15 @@ |
56 | 56 | } |
57 | 57 | |
58 | 58 | public function getAllowedParams() { |
59 | | - return array (); |
| 59 | + return array(); |
60 | 60 | } |
61 | 61 | |
62 | 62 | public function getParamDescription() { |
63 | | - return array (); |
| 63 | + return array(); |
64 | 64 | } |
65 | 65 | |
66 | 66 | public function getDescription() { |
67 | | - return array ( |
| 67 | + return array( |
68 | 68 | 'This module is used to logout and clear session data' |
69 | 69 | ); |
70 | 70 | } |
Index: trunk/phase3/includes/api/ApiParse.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Dec 01, 2007 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( "ApiBase.php" ); |
| 29 | + require_once( "ApiBase.php" ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | class ApiParse extends ApiBase { |
36 | 36 | |
37 | 37 | public function __construct( $main, $action ) { |
38 | | - parent :: __construct( $main, $action ); |
| 38 | + parent::__construct( $main, $action ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function execute() { |
— | — | @@ -44,8 +44,9 @@ |
45 | 45 | $title = $params['title']; |
46 | 46 | $page = $params['page']; |
47 | 47 | $oldid = $params['oldid']; |
48 | | - if ( !is_null( $page ) && ( !is_null( $text ) || $title != "API" ) ) |
49 | | - $this->dieUsage( "The page parameter cannot be used together with the text and title parameters", 'params' ); |
| 48 | + if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) { |
| 49 | + $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' ); |
| 50 | + } |
50 | 51 | $prop = array_flip( $params['prop'] ); |
51 | 52 | $revid = false; |
52 | 53 | |
— | — | @@ -56,26 +57,23 @@ |
57 | 58 | $popts->setTidy( true ); |
58 | 59 | $popts->enableLimitReport(); |
59 | 60 | $redirValues = null; |
60 | | - if ( !is_null( $oldid ) || !is_null( $page ) ) |
61 | | - { |
62 | | - if ( !is_null( $oldid ) ) |
63 | | - { |
| 61 | + if ( !is_null( $oldid ) || !is_null( $page ) ) { |
| 62 | + if ( !is_null( $oldid ) ) { |
64 | 63 | // Don't use the parser cache |
65 | 64 | $rev = Revision::newFromID( $oldid ); |
66 | | - if ( !$rev ) |
| 65 | + if ( !$rev ) { |
67 | 66 | $this->dieUsage( "There is no revision ID $oldid", 'missingrev' ); |
68 | | - if ( !$rev->userCan( Revision::DELETED_TEXT ) ) |
| 67 | + } |
| 68 | + if ( !$rev->userCan( Revision::DELETED_TEXT ) ) { |
69 | 69 | $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' ); |
| 70 | + } |
70 | 71 | |
71 | 72 | $text = $rev->getText( Revision::FOR_THIS_USER ); |
72 | 73 | $titleObj = $rev->getTitle(); |
73 | 74 | $wgTitle = $titleObj; |
74 | 75 | $p_result = $wgParser->parse( $text, $titleObj, $popts ); |
75 | | - } |
76 | | - else |
77 | | - { |
78 | | - if ( $params['redirects'] ) |
79 | | - { |
| 76 | + } else { |
| 77 | + if ( $params['redirects'] ) { |
80 | 78 | $req = new FauxRequest( array( |
81 | 79 | 'action' => 'query', |
82 | 80 | 'redirects' => '', |
— | — | @@ -86,42 +84,45 @@ |
87 | 85 | $data = $main->getResultData(); |
88 | 86 | $redirValues = @$data['query']['redirects']; |
89 | 87 | $to = $page; |
90 | | - foreach ( (array)$redirValues as $r ) |
| 88 | + foreach ( (array)$redirValues as $r ) { |
91 | 89 | $to = $r['to']; |
| 90 | + } |
| 91 | + } else { |
| 92 | + $to = $page; |
92 | 93 | } |
93 | | - else |
94 | | - $to = $page; |
95 | 94 | $titleObj = Title::newFromText( $to ); |
96 | | - if ( !$titleObj ) |
| 95 | + if ( !$titleObj ) { |
97 | 96 | $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); |
| 97 | + } |
98 | 98 | |
99 | 99 | $articleObj = new Article( $titleObj ); |
100 | | - if ( isset( $prop['revid'] ) ) |
| 100 | + if ( isset( $prop['revid'] ) ) { |
101 | 101 | $oldid = $articleObj->getRevIdFetched(); |
| 102 | + } |
102 | 103 | // Try the parser cache first |
103 | 104 | $p_result = false; |
104 | 105 | $pcache = ParserCache::singleton(); |
105 | | - if ( $wgEnableParserCache ) |
| 106 | + if ( $wgEnableParserCache ) { |
106 | 107 | $p_result = $pcache->get( $articleObj, $wgUser ); |
107 | | - if ( !$p_result ) |
108 | | - { |
| 108 | + } |
| 109 | + if ( !$p_result ) { |
109 | 110 | $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts ); |
110 | | - |
111 | | - if ( $wgEnableParserCache ) |
| 111 | + |
| 112 | + if ( $wgEnableParserCache ) { |
112 | 113 | $pcache->save( $p_result, $articleObj, $popts ); |
| 114 | + } |
113 | 115 | } |
114 | 116 | } |
115 | | - } |
116 | | - else |
117 | | - { |
| 117 | + } else { |
118 | 118 | $titleObj = Title::newFromText( $title ); |
119 | | - if ( !$titleObj ) |
120 | | - $titleObj = Title::newFromText( "API" ); |
| 119 | + if ( !$titleObj ) { |
| 120 | + $titleObj = Title::newFromText( 'API' ); |
| 121 | + } |
121 | 122 | $wgTitle = $titleObj; |
122 | | - if ( $params['pst'] || $params['onlypst'] ) |
| 123 | + if ( $params['pst'] || $params['onlypst'] ) { |
123 | 124 | $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts ); |
124 | | - if ( $params['onlypst'] ) |
125 | | - { |
| 125 | + } |
| 126 | + if ( $params['onlypst'] ) { |
126 | 127 | // Build a result and bail out |
127 | 128 | $result_array['text'] = array(); |
128 | 129 | $this->getResult()->setContent( $result_array['text'], $text ); |
— | — | @@ -134,50 +135,61 @@ |
135 | 136 | // Return result |
136 | 137 | $result = $this->getResult(); |
137 | 138 | $result_array = array(); |
138 | | - if ( $params['redirects'] && !is_null( $redirValues ) ) |
| 139 | + if ( $params['redirects'] && !is_null( $redirValues ) ) { |
139 | 140 | $result_array['redirects'] = $redirValues; |
140 | | - |
| 141 | + } |
| 142 | + |
141 | 143 | if ( isset( $prop['text'] ) ) { |
142 | 144 | $result_array['text'] = array(); |
143 | 145 | $result->setContent( $result_array['text'], $p_result->getText() ); |
144 | 146 | } |
145 | | - |
| 147 | + |
146 | 148 | if ( !is_null( $params['summary'] ) ) { |
147 | 149 | $result_array['parsedsummary'] = array(); |
148 | 150 | $result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) ); |
149 | 151 | } |
150 | | - |
151 | | - if ( isset( $prop['langlinks'] ) ) |
| 152 | + |
| 153 | + if ( isset( $prop['langlinks'] ) ) { |
152 | 154 | $result_array['langlinks'] = $this->formatLangLinks( $p_result->getLanguageLinks() ); |
153 | | - if ( isset( $prop['categories'] ) ) |
| 155 | + } |
| 156 | + if ( isset( $prop['categories'] ) ) { |
154 | 157 | $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() ); |
155 | | - if ( isset( $prop['links'] ) ) |
| 158 | + } |
| 159 | + if ( isset( $prop['links'] ) ) { |
156 | 160 | $result_array['links'] = $this->formatLinks( $p_result->getLinks() ); |
157 | | - if ( isset( $prop['templates'] ) ) |
| 161 | + } |
| 162 | + if ( isset( $prop['templates'] ) ) { |
158 | 163 | $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() ); |
159 | | - if ( isset( $prop['images'] ) ) |
| 164 | + } |
| 165 | + if ( isset( $prop['images'] ) ) { |
160 | 166 | $result_array['images'] = array_keys( $p_result->getImages() ); |
161 | | - if ( isset( $prop['externallinks'] ) ) |
| 167 | + } |
| 168 | + if ( isset( $prop['externallinks'] ) ) { |
162 | 169 | $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() ); |
163 | | - if ( isset( $prop['sections'] ) ) |
| 170 | + } |
| 171 | + if ( isset( $prop['sections'] ) ) { |
164 | 172 | $result_array['sections'] = $p_result->getSections(); |
165 | | - if ( isset( $prop['displaytitle'] ) ) |
| 173 | + } |
| 174 | + if ( isset( $prop['displaytitle'] ) ) { |
166 | 175 | $result_array['displaytitle'] = $p_result->getDisplayTitle() ? |
167 | 176 | $p_result->getDisplayTitle() : |
168 | 177 | $titleObj->getPrefixedText(); |
169 | | - |
170 | | - if ( isset( $prop['headitems'] ) ) |
| 178 | + } |
| 179 | + |
| 180 | + if ( isset( $prop['headitems'] ) ) { |
171 | 181 | $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() ); |
172 | | - |
| 182 | + } |
| 183 | + |
173 | 184 | if ( isset( $prop['headhtml'] ) ) { |
174 | 185 | $out = new OutputPage; |
175 | 186 | $out->addParserOutputNoText( $p_result ); |
176 | 187 | $result_array['headhtml'] = array(); |
177 | 188 | $result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) ); |
178 | 189 | } |
179 | | - |
180 | | - if ( !is_null( $oldid ) ) |
| 190 | + |
| 191 | + if ( !is_null( $oldid ) ) { |
181 | 192 | $result_array['revid'] = intval( $oldid ); |
| 193 | + } |
182 | 194 | |
183 | 195 | $result_mapping = array( |
184 | 196 | 'redirects' => 'r', |
— | — | @@ -224,8 +236,9 @@ |
225 | 237 | $entry = array(); |
226 | 238 | $entry['ns'] = $ns; |
227 | 239 | $this->getResult()->setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() ); |
228 | | - if ( $id != 0 ) |
| 240 | + if ( $id != 0 ) { |
229 | 241 | $entry['exists'] = ''; |
| 242 | + } |
230 | 243 | $result[] = $entry; |
231 | 244 | } |
232 | 245 | } |
— | — | @@ -245,15 +258,16 @@ |
246 | 259 | |
247 | 260 | private function setIndexedTagNames( &$array, $mapping ) { |
248 | 261 | foreach ( $mapping as $key => $name ) { |
249 | | - if ( isset( $array[$key] ) ) |
| 262 | + if ( isset( $array[$key] ) ) { |
250 | 263 | $this->getResult()->setIndexedTagName( $array[$key], $name ); |
| 264 | + } |
251 | 265 | } |
252 | 266 | } |
253 | 267 | |
254 | 268 | public function getAllowedParams() { |
255 | | - return array ( |
| 269 | + return array( |
256 | 270 | 'title' => array( |
257 | | - ApiBase :: PARAM_DFLT => 'API', |
| 271 | + ApiBase::PARAM_DFLT => 'API', |
258 | 272 | ), |
259 | 273 | 'text' => null, |
260 | 274 | 'summary' => null, |
— | — | @@ -261,9 +275,9 @@ |
262 | 276 | 'redirects' => false, |
263 | 277 | 'oldid' => null, |
264 | 278 | 'prop' => array( |
265 | | - ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle', |
266 | | - ApiBase :: PARAM_ISMULTI => true, |
267 | | - ApiBase :: PARAM_TYPE => array( |
| 279 | + ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle', |
| 280 | + ApiBase::PARAM_ISMULTI => true, |
| 281 | + ApiBase::PARAM_TYPE => array( |
268 | 282 | 'text', |
269 | 283 | 'langlinks', |
270 | 284 | 'categories', |
— | — | @@ -284,7 +298,7 @@ |
285 | 299 | } |
286 | 300 | |
287 | 301 | public function getParamDescription() { |
288 | | - return array ( |
| 302 | + return array( |
289 | 303 | 'text' => 'Wikitext to parse', |
290 | 304 | 'summary' => 'Summary to parse', |
291 | 305 | 'redirects' => 'If the page parameter is set to a redirect, resolve it', |
— | — | @@ -306,7 +320,7 @@ |
307 | 321 | public function getDescription() { |
308 | 322 | return 'This module parses wikitext and returns parser output'; |
309 | 323 | } |
310 | | - |
| 324 | + |
311 | 325 | public function getPossibleErrors() { |
312 | 326 | return array_merge( parent::getPossibleErrors(), array( |
313 | 327 | array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ), |
— | — | @@ -317,7 +331,7 @@ |
318 | 332 | } |
319 | 333 | |
320 | 334 | protected function getExamples() { |
321 | | - return array ( |
| 335 | + return array( |
322 | 336 | 'api.php?action=parse&text={{Project:Sandbox}}' |
323 | 337 | ); |
324 | 338 | } |
Index: trunk/phase3/includes/api/ApiProtect.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 1, 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,7 +24,7 @@ |
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 | 31 | /** |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | class ApiProtect extends ApiBase { |
35 | 35 | |
36 | 36 | public function __construct( $main, $action ) { |
37 | | - parent :: __construct( $main, $action ); |
| 37 | + parent::__construct( $main, $action ); |
38 | 38 | } |
39 | 39 | |
40 | 40 | public function execute() { |
— | — | @@ -41,60 +41,68 @@ |
42 | 42 | $params = $this->extractRequestParams(); |
43 | 43 | |
44 | 44 | $titleObj = null; |
45 | | - if ( !isset( $params['title'] ) ) |
| 45 | + if ( !isset( $params['title'] ) ) { |
46 | 46 | $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
47 | | - if ( empty( $params['protections'] ) ) |
| 47 | + } |
| 48 | + if ( empty( $params['protections'] ) ) { |
48 | 49 | $this->dieUsageMsg( array( 'missingparam', 'protections' ) ); |
| 50 | + } |
49 | 51 | |
50 | 52 | $titleObj = Title::newFromText( $params['title'] ); |
51 | | - if ( !$titleObj ) |
| 53 | + if ( !$titleObj ) { |
52 | 54 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
| 55 | + } |
53 | 56 | |
54 | 57 | $errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser ); |
55 | | - if ( $errors ) |
| 58 | + if ( $errors ) { |
56 | 59 | // We don't care about multiple errors, just report one of them |
57 | 60 | $this->dieUsageMsg( reset( $errors ) ); |
| 61 | + } |
58 | 62 | |
59 | 63 | $expiry = (array)$params['expiry']; |
60 | | - if ( count( $expiry ) != count( $params['protections'] ) ) |
61 | | - { |
62 | | - if ( count( $expiry ) == 1 ) |
| 64 | + if ( count( $expiry ) != count( $params['protections'] ) ) { |
| 65 | + if ( count( $expiry ) == 1 ) { |
63 | 66 | $expiry = array_fill( 0, count( $params['protections'] ), $expiry[0] ); |
64 | | - else |
| 67 | + } else { |
65 | 68 | $this->dieUsageMsg( array( 'toofewexpiries', count( $expiry ), count( $params['protections'] ) ) ); |
| 69 | + } |
66 | 70 | } |
67 | | - |
| 71 | + |
68 | 72 | $restrictionTypes = $titleObj->getRestrictionTypes(); |
69 | | - |
| 73 | + |
70 | 74 | $protections = array(); |
71 | 75 | $expiryarray = array(); |
72 | 76 | $resultProtections = array(); |
73 | | - foreach ( $params['protections'] as $i => $prot ) |
74 | | - { |
| 77 | + foreach ( $params['protections'] as $i => $prot ) { |
75 | 78 | $p = explode( '=', $prot ); |
76 | 79 | $protections[$p[0]] = ( $p[1] == 'all' ? '' : $p[1] ); |
77 | 80 | |
78 | | - if ( $titleObj->exists() && $p[0] == 'create' ) |
| 81 | + if ( $titleObj->exists() && $p[0] == 'create' ) { |
79 | 82 | $this->dieUsageMsg( array( 'create-titleexists' ) ); |
80 | | - if ( !$titleObj->exists() && $p[0] != 'create' ) |
| 83 | + } |
| 84 | + if ( !$titleObj->exists() && $p[0] != 'create' ) { |
81 | 85 | $this->dieUsageMsg( array( 'missingtitle-createonly' ) ); |
| 86 | + } |
82 | 87 | |
83 | | - if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) |
| 88 | + if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) { |
84 | 89 | $this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) ); |
85 | | - if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) |
| 90 | + } |
| 91 | + if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) { |
86 | 92 | $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) ); |
| 93 | + } |
87 | 94 | |
88 | | - if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) |
| 95 | + if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) { |
89 | 96 | $expiryarray[$p[0]] = Block::infinity(); |
90 | | - else |
91 | | - { |
| 97 | + } else { |
92 | 98 | $exp = strtotime( $expiry[$i] ); |
93 | | - if ( $exp < 0 || $exp == false ) |
| 99 | + if ( $exp < 0 || $exp == false ) { |
94 | 100 | $this->dieUsageMsg( array( 'invalidexpiry', $expiry[$i] ) ); |
| 101 | + } |
95 | 102 | |
96 | 103 | $exp = wfTimestamp( TS_MW, $exp ); |
97 | | - if ( $exp < wfTimestampNow() ) |
| 104 | + if ( $exp < wfTimestampNow() ) { |
98 | 105 | $this->dieUsageMsg( array( 'pastexpiry', $expiry[$i] ) ); |
| 106 | + } |
99 | 107 | $expiryarray[$p[0]] = $exp; |
100 | 108 | } |
101 | 109 | $resultProtections[] = array( $p[0] => $protections[$p[0]], |
— | — | @@ -105,19 +113,26 @@ |
106 | 114 | |
107 | 115 | $cascade = $params['cascade']; |
108 | 116 | $articleObj = new Article( $titleObj ); |
109 | | - if ( $params['watch'] ) |
| 117 | + if ( $params['watch'] ) { |
110 | 118 | $articleObj->doWatch(); |
111 | | - if ( $titleObj->exists() ) |
| 119 | + } |
| 120 | + if ( $titleObj->exists() ) { |
112 | 121 | $ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray ); |
113 | | - else |
| 122 | + } else { |
114 | 123 | $ok = $titleObj->updateTitleProtection( $protections['create'], $params['reason'], $expiryarray['create'] ); |
115 | | - if ( !$ok ) |
| 124 | + } |
| 125 | + if ( !$ok ) { |
116 | 126 | // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? |
117 | 127 | // Just throw an unknown error in this case, as it's very likely to be a race condition |
118 | 128 | $this->dieUsageMsg( array() ); |
119 | | - $res = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'] ); |
120 | | - if ( $cascade ) |
| 129 | + } |
| 130 | + $res = array( |
| 131 | + 'title' => $titleObj->getPrefixedText(), |
| 132 | + 'reason' => $params['reason'] |
| 133 | + ); |
| 134 | + if ( $cascade ) { |
121 | 135 | $res['cascade'] = ''; |
| 136 | + } |
122 | 137 | $res['protections'] = $resultProtections; |
123 | 138 | $this->getResult()->setIndexedTagName( $res['protections'], 'protection' ); |
124 | 139 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
— | — | @@ -132,16 +147,16 @@ |
133 | 148 | } |
134 | 149 | |
135 | 150 | public function getAllowedParams() { |
136 | | - return array ( |
| 151 | + return array( |
137 | 152 | 'title' => null, |
138 | 153 | 'token' => null, |
139 | 154 | 'protections' => array( |
140 | | - ApiBase :: PARAM_ISMULTI => true |
| 155 | + ApiBase::PARAM_ISMULTI => true |
141 | 156 | ), |
142 | 157 | 'expiry' => array( |
143 | | - ApiBase :: PARAM_ISMULTI => true, |
144 | | - ApiBase :: PARAM_ALLOW_DUPLICATES => true, |
145 | | - ApiBase :: PARAM_DFLT => 'infinite', |
| 158 | + ApiBase::PARAM_ISMULTI => true, |
| 159 | + ApiBase::PARAM_ALLOW_DUPLICATES => true, |
| 160 | + ApiBase::PARAM_DFLT => 'infinite', |
146 | 161 | ), |
147 | 162 | 'reason' => '', |
148 | 163 | 'cascade' => false, |
— | — | @@ -150,7 +165,7 @@ |
151 | 166 | } |
152 | 167 | |
153 | 168 | public function getParamDescription() { |
154 | | - return array ( |
| 169 | + return array( |
155 | 170 | 'title' => 'Title of the page you want to (un)protect.', |
156 | 171 | 'token' => 'A protect token previously retrieved through prop=info', |
157 | 172 | 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)', |
— | — | @@ -168,7 +183,7 @@ |
169 | 184 | 'Change the protection level of a page.' |
170 | 185 | ); |
171 | 186 | } |
172 | | - |
| 187 | + |
173 | 188 | public function getPossibleErrors() { |
174 | 189 | return array_merge( parent::getPossibleErrors(), array( |
175 | 190 | array( 'missingparam', 'title' ), |
— | — | @@ -183,13 +198,13 @@ |
184 | 199 | array( 'pastexpiry', 'expiry' ), |
185 | 200 | ) ); |
186 | 201 | } |
187 | | - |
| 202 | + |
188 | 203 | public function getTokenSalt() { |
189 | 204 | return null; |
190 | 205 | } |
191 | 206 | |
192 | 207 | protected function getExamples() { |
193 | | - return array ( |
| 208 | + return array( |
194 | 209 | 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000|never', |
195 | 210 | 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions' |
196 | 211 | ); |
Index: trunk/phase3/includes/api/ApiImport.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Feb 4, 2009 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 9 | + * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiBase.php' ); |
| 29 | + require_once( 'ApiBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -36,58 +36,65 @@ |
37 | 37 | class ApiImport extends ApiBase { |
38 | 38 | |
39 | 39 | public function __construct( $main, $action ) { |
40 | | - parent :: __construct( $main, $action ); |
| 40 | + parent::__construct( $main, $action ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | 44 | global $wgUser; |
45 | | - if ( !$wgUser->isAllowed( 'import' ) ) |
| 45 | + if ( !$wgUser->isAllowed( 'import' ) ) { |
46 | 46 | $this->dieUsageMsg( array( 'cantimport' ) ); |
| 47 | + } |
47 | 48 | $params = $this->extractRequestParams(); |
48 | 49 | |
49 | 50 | $source = null; |
50 | 51 | $isUpload = false; |
51 | | - if ( isset( $params['interwikisource'] ) ) |
52 | | - { |
53 | | - if ( !isset( $params['interwikipage'] ) ) |
| 52 | + if ( isset( $params['interwikisource'] ) ) { |
| 53 | + if ( !isset( $params['interwikipage'] ) ) { |
54 | 54 | $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) ); |
| 55 | + } |
55 | 56 | $source = ImportStreamSource::newFromInterwiki( |
56 | | - $params['interwikisource'], |
57 | | - $params['interwikipage'], |
58 | | - $params['fullhistory'], |
59 | | - $params['templates'] ); |
60 | | - } |
61 | | - else |
62 | | - { |
| 57 | + $params['interwikisource'], |
| 58 | + $params['interwikipage'], |
| 59 | + $params['fullhistory'], |
| 60 | + $params['templates'] |
| 61 | + ); |
| 62 | + } else { |
63 | 63 | $isUpload = true; |
64 | | - if ( !$wgUser->isAllowed( 'importupload' ) ) |
| 64 | + if ( !$wgUser->isAllowed( 'importupload' ) ) { |
65 | 65 | $this->dieUsageMsg( array( 'cantimport-upload' ) ); |
| 66 | + } |
66 | 67 | $source = ImportStreamSource::newFromUpload( 'xml' ); |
67 | 68 | } |
68 | | - if ( $source instanceof WikiErrorMsg ) |
| 69 | + if ( $source instanceof WikiErrorMsg ) { |
69 | 70 | $this->dieUsageMsg( array_merge( |
70 | 71 | array( $source->getMessageKey() ), |
71 | 72 | $source->getMessageArgs() ) ); |
72 | | - else if ( WikiError::isError( $source ) ) |
| 73 | + } elseif ( WikiError::isError( $source ) ) { |
73 | 74 | // This shouldn't happen |
74 | 75 | $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) ); |
| 76 | + } |
75 | 77 | |
76 | 78 | $importer = new WikiImporter( $source ); |
77 | | - if ( isset( $params['namespace'] ) ) |
| 79 | + if ( isset( $params['namespace'] ) ) { |
78 | 80 | $importer->setTargetNamespace( $params['namespace'] ); |
79 | | - $reporter = new ApiImportReporter( $importer, $isUpload, |
80 | | - $params['interwikisource'], |
81 | | - $params['summary'] ); |
| 81 | + } |
| 82 | + $reporter = new ApiImportReporter( |
| 83 | + $importer, |
| 84 | + $isUpload, |
| 85 | + $params['interwikisource'], |
| 86 | + $params['summary'] |
| 87 | + ); |
82 | 88 | |
83 | 89 | $result = $importer->doImport(); |
84 | | - if ( $result instanceof WikiXmlError ) |
| 90 | + if ( $result instanceof WikiXmlError ) { |
85 | 91 | $this->dieUsageMsg( array( 'import-xml-error', |
86 | 92 | $result->mLine, |
87 | 93 | $result->mColumn, |
88 | 94 | $result->mByte . $result->mContext, |
89 | 95 | xml_error_string( $result->mXmlError ) ) ); |
90 | | - else if ( WikiError::isError( $result ) ) |
| 96 | + } elseif ( WikiError::isError( $result ) ) { |
91 | 97 | $this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); // This shouldn't happen |
| 98 | + } |
92 | 99 | |
93 | 100 | $resultData = $reporter->getData(); |
94 | 101 | $this->getResult()->setIndexedTagName( $resultData, 'page' ); |
— | — | @@ -104,24 +111,24 @@ |
105 | 112 | |
106 | 113 | public function getAllowedParams() { |
107 | 114 | global $wgImportSources; |
108 | | - return array ( |
| 115 | + return array( |
109 | 116 | 'token' => null, |
110 | 117 | 'summary' => null, |
111 | 118 | 'xml' => null, |
112 | 119 | 'interwikisource' => array( |
113 | | - ApiBase :: PARAM_TYPE => $wgImportSources |
| 120 | + ApiBase::PARAM_TYPE => $wgImportSources |
114 | 121 | ), |
115 | 122 | 'interwikipage' => null, |
116 | 123 | 'fullhistory' => false, |
117 | 124 | 'templates' => false, |
118 | 125 | 'namespace' => array( |
119 | | - ApiBase :: PARAM_TYPE => 'namespace' |
| 126 | + ApiBase::PARAM_TYPE => 'namespace' |
120 | 127 | ) |
121 | 128 | ); |
122 | 129 | } |
123 | 130 | |
124 | 131 | public function getParamDescription() { |
125 | | - return array ( |
| 132 | + return array( |
126 | 133 | 'token' => 'Import token obtained through prop=info', |
127 | 134 | 'summary' => 'Import summary', |
128 | 135 | 'xml' => 'Uploaded XML file', |
— | — | @@ -134,11 +141,11 @@ |
135 | 142 | } |
136 | 143 | |
137 | 144 | public function getDescription() { |
138 | | - return array ( |
| 145 | + return array( |
139 | 146 | 'Import a page from another wiki, or an XML file' |
140 | 147 | ); |
141 | 148 | } |
142 | | - |
| 149 | + |
143 | 150 | public function getPossibleErrors() { |
144 | 151 | return array_merge( parent::getPossibleErrors(), array( |
145 | 152 | array( 'cantimport' ), |
— | — | @@ -148,7 +155,7 @@ |
149 | 156 | array( 'import-unknownerror', 'result' ), |
150 | 157 | ) ); |
151 | 158 | } |
152 | | - |
| 159 | + |
153 | 160 | public function getTokenSalt() { |
154 | 161 | return ''; |
155 | 162 | } |
— | — | @@ -172,8 +179,7 @@ |
173 | 180 | class ApiImportReporter extends ImportReporter { |
174 | 181 | private $mResultArr = array(); |
175 | 182 | |
176 | | - function reportPage( $title, $origTitle, $revisionCount, $successCount ) |
177 | | - { |
| 183 | + function reportPage( $title, $origTitle, $revisionCount, $successCount ) { |
178 | 184 | // Add a result entry |
179 | 185 | $r = array(); |
180 | 186 | ApiQueryBase::addTitleInfo( $r, $title ); |
— | — | @@ -184,8 +190,7 @@ |
185 | 191 | parent::reportPage( $title, $origTitle, $revisionCount, $successCount ); |
186 | 192 | } |
187 | 193 | |
188 | | - function getData() |
189 | | - { |
| 194 | + function getData() { |
190 | 195 | return $this->mResultArr; |
191 | 196 | } |
192 | 197 | } |
\ No newline at end of file |
Index: trunk/phase3/includes/api/ApiFormatYaml.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 19, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiFormatBase.php' ); |
| 29 | + require_once( 'ApiFormatBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | class ApiFormatYaml extends ApiFormatBase { |
36 | 36 | |
37 | 37 | public function __construct( $main, $format ) { |
38 | | - parent :: __construct( $main, $format ); |
| 38 | + parent::__construct( $main, $format ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getMimeType() { |
— | — | @@ -42,11 +42,11 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function execute() { |
46 | | - $this->printText( Spyc :: YAMLDump( $this->getResultData() ) ); |
| 46 | + $this->printText( Spyc::YAMLDump( $this->getResultData() ) ); |
47 | 47 | } |
48 | 48 | |
49 | 49 | public function getDescription() { |
50 | | - return 'Output data in YAML format' . parent :: getDescription(); |
| 50 | + return 'Output data in YAML format' . parent::getDescription(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | public function getVersion() { |
Index: trunk/phase3/includes/api/ApiFormatXml.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 19, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiFormatBase.php' ); |
| 29 | + require_once( 'ApiFormatBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | private $mXslt = null; |
40 | 40 | |
41 | 41 | public function __construct( $main, $format ) { |
42 | | - parent :: __construct( $main, $format ); |
| 42 | + parent::__construct( $main, $format ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function getMimeType() { |
— | — | @@ -59,45 +59,50 @@ |
60 | 60 | $this->mXslt = $params['xslt']; |
61 | 61 | |
62 | 62 | $this->printText( '<?xml version="1.0"?>' ); |
63 | | - if ( !is_null( $this->mXslt ) ) |
| 63 | + if ( !is_null( $this->mXslt ) ) { |
64 | 64 | $this->addXslt(); |
65 | | - $this->printText( self::recXmlPrint( $this->mRootElemName, |
| 65 | + } |
| 66 | + $this->printText( |
| 67 | + self::recXmlPrint( $this->mRootElemName, |
66 | 68 | $this->getResultData(), |
67 | 69 | $this->getIsHtml() ? - 2 : null, |
68 | | - $this->mDoubleQuote ) ); |
| 70 | + $this->mDoubleQuote |
| 71 | + ) |
| 72 | + ); |
69 | 73 | } |
70 | 74 | |
71 | 75 | /** |
72 | | - * This method takes an array and converts it to XML. |
73 | | - * There are several noteworthy cases: |
74 | | - * |
75 | | - * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element']. |
76 | | - * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root> |
77 | | - * |
78 | | - * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content. |
79 | | - * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root> |
80 | | - * |
81 | | - * If neither key is found, all keys become element names, and values become element content. |
82 | | - * The method is recursive, so the same rules apply to any sub-arrays. |
83 | | - */ |
| 76 | + * This method takes an array and converts it to XML. |
| 77 | + * There are several noteworthy cases: |
| 78 | + * |
| 79 | + * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element']. |
| 80 | + * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root> |
| 81 | + * |
| 82 | + * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content. |
| 83 | + * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root> |
| 84 | + * |
| 85 | + * If neither key is found, all keys become element names, and values become element content. |
| 86 | + * The method is recursive, so the same rules apply to any sub-arrays. |
| 87 | + */ |
84 | 88 | public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) { |
85 | 89 | $retval = ''; |
86 | 90 | if ( !is_null( $indent ) ) { |
87 | 91 | $indent += 2; |
88 | | - $indstr = "\n" . str_repeat( " ", $indent ); |
| 92 | + $indstr = "\n" . str_repeat( ' ', $indent ); |
89 | 93 | } else { |
90 | 94 | $indstr = ''; |
91 | 95 | } |
92 | 96 | $elemName = str_replace( ' ', '_', $elemName ); |
93 | 97 | |
94 | 98 | switch ( gettype( $elemValue ) ) { |
95 | | - case 'array' : |
96 | | - if ( isset ( $elemValue['*'] ) ) { |
| 99 | + case 'array': |
| 100 | + if ( isset( $elemValue['*'] ) ) { |
97 | 101 | $subElemContent = $elemValue['*']; |
98 | | - if ( $doublequote ) |
| 102 | + if ( $doublequote ) { |
99 | 103 | $subElemContent = Sanitizer::encodeAttribute( $subElemContent ); |
100 | | - unset ( $elemValue['*'] ); |
101 | | - |
| 104 | + } |
| 105 | + unset( $elemValue['*'] ); |
| 106 | + |
102 | 107 | // Add xml:space="preserve" to the |
103 | 108 | // element so XML parsers will leave |
104 | 109 | // whitespace in the content alone |
— | — | @@ -106,59 +111,65 @@ |
107 | 112 | $subElemContent = null; |
108 | 113 | } |
109 | 114 | |
110 | | - if ( isset ( $elemValue['_element'] ) ) { |
| 115 | + if ( isset( $elemValue['_element'] ) ) { |
111 | 116 | $subElemIndName = $elemValue['_element']; |
112 | | - unset ( $elemValue['_element'] ); |
| 117 | + unset( $elemValue['_element'] ); |
113 | 118 | } else { |
114 | 119 | $subElemIndName = null; |
115 | 120 | } |
116 | 121 | |
117 | | - $indElements = array (); |
118 | | - $subElements = array (); |
| 122 | + $indElements = array(); |
| 123 | + $subElements = array(); |
119 | 124 | foreach ( $elemValue as $subElemId => & $subElemValue ) { |
120 | | - if ( is_string( $subElemValue ) && $doublequote ) |
| 125 | + if ( is_string( $subElemValue ) && $doublequote ) { |
121 | 126 | $subElemValue = Sanitizer::encodeAttribute( $subElemValue ); |
122 | | - |
| 127 | + } |
| 128 | + |
123 | 129 | if ( gettype( $subElemId ) === 'integer' ) { |
124 | 130 | $indElements[] = $subElemValue; |
125 | | - unset ( $elemValue[$subElemId] ); |
| 131 | + unset( $elemValue[$subElemId] ); |
126 | 132 | } elseif ( is_array( $subElemValue ) ) { |
127 | 133 | $subElements[$subElemId] = $subElemValue; |
128 | 134 | unset ( $elemValue[$subElemId] ); |
129 | 135 | } |
130 | 136 | } |
131 | 137 | |
132 | | - if ( is_null( $subElemIndName ) && count( $indElements ) ) |
133 | | - ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." ); |
| 138 | + if ( is_null( $subElemIndName ) && count( $indElements ) ) { |
| 139 | + ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." ); |
| 140 | + } |
134 | 141 | |
135 | | - if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) |
136 | | - ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has content and subelements" ); |
| 142 | + if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) { |
| 143 | + ApiBase::dieDebug( __METHOD__, "($elemName, ...) has content and subelements" ); |
| 144 | + } |
137 | 145 | |
138 | 146 | if ( !is_null( $subElemContent ) ) { |
139 | 147 | $retval .= $indstr . Xml::element( $elemName, $elemValue, $subElemContent ); |
140 | 148 | } elseif ( !count( $indElements ) && !count( $subElements ) ) { |
141 | | - $retval .= $indstr . Xml::element( $elemName, $elemValue ); |
| 149 | + $retval .= $indstr . Xml::element( $elemName, $elemValue ); |
142 | 150 | } else { |
143 | 151 | $retval .= $indstr . Xml::element( $elemName, $elemValue, null ); |
144 | 152 | |
145 | | - foreach ( $subElements as $subElemId => & $subElemValue ) |
| 153 | + foreach ( $subElements as $subElemId => & $subElemValue ) { |
146 | 154 | $retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent ); |
| 155 | + } |
147 | 156 | |
148 | | - foreach ( $indElements as $subElemId => & $subElemValue ) |
| 157 | + foreach ( $indElements as $subElemId => & $subElemValue ) { |
149 | 158 | $retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent ); |
| 159 | + } |
150 | 160 | |
151 | 161 | $retval .= $indstr . Xml::closeElement( $elemName ); |
152 | 162 | } |
153 | 163 | break; |
154 | | - case 'object' : |
| 164 | + case 'object': |
155 | 165 | // ignore |
156 | 166 | break; |
157 | | - default : |
| 167 | + default: |
158 | 168 | $retval .= $indstr . Xml::element( $elemName, null, $elemValue ); |
159 | 169 | break; |
160 | 170 | } |
161 | 171 | return $retval; |
162 | 172 | } |
| 173 | + |
163 | 174 | function addXslt() { |
164 | 175 | $nt = Title::newFromText( $this->mXslt ); |
165 | 176 | if ( is_null( $nt ) || !$nt->exists() ) { |
— | — | @@ -175,23 +186,23 @@ |
176 | 187 | } |
177 | 188 | $this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' ); |
178 | 189 | } |
179 | | - |
| 190 | + |
180 | 191 | public function getAllowedParams() { |
181 | | - return array ( |
| 192 | + return array( |
182 | 193 | 'xmldoublequote' => false, |
183 | 194 | 'xslt' => null, |
184 | 195 | ); |
185 | 196 | } |
186 | 197 | |
187 | 198 | public function getParamDescription() { |
188 | | - return array ( |
| 199 | + return array( |
189 | 200 | 'xmldoublequote' => 'If specified, double quotes all attributes and content.', |
190 | 201 | 'xslt' => 'If specified, adds <xslt> as stylesheet', |
191 | 202 | ); |
192 | 203 | } |
193 | 204 | |
194 | 205 | public function getDescription() { |
195 | | - return 'Output data in XML format' . parent :: getDescription(); |
| 206 | + return 'Output data in XML format' . parent::getDescription(); |
196 | 207 | } |
197 | 208 | |
198 | 209 | public function getVersion() { |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 4, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiBase.php' ); |
| 29 | + require_once( 'ApiBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | /** |
57 | 57 | * List of available modules: action name => module class |
58 | 58 | */ |
59 | | - private static $Modules = array ( |
| 59 | + private static $Modules = array( |
60 | 60 | 'login' => 'ApiLogin', |
61 | 61 | 'logout' => 'ApiLogout', |
62 | 62 | 'query' => 'ApiQuery', |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | /** |
89 | 89 | * List of available formats: format name => format class |
90 | 90 | */ |
91 | | - private static $Formats = array ( |
| 91 | + private static $Formats = array( |
92 | 92 | 'json' => 'ApiFormatJson', |
93 | 93 | 'jsonfm' => 'ApiFormatJson', |
94 | 94 | 'php' => 'ApiFormatPhp', |
— | — | @@ -111,17 +111,17 @@ |
112 | 112 | * 'params' => array ( $someVarToSubst ) ), |
113 | 113 | * ); |
114 | 114 | */ |
115 | | - private static $mRights = array( 'writeapi' => array( |
116 | | - 'msg' => 'Use of the write API', |
117 | | - 'params' => array() |
118 | | - ), |
119 | | - 'apihighlimits' => array( |
120 | | - 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.', |
121 | | - 'params' => array ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 ) |
122 | | - ) |
| 115 | + private static $mRights = array( |
| 116 | + 'writeapi' => array( |
| 117 | + 'msg' => 'Use of the write API', |
| 118 | + 'params' => array() |
| 119 | + ), |
| 120 | + 'apihighlimits' => array( |
| 121 | + 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.', |
| 122 | + 'params' => array( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 ) |
| 123 | + ) |
123 | 124 | ); |
124 | 125 | |
125 | | - |
126 | 126 | private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames; |
127 | 127 | private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest; |
128 | 128 | private $mInternalMode, $mSquidMaxage, $mModule; |
— | — | @@ -129,20 +129,18 @@ |
130 | 130 | private $mCacheControl = array( 'must-revalidate' => true ); |
131 | 131 | |
132 | 132 | /** |
133 | | - * Constructs an instance of ApiMain that utilizes the module and format specified by $request. |
134 | | - * |
135 | | - * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs |
136 | | - * @param $enableWrite bool should be set to true if the api may modify data |
137 | | - */ |
| 133 | + * Constructs an instance of ApiMain that utilizes the module and format specified by $request. |
| 134 | + * |
| 135 | + * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs |
| 136 | + * @param $enableWrite bool should be set to true if the api may modify data |
| 137 | + */ |
138 | 138 | public function __construct( $request, $enableWrite = false ) { |
139 | | - |
140 | 139 | $this->mInternalMode = ( $request instanceof FauxRequest ); |
141 | 140 | |
142 | 141 | // Special handling for the main module: $parent === $this |
143 | | - parent :: __construct( $this, $this->mInternalMode ? 'main_int' : 'main' ); |
| 142 | + parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' ); |
144 | 143 | |
145 | 144 | if ( !$this->mInternalMode ) { |
146 | | - |
147 | 145 | // Impose module restrictions. |
148 | 146 | // If the current user cannot read, |
149 | 147 | // Remove all modules other than login |
— | — | @@ -157,19 +155,19 @@ |
158 | 156 | } |
159 | 157 | |
160 | 158 | global $wgAPIModules; // extension modules |
161 | | - $this->mModules = $wgAPIModules + self :: $Modules; |
| 159 | + $this->mModules = $wgAPIModules + self::$Modules; |
162 | 160 | |
163 | 161 | $this->mModuleNames = array_keys( $this->mModules ); |
164 | | - $this->mFormats = self :: $Formats; |
| 162 | + $this->mFormats = self::$Formats; |
165 | 163 | $this->mFormatNames = array_keys( $this->mFormats ); |
166 | 164 | |
167 | 165 | $this->mResult = new ApiResult( $this ); |
168 | 166 | $this->mShowVersions = false; |
169 | 167 | $this->mEnableWrite = $enableWrite; |
170 | 168 | |
171 | | - $this->mRequest = & $request; |
| 169 | + $this->mRequest = &$request; |
172 | 170 | |
173 | | - $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling() |
| 171 | + $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling() |
174 | 172 | $this->mCommit = false; |
175 | 173 | } |
176 | 174 | |
— | — | @@ -206,10 +204,12 @@ |
207 | 205 | * @deprecated Use isWriteMode() instead |
208 | 206 | */ |
209 | 207 | public function requestWriteMode() { |
210 | | - if ( !$this->mEnableWrite ) |
| 208 | + if ( !$this->mEnableWrite ) { |
211 | 209 | $this->dieUsageMsg( array( 'writedisabled' ) ); |
212 | | - if ( wfReadOnly() ) |
| 210 | + } |
| 211 | + if ( wfReadOnly() ) { |
213 | 212 | $this->dieUsageMsg( array( 'readonlytext' ) ); |
| 213 | + } |
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
— | — | @@ -235,8 +235,9 @@ |
236 | 236 | * Create an instance of an output formatter by its name |
237 | 237 | */ |
238 | 238 | public function createPrinterByName( $format ) { |
239 | | - if ( !isset( $this->mFormats[$format] ) ) |
| 239 | + if ( !isset( $this->mFormats[$format] ) ) { |
240 | 240 | $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' ); |
| 241 | + } |
241 | 242 | return new $this->mFormats[$format] ( $this, $format ); |
242 | 243 | } |
243 | 244 | |
— | — | @@ -245,10 +246,11 @@ |
246 | 247 | */ |
247 | 248 | public function execute() { |
248 | 249 | $this->profileIn(); |
249 | | - if ( $this->mInternalMode ) |
| 250 | + if ( $this->mInternalMode ) { |
250 | 251 | $this->executeAction(); |
251 | | - else |
| 252 | + } else { |
252 | 253 | $this->executeActionWithErrorHandling(); |
| 254 | + } |
253 | 255 | |
254 | 256 | $this->profileOut(); |
255 | 257 | } |
— | — | @@ -258,7 +260,6 @@ |
259 | 261 | * have been accumulated, and replace it with an error message and a help screen. |
260 | 262 | */ |
261 | 263 | protected function executeActionWithErrorHandling() { |
262 | | - |
263 | 264 | // In case an error occurs during data output, |
264 | 265 | // clear the output buffer and print just the error information |
265 | 266 | ob_start(); |
— | — | @@ -283,10 +284,11 @@ |
284 | 285 | $this->setCacheMaxAge( 0 ); |
285 | 286 | |
286 | 287 | $headerStr = 'MediaWiki-API-Error: ' . $errCode; |
287 | | - if ( $e->getCode() === 0 ) |
| 288 | + if ( $e->getCode() === 0 ) { |
288 | 289 | header( $headerStr ); |
289 | | - else |
| 290 | + } else { |
290 | 291 | header( $headerStr, true, $e->getCode() ); |
| 292 | + } |
291 | 293 | |
292 | 294 | // Reset and print just the error message |
293 | 295 | ob_clean(); |
— | — | @@ -324,11 +326,12 @@ |
325 | 327 | $separator = ', '; |
326 | 328 | } |
327 | 329 | } |
328 | | - |
| 330 | + |
329 | 331 | header( "Cache-Control: $ccHeader" ); |
330 | 332 | |
331 | | - if ( $this->mPrinter->getIsHtml() ) |
| 333 | + if ( $this->mPrinter->getIsHtml() ) { |
332 | 334 | echo wfReportTime(); |
| 335 | + } |
333 | 336 | |
334 | 337 | ob_end_flush(); |
335 | 338 | } |
— | — | @@ -338,17 +341,18 @@ |
339 | 342 | * Returns the error code |
340 | 343 | */ |
341 | 344 | protected function substituteResultWithError( $e ) { |
342 | | - |
343 | 345 | // Printer may not be initialized if the extractRequestParams() fails for the main module |
344 | 346 | if ( !isset ( $this->mPrinter ) ) { |
345 | 347 | // The printer has not been created yet. Try to manually get formatter value. |
346 | 348 | $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT ); |
347 | | - if ( !in_array( $value, $this->mFormatNames ) ) |
| 349 | + if ( !in_array( $value, $this->mFormatNames ) ) { |
348 | 350 | $value = self::API_DEFAULT_FORMAT; |
| 351 | + } |
349 | 352 | |
350 | 353 | $this->mPrinter = $this->createPrinterByName( $value ); |
351 | | - if ( $this->mPrinter->getNeedsRawData() ) |
| 354 | + if ( $this->mPrinter->getNeedsRawData() ) { |
352 | 355 | $this->getResult()->setRawMode(); |
| 356 | + } |
353 | 357 | } |
354 | 358 | |
355 | 359 | if ( $e instanceof UsageException ) { |
— | — | @@ -358,8 +362,9 @@ |
359 | 363 | $errMessage = $e->getMessageArray(); |
360 | 364 | |
361 | 365 | // Only print the help message when this is for the developer, not runtime |
362 | | - if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) |
363 | | - ApiResult :: setContent( $errMessage, $this->makeHelpMsg() ); |
| 366 | + if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) { |
| 367 | + ApiResult::setContent( $errMessage, $this->makeHelpMsg() ); |
| 368 | + } |
364 | 369 | |
365 | 370 | } else { |
366 | 371 | global $wgShowSQLErrors, $wgShowExceptionDetails; |
— | — | @@ -367,24 +372,25 @@ |
368 | 373 | // Something is seriously wrong |
369 | 374 | // |
370 | 375 | if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) { |
371 | | - $info = "Database query error"; |
| 376 | + $info = 'Database query error'; |
372 | 377 | } else { |
373 | 378 | $info = "Exception Caught: {$e->getMessage()}"; |
374 | 379 | } |
375 | 380 | |
376 | | - $errMessage = array ( |
| 381 | + $errMessage = array( |
377 | 382 | 'code' => 'internal_api_error_' . get_class( $e ), |
378 | 383 | 'info' => $info, |
379 | 384 | ); |
380 | | - ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" ); |
| 385 | + ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' ); |
381 | 386 | } |
382 | 387 | |
383 | 388 | $this->getResult()->reset(); |
384 | 389 | $this->getResult()->disableSizeCheck(); |
385 | 390 | // Re-add the id |
386 | 391 | $requestid = $this->getParameter( 'requestid' ); |
387 | | - if ( !is_null( $requestid ) ) |
| 392 | + if ( !is_null( $requestid ) ) { |
388 | 393 | $this->getResult()->addValue( null, 'requestid', $requestid ); |
| 394 | + } |
389 | 395 | $this->getResult()->addValue( null, 'error', $errMessage ); |
390 | 396 | |
391 | 397 | return $errMessage['code']; |
— | — | @@ -396,8 +402,9 @@ |
397 | 403 | protected function executeAction() { |
398 | 404 | // First add the id to the top element |
399 | 405 | $requestid = $this->getParameter( 'requestid' ); |
400 | | - if ( !is_null( $requestid ) ) |
| 406 | + if ( !is_null( $requestid ) ) { |
401 | 407 | $this->getResult()->addValue( null, 'requestid', $requestid ); |
| 408 | + } |
402 | 409 | |
403 | 410 | $params = $this->extractRequestParams(); |
404 | 411 | |
— | — | @@ -405,19 +412,18 @@ |
406 | 413 | $this->mAction = $params['action']; |
407 | 414 | |
408 | 415 | if ( !is_string( $this->mAction ) ) { |
409 | | - $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' ); |
| 416 | + $this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' ); |
410 | 417 | } |
411 | | - |
| 418 | + |
412 | 419 | // Instantiate the module requested by the user |
413 | 420 | $module = new $this->mModules[$this->mAction] ( $this, $this->mAction ); |
414 | 421 | $this->mModule = $module; |
415 | 422 | |
416 | 423 | $moduleParams = $module->extractRequestParams(); |
417 | | - |
| 424 | + |
418 | 425 | // Die if token required, but not provided (unless there is a gettoken parameter) |
419 | 426 | $salt = $module->getTokenSalt(); |
420 | | - if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) |
421 | | - { |
| 427 | + if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) { |
422 | 428 | if ( !isset( $moduleParams['token'] ) ) { |
423 | 429 | $this->dieUsageMsg( array( 'missingparam', 'token' ) ); |
424 | 430 | } else { |
— | — | @@ -447,20 +453,26 @@ |
448 | 454 | |
449 | 455 | global $wgUser, $wgGroupPermissions; |
450 | 456 | if ( $module->isReadMode() && !$wgGroupPermissions['*']['read'] && !$wgUser->isAllowed( 'read' ) ) |
| 457 | + { |
451 | 458 | $this->dieUsageMsg( array( 'readrequired' ) ); |
| 459 | + } |
452 | 460 | if ( $module->isWriteMode() ) { |
453 | | - if ( !$this->mEnableWrite ) |
| 461 | + if ( !$this->mEnableWrite ) { |
454 | 462 | $this->dieUsageMsg( array( 'writedisabled' ) ); |
455 | | - if ( !$wgUser->isAllowed( 'writeapi' ) ) |
| 463 | + } |
| 464 | + if ( !$wgUser->isAllowed( 'writeapi' ) ) { |
456 | 465 | $this->dieUsageMsg( array( 'writerequired' ) ); |
457 | | - if ( wfReadOnly() ) |
| 466 | + } |
| 467 | + if ( wfReadOnly() ) { |
458 | 468 | $this->dieReadOnly(); |
| 469 | + } |
459 | 470 | } |
460 | 471 | |
461 | 472 | if ( !$this->mInternalMode ) { |
462 | 473 | // Ignore mustBePosted() for internal calls |
463 | | - if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) |
464 | | - $this->dieUsageMsg( array ( 'mustbeposted', $this->mAction ) ); |
| 474 | + if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) { |
| 475 | + $this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) ); |
| 476 | + } |
465 | 477 | |
466 | 478 | // See if custom printer is used |
467 | 479 | $this->mPrinter = $module->getCustomPrinter(); |
— | — | @@ -469,8 +481,9 @@ |
470 | 482 | $this->mPrinter = $this->createPrinterByName( $params['format'] ); |
471 | 483 | } |
472 | 484 | |
473 | | - if ( $this->mPrinter->getNeedsRawData() ) |
| 485 | + if ( $this->mPrinter->getNeedsRawData() ) { |
474 | 486 | $this->getResult()->setRawMode(); |
| 487 | + } |
475 | 488 | } |
476 | 489 | |
477 | 490 | // Execute |
— | — | @@ -493,10 +506,12 @@ |
494 | 507 | $printer = $this->mPrinter; |
495 | 508 | $printer->profileIn(); |
496 | 509 | |
497 | | - /* If the help message is requested in the default (xmlfm) format, |
| 510 | + /** |
| 511 | + * If the help message is requested in the default (xmlfm) format, |
498 | 512 | * tell the printer not to escape ampersands so that our links do |
499 | | - * not break. */ |
500 | | - $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError ) |
| 513 | + * not break. |
| 514 | + */ |
| 515 | + $printer->setUnescapeAmps( ( $this->mAction == 'help' || $isError ) |
501 | 516 | && $printer->getFormat() == 'XML' && $printer->getIsHtml() ); |
502 | 517 | |
503 | 518 | $printer->initPrinter( $isError ); |
— | — | @@ -514,26 +529,26 @@ |
515 | 530 | * See ApiBase for description. |
516 | 531 | */ |
517 | 532 | public function getAllowedParams() { |
518 | | - return array ( |
519 | | - 'format' => array ( |
520 | | - ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT, |
521 | | - ApiBase :: PARAM_TYPE => $this->mFormatNames |
| 533 | + return array( |
| 534 | + 'format' => array( |
| 535 | + ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT, |
| 536 | + ApiBase::PARAM_TYPE => $this->mFormatNames |
522 | 537 | ), |
523 | | - 'action' => array ( |
524 | | - ApiBase :: PARAM_DFLT => 'help', |
525 | | - ApiBase :: PARAM_TYPE => $this->mModuleNames |
| 538 | + 'action' => array( |
| 539 | + ApiBase::PARAM_DFLT => 'help', |
| 540 | + ApiBase::PARAM_TYPE => $this->mModuleNames |
526 | 541 | ), |
527 | 542 | 'version' => false, |
528 | | - 'maxlag' => array ( |
529 | | - ApiBase :: PARAM_TYPE => 'integer' |
| 543 | + 'maxlag' => array( |
| 544 | + ApiBase::PARAM_TYPE => 'integer' |
530 | 545 | ), |
531 | | - 'smaxage' => array ( |
532 | | - ApiBase :: PARAM_TYPE => 'integer', |
533 | | - ApiBase :: PARAM_DFLT => 0 |
| 546 | + 'smaxage' => array( |
| 547 | + ApiBase::PARAM_TYPE => 'integer', |
| 548 | + ApiBase::PARAM_DFLT => 0 |
534 | 549 | ), |
535 | | - 'maxage' => array ( |
536 | | - ApiBase :: PARAM_TYPE => 'integer', |
537 | | - ApiBase :: PARAM_DFLT => 0 |
| 550 | + 'maxage' => array( |
| 551 | + ApiBase::PARAM_TYPE => 'integer', |
| 552 | + ApiBase::PARAM_DFLT => 0 |
538 | 553 | ), |
539 | 554 | 'requestid' => null, |
540 | 555 | ); |
— | — | @@ -543,7 +558,7 @@ |
544 | 559 | * See ApiBase for description. |
545 | 560 | */ |
546 | 561 | public function getParamDescription() { |
547 | | - return array ( |
| 562 | + return array( |
548 | 563 | 'format' => 'The format of the output', |
549 | 564 | 'action' => 'What action you would like to perform', |
550 | 565 | 'version' => 'When showing help, include version for each module', |
— | — | @@ -558,7 +573,7 @@ |
559 | 574 | * See ApiBase for description. |
560 | 575 | */ |
561 | 576 | public function getDescription() { |
562 | | - return array ( |
| 577 | + return array( |
563 | 578 | '', |
564 | 579 | '', |
565 | 580 | '******************************************************************', |
— | — | @@ -585,14 +600,14 @@ |
586 | 601 | ); |
587 | 602 | } |
588 | 603 | |
589 | | - public function getPossibleErrors() { |
| 604 | + public function getPossibleErrors() { |
590 | 605 | return array_merge( parent::getPossibleErrors(), array( |
591 | 606 | array( 'readonlytext' ), |
592 | 607 | array( 'code' => 'unknown_format', 'info' => 'Unrecognized format: format' ), |
593 | 608 | array( 'code' => 'unknown_action', 'info' => 'The API requires a valid action parameter' ), |
594 | 609 | array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ), |
595 | 610 | array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ), |
596 | | - ) ); |
| 611 | + ) ); |
597 | 612 | } |
598 | 613 | |
599 | 614 | /** |
— | — | @@ -624,21 +639,22 @@ |
625 | 640 | $this->getMain()->getShowVersions() ); |
626 | 641 | if ( $wgAPICacheHelp ) { |
627 | 642 | $cached = $wgMemc->get( $key ); |
628 | | - if ( $cached ) |
| 643 | + if ( $cached ) { |
629 | 644 | return $cached; |
| 645 | + } |
630 | 646 | } |
631 | 647 | $retval = $this->reallyMakeHelpMsg(); |
632 | | - if ( $wgAPICacheHelp ) |
| 648 | + if ( $wgAPICacheHelp ) { |
633 | 649 | $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout ); |
| 650 | + } |
634 | 651 | return $retval; |
635 | 652 | } |
636 | 653 | |
637 | 654 | public function reallyMakeHelpMsg() { |
638 | | - |
639 | 655 | $this->mPrinter->setHelp(); |
640 | 656 | |
641 | 657 | // Use parent to make default message for the main module |
642 | | - $msg = parent :: makeHelpMsg(); |
| 658 | + $msg = parent::makeHelpMsg(); |
643 | 659 | |
644 | 660 | $astriks = str_repeat( '*** ', 10 ); |
645 | 661 | $msg .= "\n\n$astriks Modules $astriks\n\n"; |
— | — | @@ -646,16 +662,17 @@ |
647 | 663 | $module = new $this->mModules[$moduleName] ( $this, $moduleName ); |
648 | 664 | $msg .= self::makeHelpMsgHeader( $module, 'action' ); |
649 | 665 | $msg2 = $module->makeHelpMsg(); |
650 | | - if ( $msg2 !== false ) |
| 666 | + if ( $msg2 !== false ) { |
651 | 667 | $msg .= $msg2; |
| 668 | + } |
652 | 669 | $msg .= "\n"; |
653 | 670 | } |
654 | 671 | |
655 | 672 | $msg .= "\n$astriks Permissions $astriks\n\n"; |
656 | | - foreach ( self :: $mRights as $right => $rightMsg ) { |
| 673 | + foreach ( self::$mRights as $right => $rightMsg ) { |
657 | 674 | $groups = User::getGroupsWithPermission( $right ); |
658 | 675 | $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) . |
659 | | - "\nGranted to:\n " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n"; |
| 676 | + "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n"; |
660 | 677 | |
661 | 678 | } |
662 | 679 | |
— | — | @@ -664,8 +681,9 @@ |
665 | 682 | $module = $this->createPrinterByName( $formatName ); |
666 | 683 | $msg .= self::makeHelpMsgHeader( $module, 'format' ); |
667 | 684 | $msg2 = $module->makeHelpMsg(); |
668 | | - if ( $msg2 !== false ) |
| 685 | + if ( $msg2 !== false ) { |
669 | 686 | $msg .= $msg2; |
| 687 | + } |
670 | 688 | $msg .= "\n"; |
671 | 689 | } |
672 | 690 | |
— | — | @@ -677,8 +695,9 @@ |
678 | 696 | |
679 | 697 | public static function makeHelpMsgHeader( $module, $paramName ) { |
680 | 698 | $modulePrefix = $module->getModulePrefix(); |
681 | | - if ( strval( $modulePrefix ) !== '' ) |
| 699 | + if ( strval( $modulePrefix ) !== '' ) { |
682 | 700 | $modulePrefix = "($modulePrefix) "; |
| 701 | + } |
683 | 702 | |
684 | 703 | return "* $paramName={$module->getModuleName()} $modulePrefix*"; |
685 | 704 | } |
— | — | @@ -692,7 +711,7 @@ |
693 | 712 | * OBSOLETE, use canApiHighLimits() instead |
694 | 713 | */ |
695 | 714 | public function isBot() { |
696 | | - if ( !isset ( $this->mIsBot ) ) { |
| 715 | + if ( !isset( $this->mIsBot ) ) { |
697 | 716 | global $wgUser; |
698 | 717 | $this->mIsBot = $wgUser->isAllowed( 'bot' ); |
699 | 718 | } |
— | — | @@ -705,7 +724,7 @@ |
706 | 725 | * OBSOLETE, use canApiHighLimits() instead |
707 | 726 | */ |
708 | 727 | public function isSysop() { |
709 | | - if ( !isset ( $this->mIsSysop ) ) { |
| 728 | + if ( !isset( $this->mIsSysop ) ) { |
710 | 729 | global $wgUser; |
711 | 730 | $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() ); |
712 | 731 | } |
— | — | @@ -742,9 +761,9 @@ |
743 | 762 | $vers = array (); |
744 | 763 | $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/"; |
745 | 764 | $vers[] = __CLASS__ . ': $Id$'; |
746 | | - $vers[] = ApiBase :: getBaseVersion(); |
747 | | - $vers[] = ApiFormatBase :: getBaseVersion(); |
748 | | - $vers[] = ApiQueryBase :: getBaseVersion(); |
| 765 | + $vers[] = ApiBase::getBaseVersion(); |
| 766 | + $vers[] = ApiFormatBase::getBaseVersion(); |
| 767 | + $vers[] = ApiQueryBase::getBaseVersion(); |
749 | 768 | return $vers; |
750 | 769 | } |
751 | 770 | |
— | — | @@ -753,7 +772,6 @@ |
754 | 773 | * classes who wish to add their own modules to their lexicon or override the |
755 | 774 | * behavior of inherent ones. |
756 | 775 | * |
757 | | - * @access protected |
758 | 776 | * @param $mdlName String The identifier for this module. |
759 | 777 | * @param $mdlClass String The class where this module is implemented. |
760 | 778 | */ |
— | — | @@ -765,7 +783,6 @@ |
766 | 784 | * Add or overwrite an output format for this ApiMain. Intended for use by extending |
767 | 785 | * classes who wish to add to or modify current formatters. |
768 | 786 | * |
769 | | - * @access protected |
770 | 787 | * @param $fmtName The identifier for this format. |
771 | 788 | * @param $fmtClass The class implementing this format. |
772 | 789 | */ |
— | — | @@ -793,22 +810,26 @@ |
794 | 811 | private $mExtraData; |
795 | 812 | |
796 | 813 | public function __construct( $message, $codestr, $code = 0, $extradata = null ) { |
797 | | - parent :: __construct( $message, $code ); |
| 814 | + parent::__construct( $message, $code ); |
798 | 815 | $this->mCodestr = $codestr; |
799 | 816 | $this->mExtraData = $extradata; |
800 | 817 | } |
| 818 | + |
801 | 819 | public function getCodeString() { |
802 | 820 | return $this->mCodestr; |
803 | 821 | } |
| 822 | + |
804 | 823 | public function getMessageArray() { |
805 | | - $result = array ( |
806 | | - 'code' => $this->mCodestr, |
807 | | - 'info' => $this->getMessage() |
| 824 | + $result = array( |
| 825 | + 'code' => $this->mCodestr, |
| 826 | + 'info' => $this->getMessage() |
808 | 827 | ); |
809 | | - if ( is_array( $this->mExtraData ) ) |
| 828 | + if ( is_array( $this->mExtraData ) ) { |
810 | 829 | $result = array_merge( $result, $this->mExtraData ); |
| 830 | + } |
811 | 831 | return $result; |
812 | 832 | } |
| 833 | + |
813 | 834 | public function __toString() { |
814 | 835 | return "{$this->getCodeString()}: {$this->getMessage()}"; |
815 | 836 | } |
Index: trunk/phase3/includes/api/ApiOpenSearch.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Oct 13, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( "ApiBase.php" ); |
| 29 | + require_once( "ApiBase.php" ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | class ApiOpenSearch extends ApiBase { |
36 | 36 | |
37 | 37 | public function __construct( $main, $action ) { |
38 | | - parent :: __construct( $main, $action ); |
| 38 | + parent::__construct( $main, $action ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getCustomPrinter() { |
— | — | @@ -50,9 +50,9 @@ |
51 | 51 | $suggest = $params['suggest']; |
52 | 52 | |
53 | 53 | // MWSuggest or similar hit |
54 | | - if ( $suggest && !$wgEnableOpenSearchSuggest ) |
| 54 | + if ( $suggest && !$wgEnableOpenSearchSuggest ) { |
55 | 55 | $srchres = array(); |
56 | | - else { |
| 56 | + } else { |
57 | 57 | // Open search results may be stored for a very long |
58 | 58 | // time |
59 | 59 | $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry ); |
— | — | @@ -68,26 +68,26 @@ |
69 | 69 | } |
70 | 70 | |
71 | 71 | public function getAllowedParams() { |
72 | | - return array ( |
| 72 | + return array( |
73 | 73 | 'search' => null, |
74 | 74 | 'limit' => array( |
75 | | - ApiBase :: PARAM_DFLT => 10, |
76 | | - ApiBase :: PARAM_TYPE => 'limit', |
77 | | - ApiBase :: PARAM_MIN => 1, |
78 | | - ApiBase :: PARAM_MAX => 100, |
79 | | - ApiBase :: PARAM_MAX2 => 100 |
| 75 | + ApiBase::PARAM_DFLT => 10, |
| 76 | + ApiBase::PARAM_TYPE => 'limit', |
| 77 | + ApiBase::PARAM_MIN => 1, |
| 78 | + ApiBase::PARAM_MAX => 100, |
| 79 | + ApiBase::PARAM_MAX2 => 100 |
80 | 80 | ), |
81 | 81 | 'namespace' => array( |
82 | | - ApiBase :: PARAM_DFLT => NS_MAIN, |
83 | | - ApiBase :: PARAM_TYPE => 'namespace', |
84 | | - ApiBase :: PARAM_ISMULTI => true |
| 82 | + ApiBase::PARAM_DFLT => NS_MAIN, |
| 83 | + ApiBase::PARAM_TYPE => 'namespace', |
| 84 | + ApiBase::PARAM_ISMULTI => true |
85 | 85 | ), |
86 | 86 | 'suggest' => false, |
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
90 | 90 | public function getParamDescription() { |
91 | | - return array ( |
| 91 | + return array( |
92 | 92 | 'search' => 'Search string', |
93 | 93 | 'limit' => 'Maximum amount of results to return', |
94 | 94 | 'namespace' => 'Namespaces to search', |
— | — | @@ -100,7 +100,7 @@ |
101 | 101 | } |
102 | 102 | |
103 | 103 | protected function getExamples() { |
104 | | - return array ( |
| 104 | + return array( |
105 | 105 | 'api.php?action=opensearch&search=Te' |
106 | 106 | ); |
107 | 107 | } |
Index: trunk/phase3/includes/api/ApiPageSet.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 24, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( 'ApiQueryBase.php' ); |
| 29 | + require_once( 'ApiQueryBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -59,26 +59,27 @@ |
60 | 60 | * @param $resolveRedirects bool Whether redirects should be resolved |
61 | 61 | */ |
62 | 62 | public function __construct( $query, $resolveRedirects = false ) { |
63 | | - parent :: __construct( $query, 'query' ); |
| 63 | + parent::__construct( $query, 'query' ); |
64 | 64 | |
65 | | - $this->mAllPages = array (); |
| 65 | + $this->mAllPages = array(); |
66 | 66 | $this->mTitles = array(); |
67 | | - $this->mGoodTitles = array (); |
68 | | - $this->mMissingTitles = array (); |
69 | | - $this->mInvalidTitles = array (); |
70 | | - $this->mMissingPageIDs = array (); |
71 | | - $this->mRedirectTitles = array (); |
72 | | - $this->mNormalizedTitles = array (); |
73 | | - $this->mInterwikiTitles = array (); |
| 67 | + $this->mGoodTitles = array(); |
| 68 | + $this->mMissingTitles = array(); |
| 69 | + $this->mInvalidTitles = array(); |
| 70 | + $this->mMissingPageIDs = array(); |
| 71 | + $this->mRedirectTitles = array(); |
| 72 | + $this->mNormalizedTitles = array(); |
| 73 | + $this->mInterwikiTitles = array(); |
74 | 74 | $this->mGoodRevIDs = array(); |
75 | 75 | $this->mMissingRevIDs = array(); |
76 | 76 | |
77 | | - $this->mRequestedPageFields = array (); |
| 77 | + $this->mRequestedPageFields = array(); |
78 | 78 | $this->mResolveRedirects = $resolveRedirects; |
79 | | - if ( $resolveRedirects ) |
| 79 | + if ( $resolveRedirects ) { |
80 | 80 | $this->mPendingRedirectIDs = array(); |
| 81 | + } |
81 | 82 | |
82 | | - $this->mFakePageId = - 1; |
| 83 | + $this->mFakePageId = -1; |
83 | 84 | } |
84 | 85 | |
85 | 86 | /** |
— | — | @@ -117,14 +118,15 @@ |
118 | 119 | public function getPageTableFields() { |
119 | 120 | // Ensure we get minimum required fields |
120 | 121 | // DON'T change this order |
121 | | - $pageFlds = array ( |
| 122 | + $pageFlds = array( |
122 | 123 | 'page_namespace' => null, |
123 | 124 | 'page_title' => null, |
124 | 125 | 'page_id' => null, |
125 | 126 | ); |
126 | 127 | |
127 | | - if ( $this->mResolveRedirects ) |
| 128 | + if ( $this->mResolveRedirects ) { |
128 | 129 | $pageFlds['page_is_redirect'] = null; |
| 130 | + } |
129 | 131 | |
130 | 132 | // only store non-default fields |
131 | 133 | $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds ); |
— | — | @@ -261,34 +263,38 @@ |
262 | 264 | |
263 | 265 | // Only one of the titles/pageids/revids is allowed at the same time |
264 | 266 | $dataSource = null; |
265 | | - if ( isset ( $params['titles'] ) ) |
| 267 | + if ( isset( $params['titles'] ) ) { |
266 | 268 | $dataSource = 'titles'; |
267 | | - if ( isset ( $params['pageids'] ) ) { |
268 | | - if ( isset ( $dataSource ) ) |
| 269 | + } |
| 270 | + if ( isset( $params['pageids'] ) ) { |
| 271 | + if ( isset( $dataSource ) ) { |
269 | 272 | $this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' ); |
| 273 | + } |
270 | 274 | $dataSource = 'pageids'; |
271 | 275 | } |
272 | | - if ( isset ( $params['revids'] ) ) { |
273 | | - if ( isset ( $dataSource ) ) |
| 276 | + if ( isset( $params['revids'] ) ) { |
| 277 | + if ( isset( $dataSource ) ) { |
274 | 278 | $this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' ); |
| 279 | + } |
275 | 280 | $dataSource = 'revids'; |
276 | 281 | } |
277 | 282 | |
278 | 283 | switch ( $dataSource ) { |
279 | | - case 'titles' : |
| 284 | + case 'titles': |
280 | 285 | $this->initFromTitles( $params['titles'] ); |
281 | 286 | break; |
282 | | - case 'pageids' : |
| 287 | + case 'pageids': |
283 | 288 | $this->initFromPageIds( $params['pageids'] ); |
284 | 289 | break; |
285 | | - case 'revids' : |
286 | | - if ( $this->mResolveRedirects ) |
| 290 | + case 'revids': |
| 291 | + if ( $this->mResolveRedirects ) { |
287 | 292 | $this->setWarning( 'Redirect resolution cannot be used together with the revids= parameter. ' . |
288 | 293 | 'Any redirects the revids= point to have not been resolved.' ); |
| 294 | + } |
289 | 295 | $this->mResolveRedirects = false; |
290 | 296 | $this->initFromRevIDs( $params['revids'] ); |
291 | 297 | break; |
292 | | - default : |
| 298 | + default: |
293 | 299 | // Do nothing - some queries do not need any of the data sources. |
294 | 300 | break; |
295 | 301 | } |
— | — | @@ -341,9 +347,8 @@ |
342 | 348 | * @param $row Result row |
343 | 349 | */ |
344 | 350 | public function processDbRow( $row ) { |
345 | | - |
346 | 351 | // Store Title object in various data structures |
347 | | - $title = Title :: makeTitle( $row->page_namespace, $row->page_title ); |
| 352 | + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
348 | 353 | |
349 | 354 | $pageId = intval( $row->page_id ); |
350 | 355 | $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId; |
— | — | @@ -355,8 +360,9 @@ |
356 | 361 | $this->mGoodTitles[$pageId] = $title; |
357 | 362 | } |
358 | 363 | |
359 | | - foreach ( $this->mRequestedPageFields as $fieldName => & $fieldValues ) |
| 364 | + foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) { |
360 | 365 | $fieldValues[$pageId] = $row-> $fieldName; |
| 366 | + } |
361 | 367 | } |
362 | 368 | |
363 | 369 | /** |
— | — | @@ -385,11 +391,11 @@ |
386 | 392 | * @param $titles array of Title objects or strings |
387 | 393 | */ |
388 | 394 | private function initFromTitles( $titles ) { |
389 | | - |
390 | 395 | // Get validated and normalized title objects |
391 | 396 | $linkBatch = $this->processTitlesArray( $titles ); |
392 | | - if ( $linkBatch->isEmpty() ) |
| 397 | + if ( $linkBatch->isEmpty() ) { |
393 | 398 | return; |
| 399 | + } |
394 | 400 | |
395 | 401 | $db = $this->getDB(); |
396 | 402 | $set = $linkBatch->constructSet( 'page', $db ); |
— | — | @@ -401,7 +407,7 @@ |
402 | 408 | $this->profileDBOut(); |
403 | 409 | |
404 | 410 | // Hack: get the ns:titles stored in array(ns => array(titles)) format |
405 | | - $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles |
| 411 | + $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles |
406 | 412 | |
407 | 413 | // Resolve any found redirects |
408 | 414 | $this->resolvePendingRedirects(); |
— | — | @@ -412,11 +418,12 @@ |
413 | 419 | * @param $pageids array of page IDs |
414 | 420 | */ |
415 | 421 | private function initFromPageIds( $pageids ) { |
416 | | - if ( !count( $pageids ) ) |
| 422 | + if ( !count( $pageids ) ) { |
417 | 423 | return; |
| 424 | + } |
418 | 425 | |
419 | 426 | $pageids = array_map( 'intval', $pageids ); // paranoia |
420 | | - $set = array ( |
| 427 | + $set = array( |
421 | 428 | 'page_id' => $pageids |
422 | 429 | ); |
423 | 430 | $db = $this->getDB(); |
— | — | @@ -446,19 +453,20 @@ |
447 | 454 | * If false, treat it as an array of [pageIDs] |
448 | 455 | */ |
449 | 456 | private function initFromQueryResult( $db, $res, &$remaining = null, $processTitles = null ) { |
450 | | - if ( !is_null( $remaining ) && is_null( $processTitles ) ) |
451 | | - ApiBase :: dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' ); |
| 457 | + if ( !is_null( $remaining ) && is_null( $processTitles ) ) { |
| 458 | + ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' ); |
| 459 | + } |
452 | 460 | |
453 | 461 | while ( $row = $db->fetchObject( $res ) ) { |
454 | | - |
455 | 462 | $pageId = intval( $row->page_id ); |
456 | 463 | |
457 | 464 | // Remove found page from the list of remaining items |
458 | 465 | if ( isset( $remaining ) ) { |
459 | | - if ( $processTitles ) |
460 | | - unset ( $remaining[$row->page_namespace][$row->page_title] ); |
461 | | - else |
462 | | - unset ( $remaining[$pageId] ); |
| 466 | + if ( $processTitles ) { |
| 467 | + unset( $remaining[$row->page_namespace][$row->page_title] ); |
| 468 | + } else { |
| 469 | + unset( $remaining[$pageId] ); |
| 470 | + } |
463 | 471 | } |
464 | 472 | |
465 | 473 | // Store any extra fields requested by modules |
— | — | @@ -472,21 +480,20 @@ |
473 | 481 | // The remaining titles in $remaining are non-existent pages |
474 | 482 | foreach ( $remaining as $ns => $dbkeys ) { |
475 | 483 | foreach ( $dbkeys as $dbkey => $unused ) { |
476 | | - $title = Title :: makeTitle( $ns, $dbkey ); |
| 484 | + $title = Title::makeTitle( $ns, $dbkey ); |
477 | 485 | $this->mAllPages[$ns][$dbkey] = $this->mFakePageId; |
478 | 486 | $this->mMissingTitles[$this->mFakePageId] = $title; |
479 | 487 | $this->mFakePageId--; |
480 | 488 | $this->mTitles[] = $title; |
481 | 489 | } |
482 | 490 | } |
483 | | - } |
484 | | - else |
485 | | - { |
| 491 | + } else { |
486 | 492 | // The remaining pageids do not exist |
487 | | - if ( !$this->mMissingPageIDs ) |
| 493 | + if ( !$this->mMissingPageIDs ) { |
488 | 494 | $this->mMissingPageIDs = array_keys( $remaining ); |
489 | | - else |
| 495 | + } else { |
490 | 496 | $this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) ); |
| 497 | + } |
491 | 498 | } |
492 | 499 | } |
493 | 500 | } |
— | — | @@ -497,9 +504,9 @@ |
498 | 505 | * @param $revids array of revision IDs |
499 | 506 | */ |
500 | 507 | private function initFromRevIDs( $revids ) { |
501 | | - |
502 | | - if ( !count( $revids ) ) |
| 508 | + if ( !count( $revids ) ) { |
503 | 509 | return; |
| 510 | + } |
504 | 511 | |
505 | 512 | $revids = array_map( 'intval', $revids ); // paranoia |
506 | 513 | $db = $this->getDB(); |
— | — | @@ -535,7 +542,6 @@ |
536 | 543 | * have been resolved. |
537 | 544 | */ |
538 | 545 | private function resolvePendingRedirects() { |
539 | | - |
540 | 546 | if ( $this->mResolveRedirects ) { |
541 | 547 | $db = $this->getDB(); |
542 | 548 | $pageFlds = $this->getPageTableFields(); |
— | — | @@ -543,17 +549,18 @@ |
544 | 550 | // Repeat until all redirects have been resolved |
545 | 551 | // The infinite loop is prevented by keeping all known pages in $this->mAllPages |
546 | 552 | while ( $this->mPendingRedirectIDs ) { |
547 | | - |
548 | 553 | // Resolve redirects by querying the pagelinks table, and repeat the process |
549 | 554 | // Create a new linkBatch object for the next pass |
550 | 555 | $linkBatch = $this->getRedirectTargets(); |
551 | 556 | |
552 | | - if ( $linkBatch->isEmpty() ) |
| 557 | + if ( $linkBatch->isEmpty() ) { |
553 | 558 | break; |
| 559 | + } |
554 | 560 | |
555 | 561 | $set = $linkBatch->constructSet( 'page', $db ); |
556 | | - if ( $set === false ) |
| 562 | + if ( $set === false ) { |
557 | 563 | break; |
| 564 | + } |
558 | 565 | |
559 | 566 | // Get pageIDs data from the `page` table |
560 | 567 | $this->profileDBIn(); |
— | — | @@ -578,7 +585,9 @@ |
579 | 586 | $db = $this->getDB(); |
580 | 587 | |
581 | 588 | $this->profileDBIn(); |
582 | | - $res = $db->select( 'redirect', array( |
| 589 | + $res = $db->select( |
| 590 | + 'redirect', |
| 591 | + array( |
583 | 592 | 'rd_from', |
584 | 593 | 'rd_namespace', |
585 | 594 | 'rd_title' |
— | — | @@ -587,28 +596,27 @@ |
588 | 597 | ); |
589 | 598 | $this->profileDBOut(); |
590 | 599 | |
591 | | - while ( $row = $db->fetchObject( $res ) ) |
592 | | - { |
| 600 | + while ( $row = $db->fetchObject( $res ) ) { |
593 | 601 | $rdfrom = intval( $row->rd_from ); |
594 | 602 | $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText(); |
595 | 603 | $to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText(); |
596 | 604 | unset( $this->mPendingRedirectIDs[$rdfrom] ); |
597 | | - if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) |
| 605 | + if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) { |
598 | 606 | $lb->add( $row->rd_namespace, $row->rd_title ); |
| 607 | + } |
599 | 608 | $this->mRedirectTitles[$from] = $to; |
600 | 609 | } |
601 | 610 | $db->freeResult( $res ); |
602 | | - if ( $this->mPendingRedirectIDs ) |
603 | | - { |
| 611 | + if ( $this->mPendingRedirectIDs ) { |
604 | 612 | // We found pages that aren't in the redirect table |
605 | 613 | // Add them |
606 | | - foreach ( $this->mPendingRedirectIDs as $id => $title ) |
607 | | - { |
| 614 | + foreach ( $this->mPendingRedirectIDs as $id => $title ) { |
608 | 615 | $article = new Article( $title ); |
609 | 616 | $rt = $article->insertRedirect(); |
610 | | - if ( !$rt ) |
| 617 | + if ( !$rt ) { |
611 | 618 | // What the hell. Let's just ignore this |
612 | 619 | continue; |
| 620 | + } |
613 | 621 | $lb->addObj( $rt ); |
614 | 622 | $this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText(); |
615 | 623 | unset( $this->mPendingRedirectIDs[$id] ); |
— | — | @@ -627,14 +635,11 @@ |
628 | 636 | * @return LinkBatch |
629 | 637 | */ |
630 | 638 | private function processTitlesArray( $titles ) { |
631 | | - |
632 | 639 | $linkBatch = new LinkBatch(); |
633 | 640 | |
634 | 641 | foreach ( $titles as $title ) { |
635 | | - |
636 | | - $titleObj = is_string( $title ) ? Title :: newFromText( $title ) : $title; |
637 | | - if ( !$titleObj ) |
638 | | - { |
| 642 | + $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title; |
| 643 | + if ( !$titleObj ) { |
639 | 644 | // Handle invalid titles gracefully |
640 | 645 | $this->mAllpages[0][$title] = $this->mFakePageId; |
641 | 646 | $this->mInvalidTitles[$this->mFakePageId] = $title; |
— | — | @@ -646,12 +651,12 @@ |
647 | 652 | // This title is an interwiki link. |
648 | 653 | $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw; |
649 | 654 | } else { |
650 | | - |
651 | 655 | // Validation |
652 | | - if ( $titleObj->getNamespace() < 0 ) |
653 | | - $this->setWarning( "No support for special pages has been implemented" ); |
654 | | - else |
| 656 | + if ( $titleObj->getNamespace() < 0 ) { |
| 657 | + $this->setWarning( 'No support for special pages has been implemented' ); |
| 658 | + } else { |
655 | 659 | $linkBatch->addObj( $titleObj ); |
| 660 | + } |
656 | 661 | } |
657 | 662 | |
658 | 663 | // Make sure we remember the original title that was |
— | — | @@ -668,23 +673,23 @@ |
669 | 674 | } |
670 | 675 | |
671 | 676 | protected function getAllowedParams() { |
672 | | - return array ( |
673 | | - 'titles' => array ( |
674 | | - ApiBase :: PARAM_ISMULTI => true |
| 677 | + return array( |
| 678 | + 'titles' => array( |
| 679 | + ApiBase::PARAM_ISMULTI => true |
675 | 680 | ), |
676 | | - 'pageids' => array ( |
677 | | - ApiBase :: PARAM_TYPE => 'integer', |
678 | | - ApiBase :: PARAM_ISMULTI => true |
| 681 | + 'pageids' => array( |
| 682 | + ApiBase::PARAM_TYPE => 'integer', |
| 683 | + ApiBase::PARAM_ISMULTI => true |
679 | 684 | ), |
680 | | - 'revids' => array ( |
681 | | - ApiBase :: PARAM_TYPE => 'integer', |
682 | | - ApiBase :: PARAM_ISMULTI => true |
| 685 | + 'revids' => array( |
| 686 | + ApiBase::PARAM_TYPE => 'integer', |
| 687 | + ApiBase::PARAM_ISMULTI => true |
683 | 688 | ) |
684 | 689 | ); |
685 | 690 | } |
686 | 691 | |
687 | 692 | protected function getParamDescription() { |
688 | | - return array ( |
| 693 | + return array( |
689 | 694 | 'titles' => 'A list of titles to work on', |
690 | 695 | 'pageids' => 'A list of page IDs to work on', |
691 | 696 | 'revids' => 'A list of revision IDs to work on' |
Index: trunk/phase3/includes/api/ApiHelp.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 6, 2006 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 9 | + * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | } |
57 | 57 | |
58 | 58 | public function getDescription() { |
59 | | - return array ( |
| 59 | + return array( |
60 | 60 | 'Display this help screen.' |
61 | 61 | ); |
62 | 62 | } |
Index: trunk/phase3/includes/api/ApiPatrol.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 2, 2008 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.14+ |
8 | 8 | * |
9 | | - * Copyright (C) 2008 Soxred93 soxred93@gmail.com, |
| 9 | + * Copyright © 2008 Soxred93 soxred93@gmail.com, |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | class ApiPatrol extends ApiBase { |
36 | 36 | |
37 | 37 | public function __construct( $main, $action ) { |
38 | | - parent :: __construct( $main, $action ); |
| 38 | + parent::__construct( $main, $action ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
— | — | @@ -42,18 +42,21 @@ |
43 | 43 | */ |
44 | 44 | public function execute() { |
45 | 45 | $params = $this->extractRequestParams(); |
46 | | - |
47 | | - if ( !isset( $params['rcid'] ) ) |
| 46 | + |
| 47 | + if ( !isset( $params['rcid'] ) ) { |
48 | 48 | $this->dieUsageMsg( array( 'missingparam', 'rcid' ) ); |
| 49 | + } |
49 | 50 | |
50 | 51 | $rc = RecentChange::newFromID( $params['rcid'] ); |
51 | | - if ( !$rc instanceof RecentChange ) |
| 52 | + if ( !$rc instanceof RecentChange ) { |
52 | 53 | $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) ); |
| 54 | + } |
53 | 55 | $retval = RecentChange::markPatrolled( $params['rcid'] ); |
54 | | - |
55 | | - if ( $retval ) |
| 56 | + |
| 57 | + if ( $retval ) { |
56 | 58 | $this->dieUsageMsg( reset( $retval ) ); |
57 | | - |
| 59 | + } |
| 60 | + |
58 | 61 | $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ); |
59 | 62 | ApiQueryBase::addTitleInfo( $result, $rc->getTitle() ); |
60 | 63 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
— | — | @@ -64,34 +67,34 @@ |
65 | 68 | } |
66 | 69 | |
67 | 70 | public function getAllowedParams() { |
68 | | - return array ( |
| 71 | + return array( |
69 | 72 | 'token' => null, |
70 | 73 | 'rcid' => array( |
71 | | - ApiBase :: PARAM_TYPE => 'integer' |
| 74 | + ApiBase::PARAM_TYPE => 'integer' |
72 | 75 | ), |
73 | 76 | ); |
74 | 77 | } |
75 | 78 | |
76 | 79 | public function getParamDescription() { |
77 | | - return array ( |
| 80 | + return array( |
78 | 81 | 'token' => 'Patrol token obtained from list=recentchanges', |
79 | 82 | 'rcid' => 'Recentchanges ID to patrol', |
80 | 83 | ); |
81 | 84 | } |
82 | 85 | |
83 | 86 | public function getDescription() { |
84 | | - return array ( |
| 87 | + return array( |
85 | 88 | 'Patrol a page or revision. ' |
86 | 89 | ); |
87 | 90 | } |
88 | | - |
89 | | - public function getPossibleErrors() { |
| 91 | + |
| 92 | + public function getPossibleErrors() { |
90 | 93 | return array_merge( parent::getPossibleErrors(), array( |
91 | 94 | array( 'missingparam', 'rcid' ), |
92 | 95 | array( 'nosuchrcid', 'rcid' ), |
93 | | - ) ); |
| 96 | + ) ); |
94 | 97 | } |
95 | | - |
| 98 | + |
96 | 99 | public function getTokenSalt() { |
97 | 100 | return ''; |
98 | 101 | } |
Index: trunk/phase3/includes/api/ApiParamInfo.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Dec 01, 2007 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 9 | + * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | if ( !defined( 'MEDIAWIKI' ) ) { |
28 | 28 | // Eclipse helper - will be ignored in production |
29 | | - require_once ( "ApiBase.php" ); |
| 29 | + require_once( "ApiBase.php" ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | class ApiParamInfo extends ApiBase { |
36 | 36 | |
37 | 37 | public function __construct( $main, $action ) { |
38 | | - parent :: __construct( $main, $action ); |
| 38 | + parent::__construct( $main, $action ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function execute() { |
— | — | @@ -43,14 +43,11 @@ |
44 | 44 | $result = $this->getResult(); |
45 | 45 | $queryObj = new ApiQuery( $this->getMain(), 'query' ); |
46 | 46 | $r = array(); |
47 | | - if ( is_array( $params['modules'] ) ) |
48 | | - { |
| 47 | + if ( is_array( $params['modules'] ) ) { |
49 | 48 | $modArr = $this->getMain()->getModules(); |
50 | 49 | $r['modules'] = array(); |
51 | | - foreach ( $params['modules'] as $m ) |
52 | | - { |
53 | | - if ( !isset( $modArr[$m] ) ) |
54 | | - { |
| 50 | + foreach ( $params['modules'] as $m ) { |
| 51 | + if ( !isset( $modArr[$m] ) ) { |
55 | 52 | $r['modules'][] = array( 'name' => $m, 'missing' => '' ); |
56 | 53 | continue; |
57 | 54 | } |
— | — | @@ -61,14 +58,11 @@ |
62 | 59 | } |
63 | 60 | $result->setIndexedTagName( $r['modules'], 'module' ); |
64 | 61 | } |
65 | | - if ( is_array( $params['querymodules'] ) ) |
66 | | - { |
| 62 | + if ( is_array( $params['querymodules'] ) ) { |
67 | 63 | $qmodArr = $queryObj->getModules(); |
68 | 64 | $r['querymodules'] = array(); |
69 | | - foreach ( $params['querymodules'] as $qm ) |
70 | | - { |
71 | | - if ( !isset( $qmodArr[$qm] ) ) |
72 | | - { |
| 65 | + foreach ( $params['querymodules'] as $qm ) { |
| 66 | + if ( !isset( $qmodArr[$qm] ) ) { |
73 | 67 | $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' ); |
74 | 68 | continue; |
75 | 69 | } |
— | — | @@ -79,60 +73,59 @@ |
80 | 74 | } |
81 | 75 | $result->setIndexedTagName( $r['querymodules'], 'module' ); |
82 | 76 | } |
83 | | - if ( $params['mainmodule'] ) |
| 77 | + if ( $params['mainmodule'] ) { |
84 | 78 | $r['mainmodule'] = $this->getClassInfo( $this->getMain() ); |
85 | | - if ( $params['pagesetmodule'] ) |
86 | | - { |
| 79 | + } |
| 80 | + if ( $params['pagesetmodule'] ) { |
87 | 81 | $pageSet = new ApiPageSet( $queryObj ); |
88 | 82 | $r['pagesetmodule'] = $this->getClassInfo( $pageSet ); |
89 | 83 | } |
90 | 84 | $result->addValue( null, $this->getModuleName(), $r ); |
91 | 85 | } |
92 | 86 | |
93 | | - function getClassInfo( $obj ) |
94 | | - { |
| 87 | + function getClassInfo( $obj ) { |
95 | 88 | $result = $this->getResult(); |
96 | 89 | $retval['classname'] = get_class( $obj ); |
97 | 90 | $retval['description'] = implode( "\n", (array)$obj->getDescription() ); |
98 | 91 | $retval['version'] = implode( "\n", (array)$obj->getVersion() ); |
99 | 92 | $retval['prefix'] = $obj->getModulePrefix(); |
100 | 93 | |
101 | | - if ( $obj->isReadMode() ) |
| 94 | + if ( $obj->isReadMode() ) { |
102 | 95 | $retval['readrights'] = ''; |
103 | | - if ( $obj->isWriteMode() ) |
| 96 | + } |
| 97 | + if ( $obj->isWriteMode() ) { |
104 | 98 | $retval['writerights'] = ''; |
105 | | - if ( $obj->mustBePosted() ) |
| 99 | + } |
| 100 | + if ( $obj->mustBePosted() ) { |
106 | 101 | $retval['mustbeposted'] = ''; |
107 | | - if ( $obj instanceof ApiQueryGeneratorBase ) |
| 102 | + } |
| 103 | + if ( $obj instanceof ApiQueryGeneratorBase ) { |
108 | 104 | $retval['generator'] = ''; |
| 105 | + } |
109 | 106 | |
110 | 107 | $allowedParams = $obj->getFinalParams(); |
111 | | - if ( !is_array( $allowedParams ) ) |
| 108 | + if ( !is_array( $allowedParams ) ) { |
112 | 109 | return $retval; |
113 | | - |
| 110 | + } |
| 111 | + |
114 | 112 | $retval['parameters'] = array(); |
115 | 113 | $paramDesc = $obj->getFinalParamDescription(); |
116 | | - foreach ( $allowedParams as $n => $p ) |
117 | | - { |
| 114 | + foreach ( $allowedParams as $n => $p ) { |
118 | 115 | $a = array( 'name' => $n ); |
119 | | - if ( isset( $paramDesc[$n] ) ) |
| 116 | + if ( isset( $paramDesc[$n] ) ) { |
120 | 117 | $a['description'] = implode( "\n", (array)$paramDesc[$n] ); |
121 | | - if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) |
| 118 | + } |
| 119 | + if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) { |
122 | 120 | $a['deprecated'] = ''; |
123 | | - if ( !is_array( $p ) ) |
124 | | - { |
125 | | - if ( is_bool( $p ) ) |
126 | | - { |
| 121 | + } |
| 122 | + if ( !is_array( $p ) ) { |
| 123 | + if ( is_bool( $p ) ) { |
127 | 124 | $a['type'] = 'bool'; |
128 | 125 | $a['default'] = ( $p ? 'true' : 'false' ); |
129 | | - } |
130 | | - else if ( is_string( $p ) || is_null( $p ) ) |
131 | | - { |
| 126 | + } elseif ( is_string( $p ) || is_null( $p ) ) { |
132 | 127 | $a['type'] = 'string'; |
133 | 128 | $a['default'] = strval( $p ); |
134 | | - } |
135 | | - else if ( is_int( $p ) ) |
136 | | - { |
| 129 | + } elseif ( is_int( $p ) ) { |
137 | 130 | $a['type'] = 'integer'; |
138 | 131 | $a['default'] = intval( $p ); |
139 | 132 | } |
— | — | @@ -140,42 +133,48 @@ |
141 | 134 | continue; |
142 | 135 | } |
143 | 136 | |
144 | | - if ( isset( $p[ApiBase::PARAM_DFLT] ) ) |
| 137 | + if ( isset( $p[ApiBase::PARAM_DFLT] ) ) { |
145 | 138 | $a['default'] = $p[ApiBase::PARAM_DFLT]; |
146 | | - if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) |
147 | | - if ( $p[ApiBase::PARAM_ISMULTI] ) |
148 | | - { |
| 139 | + } |
| 140 | + if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) { |
| 141 | + if ( $p[ApiBase::PARAM_ISMULTI] ) { |
149 | 142 | $a['multi'] = ''; |
150 | 143 | $a['limit'] = $this->getMain()->canApiHighLimits() ? |
151 | 144 | ApiBase::LIMIT_SML2 : |
152 | 145 | ApiBase::LIMIT_SML1; |
153 | 146 | } |
| 147 | + } |
154 | 148 | |
155 | | - if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) |
156 | | - if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) |
| 149 | + if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) { |
| 150 | + if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) { |
157 | 151 | $a['allowsduplicates'] = ''; |
| 152 | + } |
| 153 | + } |
158 | 154 | |
159 | | - if ( isset( $p[ApiBase::PARAM_TYPE] ) ) |
160 | | - { |
| 155 | + if ( isset( $p[ApiBase::PARAM_TYPE] ) ) { |
161 | 156 | $a['type'] = $p[ApiBase::PARAM_TYPE]; |
162 | | - if ( is_array( $a['type'] ) ) |
| 157 | + if ( is_array( $a['type'] ) ) { |
163 | 158 | $result->setIndexedTagName( $a['type'], 't' ); |
| 159 | + } |
164 | 160 | } |
165 | | - if ( isset( $p[ApiBase::PARAM_MAX] ) ) |
| 161 | + if ( isset( $p[ApiBase::PARAM_MAX] ) ) { |
166 | 162 | $a['max'] = $p[ApiBase::PARAM_MAX]; |
167 | | - if ( isset( $p[ApiBase::PARAM_MAX2] ) ) |
| 163 | + } |
| 164 | + if ( isset( $p[ApiBase::PARAM_MAX2] ) ) { |
168 | 165 | $a['highmax'] = $p[ApiBase::PARAM_MAX2]; |
169 | | - if ( isset( $p[ApiBase::PARAM_MIN] ) ) |
| 166 | + } |
| 167 | + if ( isset( $p[ApiBase::PARAM_MIN] ) ) { |
170 | 168 | $a['min'] = $p[ApiBase::PARAM_MIN]; |
| 169 | + } |
171 | 170 | $retval['parameters'][] = $a; |
172 | 171 | } |
173 | 172 | $result->setIndexedTagName( $retval['parameters'], 'param' ); |
174 | | - |
| 173 | + |
175 | 174 | // Errors |
176 | 175 | $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() ); |
177 | | - |
| 176 | + |
178 | 177 | $result->setIndexedTagName( $retval['errors'], 'error' ); |
179 | | - |
| 178 | + |
180 | 179 | return $retval; |
181 | 180 | } |
182 | 181 | |
— | — | @@ -184,12 +183,12 @@ |
185 | 184 | } |
186 | 185 | |
187 | 186 | public function getAllowedParams() { |
188 | | - return array ( |
| 187 | + return array( |
189 | 188 | 'modules' => array( |
190 | | - ApiBase :: PARAM_ISMULTI => true |
| 189 | + ApiBase::PARAM_ISMULTI => true |
191 | 190 | ), |
192 | 191 | 'querymodules' => array( |
193 | | - ApiBase :: PARAM_ISMULTI => true |
| 192 | + ApiBase::PARAM_ISMULTI => true |
194 | 193 | ), |
195 | 194 | 'mainmodule' => false, |
196 | 195 | 'pagesetmodule' => false, |
— | — | @@ -197,7 +196,7 @@ |
198 | 197 | } |
199 | 198 | |
200 | 199 | public function getParamDescription() { |
201 | | - return array ( |
| 200 | + return array( |
202 | 201 | 'modules' => 'List of module names (value of the action= parameter)', |
203 | 202 | 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)', |
204 | 203 | 'mainmodule' => 'Get information about the main (top-level) module as well', |
— | — | @@ -210,7 +209,7 @@ |
211 | 210 | } |
212 | 211 | |
213 | 212 | protected function getExamples() { |
214 | | - return array ( |
| 213 | + return array( |
215 | 214 | 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo' |
216 | 215 | ); |
217 | 216 | } |