Index: trunk/phase3/includes/api/ApiWatch.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 | /** |
— | — | @@ -36,35 +36,35 @@ |
37 | 37 | class ApiWatch 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->isLoggedIn() ) |
| 45 | + if ( !$wgUser->isLoggedIn() ) { |
46 | 46 | $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); |
| 47 | + } |
47 | 48 | |
48 | 49 | $params = $this->extractRequestParams(); |
49 | 50 | $title = Title::newFromText( $params['title'] ); |
50 | 51 | |
51 | | - if ( !$title ) |
| 52 | + if ( !$title ) { |
52 | 53 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
| 54 | + } |
53 | 55 | |
54 | 56 | $article = new Article( $title ); |
55 | 57 | $res = array( 'title' => $title->getPrefixedText() ); |
56 | 58 | |
57 | | - if ( $params['unwatch'] ) |
58 | | - { |
| 59 | + if ( $params['unwatch'] ) { |
59 | 60 | $res['unwatched'] = ''; |
60 | 61 | $success = $article->doUnwatch(); |
61 | | - } |
62 | | - else |
63 | | - { |
| 62 | + } else { |
64 | 63 | $res['watched'] = ''; |
65 | 64 | $success = $article->doWatch(); |
66 | 65 | } |
67 | | - if ( !$success ) |
| 66 | + if ( !$success ) { |
68 | 67 | $this->dieUsageMsg( array( 'hookaborted' ) ); |
| 68 | + } |
69 | 69 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
70 | 70 | } |
71 | 71 | |
— | — | @@ -73,25 +73,25 @@ |
74 | 74 | } |
75 | 75 | |
76 | 76 | public function getAllowedParams() { |
77 | | - return array ( |
| 77 | + return array( |
78 | 78 | 'title' => null, |
79 | 79 | 'unwatch' => false, |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | public function getParamDescription() { |
84 | | - return array ( |
| 84 | + return array( |
85 | 85 | 'title' => 'The page to (un)watch', |
86 | 86 | 'unwatch' => 'If set the page will be unwatched rather than watched', |
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
90 | 90 | public function getDescription() { |
91 | | - return array ( |
| 91 | + return array( |
92 | 92 | 'Add or remove a page from/to the current user\'s watchlist' |
93 | 93 | ); |
94 | 94 | } |
95 | | - |
| 95 | + |
96 | 96 | public function getPossibleErrors() { |
97 | 97 | return array_merge( parent::getPossibleErrors(), array( |
98 | 98 | array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ), |
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 25, 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 |
— | — | @@ -36,16 +36,14 @@ |
37 | 37 | class ApiQuerySiteinfo extends ApiQueryBase { |
38 | 38 | |
39 | 39 | public function __construct( $query, $moduleName ) { |
40 | | - parent :: __construct( $query, $moduleName, 'si' ); |
| 40 | + parent::__construct( $query, $moduleName, 'si' ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
44 | 44 | $params = $this->extractRequestParams(); |
45 | 45 | $done = array(); |
46 | | - foreach ( $params['prop'] as $p ) |
47 | | - { |
48 | | - switch ( $p ) |
49 | | - { |
| 46 | + foreach ( $params['prop'] as $p ) { |
| 47 | + switch ( $p ) { |
50 | 48 | case 'general': |
51 | 49 | $fit = $this->appendGeneralInfo( $p ); |
52 | 50 | break; |
— | — | @@ -86,11 +84,10 @@ |
87 | 85 | case 'languages': |
88 | 86 | $fit = $this->appendLanguages( $p ); |
89 | 87 | break; |
90 | | - default : |
91 | | - ApiBase :: dieDebug( __METHOD__, "Unknown prop=$p" ); |
| 88 | + default: |
| 89 | + ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" ); |
92 | 90 | } |
93 | | - if ( !$fit ) |
94 | | - { |
| 91 | + if ( !$fit ) { |
95 | 92 | // Abuse siprop as a query-continue parameter |
96 | 93 | // and set it to all unprocessed props |
97 | 94 | $this->setContinueEnumParameter( 'prop', implode( '|', |
— | — | @@ -102,11 +99,10 @@ |
103 | 100 | } |
104 | 101 | |
105 | 102 | protected function appendGeneralInfo( $property ) { |
106 | | - global $wgContLang; |
107 | | - global $wgLang; |
| 103 | + global $wgContLang, $wgLang; |
108 | 104 | |
109 | 105 | $data = array(); |
110 | | - $mainPage = Title :: newFromText( wfMsgForContent( 'mainpage' ) ); |
| 106 | + $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) ); |
111 | 107 | $data['mainpage'] = $mainPage->getPrefixedText(); |
112 | 108 | $data['base'] = $mainPage->getFullUrl(); |
113 | 109 | $data['sitename'] = $GLOBALS['wgSitename']; |
— | — | @@ -117,26 +113,30 @@ |
118 | 114 | $data['dbversion'] = $this->getDB()->getServerVersion(); |
119 | 115 | |
120 | 116 | $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] ); |
121 | | - if ( $svn ) |
| 117 | + if ( $svn ) { |
122 | 118 | $data['rev'] = $svn; |
| 119 | + } |
123 | 120 | |
124 | 121 | // 'case-insensitive' option is reserved for future |
125 | 122 | $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive'; |
126 | 123 | |
127 | | - if ( isset( $GLOBALS['wgRightsCode'] ) ) |
| 124 | + if ( isset( $GLOBALS['wgRightsCode'] ) ) { |
128 | 125 | $data['rightscode'] = $GLOBALS['wgRightsCode']; |
| 126 | + } |
129 | 127 | $data['rights'] = $GLOBALS['wgRightsText']; |
130 | 128 | $data['lang'] = $GLOBALS['wgLanguageCode']; |
131 | | - if ( $wgContLang->isRTL() ) |
| 129 | + if ( $wgContLang->isRTL() ) { |
132 | 130 | $data['rtl'] = ''; |
| 131 | + } |
133 | 132 | $data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding(); |
134 | | - |
| 133 | + |
135 | 134 | if ( wfReadOnly() ) { |
136 | 135 | $data['readonly'] = ''; |
137 | 136 | $data['readonlyreason'] = wfReadOnlyReason(); |
138 | 137 | } |
139 | | - if ( $GLOBALS['wgEnableWriteAPI'] ) |
| 138 | + if ( $GLOBALS['wgEnableWriteAPI'] ) { |
140 | 139 | $data['writeapi'] = ''; |
| 140 | + } |
141 | 141 | |
142 | 142 | $tz = $GLOBALS['wgLocaltimezone']; |
143 | 143 | $offset = $GLOBALS['wgLocalTZoffset']; |
— | — | @@ -162,23 +162,25 @@ |
163 | 163 | protected function appendNamespaces( $property ) { |
164 | 164 | global $wgContLang; |
165 | 165 | $data = array(); |
166 | | - foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) |
167 | | - { |
| 166 | + foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) { |
168 | 167 | $data[$ns] = array( |
169 | 168 | 'id' => intval( $ns ), |
170 | 169 | 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive', |
171 | 170 | ); |
172 | | - ApiResult :: setContent( $data[$ns], $title ); |
| 171 | + ApiResult::setContent( $data[$ns], $title ); |
173 | 172 | $canonical = MWNamespace::getCanonicalName( $ns ); |
174 | | - |
175 | | - if ( MWNamespace::hasSubpages( $ns ) ) |
| 173 | + |
| 174 | + if ( MWNamespace::hasSubpages( $ns ) ) { |
176 | 175 | $data[$ns]['subpages'] = ''; |
177 | | - |
178 | | - if ( $canonical ) |
| 176 | + } |
| 177 | + |
| 178 | + if ( $canonical ) { |
179 | 179 | $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' ); |
180 | | - |
181 | | - if ( MWNamespace::isContent( $ns ) ) |
| 180 | + } |
| 181 | + |
| 182 | + if ( MWNamespace::isContent( $ns ) ) { |
182 | 183 | $data[$ns]['content'] = ''; |
| 184 | + } |
183 | 185 | } |
184 | 186 | |
185 | 187 | $this->getResult()->setIndexedTagName( $data, 'ns' ); |
— | — | @@ -198,7 +200,7 @@ |
199 | 201 | $item = array( |
200 | 202 | 'id' => intval( $ns ) |
201 | 203 | ); |
202 | | - ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) ); |
| 204 | + ApiResult::setContent( $item, strtr( $title, '_', ' ' ) ); |
203 | 205 | $data[] = $item; |
204 | 206 | } |
205 | 207 | |
— | — | @@ -218,16 +220,16 @@ |
219 | 221 | $this->getResult()->setIndexedTagName( $data, 'specialpage' ); |
220 | 222 | return $this->getResult()->addValue( 'query', $property, $data ); |
221 | 223 | } |
222 | | - |
| 224 | + |
223 | 225 | protected function appendMagicWords( $property ) { |
224 | 226 | global $wgContLang; |
225 | 227 | $data = array(); |
226 | | - foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) |
227 | | - { |
| 228 | + foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) { |
228 | 229 | $caseSensitive = array_shift( $aliases ); |
229 | 230 | $arr = array( 'name' => $magicword, 'aliases' => $aliases ); |
230 | | - if ( $caseSensitive ) |
| 231 | + if ( $caseSensitive ) { |
231 | 232 | $arr['case-sensitive'] = ''; |
| 233 | + } |
232 | 234 | $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' ); |
233 | 235 | $data[] = $arr; |
234 | 236 | } |
— | — | @@ -240,12 +242,13 @@ |
241 | 243 | $this->addTables( 'interwiki' ); |
242 | 244 | $this->addFields( array( 'iw_prefix', 'iw_local', 'iw_url' ) ); |
243 | 245 | |
244 | | - if ( $filter === 'local' ) |
| 246 | + if ( $filter === 'local' ) { |
245 | 247 | $this->addWhere( 'iw_local = 1' ); |
246 | | - elseif ( $filter === '!local' ) |
| 248 | + } elseif ( $filter === '!local' ) { |
247 | 249 | $this->addWhere( 'iw_local = 0' ); |
248 | | - elseif ( $filter ) |
249 | | - ApiBase :: dieDebug( __METHOD__, "Unknown filter=$filter" ); |
| 250 | + } elseif ( $filter ) { |
| 251 | + ApiBase::dieDebug( __METHOD__, "Unknown filter=$filter" ); |
| 252 | + } |
250 | 253 | |
251 | 254 | $this->addOption( 'ORDER BY', 'iw_prefix' ); |
252 | 255 | |
— | — | @@ -254,15 +257,16 @@ |
255 | 258 | |
256 | 259 | $data = array(); |
257 | 260 | $langNames = Language::getLanguageNames(); |
258 | | - while ( $row = $db->fetchObject( $res ) ) |
259 | | - { |
| 261 | + while ( $row = $db->fetchObject( $res ) ) { |
260 | 262 | $val = array(); |
261 | 263 | $val['prefix'] = $row->iw_prefix; |
262 | | - if ( $row->iw_local == '1' ) |
| 264 | + if ( $row->iw_local == '1' ) { |
263 | 265 | $val['local'] = ''; |
264 | | -// $val['trans'] = intval($row->iw_trans); // should this be exposed? |
265 | | - if ( isset( $langNames[$row->iw_prefix] ) ) |
| 266 | + } |
| 267 | +// $val['trans'] = intval( $row->iw_trans ); // should this be exposed? |
| 268 | + if ( isset( $langNames[$row->iw_prefix] ) ) { |
266 | 269 | $val['language'] = $langNames[$row->iw_prefix]; |
| 270 | + } |
267 | 271 | $val['url'] = $row->iw_url; |
268 | 272 | |
269 | 273 | $data[] = $val; |
— | — | @@ -277,8 +281,9 @@ |
278 | 282 | global $wgShowHostnames; |
279 | 283 | $data = array(); |
280 | 284 | if ( $includeAll ) { |
281 | | - if ( !$wgShowHostnames ) |
| 285 | + if ( !$wgShowHostnames ) { |
282 | 286 | $this->dieUsage( 'Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied' ); |
| 287 | + } |
283 | 288 | |
284 | 289 | $lb = wfGetLB(); |
285 | 290 | $lags = $lb->getLagTimes(); |
— | — | @@ -326,9 +331,10 @@ |
327 | 332 | 'name' => $group, |
328 | 333 | 'rights' => array_keys( $permissions, true ), |
329 | 334 | ); |
330 | | - if ( $numberInGroup ) |
| 335 | + if ( $numberInGroup ) { |
331 | 336 | $arr['number'] = SiteStats::numberInGroup( $group ); |
332 | | - |
| 337 | + } |
| 338 | + |
333 | 339 | $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' ); |
334 | 340 | $data[] = $arr; |
335 | 341 | } |
— | — | @@ -336,10 +342,10 @@ |
337 | 343 | $this->getResult()->setIndexedTagName( $data, 'group' ); |
338 | 344 | return $this->getResult()->addValue( 'query', $property, $data ); |
339 | 345 | } |
340 | | - |
| 346 | + |
341 | 347 | protected function appendFileExtensions( $property ) { |
342 | 348 | global $wgFileExtensions; |
343 | | - |
| 349 | + |
344 | 350 | $data = array(); |
345 | 351 | foreach ( $wgFileExtensions as $ext ) { |
346 | 352 | $data[] = array( 'ext' => $ext ); |
— | — | @@ -355,10 +361,12 @@ |
356 | 362 | foreach ( $extensions as $ext ) { |
357 | 363 | $ret = array(); |
358 | 364 | $ret['type'] = $type; |
359 | | - if ( isset( $ext['name'] ) ) |
| 365 | + if ( isset( $ext['name'] ) ) { |
360 | 366 | $ret['name'] = $ext['name']; |
361 | | - if ( isset( $ext['description'] ) ) |
| 367 | + } |
| 368 | + if ( isset( $ext['description'] ) ) { |
362 | 369 | $ret['description'] = $ext['description']; |
| 370 | + } |
363 | 371 | if ( isset( $ext['descriptionmsg'] ) ) { |
364 | 372 | // Can be a string or array( key, param1, param2, ... ) |
365 | 373 | if ( is_array( $ext['descriptionmsg'] ) ) { |
— | — | @@ -421,13 +429,12 @@ |
422 | 430 | return $this->getResult()->addValue( 'query', $property, $data ); |
423 | 431 | } |
424 | 432 | |
425 | | - |
426 | 433 | public function getAllowedParams() { |
427 | 434 | return array( |
428 | 435 | 'prop' => array( |
429 | | - ApiBase :: PARAM_DFLT => 'general', |
430 | | - ApiBase :: PARAM_ISMULTI => true, |
431 | | - ApiBase :: PARAM_TYPE => array( |
| 436 | + ApiBase::PARAM_DFLT => 'general', |
| 437 | + ApiBase::PARAM_ISMULTI => true, |
| 438 | + ApiBase::PARAM_TYPE => array( |
432 | 439 | 'general', |
433 | 440 | 'namespaces', |
434 | 441 | 'namespacealiases', |
— | — | @@ -444,7 +451,7 @@ |
445 | 452 | ) |
446 | 453 | ), |
447 | 454 | 'filteriw' => array( |
448 | | - ApiBase :: PARAM_TYPE => array( |
| 455 | + ApiBase::PARAM_TYPE => array( |
449 | 456 | 'local', |
450 | 457 | '!local', |
451 | 458 | ) |
— | — | @@ -493,7 +500,7 @@ |
494 | 501 | 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics', |
495 | 502 | 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local', |
496 | 503 | 'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb', |
497 | | - ); |
| 504 | + ); |
498 | 505 | } |
499 | 506 | |
500 | 507 | public function getVersion() { |
Index: trunk/phase3/includes/api/ApiRollback.php |
— | — | @@ -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,39 +33,45 @@ |
34 | 34 | class ApiRollback 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 | 41 | $params = $this->extractRequestParams(); |
42 | 42 | |
43 | 43 | $titleObj = null; |
44 | | - if ( !isset( $params['title'] ) ) |
| 44 | + if ( !isset( $params['title'] ) ) { |
45 | 45 | $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
46 | | - if ( !isset( $params['user'] ) ) |
| 46 | + } |
| 47 | + if ( !isset( $params['user'] ) ) { |
47 | 48 | $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
| 49 | + } |
48 | 50 | |
49 | 51 | $titleObj = Title::newFromText( $params['title'] ); |
50 | | - if ( !$titleObj ) |
| 52 | + if ( !$titleObj ) { |
51 | 53 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
52 | | - if ( !$titleObj->exists() ) |
| 54 | + } |
| 55 | + if ( !$titleObj->exists() ) { |
53 | 56 | $this->dieUsageMsg( array( 'notanarticle' ) ); |
| 57 | + } |
54 | 58 | |
55 | 59 | // We need to be able to revert IPs, but getCanonicalName rejects them |
56 | 60 | $username = User::isIP( $params['user'] ) |
57 | 61 | ? $params['user'] |
58 | 62 | : User::getCanonicalName( $params['user'] ); |
59 | | - if ( !$username ) |
| 63 | + if ( !$username ) { |
60 | 64 | $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) ); |
| 65 | + } |
61 | 66 | |
62 | 67 | $articleObj = new Article( $titleObj ); |
63 | | - $summary = ( isset( $params['summary'] ) ? $params['summary'] : "" ); |
| 68 | + $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' ); |
64 | 69 | $details = null; |
65 | 70 | $retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details ); |
66 | 71 | |
67 | | - if ( $retval ) |
| 72 | + if ( $retval ) { |
68 | 73 | // We don't care about multiple errors, just report one of them |
69 | 74 | $this->dieUsageMsg( reset( $retval ) ); |
| 75 | + } |
70 | 76 | |
71 | 77 | $info = array( |
72 | 78 | 'title' => $titleObj->getPrefixedText(), |
— | — | @@ -79,14 +85,16 @@ |
80 | 86 | $this->getResult()->addValue( null, $this->getModuleName(), $info ); |
81 | 87 | } |
82 | 88 | |
83 | | - public function mustBePosted() { return true; } |
| 89 | + public function mustBePosted() { |
| 90 | + return true; |
| 91 | + } |
84 | 92 | |
85 | 93 | public function isWriteMode() { |
86 | 94 | return true; |
87 | 95 | } |
88 | 96 | |
89 | 97 | public function getAllowedParams() { |
90 | | - return array ( |
| 98 | + return array( |
91 | 99 | 'title' => null, |
92 | 100 | 'user' => null, |
93 | 101 | 'token' => null, |
— | — | @@ -96,7 +104,7 @@ |
97 | 105 | } |
98 | 106 | |
99 | 107 | public function getParamDescription() { |
100 | | - return array ( |
| 108 | + return array( |
101 | 109 | 'title' => 'Title of the page you want to rollback.', |
102 | 110 | 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.', |
103 | 111 | 'token' => 'A rollback token previously retrieved through prop=revisions', |
— | — | @@ -107,11 +115,11 @@ |
108 | 116 | |
109 | 117 | public function getDescription() { |
110 | 118 | return array( |
111 | | - 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,', |
112 | | - 'they will all be rolled back.' |
113 | | - ); |
| 119 | + 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,', |
| 120 | + 'they will all be rolled back.' |
| 121 | + ); |
114 | 122 | } |
115 | | - |
| 123 | + |
116 | 124 | public function getPossibleErrors() { |
117 | 125 | return array_merge( parent::getPossibleErrors(), array( |
118 | 126 | array( 'missingparam', 'title' ), |
— | — | @@ -121,13 +129,13 @@ |
122 | 130 | array( 'invaliduser', 'user' ), |
123 | 131 | ) ); |
124 | 132 | } |
125 | | - |
| 133 | + |
126 | 134 | public function getTokenSalt() { |
127 | 135 | return ''; |
128 | 136 | } |
129 | 137 | |
130 | 138 | protected function getExamples() { |
131 | | - return array ( |
| 139 | + return array( |
132 | 140 | 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC', |
133 | 141 | 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1' |
134 | 142 | ); |
Index: trunk/phase3/includes/api/ApiUserrights.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Mar 24, 2009 |
6 | 6 | * API for MediaWiki 1.8+ |
7 | 7 | * |
8 | | - * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 8 | + * Copyright © 2009 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,16 +33,16 @@ |
34 | 34 | class ApiUserrights 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 | 41 | $params = $this->extractRequestParams(); |
42 | | - |
| 42 | + |
43 | 43 | // User already validated in call to getTokenSalt from Main |
44 | 44 | $form = new UserrightsPage; |
45 | 45 | $user = $form->fetchUser( $params['user'] ); |
46 | | - |
| 46 | + |
47 | 47 | $r['user'] = $user->getName(); |
48 | 48 | list( $r['added'], $r['removed'] ) = |
49 | 49 | $form->doSaveUserGroups( |
— | — | @@ -66,22 +66,22 @@ |
67 | 67 | return array ( |
68 | 68 | 'user' => null, |
69 | 69 | 'add' => array( |
70 | | - ApiBase :: PARAM_TYPE => User::getAllGroups(), |
71 | | - ApiBase :: PARAM_ISMULTI => true |
| 70 | + ApiBase::PARAM_TYPE => User::getAllGroups(), |
| 71 | + ApiBase::PARAM_ISMULTI => true |
72 | 72 | ), |
73 | 73 | 'remove' => array( |
74 | | - ApiBase :: PARAM_TYPE => User::getAllGroups(), |
75 | | - ApiBase :: PARAM_ISMULTI => true |
| 74 | + ApiBase::PARAM_TYPE => User::getAllGroups(), |
| 75 | + ApiBase::PARAM_ISMULTI => true |
76 | 76 | ), |
77 | 77 | 'token' => null, |
78 | 78 | 'reason' => array( |
79 | | - ApiBase :: PARAM_DFLT => '' |
| 79 | + ApiBase::PARAM_DFLT => '' |
80 | 80 | ) |
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
84 | 84 | public function getParamDescription() { |
85 | | - return array ( |
| 85 | + return array( |
86 | 86 | 'user' => 'User name', |
87 | 87 | 'add' => 'Add the user to these groups', |
88 | 88 | 'remove' => 'Remove the user from these groups', |
— | — | @@ -95,29 +95,31 @@ |
96 | 96 | 'Add/remove a user to/from groups', |
97 | 97 | ); |
98 | 98 | } |
99 | | - |
100 | | - public function getPossibleErrors() { |
| 99 | + |
| 100 | + public function getPossibleErrors() { |
101 | 101 | return array_merge( parent::getPossibleErrors(), array( |
102 | 102 | array( 'missingparam', 'user' ), |
103 | | - ) ); |
| 103 | + ) ); |
104 | 104 | } |
105 | | - |
| 105 | + |
106 | 106 | public function getTokenSalt() { |
107 | 107 | $params = $this->extractRequestParams(); |
108 | | - if ( is_null( $params['user'] ) ) |
| 108 | + if ( is_null( $params['user'] ) ) { |
109 | 109 | $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
| 110 | + } |
110 | 111 | |
111 | 112 | $form = new UserrightsPage; |
112 | 113 | $user = $form->fetchUser( $params['user'] ); |
113 | | - if ( $user instanceof WikiErrorMsg ) |
| 114 | + if ( $user instanceof WikiErrorMsg ) { |
114 | 115 | $this->dieUsageMsg( array_merge( |
115 | 116 | (array)$user->getMessageKey(), $user->getMessageArgs() ) ); |
| 117 | + } |
116 | 118 | |
117 | 119 | return $user->getName(); |
118 | 120 | } |
119 | 121 | |
120 | 122 | protected function getExamples() { |
121 | | - return array ( |
| 123 | + return array( |
122 | 124 | 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC' |
123 | 125 | ); |
124 | 126 | } |
Index: trunk/phase3/includes/api/ApiResult.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 | /** |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | * @param $main ApiMain object |
56 | 56 | */ |
57 | 57 | public function __construct( $main ) { |
58 | | - parent :: __construct( $main, 'result' ); |
| 58 | + parent::__construct( $main, 'result' ); |
59 | 59 | $this->mIsRawMode = false; |
60 | 60 | $this->mCheckingSize = true; |
61 | 61 | $this->reset(); |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | * Clear the current result data. |
66 | 66 | */ |
67 | 67 | public function reset() { |
68 | | - $this->mData = array (); |
| 68 | + $this->mData = array(); |
69 | 69 | $this->mSize = 0; |
70 | 70 | } |
71 | 71 | |
— | — | @@ -100,12 +100,14 @@ |
101 | 101 | */ |
102 | 102 | public static function size( $value ) { |
103 | 103 | $s = 0; |
104 | | - if ( is_array( $value ) ) |
105 | | - foreach ( $value as $v ) |
| 104 | + if ( is_array( $value ) ) { |
| 105 | + foreach ( $value as $v ) { |
106 | 106 | $s += self::size( $v ); |
107 | | - else if ( !is_object( $value ) ) |
| 107 | + } |
| 108 | + } elseif ( !is_object( $value ) ) { |
108 | 109 | // Objects can't always be cast to string |
109 | 110 | $s = strlen( $value ); |
| 111 | + } |
110 | 112 | return $s; |
111 | 113 | } |
112 | 114 | |
— | — | @@ -140,21 +142,23 @@ |
141 | 143 | * @param $name string Index of $arr to add $value at |
142 | 144 | * @param $value mixed |
143 | 145 | */ |
144 | | - public static function setElement( & $arr, $name, $value ) { |
145 | | - if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) |
146 | | - ApiBase :: dieDebug( __METHOD__, 'Bad parameter' ); |
| 146 | + public static function setElement( &$arr, $name, $value ) { |
| 147 | + if ( $arr === null || $name === null || $value === null || !is_array( $arr ) || is_array( $name ) ) { |
| 148 | + ApiBase::dieDebug( __METHOD__, 'Bad parameter' ); |
| 149 | + } |
147 | 150 | |
148 | 151 | if ( !isset ( $arr[$name] ) ) { |
149 | 152 | $arr[$name] = $value; |
150 | | - } |
151 | | - elseif ( is_array( $arr[$name] ) && is_array( $value ) ) { |
| 153 | + } elseif ( is_array( $arr[$name] ) && is_array( $value ) ) { |
152 | 154 | $merged = array_intersect_key( $arr[$name], $value ); |
153 | | - if ( !count( $merged ) ) |
| 155 | + if ( !count( $merged ) ) { |
154 | 156 | $arr[$name] += $value; |
155 | | - else |
156 | | - ApiBase :: dieDebug( __METHOD__, "Attempting to merge element $name" ); |
157 | | - } else |
158 | | - ApiBase :: dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" ); |
| 157 | + } else { |
| 158 | + ApiBase::dieDebug( __METHOD__, "Attempting to merge element $name" ); |
| 159 | + } |
| 160 | + } else { |
| 161 | + ApiBase::dieDebug( __METHOD__, "Attempting to add element $name=$value, existing value is {$arr[$name]}" ); |
| 162 | + } |
159 | 163 | } |
160 | 164 | |
161 | 165 | /** |
— | — | @@ -165,15 +169,17 @@ |
166 | 170 | * as a sub item of $arr. Use this parameter to create elements in |
167 | 171 | * format <elem>text</elem> without attributes |
168 | 172 | */ |
169 | | - public static function setContent( & $arr, $value, $subElemName = null ) { |
170 | | - if ( is_array( $value ) ) |
171 | | - ApiBase :: dieDebug( __METHOD__, 'Bad parameter' ); |
| 173 | + public static function setContent( &$arr, $value, $subElemName = null ) { |
| 174 | + if ( is_array( $value ) ) { |
| 175 | + ApiBase::dieDebug( __METHOD__, 'Bad parameter' ); |
| 176 | + } |
172 | 177 | if ( is_null( $subElemName ) ) { |
173 | | - ApiResult :: setElement( $arr, '*', $value ); |
| 178 | + ApiResult::setElement( $arr, '*', $value ); |
174 | 179 | } else { |
175 | | - if ( !isset ( $arr[$subElemName] ) ) |
176 | | - $arr[$subElemName] = array (); |
177 | | - ApiResult :: setElement( $arr[$subElemName], '*', $value ); |
| 180 | + if ( !isset( $arr[$subElemName] ) ) { |
| 181 | + $arr[$subElemName] = array(); |
| 182 | + } |
| 183 | + ApiResult::setElement( $arr[$subElemName], '*', $value ); |
178 | 184 | } |
179 | 185 | } |
180 | 186 | |
— | — | @@ -184,12 +190,15 @@ |
185 | 191 | * @param $arr array |
186 | 192 | * @param $tag string Tag name |
187 | 193 | */ |
188 | | - public function setIndexedTagName( & $arr, $tag ) { |
| 194 | + public function setIndexedTagName( &$arr, $tag ) { |
189 | 195 | // In raw mode, add the '_element', otherwise just ignore |
190 | | - if ( !$this->getIsRawMode() ) |
| 196 | + if ( !$this->getIsRawMode() ) { |
191 | 197 | return; |
| 198 | + } |
192 | 199 | if ( $arr === null || $tag === null || !is_array( $arr ) || is_array( $tag ) ) |
193 | | - ApiBase :: dieDebug( __METHOD__, 'Bad parameter' ); |
| 200 | + { |
| 201 | + ApiBase::dieDebug( __METHOD__, 'Bad parameter' ); |
| 202 | + } |
194 | 203 | // Do not use setElement() as it is ok to call this more than once |
195 | 204 | $arr['_element'] = $tag; |
196 | 205 | } |
— | — | @@ -200,15 +209,16 @@ |
201 | 210 | * @param $tag string Tag name |
202 | 211 | */ |
203 | 212 | public function setIndexedTagName_recursive( &$arr, $tag ) { |
204 | | - if ( !is_array( $arr ) ) |
205 | | - return; |
206 | | - foreach ( $arr as &$a ) |
207 | | - { |
208 | | - if ( !is_array( $a ) ) |
209 | | - continue; |
210 | | - $this->setIndexedTagName( $a, $tag ); |
211 | | - $this->setIndexedTagName_recursive( $a, $tag ); |
| 213 | + if ( !is_array( $arr ) ) { |
| 214 | + return; |
212 | 215 | } |
| 216 | + foreach ( $arr as &$a ) { |
| 217 | + if ( !is_array( $a ) ) { |
| 218 | + continue; |
| 219 | + } |
| 220 | + $this->setIndexedTagName( $a, $tag ); |
| 221 | + $this->setIndexedTagName_recursive( $a, $tag ); |
| 222 | + } |
213 | 223 | } |
214 | 224 | |
215 | 225 | /** |
— | — | @@ -219,15 +229,16 @@ |
220 | 230 | * @param $tag string |
221 | 231 | */ |
222 | 232 | public function setIndexedTagName_internal( $path, $tag ) { |
223 | | - $data = & $this->mData; |
| 233 | + $data = &$this->mData; |
224 | 234 | foreach ( (array)$path as $p ) { |
225 | 235 | if ( !isset( $data[$p] ) ) { |
226 | 236 | $data[$p] = array(); |
227 | 237 | } |
228 | | - $data = & $data[$p]; |
| 238 | + $data = &$data[$p]; |
229 | 239 | } |
230 | | - if ( is_null( $data ) ) |
| 240 | + if ( is_null( $data ) ) { |
231 | 241 | return; |
| 242 | + } |
232 | 243 | $this->setIndexedTagName( $data, $tag ); |
233 | 244 | } |
234 | 245 | |
— | — | @@ -240,32 +251,36 @@ |
241 | 252 | */ |
242 | 253 | public function addValue( $path, $name, $value ) { |
243 | 254 | global $wgAPIMaxResultSize; |
244 | | - $data = & $this->mData; |
| 255 | + $data = &$this->mData; |
245 | 256 | if ( $this->mCheckingSize ) { |
246 | 257 | $newsize = $this->mSize + self::size( $value ); |
247 | | - if ( $newsize > $wgAPIMaxResultSize ) |
| 258 | + if ( $newsize > $wgAPIMaxResultSize ) { |
248 | 259 | return false; |
| 260 | + } |
249 | 261 | $this->mSize = $newsize; |
250 | 262 | } |
251 | 263 | |
252 | 264 | if ( !is_null( $path ) ) { |
253 | 265 | if ( is_array( $path ) ) { |
254 | 266 | foreach ( $path as $p ) { |
255 | | - if ( !isset ( $data[$p] ) ) |
256 | | - $data[$p] = array (); |
257 | | - $data = & $data[$p]; |
| 267 | + if ( !isset( $data[$p] ) ) { |
| 268 | + $data[$p] = array(); |
| 269 | + } |
| 270 | + $data = &$data[$p]; |
258 | 271 | } |
259 | 272 | } else { |
260 | | - if ( !isset ( $data[$path] ) ) |
261 | | - $data[$path] = array (); |
262 | | - $data = & $data[$path]; |
| 273 | + if ( !isset( $data[$path] ) ) { |
| 274 | + $data[$path] = array(); |
| 275 | + } |
| 276 | + $data = &$data[$path]; |
263 | 277 | } |
264 | 278 | } |
265 | 279 | |
266 | | - if ( !$name ) |
267 | | - $data[] = $value; // Add list element |
268 | | - else |
269 | | - ApiResult :: setElement( $data, $name, $value ); // Add named element |
| 280 | + if ( !$name ) { |
| 281 | + $data[] = $value; // Add list element |
| 282 | + } else { |
| 283 | + ApiResult::setElement( $data, $name, $value ); // Add named element |
| 284 | + } |
270 | 285 | return true; |
271 | 286 | } |
272 | 287 | |
— | — | @@ -277,13 +292,15 @@ |
278 | 293 | * @param $name string |
279 | 294 | */ |
280 | 295 | public function unsetValue( $path, $name ) { |
281 | | - $data = & $this->mData; |
282 | | - if ( !is_null( $path ) ) |
| 296 | + $data = &$this->mData; |
| 297 | + if ( !is_null( $path ) ) { |
283 | 298 | foreach ( (array)$path as $p ) { |
284 | | - if ( !isset( $data[$p] ) ) |
| 299 | + if ( !isset( $data[$p] ) ) { |
285 | 300 | return; |
286 | | - $data = & $data[$p]; |
| 301 | + } |
| 302 | + $data = &$data[$p]; |
287 | 303 | } |
| 304 | + } |
288 | 305 | $this->mSize -= self::size( $data[$name] ); |
289 | 306 | unset( $data[$name] ); |
290 | 307 | } |
— | — | @@ -291,24 +308,23 @@ |
292 | 309 | /** |
293 | 310 | * Ensure all values in this result are valid UTF-8. |
294 | 311 | */ |
295 | | - public function cleanUpUTF8() |
296 | | - { |
| 312 | + public function cleanUpUTF8() { |
297 | 313 | array_walk_recursive( $this->mData, array( 'ApiResult', 'cleanUp_helper' ) ); |
298 | 314 | } |
299 | 315 | |
300 | 316 | /** |
301 | 317 | * Callback function for cleanUpUTF8() |
302 | 318 | */ |
303 | | - private static function cleanUp_helper( &$s ) |
304 | | - { |
305 | | - if ( !is_string( $s ) ) |
| 319 | + private static function cleanUp_helper( &$s ) { |
| 320 | + if ( !is_string( $s ) ) { |
306 | 321 | return; |
| 322 | + } |
307 | 323 | global $wgContLang; |
308 | 324 | $s = $wgContLang->normalize( $s ); |
309 | 325 | } |
310 | 326 | |
311 | 327 | public function execute() { |
312 | | - ApiBase :: dieDebug( __METHOD__, 'execute() is not supported on Result object' ); |
| 328 | + ApiBase::dieDebug( __METHOD__, 'execute() is not supported on Result object' ); |
313 | 329 | } |
314 | 330 | |
315 | 331 | public function getVersion() { |
Index: trunk/phase3/includes/api/ApiUnblock.php |
— | — | @@ -1,10 +1,10 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 7, 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 | /** |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | class ApiUnblock 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 | /** |
— | — | @@ -46,27 +46,30 @@ |
47 | 47 | global $wgUser; |
48 | 48 | $params = $this->extractRequestParams(); |
49 | 49 | |
50 | | - if ( $params['gettoken'] ) |
51 | | - { |
| 50 | + if ( $params['gettoken'] ) { |
52 | 51 | $res['unblocktoken'] = $wgUser->editToken(); |
53 | 52 | $this->getResult()->addValue( null, $this->getModuleName(), $res ); |
54 | 53 | return; |
55 | 54 | } |
56 | 55 | |
57 | | - if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) |
| 56 | + if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) { |
58 | 57 | $this->dieUsageMsg( array( 'unblock-notarget' ) ); |
59 | | - if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) |
| 58 | + } |
| 59 | + if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) { |
60 | 60 | $this->dieUsageMsg( array( 'unblock-idanduser' ) ); |
| 61 | + } |
61 | 62 | |
62 | | - if ( !$wgUser->isAllowed( 'block' ) ) |
| 63 | + if ( !$wgUser->isAllowed( 'block' ) ) { |
63 | 64 | $this->dieUsageMsg( array( 'cantunblock' ) ); |
| 65 | + } |
64 | 66 | |
65 | 67 | $id = $params['id']; |
66 | 68 | $user = $params['user']; |
67 | 69 | $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] ); |
68 | 70 | $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range ); |
69 | | - if ( $retval ) |
| 71 | + if ( $retval ) { |
70 | 72 | $this->dieUsageMsg( $retval ); |
| 73 | + } |
71 | 74 | |
72 | 75 | $res['id'] = intval( $id ); |
73 | 76 | $res['user'] = $user; |
— | — | @@ -83,7 +86,7 @@ |
84 | 87 | } |
85 | 88 | |
86 | 89 | public function getAllowedParams() { |
87 | | - return array ( |
| 90 | + return array( |
88 | 91 | 'id' => null, |
89 | 92 | 'user' => null, |
90 | 93 | 'token' => null, |
— | — | @@ -93,7 +96,7 @@ |
94 | 97 | } |
95 | 98 | |
96 | 99 | public function getParamDescription() { |
97 | | - return array ( |
| 100 | + return array( |
98 | 101 | 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user', |
99 | 102 | 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id', |
100 | 103 | 'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info', |
— | — | @@ -107,21 +110,21 @@ |
108 | 111 | 'Unblock a user.' |
109 | 112 | ); |
110 | 113 | } |
111 | | - |
112 | | - public function getPossibleErrors() { |
| 114 | + |
| 115 | + public function getPossibleErrors() { |
113 | 116 | return array_merge( parent::getPossibleErrors(), array( |
114 | 117 | array( 'unblock-notarget' ), |
115 | 118 | array( 'unblock-idanduser' ), |
116 | 119 | array( 'cantunblock' ), |
117 | | - ) ); |
| 120 | + ) ); |
118 | 121 | } |
119 | | - |
| 122 | + |
120 | 123 | public function getTokenSalt() { |
121 | 124 | return ''; |
122 | 125 | } |
123 | 126 | |
124 | 127 | protected function getExamples() { |
125 | | - return array ( |
| 128 | + return array( |
126 | 129 | 'api.php?action=unblock&id=105', |
127 | 130 | 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob' |
128 | 131 | ); |
Index: trunk/phase3/includes/api/ApiQueryWatchlistRaw.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Oct 4, 2008 |
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 ( 'ApiQueryBase.php' ); |
| 29 | + require_once( 'ApiQueryBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { |
39 | 39 | |
40 | 40 | public function __construct( $query, $moduleName ) { |
41 | | - parent :: __construct( $query, $moduleName, 'wr' ); |
| 41 | + parent::__construct( $query, $moduleName, 'wr' ); |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function execute() { |
— | — | @@ -53,13 +53,15 @@ |
54 | 54 | |
55 | 55 | $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' ); |
56 | 56 | |
57 | | - if ( !$wgUser->isLoggedIn() ) |
| 57 | + if ( !$wgUser->isLoggedIn() ) { |
58 | 58 | $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); |
| 59 | + } |
59 | 60 | $params = $this->extractRequestParams(); |
60 | 61 | $prop = array_flip( (array)$params['prop'] ); |
61 | 62 | $show = array_flip( (array)$params['show'] ); |
62 | | - if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) |
| 63 | + if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) { |
63 | 64 | $this->dieUsageMsg( array( 'show' ) ); |
| 65 | + } |
64 | 66 | |
65 | 67 | $this->addTables( 'watchlist' ); |
66 | 68 | $this->addFields( array( 'wl_namespace', 'wl_title' ) ); |
— | — | @@ -69,34 +71,35 @@ |
70 | 72 | $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) ); |
71 | 73 | $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) ); |
72 | 74 | |
73 | | - if ( isset( $params['continue'] ) ) |
74 | | - { |
| 75 | + if ( isset( $params['continue'] ) ) { |
75 | 76 | $cont = explode( '|', $params['continue'] ); |
76 | | - if ( count( $cont ) != 2 ) |
| 77 | + if ( count( $cont ) != 2 ) { |
77 | 78 | $this->dieUsage( "Invalid continue param. You should pass the " . |
78 | 79 | "original value returned by the previous query", "_badcontinue" ); |
| 80 | + } |
79 | 81 | $ns = intval( $cont[0] ); |
80 | 82 | $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) ); |
81 | | - $this->addWhere( "wl_namespace > '$ns' OR " . |
82 | | - "(wl_namespace = '$ns' AND " . |
83 | | - "wl_title >= '$title')" ); |
| 83 | + $this->addWhere( |
| 84 | + "wl_namespace > '$ns' OR " . |
| 85 | + "(wl_namespace = '$ns' AND " . |
| 86 | + "wl_title >= '$title')" |
| 87 | + ); |
84 | 88 | } |
85 | 89 | |
86 | 90 | // Don't ORDER BY wl_namespace if it's constant in the WHERE clause |
87 | | - if ( count( $params['namespace'] ) == 1 ) |
| 91 | + if ( count( $params['namespace'] ) == 1 ) { |
88 | 92 | $this->addOption( 'ORDER BY', 'wl_title' ); |
89 | | - else |
| 93 | + } else { |
90 | 94 | $this->addOption( 'ORDER BY', 'wl_namespace, wl_title' ); |
| 95 | + } |
91 | 96 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
92 | 97 | $res = $this->select( __METHOD__ ); |
93 | | - |
| 98 | + |
94 | 99 | $db = $this->getDB(); |
95 | 100 | $titles = array(); |
96 | 101 | $count = 0; |
97 | | - while ( $row = $db->fetchObject( $res ) ) |
98 | | - { |
99 | | - if ( ++$count > $params['limit'] ) |
100 | | - { |
| 102 | + while ( $row = $db->fetchObject( $res ) ) { |
| 103 | + if ( ++$count > $params['limit'] ) { |
101 | 104 | // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
102 | 105 | $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' . |
103 | 106 | $this->keyToTitle( $row->wl_title ) ); |
— | — | @@ -104,52 +107,53 @@ |
105 | 108 | } |
106 | 109 | $t = Title::makeTitle( $row->wl_namespace, $row->wl_title ); |
107 | 110 | |
108 | | - if ( is_null( $resultPageSet ) ) |
109 | | - { |
| 111 | + if ( is_null( $resultPageSet ) ) { |
110 | 112 | $vals = array(); |
111 | 113 | ApiQueryBase::addTitleInfo( $vals, $t ); |
112 | 114 | if ( isset( $prop['changed'] ) && !is_null( $row->wl_notificationtimestamp ) ) |
| 115 | + { |
113 | 116 | $vals['changed'] = wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp ); |
| 117 | + } |
114 | 118 | $fit = $this->getResult()->addValue( $this->getModuleName(), null, $vals ); |
115 | | - if ( !$fit ) |
116 | | - { |
| 119 | + if ( !$fit ) { |
117 | 120 | $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' . |
118 | 121 | $this->keyToTitle( $row->wl_title ) ); |
119 | 122 | break; |
120 | 123 | } |
| 124 | + } else { |
| 125 | + $titles[] = $t; |
121 | 126 | } |
122 | | - else |
123 | | - $titles[] = $t; |
124 | 127 | } |
125 | | - if ( is_null( $resultPageSet ) ) |
| 128 | + if ( is_null( $resultPageSet ) ) { |
126 | 129 | $this->getResult()->setIndexedTagName_internal( $this->getModuleName(), 'wr' ); |
127 | | - else |
| 130 | + } else { |
128 | 131 | $resultPageSet->populateFromTitles( $titles ); |
| 132 | + } |
129 | 133 | } |
130 | 134 | |
131 | 135 | public function getAllowedParams() { |
132 | | - return array ( |
| 136 | + return array( |
133 | 137 | 'continue' => null, |
134 | | - 'namespace' => array ( |
135 | | - ApiBase :: PARAM_ISMULTI => true, |
136 | | - ApiBase :: PARAM_TYPE => 'namespace' |
| 138 | + 'namespace' => array( |
| 139 | + ApiBase::PARAM_ISMULTI => true, |
| 140 | + ApiBase::PARAM_TYPE => 'namespace' |
137 | 141 | ), |
138 | | - 'limit' => array ( |
139 | | - ApiBase :: PARAM_DFLT => 10, |
140 | | - ApiBase :: PARAM_TYPE => 'limit', |
141 | | - ApiBase :: PARAM_MIN => 1, |
142 | | - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
143 | | - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 142 | + 'limit' => array( |
| 143 | + ApiBase::PARAM_DFLT => 10, |
| 144 | + ApiBase::PARAM_TYPE => 'limit', |
| 145 | + ApiBase::PARAM_MIN => 1, |
| 146 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 147 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
144 | 148 | ), |
145 | | - 'prop' => array ( |
146 | | - ApiBase :: PARAM_ISMULTI => true, |
147 | | - ApiBase :: PARAM_TYPE => array ( |
| 149 | + 'prop' => array( |
| 150 | + ApiBase::PARAM_ISMULTI => true, |
| 151 | + ApiBase::PARAM_TYPE => array( |
148 | 152 | 'changed', |
149 | 153 | ) |
150 | 154 | ), |
151 | | - 'show' => array ( |
152 | | - ApiBase :: PARAM_ISMULTI => true, |
153 | | - ApiBase :: PARAM_TYPE => array ( |
| 155 | + 'show' => array( |
| 156 | + ApiBase::PARAM_ISMULTI => true, |
| 157 | + ApiBase::PARAM_TYPE => array( |
154 | 158 | 'changed', |
155 | 159 | '!changed', |
156 | 160 | ) |
— | — | @@ -158,7 +162,7 @@ |
159 | 163 | } |
160 | 164 | |
161 | 165 | public function getParamDescription() { |
162 | | - return array ( |
| 166 | + return array( |
163 | 167 | 'continue' => 'When more results are available, use this to continue', |
164 | 168 | 'namespace' => 'Only list pages in the given namespace(s).', |
165 | 169 | 'limit' => 'How many total results to return per request.', |
— | — | @@ -170,7 +174,7 @@ |
171 | 175 | public function getDescription() { |
172 | 176 | return "Get all pages on the logged in user's watchlist"; |
173 | 177 | } |
174 | | - |
| 178 | + |
175 | 179 | public function getPossibleErrors() { |
176 | 180 | return array_merge( parent::getPossibleErrors(), array( |
177 | 181 | array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ), |
— | — | @@ -179,7 +183,7 @@ |
180 | 184 | } |
181 | 185 | |
182 | 186 | protected function getExamples() { |
183 | | - return array ( |
| 187 | + return array( |
184 | 188 | 'api.php?action=query&list=watchlistraw', |
185 | 189 | 'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions', |
186 | 190 | ); |
Index: trunk/phase3/includes/api/ApiQueryUserInfo.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on July 30, 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 ( 'ApiQueryBase.php' ); |
| 29 | + require_once( 'ApiQueryBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | class ApiQueryUserInfo extends ApiQueryBase { |
38 | 38 | |
39 | 39 | public function __construct( $query, $moduleName ) { |
40 | | - parent :: __construct( $query, $moduleName, 'ui' ); |
| 40 | + parent::__construct( $query, $moduleName, 'ui' ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function execute() { |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | $this->prop = array(); |
52 | 52 | } |
53 | 53 | $r = $this->getCurrentUserInfo(); |
54 | | - $result->addValue( "query", $this->getModuleName(), $r ); |
| 54 | + $result->addValue( 'query', $this->getModuleName(), $r ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | protected function getCurrentUserInfo() { |
— | — | @@ -60,8 +60,9 @@ |
61 | 61 | $vals['id'] = intval( $wgUser->getId() ); |
62 | 62 | $vals['name'] = $wgUser->getName(); |
63 | 63 | |
64 | | - if ( $wgUser->isAnon() ) |
| 64 | + if ( $wgUser->isAnon() ) { |
65 | 65 | $vals['anon'] = ''; |
| 66 | + } |
66 | 67 | |
67 | 68 | if ( isset( $this->prop['blockinfo'] ) ) { |
68 | 69 | if ( $wgUser->isBlocked() ) { |
— | — | @@ -97,7 +98,11 @@ |
98 | 99 | $vals['options'] = $wgUser->getOptions(); |
99 | 100 | } |
100 | 101 | |
101 | | - if ( isset( $this->prop['preferencestoken'] ) && is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) { |
| 102 | + if ( |
| 103 | + isset( $this->prop['preferencestoken'] ) && |
| 104 | + is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) |
| 105 | + ) |
| 106 | + { |
102 | 107 | $vals['preferencestoken'] = $wgUser->editToken(); |
103 | 108 | } |
104 | 109 | |
— | — | @@ -112,26 +117,27 @@ |
113 | 118 | if ( isset( $this->prop['email'] ) ) { |
114 | 119 | $vals['email'] = $wgUser->getEmail(); |
115 | 120 | $auth = $wgUser->getEmailAuthenticationTimestamp(); |
116 | | - if ( !is_null( $auth ) ) |
| 121 | + if ( !is_null( $auth ) ) { |
117 | 122 | $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth ); |
| 123 | + } |
118 | 124 | } |
119 | 125 | return $vals; |
120 | 126 | } |
121 | 127 | |
122 | | - protected function getRateLimits() |
123 | | - { |
| 128 | + protected function getRateLimits() { |
124 | 129 | global $wgUser, $wgRateLimits; |
125 | | - if ( !$wgUser->isPingLimitable() ) |
| 130 | + if ( !$wgUser->isPingLimitable() ) { |
126 | 131 | return array(); // No limits |
| 132 | + } |
127 | 133 | |
128 | 134 | // Find out which categories we belong to |
129 | 135 | $categories = array(); |
130 | | - if ( $wgUser->isAnon() ) |
| 136 | + if ( $wgUser->isAnon() ) { |
131 | 137 | $categories[] = 'anon'; |
132 | | - else |
| 138 | + } else { |
133 | 139 | $categories[] = 'user'; |
134 | | - if ( $wgUser->isNewBie() ) |
135 | | - { |
| 140 | + } |
| 141 | + if ( $wgUser->isNewbie() ) { |
136 | 142 | $categories[] = 'ip'; |
137 | 143 | $categories[] = 'subnet'; |
138 | 144 | if ( !$wgUser->isAnon() ) |
— | — | @@ -141,22 +147,23 @@ |
142 | 148 | |
143 | 149 | // Now get the actual limits |
144 | 150 | $retval = array(); |
145 | | - foreach ( $wgRateLimits as $action => $limits ) |
146 | | - foreach ( $categories as $cat ) |
147 | | - if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) |
148 | | - { |
| 151 | + foreach ( $wgRateLimits as $action => $limits ) { |
| 152 | + foreach ( $categories as $cat ) { |
| 153 | + if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) { |
149 | 154 | $retval[$action][$cat]['hits'] = intval( $limits[$cat][0] ); |
150 | 155 | $retval[$action][$cat]['seconds'] = intval( $limits[$cat][1] ); |
151 | 156 | } |
| 157 | + } |
| 158 | + } |
152 | 159 | return $retval; |
153 | 160 | } |
154 | 161 | |
155 | 162 | public function getAllowedParams() { |
156 | | - return array ( |
157 | | - 'prop' => array ( |
158 | | - ApiBase :: PARAM_DFLT => null, |
159 | | - ApiBase :: PARAM_ISMULTI => true, |
160 | | - ApiBase :: PARAM_TYPE => array ( |
| 163 | + return array( |
| 164 | + 'prop' => array( |
| 165 | + ApiBase::PARAM_DFLT => null, |
| 166 | + ApiBase::PARAM_ISMULTI => true, |
| 167 | + ApiBase::PARAM_TYPE => array( |
161 | 168 | 'blockinfo', |
162 | 169 | 'hasmsg', |
163 | 170 | 'groups', |
— | — | @@ -173,7 +180,7 @@ |
174 | 181 | } |
175 | 182 | |
176 | 183 | public function getParamDescription() { |
177 | | - return array ( |
| 184 | + return array( |
178 | 185 | 'prop' => array( |
179 | 186 | 'What pieces of information to include', |
180 | 187 | ' blockinfo - tags if the current user is blocked, by whom, and for what reason', |
— | — | @@ -193,7 +200,7 @@ |
194 | 201 | } |
195 | 202 | |
196 | 203 | protected function getExamples() { |
197 | | - return array ( |
| 204 | + return array( |
198 | 205 | 'api.php?action=query&meta=userinfo', |
199 | 206 | 'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg', |
200 | 207 | ); |
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Sep 25, 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 | /** |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | class ApiQueryWatchlist extends ApiQueryGeneratorBase { |
39 | 39 | |
40 | 40 | public function __construct( $query, $moduleName ) { |
41 | | - parent :: __construct( $query, $moduleName, 'wl' ); |
| 41 | + parent::__construct( $query, $moduleName, 'wl' ); |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function execute() { |
— | — | @@ -75,7 +75,6 @@ |
76 | 76 | } |
77 | 77 | |
78 | 78 | if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) { |
79 | | - |
80 | 79 | $prop = array_flip( $params['prop'] ); |
81 | 80 | |
82 | 81 | $this->fld_ids = isset( $prop['ids'] ); |
— | — | @@ -90,19 +89,20 @@ |
91 | 90 | $this->fld_notificationtimestamp = isset( $prop['notificationtimestamp'] ); |
92 | 91 | |
93 | 92 | if ( $this->fld_patrol ) { |
94 | | - if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) |
| 93 | + if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) { |
95 | 94 | $this->dieUsage( 'patrol property is not available', 'patrol' ); |
| 95 | + } |
96 | 96 | } |
97 | 97 | } |
98 | | - |
99 | | - $this->addFields( array ( |
| 98 | + |
| 99 | + $this->addFields( array( |
100 | 100 | 'rc_namespace', |
101 | 101 | 'rc_title', |
102 | 102 | 'rc_timestamp' |
103 | 103 | ) ); |
104 | 104 | |
105 | 105 | if ( is_null( $resultPageSet ) ) { |
106 | | - $this->addFields( array ( |
| 106 | + $this->addFields( array( |
107 | 107 | 'rc_cur_id', |
108 | 108 | 'rc_this_oldid' |
109 | 109 | ) ); |
— | — | @@ -123,14 +123,14 @@ |
124 | 124 | $this->addFields( 'rc_cur_id' ); |
125 | 125 | } |
126 | 126 | |
127 | | - $this->addTables( array ( |
| 127 | + $this->addTables( array( |
128 | 128 | 'watchlist', |
129 | 129 | 'page', |
130 | 130 | 'recentchanges' |
131 | 131 | ) ); |
132 | 132 | |
133 | 133 | $userId = $user->getId(); |
134 | | - $this->addWhere( array ( |
| 134 | + $this->addWhere( array( |
135 | 135 | 'wl_namespace = rc_namespace', |
136 | 136 | 'wl_title = rc_title', |
137 | 137 | 'rc_cur_id = page_id', |
— | — | @@ -149,41 +149,47 @@ |
150 | 150 | if ( ( isset ( $show['minor'] ) && isset ( $show['!minor'] ) ) |
151 | 151 | || ( isset ( $show['bot'] ) && isset ( $show['!bot'] ) ) |
152 | 152 | || ( isset ( $show['anon'] ) && isset ( $show['!anon'] ) ) |
153 | | - || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) ) ) { |
154 | | - |
| 153 | + || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) ) |
| 154 | + ) |
| 155 | + { |
155 | 156 | $this->dieUsageMsg( array( 'show' ) ); |
156 | 157 | } |
157 | | - |
| 158 | + |
158 | 159 | // Check permissions. FIXME: should this check $user instead of $wgUser? |
159 | 160 | if ( ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) |
160 | | - $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' ); |
| 161 | + { |
| 162 | + $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); |
| 163 | + } |
161 | 164 | |
162 | 165 | /* Add additional conditions to query depending upon parameters. */ |
163 | | - $this->addWhereIf( 'rc_minor = 0', isset ( $show['!minor'] ) ); |
164 | | - $this->addWhereIf( 'rc_minor != 0', isset ( $show['minor'] ) ); |
165 | | - $this->addWhereIf( 'rc_bot = 0', isset ( $show['!bot'] ) ); |
166 | | - $this->addWhereIf( 'rc_bot != 0', isset ( $show['bot'] ) ); |
167 | | - $this->addWhereIf( 'rc_user = 0', isset ( $show['anon'] ) ); |
168 | | - $this->addWhereIf( 'rc_user != 0', isset ( $show['!anon'] ) ); |
| 166 | + $this->addWhereIf( 'rc_minor = 0', isset( $show['!minor'] ) ); |
| 167 | + $this->addWhereIf( 'rc_minor != 0', isset( $show['minor'] ) ); |
| 168 | + $this->addWhereIf( 'rc_bot = 0', isset( $show['!bot'] ) ); |
| 169 | + $this->addWhereIf( 'rc_bot != 0', isset( $show['bot'] ) ); |
| 170 | + $this->addWhereIf( 'rc_user = 0', isset( $show['anon'] ) ); |
| 171 | + $this->addWhereIf( 'rc_user != 0', isset( $show['!anon'] ) ); |
169 | 172 | $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) ); |
170 | 173 | $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) ); |
171 | 174 | } |
172 | 175 | |
173 | | - if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) |
| 176 | + if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) { |
174 | 177 | $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' ); |
175 | | - if ( !is_null( $params['user'] ) ) |
| 178 | + } |
| 179 | + if ( !is_null( $params['user'] ) ) { |
176 | 180 | $this->addWhereFld( 'rc_user_text', $params['user'] ); |
177 | | - if ( !is_null( $params['excludeuser'] ) ) |
| 181 | + } |
| 182 | + if ( !is_null( $params['excludeuser'] ) ) { |
178 | 183 | $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) ); |
| 184 | + } |
179 | 185 | |
180 | 186 | $db = $this->getDB(); |
181 | | - |
| 187 | + |
182 | 188 | // This is an index optimization for mysql, as done in the Special:Watchlist page |
183 | | - $this->addWhereIf( "rc_timestamp > ''", !isset ( $params['start'] ) && !isset ( $params['end'] ) && $db->getType() == 'mysql' ); |
| 189 | + $this->addWhereIf( "rc_timestamp > ''", !isset( $params['start'] ) && !isset( $params['end'] ) && $db->getType() == 'mysql' ); |
184 | 190 | |
185 | 191 | $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
186 | 192 | |
187 | | - $ids = array (); |
| 193 | + $ids = array(); |
188 | 194 | $count = 0; |
189 | 195 | $res = $this->select( __METHOD__ ); |
190 | 196 | |
— | — | @@ -197,8 +203,7 @@ |
198 | 204 | if ( is_null( $resultPageSet ) ) { |
199 | 205 | $vals = $this->extractRowInfo( $row ); |
200 | 206 | $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
201 | | - if ( !$fit ) |
202 | | - { |
| 207 | + if ( !$fit ) { |
203 | 208 | $this->setContinueEnumParameter( 'start', |
204 | 209 | wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) ); |
205 | 210 | break; |
— | — | @@ -216,8 +221,7 @@ |
217 | 222 | |
218 | 223 | if ( is_null( $resultPageSet ) ) { |
219 | 224 | $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' ); |
220 | | - } |
221 | | - elseif ( $params['allrev'] ) { |
| 225 | + } elseif ( $params['allrev'] ) { |
222 | 226 | $resultPageSet->populateFromRevisionIDs( $ids ); |
223 | 227 | } else { |
224 | 228 | $resultPageSet->populateFromPageIDs( $ids ); |
— | — | @@ -225,9 +229,8 @@ |
226 | 230 | } |
227 | 231 | |
228 | 232 | private function extractRowInfo( $row ) { |
| 233 | + $vals = array(); |
229 | 234 | |
230 | | - $vals = array (); |
231 | | - |
232 | 235 | if ( $this->fld_ids ) { |
233 | 236 | $vals['pageid'] = intval( $row->rc_cur_id ); |
234 | 237 | $vals['revid'] = intval( $row->rc_this_oldid ); |
— | — | @@ -235,41 +238,50 @@ |
236 | 239 | |
237 | 240 | $title = Title::makeTitle( $row->rc_namespace, $row->rc_title ); |
238 | 241 | |
239 | | - if ( $this->fld_title ) |
| 242 | + if ( $this->fld_title ) { |
240 | 243 | ApiQueryBase::addTitleInfo( $vals, $title ); |
| 244 | + } |
241 | 245 | |
242 | 246 | if ( $this->fld_user ) { |
243 | 247 | $vals['user'] = $row->rc_user_text; |
244 | | - if ( !$row->rc_user ) |
| 248 | + if ( !$row->rc_user ) { |
245 | 249 | $vals['anon'] = ''; |
| 250 | + } |
246 | 251 | } |
247 | 252 | |
248 | 253 | if ( $this->fld_flags ) { |
249 | | - if ( $row->rc_new ) |
| 254 | + if ( $row->rc_new ) { |
250 | 255 | $vals['new'] = ''; |
251 | | - if ( $row->rc_minor ) |
| 256 | + } |
| 257 | + if ( $row->rc_minor ) { |
252 | 258 | $vals['minor'] = ''; |
253 | | - if ( $row->rc_bot ) |
| 259 | + } |
| 260 | + if ( $row->rc_bot ) { |
254 | 261 | $vals['bot'] = ''; |
| 262 | + } |
255 | 263 | } |
256 | 264 | |
257 | | - if ( $this->fld_patrol && isset( $row->rc_patrolled ) ) |
| 265 | + if ( $this->fld_patrol && isset( $row->rc_patrolled ) ) { |
258 | 266 | $vals['patrolled'] = ''; |
| 267 | + } |
259 | 268 | |
260 | | - if ( $this->fld_timestamp ) |
| 269 | + if ( $this->fld_timestamp ) { |
261 | 270 | $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp ); |
| 271 | + } |
262 | 272 | |
263 | 273 | if ( $this->fld_sizes ) { |
264 | 274 | $vals['oldlen'] = intval( $row->rc_old_len ); |
265 | 275 | $vals['newlen'] = intval( $row->rc_new_len ); |
266 | 276 | } |
267 | | - |
268 | | - if ( $this->fld_notificationtimestamp ) |
| 277 | + |
| 278 | + if ( $this->fld_notificationtimestamp ) { |
269 | 279 | $vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null ) ? '' : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp ); |
| 280 | + } |
270 | 281 | |
271 | | - if ( $this->fld_comment && isset( $row->rc_comment ) ) |
| 282 | + if ( $this->fld_comment && isset( $row->rc_comment ) ) { |
272 | 283 | $vals['comment'] = $row->rc_comment; |
273 | | - |
| 284 | + } |
| 285 | + |
274 | 286 | if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) { |
275 | 287 | global $wgUser; |
276 | 288 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title ); |
— | — | @@ -279,42 +291,42 @@ |
280 | 292 | } |
281 | 293 | |
282 | 294 | public function getAllowedParams() { |
283 | | - return array ( |
| 295 | + return array( |
284 | 296 | 'allrev' => false, |
285 | | - 'start' => array ( |
286 | | - ApiBase :: PARAM_TYPE => 'timestamp' |
| 297 | + 'start' => array( |
| 298 | + ApiBase::PARAM_TYPE => 'timestamp' |
287 | 299 | ), |
288 | | - 'end' => array ( |
289 | | - ApiBase :: PARAM_TYPE => 'timestamp' |
| 300 | + 'end' => array( |
| 301 | + ApiBase::PARAM_TYPE => 'timestamp' |
290 | 302 | ), |
291 | 303 | 'namespace' => array ( |
292 | | - ApiBase :: PARAM_ISMULTI => true, |
293 | | - ApiBase :: PARAM_TYPE => 'namespace' |
| 304 | + ApiBase::PARAM_ISMULTI => true, |
| 305 | + ApiBase::PARAM_TYPE => 'namespace' |
294 | 306 | ), |
295 | 307 | 'user' => array( |
296 | | - ApiBase :: PARAM_TYPE => 'user', |
| 308 | + ApiBase::PARAM_TYPE => 'user', |
297 | 309 | ), |
298 | 310 | 'excludeuser' => array( |
299 | | - ApiBase :: PARAM_TYPE => 'user', |
| 311 | + ApiBase::PARAM_TYPE => 'user', |
300 | 312 | ), |
301 | | - 'dir' => array ( |
302 | | - ApiBase :: PARAM_DFLT => 'older', |
303 | | - ApiBase :: PARAM_TYPE => array ( |
| 313 | + 'dir' => array( |
| 314 | + ApiBase::PARAM_DFLT => 'older', |
| 315 | + ApiBase::PARAM_TYPE => array( |
304 | 316 | 'newer', |
305 | 317 | 'older' |
306 | 318 | ) |
307 | 319 | ), |
308 | | - 'limit' => array ( |
309 | | - ApiBase :: PARAM_DFLT => 10, |
310 | | - ApiBase :: PARAM_TYPE => 'limit', |
311 | | - ApiBase :: PARAM_MIN => 1, |
312 | | - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
313 | | - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 320 | + 'limit' => array( |
| 321 | + ApiBase::PARAM_DFLT => 10, |
| 322 | + ApiBase::PARAM_TYPE => 'limit', |
| 323 | + ApiBase::PARAM_MIN => 1, |
| 324 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 325 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
314 | 326 | ), |
315 | | - 'prop' => array ( |
316 | | - APIBase :: PARAM_ISMULTI => true, |
317 | | - APIBase :: PARAM_DFLT => 'ids|title|flags', |
318 | | - APIBase :: PARAM_TYPE => array ( |
| 327 | + 'prop' => array( |
| 328 | + APIBase::PARAM_ISMULTI => true, |
| 329 | + APIBase::PARAM_DFLT => 'ids|title|flags', |
| 330 | + APIBase::PARAM_TYPE => array( |
319 | 331 | 'ids', |
320 | 332 | 'title', |
321 | 333 | 'flags', |
— | — | @@ -327,9 +339,9 @@ |
328 | 340 | 'notificationtimestamp' |
329 | 341 | ) |
330 | 342 | ), |
331 | | - 'show' => array ( |
332 | | - ApiBase :: PARAM_ISMULTI => true, |
333 | | - ApiBase :: PARAM_TYPE => array ( |
| 343 | + 'show' => array( |
| 344 | + ApiBase::PARAM_ISMULTI => true, |
| 345 | + ApiBase::PARAM_TYPE => array( |
334 | 346 | 'minor', |
335 | 347 | '!minor', |
336 | 348 | 'bot', |
— | — | @@ -340,17 +352,17 @@ |
341 | 353 | '!patrolled', |
342 | 354 | ) |
343 | 355 | ), |
344 | | - 'owner' => array ( |
345 | | - ApiBase :: PARAM_TYPE => 'user' |
| 356 | + 'owner' => array( |
| 357 | + ApiBase::PARAM_TYPE => 'user' |
346 | 358 | ), |
347 | | - 'token' => array ( |
348 | | - ApiBase :: PARAM_TYPE => 'string' |
| 359 | + 'token' => array( |
| 360 | + ApiBase::PARAM_TYPE => 'string' |
349 | 361 | ) |
350 | 362 | ); |
351 | 363 | } |
352 | 364 | |
353 | 365 | public function getParamDescription() { |
354 | | - return array ( |
| 366 | + return array( |
355 | 367 | 'allrev' => 'Include multiple revisions of the same page within given timeframe.', |
356 | 368 | 'start' => 'The timestamp to start enumerating from.', |
357 | 369 | 'end' => 'The timestamp to end enumerating.', |
— | — | @@ -360,7 +372,7 @@ |
361 | 373 | 'dir' => 'In which direction to enumerate pages.', |
362 | 374 | 'limit' => 'How many total results to return per request.', |
363 | 375 | 'prop' => 'Which additional items to get (non-generator mode only).', |
364 | | - 'show' => array ( |
| 376 | + 'show' => array( |
365 | 377 | 'Show only items that meet this criteria.', |
366 | 378 | 'For example, to see only minor edits done by logged-in users, set show=minor|!anon' |
367 | 379 | ), |
— | — | @@ -372,7 +384,7 @@ |
373 | 385 | public function getDescription() { |
374 | 386 | return "Get all recent changes to pages in the logged in user's watchlist"; |
375 | 387 | } |
376 | | - |
| 388 | + |
377 | 389 | public function getPossibleErrors() { |
378 | 390 | return array_merge( parent::getPossibleErrors(), array( |
379 | 391 | array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ), |
— | — | @@ -386,7 +398,7 @@ |
387 | 399 | } |
388 | 400 | |
389 | 401 | protected function getExamples() { |
390 | | - return array ( |
| 402 | + return array( |
391 | 403 | 'api.php?action=query&list=watchlist', |
392 | 404 | 'api.php?action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment', |
393 | 405 | 'api.php?action=query&list=watchlist&wlallrev&wlprop=ids|title|timestamp|user|comment', |
Index: trunk/phase3/includes/api/ApiUndelete.php |
— | — | @@ -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 ApiUndelete 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,37 +41,46 @@ |
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 | + } |
47 | 48 | |
48 | | - if ( !$wgUser->isAllowed( 'undelete' ) ) |
| 49 | + if ( !$wgUser->isAllowed( 'undelete' ) ) { |
49 | 50 | $this->dieUsageMsg( array( 'permdenied-undelete' ) ); |
| 51 | + } |
50 | 52 | |
51 | | - if ( $wgUser->isBlocked() ) |
| 53 | + if ( $wgUser->isBlocked() ) { |
52 | 54 | $this->dieUsageMsg( array( 'blockedtext' ) ); |
| 55 | + } |
53 | 56 | |
54 | 57 | $titleObj = Title::newFromText( $params['title'] ); |
55 | | - if ( !$titleObj ) |
| 58 | + if ( !$titleObj ) { |
56 | 59 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
| 60 | + } |
57 | 61 | |
58 | 62 | // Convert timestamps |
59 | | - if ( !isset( $params['timestamps'] ) ) |
| 63 | + if ( !isset( $params['timestamps'] ) ) { |
60 | 64 | $params['timestamps'] = array(); |
61 | | - if ( !is_array( $params['timestamps'] ) ) |
| 65 | + } |
| 66 | + if ( !is_array( $params['timestamps'] ) ) { |
62 | 67 | $params['timestamps'] = array( $params['timestamps'] ); |
63 | | - foreach ( $params['timestamps'] as $i => $ts ) |
| 68 | + } |
| 69 | + foreach ( $params['timestamps'] as $i => $ts ) { |
64 | 70 | $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts ); |
| 71 | + } |
65 | 72 | |
66 | 73 | $pa = new PageArchive( $titleObj ); |
67 | 74 | $dbw = wfGetDB( DB_MASTER ); |
68 | 75 | $dbw->begin(); |
69 | 76 | $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] ); |
70 | | - if ( !is_array( $retval ) ) |
| 77 | + if ( !is_array( $retval ) ) { |
71 | 78 | $this->dieUsageMsg( array( 'cannotundelete' ) ); |
| 79 | + } |
72 | 80 | |
73 | | - if ( $retval[1] ) |
| 81 | + if ( $retval[1] ) { |
74 | 82 | wfRunHooks( 'FileUndeleteComplete', |
75 | 83 | array( $titleObj, array(), $wgUser, $params['reason'] ) ); |
| 84 | + } |
76 | 85 | |
77 | 86 | $info['title'] = $titleObj->getPrefixedText(); |
78 | 87 | $info['revisions'] = intval( $retval[0] ); |
— | — | @@ -89,18 +98,18 @@ |
90 | 99 | } |
91 | 100 | |
92 | 101 | public function getAllowedParams() { |
93 | | - return array ( |
| 102 | + return array( |
94 | 103 | 'title' => null, |
95 | 104 | 'token' => null, |
96 | | - 'reason' => "", |
| 105 | + 'reason' => '', |
97 | 106 | 'timestamps' => array( |
98 | | - ApiBase :: PARAM_ISMULTI => true |
| 107 | + ApiBase::PARAM_ISMULTI => true |
99 | 108 | ) |
100 | 109 | ); |
101 | 110 | } |
102 | 111 | |
103 | 112 | public function getParamDescription() { |
104 | | - return array ( |
| 113 | + return array( |
105 | 114 | 'title' => 'Title of the page you want to restore.', |
106 | 115 | 'token' => 'An undelete token previously retrieved through list=deletedrevs', |
107 | 116 | 'reason' => 'Reason for restoring (optional)', |
— | — | @@ -114,7 +123,7 @@ |
115 | 124 | 'retrieved through list=deletedrevs' |
116 | 125 | ); |
117 | 126 | } |
118 | | - |
| 127 | + |
119 | 128 | public function getPossibleErrors() { |
120 | 129 | return array_merge( parent::getPossibleErrors(), array( |
121 | 130 | array( 'missingparam', 'title' ), |
— | — | @@ -124,13 +133,13 @@ |
125 | 134 | array( 'cannotundelete' ), |
126 | 135 | ) ); |
127 | 136 | } |
128 | | - |
| 137 | + |
129 | 138 | public function getTokenSalt() { |
130 | 139 | return ''; |
131 | 140 | } |
132 | 141 | |
133 | 142 | protected function getExamples() { |
134 | | - return array ( |
| 143 | + return array( |
135 | 144 | 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page', |
136 | 145 | 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856' |
137 | 146 | ); |
Index: trunk/phase3/includes/api/ApiQueryTags.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Jul 9, 2009 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2009 |
| 9 | + * Copyright © 2009 |
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 | /** |
— | — | @@ -34,127 +34,131 @@ |
35 | 35 | * @ingroup API |
36 | 36 | */ |
37 | 37 | class ApiQueryTags extends ApiQueryBase { |
38 | | - |
| 38 | + |
39 | 39 | private $limit, $result; |
40 | 40 | private $fld_displayname = false, $fld_description = false, |
41 | 41 | $fld_hitcount = false; |
42 | | - |
| 42 | + |
43 | 43 | public function __construct( $query, $moduleName ) { |
44 | | - parent :: __construct( $query, $moduleName, 'tg' ); |
| 44 | + parent::__construct( $query, $moduleName, 'tg' ); |
45 | 45 | } |
46 | 46 | |
47 | 47 | public function execute() { |
48 | 48 | $params = $this->extractRequestParams(); |
49 | | - |
| 49 | + |
50 | 50 | $prop = array_flip( $params['prop'] ); |
51 | | - |
| 51 | + |
52 | 52 | $this->fld_displayname = isset( $prop['displayname'] ); |
53 | 53 | $this->fld_description = isset( $prop['description'] ); |
54 | 54 | $this->fld_hitcount = isset( $prop['hitcount'] ); |
55 | | - |
| 55 | + |
56 | 56 | $this->limit = $params['limit']; |
57 | 57 | $this->result = $this->getResult(); |
58 | | - |
| 58 | + |
59 | 59 | $pageSet = $this->getPageSet(); |
60 | 60 | $titles = $pageSet->getTitles(); |
61 | 61 | $data = array(); |
62 | | - |
| 62 | + |
63 | 63 | $this->addTables( 'change_tag' ); |
64 | 64 | $this->addFields( 'ct_tag' ); |
65 | | - |
66 | | - if ( $this->fld_hitcount ) |
| 65 | + |
| 66 | + if ( $this->fld_hitcount ) { |
67 | 67 | $this->addFields( 'count(*) AS hitcount' ); |
68 | | - |
| 68 | + } |
| 69 | + |
69 | 70 | $this->addOption( 'LIMIT', $this->limit + 1 ); |
70 | 71 | $this->addOption( 'GROUP BY', 'ct_tag' ); |
71 | 72 | $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null ); |
72 | | - |
| 73 | + |
73 | 74 | $res = $this->select( __METHOD__ ); |
74 | | - |
| 75 | + |
75 | 76 | $ok = true; |
76 | | - |
| 77 | + |
77 | 78 | while ( $row = $res->fetchObject() ) { |
78 | | - if ( !$ok ) break; |
| 79 | + if ( !$ok ) { |
| 80 | + break; |
| 81 | + } |
79 | 82 | $ok = $this->doTag( $row->ct_tag, $row->hitcount ); |
80 | 83 | } |
81 | | - |
| 84 | + |
82 | 85 | // include tags with no hits yet |
83 | 86 | foreach ( ChangeTags::listDefinedTags() as $tag ) { |
84 | | - if ( !$ok ) break; |
| 87 | + if ( !$ok ) { |
| 88 | + break; |
| 89 | + } |
85 | 90 | $ok = $this->doTag( $tag, 0 ); |
86 | 91 | } |
87 | | - |
| 92 | + |
88 | 93 | $this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' ); |
89 | 94 | } |
90 | | - |
| 95 | + |
91 | 96 | private function doTag( $tagName, $hitcount ) { |
92 | 97 | static $count = 0; |
93 | 98 | static $doneTags = array(); |
94 | | - |
| 99 | + |
95 | 100 | if ( in_array( $tagName, $doneTags ) ) { |
96 | 101 | return true; |
97 | 102 | } |
98 | | - |
99 | | - if ( ++$count > $this->limit ) |
100 | | - { |
| 103 | + |
| 104 | + if ( ++$count > $this->limit ) { |
101 | 105 | $this->setContinueEnumParameter( 'continue', $tagName ); |
102 | 106 | return false; |
103 | 107 | } |
104 | | - |
| 108 | + |
105 | 109 | $tag = array(); |
106 | 110 | $tag['name'] = $tagName; |
107 | | - |
108 | | - if ( $this->fld_displayname ) |
| 111 | + |
| 112 | + if ( $this->fld_displayname ) { |
109 | 113 | $tag['displayname'] = ChangeTags::tagDescription( $tagName ); |
110 | | - |
111 | | - if ( $this->fld_description ) |
112 | | - { |
| 114 | + } |
| 115 | + |
| 116 | + if ( $this->fld_description ) { |
113 | 117 | $msg = wfMsg( "tag-$tagName-description" ); |
114 | 118 | $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg; |
115 | 119 | $tag['description'] = $msg; |
116 | 120 | } |
117 | | - |
118 | | - if ( $this->fld_hitcount ) |
| 121 | + |
| 122 | + if ( $this->fld_hitcount ) { |
119 | 123 | $tag['hitcount'] = $hitcount; |
120 | | - |
| 124 | + } |
| 125 | + |
121 | 126 | $doneTags[] = $tagName; |
122 | | - |
| 127 | + |
123 | 128 | $fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag ); |
124 | | - if ( !$fit ) |
125 | | - { |
| 129 | + if ( !$fit ) { |
126 | 130 | $this->setContinueEnumParameter( 'continue', $tagName ); |
127 | 131 | return false; |
128 | 132 | } |
129 | | - |
| 133 | + |
130 | 134 | return true; |
131 | 135 | } |
132 | | - |
| 136 | + |
133 | 137 | public function getAllowedParams() { |
134 | | - return array ( |
| 138 | + return array( |
135 | 139 | 'continue' => array( |
136 | 140 | ), |
137 | 141 | 'limit' => array( |
138 | | - ApiBase :: PARAM_DFLT => 10, |
139 | | - ApiBase :: PARAM_TYPE => 'limit', |
140 | | - ApiBase :: PARAM_MIN => 1, |
141 | | - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
142 | | - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 142 | + ApiBase::PARAM_DFLT => 10, |
| 143 | + ApiBase::PARAM_TYPE => 'limit', |
| 144 | + ApiBase::PARAM_MIN => 1, |
| 145 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 146 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
143 | 147 | ), |
144 | 148 | 'prop' => array( |
145 | | - ApiBase :: PARAM_DFLT => 'name', |
146 | | - ApiBase :: PARAM_TYPE => array( |
147 | | - 'name', |
148 | | - 'displayname', |
149 | | - 'description', |
150 | | - 'hitcount' |
151 | | - ), |
152 | | - ApiBase :: PARAM_ISMULTI => true |
| 149 | + ApiBase::PARAM_DFLT => 'name', |
| 150 | + ApiBase::PARAM_TYPE => array( |
| 151 | + 'name', |
| 152 | + 'displayname', |
| 153 | + 'description', |
| 154 | + 'hitcount' |
| 155 | + ), |
| 156 | + ApiBase::PARAM_ISMULTI => true |
153 | 157 | ) |
154 | 158 | ); |
155 | 159 | } |
156 | 160 | |
157 | 161 | public function getParamDescription() { |
158 | | - return array ( |
| 162 | + return array( |
159 | 163 | 'continue' => 'When more results are available, use this to continue', |
160 | 164 | 'limit' => 'The maximum number of tags to list', |
161 | 165 | 'prop' => 'Which properties to get', |
— | — | @@ -166,7 +170,7 @@ |
167 | 171 | } |
168 | 172 | |
169 | 173 | protected function getExamples() { |
170 | | - return array ( |
| 174 | + return array( |
171 | 175 | 'api.php?action=query&list=tags&tgprop=displayname|description|hitcount' |
172 | 176 | ); |
173 | 177 | } |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | | -/* |
| 3 | +/** |
4 | 4 | * Created on Aug 21, 2008 |
5 | 5 | * API for MediaWiki 1.8+ |
6 | 6 | * |
7 | | - * Copyright (C) 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 7 | + * Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
8 | 8 | * |
9 | 9 | * This program is free software; you can redistribute it and/or modify |
10 | 10 | * it under the terms of the GNU General Public License as published by |
— | — | @@ -41,8 +41,9 @@ |
42 | 42 | global $wgUser, $wgAllowCopyUploads; |
43 | 43 | |
44 | 44 | // Check whether upload is enabled |
45 | | - if ( !UploadBase::isEnabled() ) |
| 45 | + if ( !UploadBase::isEnabled() ) { |
46 | 46 | $this->dieUsageMsg( array( 'uploaddisabled' ) ); |
| 47 | + } |
47 | 48 | |
48 | 49 | $this->mParams = $this->extractRequestParams(); |
49 | 50 | $request = $this->getMain()->getRequest(); |
— | — | @@ -75,18 +76,18 @@ |
76 | 77 | * Upload stashed in a previous request |
77 | 78 | */ |
78 | 79 | // Check the session key |
79 | | - if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) ) |
| 80 | + if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) ) { |
80 | 81 | $this->dieUsageMsg( array( 'invalid-session-key' ) ); |
| 82 | + } |
81 | 83 | |
82 | 84 | $this->mUpload = new UploadFromStash(); |
83 | 85 | $this->mUpload->initialize( $this->mParams['filename'], |
84 | 86 | $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ); |
85 | 87 | } elseif ( isset( $this->mParams['filename'] ) ) { |
86 | 88 | /** |
87 | | - * Upload from url, etc |
| 89 | + * Upload from URL, etc. |
88 | 90 | * Parameter filename is required |
89 | 91 | */ |
90 | | - |
91 | 92 | if ( isset( $this->mParams['file'] ) ) { |
92 | 93 | $this->mUpload = new UploadFromFile(); |
93 | 94 | $this->mUpload->initialize( |
— | — | @@ -95,13 +96,15 @@ |
96 | 97 | $request->getFileSize( 'file' ) |
97 | 98 | ); |
98 | 99 | } elseif ( isset( $this->mParams['url'] ) ) { |
99 | | - // make sure upload by url is enabled: |
100 | | - if ( !$wgAllowCopyUploads ) |
| 100 | + // make sure upload by URL is enabled: |
| 101 | + if ( !$wgAllowCopyUploads ) { |
101 | 102 | $this->dieUsageMsg( array( 'uploaddisabled' ) ); |
| 103 | + } |
102 | 104 | |
103 | 105 | // make sure the current user can upload |
104 | | - if ( ! $wgUser->isAllowed( 'upload_by_url' ) ) |
| 106 | + if ( !$wgUser->isAllowed( 'upload_by_url' ) ) { |
105 | 107 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 108 | + } |
106 | 109 | |
107 | 110 | $this->mUpload = new UploadFromUrl(); |
108 | 111 | $this->mUpload->initialize( $this->mParams['filename'], |
— | — | @@ -112,19 +115,23 @@ |
113 | 116 | $this->dieUsage( $status->getWikiText(), 'fetchfileerror' ); |
114 | 117 | } |
115 | 118 | } |
116 | | - } else $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); |
| 119 | + } else { |
| 120 | + $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); |
| 121 | + } |
117 | 122 | |
118 | | - if ( !isset( $this->mUpload ) ) |
| 123 | + if ( !isset( $this->mUpload ) ) { |
119 | 124 | $this->dieUsage( 'No upload module set', 'nomodule' ); |
| 125 | + } |
120 | 126 | |
121 | 127 | // Check whether the user has the appropriate permissions to upload anyway |
122 | 128 | $permission = $this->mUpload->isAllowed( $wgUser ); |
123 | 129 | |
124 | 130 | if ( $permission !== true ) { |
125 | | - if ( !$wgUser->isLoggedIn() ) |
| 131 | + if ( !$wgUser->isLoggedIn() ) { |
126 | 132 | $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) ); |
127 | | - else |
| 133 | + } else { |
128 | 134 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 135 | + } |
129 | 136 | } |
130 | 137 | // Perform the upload |
131 | 138 | $result = $this->performUpload(); |
— | — | @@ -134,7 +141,9 @@ |
135 | 142 | |
136 | 143 | if ( isset( $result['chunked-output'] ) ) { |
137 | 144 | foreach ( $result['chunked-output'] as $key => $value ) { |
138 | | - if ( $value === null ) $value = ""; |
| 145 | + if ( $value === null ) { |
| 146 | + $value = ''; |
| 147 | + } |
139 | 148 | $this->getResult()->addValue( null, $key, $value ); |
140 | 149 | } |
141 | 150 | } else { |
— | — | @@ -209,7 +218,6 @@ |
210 | 219 | $warnings['duplicate'] = $dupes; |
211 | 220 | } |
212 | 221 | |
213 | | - |
214 | 222 | if ( isset( $warnings['exists'] ) ) { |
215 | 223 | $warning = $warnings['exists']; |
216 | 224 | unset( $warnings['exists'] ); |
— | — | @@ -220,8 +228,9 @@ |
221 | 229 | $result['warnings'] = $warnings; |
222 | 230 | |
223 | 231 | $sessionKey = $this->mUpload->stashSession(); |
224 | | - if ( !$sessionKey ) |
| 232 | + if ( !$sessionKey ) { |
225 | 233 | $this->dieUsage( 'Stashing temporary file failed', 'stashfailed' ); |
| 234 | + } |
226 | 235 | |
227 | 236 | $result['sessionkey'] = $sessionKey; |
228 | 237 | |
— | — | @@ -230,8 +239,9 @@ |
231 | 240 | } |
232 | 241 | |
233 | 242 | // Use comment as initial page text by default |
234 | | - if ( is_null( $this->mParams['text'] ) ) |
| 243 | + if ( is_null( $this->mParams['text'] ) ) { |
235 | 244 | $this->mParams['text'] = $this->mParams['comment']; |
| 245 | + } |
236 | 246 | |
237 | 247 | // No errors, no warnings: do the upload |
238 | 248 | $status = $this->mUpload->performUpload( $this->mParams['comment'], |
— | — | @@ -243,7 +253,7 @@ |
244 | 254 | |
245 | 255 | $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error ); |
246 | 256 | } elseif ( $this->mParams['enablechunks'] ) { |
247 | | - return array( "chunked-output" => $status->value ); |
| 257 | + return array( 'chunked-output' => $status->value ); |
248 | 258 | } |
249 | 259 | |
250 | 260 | $file = $this->mUpload->getLocalFile(); |
— | — | @@ -281,10 +291,10 @@ |
282 | 292 | 'sessionkey' => null, |
283 | 293 | ); |
284 | 294 | |
285 | | - if ( $this->getMain()->isInternalMode() ) |
| 295 | + if ( $this->getMain()->isInternalMode() ) { |
286 | 296 | $params['internalhttpsession'] = null; |
| 297 | + } |
287 | 298 | return $params; |
288 | | - |
289 | 299 | } |
290 | 300 | |
291 | 301 | public function getParamDescription() { |
— | — | @@ -320,8 +330,8 @@ |
321 | 331 | 'log out and then log back in). Also you must get and send an edit token before doing any upload stuff.' |
322 | 332 | ); |
323 | 333 | } |
324 | | - |
325 | | - public function getPossibleErrors() { |
| 334 | + |
| 335 | + public function getPossibleErrors() { |
326 | 336 | return array_merge( parent::getPossibleErrors(), array( |
327 | 337 | array( 'uploaddisabled' ), |
328 | 338 | array( 'invalid-session-key' ), |
— | — | @@ -339,9 +349,9 @@ |
340 | 350 | array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ), |
341 | 351 | array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ), |
342 | 352 | array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ), |
343 | | - ) ); |
| 353 | + ) ); |
344 | 354 | } |
345 | | - |
| 355 | + |
346 | 356 | public function getTokenSalt() { |
347 | 357 | return ''; |
348 | 358 | } |
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on Oct 16, 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 | /** |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | class ApiQueryContributions extends ApiQueryBase { |
38 | 38 | |
39 | 39 | public function __construct( $query, $moduleName ) { |
40 | | - parent :: __construct( $query, $moduleName, 'uc' ); |
| 40 | + parent::__construct( $query, $moduleName, 'uc' ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | private $params, $username; |
— | — | @@ -63,21 +63,21 @@ |
64 | 64 | $this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' ); |
65 | 65 | $db = $this->getDB(); |
66 | 66 | |
67 | | - if ( isset( $this->params['userprefix'] ) ) |
68 | | - { |
| 67 | + if ( isset( $this->params['userprefix'] ) ) { |
69 | 68 | $this->prefixMode = true; |
70 | 69 | $this->multiUserMode = true; |
71 | 70 | $this->userprefix = $this->params['userprefix']; |
72 | | - } |
73 | | - else |
74 | | - { |
| 71 | + } else { |
75 | 72 | $this->usernames = array(); |
76 | | - if ( !is_array( $this->params['user'] ) ) |
| 73 | + if ( !is_array( $this->params['user'] ) ) { |
77 | 74 | $this->params['user'] = array( $this->params['user'] ); |
78 | | - if ( !count( $this->params['user'] ) ) |
| 75 | + } |
| 76 | + if ( !count( $this->params['user'] ) ) { |
79 | 77 | $this->dieUsage( 'User parameter may not be empty.', 'param_user' ); |
80 | | - foreach ( $this->params['user'] as $u ) |
| 78 | + } |
| 79 | + foreach ( $this->params['user'] as $u ) { |
81 | 80 | $this->prepareUsername( $u ); |
| 81 | + } |
82 | 82 | $this->prefixMode = false; |
83 | 83 | $this->multiUserMode = ( count( $this->params['user'] ) > 1 ); |
84 | 84 | } |
— | — | @@ -94,21 +94,22 @@ |
95 | 95 | while ( $row = $db->fetchObject( $res ) ) { |
96 | 96 | if ( ++ $count > $limit ) { |
97 | 97 | // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
98 | | - if ( $this->multiUserMode ) |
| 98 | + if ( $this->multiUserMode ) { |
99 | 99 | $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) ); |
100 | | - else |
| 100 | + } else { |
101 | 101 | $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) ); |
| 102 | + } |
102 | 103 | break; |
103 | 104 | } |
104 | 105 | |
105 | 106 | $vals = $this->extractRowInfo( $row ); |
106 | 107 | $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
107 | | - if ( !$fit ) |
108 | | - { |
109 | | - if ( $this->multiUserMode ) |
| 108 | + if ( !$fit ) { |
| 109 | + if ( $this->multiUserMode ) { |
110 | 110 | $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) ); |
111 | | - else |
| 111 | + } else { |
112 | 112 | $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) ); |
| 113 | + } |
113 | 114 | break; |
114 | 115 | } |
115 | 116 | } |
— | — | @@ -150,32 +151,37 @@ |
151 | 152 | $this->addWhere( 'page_id=rev_page' ); |
152 | 153 | |
153 | 154 | // Handle continue parameter |
154 | | - if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) |
155 | | - { |
| 155 | + if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) { |
156 | 156 | $continue = explode( '|', $this->params['continue'] ); |
157 | | - if ( count( $continue ) != 2 ) |
158 | | - $this->dieUsage( "Invalid continue param. You should pass the original " . |
159 | | - "value returned by the previous query", "_badcontinue" ); |
| 157 | + if ( count( $continue ) != 2 ) { |
| 158 | + $this->dieUsage( 'Invalid continue param. You should pass the original ' . |
| 159 | + 'value returned by the previous query', '_badcontinue' ); |
| 160 | + } |
160 | 161 | $encUser = $this->getDB()->strencode( $continue[0] ); |
161 | 162 | $encTS = wfTimestamp( TS_MW, $continue[1] ); |
162 | 163 | $op = ( $this->params['dir'] == 'older' ? '<' : '>' ); |
163 | | - $this->addWhere( "rev_user_text $op '$encUser' OR " . |
164 | | - "(rev_user_text = '$encUser' AND " . |
165 | | - "rev_timestamp $op= '$encTS')" ); |
| 164 | + $this->addWhere( |
| 165 | + "rev_user_text $op '$encUser' OR " . |
| 166 | + "(rev_user_text = '$encUser' AND " . |
| 167 | + "rev_timestamp $op= '$encTS')" |
| 168 | + ); |
166 | 169 | } |
167 | 170 | |
168 | | - if ( !$wgUser->isAllowed( 'hideuser' ) ) |
| 171 | + if ( !$wgUser->isAllowed( 'hideuser' ) ) { |
169 | 172 | $this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ); |
| 173 | + } |
170 | 174 | // We only want pages by the specified users. |
171 | | - if ( $this->prefixMode ) |
| 175 | + if ( $this->prefixMode ) { |
172 | 176 | $this->addWhere( 'rev_user_text' . $this->getDB()->buildLike( $this->userprefix, $this->getDB()->anyString() ) ); |
173 | | - else |
| 177 | + } else { |
174 | 178 | $this->addWhereFld( 'rev_user_text', $this->usernames ); |
| 179 | + } |
175 | 180 | // ... and in the specified timeframe. |
176 | 181 | // Ensure the same sort order for rev_user_text and rev_timestamp |
177 | 182 | // so our query is indexed |
178 | | - if ( $this->multiUserMode ) |
| 183 | + if ( $this->multiUserMode ) { |
179 | 184 | $this->addWhereRange( 'rev_user_text', $this->params['dir'], null, null ); |
| 185 | + } |
180 | 186 | $this->addWhereRange( 'rev_timestamp', |
181 | 187 | $this->params['dir'], $this->params['start'], $this->params['end'] ); |
182 | 188 | $this->addWhereFld( 'page_namespace', $this->params['namespace'] ); |
— | — | @@ -185,7 +191,9 @@ |
186 | 192 | $show = array_flip( $show ); |
187 | 193 | if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) ) |
188 | 194 | || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) ) |
| 195 | + { |
189 | 196 | $this->dieUsageMsg( array( 'show' ) ); |
| 197 | + } |
190 | 198 | |
191 | 199 | $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) ); |
192 | 200 | $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) ); |
— | — | @@ -205,19 +213,19 @@ |
206 | 214 | 'rev_user_text', |
207 | 215 | 'rev_deleted' |
208 | 216 | ) ); |
209 | | - |
| 217 | + |
210 | 218 | if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) || |
211 | 219 | $this->fld_patrolled ) |
212 | 220 | { |
213 | 221 | global $wgUser; |
214 | | - if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) |
215 | | - $this->dieUsage( "You need the patrol right to request the patrolled flag", 'permissiondenied' ); |
| 222 | + if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) { |
| 223 | + $this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' ); |
| 224 | + } |
216 | 225 | // Use a redundant join condition on both |
217 | 226 | // timestamp and ID so we can use the timestamp |
218 | 227 | // index |
219 | 228 | $index['recentchanges'] = 'rc_user_text'; |
220 | | - if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) |
221 | | - { |
| 229 | + if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) { |
222 | 230 | // Put the tables in the right order for |
223 | 231 | // STRAIGHT_JOIN |
224 | 232 | $tables = array( 'revision', 'recentchanges', 'page' ); |
— | — | @@ -225,9 +233,7 @@ |
226 | 234 | $this->addWhere( 'rc_user_text=rev_user_text' ); |
227 | 235 | $this->addWhere( 'rc_timestamp=rev_timestamp' ); |
228 | 236 | $this->addWhere( 'rc_this_oldid=rev_id' ); |
229 | | - } |
230 | | - else |
231 | | - { |
| 237 | + } else { |
232 | 238 | $tables[] = 'recentchanges'; |
233 | 239 | $this->addJoinConds( array( 'recentchanges' => array( |
234 | 240 | 'LEFT JOIN', array( |
— | — | @@ -241,28 +247,27 @@ |
242 | 248 | $this->addFieldsIf( 'rev_page', $this->fld_ids ); |
243 | 249 | $this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags ); |
244 | 250 | $this->addFieldsIf( 'page_latest', $this->fld_flags ); |
245 | | - // $this->addFieldsIf('rev_text_id', $this->fld_ids); // Should this field be exposed? |
| 251 | + // $this->addFieldsIf( 'rev_text_id', $this->fld_ids ); // Should this field be exposed? |
246 | 252 | $this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment ); |
247 | 253 | $this->addFieldsIf( 'rev_len', $this->fld_size ); |
248 | 254 | $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags ); |
249 | 255 | $this->addFieldsIf( 'rev_parent_id', $this->fld_flags ); |
250 | 256 | $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled ); |
251 | | - |
252 | | - if ( $this->fld_tags ) |
253 | | - { |
| 257 | + |
| 258 | + if ( $this->fld_tags ) { |
254 | 259 | $this->addTables( 'tag_summary' ); |
255 | 260 | $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) ); |
256 | 261 | $this->addFields( 'ts_tags' ); |
257 | 262 | } |
258 | | - |
| 263 | + |
259 | 264 | if ( isset( $this->params['tag'] ) ) { |
260 | 265 | $this->addTables( 'change_tag' ); |
261 | 266 | $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) ); |
262 | 267 | $this->addWhereFld( 'ct_tag', $this->params['tag'] ); |
263 | 268 | global $wgOldChangeTagsIndex; |
264 | | - $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; |
| 269 | + $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; |
265 | 270 | } |
266 | | - |
| 271 | + |
267 | 272 | $this->addOption( 'USE INDEX', $index ); |
268 | 273 | } |
269 | 274 | |
— | — | @@ -270,42 +275,48 @@ |
271 | 276 | * Extract fields from the database row and append them to a result array |
272 | 277 | */ |
273 | 278 | private function extractRowInfo( $row ) { |
274 | | - |
275 | 279 | $vals = array(); |
276 | 280 | |
277 | 281 | $vals['user'] = $row->rev_user_text; |
278 | | - if ( $row->rev_deleted & Revision::DELETED_USER ) |
| 282 | + if ( $row->rev_deleted & Revision::DELETED_USER ) { |
279 | 283 | $vals['userhidden'] = ''; |
| 284 | + } |
280 | 285 | if ( $this->fld_ids ) { |
281 | 286 | $vals['pageid'] = intval( $row->rev_page ); |
282 | 287 | $vals['revid'] = intval( $row->rev_id ); |
283 | | - // $vals['textid'] = intval($row->rev_text_id); // todo: Should this field be exposed? |
| 288 | + // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed? |
284 | 289 | } |
285 | 290 | |
286 | 291 | $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
287 | 292 | |
288 | | - if ( $this->fld_title ) |
| 293 | + if ( $this->fld_title ) { |
289 | 294 | ApiQueryBase::addTitleInfo( $vals, $title ); |
| 295 | + } |
290 | 296 | |
291 | | - if ( $this->fld_timestamp ) |
| 297 | + if ( $this->fld_timestamp ) { |
292 | 298 | $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp ); |
| 299 | + } |
293 | 300 | |
294 | 301 | if ( $this->fld_flags ) { |
295 | | - if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) ) |
| 302 | + if ( $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id ) ) { |
296 | 303 | $vals['new'] = ''; |
297 | | - if ( $row->rev_minor_edit ) |
| 304 | + } |
| 305 | + if ( $row->rev_minor_edit ) { |
298 | 306 | $vals['minor'] = ''; |
299 | | - if ( $row->page_latest == $row->rev_id ) |
| 307 | + } |
| 308 | + if ( $row->page_latest == $row->rev_id ) { |
300 | 309 | $vals['top'] = ''; |
| 310 | + } |
301 | 311 | } |
302 | 312 | |
303 | 313 | if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) { |
304 | | - if ( $row->rev_deleted & Revision::DELETED_COMMENT ) |
| 314 | + if ( $row->rev_deleted & Revision::DELETED_COMMENT ) { |
305 | 315 | $vals['commenthidden'] = ''; |
306 | | - else { |
307 | | - if ( $this->fld_comment ) |
| 316 | + } else { |
| 317 | + if ( $this->fld_comment ) { |
308 | 318 | $vals['comment'] = $row->rev_comment; |
309 | | - |
| 319 | + } |
| 320 | + |
310 | 321 | if ( $this->fld_parsedcomment ) { |
311 | 322 | global $wgUser; |
312 | 323 | $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title ); |
— | — | @@ -313,11 +324,13 @@ |
314 | 325 | } |
315 | 326 | } |
316 | 327 | |
317 | | - if ( $this->fld_patrolled && $row->rc_patrolled ) |
| 328 | + if ( $this->fld_patrolled && $row->rc_patrolled ) { |
318 | 329 | $vals['patrolled'] = ''; |
319 | | - |
320 | | - if ( $this->fld_size && !is_null( $row->rev_len ) ) |
| 330 | + } |
| 331 | + |
| 332 | + if ( $this->fld_size && !is_null( $row->rev_len ) ) { |
321 | 333 | $vals['size'] = intval( $row->rev_len ); |
| 334 | + } |
322 | 335 | |
323 | 336 | if ( $this->fld_tags ) { |
324 | 337 | if ( $row->ts_tags ) { |
— | — | @@ -328,51 +341,50 @@ |
329 | 342 | $vals['tags'] = array(); |
330 | 343 | } |
331 | 344 | } |
332 | | - |
| 345 | + |
333 | 346 | return $vals; |
334 | 347 | } |
335 | | - |
336 | | - private function continueStr( $row ) |
337 | | - { |
| 348 | + |
| 349 | + private function continueStr( $row ) { |
338 | 350 | return $row->rev_user_text . '|' . |
339 | 351 | wfTimestamp( TS_ISO_8601, $row->rev_timestamp ); |
340 | 352 | } |
341 | 353 | |
342 | 354 | public function getAllowedParams() { |
343 | | - return array ( |
344 | | - 'limit' => array ( |
345 | | - ApiBase :: PARAM_DFLT => 10, |
346 | | - ApiBase :: PARAM_TYPE => 'limit', |
347 | | - ApiBase :: PARAM_MIN => 1, |
348 | | - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
349 | | - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 355 | + return array( |
| 356 | + 'limit' => array( |
| 357 | + ApiBase::PARAM_DFLT => 10, |
| 358 | + ApiBase::PARAM_TYPE => 'limit', |
| 359 | + ApiBase::PARAM_MIN => 1, |
| 360 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 361 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
350 | 362 | ), |
351 | | - 'start' => array ( |
352 | | - ApiBase :: PARAM_TYPE => 'timestamp' |
| 363 | + 'start' => array( |
| 364 | + ApiBase::PARAM_TYPE => 'timestamp' |
353 | 365 | ), |
354 | | - 'end' => array ( |
355 | | - ApiBase :: PARAM_TYPE => 'timestamp' |
| 366 | + 'end' => array( |
| 367 | + ApiBase::PARAM_TYPE => 'timestamp' |
356 | 368 | ), |
357 | 369 | 'continue' => null, |
358 | | - 'user' => array ( |
359 | | - ApiBase :: PARAM_ISMULTI => true |
| 370 | + 'user' => array( |
| 371 | + ApiBase::PARAM_ISMULTI => true |
360 | 372 | ), |
361 | 373 | 'userprefix' => null, |
362 | | - 'dir' => array ( |
363 | | - ApiBase :: PARAM_DFLT => 'older', |
364 | | - ApiBase :: PARAM_TYPE => array ( |
| 374 | + 'dir' => array( |
| 375 | + ApiBase::PARAM_DFLT => 'older', |
| 376 | + ApiBase::PARAM_TYPE => array( |
365 | 377 | 'newer', |
366 | 378 | 'older' |
367 | 379 | ) |
368 | 380 | ), |
369 | | - 'namespace' => array ( |
370 | | - ApiBase :: PARAM_ISMULTI => true, |
371 | | - ApiBase :: PARAM_TYPE => 'namespace' |
| 381 | + 'namespace' => array( |
| 382 | + ApiBase::PARAM_ISMULTI => true, |
| 383 | + ApiBase::PARAM_TYPE => 'namespace' |
372 | 384 | ), |
373 | | - 'prop' => array ( |
374 | | - ApiBase :: PARAM_ISMULTI => true, |
375 | | - ApiBase :: PARAM_DFLT => 'ids|title|timestamp|comment|size|flags', |
376 | | - ApiBase :: PARAM_TYPE => array ( |
| 385 | + 'prop' => array( |
| 386 | + ApiBase::PARAM_ISMULTI => true, |
| 387 | + ApiBase::PARAM_DFLT => 'ids|title|timestamp|comment|size|flags', |
| 388 | + ApiBase::PARAM_TYPE => array( |
377 | 389 | 'ids', |
378 | 390 | 'title', |
379 | 391 | 'timestamp', |
— | — | @@ -384,9 +396,9 @@ |
385 | 397 | 'tags' |
386 | 398 | ) |
387 | 399 | ), |
388 | | - 'show' => array ( |
389 | | - ApiBase :: PARAM_ISMULTI => true, |
390 | | - ApiBase :: PARAM_TYPE => array ( |
| 400 | + 'show' => array( |
| 401 | + ApiBase::PARAM_ISMULTI => true, |
| 402 | + ApiBase::PARAM_TYPE => array( |
391 | 403 | 'minor', |
392 | 404 | '!minor', |
393 | 405 | 'patrolled', |
— | — | @@ -398,7 +410,7 @@ |
399 | 411 | } |
400 | 412 | |
401 | 413 | public function getParamDescription() { |
402 | | - return array ( |
| 414 | + return array( |
403 | 415 | 'limit' => 'The maximum number of contributions to return.', |
404 | 416 | 'start' => 'The start timestamp to return from.', |
405 | 417 | 'end' => 'The end timestamp to return to.', |
— | — | @@ -417,7 +429,7 @@ |
418 | 430 | public function getDescription() { |
419 | 431 | return 'Get all edits by a user'; |
420 | 432 | } |
421 | | - |
| 433 | + |
422 | 434 | public function getPossibleErrors() { |
423 | 435 | return array_merge( parent::getPossibleErrors(), array( |
424 | 436 | array( 'code' => 'param_user', 'info' => 'User parameter may not be empty.' ), |
— | — | @@ -428,7 +440,7 @@ |
429 | 441 | } |
430 | 442 | |
431 | 443 | protected function getExamples() { |
432 | | - return array ( |
| 444 | + return array( |
433 | 445 | 'api.php?action=query&list=usercontribs&ucuser=YurikBot', |
434 | 446 | 'api.php?action=query&list=usercontribs&ucuserprefix=217.121.114.', |
435 | 447 | ); |
Index: trunk/phase3/includes/api/ApiQueryUsers.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/* |
| 4 | +/** |
5 | 5 | * Created on July 30, 2007 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
9 | | - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 9 | + * Copyright © 2007 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 ( 'ApiQueryBase.php' ); |
| 29 | + require_once( 'ApiQueryBase.php' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -36,9 +36,9 @@ |
37 | 37 | class ApiQueryUsers extends ApiQueryBase { |
38 | 38 | |
39 | 39 | public function __construct( $query, $moduleName ) { |
40 | | - parent :: __construct( $query, $moduleName, 'us' ); |
| 40 | + parent::__construct( $query, $moduleName, 'us' ); |
41 | 41 | } |
42 | | - |
| 42 | + |
43 | 43 | /** |
44 | 44 | * Get an array mapping token names to their handler functions. |
45 | 45 | * The prototype for a token function is func($user) |
— | — | @@ -47,12 +47,14 @@ |
48 | 48 | */ |
49 | 49 | protected function getTokenFunctions() { |
50 | 50 | // Don't call the hooks twice |
51 | | - if ( isset( $this->tokenFunctions ) ) |
| 51 | + if ( isset( $this->tokenFunctions ) ) { |
52 | 52 | return $this->tokenFunctions; |
| 53 | + } |
53 | 54 | |
54 | 55 | // If we're in JSON callback mode, no tokens can be obtained |
55 | | - if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) |
| 56 | + if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) { |
56 | 57 | return array(); |
| 58 | + } |
57 | 59 | |
58 | 60 | $this->tokenFunctions = array( |
59 | 61 | 'userrights' => array( 'ApiQueryUsers', 'getUserrightsToken' ), |
— | — | @@ -60,9 +62,8 @@ |
61 | 63 | wfRunHooks( 'APIQueryUsersTokens', array( &$this->tokenFunctions ) ); |
62 | 64 | return $this->tokenFunctions; |
63 | 65 | } |
64 | | - |
65 | | - public static function getUserrightsToken( $user ) |
66 | | - { |
| 66 | + |
| 67 | + public static function getUserrightsToken( $user ) { |
67 | 68 | global $wgUser; |
68 | 69 | // Since the permissions check for userrights is non-trivial, |
69 | 70 | // don't bother with it here |
— | — | @@ -86,26 +87,23 @@ |
87 | 88 | // Canonicalize user names |
88 | 89 | foreach ( $users as $u ) { |
89 | 90 | $n = User::getCanonicalName( $u ); |
90 | | - if ( $n === false || $n === '' ) |
91 | | - { |
| 91 | + if ( $n === false || $n === '' ) { |
92 | 92 | $vals = array( 'name' => $u, 'invalid' => '' ); |
93 | 93 | $fit = $result->addValue( array( 'query', $this->getModuleName() ), |
94 | 94 | null, $vals ); |
95 | | - if ( !$fit ) |
96 | | - { |
| 95 | + if ( !$fit ) { |
97 | 96 | $this->setContinueEnumParameter( 'users', |
98 | 97 | implode( '|', array_diff( $users, $done ) ) ); |
99 | 98 | $goodNames = array(); |
100 | 99 | break; |
101 | 100 | } |
102 | 101 | $done[] = $u; |
| 102 | + } else { |
| 103 | + $goodNames[] = $n; |
103 | 104 | } |
104 | | - else |
105 | | - $goodNames[] = $n; |
106 | 105 | } |
107 | 106 | |
108 | | - if ( count( $goodNames ) ) |
109 | | - { |
| 107 | + if ( count( $goodNames ) ) { |
110 | 108 | $db = $this->getDb(); |
111 | 109 | $this->addTables( 'user', 'u1' ); |
112 | 110 | $this->addFields( 'u1.*' ); |
— | — | @@ -132,19 +130,23 @@ |
133 | 131 | $user = User::newFromRow( $r ); |
134 | 132 | $name = $user->getName(); |
135 | 133 | $data[$name]['name'] = $name; |
136 | | - if ( isset( $this->prop['editcount'] ) ) |
| 134 | + if ( isset( $this->prop['editcount'] ) ) { |
137 | 135 | $data[$name]['editcount'] = intval( $user->getEditCount() ); |
138 | | - if ( isset( $this->prop['registration'] ) ) |
| 136 | + } |
| 137 | + if ( isset( $this->prop['registration'] ) ) { |
139 | 138 | $data[$name]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() ); |
140 | | - if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) |
| 139 | + } |
| 140 | + if ( isset( $this->prop['groups'] ) && !is_null( $r->ug_group ) ) { |
141 | 141 | // This row contains only one group, others will be added from other rows |
142 | 142 | $data[$name]['groups'][] = $r->ug_group; |
| 143 | + } |
143 | 144 | if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) { |
144 | 145 | $data[$name]['blockedby'] = $r->blocker_name; |
145 | 146 | $data[$name]['blockreason'] = $r->ipb_reason; |
146 | 147 | } |
147 | | - if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) |
| 148 | + if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) { |
148 | 149 | $data[$name]['emailable'] = ''; |
| 150 | + } |
149 | 151 | |
150 | 152 | if ( isset( $this->prop['gender'] ) ) { |
151 | 153 | $gender = $user->getOption( 'gender' ); |
— | — | @@ -154,16 +156,15 @@ |
155 | 157 | $data[$name]['gender'] = $gender; |
156 | 158 | } |
157 | 159 | |
158 | | - if ( !is_null( $params['token'] ) ) |
159 | | - { |
| 160 | + if ( !is_null( $params['token'] ) ) { |
160 | 161 | $tokenFunctions = $this->getTokenFunctions(); |
161 | | - foreach ( $params['token'] as $t ) |
162 | | - { |
| 162 | + foreach ( $params['token'] as $t ) { |
163 | 163 | $val = call_user_func( $tokenFunctions[$t], $user ); |
164 | | - if ( $val === false ) |
| 164 | + if ( $val === false ) { |
165 | 165 | $this->setWarning( "Action '$t' is not allowed for the current user" ); |
166 | | - else |
| 166 | + } else { |
167 | 167 | $data[$name][$t . 'token'] = $val; |
| 168 | + } |
168 | 169 | } |
169 | 170 | } |
170 | 171 | } |
— | — | @@ -176,28 +177,29 @@ |
177 | 178 | $iwUser = $urPage->fetchUser( $u ); |
178 | 179 | if ( $iwUser instanceof UserRightsProxy ) { |
179 | 180 | $data[$u]['interwiki'] = ''; |
180 | | - if ( !is_null( $params['token'] ) ) |
181 | | - { |
| 181 | + if ( !is_null( $params['token'] ) ) { |
182 | 182 | $tokenFunctions = $this->getTokenFunctions(); |
183 | | - foreach ( $params['token'] as $t ) |
184 | | - { |
| 183 | + foreach ( $params['token'] as $t ) { |
185 | 184 | $val = call_user_func( $tokenFunctions[$t], $iwUser ); |
186 | | - if ( $val === false ) |
| 185 | + if ( $val === false ) { |
187 | 186 | $this->setWarning( "Action '$t' is not allowed for the current user" ); |
188 | | - else |
| 187 | + } else { |
189 | 188 | $data[$u][$t . 'token'] = $val; |
| 189 | + } |
190 | 190 | } |
191 | 191 | } |
192 | | - } else |
| 192 | + } else { |
193 | 193 | $data[$u]['missing'] = ''; |
| 194 | + } |
194 | 195 | } else { |
195 | 196 | if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) |
| 197 | + { |
196 | 198 | $this->getResult()->setIndexedTagName( $data[$u]['groups'], 'g' ); |
| 199 | + } |
197 | 200 | } |
198 | 201 | $fit = $result->addValue( array( 'query', $this->getModuleName() ), |
199 | 202 | null, $data[$u] ); |
200 | | - if ( !$fit ) |
201 | | - { |
| 203 | + if ( !$fit ) { |
202 | 204 | $this->setContinueEnumParameter( 'users', |
203 | 205 | implode( '|', array_diff( $users, $done ) ) ); |
204 | 206 | break; |
— | — | @@ -208,11 +210,11 @@ |
209 | 211 | } |
210 | 212 | |
211 | 213 | public function getAllowedParams() { |
212 | | - return array ( |
213 | | - 'prop' => array ( |
214 | | - ApiBase :: PARAM_DFLT => null, |
215 | | - ApiBase :: PARAM_ISMULTI => true, |
216 | | - ApiBase :: PARAM_TYPE => array ( |
| 214 | + return array( |
| 215 | + 'prop' => array( |
| 216 | + ApiBase::PARAM_DFLT => null, |
| 217 | + ApiBase::PARAM_ISMULTI => true, |
| 218 | + ApiBase::PARAM_TYPE => array( |
217 | 219 | 'blockinfo', |
218 | 220 | 'groups', |
219 | 221 | 'editcount', |
— | — | @@ -222,17 +224,17 @@ |
223 | 225 | ) |
224 | 226 | ), |
225 | 227 | 'users' => array( |
226 | | - ApiBase :: PARAM_ISMULTI => true |
| 228 | + ApiBase::PARAM_ISMULTI => true |
227 | 229 | ), |
228 | 230 | 'token' => array( |
229 | | - ApiBase :: PARAM_TYPE => array_keys( $this->getTokenFunctions() ), |
230 | | - ApiBase :: PARAM_ISMULTI => true |
| 231 | + ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ), |
| 232 | + ApiBase::PARAM_ISMULTI => true |
231 | 233 | ), |
232 | 234 | ); |
233 | 235 | } |
234 | 236 | |
235 | 237 | public function getParamDescription() { |
236 | | - return array ( |
| 238 | + return array( |
237 | 239 | 'prop' => array( |
238 | 240 | 'What pieces of information to include', |
239 | 241 | ' blockinfo - tags if the user is blocked, by whom, and for what reason', |