r63005 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63004‎ | r63005 | r63006 >
Date:13:18, 26 February 2010
Author:ashley
Status:ok
Tags:
Comment:
API: fix copyright symbol, coding style cleanup, more braces
Modified paths:
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryTags.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserContributions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlistRaw.php (modified) (history)
  • /trunk/phase3/includes/api/ApiResult.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRollback.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUserrights.php (modified) (history)
  • /trunk/phase3/includes/api/ApiWatch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiWatch.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Jan 4, 2008
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
 9+ * Copyright © 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiBase.php' );
 29+ require_once( 'ApiBase.php' );
3030 }
3131
3232 /**
@@ -36,35 +36,35 @@
3737 class ApiWatch extends ApiBase {
3838
3939 public function __construct( $main, $action ) {
40 - parent :: __construct( $main, $action );
 40+ parent::__construct( $main, $action );
4141 }
4242
4343 public function execute() {
4444 global $wgUser;
45 - if ( !$wgUser->isLoggedIn() )
 45+ if ( !$wgUser->isLoggedIn() ) {
4646 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
 47+ }
4748
4849 $params = $this->extractRequestParams();
4950 $title = Title::newFromText( $params['title'] );
5051
51 - if ( !$title )
 52+ if ( !$title ) {
5253 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 54+ }
5355
5456 $article = new Article( $title );
5557 $res = array( 'title' => $title->getPrefixedText() );
5658
57 - if ( $params['unwatch'] )
58 - {
 59+ if ( $params['unwatch'] ) {
5960 $res['unwatched'] = '';
6061 $success = $article->doUnwatch();
61 - }
62 - else
63 - {
 62+ } else {
6463 $res['watched'] = '';
6564 $success = $article->doWatch();
6665 }
67 - if ( !$success )
 66+ if ( !$success ) {
6867 $this->dieUsageMsg( array( 'hookaborted' ) );
 68+ }
6969 $this->getResult()->addValue( null, $this->getModuleName(), $res );
7070 }
7171
@@ -73,25 +73,25 @@
7474 }
7575
7676 public function getAllowedParams() {
77 - return array (
 77+ return array(
7878 'title' => null,
7979 'unwatch' => false,
8080 );
8181 }
8282
8383 public function getParamDescription() {
84 - return array (
 84+ return array(
8585 'title' => 'The page to (un)watch',
8686 'unwatch' => 'If set the page will be unwatched rather than watched',
8787 );
8888 }
8989
9090 public function getDescription() {
91 - return array (
 91+ return array(
9292 'Add or remove a page from/to the current user\'s watchlist'
9393 );
9494 }
95 -
 95+
9696 public function getPossibleErrors() {
9797 return array_merge( parent::getPossibleErrors(), array(
9898 array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 25, 2006
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -36,16 +36,14 @@
3737 class ApiQuerySiteinfo extends ApiQueryBase {
3838
3939 public function __construct( $query, $moduleName ) {
40 - parent :: __construct( $query, $moduleName, 'si' );
 40+ parent::__construct( $query, $moduleName, 'si' );
4141 }
4242
4343 public function execute() {
4444 $params = $this->extractRequestParams();
4545 $done = array();
46 - foreach ( $params['prop'] as $p )
47 - {
48 - switch ( $p )
49 - {
 46+ foreach ( $params['prop'] as $p ) {
 47+ switch ( $p ) {
5048 case 'general':
5149 $fit = $this->appendGeneralInfo( $p );
5250 break;
@@ -86,11 +84,10 @@
8785 case 'languages':
8886 $fit = $this->appendLanguages( $p );
8987 break;
90 - default :
91 - ApiBase :: dieDebug( __METHOD__, "Unknown prop=$p" );
 88+ default:
 89+ ApiBase::dieDebug( __METHOD__, "Unknown prop=$p" );
9290 }
93 - if ( !$fit )
94 - {
 91+ if ( !$fit ) {
9592 // Abuse siprop as a query-continue parameter
9693 // and set it to all unprocessed props
9794 $this->setContinueEnumParameter( 'prop', implode( '|',
@@ -102,11 +99,10 @@
103100 }
104101
105102 protected function appendGeneralInfo( $property ) {
106 - global $wgContLang;
107 - global $wgLang;
 103+ global $wgContLang, $wgLang;
108104
109105 $data = array();
110 - $mainPage = Title :: newFromText( wfMsgForContent( 'mainpage' ) );
 106+ $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) );
111107 $data['mainpage'] = $mainPage->getPrefixedText();
112108 $data['base'] = $mainPage->getFullUrl();
113109 $data['sitename'] = $GLOBALS['wgSitename'];
@@ -117,26 +113,30 @@
118114 $data['dbversion'] = $this->getDB()->getServerVersion();
119115
120116 $svn = SpecialVersion::getSvnRevision( $GLOBALS['IP'] );
121 - if ( $svn )
 117+ if ( $svn ) {
122118 $data['rev'] = $svn;
 119+ }
123120
124121 // 'case-insensitive' option is reserved for future
125122 $data['case'] = $GLOBALS['wgCapitalLinks'] ? 'first-letter' : 'case-sensitive';
126123
127 - if ( isset( $GLOBALS['wgRightsCode'] ) )
 124+ if ( isset( $GLOBALS['wgRightsCode'] ) ) {
128125 $data['rightscode'] = $GLOBALS['wgRightsCode'];
 126+ }
129127 $data['rights'] = $GLOBALS['wgRightsText'];
130128 $data['lang'] = $GLOBALS['wgLanguageCode'];
131 - if ( $wgContLang->isRTL() )
 129+ if ( $wgContLang->isRTL() ) {
132130 $data['rtl'] = '';
 131+ }
133132 $data['fallback8bitEncoding'] = $wgLang->fallback8bitEncoding();
134 -
 133+
135134 if ( wfReadOnly() ) {
136135 $data['readonly'] = '';
137136 $data['readonlyreason'] = wfReadOnlyReason();
138137 }
139 - if ( $GLOBALS['wgEnableWriteAPI'] )
 138+ if ( $GLOBALS['wgEnableWriteAPI'] ) {
140139 $data['writeapi'] = '';
 140+ }
141141
142142 $tz = $GLOBALS['wgLocaltimezone'];
143143 $offset = $GLOBALS['wgLocalTZoffset'];
@@ -162,23 +162,25 @@
163163 protected function appendNamespaces( $property ) {
164164 global $wgContLang;
165165 $data = array();
166 - foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title )
167 - {
 166+ foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
168167 $data[$ns] = array(
169168 'id' => intval( $ns ),
170169 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
171170 );
172 - ApiResult :: setContent( $data[$ns], $title );
 171+ ApiResult::setContent( $data[$ns], $title );
173172 $canonical = MWNamespace::getCanonicalName( $ns );
174 -
175 - if ( MWNamespace::hasSubpages( $ns ) )
 173+
 174+ if ( MWNamespace::hasSubpages( $ns ) ) {
176175 $data[$ns]['subpages'] = '';
177 -
178 - if ( $canonical )
 176+ }
 177+
 178+ if ( $canonical ) {
179179 $data[$ns]['canonical'] = strtr( $canonical, '_', ' ' );
180 -
181 - if ( MWNamespace::isContent( $ns ) )
 180+ }
 181+
 182+ if ( MWNamespace::isContent( $ns ) ) {
182183 $data[$ns]['content'] = '';
 184+ }
183185 }
184186
185187 $this->getResult()->setIndexedTagName( $data, 'ns' );
@@ -198,7 +200,7 @@
199201 $item = array(
200202 'id' => intval( $ns )
201203 );
202 - ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) );
 204+ ApiResult::setContent( $item, strtr( $title, '_', ' ' ) );
203205 $data[] = $item;
204206 }
205207
@@ -218,16 +220,16 @@
219221 $this->getResult()->setIndexedTagName( $data, 'specialpage' );
220222 return $this->getResult()->addValue( 'query', $property, $data );
221223 }
222 -
 224+
223225 protected function appendMagicWords( $property ) {
224226 global $wgContLang;
225227 $data = array();
226 - foreach ( $wgContLang->getMagicWords() as $magicword => $aliases )
227 - {
 228+ foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
228229 $caseSensitive = array_shift( $aliases );
229230 $arr = array( 'name' => $magicword, 'aliases' => $aliases );
230 - if ( $caseSensitive )
 231+ if ( $caseSensitive ) {
231232 $arr['case-sensitive'] = '';
 233+ }
232234 $this->getResult()->setIndexedTagName( $arr['aliases'], 'alias' );
233235 $data[] = $arr;
234236 }
@@ -240,12 +242,13 @@
241243 $this->addTables( 'interwiki' );
242244 $this->addFields( array( 'iw_prefix', 'iw_local', 'iw_url' ) );
243245
244 - if ( $filter === 'local' )
 246+ if ( $filter === 'local' ) {
245247 $this->addWhere( 'iw_local = 1' );
246 - elseif ( $filter === '!local' )
 248+ } elseif ( $filter === '!local' ) {
247249 $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+ }
250253
251254 $this->addOption( 'ORDER BY', 'iw_prefix' );
252255
@@ -254,15 +257,16 @@
255258
256259 $data = array();
257260 $langNames = Language::getLanguageNames();
258 - while ( $row = $db->fetchObject( $res ) )
259 - {
 261+ while ( $row = $db->fetchObject( $res ) ) {
260262 $val = array();
261263 $val['prefix'] = $row->iw_prefix;
262 - if ( $row->iw_local == '1' )
 264+ if ( $row->iw_local == '1' ) {
263265 $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] ) ) {
266269 $val['language'] = $langNames[$row->iw_prefix];
 270+ }
267271 $val['url'] = $row->iw_url;
268272
269273 $data[] = $val;
@@ -277,8 +281,9 @@
278282 global $wgShowHostnames;
279283 $data = array();
280284 if ( $includeAll ) {
281 - if ( !$wgShowHostnames )
 285+ if ( !$wgShowHostnames ) {
282286 $this->dieUsage( 'Cannot view all servers info unless $wgShowHostnames is true', 'includeAllDenied' );
 287+ }
283288
284289 $lb = wfGetLB();
285290 $lags = $lb->getLagTimes();
@@ -326,9 +331,10 @@
327332 'name' => $group,
328333 'rights' => array_keys( $permissions, true ),
329334 );
330 - if ( $numberInGroup )
 335+ if ( $numberInGroup ) {
331336 $arr['number'] = SiteStats::numberInGroup( $group );
332 -
 337+ }
 338+
333339 $this->getResult()->setIndexedTagName( $arr['rights'], 'permission' );
334340 $data[] = $arr;
335341 }
@@ -336,10 +342,10 @@
337343 $this->getResult()->setIndexedTagName( $data, 'group' );
338344 return $this->getResult()->addValue( 'query', $property, $data );
339345 }
340 -
 346+
341347 protected function appendFileExtensions( $property ) {
342348 global $wgFileExtensions;
343 -
 349+
344350 $data = array();
345351 foreach ( $wgFileExtensions as $ext ) {
346352 $data[] = array( 'ext' => $ext );
@@ -355,10 +361,12 @@
356362 foreach ( $extensions as $ext ) {
357363 $ret = array();
358364 $ret['type'] = $type;
359 - if ( isset( $ext['name'] ) )
 365+ if ( isset( $ext['name'] ) ) {
360366 $ret['name'] = $ext['name'];
361 - if ( isset( $ext['description'] ) )
 367+ }
 368+ if ( isset( $ext['description'] ) ) {
362369 $ret['description'] = $ext['description'];
 370+ }
363371 if ( isset( $ext['descriptionmsg'] ) ) {
364372 // Can be a string or array( key, param1, param2, ... )
365373 if ( is_array( $ext['descriptionmsg'] ) ) {
@@ -421,13 +429,12 @@
422430 return $this->getResult()->addValue( 'query', $property, $data );
423431 }
424432
425 -
426433 public function getAllowedParams() {
427434 return array(
428435 '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(
432439 'general',
433440 'namespaces',
434441 'namespacealiases',
@@ -444,7 +451,7 @@
445452 )
446453 ),
447454 'filteriw' => array(
448 - ApiBase :: PARAM_TYPE => array(
 455+ ApiBase::PARAM_TYPE => array(
449456 'local',
450457 '!local',
451458 )
@@ -493,7 +500,7 @@
494501 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
495502 'api.php?action=query&meta=siteinfo&siprop=interwikimap&sifilteriw=local',
496503 'api.php?action=query&meta=siteinfo&siprop=dbrepllag&sishowalldb',
497 - );
 504+ );
498505 }
499506
500507 public function getVersion() {
Index: trunk/phase3/includes/api/ApiRollback.php
@@ -24,7 +24,7 @@
2525
2626 if ( !defined( 'MEDIAWIKI' ) ) {
2727 // Eclipse helper - will be ignored in production
28 - require_once ( "ApiBase.php" );
 28+ require_once( "ApiBase.php" );
2929 }
3030
3131 /**
@@ -33,39 +33,45 @@
3434 class ApiRollback extends ApiBase {
3535
3636 public function __construct( $main, $action ) {
37 - parent :: __construct( $main, $action );
 37+ parent::__construct( $main, $action );
3838 }
3939
4040 public function execute() {
4141 $params = $this->extractRequestParams();
4242
4343 $titleObj = null;
44 - if ( !isset( $params['title'] ) )
 44+ if ( !isset( $params['title'] ) ) {
4545 $this->dieUsageMsg( array( 'missingparam', 'title' ) );
46 - if ( !isset( $params['user'] ) )
 46+ }
 47+ if ( !isset( $params['user'] ) ) {
4748 $this->dieUsageMsg( array( 'missingparam', 'user' ) );
 49+ }
4850
4951 $titleObj = Title::newFromText( $params['title'] );
50 - if ( !$titleObj )
 52+ if ( !$titleObj ) {
5153 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
52 - if ( !$titleObj->exists() )
 54+ }
 55+ if ( !$titleObj->exists() ) {
5356 $this->dieUsageMsg( array( 'notanarticle' ) );
 57+ }
5458
5559 // We need to be able to revert IPs, but getCanonicalName rejects them
5660 $username = User::isIP( $params['user'] )
5761 ? $params['user']
5862 : User::getCanonicalName( $params['user'] );
59 - if ( !$username )
 63+ if ( !$username ) {
6064 $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
 65+ }
6166
6267 $articleObj = new Article( $titleObj );
63 - $summary = ( isset( $params['summary'] ) ? $params['summary'] : "" );
 68+ $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
6469 $details = null;
6570 $retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details );
6671
67 - if ( $retval )
 72+ if ( $retval ) {
6873 // We don't care about multiple errors, just report one of them
6974 $this->dieUsageMsg( reset( $retval ) );
 75+ }
7076
7177 $info = array(
7278 'title' => $titleObj->getPrefixedText(),
@@ -79,14 +85,16 @@
8086 $this->getResult()->addValue( null, $this->getModuleName(), $info );
8187 }
8288
83 - public function mustBePosted() { return true; }
 89+ public function mustBePosted() {
 90+ return true;
 91+ }
8492
8593 public function isWriteMode() {
8694 return true;
8795 }
8896
8997 public function getAllowedParams() {
90 - return array (
 98+ return array(
9199 'title' => null,
92100 'user' => null,
93101 'token' => null,
@@ -96,7 +104,7 @@
97105 }
98106
99107 public function getParamDescription() {
100 - return array (
 108+ return array(
101109 'title' => 'Title of the page you want to rollback.',
102110 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
103111 'token' => 'A rollback token previously retrieved through prop=revisions',
@@ -107,11 +115,11 @@
108116
109117 public function getDescription() {
110118 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+ );
114122 }
115 -
 123+
116124 public function getPossibleErrors() {
117125 return array_merge( parent::getPossibleErrors(), array(
118126 array( 'missingparam', 'title' ),
@@ -121,13 +129,13 @@
122130 array( 'invaliduser', 'user' ),
123131 ) );
124132 }
125 -
 133+
126134 public function getTokenSalt() {
127135 return '';
128136 }
129137
130138 protected function getExamples() {
131 - return array (
 139+ return array(
132140 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
133141 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
134142 );
Index: trunk/phase3/includes/api/ApiUserrights.php
@@ -1,10 +1,10 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Mar 24, 2009
66 * API for MediaWiki 1.8+
77 *
8 - * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
 8+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
99 *
1010 * This program is free software; you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
2525
2626 if ( !defined( 'MEDIAWIKI' ) ) {
2727 // Eclipse helper - will be ignored in production
28 - require_once ( "ApiBase.php" );
 28+ require_once( "ApiBase.php" );
2929 }
3030
3131 /**
@@ -33,16 +33,16 @@
3434 class ApiUserrights extends ApiBase {
3535
3636 public function __construct( $main, $action ) {
37 - parent :: __construct( $main, $action );
 37+ parent::__construct( $main, $action );
3838 }
3939
4040 public function execute() {
4141 $params = $this->extractRequestParams();
42 -
 42+
4343 // User already validated in call to getTokenSalt from Main
4444 $form = new UserrightsPage;
4545 $user = $form->fetchUser( $params['user'] );
46 -
 46+
4747 $r['user'] = $user->getName();
4848 list( $r['added'], $r['removed'] ) =
4949 $form->doSaveUserGroups(
@@ -66,22 +66,22 @@
6767 return array (
6868 'user' => null,
6969 'add' => array(
70 - ApiBase :: PARAM_TYPE => User::getAllGroups(),
71 - ApiBase :: PARAM_ISMULTI => true
 70+ ApiBase::PARAM_TYPE => User::getAllGroups(),
 71+ ApiBase::PARAM_ISMULTI => true
7272 ),
7373 'remove' => array(
74 - ApiBase :: PARAM_TYPE => User::getAllGroups(),
75 - ApiBase :: PARAM_ISMULTI => true
 74+ ApiBase::PARAM_TYPE => User::getAllGroups(),
 75+ ApiBase::PARAM_ISMULTI => true
7676 ),
7777 'token' => null,
7878 'reason' => array(
79 - ApiBase :: PARAM_DFLT => ''
 79+ ApiBase::PARAM_DFLT => ''
8080 )
8181 );
8282 }
8383
8484 public function getParamDescription() {
85 - return array (
 85+ return array(
8686 'user' => 'User name',
8787 'add' => 'Add the user to these groups',
8888 'remove' => 'Remove the user from these groups',
@@ -95,29 +95,31 @@
9696 'Add/remove a user to/from groups',
9797 );
9898 }
99 -
100 - public function getPossibleErrors() {
 99+
 100+ public function getPossibleErrors() {
101101 return array_merge( parent::getPossibleErrors(), array(
102102 array( 'missingparam', 'user' ),
103 - ) );
 103+ ) );
104104 }
105 -
 105+
106106 public function getTokenSalt() {
107107 $params = $this->extractRequestParams();
108 - if ( is_null( $params['user'] ) )
 108+ if ( is_null( $params['user'] ) ) {
109109 $this->dieUsageMsg( array( 'missingparam', 'user' ) );
 110+ }
110111
111112 $form = new UserrightsPage;
112113 $user = $form->fetchUser( $params['user'] );
113 - if ( $user instanceof WikiErrorMsg )
 114+ if ( $user instanceof WikiErrorMsg ) {
114115 $this->dieUsageMsg( array_merge(
115116 (array)$user->getMessageKey(), $user->getMessageArgs() ) );
 117+ }
116118
117119 return $user->getName();
118120 }
119121
120122 protected function getExamples() {
121 - return array (
 123+ return array(
122124 'api.php?action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
123125 );
124126 }
Index: trunk/phase3/includes/api/ApiResult.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 4, 2006
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiBase.php' );
 29+ require_once( 'ApiBase.php' );
3030 }
3131
3232 /**
@@ -54,7 +54,7 @@
5555 * @param $main ApiMain object
5656 */
5757 public function __construct( $main ) {
58 - parent :: __construct( $main, 'result' );
 58+ parent::__construct( $main, 'result' );
5959 $this->mIsRawMode = false;
6060 $this->mCheckingSize = true;
6161 $this->reset();
@@ -64,7 +64,7 @@
6565 * Clear the current result data.
6666 */
6767 public function reset() {
68 - $this->mData = array ();
 68+ $this->mData = array();
6969 $this->mSize = 0;
7070 }
7171
@@ -100,12 +100,14 @@
101101 */
102102 public static function size( $value ) {
103103 $s = 0;
104 - if ( is_array( $value ) )
105 - foreach ( $value as $v )
 104+ if ( is_array( $value ) ) {
 105+ foreach ( $value as $v ) {
106106 $s += self::size( $v );
107 - else if ( !is_object( $value ) )
 107+ }
 108+ } elseif ( !is_object( $value ) ) {
108109 // Objects can't always be cast to string
109110 $s = strlen( $value );
 111+ }
110112 return $s;
111113 }
112114
@@ -140,21 +142,23 @@
141143 * @param $name string Index of $arr to add $value at
142144 * @param $value mixed
143145 */
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+ }
147150
148151 if ( !isset ( $arr[$name] ) ) {
149152 $arr[$name] = $value;
150 - }
151 - elseif ( is_array( $arr[$name] ) && is_array( $value ) ) {
 153+ } elseif ( is_array( $arr[$name] ) && is_array( $value ) ) {
152154 $merged = array_intersect_key( $arr[$name], $value );
153 - if ( !count( $merged ) )
 155+ if ( !count( $merged ) ) {
154156 $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+ }
159163 }
160164
161165 /**
@@ -165,15 +169,17 @@
166170 * as a sub item of $arr. Use this parameter to create elements in
167171 * format <elem>text</elem> without attributes
168172 */
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+ }
172177 if ( is_null( $subElemName ) ) {
173 - ApiResult :: setElement( $arr, '*', $value );
 178+ ApiResult::setElement( $arr, '*', $value );
174179 } 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 );
178184 }
179185 }
180186
@@ -184,12 +190,15 @@
185191 * @param $arr array
186192 * @param $tag string Tag name
187193 */
188 - public function setIndexedTagName( & $arr, $tag ) {
 194+ public function setIndexedTagName( &$arr, $tag ) {
189195 // In raw mode, add the '_element', otherwise just ignore
190 - if ( !$this->getIsRawMode() )
 196+ if ( !$this->getIsRawMode() ) {
191197 return;
 198+ }
192199 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+ }
194203 // Do not use setElement() as it is ok to call this more than once
195204 $arr['_element'] = $tag;
196205 }
@@ -200,15 +209,16 @@
201210 * @param $tag string Tag name
202211 */
203212 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;
212215 }
 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+ }
213223 }
214224
215225 /**
@@ -219,15 +229,16 @@
220230 * @param $tag string
221231 */
222232 public function setIndexedTagName_internal( $path, $tag ) {
223 - $data = & $this->mData;
 233+ $data = &$this->mData;
224234 foreach ( (array)$path as $p ) {
225235 if ( !isset( $data[$p] ) ) {
226236 $data[$p] = array();
227237 }
228 - $data = & $data[$p];
 238+ $data = &$data[$p];
229239 }
230 - if ( is_null( $data ) )
 240+ if ( is_null( $data ) ) {
231241 return;
 242+ }
232243 $this->setIndexedTagName( $data, $tag );
233244 }
234245
@@ -240,32 +251,36 @@
241252 */
242253 public function addValue( $path, $name, $value ) {
243254 global $wgAPIMaxResultSize;
244 - $data = & $this->mData;
 255+ $data = &$this->mData;
245256 if ( $this->mCheckingSize ) {
246257 $newsize = $this->mSize + self::size( $value );
247 - if ( $newsize > $wgAPIMaxResultSize )
 258+ if ( $newsize > $wgAPIMaxResultSize ) {
248259 return false;
 260+ }
249261 $this->mSize = $newsize;
250262 }
251263
252264 if ( !is_null( $path ) ) {
253265 if ( is_array( $path ) ) {
254266 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];
258271 }
259272 } 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];
263277 }
264278 }
265279
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+ }
270285 return true;
271286 }
272287
@@ -277,13 +292,15 @@
278293 * @param $name string
279294 */
280295 public function unsetValue( $path, $name ) {
281 - $data = & $this->mData;
282 - if ( !is_null( $path ) )
 296+ $data = &$this->mData;
 297+ if ( !is_null( $path ) ) {
283298 foreach ( (array)$path as $p ) {
284 - if ( !isset( $data[$p] ) )
 299+ if ( !isset( $data[$p] ) ) {
285300 return;
286 - $data = & $data[$p];
 301+ }
 302+ $data = &$data[$p];
287303 }
 304+ }
288305 $this->mSize -= self::size( $data[$name] );
289306 unset( $data[$name] );
290307 }
@@ -291,24 +308,23 @@
292309 /**
293310 * Ensure all values in this result are valid UTF-8.
294311 */
295 - public function cleanUpUTF8()
296 - {
 312+ public function cleanUpUTF8() {
297313 array_walk_recursive( $this->mData, array( 'ApiResult', 'cleanUp_helper' ) );
298314 }
299315
300316 /**
301317 * Callback function for cleanUpUTF8()
302318 */
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 ) ) {
306321 return;
 322+ }
307323 global $wgContLang;
308324 $s = $wgContLang->normalize( $s );
309325 }
310326
311327 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' );
313329 }
314330
315331 public function getVersion() {
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -1,10 +1,10 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 7, 2007
66 * API for MediaWiki 1.8+
77 *
8 - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
 8+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
99 *
1010 * This program is free software; you can redistribute it and/or modify
1111 * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
2525
2626 if ( !defined( 'MEDIAWIKI' ) ) {
2727 // Eclipse helper - will be ignored in production
28 - require_once ( "ApiBase.php" );
 28+ require_once( "ApiBase.php" );
2929 }
3030
3131 /**
@@ -36,7 +36,7 @@
3737 class ApiUnblock extends ApiBase {
3838
3939 public function __construct( $main, $action ) {
40 - parent :: __construct( $main, $action );
 40+ parent::__construct( $main, $action );
4141 }
4242
4343 /**
@@ -46,27 +46,30 @@
4747 global $wgUser;
4848 $params = $this->extractRequestParams();
4949
50 - if ( $params['gettoken'] )
51 - {
 50+ if ( $params['gettoken'] ) {
5251 $res['unblocktoken'] = $wgUser->editToken();
5352 $this->getResult()->addValue( null, $this->getModuleName(), $res );
5453 return;
5554 }
5655
57 - if ( is_null( $params['id'] ) && is_null( $params['user'] ) )
 56+ if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
5857 $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'] ) ) {
6060 $this->dieUsageMsg( array( 'unblock-idanduser' ) );
 61+ }
6162
62 - if ( !$wgUser->isAllowed( 'block' ) )
 63+ if ( !$wgUser->isAllowed( 'block' ) ) {
6364 $this->dieUsageMsg( array( 'cantunblock' ) );
 65+ }
6466
6567 $id = $params['id'];
6668 $user = $params['user'];
6769 $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
6870 $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
69 - if ( $retval )
 71+ if ( $retval ) {
7072 $this->dieUsageMsg( $retval );
 73+ }
7174
7275 $res['id'] = intval( $id );
7376 $res['user'] = $user;
@@ -83,7 +86,7 @@
8487 }
8588
8689 public function getAllowedParams() {
87 - return array (
 90+ return array(
8891 'id' => null,
8992 'user' => null,
9093 'token' => null,
@@ -93,7 +96,7 @@
9497 }
9598
9699 public function getParamDescription() {
97 - return array (
 100+ return array(
98101 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
99102 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
100103 'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info',
@@ -107,21 +110,21 @@
108111 'Unblock a user.'
109112 );
110113 }
111 -
112 - public function getPossibleErrors() {
 114+
 115+ public function getPossibleErrors() {
113116 return array_merge( parent::getPossibleErrors(), array(
114117 array( 'unblock-notarget' ),
115118 array( 'unblock-idanduser' ),
116119 array( 'cantunblock' ),
117 - ) );
 120+ ) );
118121 }
119 -
 122+
120123 public function getTokenSalt() {
121124 return '';
122125 }
123126
124127 protected function getExamples() {
125 - return array (
 128+ return array(
126129 'api.php?action=unblock&id=105',
127130 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
128131 );
Index: trunk/phase3/includes/api/ApiQueryWatchlistRaw.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Oct 4, 2008
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
 9+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -37,7 +37,7 @@
3838 class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase {
3939
4040 public function __construct( $query, $moduleName ) {
41 - parent :: __construct( $query, $moduleName, 'wr' );
 41+ parent::__construct( $query, $moduleName, 'wr' );
4242 }
4343
4444 public function execute() {
@@ -53,13 +53,15 @@
5454
5555 $this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
5656
57 - if ( !$wgUser->isLoggedIn() )
 57+ if ( !$wgUser->isLoggedIn() ) {
5858 $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
 59+ }
5960 $params = $this->extractRequestParams();
6061 $prop = array_flip( (array)$params['prop'] );
6162 $show = array_flip( (array)$params['show'] );
62 - if ( isset( $show['changed'] ) && isset( $show['!changed'] ) )
 63+ if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) {
6364 $this->dieUsageMsg( array( 'show' ) );
 65+ }
6466
6567 $this->addTables( 'watchlist' );
6668 $this->addFields( array( 'wl_namespace', 'wl_title' ) );
@@ -69,34 +71,35 @@
7072 $this->addWhereIf( 'wl_notificationtimestamp IS NOT NULL', isset( $show['changed'] ) );
7173 $this->addWhereIf( 'wl_notificationtimestamp IS NULL', isset( $show['!changed'] ) );
7274
73 - if ( isset( $params['continue'] ) )
74 - {
 75+ if ( isset( $params['continue'] ) ) {
7576 $cont = explode( '|', $params['continue'] );
76 - if ( count( $cont ) != 2 )
 77+ if ( count( $cont ) != 2 ) {
7778 $this->dieUsage( "Invalid continue param. You should pass the " .
7879 "original value returned by the previous query", "_badcontinue" );
 80+ }
7981 $ns = intval( $cont[0] );
8082 $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+ );
8488 }
8589
8690 // 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 ) {
8892 $this->addOption( 'ORDER BY', 'wl_title' );
89 - else
 93+ } else {
9094 $this->addOption( 'ORDER BY', 'wl_namespace, wl_title' );
 95+ }
9196 $this->addOption( 'LIMIT', $params['limit'] + 1 );
9297 $res = $this->select( __METHOD__ );
93 -
 98+
9499 $db = $this->getDB();
95100 $titles = array();
96101 $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'] ) {
101104 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
102105 $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
103106 $this->keyToTitle( $row->wl_title ) );
@@ -104,52 +107,53 @@
105108 }
106109 $t = Title::makeTitle( $row->wl_namespace, $row->wl_title );
107110
108 - if ( is_null( $resultPageSet ) )
109 - {
 111+ if ( is_null( $resultPageSet ) ) {
110112 $vals = array();
111113 ApiQueryBase::addTitleInfo( $vals, $t );
112114 if ( isset( $prop['changed'] ) && !is_null( $row->wl_notificationtimestamp ) )
 115+ {
113116 $vals['changed'] = wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
 117+ }
114118 $fit = $this->getResult()->addValue( $this->getModuleName(), null, $vals );
115 - if ( !$fit )
116 - {
 119+ if ( !$fit ) {
117120 $this->setContinueEnumParameter( 'continue', $row->wl_namespace . '|' .
118121 $this->keyToTitle( $row->wl_title ) );
119122 break;
120123 }
 124+ } else {
 125+ $titles[] = $t;
121126 }
122 - else
123 - $titles[] = $t;
124127 }
125 - if ( is_null( $resultPageSet ) )
 128+ if ( is_null( $resultPageSet ) ) {
126129 $this->getResult()->setIndexedTagName_internal( $this->getModuleName(), 'wr' );
127 - else
 130+ } else {
128131 $resultPageSet->populateFromTitles( $titles );
 132+ }
129133 }
130134
131135 public function getAllowedParams() {
132 - return array (
 136+ return array(
133137 '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'
137141 ),
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
144148 ),
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(
148152 'changed',
149153 )
150154 ),
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(
154158 'changed',
155159 '!changed',
156160 )
@@ -158,7 +162,7 @@
159163 }
160164
161165 public function getParamDescription() {
162 - return array (
 166+ return array(
163167 'continue' => 'When more results are available, use this to continue',
164168 'namespace' => 'Only list pages in the given namespace(s).',
165169 'limit' => 'How many total results to return per request.',
@@ -170,7 +174,7 @@
171175 public function getDescription() {
172176 return "Get all pages on the logged in user's watchlist";
173177 }
174 -
 178+
175179 public function getPossibleErrors() {
176180 return array_merge( parent::getPossibleErrors(), array(
177181 array( 'code' => 'notloggedin', 'info' => 'You must be logged-in to have a watchlist' ),
@@ -179,7 +183,7 @@
180184 }
181185
182186 protected function getExamples() {
183 - return array (
 187+ return array(
184188 'api.php?action=query&list=watchlistraw',
185189 'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
186190 );
Index: trunk/phase3/includes/api/ApiQueryUserInfo.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on July 30, 2007
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -36,7 +36,7 @@
3737 class ApiQueryUserInfo extends ApiQueryBase {
3838
3939 public function __construct( $query, $moduleName ) {
40 - parent :: __construct( $query, $moduleName, 'ui' );
 40+ parent::__construct( $query, $moduleName, 'ui' );
4141 }
4242
4343 public function execute() {
@@ -50,7 +50,7 @@
5151 $this->prop = array();
5252 }
5353 $r = $this->getCurrentUserInfo();
54 - $result->addValue( "query", $this->getModuleName(), $r );
 54+ $result->addValue( 'query', $this->getModuleName(), $r );
5555 }
5656
5757 protected function getCurrentUserInfo() {
@@ -60,8 +60,9 @@
6161 $vals['id'] = intval( $wgUser->getId() );
6262 $vals['name'] = $wgUser->getName();
6363
64 - if ( $wgUser->isAnon() )
 64+ if ( $wgUser->isAnon() ) {
6565 $vals['anon'] = '';
 66+ }
6667
6768 if ( isset( $this->prop['blockinfo'] ) ) {
6869 if ( $wgUser->isBlocked() ) {
@@ -97,7 +98,11 @@
9899 $vals['options'] = $wgUser->getOptions();
99100 }
100101
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+ {
102107 $vals['preferencestoken'] = $wgUser->editToken();
103108 }
104109
@@ -112,26 +117,27 @@
113118 if ( isset( $this->prop['email'] ) ) {
114119 $vals['email'] = $wgUser->getEmail();
115120 $auth = $wgUser->getEmailAuthenticationTimestamp();
116 - if ( !is_null( $auth ) )
 121+ if ( !is_null( $auth ) ) {
117122 $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
 123+ }
118124 }
119125 return $vals;
120126 }
121127
122 - protected function getRateLimits()
123 - {
 128+ protected function getRateLimits() {
124129 global $wgUser, $wgRateLimits;
125 - if ( !$wgUser->isPingLimitable() )
 130+ if ( !$wgUser->isPingLimitable() ) {
126131 return array(); // No limits
 132+ }
127133
128134 // Find out which categories we belong to
129135 $categories = array();
130 - if ( $wgUser->isAnon() )
 136+ if ( $wgUser->isAnon() ) {
131137 $categories[] = 'anon';
132 - else
 138+ } else {
133139 $categories[] = 'user';
134 - if ( $wgUser->isNewBie() )
135 - {
 140+ }
 141+ if ( $wgUser->isNewbie() ) {
136142 $categories[] = 'ip';
137143 $categories[] = 'subnet';
138144 if ( !$wgUser->isAnon() )
@@ -141,22 +147,23 @@
142148
143149 // Now get the actual limits
144150 $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] ) ) {
149154 $retval[$action][$cat]['hits'] = intval( $limits[$cat][0] );
150155 $retval[$action][$cat]['seconds'] = intval( $limits[$cat][1] );
151156 }
 157+ }
 158+ }
152159 return $retval;
153160 }
154161
155162 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(
161168 'blockinfo',
162169 'hasmsg',
163170 'groups',
@@ -173,7 +180,7 @@
174181 }
175182
176183 public function getParamDescription() {
177 - return array (
 184+ return array(
178185 'prop' => array(
179186 'What pieces of information to include',
180187 ' blockinfo - tags if the current user is blocked, by whom, and for what reason',
@@ -193,7 +200,7 @@
194201 }
195202
196203 protected function getExamples() {
197 - return array (
 204+ return array(
198205 'api.php?action=query&meta=userinfo',
199206 'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
200207 );
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 25, 2006
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -37,7 +37,7 @@
3838 class ApiQueryWatchlist extends ApiQueryGeneratorBase {
3939
4040 public function __construct( $query, $moduleName ) {
41 - parent :: __construct( $query, $moduleName, 'wl' );
 41+ parent::__construct( $query, $moduleName, 'wl' );
4242 }
4343
4444 public function execute() {
@@ -75,7 +75,6 @@
7676 }
7777
7878 if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) {
79 -
8079 $prop = array_flip( $params['prop'] );
8180
8281 $this->fld_ids = isset( $prop['ids'] );
@@ -90,19 +89,20 @@
9190 $this->fld_notificationtimestamp = isset( $prop['notificationtimestamp'] );
9291
9392 if ( $this->fld_patrol ) {
94 - if ( !$user->useRCPatrol() && !$user->useNPPatrol() )
 93+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
9594 $this->dieUsage( 'patrol property is not available', 'patrol' );
 95+ }
9696 }
9797 }
98 -
99 - $this->addFields( array (
 98+
 99+ $this->addFields( array(
100100 'rc_namespace',
101101 'rc_title',
102102 'rc_timestamp'
103103 ) );
104104
105105 if ( is_null( $resultPageSet ) ) {
106 - $this->addFields( array (
 106+ $this->addFields( array(
107107 'rc_cur_id',
108108 'rc_this_oldid'
109109 ) );
@@ -123,14 +123,14 @@
124124 $this->addFields( 'rc_cur_id' );
125125 }
126126
127 - $this->addTables( array (
 127+ $this->addTables( array(
128128 'watchlist',
129129 'page',
130130 'recentchanges'
131131 ) );
132132
133133 $userId = $user->getId();
134 - $this->addWhere( array (
 134+ $this->addWhere( array(
135135 'wl_namespace = rc_namespace',
136136 'wl_title = rc_title',
137137 'rc_cur_id = page_id',
@@ -149,41 +149,47 @@
150150 if ( ( isset ( $show['minor'] ) && isset ( $show['!minor'] ) )
151151 || ( isset ( $show['bot'] ) && isset ( $show['!bot'] ) )
152152 || ( isset ( $show['anon'] ) && isset ( $show['!anon'] ) )
153 - || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) ) ) {
154 -
 153+ || ( isset ( $show['patrolled'] ) && isset ( $show['!patrolled'] ) )
 154+ )
 155+ {
155156 $this->dieUsageMsg( array( 'show' ) );
156157 }
157 -
 158+
158159 // Check permissions. FIXME: should this check $user instead of $wgUser?
159160 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+ }
161164
162165 /* 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'] ) );
169172 $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
170173 $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
171174 }
172175
173 - if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) )
 176+ if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
174177 $this->dieUsage( 'user and excludeuser cannot be used together', 'user-excludeuser' );
175 - if ( !is_null( $params['user'] ) )
 178+ }
 179+ if ( !is_null( $params['user'] ) ) {
176180 $this->addWhereFld( 'rc_user_text', $params['user'] );
177 - if ( !is_null( $params['excludeuser'] ) )
 181+ }
 182+ if ( !is_null( $params['excludeuser'] ) ) {
178183 $this->addWhere( 'rc_user_text != ' . $this->getDB()->addQuotes( $params['excludeuser'] ) );
 184+ }
179185
180186 $db = $this->getDB();
181 -
 187+
182188 // 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' );
184190
185191 $this->addOption( 'LIMIT', $params['limit'] + 1 );
186192
187 - $ids = array ();
 193+ $ids = array();
188194 $count = 0;
189195 $res = $this->select( __METHOD__ );
190196
@@ -197,8 +203,7 @@
198204 if ( is_null( $resultPageSet ) ) {
199205 $vals = $this->extractRowInfo( $row );
200206 $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
201 - if ( !$fit )
202 - {
 207+ if ( !$fit ) {
203208 $this->setContinueEnumParameter( 'start',
204209 wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
205210 break;
@@ -216,8 +221,7 @@
217222
218223 if ( is_null( $resultPageSet ) ) {
219224 $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' );
220 - }
221 - elseif ( $params['allrev'] ) {
 225+ } elseif ( $params['allrev'] ) {
222226 $resultPageSet->populateFromRevisionIDs( $ids );
223227 } else {
224228 $resultPageSet->populateFromPageIDs( $ids );
@@ -225,9 +229,8 @@
226230 }
227231
228232 private function extractRowInfo( $row ) {
 233+ $vals = array();
229234
230 - $vals = array ();
231 -
232235 if ( $this->fld_ids ) {
233236 $vals['pageid'] = intval( $row->rc_cur_id );
234237 $vals['revid'] = intval( $row->rc_this_oldid );
@@ -235,41 +238,50 @@
236239
237240 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
238241
239 - if ( $this->fld_title )
 242+ if ( $this->fld_title ) {
240243 ApiQueryBase::addTitleInfo( $vals, $title );
 244+ }
241245
242246 if ( $this->fld_user ) {
243247 $vals['user'] = $row->rc_user_text;
244 - if ( !$row->rc_user )
 248+ if ( !$row->rc_user ) {
245249 $vals['anon'] = '';
 250+ }
246251 }
247252
248253 if ( $this->fld_flags ) {
249 - if ( $row->rc_new )
 254+ if ( $row->rc_new ) {
250255 $vals['new'] = '';
251 - if ( $row->rc_minor )
 256+ }
 257+ if ( $row->rc_minor ) {
252258 $vals['minor'] = '';
253 - if ( $row->rc_bot )
 259+ }
 260+ if ( $row->rc_bot ) {
254261 $vals['bot'] = '';
 262+ }
255263 }
256264
257 - if ( $this->fld_patrol && isset( $row->rc_patrolled ) )
 265+ if ( $this->fld_patrol && isset( $row->rc_patrolled ) ) {
258266 $vals['patrolled'] = '';
 267+ }
259268
260 - if ( $this->fld_timestamp )
 269+ if ( $this->fld_timestamp ) {
261270 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
 271+ }
262272
263273 if ( $this->fld_sizes ) {
264274 $vals['oldlen'] = intval( $row->rc_old_len );
265275 $vals['newlen'] = intval( $row->rc_new_len );
266276 }
267 -
268 - if ( $this->fld_notificationtimestamp )
 277+
 278+ if ( $this->fld_notificationtimestamp ) {
269279 $vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null ) ? '' : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp );
 280+ }
270281
271 - if ( $this->fld_comment && isset( $row->rc_comment ) )
 282+ if ( $this->fld_comment && isset( $row->rc_comment ) ) {
272283 $vals['comment'] = $row->rc_comment;
273 -
 284+ }
 285+
274286 if ( $this->fld_parsedcomment && isset( $row->rc_comment ) ) {
275287 global $wgUser;
276288 $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rc_comment, $title );
@@ -279,42 +291,42 @@
280292 }
281293
282294 public function getAllowedParams() {
283 - return array (
 295+ return array(
284296 'allrev' => false,
285 - 'start' => array (
286 - ApiBase :: PARAM_TYPE => 'timestamp'
 297+ 'start' => array(
 298+ ApiBase::PARAM_TYPE => 'timestamp'
287299 ),
288 - 'end' => array (
289 - ApiBase :: PARAM_TYPE => 'timestamp'
 300+ 'end' => array(
 301+ ApiBase::PARAM_TYPE => 'timestamp'
290302 ),
291303 'namespace' => array (
292 - ApiBase :: PARAM_ISMULTI => true,
293 - ApiBase :: PARAM_TYPE => 'namespace'
 304+ ApiBase::PARAM_ISMULTI => true,
 305+ ApiBase::PARAM_TYPE => 'namespace'
294306 ),
295307 'user' => array(
296 - ApiBase :: PARAM_TYPE => 'user',
 308+ ApiBase::PARAM_TYPE => 'user',
297309 ),
298310 'excludeuser' => array(
299 - ApiBase :: PARAM_TYPE => 'user',
 311+ ApiBase::PARAM_TYPE => 'user',
300312 ),
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(
304316 'newer',
305317 'older'
306318 )
307319 ),
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
314326 ),
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(
319331 'ids',
320332 'title',
321333 'flags',
@@ -327,9 +339,9 @@
328340 'notificationtimestamp'
329341 )
330342 ),
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(
334346 'minor',
335347 '!minor',
336348 'bot',
@@ -340,17 +352,17 @@
341353 '!patrolled',
342354 )
343355 ),
344 - 'owner' => array (
345 - ApiBase :: PARAM_TYPE => 'user'
 356+ 'owner' => array(
 357+ ApiBase::PARAM_TYPE => 'user'
346358 ),
347 - 'token' => array (
348 - ApiBase :: PARAM_TYPE => 'string'
 359+ 'token' => array(
 360+ ApiBase::PARAM_TYPE => 'string'
349361 )
350362 );
351363 }
352364
353365 public function getParamDescription() {
354 - return array (
 366+ return array(
355367 'allrev' => 'Include multiple revisions of the same page within given timeframe.',
356368 'start' => 'The timestamp to start enumerating from.',
357369 'end' => 'The timestamp to end enumerating.',
@@ -360,7 +372,7 @@
361373 'dir' => 'In which direction to enumerate pages.',
362374 'limit' => 'How many total results to return per request.',
363375 'prop' => 'Which additional items to get (non-generator mode only).',
364 - 'show' => array (
 376+ 'show' => array(
365377 'Show only items that meet this criteria.',
366378 'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
367379 ),
@@ -372,7 +384,7 @@
373385 public function getDescription() {
374386 return "Get all recent changes to pages in the logged in user's watchlist";
375387 }
376 -
 388+
377389 public function getPossibleErrors() {
378390 return array_merge( parent::getPossibleErrors(), array(
379391 array( 'code' => 'bad_wlowner', 'info' => 'Specified user does not exist' ),
@@ -386,7 +398,7 @@
387399 }
388400
389401 protected function getExamples() {
390 - return array (
 402+ return array(
391403 'api.php?action=query&list=watchlist',
392404 'api.php?action=query&list=watchlist&wlprop=ids|title|timestamp|user|comment',
393405 'api.php?action=query&list=watchlist&wlallrev&wlprop=ids|title|timestamp|user|comment',
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -24,7 +24,7 @@
2525
2626 if ( !defined( 'MEDIAWIKI' ) ) {
2727 // Eclipse helper - will be ignored in production
28 - require_once ( "ApiBase.php" );
 28+ require_once( "ApiBase.php" );
2929 }
3030
3131 /**
@@ -33,7 +33,7 @@
3434 class ApiUndelete extends ApiBase {
3535
3636 public function __construct( $main, $action ) {
37 - parent :: __construct( $main, $action );
 37+ parent::__construct( $main, $action );
3838 }
3939
4040 public function execute() {
@@ -41,37 +41,46 @@
4242 $params = $this->extractRequestParams();
4343
4444 $titleObj = null;
45 - if ( !isset( $params['title'] ) )
 45+ if ( !isset( $params['title'] ) ) {
4646 $this->dieUsageMsg( array( 'missingparam', 'title' ) );
 47+ }
4748
48 - if ( !$wgUser->isAllowed( 'undelete' ) )
 49+ if ( !$wgUser->isAllowed( 'undelete' ) ) {
4950 $this->dieUsageMsg( array( 'permdenied-undelete' ) );
 51+ }
5052
51 - if ( $wgUser->isBlocked() )
 53+ if ( $wgUser->isBlocked() ) {
5254 $this->dieUsageMsg( array( 'blockedtext' ) );
 55+ }
5356
5457 $titleObj = Title::newFromText( $params['title'] );
55 - if ( !$titleObj )
 58+ if ( !$titleObj ) {
5659 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 60+ }
5761
5862 // Convert timestamps
59 - if ( !isset( $params['timestamps'] ) )
 63+ if ( !isset( $params['timestamps'] ) ) {
6064 $params['timestamps'] = array();
61 - if ( !is_array( $params['timestamps'] ) )
 65+ }
 66+ if ( !is_array( $params['timestamps'] ) ) {
6267 $params['timestamps'] = array( $params['timestamps'] );
63 - foreach ( $params['timestamps'] as $i => $ts )
 68+ }
 69+ foreach ( $params['timestamps'] as $i => $ts ) {
6470 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
 71+ }
6572
6673 $pa = new PageArchive( $titleObj );
6774 $dbw = wfGetDB( DB_MASTER );
6875 $dbw->begin();
6976 $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
70 - if ( !is_array( $retval ) )
 77+ if ( !is_array( $retval ) ) {
7178 $this->dieUsageMsg( array( 'cannotundelete' ) );
 79+ }
7280
73 - if ( $retval[1] )
 81+ if ( $retval[1] ) {
7482 wfRunHooks( 'FileUndeleteComplete',
7583 array( $titleObj, array(), $wgUser, $params['reason'] ) );
 84+ }
7685
7786 $info['title'] = $titleObj->getPrefixedText();
7887 $info['revisions'] = intval( $retval[0] );
@@ -89,18 +98,18 @@
9099 }
91100
92101 public function getAllowedParams() {
93 - return array (
 102+ return array(
94103 'title' => null,
95104 'token' => null,
96 - 'reason' => "",
 105+ 'reason' => '',
97106 'timestamps' => array(
98 - ApiBase :: PARAM_ISMULTI => true
 107+ ApiBase::PARAM_ISMULTI => true
99108 )
100109 );
101110 }
102111
103112 public function getParamDescription() {
104 - return array (
 113+ return array(
105114 'title' => 'Title of the page you want to restore.',
106115 'token' => 'An undelete token previously retrieved through list=deletedrevs',
107116 'reason' => 'Reason for restoring (optional)',
@@ -114,7 +123,7 @@
115124 'retrieved through list=deletedrevs'
116125 );
117126 }
118 -
 127+
119128 public function getPossibleErrors() {
120129 return array_merge( parent::getPossibleErrors(), array(
121130 array( 'missingparam', 'title' ),
@@ -124,13 +133,13 @@
125134 array( 'cannotundelete' ),
126135 ) );
127136 }
128 -
 137+
129138 public function getTokenSalt() {
130139 return '';
131140 }
132141
133142 protected function getExamples() {
134 - return array (
 143+ return array(
135144 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
136145 'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
137146 );
Index: trunk/phase3/includes/api/ApiQueryTags.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Jul 9, 2009
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2009
 9+ * Copyright © 2009
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -34,127 +34,131 @@
3535 * @ingroup API
3636 */
3737 class ApiQueryTags extends ApiQueryBase {
38 -
 38+
3939 private $limit, $result;
4040 private $fld_displayname = false, $fld_description = false,
4141 $fld_hitcount = false;
42 -
 42+
4343 public function __construct( $query, $moduleName ) {
44 - parent :: __construct( $query, $moduleName, 'tg' );
 44+ parent::__construct( $query, $moduleName, 'tg' );
4545 }
4646
4747 public function execute() {
4848 $params = $this->extractRequestParams();
49 -
 49+
5050 $prop = array_flip( $params['prop'] );
51 -
 51+
5252 $this->fld_displayname = isset( $prop['displayname'] );
5353 $this->fld_description = isset( $prop['description'] );
5454 $this->fld_hitcount = isset( $prop['hitcount'] );
55 -
 55+
5656 $this->limit = $params['limit'];
5757 $this->result = $this->getResult();
58 -
 58+
5959 $pageSet = $this->getPageSet();
6060 $titles = $pageSet->getTitles();
6161 $data = array();
62 -
 62+
6363 $this->addTables( 'change_tag' );
6464 $this->addFields( 'ct_tag' );
65 -
66 - if ( $this->fld_hitcount )
 65+
 66+ if ( $this->fld_hitcount ) {
6767 $this->addFields( 'count(*) AS hitcount' );
68 -
 68+ }
 69+
6970 $this->addOption( 'LIMIT', $this->limit + 1 );
7071 $this->addOption( 'GROUP BY', 'ct_tag' );
7172 $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null );
72 -
 73+
7374 $res = $this->select( __METHOD__ );
74 -
 75+
7576 $ok = true;
76 -
 77+
7778 while ( $row = $res->fetchObject() ) {
78 - if ( !$ok ) break;
 79+ if ( !$ok ) {
 80+ break;
 81+ }
7982 $ok = $this->doTag( $row->ct_tag, $row->hitcount );
8083 }
81 -
 84+
8285 // include tags with no hits yet
8386 foreach ( ChangeTags::listDefinedTags() as $tag ) {
84 - if ( !$ok ) break;
 87+ if ( !$ok ) {
 88+ break;
 89+ }
8590 $ok = $this->doTag( $tag, 0 );
8691 }
87 -
 92+
8893 $this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' );
8994 }
90 -
 95+
9196 private function doTag( $tagName, $hitcount ) {
9297 static $count = 0;
9398 static $doneTags = array();
94 -
 99+
95100 if ( in_array( $tagName, $doneTags ) ) {
96101 return true;
97102 }
98 -
99 - if ( ++$count > $this->limit )
100 - {
 103+
 104+ if ( ++$count > $this->limit ) {
101105 $this->setContinueEnumParameter( 'continue', $tagName );
102106 return false;
103107 }
104 -
 108+
105109 $tag = array();
106110 $tag['name'] = $tagName;
107 -
108 - if ( $this->fld_displayname )
 111+
 112+ if ( $this->fld_displayname ) {
109113 $tag['displayname'] = ChangeTags::tagDescription( $tagName );
110 -
111 - if ( $this->fld_description )
112 - {
 114+ }
 115+
 116+ if ( $this->fld_description ) {
113117 $msg = wfMsg( "tag-$tagName-description" );
114118 $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
115119 $tag['description'] = $msg;
116120 }
117 -
118 - if ( $this->fld_hitcount )
 121+
 122+ if ( $this->fld_hitcount ) {
119123 $tag['hitcount'] = $hitcount;
120 -
 124+ }
 125+
121126 $doneTags[] = $tagName;
122 -
 127+
123128 $fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
124 - if ( !$fit )
125 - {
 129+ if ( !$fit ) {
126130 $this->setContinueEnumParameter( 'continue', $tagName );
127131 return false;
128132 }
129 -
 133+
130134 return true;
131135 }
132 -
 136+
133137 public function getAllowedParams() {
134 - return array (
 138+ return array(
135139 'continue' => array(
136140 ),
137141 '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
143147 ),
144148 '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
153157 )
154158 );
155159 }
156160
157161 public function getParamDescription() {
158 - return array (
 162+ return array(
159163 'continue' => 'When more results are available, use this to continue',
160164 'limit' => 'The maximum number of tags to list',
161165 'prop' => 'Which properties to get',
@@ -166,7 +170,7 @@
167171 }
168172
169173 protected function getExamples() {
170 - return array (
 174+ return array(
171175 'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
172176 );
173177 }
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -1,9 +1,9 @@
22 <?php
3 -/*
 3+/**
44 * Created on Aug 21, 2008
55 * API for MediaWiki 1.8+
66 *
7 - * Copyright (C) 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
 7+ * Copyright © 2008 - 2010 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
88 *
99 * This program is free software; you can redistribute it and/or modify
1010 * it under the terms of the GNU General Public License as published by
@@ -41,8 +41,9 @@
4242 global $wgUser, $wgAllowCopyUploads;
4343
4444 // Check whether upload is enabled
45 - if ( !UploadBase::isEnabled() )
 45+ if ( !UploadBase::isEnabled() ) {
4646 $this->dieUsageMsg( array( 'uploaddisabled' ) );
 47+ }
4748
4849 $this->mParams = $this->extractRequestParams();
4950 $request = $this->getMain()->getRequest();
@@ -75,18 +76,18 @@
7677 * Upload stashed in a previous request
7778 */
7879 // Check the session key
79 - if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) )
 80+ if ( !isset( $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ) ) {
8081 $this->dieUsageMsg( array( 'invalid-session-key' ) );
 82+ }
8183
8284 $this->mUpload = new UploadFromStash();
8385 $this->mUpload->initialize( $this->mParams['filename'],
8486 $_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
8587 } elseif ( isset( $this->mParams['filename'] ) ) {
8688 /**
87 - * Upload from url, etc
 89+ * Upload from URL, etc.
8890 * Parameter filename is required
8991 */
90 -
9192 if ( isset( $this->mParams['file'] ) ) {
9293 $this->mUpload = new UploadFromFile();
9394 $this->mUpload->initialize(
@@ -95,13 +96,15 @@
9697 $request->getFileSize( 'file' )
9798 );
9899 } 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 ) {
101102 $this->dieUsageMsg( array( 'uploaddisabled' ) );
 103+ }
102104
103105 // make sure the current user can upload
104 - if ( ! $wgUser->isAllowed( 'upload_by_url' ) )
 106+ if ( !$wgUser->isAllowed( 'upload_by_url' ) ) {
105107 $this->dieUsageMsg( array( 'badaccess-groups' ) );
 108+ }
106109
107110 $this->mUpload = new UploadFromUrl();
108111 $this->mUpload->initialize( $this->mParams['filename'],
@@ -112,19 +115,23 @@
113116 $this->dieUsage( $status->getWikiText(), 'fetchfileerror' );
114117 }
115118 }
116 - } else $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
 119+ } else {
 120+ $this->dieUsageMsg( array( 'missingparam', 'filename' ) );
 121+ }
117122
118 - if ( !isset( $this->mUpload ) )
 123+ if ( !isset( $this->mUpload ) ) {
119124 $this->dieUsage( 'No upload module set', 'nomodule' );
 125+ }
120126
121127 // Check whether the user has the appropriate permissions to upload anyway
122128 $permission = $this->mUpload->isAllowed( $wgUser );
123129
124130 if ( $permission !== true ) {
125 - if ( !$wgUser->isLoggedIn() )
 131+ if ( !$wgUser->isLoggedIn() ) {
126132 $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
127 - else
 133+ } else {
128134 $this->dieUsageMsg( array( 'badaccess-groups' ) );
 135+ }
129136 }
130137 // Perform the upload
131138 $result = $this->performUpload();
@@ -134,7 +141,9 @@
135142
136143 if ( isset( $result['chunked-output'] ) ) {
137144 foreach ( $result['chunked-output'] as $key => $value ) {
138 - if ( $value === null ) $value = "";
 145+ if ( $value === null ) {
 146+ $value = '';
 147+ }
139148 $this->getResult()->addValue( null, $key, $value );
140149 }
141150 } else {
@@ -209,7 +218,6 @@
210219 $warnings['duplicate'] = $dupes;
211220 }
212221
213 -
214222 if ( isset( $warnings['exists'] ) ) {
215223 $warning = $warnings['exists'];
216224 unset( $warnings['exists'] );
@@ -220,8 +228,9 @@
221229 $result['warnings'] = $warnings;
222230
223231 $sessionKey = $this->mUpload->stashSession();
224 - if ( !$sessionKey )
 232+ if ( !$sessionKey ) {
225233 $this->dieUsage( 'Stashing temporary file failed', 'stashfailed' );
 234+ }
226235
227236 $result['sessionkey'] = $sessionKey;
228237
@@ -230,8 +239,9 @@
231240 }
232241
233242 // Use comment as initial page text by default
234 - if ( is_null( $this->mParams['text'] ) )
 243+ if ( is_null( $this->mParams['text'] ) ) {
235244 $this->mParams['text'] = $this->mParams['comment'];
 245+ }
236246
237247 // No errors, no warnings: do the upload
238248 $status = $this->mUpload->performUpload( $this->mParams['comment'],
@@ -243,7 +253,7 @@
244254
245255 $this->dieUsage( 'An internal error occurred', 'internal-error', 0, $error );
246256 } elseif ( $this->mParams['enablechunks'] ) {
247 - return array( "chunked-output" => $status->value );
 257+ return array( 'chunked-output' => $status->value );
248258 }
249259
250260 $file = $this->mUpload->getLocalFile();
@@ -281,10 +291,10 @@
282292 'sessionkey' => null,
283293 );
284294
285 - if ( $this->getMain()->isInternalMode() )
 295+ if ( $this->getMain()->isInternalMode() ) {
286296 $params['internalhttpsession'] = null;
 297+ }
287298 return $params;
288 -
289299 }
290300
291301 public function getParamDescription() {
@@ -320,8 +330,8 @@
321331 'log out and then log back in). Also you must get and send an edit token before doing any upload stuff.'
322332 );
323333 }
324 -
325 - public function getPossibleErrors() {
 334+
 335+ public function getPossibleErrors() {
326336 return array_merge( parent::getPossibleErrors(), array(
327337 array( 'uploaddisabled' ),
328338 array( 'invalid-session-key' ),
@@ -339,9 +349,9 @@
340350 array( 'code' => 'overwrite', 'info' => 'Overwriting an existing file is not allowed' ),
341351 array( 'code' => 'stashfailed', 'info' => 'Stashing temporary file failed' ),
342352 array( 'code' => 'internal-error', 'info' => 'An internal error occurred' ),
343 - ) );
 353+ ) );
344354 }
345 -
 355+
346356 public function getTokenSalt() {
347357 return '';
348358 }
Index: trunk/phase3/includes/api/ApiQueryUserContributions.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Oct 16, 2006
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 9+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -36,7 +36,7 @@
3737 class ApiQueryContributions extends ApiQueryBase {
3838
3939 public function __construct( $query, $moduleName ) {
40 - parent :: __construct( $query, $moduleName, 'uc' );
 40+ parent::__construct( $query, $moduleName, 'uc' );
4141 }
4242
4343 private $params, $username;
@@ -63,21 +63,21 @@
6464 $this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' );
6565 $db = $this->getDB();
6666
67 - if ( isset( $this->params['userprefix'] ) )
68 - {
 67+ if ( isset( $this->params['userprefix'] ) ) {
6968 $this->prefixMode = true;
7069 $this->multiUserMode = true;
7170 $this->userprefix = $this->params['userprefix'];
72 - }
73 - else
74 - {
 71+ } else {
7572 $this->usernames = array();
76 - if ( !is_array( $this->params['user'] ) )
 73+ if ( !is_array( $this->params['user'] ) ) {
7774 $this->params['user'] = array( $this->params['user'] );
78 - if ( !count( $this->params['user'] ) )
 75+ }
 76+ if ( !count( $this->params['user'] ) ) {
7977 $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 ) {
8180 $this->prepareUsername( $u );
 81+ }
8282 $this->prefixMode = false;
8383 $this->multiUserMode = ( count( $this->params['user'] ) > 1 );
8484 }
@@ -94,21 +94,22 @@
9595 while ( $row = $db->fetchObject( $res ) ) {
9696 if ( ++ $count > $limit ) {
9797 // 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 ) {
9999 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
100 - else
 100+ } else {
101101 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
 102+ }
102103 break;
103104 }
104105
105106 $vals = $this->extractRowInfo( $row );
106107 $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 ) {
110110 $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) );
111 - else
 111+ } else {
112112 $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rev_timestamp ) );
 113+ }
113114 break;
114115 }
115116 }
@@ -150,32 +151,37 @@
151152 $this->addWhere( 'page_id=rev_page' );
152153
153154 // Handle continue parameter
154 - if ( $this->multiUserMode && !is_null( $this->params['continue'] ) )
155 - {
 155+ if ( $this->multiUserMode && !is_null( $this->params['continue'] ) ) {
156156 $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+ }
160161 $encUser = $this->getDB()->strencode( $continue[0] );
161162 $encTS = wfTimestamp( TS_MW, $continue[1] );
162163 $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+ );
166169 }
167170
168 - if ( !$wgUser->isAllowed( 'hideuser' ) )
 171+ if ( !$wgUser->isAllowed( 'hideuser' ) ) {
169172 $this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
 173+ }
170174 // We only want pages by the specified users.
171 - if ( $this->prefixMode )
 175+ if ( $this->prefixMode ) {
172176 $this->addWhere( 'rev_user_text' . $this->getDB()->buildLike( $this->userprefix, $this->getDB()->anyString() ) );
173 - else
 177+ } else {
174178 $this->addWhereFld( 'rev_user_text', $this->usernames );
 179+ }
175180 // ... and in the specified timeframe.
176181 // Ensure the same sort order for rev_user_text and rev_timestamp
177182 // so our query is indexed
178 - if ( $this->multiUserMode )
 183+ if ( $this->multiUserMode ) {
179184 $this->addWhereRange( 'rev_user_text', $this->params['dir'], null, null );
 185+ }
180186 $this->addWhereRange( 'rev_timestamp',
181187 $this->params['dir'], $this->params['start'], $this->params['end'] );
182188 $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
@@ -185,7 +191,9 @@
186192 $show = array_flip( $show );
187193 if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
188194 || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) )
 195+ {
189196 $this->dieUsageMsg( array( 'show' ) );
 197+ }
190198
191199 $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
192200 $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
@@ -205,19 +213,19 @@
206214 'rev_user_text',
207215 'rev_deleted'
208216 ) );
209 -
 217+
210218 if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
211219 $this->fld_patrolled )
212220 {
213221 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+ }
216225 // Use a redundant join condition on both
217226 // timestamp and ID so we can use the timestamp
218227 // index
219228 $index['recentchanges'] = 'rc_user_text';
220 - if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) )
221 - {
 229+ if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
222230 // Put the tables in the right order for
223231 // STRAIGHT_JOIN
224232 $tables = array( 'revision', 'recentchanges', 'page' );
@@ -225,9 +233,7 @@
226234 $this->addWhere( 'rc_user_text=rev_user_text' );
227235 $this->addWhere( 'rc_timestamp=rev_timestamp' );
228236 $this->addWhere( 'rc_this_oldid=rev_id' );
229 - }
230 - else
231 - {
 237+ } else {
232238 $tables[] = 'recentchanges';
233239 $this->addJoinConds( array( 'recentchanges' => array(
234240 'LEFT JOIN', array(
@@ -241,28 +247,27 @@
242248 $this->addFieldsIf( 'rev_page', $this->fld_ids );
243249 $this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags );
244250 $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?
246252 $this->addFieldsIf( 'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
247253 $this->addFieldsIf( 'rev_len', $this->fld_size );
248254 $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags );
249255 $this->addFieldsIf( 'rev_parent_id', $this->fld_flags );
250256 $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
251 -
252 - if ( $this->fld_tags )
253 - {
 257+
 258+ if ( $this->fld_tags ) {
254259 $this->addTables( 'tag_summary' );
255260 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
256261 $this->addFields( 'ts_tags' );
257262 }
258 -
 263+
259264 if ( isset( $this->params['tag'] ) ) {
260265 $this->addTables( 'change_tag' );
261266 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
262267 $this->addWhereFld( 'ct_tag', $this->params['tag'] );
263268 global $wgOldChangeTagsIndex;
264 - $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
 269+ $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
265270 }
266 -
 271+
267272 $this->addOption( 'USE INDEX', $index );
268273 }
269274
@@ -270,42 +275,48 @@
271276 * Extract fields from the database row and append them to a result array
272277 */
273278 private function extractRowInfo( $row ) {
274 -
275279 $vals = array();
276280
277281 $vals['user'] = $row->rev_user_text;
278 - if ( $row->rev_deleted & Revision::DELETED_USER )
 282+ if ( $row->rev_deleted & Revision::DELETED_USER ) {
279283 $vals['userhidden'] = '';
 284+ }
280285 if ( $this->fld_ids ) {
281286 $vals['pageid'] = intval( $row->rev_page );
282287 $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?
284289 }
285290
286291 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
287292
288 - if ( $this->fld_title )
 293+ if ( $this->fld_title ) {
289294 ApiQueryBase::addTitleInfo( $vals, $title );
 295+ }
290296
291 - if ( $this->fld_timestamp )
 297+ if ( $this->fld_timestamp ) {
292298 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
 299+ }
293300
294301 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 ) ) {
296303 $vals['new'] = '';
297 - if ( $row->rev_minor_edit )
 304+ }
 305+ if ( $row->rev_minor_edit ) {
298306 $vals['minor'] = '';
299 - if ( $row->page_latest == $row->rev_id )
 307+ }
 308+ if ( $row->page_latest == $row->rev_id ) {
300309 $vals['top'] = '';
 310+ }
301311 }
302312
303313 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 ) {
305315 $vals['commenthidden'] = '';
306 - else {
307 - if ( $this->fld_comment )
 316+ } else {
 317+ if ( $this->fld_comment ) {
308318 $vals['comment'] = $row->rev_comment;
309 -
 319+ }
 320+
310321 if ( $this->fld_parsedcomment ) {
311322 global $wgUser;
312323 $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->rev_comment, $title );
@@ -313,11 +324,13 @@
314325 }
315326 }
316327
317 - if ( $this->fld_patrolled && $row->rc_patrolled )
 328+ if ( $this->fld_patrolled && $row->rc_patrolled ) {
318329 $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 ) ) {
321333 $vals['size'] = intval( $row->rev_len );
 334+ }
322335
323336 if ( $this->fld_tags ) {
324337 if ( $row->ts_tags ) {
@@ -328,51 +341,50 @@
329342 $vals['tags'] = array();
330343 }
331344 }
332 -
 345+
333346 return $vals;
334347 }
335 -
336 - private function continueStr( $row )
337 - {
 348+
 349+ private function continueStr( $row ) {
338350 return $row->rev_user_text . '|' .
339351 wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
340352 }
341353
342354 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
350362 ),
351 - 'start' => array (
352 - ApiBase :: PARAM_TYPE => 'timestamp'
 363+ 'start' => array(
 364+ ApiBase::PARAM_TYPE => 'timestamp'
353365 ),
354 - 'end' => array (
355 - ApiBase :: PARAM_TYPE => 'timestamp'
 366+ 'end' => array(
 367+ ApiBase::PARAM_TYPE => 'timestamp'
356368 ),
357369 'continue' => null,
358 - 'user' => array (
359 - ApiBase :: PARAM_ISMULTI => true
 370+ 'user' => array(
 371+ ApiBase::PARAM_ISMULTI => true
360372 ),
361373 '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(
365377 'newer',
366378 'older'
367379 )
368380 ),
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'
372384 ),
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(
377389 'ids',
378390 'title',
379391 'timestamp',
@@ -384,9 +396,9 @@
385397 'tags'
386398 )
387399 ),
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(
391403 'minor',
392404 '!minor',
393405 'patrolled',
@@ -398,7 +410,7 @@
399411 }
400412
401413 public function getParamDescription() {
402 - return array (
 414+ return array(
403415 'limit' => 'The maximum number of contributions to return.',
404416 'start' => 'The start timestamp to return from.',
405417 'end' => 'The end timestamp to return to.',
@@ -417,7 +429,7 @@
418430 public function getDescription() {
419431 return 'Get all edits by a user';
420432 }
421 -
 433+
422434 public function getPossibleErrors() {
423435 return array_merge( parent::getPossibleErrors(), array(
424436 array( 'code' => 'param_user', 'info' => 'User parameter may not be empty.' ),
@@ -428,7 +440,7 @@
429441 }
430442
431443 protected function getExamples() {
432 - return array (
 444+ return array(
433445 'api.php?action=query&list=usercontribs&ucuser=YurikBot',
434446 'api.php?action=query&list=usercontribs&ucuserprefix=217.121.114.',
435447 );
Index: trunk/phase3/includes/api/ApiQueryUsers.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on July 30, 2007
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
 9+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2626
2727 if ( !defined( 'MEDIAWIKI' ) ) {
2828 // Eclipse helper - will be ignored in production
29 - require_once ( 'ApiQueryBase.php' );
 29+ require_once( 'ApiQueryBase.php' );
3030 }
3131
3232 /**
@@ -36,9 +36,9 @@
3737 class ApiQueryUsers extends ApiQueryBase {
3838
3939 public function __construct( $query, $moduleName ) {
40 - parent :: __construct( $query, $moduleName, 'us' );
 40+ parent::__construct( $query, $moduleName, 'us' );
4141 }
42 -
 42+
4343 /**
4444 * Get an array mapping token names to their handler functions.
4545 * The prototype for a token function is func($user)
@@ -47,12 +47,14 @@
4848 */
4949 protected function getTokenFunctions() {
5050 // Don't call the hooks twice
51 - if ( isset( $this->tokenFunctions ) )
 51+ if ( isset( $this->tokenFunctions ) ) {
5252 return $this->tokenFunctions;
 53+ }
5354
5455 // 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' ) ) ) {
5657 return array();
 58+ }
5759
5860 $this->tokenFunctions = array(
5961 'userrights' => array( 'ApiQueryUsers', 'getUserrightsToken' ),
@@ -60,9 +62,8 @@
6163 wfRunHooks( 'APIQueryUsersTokens', array( &$this->tokenFunctions ) );
6264 return $this->tokenFunctions;
6365 }
64 -
65 - public static function getUserrightsToken( $user )
66 - {
 66+
 67+ public static function getUserrightsToken( $user ) {
6768 global $wgUser;
6869 // Since the permissions check for userrights is non-trivial,
6970 // don't bother with it here
@@ -86,26 +87,23 @@
8788 // Canonicalize user names
8889 foreach ( $users as $u ) {
8990 $n = User::getCanonicalName( $u );
90 - if ( $n === false || $n === '' )
91 - {
 91+ if ( $n === false || $n === '' ) {
9292 $vals = array( 'name' => $u, 'invalid' => '' );
9393 $fit = $result->addValue( array( 'query', $this->getModuleName() ),
9494 null, $vals );
95 - if ( !$fit )
96 - {
 95+ if ( !$fit ) {
9796 $this->setContinueEnumParameter( 'users',
9897 implode( '|', array_diff( $users, $done ) ) );
9998 $goodNames = array();
10099 break;
101100 }
102101 $done[] = $u;
 102+ } else {
 103+ $goodNames[] = $n;
103104 }
104 - else
105 - $goodNames[] = $n;
106105 }
107106
108 - if ( count( $goodNames ) )
109 - {
 107+ if ( count( $goodNames ) ) {
110108 $db = $this->getDb();
111109 $this->addTables( 'user', 'u1' );
112110 $this->addFields( 'u1.*' );
@@ -132,19 +130,23 @@
133131 $user = User::newFromRow( $r );
134132 $name = $user->getName();
135133 $data[$name]['name'] = $name;
136 - if ( isset( $this->prop['editcount'] ) )
 134+ if ( isset( $this->prop['editcount'] ) ) {
137135 $data[$name]['editcount'] = intval( $user->getEditCount() );
138 - if ( isset( $this->prop['registration'] ) )
 136+ }
 137+ if ( isset( $this->prop['registration'] ) ) {
139138 $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 ) ) {
141141 // This row contains only one group, others will be added from other rows
142142 $data[$name]['groups'][] = $r->ug_group;
 143+ }
143144 if ( isset( $this->prop['blockinfo'] ) && !is_null( $r->blocker_name ) ) {
144145 $data[$name]['blockedby'] = $r->blocker_name;
145146 $data[$name]['blockreason'] = $r->ipb_reason;
146147 }
147 - if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() )
 148+ if ( isset( $this->prop['emailable'] ) && $user->canReceiveEmail() ) {
148149 $data[$name]['emailable'] = '';
 150+ }
149151
150152 if ( isset( $this->prop['gender'] ) ) {
151153 $gender = $user->getOption( 'gender' );
@@ -154,16 +156,15 @@
155157 $data[$name]['gender'] = $gender;
156158 }
157159
158 - if ( !is_null( $params['token'] ) )
159 - {
 160+ if ( !is_null( $params['token'] ) ) {
160161 $tokenFunctions = $this->getTokenFunctions();
161 - foreach ( $params['token'] as $t )
162 - {
 162+ foreach ( $params['token'] as $t ) {
163163 $val = call_user_func( $tokenFunctions[$t], $user );
164 - if ( $val === false )
 164+ if ( $val === false ) {
165165 $this->setWarning( "Action '$t' is not allowed for the current user" );
166 - else
 166+ } else {
167167 $data[$name][$t . 'token'] = $val;
 168+ }
168169 }
169170 }
170171 }
@@ -176,28 +177,29 @@
177178 $iwUser = $urPage->fetchUser( $u );
178179 if ( $iwUser instanceof UserRightsProxy ) {
179180 $data[$u]['interwiki'] = '';
180 - if ( !is_null( $params['token'] ) )
181 - {
 181+ if ( !is_null( $params['token'] ) ) {
182182 $tokenFunctions = $this->getTokenFunctions();
183 - foreach ( $params['token'] as $t )
184 - {
 183+ foreach ( $params['token'] as $t ) {
185184 $val = call_user_func( $tokenFunctions[$t], $iwUser );
186 - if ( $val === false )
 185+ if ( $val === false ) {
187186 $this->setWarning( "Action '$t' is not allowed for the current user" );
188 - else
 187+ } else {
189188 $data[$u][$t . 'token'] = $val;
 189+ }
190190 }
191191 }
192 - } else
 192+ } else {
193193 $data[$u]['missing'] = '';
 194+ }
194195 } else {
195196 if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) )
 197+ {
196198 $this->getResult()->setIndexedTagName( $data[$u]['groups'], 'g' );
 199+ }
197200 }
198201 $fit = $result->addValue( array( 'query', $this->getModuleName() ),
199202 null, $data[$u] );
200 - if ( !$fit )
201 - {
 203+ if ( !$fit ) {
202204 $this->setContinueEnumParameter( 'users',
203205 implode( '|', array_diff( $users, $done ) ) );
204206 break;
@@ -208,11 +210,11 @@
209211 }
210212
211213 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(
217219 'blockinfo',
218220 'groups',
219221 'editcount',
@@ -222,17 +224,17 @@
223225 )
224226 ),
225227 'users' => array(
226 - ApiBase :: PARAM_ISMULTI => true
 228+ ApiBase::PARAM_ISMULTI => true
227229 ),
228230 '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
231233 ),
232234 );
233235 }
234236
235237 public function getParamDescription() {
236 - return array (
 238+ return array(
237239 'prop' => array(
238240 'What pieces of information to include',
239241 ' blockinfo - tags if the user is blocked, by whom, and for what reason',

Status & tagging log