r62883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62882‎ | r62883 | r62884 >
Date:18:05, 23 February 2010
Author:ashley
Status:ok
Tags:
Comment:
API: fix copyright symbol, coding style cleanup, more braces
Modified paths:
  • /trunk/phase3/includes/api/ApiFormatXml.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFormatYaml.php (modified) (history)
  • /trunk/phase3/includes/api/ApiHelp.php (modified) (history)
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogout.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiOpenSearch.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParamInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPatrol.php (modified) (history)
  • /trunk/phase3/includes/api/ApiProtect.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiLogout.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 /**
@@ -37,14 +37,14 @@
3838 class ApiLogout extends ApiBase {
3939
4040 public function __construct( $main, $action ) {
41 - parent :: __construct( $main, $action );
 41+ parent::__construct( $main, $action );
4242 }
4343
4444 public function execute() {
4545 global $wgUser;
4646 $oldName = $wgUser->getName();
4747 $wgUser->logout();
48 -
 48+
4949 // Give extensions to do something after user logout
5050 $injected_html = '';
5151 wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
@@ -55,15 +55,15 @@
5656 }
5757
5858 public function getAllowedParams() {
59 - return array ();
 59+ return array();
6060 }
6161
6262 public function getParamDescription() {
63 - return array ();
 63+ return array();
6464 }
6565
6666 public function getDescription() {
67 - return array (
 67+ return array(
6868 'This module is used to logout and clear session data'
6969 );
7070 }
Index: trunk/phase3/includes/api/ApiParse.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Dec 01, 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 ( "ApiBase.php" );
 29+ require_once( "ApiBase.php" );
3030 }
3131
3232 /**
@@ -34,7 +34,7 @@
3535 class ApiParse extends ApiBase {
3636
3737 public function __construct( $main, $action ) {
38 - parent :: __construct( $main, $action );
 38+ parent::__construct( $main, $action );
3939 }
4040
4141 public function execute() {
@@ -44,8 +44,9 @@
4545 $title = $params['title'];
4646 $page = $params['page'];
4747 $oldid = $params['oldid'];
48 - if ( !is_null( $page ) && ( !is_null( $text ) || $title != "API" ) )
49 - $this->dieUsage( "The page parameter cannot be used together with the text and title parameters", 'params' );
 48+ if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
 49+ $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
 50+ }
5051 $prop = array_flip( $params['prop'] );
5152 $revid = false;
5253
@@ -56,26 +57,23 @@
5758 $popts->setTidy( true );
5859 $popts->enableLimitReport();
5960 $redirValues = null;
60 - if ( !is_null( $oldid ) || !is_null( $page ) )
61 - {
62 - if ( !is_null( $oldid ) )
63 - {
 61+ if ( !is_null( $oldid ) || !is_null( $page ) ) {
 62+ if ( !is_null( $oldid ) ) {
6463 // Don't use the parser cache
6564 $rev = Revision::newFromID( $oldid );
66 - if ( !$rev )
 65+ if ( !$rev ) {
6766 $this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
68 - if ( !$rev->userCan( Revision::DELETED_TEXT ) )
 67+ }
 68+ if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
6969 $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
 70+ }
7071
7172 $text = $rev->getText( Revision::FOR_THIS_USER );
7273 $titleObj = $rev->getTitle();
7374 $wgTitle = $titleObj;
7475 $p_result = $wgParser->parse( $text, $titleObj, $popts );
75 - }
76 - else
77 - {
78 - if ( $params['redirects'] )
79 - {
 76+ } else {
 77+ if ( $params['redirects'] ) {
8078 $req = new FauxRequest( array(
8179 'action' => 'query',
8280 'redirects' => '',
@@ -86,42 +84,45 @@
8785 $data = $main->getResultData();
8886 $redirValues = @$data['query']['redirects'];
8987 $to = $page;
90 - foreach ( (array)$redirValues as $r )
 88+ foreach ( (array)$redirValues as $r ) {
9189 $to = $r['to'];
 90+ }
 91+ } else {
 92+ $to = $page;
9293 }
93 - else
94 - $to = $page;
9594 $titleObj = Title::newFromText( $to );
96 - if ( !$titleObj )
 95+ if ( !$titleObj ) {
9796 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
 97+ }
9898
9999 $articleObj = new Article( $titleObj );
100 - if ( isset( $prop['revid'] ) )
 100+ if ( isset( $prop['revid'] ) ) {
101101 $oldid = $articleObj->getRevIdFetched();
 102+ }
102103 // Try the parser cache first
103104 $p_result = false;
104105 $pcache = ParserCache::singleton();
105 - if ( $wgEnableParserCache )
 106+ if ( $wgEnableParserCache ) {
106107 $p_result = $pcache->get( $articleObj, $wgUser );
107 - if ( !$p_result )
108 - {
 108+ }
 109+ if ( !$p_result ) {
109110 $p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
110 -
111 - if ( $wgEnableParserCache )
 111+
 112+ if ( $wgEnableParserCache ) {
112113 $pcache->save( $p_result, $articleObj, $popts );
 114+ }
113115 }
114116 }
115 - }
116 - else
117 - {
 117+ } else {
118118 $titleObj = Title::newFromText( $title );
119 - if ( !$titleObj )
120 - $titleObj = Title::newFromText( "API" );
 119+ if ( !$titleObj ) {
 120+ $titleObj = Title::newFromText( 'API' );
 121+ }
121122 $wgTitle = $titleObj;
122 - if ( $params['pst'] || $params['onlypst'] )
 123+ if ( $params['pst'] || $params['onlypst'] ) {
123124 $text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts );
124 - if ( $params['onlypst'] )
125 - {
 125+ }
 126+ if ( $params['onlypst'] ) {
126127 // Build a result and bail out
127128 $result_array['text'] = array();
128129 $this->getResult()->setContent( $result_array['text'], $text );
@@ -134,50 +135,61 @@
135136 // Return result
136137 $result = $this->getResult();
137138 $result_array = array();
138 - if ( $params['redirects'] && !is_null( $redirValues ) )
 139+ if ( $params['redirects'] && !is_null( $redirValues ) ) {
139140 $result_array['redirects'] = $redirValues;
140 -
 141+ }
 142+
141143 if ( isset( $prop['text'] ) ) {
142144 $result_array['text'] = array();
143145 $result->setContent( $result_array['text'], $p_result->getText() );
144146 }
145 -
 147+
146148 if ( !is_null( $params['summary'] ) ) {
147149 $result_array['parsedsummary'] = array();
148150 $result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) );
149151 }
150 -
151 - if ( isset( $prop['langlinks'] ) )
 152+
 153+ if ( isset( $prop['langlinks'] ) ) {
152154 $result_array['langlinks'] = $this->formatLangLinks( $p_result->getLanguageLinks() );
153 - if ( isset( $prop['categories'] ) )
 155+ }
 156+ if ( isset( $prop['categories'] ) ) {
154157 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
155 - if ( isset( $prop['links'] ) )
 158+ }
 159+ if ( isset( $prop['links'] ) ) {
156160 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
157 - if ( isset( $prop['templates'] ) )
 161+ }
 162+ if ( isset( $prop['templates'] ) ) {
158163 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
159 - if ( isset( $prop['images'] ) )
 164+ }
 165+ if ( isset( $prop['images'] ) ) {
160166 $result_array['images'] = array_keys( $p_result->getImages() );
161 - if ( isset( $prop['externallinks'] ) )
 167+ }
 168+ if ( isset( $prop['externallinks'] ) ) {
162169 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
163 - if ( isset( $prop['sections'] ) )
 170+ }
 171+ if ( isset( $prop['sections'] ) ) {
164172 $result_array['sections'] = $p_result->getSections();
165 - if ( isset( $prop['displaytitle'] ) )
 173+ }
 174+ if ( isset( $prop['displaytitle'] ) ) {
166175 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
167176 $p_result->getDisplayTitle() :
168177 $titleObj->getPrefixedText();
169 -
170 - if ( isset( $prop['headitems'] ) )
 178+ }
 179+
 180+ if ( isset( $prop['headitems'] ) ) {
171181 $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
172 -
 182+ }
 183+
173184 if ( isset( $prop['headhtml'] ) ) {
174185 $out = new OutputPage;
175186 $out->addParserOutputNoText( $p_result );
176187 $result_array['headhtml'] = array();
177188 $result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) );
178189 }
179 -
180 - if ( !is_null( $oldid ) )
 190+
 191+ if ( !is_null( $oldid ) ) {
181192 $result_array['revid'] = intval( $oldid );
 193+ }
182194
183195 $result_mapping = array(
184196 'redirects' => 'r',
@@ -224,8 +236,9 @@
225237 $entry = array();
226238 $entry['ns'] = $ns;
227239 $this->getResult()->setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
228 - if ( $id != 0 )
 240+ if ( $id != 0 ) {
229241 $entry['exists'] = '';
 242+ }
230243 $result[] = $entry;
231244 }
232245 }
@@ -245,15 +258,16 @@
246259
247260 private function setIndexedTagNames( &$array, $mapping ) {
248261 foreach ( $mapping as $key => $name ) {
249 - if ( isset( $array[$key] ) )
 262+ if ( isset( $array[$key] ) ) {
250263 $this->getResult()->setIndexedTagName( $array[$key], $name );
 264+ }
251265 }
252266 }
253267
254268 public function getAllowedParams() {
255 - return array (
 269+ return array(
256270 'title' => array(
257 - ApiBase :: PARAM_DFLT => 'API',
 271+ ApiBase::PARAM_DFLT => 'API',
258272 ),
259273 'text' => null,
260274 'summary' => null,
@@ -261,9 +275,9 @@
262276 'redirects' => false,
263277 'oldid' => null,
264278 'prop' => array(
265 - ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
266 - ApiBase :: PARAM_ISMULTI => true,
267 - ApiBase :: PARAM_TYPE => array(
 279+ ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
 280+ ApiBase::PARAM_ISMULTI => true,
 281+ ApiBase::PARAM_TYPE => array(
268282 'text',
269283 'langlinks',
270284 'categories',
@@ -284,7 +298,7 @@
285299 }
286300
287301 public function getParamDescription() {
288 - return array (
 302+ return array(
289303 'text' => 'Wikitext to parse',
290304 'summary' => 'Summary to parse',
291305 'redirects' => 'If the page parameter is set to a redirect, resolve it',
@@ -306,7 +320,7 @@
307321 public function getDescription() {
308322 return 'This module parses wikitext and returns parser output';
309323 }
310 -
 324+
311325 public function getPossibleErrors() {
312326 return array_merge( parent::getPossibleErrors(), array(
313327 array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ),
@@ -317,7 +331,7 @@
318332 }
319333
320334 protected function getExamples() {
321 - return array (
 335+ return array(
322336 'api.php?action=parse&text={{Project:Sandbox}}'
323337 );
324338 }
Index: trunk/phase3/includes/api/ApiProtect.php
@@ -1,10 +1,10 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 1, 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 /**
@@ -33,7 +33,7 @@
3434 class ApiProtect 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,60 +41,68 @@
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 - if ( empty( $params['protections'] ) )
 47+ }
 48+ if ( empty( $params['protections'] ) ) {
4849 $this->dieUsageMsg( array( 'missingparam', 'protections' ) );
 50+ }
4951
5052 $titleObj = Title::newFromText( $params['title'] );
51 - if ( !$titleObj )
 53+ if ( !$titleObj ) {
5254 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 55+ }
5356
5457 $errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser );
55 - if ( $errors )
 58+ if ( $errors ) {
5659 // We don't care about multiple errors, just report one of them
5760 $this->dieUsageMsg( reset( $errors ) );
 61+ }
5862
5963 $expiry = (array)$params['expiry'];
60 - if ( count( $expiry ) != count( $params['protections'] ) )
61 - {
62 - if ( count( $expiry ) == 1 )
 64+ if ( count( $expiry ) != count( $params['protections'] ) ) {
 65+ if ( count( $expiry ) == 1 ) {
6366 $expiry = array_fill( 0, count( $params['protections'] ), $expiry[0] );
64 - else
 67+ } else {
6568 $this->dieUsageMsg( array( 'toofewexpiries', count( $expiry ), count( $params['protections'] ) ) );
 69+ }
6670 }
67 -
 71+
6872 $restrictionTypes = $titleObj->getRestrictionTypes();
69 -
 73+
7074 $protections = array();
7175 $expiryarray = array();
7276 $resultProtections = array();
73 - foreach ( $params['protections'] as $i => $prot )
74 - {
 77+ foreach ( $params['protections'] as $i => $prot ) {
7578 $p = explode( '=', $prot );
7679 $protections[$p[0]] = ( $p[1] == 'all' ? '' : $p[1] );
7780
78 - if ( $titleObj->exists() && $p[0] == 'create' )
 81+ if ( $titleObj->exists() && $p[0] == 'create' ) {
7982 $this->dieUsageMsg( array( 'create-titleexists' ) );
80 - if ( !$titleObj->exists() && $p[0] != 'create' )
 83+ }
 84+ if ( !$titleObj->exists() && $p[0] != 'create' ) {
8185 $this->dieUsageMsg( array( 'missingtitle-createonly' ) );
 86+ }
8287
83 - if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' )
 88+ if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) {
8489 $this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) );
85 - if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' )
 90+ }
 91+ if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) {
8692 $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
 93+ }
8794
88 - if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) )
 95+ if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
8996 $expiryarray[$p[0]] = Block::infinity();
90 - else
91 - {
 97+ } else {
9298 $exp = strtotime( $expiry[$i] );
93 - if ( $exp < 0 || $exp == false )
 99+ if ( $exp < 0 || $exp == false ) {
94100 $this->dieUsageMsg( array( 'invalidexpiry', $expiry[$i] ) );
 101+ }
95102
96103 $exp = wfTimestamp( TS_MW, $exp );
97 - if ( $exp < wfTimestampNow() )
 104+ if ( $exp < wfTimestampNow() ) {
98105 $this->dieUsageMsg( array( 'pastexpiry', $expiry[$i] ) );
 106+ }
99107 $expiryarray[$p[0]] = $exp;
100108 }
101109 $resultProtections[] = array( $p[0] => $protections[$p[0]],
@@ -105,19 +113,26 @@
106114
107115 $cascade = $params['cascade'];
108116 $articleObj = new Article( $titleObj );
109 - if ( $params['watch'] )
 117+ if ( $params['watch'] ) {
110118 $articleObj->doWatch();
111 - if ( $titleObj->exists() )
 119+ }
 120+ if ( $titleObj->exists() ) {
112121 $ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray );
113 - else
 122+ } else {
114123 $ok = $titleObj->updateTitleProtection( $protections['create'], $params['reason'], $expiryarray['create'] );
115 - if ( !$ok )
 124+ }
 125+ if ( !$ok ) {
116126 // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?
117127 // Just throw an unknown error in this case, as it's very likely to be a race condition
118128 $this->dieUsageMsg( array() );
119 - $res = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'] );
120 - if ( $cascade )
 129+ }
 130+ $res = array(
 131+ 'title' => $titleObj->getPrefixedText(),
 132+ 'reason' => $params['reason']
 133+ );
 134+ if ( $cascade ) {
121135 $res['cascade'] = '';
 136+ }
122137 $res['protections'] = $resultProtections;
123138 $this->getResult()->setIndexedTagName( $res['protections'], 'protection' );
124139 $this->getResult()->addValue( null, $this->getModuleName(), $res );
@@ -132,16 +147,16 @@
133148 }
134149
135150 public function getAllowedParams() {
136 - return array (
 151+ return array(
137152 'title' => null,
138153 'token' => null,
139154 'protections' => array(
140 - ApiBase :: PARAM_ISMULTI => true
 155+ ApiBase::PARAM_ISMULTI => true
141156 ),
142157 'expiry' => array(
143 - ApiBase :: PARAM_ISMULTI => true,
144 - ApiBase :: PARAM_ALLOW_DUPLICATES => true,
145 - ApiBase :: PARAM_DFLT => 'infinite',
 158+ ApiBase::PARAM_ISMULTI => true,
 159+ ApiBase::PARAM_ALLOW_DUPLICATES => true,
 160+ ApiBase::PARAM_DFLT => 'infinite',
146161 ),
147162 'reason' => '',
148163 'cascade' => false,
@@ -150,7 +165,7 @@
151166 }
152167
153168 public function getParamDescription() {
154 - return array (
 169+ return array(
155170 'title' => 'Title of the page you want to (un)protect.',
156171 'token' => 'A protect token previously retrieved through prop=info',
157172 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)',
@@ -168,7 +183,7 @@
169184 'Change the protection level of a page.'
170185 );
171186 }
172 -
 187+
173188 public function getPossibleErrors() {
174189 return array_merge( parent::getPossibleErrors(), array(
175190 array( 'missingparam', 'title' ),
@@ -183,13 +198,13 @@
184199 array( 'pastexpiry', 'expiry' ),
185200 ) );
186201 }
187 -
 202+
188203 public function getTokenSalt() {
189204 return null;
190205 }
191206
192207 protected function getExamples() {
193 - return array (
 208+ return array(
194209 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000|never',
195210 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions'
196211 );
Index: trunk/phase3/includes/api/ApiImport.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Feb 4, 2009
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
 9+ * Copyright © 2009 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 ( 'ApiBase.php' );
 29+ require_once( 'ApiBase.php' );
3030 }
3131
3232 /**
@@ -36,58 +36,65 @@
3737 class ApiImport 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->isAllowed( 'import' ) )
 45+ if ( !$wgUser->isAllowed( 'import' ) ) {
4646 $this->dieUsageMsg( array( 'cantimport' ) );
 47+ }
4748 $params = $this->extractRequestParams();
4849
4950 $source = null;
5051 $isUpload = false;
51 - if ( isset( $params['interwikisource'] ) )
52 - {
53 - if ( !isset( $params['interwikipage'] ) )
 52+ if ( isset( $params['interwikisource'] ) ) {
 53+ if ( !isset( $params['interwikipage'] ) ) {
5454 $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
 55+ }
5556 $source = ImportStreamSource::newFromInterwiki(
56 - $params['interwikisource'],
57 - $params['interwikipage'],
58 - $params['fullhistory'],
59 - $params['templates'] );
60 - }
61 - else
62 - {
 57+ $params['interwikisource'],
 58+ $params['interwikipage'],
 59+ $params['fullhistory'],
 60+ $params['templates']
 61+ );
 62+ } else {
6363 $isUpload = true;
64 - if ( !$wgUser->isAllowed( 'importupload' ) )
 64+ if ( !$wgUser->isAllowed( 'importupload' ) ) {
6565 $this->dieUsageMsg( array( 'cantimport-upload' ) );
 66+ }
6667 $source = ImportStreamSource::newFromUpload( 'xml' );
6768 }
68 - if ( $source instanceof WikiErrorMsg )
 69+ if ( $source instanceof WikiErrorMsg ) {
6970 $this->dieUsageMsg( array_merge(
7071 array( $source->getMessageKey() ),
7172 $source->getMessageArgs() ) );
72 - else if ( WikiError::isError( $source ) )
 73+ } elseif ( WikiError::isError( $source ) ) {
7374 // This shouldn't happen
7475 $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
 76+ }
7577
7678 $importer = new WikiImporter( $source );
77 - if ( isset( $params['namespace'] ) )
 79+ if ( isset( $params['namespace'] ) ) {
7880 $importer->setTargetNamespace( $params['namespace'] );
79 - $reporter = new ApiImportReporter( $importer, $isUpload,
80 - $params['interwikisource'],
81 - $params['summary'] );
 81+ }
 82+ $reporter = new ApiImportReporter(
 83+ $importer,
 84+ $isUpload,
 85+ $params['interwikisource'],
 86+ $params['summary']
 87+ );
8288
8389 $result = $importer->doImport();
84 - if ( $result instanceof WikiXmlError )
 90+ if ( $result instanceof WikiXmlError ) {
8591 $this->dieUsageMsg( array( 'import-xml-error',
8692 $result->mLine,
8793 $result->mColumn,
8894 $result->mByte . $result->mContext,
8995 xml_error_string( $result->mXmlError ) ) );
90 - else if ( WikiError::isError( $result ) )
 96+ } elseif ( WikiError::isError( $result ) ) {
9197 $this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); // This shouldn't happen
 98+ }
9299
93100 $resultData = $reporter->getData();
94101 $this->getResult()->setIndexedTagName( $resultData, 'page' );
@@ -104,24 +111,24 @@
105112
106113 public function getAllowedParams() {
107114 global $wgImportSources;
108 - return array (
 115+ return array(
109116 'token' => null,
110117 'summary' => null,
111118 'xml' => null,
112119 'interwikisource' => array(
113 - ApiBase :: PARAM_TYPE => $wgImportSources
 120+ ApiBase::PARAM_TYPE => $wgImportSources
114121 ),
115122 'interwikipage' => null,
116123 'fullhistory' => false,
117124 'templates' => false,
118125 'namespace' => array(
119 - ApiBase :: PARAM_TYPE => 'namespace'
 126+ ApiBase::PARAM_TYPE => 'namespace'
120127 )
121128 );
122129 }
123130
124131 public function getParamDescription() {
125 - return array (
 132+ return array(
126133 'token' => 'Import token obtained through prop=info',
127134 'summary' => 'Import summary',
128135 'xml' => 'Uploaded XML file',
@@ -134,11 +141,11 @@
135142 }
136143
137144 public function getDescription() {
138 - return array (
 145+ return array(
139146 'Import a page from another wiki, or an XML file'
140147 );
141148 }
142 -
 149+
143150 public function getPossibleErrors() {
144151 return array_merge( parent::getPossibleErrors(), array(
145152 array( 'cantimport' ),
@@ -148,7 +155,7 @@
149156 array( 'import-unknownerror', 'result' ),
150157 ) );
151158 }
152 -
 159+
153160 public function getTokenSalt() {
154161 return '';
155162 }
@@ -172,8 +179,7 @@
173180 class ApiImportReporter extends ImportReporter {
174181 private $mResultArr = array();
175182
176 - function reportPage( $title, $origTitle, $revisionCount, $successCount )
177 - {
 183+ function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
178184 // Add a result entry
179185 $r = array();
180186 ApiQueryBase::addTitleInfo( $r, $title );
@@ -184,8 +190,7 @@
185191 parent::reportPage( $title, $origTitle, $revisionCount, $successCount );
186192 }
187193
188 - function getData()
189 - {
 194+ function getData() {
190195 return $this->mResultArr;
191196 }
192197 }
\ No newline at end of file
Index: trunk/phase3/includes/api/ApiFormatYaml.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 19, 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 ( 'ApiFormatBase.php' );
 29+ require_once( 'ApiFormatBase.php' );
3030 }
3131
3232 /**
@@ -34,7 +34,7 @@
3535 class ApiFormatYaml extends ApiFormatBase {
3636
3737 public function __construct( $main, $format ) {
38 - parent :: __construct( $main, $format );
 38+ parent::__construct( $main, $format );
3939 }
4040
4141 public function getMimeType() {
@@ -42,11 +42,11 @@
4343 }
4444
4545 public function execute() {
46 - $this->printText( Spyc :: YAMLDump( $this->getResultData() ) );
 46+ $this->printText( Spyc::YAMLDump( $this->getResultData() ) );
4747 }
4848
4949 public function getDescription() {
50 - return 'Output data in YAML format' . parent :: getDescription();
 50+ return 'Output data in YAML format' . parent::getDescription();
5151 }
5252
5353 public function getVersion() {
Index: trunk/phase3/includes/api/ApiFormatXml.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 19, 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 ( 'ApiFormatBase.php' );
 29+ require_once( 'ApiFormatBase.php' );
3030 }
3131
3232 /**
@@ -38,7 +38,7 @@
3939 private $mXslt = null;
4040
4141 public function __construct( $main, $format ) {
42 - parent :: __construct( $main, $format );
 42+ parent::__construct( $main, $format );
4343 }
4444
4545 public function getMimeType() {
@@ -59,45 +59,50 @@
6060 $this->mXslt = $params['xslt'];
6161
6262 $this->printText( '<?xml version="1.0"?>' );
63 - if ( !is_null( $this->mXslt ) )
 63+ if ( !is_null( $this->mXslt ) ) {
6464 $this->addXslt();
65 - $this->printText( self::recXmlPrint( $this->mRootElemName,
 65+ }
 66+ $this->printText(
 67+ self::recXmlPrint( $this->mRootElemName,
6668 $this->getResultData(),
6769 $this->getIsHtml() ? - 2 : null,
68 - $this->mDoubleQuote ) );
 70+ $this->mDoubleQuote
 71+ )
 72+ );
6973 }
7074
7175 /**
72 - * This method takes an array and converts it to XML.
73 - * There are several noteworthy cases:
74 - *
75 - * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
76 - * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root>
77 - *
78 - * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
79 - * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root>
80 - *
81 - * If neither key is found, all keys become element names, and values become element content.
82 - * The method is recursive, so the same rules apply to any sub-arrays.
83 - */
 76+ * This method takes an array and converts it to XML.
 77+ * There are several noteworthy cases:
 78+ *
 79+ * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
 80+ * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root>
 81+ *
 82+ * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
 83+ * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root>
 84+ *
 85+ * If neither key is found, all keys become element names, and values become element content.
 86+ * The method is recursive, so the same rules apply to any sub-arrays.
 87+ */
8488 public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) {
8589 $retval = '';
8690 if ( !is_null( $indent ) ) {
8791 $indent += 2;
88 - $indstr = "\n" . str_repeat( " ", $indent );
 92+ $indstr = "\n" . str_repeat( ' ', $indent );
8993 } else {
9094 $indstr = '';
9195 }
9296 $elemName = str_replace( ' ', '_', $elemName );
9397
9498 switch ( gettype( $elemValue ) ) {
95 - case 'array' :
96 - if ( isset ( $elemValue['*'] ) ) {
 99+ case 'array':
 100+ if ( isset( $elemValue['*'] ) ) {
97101 $subElemContent = $elemValue['*'];
98 - if ( $doublequote )
 102+ if ( $doublequote ) {
99103 $subElemContent = Sanitizer::encodeAttribute( $subElemContent );
100 - unset ( $elemValue['*'] );
101 -
 104+ }
 105+ unset( $elemValue['*'] );
 106+
102107 // Add xml:space="preserve" to the
103108 // element so XML parsers will leave
104109 // whitespace in the content alone
@@ -106,59 +111,65 @@
107112 $subElemContent = null;
108113 }
109114
110 - if ( isset ( $elemValue['_element'] ) ) {
 115+ if ( isset( $elemValue['_element'] ) ) {
111116 $subElemIndName = $elemValue['_element'];
112 - unset ( $elemValue['_element'] );
 117+ unset( $elemValue['_element'] );
113118 } else {
114119 $subElemIndName = null;
115120 }
116121
117 - $indElements = array ();
118 - $subElements = array ();
 122+ $indElements = array();
 123+ $subElements = array();
119124 foreach ( $elemValue as $subElemId => & $subElemValue ) {
120 - if ( is_string( $subElemValue ) && $doublequote )
 125+ if ( is_string( $subElemValue ) && $doublequote ) {
121126 $subElemValue = Sanitizer::encodeAttribute( $subElemValue );
122 -
 127+ }
 128+
123129 if ( gettype( $subElemId ) === 'integer' ) {
124130 $indElements[] = $subElemValue;
125 - unset ( $elemValue[$subElemId] );
 131+ unset( $elemValue[$subElemId] );
126132 } elseif ( is_array( $subElemValue ) ) {
127133 $subElements[$subElemId] = $subElemValue;
128134 unset ( $elemValue[$subElemId] );
129135 }
130136 }
131137
132 - if ( is_null( $subElemIndName ) && count( $indElements ) )
133 - ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
 138+ if ( is_null( $subElemIndName ) && count( $indElements ) ) {
 139+ ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
 140+ }
134141
135 - if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) )
136 - ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
 142+ if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) {
 143+ ApiBase::dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
 144+ }
137145
138146 if ( !is_null( $subElemContent ) ) {
139147 $retval .= $indstr . Xml::element( $elemName, $elemValue, $subElemContent );
140148 } elseif ( !count( $indElements ) && !count( $subElements ) ) {
141 - $retval .= $indstr . Xml::element( $elemName, $elemValue );
 149+ $retval .= $indstr . Xml::element( $elemName, $elemValue );
142150 } else {
143151 $retval .= $indstr . Xml::element( $elemName, $elemValue, null );
144152
145 - foreach ( $subElements as $subElemId => & $subElemValue )
 153+ foreach ( $subElements as $subElemId => & $subElemValue ) {
146154 $retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent );
 155+ }
147156
148 - foreach ( $indElements as $subElemId => & $subElemValue )
 157+ foreach ( $indElements as $subElemId => & $subElemValue ) {
149158 $retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent );
 159+ }
150160
151161 $retval .= $indstr . Xml::closeElement( $elemName );
152162 }
153163 break;
154 - case 'object' :
 164+ case 'object':
155165 // ignore
156166 break;
157 - default :
 167+ default:
158168 $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
159169 break;
160170 }
161171 return $retval;
162172 }
 173+
163174 function addXslt() {
164175 $nt = Title::newFromText( $this->mXslt );
165176 if ( is_null( $nt ) || !$nt->exists() ) {
@@ -175,23 +186,23 @@
176187 }
177188 $this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' );
178189 }
179 -
 190+
180191 public function getAllowedParams() {
181 - return array (
 192+ return array(
182193 'xmldoublequote' => false,
183194 'xslt' => null,
184195 );
185196 }
186197
187198 public function getParamDescription() {
188 - return array (
 199+ return array(
189200 'xmldoublequote' => 'If specified, double quotes all attributes and content.',
190201 'xslt' => 'If specified, adds <xslt> as stylesheet',
191202 );
192203 }
193204
194205 public function getDescription() {
195 - return 'Output data in XML format' . parent :: getDescription();
 206+ return 'Output data in XML format' . parent::getDescription();
196207 }
197208
198209 public function getVersion() {
Index: trunk/phase3/includes/api/ApiMain.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 /**
@@ -55,7 +55,7 @@
5656 /**
5757 * List of available modules: action name => module class
5858 */
59 - private static $Modules = array (
 59+ private static $Modules = array(
6060 'login' => 'ApiLogin',
6161 'logout' => 'ApiLogout',
6262 'query' => 'ApiQuery',
@@ -87,7 +87,7 @@
8888 /**
8989 * List of available formats: format name => format class
9090 */
91 - private static $Formats = array (
 91+ private static $Formats = array(
9292 'json' => 'ApiFormatJson',
9393 'jsonfm' => 'ApiFormatJson',
9494 'php' => 'ApiFormatPhp',
@@ -111,17 +111,17 @@
112112 * 'params' => array ( $someVarToSubst ) ),
113113 * );
114114 */
115 - private static $mRights = array( 'writeapi' => array(
116 - 'msg' => 'Use of the write API',
117 - 'params' => array()
118 - ),
119 - 'apihighlimits' => array(
120 - 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
121 - 'params' => array ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
122 - )
 115+ private static $mRights = array(
 116+ 'writeapi' => array(
 117+ 'msg' => 'Use of the write API',
 118+ 'params' => array()
 119+ ),
 120+ 'apihighlimits' => array(
 121+ 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
 122+ 'params' => array( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
 123+ )
123124 );
124125
125 -
126126 private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
127127 private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
128128 private $mInternalMode, $mSquidMaxage, $mModule;
@@ -129,20 +129,18 @@
130130 private $mCacheControl = array( 'must-revalidate' => true );
131131
132132 /**
133 - * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
134 - *
135 - * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs
136 - * @param $enableWrite bool should be set to true if the api may modify data
137 - */
 133+ * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
 134+ *
 135+ * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs
 136+ * @param $enableWrite bool should be set to true if the api may modify data
 137+ */
138138 public function __construct( $request, $enableWrite = false ) {
139 -
140139 $this->mInternalMode = ( $request instanceof FauxRequest );
141140
142141 // Special handling for the main module: $parent === $this
143 - parent :: __construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
 142+ parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
144143
145144 if ( !$this->mInternalMode ) {
146 -
147145 // Impose module restrictions.
148146 // If the current user cannot read,
149147 // Remove all modules other than login
@@ -157,19 +155,19 @@
158156 }
159157
160158 global $wgAPIModules; // extension modules
161 - $this->mModules = $wgAPIModules + self :: $Modules;
 159+ $this->mModules = $wgAPIModules + self::$Modules;
162160
163161 $this->mModuleNames = array_keys( $this->mModules );
164 - $this->mFormats = self :: $Formats;
 162+ $this->mFormats = self::$Formats;
165163 $this->mFormatNames = array_keys( $this->mFormats );
166164
167165 $this->mResult = new ApiResult( $this );
168166 $this->mShowVersions = false;
169167 $this->mEnableWrite = $enableWrite;
170168
171 - $this->mRequest = & $request;
 169+ $this->mRequest = &$request;
172170
173 - $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
 171+ $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
174172 $this->mCommit = false;
175173 }
176174
@@ -206,10 +204,12 @@
207205 * @deprecated Use isWriteMode() instead
208206 */
209207 public function requestWriteMode() {
210 - if ( !$this->mEnableWrite )
 208+ if ( !$this->mEnableWrite ) {
211209 $this->dieUsageMsg( array( 'writedisabled' ) );
212 - if ( wfReadOnly() )
 210+ }
 211+ if ( wfReadOnly() ) {
213212 $this->dieUsageMsg( array( 'readonlytext' ) );
 213+ }
214214 }
215215
216216 /**
@@ -235,8 +235,9 @@
236236 * Create an instance of an output formatter by its name
237237 */
238238 public function createPrinterByName( $format ) {
239 - if ( !isset( $this->mFormats[$format] ) )
 239+ if ( !isset( $this->mFormats[$format] ) ) {
240240 $this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
 241+ }
241242 return new $this->mFormats[$format] ( $this, $format );
242243 }
243244
@@ -245,10 +246,11 @@
246247 */
247248 public function execute() {
248249 $this->profileIn();
249 - if ( $this->mInternalMode )
 250+ if ( $this->mInternalMode ) {
250251 $this->executeAction();
251 - else
 252+ } else {
252253 $this->executeActionWithErrorHandling();
 254+ }
253255
254256 $this->profileOut();
255257 }
@@ -258,7 +260,6 @@
259261 * have been accumulated, and replace it with an error message and a help screen.
260262 */
261263 protected function executeActionWithErrorHandling() {
262 -
263264 // In case an error occurs during data output,
264265 // clear the output buffer and print just the error information
265266 ob_start();
@@ -283,10 +284,11 @@
284285 $this->setCacheMaxAge( 0 );
285286
286287 $headerStr = 'MediaWiki-API-Error: ' . $errCode;
287 - if ( $e->getCode() === 0 )
 288+ if ( $e->getCode() === 0 ) {
288289 header( $headerStr );
289 - else
 290+ } else {
290291 header( $headerStr, true, $e->getCode() );
 292+ }
291293
292294 // Reset and print just the error message
293295 ob_clean();
@@ -324,11 +326,12 @@
325327 $separator = ', ';
326328 }
327329 }
328 -
 330+
329331 header( "Cache-Control: $ccHeader" );
330332
331 - if ( $this->mPrinter->getIsHtml() )
 333+ if ( $this->mPrinter->getIsHtml() ) {
332334 echo wfReportTime();
 335+ }
333336
334337 ob_end_flush();
335338 }
@@ -338,17 +341,18 @@
339342 * Returns the error code
340343 */
341344 protected function substituteResultWithError( $e ) {
342 -
343345 // Printer may not be initialized if the extractRequestParams() fails for the main module
344346 if ( !isset ( $this->mPrinter ) ) {
345347 // The printer has not been created yet. Try to manually get formatter value.
346348 $value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
347 - if ( !in_array( $value, $this->mFormatNames ) )
 349+ if ( !in_array( $value, $this->mFormatNames ) ) {
348350 $value = self::API_DEFAULT_FORMAT;
 351+ }
349352
350353 $this->mPrinter = $this->createPrinterByName( $value );
351 - if ( $this->mPrinter->getNeedsRawData() )
 354+ if ( $this->mPrinter->getNeedsRawData() ) {
352355 $this->getResult()->setRawMode();
 356+ }
353357 }
354358
355359 if ( $e instanceof UsageException ) {
@@ -358,8 +362,9 @@
359363 $errMessage = $e->getMessageArray();
360364
361365 // Only print the help message when this is for the developer, not runtime
362 - if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
363 - ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
 366+ if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) {
 367+ ApiResult::setContent( $errMessage, $this->makeHelpMsg() );
 368+ }
364369
365370 } else {
366371 global $wgShowSQLErrors, $wgShowExceptionDetails;
@@ -367,24 +372,25 @@
368373 // Something is seriously wrong
369374 //
370375 if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
371 - $info = "Database query error";
 376+ $info = 'Database query error';
372377 } else {
373378 $info = "Exception Caught: {$e->getMessage()}";
374379 }
375380
376 - $errMessage = array (
 381+ $errMessage = array(
377382 'code' => 'internal_api_error_' . get_class( $e ),
378383 'info' => $info,
379384 );
380 - ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
 385+ ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
381386 }
382387
383388 $this->getResult()->reset();
384389 $this->getResult()->disableSizeCheck();
385390 // Re-add the id
386391 $requestid = $this->getParameter( 'requestid' );
387 - if ( !is_null( $requestid ) )
 392+ if ( !is_null( $requestid ) ) {
388393 $this->getResult()->addValue( null, 'requestid', $requestid );
 394+ }
389395 $this->getResult()->addValue( null, 'error', $errMessage );
390396
391397 return $errMessage['code'];
@@ -396,8 +402,9 @@
397403 protected function executeAction() {
398404 // First add the id to the top element
399405 $requestid = $this->getParameter( 'requestid' );
400 - if ( !is_null( $requestid ) )
 406+ if ( !is_null( $requestid ) ) {
401407 $this->getResult()->addValue( null, 'requestid', $requestid );
 408+ }
402409
403410 $params = $this->extractRequestParams();
404411
@@ -405,19 +412,18 @@
406413 $this->mAction = $params['action'];
407414
408415 if ( !is_string( $this->mAction ) ) {
409 - $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' );
 416+ $this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' );
410417 }
411 -
 418+
412419 // Instantiate the module requested by the user
413420 $module = new $this->mModules[$this->mAction] ( $this, $this->mAction );
414421 $this->mModule = $module;
415422
416423 $moduleParams = $module->extractRequestParams();
417 -
 424+
418425 // Die if token required, but not provided (unless there is a gettoken parameter)
419426 $salt = $module->getTokenSalt();
420 - if ( $salt !== false && !isset( $moduleParams['gettoken'] ) )
421 - {
 427+ if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
422428 if ( !isset( $moduleParams['token'] ) ) {
423429 $this->dieUsageMsg( array( 'missingparam', 'token' ) );
424430 } else {
@@ -447,20 +453,26 @@
448454
449455 global $wgUser, $wgGroupPermissions;
450456 if ( $module->isReadMode() && !$wgGroupPermissions['*']['read'] && !$wgUser->isAllowed( 'read' ) )
 457+ {
451458 $this->dieUsageMsg( array( 'readrequired' ) );
 459+ }
452460 if ( $module->isWriteMode() ) {
453 - if ( !$this->mEnableWrite )
 461+ if ( !$this->mEnableWrite ) {
454462 $this->dieUsageMsg( array( 'writedisabled' ) );
455 - if ( !$wgUser->isAllowed( 'writeapi' ) )
 463+ }
 464+ if ( !$wgUser->isAllowed( 'writeapi' ) ) {
456465 $this->dieUsageMsg( array( 'writerequired' ) );
457 - if ( wfReadOnly() )
 466+ }
 467+ if ( wfReadOnly() ) {
458468 $this->dieReadOnly();
 469+ }
459470 }
460471
461472 if ( !$this->mInternalMode ) {
462473 // Ignore mustBePosted() for internal calls
463 - if ( $module->mustBePosted() && !$this->mRequest->wasPosted() )
464 - $this->dieUsageMsg( array ( 'mustbeposted', $this->mAction ) );
 474+ if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
 475+ $this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
 476+ }
465477
466478 // See if custom printer is used
467479 $this->mPrinter = $module->getCustomPrinter();
@@ -469,8 +481,9 @@
470482 $this->mPrinter = $this->createPrinterByName( $params['format'] );
471483 }
472484
473 - if ( $this->mPrinter->getNeedsRawData() )
 485+ if ( $this->mPrinter->getNeedsRawData() ) {
474486 $this->getResult()->setRawMode();
 487+ }
475488 }
476489
477490 // Execute
@@ -493,10 +506,12 @@
494507 $printer = $this->mPrinter;
495508 $printer->profileIn();
496509
497 - /* If the help message is requested in the default (xmlfm) format,
 510+ /**
 511+ * If the help message is requested in the default (xmlfm) format,
498512 * tell the printer not to escape ampersands so that our links do
499 - * not break. */
500 - $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
 513+ * not break.
 514+ */
 515+ $printer->setUnescapeAmps( ( $this->mAction == 'help' || $isError )
501516 && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
502517
503518 $printer->initPrinter( $isError );
@@ -514,26 +529,26 @@
515530 * See ApiBase for description.
516531 */
517532 public function getAllowedParams() {
518 - return array (
519 - 'format' => array (
520 - ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
521 - ApiBase :: PARAM_TYPE => $this->mFormatNames
 533+ return array(
 534+ 'format' => array(
 535+ ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
 536+ ApiBase::PARAM_TYPE => $this->mFormatNames
522537 ),
523 - 'action' => array (
524 - ApiBase :: PARAM_DFLT => 'help',
525 - ApiBase :: PARAM_TYPE => $this->mModuleNames
 538+ 'action' => array(
 539+ ApiBase::PARAM_DFLT => 'help',
 540+ ApiBase::PARAM_TYPE => $this->mModuleNames
526541 ),
527542 'version' => false,
528 - 'maxlag' => array (
529 - ApiBase :: PARAM_TYPE => 'integer'
 543+ 'maxlag' => array(
 544+ ApiBase::PARAM_TYPE => 'integer'
530545 ),
531 - 'smaxage' => array (
532 - ApiBase :: PARAM_TYPE => 'integer',
533 - ApiBase :: PARAM_DFLT => 0
 546+ 'smaxage' => array(
 547+ ApiBase::PARAM_TYPE => 'integer',
 548+ ApiBase::PARAM_DFLT => 0
534549 ),
535 - 'maxage' => array (
536 - ApiBase :: PARAM_TYPE => 'integer',
537 - ApiBase :: PARAM_DFLT => 0
 550+ 'maxage' => array(
 551+ ApiBase::PARAM_TYPE => 'integer',
 552+ ApiBase::PARAM_DFLT => 0
538553 ),
539554 'requestid' => null,
540555 );
@@ -543,7 +558,7 @@
544559 * See ApiBase for description.
545560 */
546561 public function getParamDescription() {
547 - return array (
 562+ return array(
548563 'format' => 'The format of the output',
549564 'action' => 'What action you would like to perform',
550565 'version' => 'When showing help, include version for each module',
@@ -558,7 +573,7 @@
559574 * See ApiBase for description.
560575 */
561576 public function getDescription() {
562 - return array (
 577+ return array(
563578 '',
564579 '',
565580 '******************************************************************',
@@ -585,14 +600,14 @@
586601 );
587602 }
588603
589 - public function getPossibleErrors() {
 604+ public function getPossibleErrors() {
590605 return array_merge( parent::getPossibleErrors(), array(
591606 array( 'readonlytext' ),
592607 array( 'code' => 'unknown_format', 'info' => 'Unrecognized format: format' ),
593608 array( 'code' => 'unknown_action', 'info' => 'The API requires a valid action parameter' ),
594609 array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ),
595610 array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ),
596 - ) );
 611+ ) );
597612 }
598613
599614 /**
@@ -624,21 +639,22 @@
625640 $this->getMain()->getShowVersions() );
626641 if ( $wgAPICacheHelp ) {
627642 $cached = $wgMemc->get( $key );
628 - if ( $cached )
 643+ if ( $cached ) {
629644 return $cached;
 645+ }
630646 }
631647 $retval = $this->reallyMakeHelpMsg();
632 - if ( $wgAPICacheHelp )
 648+ if ( $wgAPICacheHelp ) {
633649 $wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
 650+ }
634651 return $retval;
635652 }
636653
637654 public function reallyMakeHelpMsg() {
638 -
639655 $this->mPrinter->setHelp();
640656
641657 // Use parent to make default message for the main module
642 - $msg = parent :: makeHelpMsg();
 658+ $msg = parent::makeHelpMsg();
643659
644660 $astriks = str_repeat( '*** ', 10 );
645661 $msg .= "\n\n$astriks Modules $astriks\n\n";
@@ -646,16 +662,17 @@
647663 $module = new $this->mModules[$moduleName] ( $this, $moduleName );
648664 $msg .= self::makeHelpMsgHeader( $module, 'action' );
649665 $msg2 = $module->makeHelpMsg();
650 - if ( $msg2 !== false )
 666+ if ( $msg2 !== false ) {
651667 $msg .= $msg2;
 668+ }
652669 $msg .= "\n";
653670 }
654671
655672 $msg .= "\n$astriks Permissions $astriks\n\n";
656 - foreach ( self :: $mRights as $right => $rightMsg ) {
 673+ foreach ( self::$mRights as $right => $rightMsg ) {
657674 $groups = User::getGroupsWithPermission( $right );
658675 $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) .
659 - "\nGranted to:\n " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n";
 676+ "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n";
660677
661678 }
662679
@@ -664,8 +681,9 @@
665682 $module = $this->createPrinterByName( $formatName );
666683 $msg .= self::makeHelpMsgHeader( $module, 'format' );
667684 $msg2 = $module->makeHelpMsg();
668 - if ( $msg2 !== false )
 685+ if ( $msg2 !== false ) {
669686 $msg .= $msg2;
 687+ }
670688 $msg .= "\n";
671689 }
672690
@@ -677,8 +695,9 @@
678696
679697 public static function makeHelpMsgHeader( $module, $paramName ) {
680698 $modulePrefix = $module->getModulePrefix();
681 - if ( strval( $modulePrefix ) !== '' )
 699+ if ( strval( $modulePrefix ) !== '' ) {
682700 $modulePrefix = "($modulePrefix) ";
 701+ }
683702
684703 return "* $paramName={$module->getModuleName()} $modulePrefix*";
685704 }
@@ -692,7 +711,7 @@
693712 * OBSOLETE, use canApiHighLimits() instead
694713 */
695714 public function isBot() {
696 - if ( !isset ( $this->mIsBot ) ) {
 715+ if ( !isset( $this->mIsBot ) ) {
697716 global $wgUser;
698717 $this->mIsBot = $wgUser->isAllowed( 'bot' );
699718 }
@@ -705,7 +724,7 @@
706725 * OBSOLETE, use canApiHighLimits() instead
707726 */
708727 public function isSysop() {
709 - if ( !isset ( $this->mIsSysop ) ) {
 728+ if ( !isset( $this->mIsSysop ) ) {
710729 global $wgUser;
711730 $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
712731 }
@@ -742,9 +761,9 @@
743762 $vers = array ();
744763 $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
745764 $vers[] = __CLASS__ . ': $Id$';
746 - $vers[] = ApiBase :: getBaseVersion();
747 - $vers[] = ApiFormatBase :: getBaseVersion();
748 - $vers[] = ApiQueryBase :: getBaseVersion();
 765+ $vers[] = ApiBase::getBaseVersion();
 766+ $vers[] = ApiFormatBase::getBaseVersion();
 767+ $vers[] = ApiQueryBase::getBaseVersion();
749768 return $vers;
750769 }
751770
@@ -753,7 +772,6 @@
754773 * classes who wish to add their own modules to their lexicon or override the
755774 * behavior of inherent ones.
756775 *
757 - * @access protected
758776 * @param $mdlName String The identifier for this module.
759777 * @param $mdlClass String The class where this module is implemented.
760778 */
@@ -765,7 +783,6 @@
766784 * Add or overwrite an output format for this ApiMain. Intended for use by extending
767785 * classes who wish to add to or modify current formatters.
768786 *
769 - * @access protected
770787 * @param $fmtName The identifier for this format.
771788 * @param $fmtClass The class implementing this format.
772789 */
@@ -793,22 +810,26 @@
794811 private $mExtraData;
795812
796813 public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
797 - parent :: __construct( $message, $code );
 814+ parent::__construct( $message, $code );
798815 $this->mCodestr = $codestr;
799816 $this->mExtraData = $extradata;
800817 }
 818+
801819 public function getCodeString() {
802820 return $this->mCodestr;
803821 }
 822+
804823 public function getMessageArray() {
805 - $result = array (
806 - 'code' => $this->mCodestr,
807 - 'info' => $this->getMessage()
 824+ $result = array(
 825+ 'code' => $this->mCodestr,
 826+ 'info' => $this->getMessage()
808827 );
809 - if ( is_array( $this->mExtraData ) )
 828+ if ( is_array( $this->mExtraData ) ) {
810829 $result = array_merge( $result, $this->mExtraData );
 830+ }
811831 return $result;
812832 }
 833+
813834 public function __toString() {
814835 return "{$this->getCodeString()}: {$this->getMessage()}";
815836 }
Index: trunk/phase3/includes/api/ApiOpenSearch.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Oct 13, 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 /**
@@ -34,7 +34,7 @@
3535 class ApiOpenSearch extends ApiBase {
3636
3737 public function __construct( $main, $action ) {
38 - parent :: __construct( $main, $action );
 38+ parent::__construct( $main, $action );
3939 }
4040
4141 public function getCustomPrinter() {
@@ -50,9 +50,9 @@
5151 $suggest = $params['suggest'];
5252
5353 // MWSuggest or similar hit
54 - if ( $suggest && !$wgEnableOpenSearchSuggest )
 54+ if ( $suggest && !$wgEnableOpenSearchSuggest ) {
5555 $srchres = array();
56 - else {
 56+ } else {
5757 // Open search results may be stored for a very long
5858 // time
5959 $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
@@ -68,26 +68,26 @@
6969 }
7070
7171 public function getAllowedParams() {
72 - return array (
 72+ return array(
7373 'search' => null,
7474 'limit' => array(
75 - ApiBase :: PARAM_DFLT => 10,
76 - ApiBase :: PARAM_TYPE => 'limit',
77 - ApiBase :: PARAM_MIN => 1,
78 - ApiBase :: PARAM_MAX => 100,
79 - ApiBase :: PARAM_MAX2 => 100
 75+ ApiBase::PARAM_DFLT => 10,
 76+ ApiBase::PARAM_TYPE => 'limit',
 77+ ApiBase::PARAM_MIN => 1,
 78+ ApiBase::PARAM_MAX => 100,
 79+ ApiBase::PARAM_MAX2 => 100
8080 ),
8181 'namespace' => array(
82 - ApiBase :: PARAM_DFLT => NS_MAIN,
83 - ApiBase :: PARAM_TYPE => 'namespace',
84 - ApiBase :: PARAM_ISMULTI => true
 82+ ApiBase::PARAM_DFLT => NS_MAIN,
 83+ ApiBase::PARAM_TYPE => 'namespace',
 84+ ApiBase::PARAM_ISMULTI => true
8585 ),
8686 'suggest' => false,
8787 );
8888 }
8989
9090 public function getParamDescription() {
91 - return array (
 91+ return array(
9292 'search' => 'Search string',
9393 'limit' => 'Maximum amount of results to return',
9494 'namespace' => 'Namespaces to search',
@@ -100,7 +100,7 @@
101101 }
102102
103103 protected function getExamples() {
104 - return array (
 104+ return array(
105105 'api.php?action=opensearch&search=Te'
106106 );
107107 }
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 24, 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 /**
@@ -59,26 +59,27 @@
6060 * @param $resolveRedirects bool Whether redirects should be resolved
6161 */
6262 public function __construct( $query, $resolveRedirects = false ) {
63 - parent :: __construct( $query, 'query' );
 63+ parent::__construct( $query, 'query' );
6464
65 - $this->mAllPages = array ();
 65+ $this->mAllPages = array();
6666 $this->mTitles = array();
67 - $this->mGoodTitles = array ();
68 - $this->mMissingTitles = array ();
69 - $this->mInvalidTitles = array ();
70 - $this->mMissingPageIDs = array ();
71 - $this->mRedirectTitles = array ();
72 - $this->mNormalizedTitles = array ();
73 - $this->mInterwikiTitles = array ();
 67+ $this->mGoodTitles = array();
 68+ $this->mMissingTitles = array();
 69+ $this->mInvalidTitles = array();
 70+ $this->mMissingPageIDs = array();
 71+ $this->mRedirectTitles = array();
 72+ $this->mNormalizedTitles = array();
 73+ $this->mInterwikiTitles = array();
7474 $this->mGoodRevIDs = array();
7575 $this->mMissingRevIDs = array();
7676
77 - $this->mRequestedPageFields = array ();
 77+ $this->mRequestedPageFields = array();
7878 $this->mResolveRedirects = $resolveRedirects;
79 - if ( $resolveRedirects )
 79+ if ( $resolveRedirects ) {
8080 $this->mPendingRedirectIDs = array();
 81+ }
8182
82 - $this->mFakePageId = - 1;
 83+ $this->mFakePageId = -1;
8384 }
8485
8586 /**
@@ -117,14 +118,15 @@
118119 public function getPageTableFields() {
119120 // Ensure we get minimum required fields
120121 // DON'T change this order
121 - $pageFlds = array (
 122+ $pageFlds = array(
122123 'page_namespace' => null,
123124 'page_title' => null,
124125 'page_id' => null,
125126 );
126127
127 - if ( $this->mResolveRedirects )
 128+ if ( $this->mResolveRedirects ) {
128129 $pageFlds['page_is_redirect'] = null;
 130+ }
129131
130132 // only store non-default fields
131133 $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
@@ -261,34 +263,38 @@
262264
263265 // Only one of the titles/pageids/revids is allowed at the same time
264266 $dataSource = null;
265 - if ( isset ( $params['titles'] ) )
 267+ if ( isset( $params['titles'] ) ) {
266268 $dataSource = 'titles';
267 - if ( isset ( $params['pageids'] ) ) {
268 - if ( isset ( $dataSource ) )
 269+ }
 270+ if ( isset( $params['pageids'] ) ) {
 271+ if ( isset( $dataSource ) ) {
269272 $this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
 273+ }
270274 $dataSource = 'pageids';
271275 }
272 - if ( isset ( $params['revids'] ) ) {
273 - if ( isset ( $dataSource ) )
 276+ if ( isset( $params['revids'] ) ) {
 277+ if ( isset( $dataSource ) ) {
274278 $this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
 279+ }
275280 $dataSource = 'revids';
276281 }
277282
278283 switch ( $dataSource ) {
279 - case 'titles' :
 284+ case 'titles':
280285 $this->initFromTitles( $params['titles'] );
281286 break;
282 - case 'pageids' :
 287+ case 'pageids':
283288 $this->initFromPageIds( $params['pageids'] );
284289 break;
285 - case 'revids' :
286 - if ( $this->mResolveRedirects )
 290+ case 'revids':
 291+ if ( $this->mResolveRedirects ) {
287292 $this->setWarning( 'Redirect resolution cannot be used together with the revids= parameter. ' .
288293 'Any redirects the revids= point to have not been resolved.' );
 294+ }
289295 $this->mResolveRedirects = false;
290296 $this->initFromRevIDs( $params['revids'] );
291297 break;
292 - default :
 298+ default:
293299 // Do nothing - some queries do not need any of the data sources.
294300 break;
295301 }
@@ -341,9 +347,8 @@
342348 * @param $row Result row
343349 */
344350 public function processDbRow( $row ) {
345 -
346351 // Store Title object in various data structures
347 - $title = Title :: makeTitle( $row->page_namespace, $row->page_title );
 352+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
348353
349354 $pageId = intval( $row->page_id );
350355 $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
@@ -355,8 +360,9 @@
356361 $this->mGoodTitles[$pageId] = $title;
357362 }
358363
359 - foreach ( $this->mRequestedPageFields as $fieldName => & $fieldValues )
 364+ foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
360365 $fieldValues[$pageId] = $row-> $fieldName;
 366+ }
361367 }
362368
363369 /**
@@ -385,11 +391,11 @@
386392 * @param $titles array of Title objects or strings
387393 */
388394 private function initFromTitles( $titles ) {
389 -
390395 // Get validated and normalized title objects
391396 $linkBatch = $this->processTitlesArray( $titles );
392 - if ( $linkBatch->isEmpty() )
 397+ if ( $linkBatch->isEmpty() ) {
393398 return;
 399+ }
394400
395401 $db = $this->getDB();
396402 $set = $linkBatch->constructSet( 'page', $db );
@@ -401,7 +407,7 @@
402408 $this->profileDBOut();
403409
404410 // Hack: get the ns:titles stored in array(ns => array(titles)) format
405 - $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
 411+ $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
406412
407413 // Resolve any found redirects
408414 $this->resolvePendingRedirects();
@@ -412,11 +418,12 @@
413419 * @param $pageids array of page IDs
414420 */
415421 private function initFromPageIds( $pageids ) {
416 - if ( !count( $pageids ) )
 422+ if ( !count( $pageids ) ) {
417423 return;
 424+ }
418425
419426 $pageids = array_map( 'intval', $pageids ); // paranoia
420 - $set = array (
 427+ $set = array(
421428 'page_id' => $pageids
422429 );
423430 $db = $this->getDB();
@@ -446,19 +453,20 @@
447454 * If false, treat it as an array of [pageIDs]
448455 */
449456 private function initFromQueryResult( $db, $res, &$remaining = null, $processTitles = null ) {
450 - if ( !is_null( $remaining ) && is_null( $processTitles ) )
451 - ApiBase :: dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
 457+ if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
 458+ ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
 459+ }
452460
453461 while ( $row = $db->fetchObject( $res ) ) {
454 -
455462 $pageId = intval( $row->page_id );
456463
457464 // Remove found page from the list of remaining items
458465 if ( isset( $remaining ) ) {
459 - if ( $processTitles )
460 - unset ( $remaining[$row->page_namespace][$row->page_title] );
461 - else
462 - unset ( $remaining[$pageId] );
 466+ if ( $processTitles ) {
 467+ unset( $remaining[$row->page_namespace][$row->page_title] );
 468+ } else {
 469+ unset( $remaining[$pageId] );
 470+ }
463471 }
464472
465473 // Store any extra fields requested by modules
@@ -472,21 +480,20 @@
473481 // The remaining titles in $remaining are non-existent pages
474482 foreach ( $remaining as $ns => $dbkeys ) {
475483 foreach ( $dbkeys as $dbkey => $unused ) {
476 - $title = Title :: makeTitle( $ns, $dbkey );
 484+ $title = Title::makeTitle( $ns, $dbkey );
477485 $this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
478486 $this->mMissingTitles[$this->mFakePageId] = $title;
479487 $this->mFakePageId--;
480488 $this->mTitles[] = $title;
481489 }
482490 }
483 - }
484 - else
485 - {
 491+ } else {
486492 // The remaining pageids do not exist
487 - if ( !$this->mMissingPageIDs )
 493+ if ( !$this->mMissingPageIDs ) {
488494 $this->mMissingPageIDs = array_keys( $remaining );
489 - else
 495+ } else {
490496 $this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
 497+ }
491498 }
492499 }
493500 }
@@ -497,9 +504,9 @@
498505 * @param $revids array of revision IDs
499506 */
500507 private function initFromRevIDs( $revids ) {
501 -
502 - if ( !count( $revids ) )
 508+ if ( !count( $revids ) ) {
503509 return;
 510+ }
504511
505512 $revids = array_map( 'intval', $revids ); // paranoia
506513 $db = $this->getDB();
@@ -535,7 +542,6 @@
536543 * have been resolved.
537544 */
538545 private function resolvePendingRedirects() {
539 -
540546 if ( $this->mResolveRedirects ) {
541547 $db = $this->getDB();
542548 $pageFlds = $this->getPageTableFields();
@@ -543,17 +549,18 @@
544550 // Repeat until all redirects have been resolved
545551 // The infinite loop is prevented by keeping all known pages in $this->mAllPages
546552 while ( $this->mPendingRedirectIDs ) {
547 -
548553 // Resolve redirects by querying the pagelinks table, and repeat the process
549554 // Create a new linkBatch object for the next pass
550555 $linkBatch = $this->getRedirectTargets();
551556
552 - if ( $linkBatch->isEmpty() )
 557+ if ( $linkBatch->isEmpty() ) {
553558 break;
 559+ }
554560
555561 $set = $linkBatch->constructSet( 'page', $db );
556 - if ( $set === false )
 562+ if ( $set === false ) {
557563 break;
 564+ }
558565
559566 // Get pageIDs data from the `page` table
560567 $this->profileDBIn();
@@ -578,7 +585,9 @@
579586 $db = $this->getDB();
580587
581588 $this->profileDBIn();
582 - $res = $db->select( 'redirect', array(
 589+ $res = $db->select(
 590+ 'redirect',
 591+ array(
583592 'rd_from',
584593 'rd_namespace',
585594 'rd_title'
@@ -587,28 +596,27 @@
588597 );
589598 $this->profileDBOut();
590599
591 - while ( $row = $db->fetchObject( $res ) )
592 - {
 600+ while ( $row = $db->fetchObject( $res ) ) {
593601 $rdfrom = intval( $row->rd_from );
594602 $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
595603 $to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText();
596604 unset( $this->mPendingRedirectIDs[$rdfrom] );
597 - if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) )
 605+ if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
598606 $lb->add( $row->rd_namespace, $row->rd_title );
 607+ }
599608 $this->mRedirectTitles[$from] = $to;
600609 }
601610 $db->freeResult( $res );
602 - if ( $this->mPendingRedirectIDs )
603 - {
 611+ if ( $this->mPendingRedirectIDs ) {
604612 // We found pages that aren't in the redirect table
605613 // Add them
606 - foreach ( $this->mPendingRedirectIDs as $id => $title )
607 - {
 614+ foreach ( $this->mPendingRedirectIDs as $id => $title ) {
608615 $article = new Article( $title );
609616 $rt = $article->insertRedirect();
610 - if ( !$rt )
 617+ if ( !$rt ) {
611618 // What the hell. Let's just ignore this
612619 continue;
 620+ }
613621 $lb->addObj( $rt );
614622 $this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText();
615623 unset( $this->mPendingRedirectIDs[$id] );
@@ -627,14 +635,11 @@
628636 * @return LinkBatch
629637 */
630638 private function processTitlesArray( $titles ) {
631 -
632639 $linkBatch = new LinkBatch();
633640
634641 foreach ( $titles as $title ) {
635 -
636 - $titleObj = is_string( $title ) ? Title :: newFromText( $title ) : $title;
637 - if ( !$titleObj )
638 - {
 642+ $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title;
 643+ if ( !$titleObj ) {
639644 // Handle invalid titles gracefully
640645 $this->mAllpages[0][$title] = $this->mFakePageId;
641646 $this->mInvalidTitles[$this->mFakePageId] = $title;
@@ -646,12 +651,12 @@
647652 // This title is an interwiki link.
648653 $this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw;
649654 } else {
650 -
651655 // Validation
652 - if ( $titleObj->getNamespace() < 0 )
653 - $this->setWarning( "No support for special pages has been implemented" );
654 - else
 656+ if ( $titleObj->getNamespace() < 0 ) {
 657+ $this->setWarning( 'No support for special pages has been implemented' );
 658+ } else {
655659 $linkBatch->addObj( $titleObj );
 660+ }
656661 }
657662
658663 // Make sure we remember the original title that was
@@ -668,23 +673,23 @@
669674 }
670675
671676 protected function getAllowedParams() {
672 - return array (
673 - 'titles' => array (
674 - ApiBase :: PARAM_ISMULTI => true
 677+ return array(
 678+ 'titles' => array(
 679+ ApiBase::PARAM_ISMULTI => true
675680 ),
676 - 'pageids' => array (
677 - ApiBase :: PARAM_TYPE => 'integer',
678 - ApiBase :: PARAM_ISMULTI => true
 681+ 'pageids' => array(
 682+ ApiBase::PARAM_TYPE => 'integer',
 683+ ApiBase::PARAM_ISMULTI => true
679684 ),
680 - 'revids' => array (
681 - ApiBase :: PARAM_TYPE => 'integer',
682 - ApiBase :: PARAM_ISMULTI => true
 685+ 'revids' => array(
 686+ ApiBase::PARAM_TYPE => 'integer',
 687+ ApiBase::PARAM_ISMULTI => true
683688 )
684689 );
685690 }
686691
687692 protected function getParamDescription() {
688 - return array (
 693+ return array(
689694 'titles' => 'A list of titles to work on',
690695 'pageids' => 'A list of page IDs to work on',
691696 'revids' => 'A list of revision IDs to work on'
Index: trunk/phase3/includes/api/ApiHelp.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 6, 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
@@ -55,7 +55,7 @@
5656 }
5757
5858 public function getDescription() {
59 - return array (
 59+ return array(
6060 'Display this help screen.'
6161 );
6262 }
Index: trunk/phase3/includes/api/ApiPatrol.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Sep 2, 2008
66 *
77 * API for MediaWiki 1.14+
88 *
9 - * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
 9+ * Copyright © 2008 Soxred93 soxred93@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
@@ -34,7 +34,7 @@
3535 class ApiPatrol extends ApiBase {
3636
3737 public function __construct( $main, $action ) {
38 - parent :: __construct( $main, $action );
 38+ parent::__construct( $main, $action );
3939 }
4040
4141 /**
@@ -42,18 +42,21 @@
4343 */
4444 public function execute() {
4545 $params = $this->extractRequestParams();
46 -
47 - if ( !isset( $params['rcid'] ) )
 46+
 47+ if ( !isset( $params['rcid'] ) ) {
4848 $this->dieUsageMsg( array( 'missingparam', 'rcid' ) );
 49+ }
4950
5051 $rc = RecentChange::newFromID( $params['rcid'] );
51 - if ( !$rc instanceof RecentChange )
 52+ if ( !$rc instanceof RecentChange ) {
5253 $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
 54+ }
5355 $retval = RecentChange::markPatrolled( $params['rcid'] );
54 -
55 - if ( $retval )
 56+
 57+ if ( $retval ) {
5658 $this->dieUsageMsg( reset( $retval ) );
57 -
 59+ }
 60+
5861 $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
5962 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
6063 $this->getResult()->addValue( null, $this->getModuleName(), $result );
@@ -64,34 +67,34 @@
6568 }
6669
6770 public function getAllowedParams() {
68 - return array (
 71+ return array(
6972 'token' => null,
7073 'rcid' => array(
71 - ApiBase :: PARAM_TYPE => 'integer'
 74+ ApiBase::PARAM_TYPE => 'integer'
7275 ),
7376 );
7477 }
7578
7679 public function getParamDescription() {
77 - return array (
 80+ return array(
7881 'token' => 'Patrol token obtained from list=recentchanges',
7982 'rcid' => 'Recentchanges ID to patrol',
8083 );
8184 }
8285
8386 public function getDescription() {
84 - return array (
 87+ return array(
8588 'Patrol a page or revision. '
8689 );
8790 }
88 -
89 - public function getPossibleErrors() {
 91+
 92+ public function getPossibleErrors() {
9093 return array_merge( parent::getPossibleErrors(), array(
9194 array( 'missingparam', 'rcid' ),
9295 array( 'nosuchrcid', 'rcid' ),
93 - ) );
 96+ ) );
9497 }
95 -
 98+
9699 public function getTokenSalt() {
97100 return '';
98101 }
Index: trunk/phase3/includes/api/ApiParamInfo.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Dec 01, 2007
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 ( "ApiBase.php" );
 29+ require_once( "ApiBase.php" );
3030 }
3131
3232 /**
@@ -34,7 +34,7 @@
3535 class ApiParamInfo extends ApiBase {
3636
3737 public function __construct( $main, $action ) {
38 - parent :: __construct( $main, $action );
 38+ parent::__construct( $main, $action );
3939 }
4040
4141 public function execute() {
@@ -43,14 +43,11 @@
4444 $result = $this->getResult();
4545 $queryObj = new ApiQuery( $this->getMain(), 'query' );
4646 $r = array();
47 - if ( is_array( $params['modules'] ) )
48 - {
 47+ if ( is_array( $params['modules'] ) ) {
4948 $modArr = $this->getMain()->getModules();
5049 $r['modules'] = array();
51 - foreach ( $params['modules'] as $m )
52 - {
53 - if ( !isset( $modArr[$m] ) )
54 - {
 50+ foreach ( $params['modules'] as $m ) {
 51+ if ( !isset( $modArr[$m] ) ) {
5552 $r['modules'][] = array( 'name' => $m, 'missing' => '' );
5653 continue;
5754 }
@@ -61,14 +58,11 @@
6259 }
6360 $result->setIndexedTagName( $r['modules'], 'module' );
6461 }
65 - if ( is_array( $params['querymodules'] ) )
66 - {
 62+ if ( is_array( $params['querymodules'] ) ) {
6763 $qmodArr = $queryObj->getModules();
6864 $r['querymodules'] = array();
69 - foreach ( $params['querymodules'] as $qm )
70 - {
71 - if ( !isset( $qmodArr[$qm] ) )
72 - {
 65+ foreach ( $params['querymodules'] as $qm ) {
 66+ if ( !isset( $qmodArr[$qm] ) ) {
7367 $r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
7468 continue;
7569 }
@@ -79,60 +73,59 @@
8074 }
8175 $result->setIndexedTagName( $r['querymodules'], 'module' );
8276 }
83 - if ( $params['mainmodule'] )
 77+ if ( $params['mainmodule'] ) {
8478 $r['mainmodule'] = $this->getClassInfo( $this->getMain() );
85 - if ( $params['pagesetmodule'] )
86 - {
 79+ }
 80+ if ( $params['pagesetmodule'] ) {
8781 $pageSet = new ApiPageSet( $queryObj );
8882 $r['pagesetmodule'] = $this->getClassInfo( $pageSet );
8983 }
9084 $result->addValue( null, $this->getModuleName(), $r );
9185 }
9286
93 - function getClassInfo( $obj )
94 - {
 87+ function getClassInfo( $obj ) {
9588 $result = $this->getResult();
9689 $retval['classname'] = get_class( $obj );
9790 $retval['description'] = implode( "\n", (array)$obj->getDescription() );
9891 $retval['version'] = implode( "\n", (array)$obj->getVersion() );
9992 $retval['prefix'] = $obj->getModulePrefix();
10093
101 - if ( $obj->isReadMode() )
 94+ if ( $obj->isReadMode() ) {
10295 $retval['readrights'] = '';
103 - if ( $obj->isWriteMode() )
 96+ }
 97+ if ( $obj->isWriteMode() ) {
10498 $retval['writerights'] = '';
105 - if ( $obj->mustBePosted() )
 99+ }
 100+ if ( $obj->mustBePosted() ) {
106101 $retval['mustbeposted'] = '';
107 - if ( $obj instanceof ApiQueryGeneratorBase )
 102+ }
 103+ if ( $obj instanceof ApiQueryGeneratorBase ) {
108104 $retval['generator'] = '';
 105+ }
109106
110107 $allowedParams = $obj->getFinalParams();
111 - if ( !is_array( $allowedParams ) )
 108+ if ( !is_array( $allowedParams ) ) {
112109 return $retval;
113 -
 110+ }
 111+
114112 $retval['parameters'] = array();
115113 $paramDesc = $obj->getFinalParamDescription();
116 - foreach ( $allowedParams as $n => $p )
117 - {
 114+ foreach ( $allowedParams as $n => $p ) {
118115 $a = array( 'name' => $n );
119 - if ( isset( $paramDesc[$n] ) )
 116+ if ( isset( $paramDesc[$n] ) ) {
120117 $a['description'] = implode( "\n", (array)$paramDesc[$n] );
121 - if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] )
 118+ }
 119+ if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
122120 $a['deprecated'] = '';
123 - if ( !is_array( $p ) )
124 - {
125 - if ( is_bool( $p ) )
126 - {
 121+ }
 122+ if ( !is_array( $p ) ) {
 123+ if ( is_bool( $p ) ) {
127124 $a['type'] = 'bool';
128125 $a['default'] = ( $p ? 'true' : 'false' );
129 - }
130 - else if ( is_string( $p ) || is_null( $p ) )
131 - {
 126+ } elseif ( is_string( $p ) || is_null( $p ) ) {
132127 $a['type'] = 'string';
133128 $a['default'] = strval( $p );
134 - }
135 - else if ( is_int( $p ) )
136 - {
 129+ } elseif ( is_int( $p ) ) {
137130 $a['type'] = 'integer';
138131 $a['default'] = intval( $p );
139132 }
@@ -140,42 +133,48 @@
141134 continue;
142135 }
143136
144 - if ( isset( $p[ApiBase::PARAM_DFLT] ) )
 137+ if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
145138 $a['default'] = $p[ApiBase::PARAM_DFLT];
146 - if ( isset( $p[ApiBase::PARAM_ISMULTI] ) )
147 - if ( $p[ApiBase::PARAM_ISMULTI] )
148 - {
 139+ }
 140+ if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) {
 141+ if ( $p[ApiBase::PARAM_ISMULTI] ) {
149142 $a['multi'] = '';
150143 $a['limit'] = $this->getMain()->canApiHighLimits() ?
151144 ApiBase::LIMIT_SML2 :
152145 ApiBase::LIMIT_SML1;
153146 }
 147+ }
154148
155 - if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) )
156 - if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] )
 149+ if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
 150+ if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
157151 $a['allowsduplicates'] = '';
 152+ }
 153+ }
158154
159 - if ( isset( $p[ApiBase::PARAM_TYPE] ) )
160 - {
 155+ if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
161156 $a['type'] = $p[ApiBase::PARAM_TYPE];
162 - if ( is_array( $a['type'] ) )
 157+ if ( is_array( $a['type'] ) ) {
163158 $result->setIndexedTagName( $a['type'], 't' );
 159+ }
164160 }
165 - if ( isset( $p[ApiBase::PARAM_MAX] ) )
 161+ if ( isset( $p[ApiBase::PARAM_MAX] ) ) {
166162 $a['max'] = $p[ApiBase::PARAM_MAX];
167 - if ( isset( $p[ApiBase::PARAM_MAX2] ) )
 163+ }
 164+ if ( isset( $p[ApiBase::PARAM_MAX2] ) ) {
168165 $a['highmax'] = $p[ApiBase::PARAM_MAX2];
169 - if ( isset( $p[ApiBase::PARAM_MIN] ) )
 166+ }
 167+ if ( isset( $p[ApiBase::PARAM_MIN] ) ) {
170168 $a['min'] = $p[ApiBase::PARAM_MIN];
 169+ }
171170 $retval['parameters'][] = $a;
172171 }
173172 $result->setIndexedTagName( $retval['parameters'], 'param' );
174 -
 173+
175174 // Errors
176175 $retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
177 -
 176+
178177 $result->setIndexedTagName( $retval['errors'], 'error' );
179 -
 178+
180179 return $retval;
181180 }
182181
@@ -184,12 +183,12 @@
185184 }
186185
187186 public function getAllowedParams() {
188 - return array (
 187+ return array(
189188 'modules' => array(
190 - ApiBase :: PARAM_ISMULTI => true
 189+ ApiBase::PARAM_ISMULTI => true
191190 ),
192191 'querymodules' => array(
193 - ApiBase :: PARAM_ISMULTI => true
 192+ ApiBase::PARAM_ISMULTI => true
194193 ),
195194 'mainmodule' => false,
196195 'pagesetmodule' => false,
@@ -197,7 +196,7 @@
198197 }
199198
200199 public function getParamDescription() {
201 - return array (
 200+ return array(
202201 'modules' => 'List of module names (value of the action= parameter)',
203202 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
204203 'mainmodule' => 'Get information about the main (top-level) module as well',
@@ -210,7 +209,7 @@
211210 }
212211
213212 protected function getExamples() {
214 - return array (
 213+ return array(
215214 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
216215 );
217216 }

Status & tagging log