r72375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72374‎ | r72375 | r72376 >
Date:13:48, 4 September 2010
Author:siebrand
Status:ok
Tags:
Comment:
More whitespace updates for files touched in r72342:
* stylize.php run
* code formatting updates
* updated a few comments
* added braces where not used
Modified paths:
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/installer/CliInstaller.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/Selenium.php (modified) (history)
  • /trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -76,6 +76,7 @@
7777 break;
7878 }
7979 }
 80+
8081 $this->term = $this->color
8182 ? new AnsiTermColorer()
8283 : new DummyTermColorer();
@@ -163,6 +164,7 @@
164165 mt_srand( ++$this->fuzzSeed );
165166 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
166167 $input = '';
 168+
167169 while ( strlen( $input ) < $totalLength ) {
168170 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
169171 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
@@ -172,6 +174,7 @@
173175
174176 $this->setupGlobals();
175177 $parser = $this->getParser();
 178+
176179 // Run the test
177180 try {
178181 $parser->parse( $input, $title, $opts );
@@ -189,6 +192,7 @@
190193 } else {
191194 $numSuccess++;
192195 }
 196+
193197 $numTotal++;
194198 $this->teardownGlobals();
195199 $parser->__destruct();
@@ -199,6 +203,7 @@
200204 if ( $usage > 90 ) {
201205 echo "Out of memory:\n";
202206 $memStats = $this->getMemoryBreakdown();
 207+
203208 foreach ( $memStats as $name => $usage ) {
204209 echo "$name: $usage\n";
205210 }
@@ -213,13 +218,16 @@
214219 */
215220 function getFuzzInput( $filenames ) {
216221 $dict = '';
 222+
217223 foreach ( $filenames as $filename ) {
218224 $contents = file_get_contents( $filename );
219225 preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
 226+
220227 foreach ( $matches[1] as $match ) {
221228 $dict .= $match . "\n";
222229 }
223230 }
 231+
224232 return $dict;
225233 }
226234
@@ -228,25 +236,33 @@
229237 */
230238 function getMemoryBreakdown() {
231239 $memStats = array();
 240+
232241 foreach ( $GLOBALS as $name => $value ) {
233242 $memStats['$' . $name] = strlen( serialize( $value ) );
234243 }
 244+
235245 $classes = get_declared_classes();
 246+
236247 foreach ( $classes as $class ) {
237248 $rc = new ReflectionClass( $class );
238249 $props = $rc->getStaticProperties();
239250 $memStats[$class] = strlen( serialize( $props ) );
240251 $methods = $rc->getMethods();
 252+
241253 foreach ( $methods as $method ) {
242254 $memStats[$class] += strlen( serialize( $method->getStaticVariables() ) );
243255 }
244256 }
 257+
245258 $functions = get_defined_functions();
 259+
246260 foreach ( $functions['user'] as $function ) {
247261 $rf = new ReflectionFunction( $function );
248262 $memStats["$function()"] = strlen( serialize( $rf->getStaticVariables() ) );
249263 }
 264+
250265 asort( $memStats );
 266+
251267 return $memStats;
252268 }
253269
@@ -270,27 +286,33 @@
271287 $this->recorder->start();
272288 $this->setupDatabase();
273289 $ok = true;
 290+
274291 foreach ( $filenames as $filename ) {
275292 $tests = new TestFileIterator( $filename, $this );
276293 $ok = $this->runTests( $tests ) && $ok;
277294 }
 295+
278296 $this->teardownDatabase();
279297 $this->recorder->report();
280298 $this->recorder->end();
 299+
281300 return $ok;
282301 }
283302
284303 function runTests( $tests ) {
285304 $ok = true;
 305+
286306 foreach ( $tests as $i => $t ) {
287307 $result =
288308 $this->runTest( $t['test'], $t['input'], $t['result'], $t['options'], $t['config'] );
289309 $ok = $ok && $result;
290310 $this->recorder->record( $t['test'], $result );
291311 }
 312+
292313 if ( $this->showProgress ) {
293314 print "\n";
294315 }
 316+
295317 return $ok;
296318 }
297319
@@ -299,16 +321,21 @@
300322 */
301323 function getParser( $preprocessor = null ) {
302324 global $wgParserConf;
 325+
303326 $class = $wgParserConf['class'];
304327 $parser = new $class( array( 'preprocessorClass' => $preprocessor ) + $wgParserConf );
 328+
305329 foreach ( $this->hooks as $tag => $callback ) {
306330 $parser->setHook( $tag, $callback );
307331 }
 332+
308333 foreach ( $this->functionHooks as $tag => $bits ) {
309334 list( $callback, $flags ) = $bits;
310335 $parser->setFunctionHook( $tag, $callback, $flags );
311336 }
 337+
312338 wfRunHooks( 'ParserTestParser', array( &$parser ) );
 339+
313340 return $parser;
314341 }
315342
@@ -369,15 +396,21 @@
370397 $out = $output->getText();
371398
372399 if ( isset( $opts['showtitle'] ) ) {
373 - if ( $output->getTitleText() ) $title = $output->getTitleText();
 400+ if ( $output->getTitleText() ) {
 401+ $title = $output->getTitleText();
 402+ }
 403+
374404 $out = "$title\n$out";
375405 }
 406+
376407 if ( isset( $opts['ill'] ) ) {
377408 $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
378409 } elseif ( isset( $opts['cat'] ) ) {
379410 global $wgOut;
 411+
380412 $wgOut->addCategoryLinks( $output->getCategories() );
381413 $cats = $wgOut->getCategoryLinks();
 414+
382415 if ( isset( $cats['normal'] ) ) {
383416 $out = $this->tidy( implode( ' ', $cats['normal'] ) );
384417 } else {
@@ -398,7 +431,6 @@
399432 }
400433 }
401434
402 -
403435 /**
404436 * Use a regex to find out the value of an option
405437 * @param $key String: name of option val to retrieve
@@ -407,6 +439,7 @@
408440 */
409441 private static function getOptionValue( $key, $opts, $default ) {
410442 $key = strtolower( $key );
 443+
411444 if ( isset( $opts[$key] ) ) {
412445 return $opts[$key];
413446 } else {
@@ -474,6 +507,7 @@
475508 if ( substr( $opt, 0, 1 ) == '"' ) {
476509 return substr( $opt, 1, -1 );
477510 }
 511+
478512 if ( substr( $opt, 0, 2 ) == '[[' ) {
479513 return substr( $opt, 2, -2 );
480514 }
@@ -565,12 +599,15 @@
566600 }
567601
568602 $this->savedGlobals = array();
 603+
569604 foreach ( $settings as $var => $val ) {
570605 if ( array_key_exists( $var, $GLOBALS ) ) {
571606 $this->savedGlobals[$var] = $GLOBALS[$var];
572607 }
 608+
573609 $GLOBALS[$var] = $val;
574610 }
 611+
575612 $langObj = Language::factory( $lang );
576613 $GLOBALS['wgLang'] = $langObj;
577614 $GLOBALS['wgContLang'] = $langObj;
@@ -578,6 +615,7 @@
579616 $GLOBALS['wgOut'] = new OutputPage;
580617
581618 global $wgHooks;
 619+
582620 $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
583621 $wgHooks['ParserTestParser'][] = 'ParserTestStaticParserHook::setup';
584622 $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
@@ -594,6 +632,7 @@
595633 */
596634 private function listTables() {
597635 global $wgDBtype;
 636+
598637 $tables = array( 'user', 'user_properties', 'page', 'page_restrictions',
599638 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
600639 'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
@@ -621,12 +660,15 @@
622661 */
623662 public function setupDatabase() {
624663 global $wgDBprefix, $wgDBtype;
 664+
625665 if ( $this->databaseSetupDone ) {
626666 return;
627667 }
 668+
628669 if ( $wgDBprefix === 'parsertest_' || ( $wgDBtype == 'oracle' && $wgDBprefix === 'pt_' ) ) {
629670 throw new MWException( 'setupDatabase should be called before setupGlobals' );
630671 }
 672+
631673 $this->databaseSetupDone = true;
632674 $this->oldTablePrefix = $wgDBprefix;
633675
@@ -663,9 +705,11 @@
664706 } elseif ( $db->tableExists( $tbl ) ) {
665707 $db->query( "DROP TABLE $newTableName" );
666708 }
 709+
667710 # Create new table
668711 $db->duplicateTableStructure( $oldTableName, $newTableName, $temporary );
669712 }
 713+
670714 if ( $wgDBtype == 'oracle' )
671715 $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
672716
@@ -737,7 +781,7 @@
738782 'media_type' => MEDIATYPE_BITMAP,
739783 'mime' => 'image/jpeg',
740784 'metadata' => serialize( array() ),
741 - 'sha1' => sha1(''),
 785+ 'sha1' => sha1( '' ),
742786 'fileExists' => true
743787 ), $db->timestamp( '20010115123500' ), $user );
744788
@@ -751,7 +795,7 @@
752796 'media_type' => MEDIATYPE_BITMAP,
753797 'mime' => 'image/jpeg',
754798 'metadata' => serialize( array() ),
755 - 'sha1' => sha1(''),
 799+ 'sha1' => sha1( '' ),
756800 'fileExists' => true
757801 ), $db->timestamp( '20010115123500' ), $user );
758802 }
@@ -775,6 +819,7 @@
776820
777821 public function teardownDatabase() {
778822 global $wgDBtype;
 823+
779824 if ( !$this->databaseSetupDone ) {
780825 return;
781826 }
@@ -782,6 +827,7 @@
783828
784829 $this->changePrefix( $this->oldTablePrefix );
785830 $this->databaseSetupDone = false;
 831+
786832 if ( $this->useTemporaryTables ) {
787833 # Don't need to do anything
788834 return;
@@ -789,12 +835,14 @@
790836
791837 $tables = $this->listTables();
792838 $db = wfGetDB( DB_MASTER );
 839+
793840 foreach ( $tables as $table ) {
794841 $sql = $wgDBtype == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
795842 $db->query( $sql );
796843 }
797 - if ($wgDBtype == 'oracle')
798 - $db->query('BEGIN FILL_WIKI_INFO; END;');
 844+
 845+ if ( $wgDBtype == 'oracle' )
 846+ $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
799847 }
800848
801849 /**
@@ -805,8 +853,10 @@
806854 */
807855 private function setupUploadDir() {
808856 global $IP;
 857+
809858 if ( $this->keepUploads ) {
810859 $dir = wfTempDir() . '/mwParser-images';
 860+
811861 if ( is_dir( $dir ) ) {
812862 return $dir;
813863 }
@@ -814,15 +864,17 @@
815865 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
816866 }
817867
818 - //wfDebug( "Creating upload directory $dir\n" );
 868+ // wfDebug( "Creating upload directory $dir\n" );
819869 if ( file_exists( $dir ) ) {
820870 wfDebug( "Already exists!\n" );
821871 return $dir;
822872 }
 873+
823874 wfMkdirParents( $dir . '/3/3a' );
824875 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
825876 wfMkdirParents( $dir . '/0/09' );
826877 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 878+
827879 return $dir;
828880 }
829881
@@ -833,6 +885,7 @@
834886 private function teardownGlobals() {
835887 RepoGroup::destroySingleton();
836888 LinkCache::singleton()->clear();
 889+
837890 foreach ( $this->savedGlobals as $var => $val ) {
838891 $GLOBALS[$var] = $val;
839892 }
@@ -924,6 +977,7 @@
925978 if ( $this->showProgress ) {
926979 print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n";
927980 }
 981+
928982 return true;
929983 }
930984
@@ -943,10 +997,13 @@
944998 # test, in case it succeeded. Show it now:
945999 $this->showTesting( $desc );
9461000 }
 1001+
9471002 print $this->term->color( '31' ) . 'FAILED!' . $this->term->reset() . "\n";
 1003+
9481004 if ( $this->showOutput ) {
9491005 print "--- Expected ---\n$result\n--- Actual ---\n$html\n";
9501006 }
 1007+
9511008 if ( $this->showDiffs ) {
9521009 print $this->quickDiff( $result, $html );
9531010 if ( !$this->wellFormed( $html ) ) {
@@ -954,6 +1011,7 @@
9551012 }
9561013 }
9571014 }
 1015+
9581016 return false;
9591017 }
9601018
@@ -1034,11 +1092,13 @@
10351093 $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637
10361094
10371095 $title = Title::newFromText( $name );
 1096+
10381097 if ( is_null( $title ) ) {
10391098 wfDie( "invalid title at line $line\n" );
10401099 }
10411100
10421101 $aid = $title->getArticleID( GAID_FOR_UPDATE );
 1102+
10431103 if ( $aid != 0 ) {
10441104 wfDie( "duplicate article '$name' at line $line\n" );
10451105 }
@@ -1059,13 +1119,16 @@
10601120 */
10611121 public function requireHook( $name ) {
10621122 global $wgParser;
 1123+
10631124 $wgParser->firstCallInit( ); // make sure hooks are loaded.
 1125+
10641126 if ( isset( $wgParser->mTagHooks[$name] ) ) {
10651127 $this->hooks[$name] = $wgParser->mTagHooks[$name];
10661128 } else {
10671129 echo " This test suite requires the '$name' hook extension, skipping.\n";
10681130 return false;
10691131 }
 1132+
10701133 return true;
10711134 }
10721135
@@ -1079,13 +1142,16 @@
10801143 */
10811144 public function requireFunctionHook( $name ) {
10821145 global $wgParser;
 1146+
10831147 $wgParser->firstCallInit( ); // make sure hooks are loaded.
 1148+
10841149 if ( isset( $wgParser->mFunctionHooks[$name] ) ) {
10851150 $this->functionHooks[$name] = $wgParser->mFunctionHooks[$name];
10861151 } else {
10871152 echo " This test suite requires the '$name' function hook extension, skipping.\n";
10881153 return false;
10891154 }
 1155+
10901156 return true;
10911157 }
10921158
@@ -1099,9 +1165,11 @@
11001166 */
11011167 private function tidy( $text ) {
11021168 global $wgUseTidy;
 1169+
11031170 if ( $wgUseTidy ) {
11041171 $text = MWTidy::tidy( $text );
11051172 }
 1173+
11061174 return $text;
11071175 }
11081176
@@ -1123,9 +1191,12 @@
11241192 $fragment = $this->extractFragment( $html, $position );
11251193 $this->mXmlError = "$err at byte $position:\n$fragment";
11261194 xml_parser_free( $parser );
 1195+
11271196 return false;
11281197 }
 1198+
11291199 xml_parser_free( $parser );
 1200+
11301201 return true;
11311202 }
11321203
@@ -1150,6 +1221,7 @@
11511222 $this->term->color( 31 ) .
11521223 '^' .
11531224 $this->term->color( 0 );
 1225+
11541226 return "$display\n$caret";
11551227 }
11561228
@@ -1171,7 +1243,9 @@
11721244 */
11731245 public function color( $color ) {
11741246 global $wgCommandLineDarkBg;
 1247+
11751248 $light = $wgCommandLineDarkBg ? "1;" : "0;";
 1249+
11761250 return "\x1b[{$light}{$color}m";
11771251 }
11781252
@@ -1230,13 +1304,16 @@
12311305 function reportPercentage( $success, $total ) {
12321306 $ratio = wfPercent( 100 * $success / $total );
12331307 print $this->term->color( 1 ) . "Passed $success of $total tests ($ratio)... ";
 1308+
12341309 if ( $success == $total ) {
12351310 print $this->term->color( 32 ) . "ALL TESTS PASSED!";
12361311 } else {
12371312 $failed = $total - $success ;
12381313 print $this->term->color( 31 ) . "$failed tests failed!";
12391314 }
 1315+
12401316 print $this->term->reset() . "\n";
 1317+
12411318 return ( $success == $total );
12421319 }
12431320 }
@@ -1253,6 +1330,7 @@
12541331 */
12551332 function __construct( $parent ) {
12561333 parent::__construct( $parent );
 1334+
12571335 $this->lb = wfGetLBFactory()->newMainLB();
12581336 // This connection will have the wiki's table prefix, not parsertest_
12591337 $this->db = $this->lb->getConnection( DB_MASTER );
@@ -1274,6 +1352,7 @@
12751353 // We'll make comparisons against the previous run later...
12761354 $this->prevRun = $this->db->selectField( 'testrun', 'MAX(tr_id)' );
12771355 }
 1356+
12781357 $this->results = array();
12791358 }
12801359
@@ -1301,6 +1380,7 @@
13021381
13031382 $res = $this->db->select( 'testitem', array( 'ti_name', 'ti_success' ),
13041383 array( 'ti_run' => $this->prevRun ), __METHOD__ );
 1384+
13051385 foreach ( $res as $row ) {
13061386 if ( !$this->parent->regex
13071387 || preg_match( "/{$this->parent->regex}/i", $row->ti_name ) )
@@ -1321,6 +1401,7 @@
13221402 } else /* if ( $prevResults[$test] == 0 )*/ {
13231403 $before = 'f';
13241404 }
 1405+
13251406 if ( !isset( $this->results[$test] ) ) {
13261407 $after = 'n';
13271408 } elseif ( $this->results[$test] == 1 ) {
@@ -1328,7 +1409,9 @@
13291410 } else /*if ( $this->results[$test] == 0 ) */ {
13301411 $after = 'f';
13311412 }
 1413+
13321414 $code = $before . $after;
 1415+
13331416 if ( isset( $table[$code] ) ) {
13341417 $breakdown[$code][$test] = $this->getTestStatusInfo( $test, $after );
13351418 }
@@ -1339,6 +1422,7 @@
13401423 if ( !empty( $breakdown[$code] ) ) {
13411424 $count = count( $breakdown[$code] );
13421425 printf( "\n%4d %s\n", $count, $label );
 1426+
13431427 foreach ( $breakdown[$code] as $differing_test_name => $statusInfo ) {
13441428 print " * $differing_test_name [$statusInfo]\n";
13451429 }
@@ -1347,6 +1431,7 @@
13481432 } else {
13491433 print "No previous test runs to compare against.\n";
13501434 }
 1435+
13511436 print "\n";
13521437 parent::report();
13531438 }
@@ -1357,7 +1442,6 @@
13581443 * which have never passed (which are more change requests than regressions).
13591444 */
13601445 private function getTestStatusInfo( $testname, $after ) {
1361 -
13621446 // If we're looking at a test that has just been removed, then say when it first appeared.
13631447 if ( $after == 'n' ) {
13641448 $changedRun = $this->db->selectField ( 'testitem',
@@ -1368,6 +1452,7 @@
13691453 array( 'tr_date', 'tr_mw_version' ),
13701454 array( 'tr_id' => $changedRun ),
13711455 __METHOD__ );
 1456+
13721457 return "First recorded appearance: "
13731458 . date( "d-M-Y H:i:s", strtotime ( $appear->tr_date ) )
13741459 . ", " . $appear->tr_mw_version;
@@ -1378,6 +1463,7 @@
13791464 $conds = array(
13801465 'ti_name' => $testname,
13811466 'ti_success' => ( $after == 'f' ? "1" : "0" ) );
 1467+
13821468 if ( $this->curRun ) {
13831469 $conds[] = "ti_run != " . $this->db->addQuotes ( $this->curRun );
13841470 }
@@ -1412,6 +1498,7 @@
14131499 } else {
14141500 $postDate = 'now';
14151501 }
 1502+
14161503 return ( $after == "f" ? "Introduced" : "Fixed" ) . " between "
14171504 . date( "d-M-Y H:i:s", strtotime ( $pre->tr_date ) ) . ", " . $pre->tr_mw_version
14181505 . " and $postDate";
@@ -1444,12 +1531,14 @@
14451532 or ! $this->db->tableExists( 'testitem' ) )
14461533 {
14471534 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
1448 - if ( $wgDBtype === 'postgres' )
 1535+ if ( $wgDBtype === 'postgres' ) {
14491536 $this->db->sourceFile( dirname( __FILE__ ) . '/testRunner.postgres.sql' );
1450 - elseif ( $wgDBtype === 'oracle' )
 1537+ } elseif ( $wgDBtype === 'oracle' ) {
14511538 $this->db->sourceFile( dirname( __FILE__ ) . '/testRunner.ora.sql' );
1452 - else
 1539+ } else {
14531540 $this->db->sourceFile( dirname( __FILE__ ) . '/testRunner.sql' );
 1541+ }
 1542+
14541543 echo "OK, resuming.\n";
14551544 }
14561545
@@ -1464,10 +1553,11 @@
14651554 'tr_uname' => php_uname()
14661555 ),
14671556 __METHOD__ );
1468 - if ( $wgDBtype === 'postgres' )
 1557+ if ( $wgDBtype === 'postgres' ) {
14691558 $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
1470 - else
 1559+ } else {
14711560 $this->curRun = $this->db->insertId();
 1561+ }
14721562 }
14731563
14741564 /**
@@ -1478,6 +1568,7 @@
14791569 */
14801570 function record( $test, $result ) {
14811571 parent::record( $test, $result );
 1572+
14821573 $this->db->insert( 'testitem',
14831574 array(
14841575 'ti_run' => $this->curRun,
@@ -1491,6 +1582,7 @@
14921583 class RemoteTestRecorder extends TestRecorder {
14931584 function start() {
14941585 parent::start();
 1586+
14951587 $this->results = array();
14961588 $this->ping( 'running' );
14971589 }
@@ -1532,6 +1624,7 @@
15331625 $revId,
15341626 $status,
15351627 );
 1628+
15361629 if ( $status == "complete" ) {
15371630 $message[] = $jsonResults;
15381631 }
@@ -1546,21 +1639,26 @@
15471640 'status' => $status,
15481641 'hmac' => $hmac,
15491642 );
 1643+
15501644 if ( $status == "complete" ) {
15511645 $postData['results'] = $jsonResults;
15521646 }
 1647+
15531648 $response = $this->post( $remote['api-url'], $postData );
15541649
15551650 if ( $response === false ) {
15561651 print "CodeReview info upload failed to reach server.\n";
15571652 exit( 1 );
15581653 }
 1654+
15591655 $responseData = FormatJson::decode( $response, true );
 1656+
15601657 if ( !is_array( $responseData ) ) {
15611658 print "CodeReview API response not recognized...\n";
15621659 wfDebug( "Unrecognized CodeReview API response: $response\n" );
15631660 exit( 1 );
15641661 }
 1662+
15651663 if ( isset( $responseData['error'] ) ) {
15661664 $code = $responseData['error']['code'];
15671665 $info = $responseData['error']['info'];
@@ -1588,13 +1686,17 @@
15891687
15901688 $this->file = $file;
15911689 $this->fh = fopen( $this->file, "rt" );
 1690+
15921691 if ( !$this->fh ) {
15931692 wfDie( "Couldn't open file '$file'\n" );
15941693 }
15951694
15961695 $this->parser = $parser;
15971696
1598 - if ( $this->parser ) $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) );
 1697+ if ( $this->parser ) {
 1698+ $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) );
 1699+ }
 1700+
15991701 $this->lineNum = $this->index = 0;
16001702 }
16011703
@@ -1606,6 +1708,7 @@
16071709 if ( fseek( $this->fh, 0 ) ) {
16081710 wfDie( "Couldn't fseek to the start of '$this->file'\n" );
16091711 }
 1712+
16101713 $this->index = -1;
16111714 $this->lineNum = 0;
16121715 $this->eof = false;
@@ -1642,68 +1745,89 @@
16431746 while ( false !== ( $line = fgets( $this->fh ) ) ) {
16441747 $this->lineNum++;
16451748 $matches = array();
 1749+
16461750 if ( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
16471751 $section = strtolower( $matches[1] );
 1752+
16481753 if ( $section == 'endarticle' ) {
16491754 if ( !isset( $data['text'] ) ) {
16501755 wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
16511756 }
 1757+
16521758 if ( !isset( $data['article'] ) ) {
16531759 wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
16541760 }
 1761+
16551762 if ( $this->parser ) {
16561763 $this->parser->addArticle( $this->parser->chomp( $data['article'] ), $this->parser->chomp( $data['text'] ),
16571764 $this->lineNum );
16581765 }
 1766+
16591767 $data = array();
16601768 $section = null;
 1769+
16611770 continue;
16621771 }
 1772+
16631773 if ( $section == 'endhooks' ) {
16641774 if ( !isset( $data['hooks'] ) ) {
16651775 wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
16661776 }
 1777+
16671778 foreach ( explode( "\n", $data['hooks'] ) as $line ) {
16681779 $line = trim( $line );
 1780+
16691781 if ( $line ) {
16701782 if ( $this->parser && !$this->parser->requireHook( $line ) ) {
16711783 return false;
16721784 }
16731785 }
16741786 }
 1787+
16751788 $data = array();
16761789 $section = null;
 1790+
16771791 continue;
16781792 }
 1793+
16791794 if ( $section == 'endfunctionhooks' ) {
16801795 if ( !isset( $data['functionhooks'] ) ) {
16811796 wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
16821797 }
 1798+
16831799 foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
16841800 $line = trim( $line );
 1801+
16851802 if ( $line ) {
16861803 if ( $this->parser && !$this->parser->requireFunctionHook( $line ) ) {
16871804 return false;
16881805 }
16891806 }
16901807 }
 1808+
16911809 $data = array();
16921810 $section = null;
 1811+
16931812 continue;
16941813 }
 1814+
16951815 if ( $section == 'end' ) {
16961816 if ( !isset( $data['test'] ) ) {
16971817 wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
16981818 }
 1819+
16991820 if ( !isset( $data['input'] ) ) {
17001821 wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
17011822 }
 1823+
17021824 if ( !isset( $data['result'] ) ) {
17031825 wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
17041826 }
 1827+
17051828 if ( !isset( $data['options'] ) ) {
17061829 $data['options'] = '';
17071830 }
 1831+
17081832 if ( !isset( $data['config'] ) )
17091833 $data['config'] = '';
17101834
@@ -1713,14 +1837,18 @@
17141838 # disabled test
17151839 $data = array();
17161840 $section = null;
 1841+
17171842 continue;
17181843 }
 1844+
17191845 global $wgUseTeX;
 1846+
17201847 if ( $this->parser &&
17211848 preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
17221849 # don't run math tests if $wgUseTeX is set to false in LocalSettings
17231850 $data = array();
17241851 $section = null;
 1852+
17251853 continue;
17261854 }
17271855
@@ -1734,19 +1862,24 @@
17351863 } else {
17361864 $this->test['test'] = $data['test'];
17371865 }
 1866+
17381867 return true;
17391868 }
 1869+
17401870 if ( isset ( $data[$section] ) ) {
17411871 wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
17421872 }
 1873+
17431874 $data[$section] = '';
 1875+
17441876 continue;
17451877 }
 1878+
17461879 if ( $section ) {
17471880 $data[$section] .= $line;
17481881 }
17491882 }
 1883+
17501884 return false;
17511885 }
17521886 }
1753 -
Index: trunk/phase3/maintenance/tests/UploadFromUrlTestSuite.php
@@ -1,13 +1,13 @@
22 <?php
33
4 -class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite
5 -{
 4+class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite {
65 public static function addTables( &$tables ) {
76 $tables[] = 'user_properties';
87 $tables[] = 'filearchive';
98 $tables[] = 'logging';
109 $tables[] = 'updatelog';
1110 $tables[] = 'iwlinks';
 11+
1212 return true;
1313 }
1414
@@ -28,9 +28,9 @@
2929 $wgLocalFileRepo = array(
3030 'class' => 'LocalRepo',
3131 'name' => 'local',
32 - 'directory' => wfTempDir().'/test-repo',
 32+ 'directory' => wfTempDir() . '/test-repo',
3333 'url' => 'http://example.com/images',
34 - 'deletedDir' => wfTempDir().'/test-repo/delete',
 34+ 'deletedDir' => wfTempDir() . '/test-repo/delete',
3535 'hashLevels' => 2,
3636 'transformVia404' => false,
3737 );
@@ -45,7 +45,7 @@
4646 $messageMemc =& wfGetMessageCacheStorage();
4747 $parserMemc =& wfGetParserCacheStorage();
4848
49 - //$wgContLang = new StubContLang;
 49+ // $wgContLang = new StubContLang;
5050 $wgUser = new User;
5151 $wgLang = new StubUserLang;
5252 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
@@ -55,7 +55,9 @@
5656 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
5757 array( $messageMemc, $wgUseDatabaseMessages,
5858 $wgMsgCacheExpiry ) );
59 - if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
 59+ if ( $wgStyleDirectory === false ) {
 60+ $wgStyleDirectory = "$IP/skins";
 61+ }
6062
6163 }
6264
@@ -106,7 +108,6 @@
107109 );
108110 }
109111
110 -
111112 /**
112113 * Delete the specified files, if they exist.
113114 *
@@ -141,8 +142,10 @@
142143 */
143144 private function setupUploadDir() {
144145 global $IP;
 146+
145147 if ( $this->keepUploads ) {
146148 $dir = wfTempDir() . '/mwParser-images';
 149+
147150 if ( is_dir( $dir ) ) {
148151 return $dir;
149152 }
@@ -151,22 +154,22 @@
152155 }
153156
154157 wfDebug( "Creating upload directory $dir\n" );
 158+
155159 if ( file_exists( $dir ) ) {
156160 wfDebug( "Already exists!\n" );
157161 return $dir;
158162 }
 163+
159164 wfMkdirParents( $dir . '/3/3a' );
160165 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
161166
162167 wfMkdirParents( $dir . '/0/09' );
163168 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 169+
164170 return $dir;
165171 }
166172
167 - public static function suite()
168 - {
 173+ public static function suite() {
169174 return new UploadFromUrlTestSuite( 'UploadFromUrlTest' );
170175 }
171 -
172176 }
173 -
Index: trunk/phase3/maintenance/tests/selenium/SeleniumTestSuite.php
@@ -11,7 +11,7 @@
1212
1313 public function setUp() {
1414 // Hack because because PHPUnit version 3.0.6 which is on prototype does not
15 - //run setUp as part of TestSuite::run
 15+ // run setUp as part of TestSuite::run
1616 if ( $this->isSetUp ) {
1717 return;
1818 }
@@ -34,4 +34,3 @@
3535 $this->selenium->loadPage( $title, $action );
3636 }
3737 }
38 -
Index: trunk/phase3/maintenance/tests/selenium/Selenium.php
@@ -5,6 +5,7 @@
66 */
77
88 require( 'Testing/Selenium.php' );
 9+
910 class Selenium {
1011 protected static $_instance = null;
1112 public $isStarted = false;
@@ -36,7 +37,7 @@
3738 if ( null === self::$_instance ) {
3839 self::$_instance = $this;
3940 } else {
40 - throw new MWException("Already have one Selenium instance.");
 41+ throw new MWException( "Already have one Selenium instance." );
4142 }
4243 }
4344
@@ -75,9 +76,11 @@
7677 $this->type( 'wpName1', $this->user );
7778 $this->type( 'wpPassword1', $this->pass );
7879 $this->click( "//input[@id='wpLoginAttempt']" );
79 - $this->waitForPageToLoad(5000);
80 - //after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
 80+ $this->waitForPageToLoad( 5000 );
 81+
 82+ // after login we redirect to the main page. So check whether the "Prefernces" top menu item exists
8183 $value = $this->isElementPresent( "//li[@id='pt-preferences']" );
 84+
8285 if ( $value != true ) {
8386 throw new Testing_Selenium_Exception( "Login Failed" );
8487 }
@@ -95,7 +98,7 @@
9699 public function loadPage( $title, $action ) {
97100 $this->open( self::$url . '/index.php?title=' . $title . '&action=' . $action );
98101 }
99 -
 102+
100103 public function setLogger( $logger ) {
101104 $this->logger = $logger;
102105 }
@@ -138,14 +141,17 @@
139142
140143 public function setBrowser( $b ) {
141144 $browsers = $this->setupBrowsers();
 145+
 146+
142147 if ( !isset( $browsers[$b] ) ) {
143148 throw new MWException( "Invalid Browser: $b.\n" );
144149 }
 150+
145151 $this->browser = $browsers[$b];
146152 }
147153
148154 public function __call( $name, $args ) {
149 - $t = call_user_func_array( array( $this->tester, $name), $args );
 155+ $t = call_user_func_array( array( $this->tester, $name ), $args );
150156 return $t;
151157 }
152158
@@ -179,14 +185,16 @@
180186
181187 public function setBrowser( $b ) {
182188 $browsers = $this->setupBrowsers();
 189+
183190 if ( !isset( $browsers[$b] ) ) {
184191 throw new MWException( "Invalid Browser: $b.\n" );
185192 }
 193+
186194 $this->browser = $browsers[$b];
187195 }
188196
189197 public function __call( $name, $args ) {
190 - $t = call_user_func_array( array( $this->tester, $name), $args );
 198+ $t = call_user_func_array( array( $this->tester, $name ), $args );
191199 return $t;
192200 }
193201
Index: trunk/phase3/includes/db/Database.php
@@ -21,9 +21,9 @@
2222 */
2323 abstract class DatabaseBase implements DatabaseType {
2424
25 -#------------------------------------------------------------------------------
 25+# ------------------------------------------------------------------------------
2626 # Variables
27 -#------------------------------------------------------------------------------
 27+# ------------------------------------------------------------------------------
2828
2929 protected $mLastQuery = '';
3030 protected $mDoneWrites = false;
@@ -41,9 +41,9 @@
4242 protected $mFakeSlaveLag = null, $mFakeMaster = false;
4343 protected $mDefaultBigSelects = null;
4444
45 -#------------------------------------------------------------------------------
 45+# ------------------------------------------------------------------------------
4646 # Accessors
47 -#------------------------------------------------------------------------------
 47+# ------------------------------------------------------------------------------
4848 # These optionally set a variable and return the previous state
4949
5050 /**
@@ -258,7 +258,7 @@
259259 * @return Boolean
260260 */
261261 function getFlag( $flag ) {
262 - return !!($this->mFlags & $flag);
 262+ return !!( $this->mFlags & $flag );
263263 }
264264
265265 /**
@@ -269,7 +269,7 @@
270270 }
271271
272272 function getWikiID() {
273 - if( $this->mTablePrefix ) {
 273+ if ( $this->mTablePrefix ) {
274274 return "{$this->mDBname}-{$this->mTablePrefix}";
275275 } else {
276276 return $this->mDBname;
@@ -288,9 +288,9 @@
289289 }
290290 }
291291
292 -#------------------------------------------------------------------------------
 292+# ------------------------------------------------------------------------------
293293 # Other functions
294 -#------------------------------------------------------------------------------
 294+# ------------------------------------------------------------------------------
295295
296296 /**
297297 * Constructor.
@@ -303,9 +303,10 @@
304304 * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
305305 */
306306 function __construct( $server = false, $user = false, $password = false, $dbName = false,
307 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) {
 307+ $failFunction = false, $flags = 0, $tablePrefix = 'get from global'
 308+ ) {
 309+ global $wgOut, $wgDBprefix, $wgCommandLineMode;
308310
309 - global $wgOut, $wgDBprefix, $wgCommandLineMode;
310311 # Can't get a reference if it hasn't been set yet
311312 if ( !isset( $wgOut ) ) {
312313 $wgOut = null;
@@ -350,8 +351,7 @@
351352 * @param failFunction
352353 * @param $flags
353354 */
354 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
355 - {
 355+ static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
356356 wfDeprecated( __METHOD__ );
357357 return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags );
358358 }
@@ -441,7 +441,7 @@
442442 # logging size most of the time. The substr is really just a sanity check.
443443
444444 # Who's been wasting my precious column space? -- TS
445 - #$profName = 'query: ' . $fname . ' ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
 445+ # $profName = 'query: ' . $fname . ' ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
446446
447447 if ( $isMaster ) {
448448 $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
@@ -450,6 +450,7 @@
451451 $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
452452 $totalProf = 'DatabaseBase::query';
453453 }
 454+
454455 wfProfileIn( $totalProf );
455456 wfProfileIn( $queryProf );
456457 }
@@ -457,14 +458,14 @@
458459 $this->mLastQuery = $sql;
459460 if ( !$this->mDoneWrites && $this->isWriteQuery( $sql ) ) {
460461 // Set a flag indicating that writes have been done
461 - wfDebug( __METHOD__.": Writes done: $sql\n" );
 462+ wfDebug( __METHOD__ . ": Writes done: $sql\n" );
462463 $this->mDoneWrites = true;
463464 }
464465
465466 # Add a comment for easy SHOW PROCESSLIST interpretation
466 - #if ( $fname ) {
 467+ # if ( $fname ) {
467468 global $wgUser;
468 - if ( is_object( $wgUser ) && !($wgUser instanceof StubObject) ) {
 469+ if ( is_object( $wgUser ) && !( $wgUser instanceof StubObject ) ) {
469470 $userName = $wgUser->getName();
470471 if ( mb_strlen( $userName ) > 15 ) {
471472 $userName = mb_substr( $userName, 0, 15 ) . '...';
@@ -473,27 +474,29 @@
474475 } else {
475476 $userName = '';
476477 }
477 - $commentedSql = preg_replace('/\s/', " /* $fname $userName */ ", $sql, 1);
478 - #} else {
 478+ $commentedSql = preg_replace( '/\s/', " /* $fname $userName */ ", $sql, 1 );
 479+ # } else {
479480 # $commentedSql = $sql;
480 - #}
 481+ # }
481482
482483 # If DBO_TRX is set, start a transaction
483484 if ( ( $this->mFlags & DBO_TRX ) && !$this->trxLevel() &&
484 - $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK') {
 485+ $sql != 'BEGIN' && $sql != 'COMMIT' && $sql != 'ROLLBACK' ) {
485486 // avoid establishing transactions for SHOW and SET statements too -
486487 // that would delay transaction initializations to once connection
487488 // is really used by application
488 - $sqlstart = substr($sql,0,10); // very much worth it, benchmark certified(tm)
489 - if (strpos($sqlstart,"SHOW ")!==0 and strpos($sqlstart,"SET ")!==0)
 489+ $sqlstart = substr( $sql, 0, 10 ); // very much worth it, benchmark certified(tm)
 490+ if ( strpos( $sqlstart, "SHOW " ) !== 0 and strpos( $sqlstart, "SET " ) !== 0 )
490491 $this->begin();
491492 }
492493
493494 if ( $this->debug() ) {
494495 static $cnt = 0;
 496+
495497 $cnt++;
496498 $sqlx = substr( $commentedSql, 0, 500 );
497499 $sqlx = strtr( $sqlx, "\t\n", ' ' );
 500+
498501 if ( $isMaster ) {
499502 wfDebug( "Query $cnt (master): $sqlx\n" );
500503 } else {
@@ -513,12 +516,13 @@
514517 # Transaction is gone, like it or not
515518 $this->mTrxLevel = 0;
516519 wfDebug( "Connection lost, reconnecting...\n" );
 520+
517521 if ( $this->ping() ) {
518522 wfDebug( "Reconnected\n" );
519523 $sqlx = substr( $commentedSql, 0, 500 );
520524 $sqlx = strtr( $sqlx, "\t\n", ' ' );
521525 global $wgRequestTime;
522 - $elapsed = round( microtime(true) - $wgRequestTime, 3 );
 526+ $elapsed = round( microtime( true ) - $wgRequestTime, 3 );
523527 wfLogDBError( "Connection lost and reconnected after {$elapsed}s, query: $sqlx\n" );
524528 $ret = $this->doQuery( $commentedSql );
525529 } else {
@@ -534,6 +538,7 @@
535539 wfProfileOut( $queryProf );
536540 wfProfileOut( $totalProf );
537541 }
 542+
538543 return $this->resultObject( $ret );
539544 }
540545
@@ -549,13 +554,13 @@
550555 $ignore = $this->ignoreErrors( true );
551556 ++$this->mErrorCount;
552557
553 - if( $ignore || $tempIgnore ) {
554 - wfDebug("SQL ERROR (ignored): $error\n");
 558+ if ( $ignore || $tempIgnore ) {
 559+ wfDebug( "SQL ERROR (ignored): $error\n" );
555560 $this->ignoreErrors( $ignore );
556561 } else {
557562 $sql1line = str_replace( "\n", "\\n", $sql );
558 - wfLogDBError("$fname\t{$this->mServer}\t$errno\t$error\t$sql1line\n");
559 - wfDebug("SQL ERROR: " . $error . "\n");
 563+ wfLogDBError( "$fname\t{$this->mServer}\t$errno\t$error\t$sql1line\n" );
 564+ wfDebug( "SQL ERROR: " . $error . "\n" );
560565 throw new DBQueryError( $this, $error, $errno, $sql, $fname );
561566 }
562567 }
@@ -587,12 +592,14 @@
588593 * @param $args Mixed: Either an array here, or put scalars as varargs
589594 */
590595 function execute( $prepared, $args = null ) {
591 - if( !is_array( $args ) ) {
 596+ if ( !is_array( $args ) ) {
592597 # Pull the var args
593598 $args = func_get_args();
594599 array_shift( $args );
595600 }
 601+
596602 $sql = $this->fillPrepared( $prepared['query'], $args );
 603+
597604 return $this->query( $sql, $prepared['func'] );
598605 }
599606
@@ -604,13 +611,16 @@
605612 */
606613 function safeQuery( $query, $args = null ) {
607614 $prepared = $this->prepare( $query, 'DatabaseBase::safeQuery' );
608 - if( !is_array( $args ) ) {
 615+
 616+ if ( !is_array( $args ) ) {
609617 # Pull the var args
610618 $args = func_get_args();
611619 array_shift( $args );
612620 }
 621+
613622 $retval = $this->execute( $prepared, $args );
614623 $this->freePrepared( $prepared );
 624+
615625 return $retval;
616626 }
617627
@@ -624,6 +634,7 @@
625635 function fillPrepared( $preparedQuery, $args ) {
626636 reset( $args );
627637 $this->preparedArgs =& $args;
 638+
628639 return preg_replace_callback( '/(\\\\[?!&]|[?!&])/',
629640 array( &$this, 'fillPreparedArg' ), $preparedQuery );
630641 }
@@ -643,7 +654,9 @@
644655 case '\\!': return '!';
645656 case '\\&': return '&';
646657 }
 658+
647659 list( /* $n */ , $arg ) = each( $this->preparedArgs );
 660+
648661 switch( $matches[1] ) {
649662 case '?': return $this->addQuotes( $arg );
650663 case '!': return $arg;
@@ -676,6 +689,7 @@
677690 $table = $this->tableName( $table );
678691 $sql = "UPDATE $table SET $var = '" .
679692 $this->strencode( $value ) . "' WHERE ($cond)";
 693+
680694 return (bool)$this->query( $sql, $fname );
681695 }
682696
@@ -684,17 +698,21 @@
685699 * Usually aborts on failure
686700 * If errors are explicitly ignored, returns FALSE on failure
687701 */
688 - function selectField( $table, $var, $cond='', $fname = 'DatabaseBase::selectField', $options = array() ) {
 702+ function selectField( $table, $var, $cond = '', $fname = 'DatabaseBase::selectField', $options = array() ) {
689703 if ( !is_array( $options ) ) {
690704 $options = array( $options );
691705 }
 706+
692707 $options['LIMIT'] = 1;
693708
694709 $res = $this->select( $table, $var, $cond, $fname, $options );
 710+
695711 if ( $res === false || !$this->numRows( $res ) ) {
696712 return false;
697713 }
 714+
698715 $row = $this->fetchRow( $res );
 716+
699717 if ( $row !== false ) {
700718 return reset( $row );
701719 } else {
@@ -717,6 +735,7 @@
718736 $startOpts = '';
719737
720738 $noKeyOptions = array();
 739+
721740 foreach ( $options as $key => $option ) {
722741 if ( is_numeric( $key ) ) {
723742 $noKeyOptions[$option] = true;
@@ -726,25 +745,29 @@
727746 if ( isset( $options['GROUP BY'] ) ) {
728747 $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
729748 }
 749+
730750 if ( isset( $options['HAVING'] ) ) {
731751 $preLimitTail .= " HAVING {$options['HAVING']}";
732752 }
 753+
733754 if ( isset( $options['ORDER BY'] ) ) {
734755 $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
735756 }
736757
737 - //if (isset($options['LIMIT'])) {
 758+ // if (isset($options['LIMIT'])) {
738759 // $tailOpts .= $this->limitResult('', $options['LIMIT'],
739760 // isset($options['OFFSET']) ? $options['OFFSET']
740761 // : false);
741 - //}
 762+ // }
742763
743764 if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
744765 $postLimitTail .= ' FOR UPDATE';
745766 }
 767+
746768 if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
747769 $postLimitTail .= ' LOCK IN SHARE MODE';
748770 }
 771+
749772 if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) {
750773 $startOpts .= 'DISTINCT';
751774 }
@@ -753,24 +776,31 @@
754777 if ( isset( $noKeyOptions['STRAIGHT_JOIN'] ) ) {
755778 $startOpts .= ' /*! STRAIGHT_JOIN */';
756779 }
 780+
757781 if ( isset( $noKeyOptions['HIGH_PRIORITY'] ) ) {
758782 $startOpts .= ' HIGH_PRIORITY';
759783 }
 784+
760785 if ( isset( $noKeyOptions['SQL_BIG_RESULT'] ) ) {
761786 $startOpts .= ' SQL_BIG_RESULT';
762787 }
 788+
763789 if ( isset( $noKeyOptions['SQL_BUFFER_RESULT'] ) ) {
764790 $startOpts .= ' SQL_BUFFER_RESULT';
765791 }
 792+
766793 if ( isset( $noKeyOptions['SQL_SMALL_RESULT'] ) ) {
767794 $startOpts .= ' SQL_SMALL_RESULT';
768795 }
 796+
769797 if ( isset( $noKeyOptions['SQL_CALC_FOUND_ROWS'] ) ) {
770798 $startOpts .= ' SQL_CALC_FOUND_ROWS';
771799 }
 800+
772801 if ( isset( $noKeyOptions['SQL_CACHE'] ) ) {
773802 $startOpts .= ' SQL_CACHE';
774803 }
 804+
775805 if ( isset( $noKeyOptions['SQL_NO_CACHE'] ) ) {
776806 $startOpts .= ' SQL_NO_CACHE';
777807 }
@@ -797,8 +827,9 @@
798828 * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
799829 * @return mixed Database result resource (feed to DatabaseBase::fetchObject or whatever), or false on failure
800830 */
801 - function select( $table, $vars, $conds='', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) {
 831+ function select( $table, $vars, $conds = '', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) {
802832 $sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
 833+
803834 return $this->query( $sql, $fname );
804835 }
805836
@@ -815,21 +846,23 @@
816847 * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
817848 * @return string, the SQL text
818849 */
819 - function selectSQLText( $table, $vars, $conds='', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) {
820 - if( is_array( $vars ) ) {
 850+ function selectSQLText( $table, $vars, $conds = '', $fname = 'DatabaseBase::select', $options = array(), $join_conds = array() ) {
 851+ if ( is_array( $vars ) ) {
821852 $vars = implode( ',', $vars );
822853 }
823 - if( !is_array( $options ) ) {
 854+
 855+ if ( !is_array( $options ) ) {
824856 $options = array( $options );
825857 }
826 - if( is_array( $table ) ) {
827 - if ( !empty($join_conds) || ( isset( $options['USE INDEX'] ) && is_array( @$options['USE INDEX'] ) ) ) {
 858+
 859+ if ( is_array( $table ) ) {
 860+ if ( !empty( $join_conds ) || ( isset( $options['USE INDEX'] ) && is_array( @$options['USE INDEX'] ) ) ) {
828861 $from = ' FROM ' . $this->tableNamesWithUseIndexOrJOIN( $table, @$options['USE INDEX'], $join_conds );
829862 } else {
830863 $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) );
831864 }
832 - } elseif ($table!='') {
833 - if ($table{0}==' ') {
 865+ } elseif ( $table != '' ) {
 866+ if ( $table { 0 } == ' ' ) {
834867 $from = ' FROM ' . $table;
835868 } else {
836869 $from = ' FROM ' . $this->tableName( $table );
@@ -840,7 +873,7 @@
841874
842875 list( $startOpts, $useIndex, $preLimitTail, $postLimitTail ) = $this->makeSelectOptions( $options );
843876
844 - if( !empty( $conds ) ) {
 877+ if ( !empty( $conds ) ) {
845878 if ( is_array( $conds ) ) {
846879 $conds = $this->makeList( $conds, LIST_AND );
847880 }
@@ -849,14 +882,15 @@
850883 $sql = "SELECT $startOpts $vars $from $useIndex $preLimitTail";
851884 }
852885
853 - if (isset($options['LIMIT']))
854 - $sql = $this->limitResult($sql, $options['LIMIT'],
855 - isset($options['OFFSET']) ? $options['OFFSET'] : false);
 886+ if ( isset( $options['LIMIT'] ) )
 887+ $sql = $this->limitResult( $sql, $options['LIMIT'],
 888+ isset( $options['OFFSET'] ) ? $options['OFFSET'] : false );
856889 $sql = "$sql $postLimitTail";
857890
858 - if (isset($options['EXPLAIN'])) {
 891+ if ( isset( $options['EXPLAIN'] ) ) {
859892 $sql = 'EXPLAIN ' . $sql;
860893 }
 894+
861895 return $sql;
862896 }
863897
@@ -881,13 +915,17 @@
882916 function selectRow( $table, $vars, $conds, $fname = 'DatabaseBase::selectRow', $options = array(), $join_conds = array() ) {
883917 $options['LIMIT'] = 1;
884918 $res = $this->select( $table, $vars, $conds, $fname, $options, $join_conds );
 919+
885920 if ( $res === false ) {
886921 return false;
887922 }
888 - if ( !$this->numRows($res) ) {
 923+
 924+ if ( !$this->numRows( $res ) ) {
889925 return false;
890926 }
 927+
891928 $obj = $this->fetchObject( $res );
 929+
892930 return $obj;
893931 }
894932
@@ -904,13 +942,15 @@
905943 * @param $options Array: options for select
906944 * @return Integer: row count
907945 */
908 - public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseBase::estimateRowCount', $options = array() ) {
 946+ public function estimateRowCount( $table, $vars = '*', $conds = '', $fname = 'DatabaseBase::estimateRowCount', $options = array() ) {
909947 $rows = 0;
910948 $res = $this->select ( $table, 'COUNT(*) AS rowcount', $conds, $fname, $options );
 949+
911950 if ( $res ) {
912951 $row = $this->fetchRow( $res );
913952 $rows = ( isset( $row['rowcount'] ) ) ? $row['rowcount'] : 0;
914953 }
 954+
915955 return $rows;
916956 }
917957
@@ -925,17 +965,17 @@
926966 # as to avoid crashing php on some large strings.
927967 # $sql = preg_replace ( "/'([^\\\\']|\\\\.)*'|\"([^\\\\\"]|\\\\.)*\"/", "'X'", $sql);
928968
929 - $sql = str_replace ( "\\\\", '', $sql);
930 - $sql = str_replace ( "\\'", '', $sql);
931 - $sql = str_replace ( "\\\"", '', $sql);
932 - $sql = preg_replace ("/'.*'/s", "'X'", $sql);
933 - $sql = preg_replace ('/".*"/s', "'X'", $sql);
 969+ $sql = str_replace ( "\\\\", '', $sql );
 970+ $sql = str_replace ( "\\'", '', $sql );
 971+ $sql = str_replace ( "\\\"", '', $sql );
 972+ $sql = preg_replace ( "/'.*'/s", "'X'", $sql );
 973+ $sql = preg_replace ( '/".*"/s', "'X'", $sql );
934974
935975 # All newlines, tabs, etc replaced by single space
936 - $sql = preg_replace ( '/\s+/', ' ', $sql);
 976+ $sql = preg_replace ( '/\s+/', ' ', $sql );
937977
938978 # All numbers => N
939 - $sql = preg_replace ('/-?[0-9]+/s', 'N', $sql);
 979+ $sql = preg_replace ( '/-?[0-9]+/s', 'N', $sql );
940980
941981 return $sql;
942982 }
@@ -950,6 +990,7 @@
951991 */
952992 function fieldExists( $table, $field, $fname = 'DatabaseBase::fieldExists' ) {
953993 $info = $this->fieldInfo( $table, $field );
 994+
954995 return (bool)$info;
955996 }
956997
@@ -978,20 +1019,22 @@
9791020 # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
9801021 $table = $this->tableName( $table );
9811022 $index = $this->indexName( $index );
982 - $sql = 'SHOW INDEX FROM '.$table;
 1023+ $sql = 'SHOW INDEX FROM ' . $table;
9831024 $res = $this->query( $sql, $fname );
 1025+
9841026 if ( !$res ) {
9851027 return null;
9861028 }
9871029
9881030 $result = array();
 1031+
9891032 while ( $row = $this->fetchObject( $res ) ) {
9901033 if ( $row->Key_name == $index ) {
9911034 $result[] = $row;
9921035 }
9931036 }
9941037
995 - return empty($result) ? false : $result;
 1038+ return empty( $result ) ? false : $result;
9961039 }
9971040
9981041 /**
@@ -1002,6 +1045,7 @@
10031046 $old = $this->ignoreErrors( true );
10041047 $res = $this->query( "SELECT 1 FROM $table LIMIT 1" );
10051048 $this->ignoreErrors( $old );
 1049+
10061050 return (bool)$res;
10071051 }
10081052
@@ -1012,6 +1056,7 @@
10131057 if ( $res instanceof ResultWrapper ) {
10141058 $res = $res->result;
10151059 }
 1060+
10161061 return mysql_field_type( $res, $index );
10171062 }
10181063
@@ -1020,12 +1065,14 @@
10211066 */
10221067 function indexUnique( $table, $index ) {
10231068 $indexInfo = $this->indexInfo( $table, $index );
 1069+
10241070 if ( !$indexInfo ) {
10251071 return null;
10261072 }
 1073+
10271074 return !$indexInfo[0]->Non_unique;
10281075 }
1029 -
 1076+
10301077 /**
10311078 * INSERT wrapper, inserts an array into a table
10321079 *
@@ -1049,9 +1096,11 @@
10501097 }
10511098
10521099 $table = $this->tableName( $table );
 1100+
10531101 if ( !is_array( $options ) ) {
10541102 $options = array( $options );
10551103 }
 1104+
10561105 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
10571106 $multi = true;
10581107 $keys = array_keys( $a[0] );
@@ -1088,17 +1137,21 @@
10891138 * @return string
10901139 */
10911140 function makeUpdateOptions( $options ) {
1092 - if( !is_array( $options ) ) {
 1141+ if ( !is_array( $options ) ) {
10931142 $options = array( $options );
10941143 }
 1144+
10951145 $opts = array();
 1146+
10961147 if ( in_array( 'LOW_PRIORITY', $options ) ) {
10971148 $opts[] = $this->lowPriorityOption();
10981149 }
 1150+
10991151 if ( in_array( 'IGNORE', $options ) ) {
11001152 $opts[] = 'IGNORE';
11011153 }
1102 - return implode(' ', $opts);
 1154+
 1155+ return implode( ' ', $opts );
11031156 }
11041157
11051158 /**
@@ -1117,9 +1170,11 @@
11181171 $table = $this->tableName( $table );
11191172 $opts = $this->makeUpdateOptions( $options );
11201173 $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET );
 1174+
11211175 if ( $conds != '*' ) {
11221176 $sql .= " WHERE " . $this->makeList( $conds, LIST_AND );
11231177 }
 1178+
11241179 return $this->query( $sql, $fname );
11251180 }
11261181
@@ -1139,11 +1194,12 @@
11401195
11411196 $first = true;
11421197 $list = '';
 1198+
11431199 foreach ( $a as $field => $value ) {
11441200 if ( !$first ) {
11451201 if ( $mode == LIST_AND ) {
11461202 $list .= ' AND ';
1147 - } elseif($mode == LIST_OR) {
 1203+ } elseif ( $mode == LIST_OR ) {
11481204 $list .= ' OR ';
11491205 } else {
11501206 $list .= ',';
@@ -1151,21 +1207,22 @@
11521208 } else {
11531209 $first = false;
11541210 }
1155 - if ( ($mode == LIST_AND || $mode == LIST_OR) && is_numeric( $field ) ) {
 1211+
 1212+ if ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_numeric( $field ) ) {
11561213 $list .= "($value)";
1157 - } elseif ( ($mode == LIST_SET) && is_numeric( $field ) ) {
 1214+ } elseif ( ( $mode == LIST_SET ) && is_numeric( $field ) ) {
11581215 $list .= "$value";
1159 - } elseif ( ($mode == LIST_AND || $mode == LIST_OR) && is_array($value) ) {
 1216+ } elseif ( ( $mode == LIST_AND || $mode == LIST_OR ) && is_array( $value ) ) {
11601217 if ( count( $value ) == 0 ) {
1161 - throw new MWException( __METHOD__.': empty input' );
1162 - } elseif( count( $value ) == 1 ) {
 1218+ throw new MWException( __METHOD__ . ': empty input' );
 1219+ } elseif ( count( $value ) == 1 ) {
11631220 // Special-case single values, as IN isn't terribly efficient
11641221 // Don't necessarily assume the single key is 0; we don't
11651222 // enforce linear numeric ordering on other arrays here.
11661223 $value = array_values( $value );
1167 - $list .= $field." = ".$this->addQuotes( $value[0] );
 1224+ $list .= $field . " = " . $this->addQuotes( $value[0] );
11681225 } else {
1169 - $list .= $field." IN (".$this->makeList($value).") ";
 1226+ $list .= $field . " IN (" . $this->makeList( $value ) . ") ";
11701227 }
11711228 } elseif ( $value === null ) {
11721229 if ( $mode == LIST_AND || $mode == LIST_OR ) {
@@ -1181,6 +1238,7 @@
11821239 $list .= $mode == LIST_NAMES ? $value : $this->addQuotes( $value );
11831240 }
11841241 }
 1242+
11851243 return $list;
11861244 }
11871245
@@ -1195,11 +1253,12 @@
11961254 */
11971255 function makeWhereFrom2d( $data, $baseKey, $subKey ) {
11981256 $conds = array();
 1257+
11991258 foreach ( $data as $base => $sub ) {
12001259 if ( count( $sub ) ) {
12011260 $conds[] = $this->makeList(
12021261 array( $baseKey => $base, $subKey => array_keys( $sub ) ),
1203 - LIST_AND);
 1262+ LIST_AND );
12041263 }
12051264 }
12061265
@@ -1215,28 +1274,28 @@
12161275 * Bitwise operations
12171276 */
12181277
1219 - function bitNot($field) {
 1278+ function bitNot( $field ) {
12201279 return "(~$field)";
12211280 }
12221281
1223 - function bitAnd($fieldLeft, $fieldRight) {
 1282+ function bitAnd( $fieldLeft, $fieldRight ) {
12241283 return "($fieldLeft & $fieldRight)";
12251284 }
12261285
1227 - function bitOr($fieldLeft, $fieldRight) {
 1286+ function bitOr( $fieldLeft, $fieldRight ) {
12281287 return "($fieldLeft | $fieldRight)";
12291288 }
12301289
12311290 /**
12321291 * Change the current database
12331292 *
 1293+ * @todo Explain what exactly will fail if this is not overridden.
12341294 * @return bool Success or failure
12351295 */
12361296 function selectDB( $db ) {
12371297 # Stub. Shouldn't cause serious problems if it's not overridden, but
12381298 # if your database engine supports a concept similar to MySQL's
1239 - # databases you may as well. TODO: explain what exactly will fail if
1240 - # this is not overridden.
 1299+ # databases you may as well.
12411300 return true;
12421301 }
12431302
@@ -1284,7 +1343,7 @@
12851344 # Note that we use a whitespace test rather than a \b test to avoid
12861345 # any remote case where a word like on may be inside of a table name
12871346 # surrounded by symbols which may be considered word breaks.
1288 - if( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) {
 1347+ if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) {
12891348 return $name;
12901349 }
12911350
@@ -1292,7 +1351,7 @@
12931352 # We reverse the explode so that database.table and table both output
12941353 # the correct table.
12951354 $dbDetails = array_reverse( explode( '.', $name, 2 ) );
1296 - if( isset( $dbDetails[1] ) ) {
 1355+ if ( isset( $dbDetails[1] ) ) {
12971356 @list( $table, $database ) = $dbDetails;
12981357 } else {
12991358 @list( $table ) = $dbDetails;
@@ -1301,13 +1360,13 @@
13021361
13031362 # A database name has been specified in input. Quote the table name
13041363 # because we don't want any prefixes added.
1305 - if( isset($database) ) {
 1364+ if ( isset( $database ) ) {
13061365 $table = ( $table[0] == '`' ? $table : "`{$table}`" );
13071366 }
13081367
13091368 # Note that we use the long format because php will complain in in_array if
13101369 # the input is not an array, and will complain in is_array if it is not set.
1311 - if( !isset( $database ) # Don't use shared database if pre selected.
 1370+ if ( !isset( $database ) # Don't use shared database if pre selected.
13121371 && isset( $wgSharedDB ) # We have a shared database
13131372 && $table[0] != '`' # Paranoia check to prevent shared tables listing '`table`'
13141373 && isset( $wgSharedTables )
@@ -1318,15 +1377,14 @@
13191378 }
13201379
13211380 # Quote the $database and $table and apply the prefix if not quoted.
1322 - if( isset($database) ) {
 1381+ if ( isset( $database ) ) {
13231382 $database = ( $database[0] == '`' ? $database : "`{$database}`" );
13241383 }
13251384 $table = ( $table[0] == '`' ? $table : "`{$prefix}{$table}`" );
13261385
13271386 # Merge our database and table into our final table name.
1328 - $tableName = ( isset($database) ? "{$database}.{$table}" : "{$table}" );
 1387+ $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" );
13291388
1330 - # We're finished, return.
13311389 return $tableName;
13321390 }
13331391
@@ -1342,9 +1400,11 @@
13431401 public function tableNames() {
13441402 $inArray = func_get_args();
13451403 $retVal = array();
 1404+
13461405 foreach ( $inArray as $name ) {
13471406 $retVal[$name] = $this->tableName( $name );
13481407 }
 1408+
13491409 return $retVal;
13501410 }
13511411
@@ -1360,9 +1420,11 @@
13611421 public function tableNamesN() {
13621422 $inArray = func_get_args();
13631423 $retVal = array();
 1424+
13641425 foreach ( $inArray as $name ) {
13651426 $retVal[] = $this->tableName( $name );
13661427 }
 1428+
13671429 return $retVal;
13681430 }
13691431
@@ -1372,41 +1434,48 @@
13731435 function tableNamesWithUseIndexOrJOIN( $tables, $use_index = array(), $join_conds = array() ) {
13741436 $ret = array();
13751437 $retJOIN = array();
1376 - $use_index_safe = is_array($use_index) ? $use_index : array();
1377 - $join_conds_safe = is_array($join_conds) ? $join_conds : array();
 1438+ $use_index_safe = is_array( $use_index ) ? $use_index : array();
 1439+ $join_conds_safe = is_array( $join_conds ) ? $join_conds : array();
 1440+
13781441 foreach ( $tables as $table ) {
13791442 // Is there a JOIN and INDEX clause for this table?
1380 - if ( isset($join_conds_safe[$table]) && isset($use_index_safe[$table]) ) {
 1443+ if ( isset( $join_conds_safe[$table] ) && isset( $use_index_safe[$table] ) ) {
13811444 $tableClause = $join_conds_safe[$table][0] . ' ' . $this->tableName( $table );
13821445 $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$table] ) );
1383 - $on = $this->makeList((array)$join_conds_safe[$table][1], LIST_AND);
 1446+ $on = $this->makeList( (array)$join_conds_safe[$table][1], LIST_AND );
 1447+
13841448 if ( $on != '' ) {
13851449 $tableClause .= ' ON (' . $on . ')';
13861450 }
 1451+
13871452 $retJOIN[] = $tableClause;
13881453 // Is there an INDEX clause?
1389 - } else if ( isset($use_index_safe[$table]) ) {
 1454+ } else if ( isset( $use_index_safe[$table] ) ) {
13901455 $tableClause = $this->tableName( $table );
13911456 $tableClause .= ' ' . $this->useIndexClause( implode( ',', (array)$use_index_safe[$table] ) );
13921457 $ret[] = $tableClause;
13931458 // Is there a JOIN clause?
1394 - } else if ( isset($join_conds_safe[$table]) ) {
 1459+ } else if ( isset( $join_conds_safe[$table] ) ) {
13951460 $tableClause = $join_conds_safe[$table][0] . ' ' . $this->tableName( $table );
1396 - $on = $this->makeList((array)$join_conds_safe[$table][1], LIST_AND);
 1461+ $on = $this->makeList( (array)$join_conds_safe[$table][1], LIST_AND );
 1462+
13971463 if ( $on != '' ) {
13981464 $tableClause .= ' ON (' . $on . ')';
13991465 }
 1466+
14001467 $retJOIN[] = $tableClause;
14011468 } else {
14021469 $tableClause = $this->tableName( $table );
14031470 $ret[] = $tableClause;
14041471 }
14051472 }
 1473+
14061474 // We can't separate explicit JOIN clauses with ',', use ' ' for those
1407 - $straightJoins = !empty($ret) ? implode( ',', $ret ) : "";
1408 - $otherJoins = !empty($retJOIN) ? implode( ' ', $retJOIN ) : "";
 1475+ $straightJoins = !empty( $ret ) ? implode( ',', $ret ) : "";
 1476+ $otherJoins = !empty( $retJOIN ) ? implode( ' ', $retJOIN ) : "";
 1477+
14091478 // Compile our final table clause
1410 - return implode(' ',array($straightJoins,$otherJoins) );
 1479+ return implode( ' ', array( $straightJoins, $otherJoins ) );
14111480 }
14121481
14131482 /**
@@ -1419,6 +1488,7 @@
14201489 'un_user_id' => 'user_id',
14211490 'un_user_ip' => 'user_ip',
14221491 );
 1492+
14231493 if ( isset( $renamed[$index] ) ) {
14241494 return $renamed[$index];
14251495 } else {
@@ -1457,6 +1527,7 @@
14581528 $s = str_replace( '\\', '\\\\', $s );
14591529 $s = $this->strencode( $s );
14601530 $s = str_replace( array( '%', '_' ), array( '\%', '\_' ), $s );
 1531+
14611532 return $s;
14621533 }
14631534
@@ -1474,18 +1545,21 @@
14751546 */
14761547 function buildLike() {
14771548 $params = func_get_args();
1478 - if (count($params) > 0 && is_array($params[0])) {
 1549+
 1550+ if ( count( $params ) > 0 && is_array( $params[0] ) ) {
14791551 $params = $params[0];
14801552 }
14811553
14821554 $s = '';
1483 - foreach( $params as $value) {
1484 - if( $value instanceof LikeMatch ) {
 1555+
 1556+ foreach ( $params as $value ) {
 1557+ if ( $value instanceof LikeMatch ) {
14851558 $s .= $value->toString();
14861559 } else {
14871560 $s .= $this->escapeLikeInternal( $value );
14881561 }
14891562 }
 1563+
14901564 return " LIKE '" . $s . "' ";
14911565 }
14921566
@@ -1548,16 +1622,19 @@
15491623 $rows = array( $rows );
15501624 }
15511625
1552 - $sql = "REPLACE INTO $table (" . implode( ',', array_keys( $rows[0] ) ) .') VALUES ';
 1626+ $sql = "REPLACE INTO $table (" . implode( ',', array_keys( $rows[0] ) ) . ') VALUES ';
15531627 $first = true;
 1628+
15541629 foreach ( $rows as $row ) {
15551630 if ( $first ) {
15561631 $first = false;
15571632 } else {
15581633 $sql .= ',';
15591634 }
 1635+
15601636 $sql .= '(' . $this->makeList( $row ) . ')';
15611637 }
 1638+
15621639 return $this->query( $sql, $fname );
15631640 }
15641641
@@ -1585,6 +1662,7 @@
15861663 $delTable = $this->tableName( $delTable );
15871664 $joinTable = $this->tableName( $joinTable );
15881665 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
 1666+
15891667 if ( $conds != '*' ) {
15901668 $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
15911669 }
@@ -1602,11 +1680,13 @@
16031681 $row = $this->fetchObject( $res );
16041682
16051683 $m = array();
 1684+
16061685 if ( preg_match( '/\((.*)\)/', $row->Type, $m ) ) {
16071686 $size = $m[1];
16081687 } else {
16091688 $size = -1;
16101689 }
 1690+
16111691 return $size;
16121692 }
16131693
@@ -1630,11 +1710,14 @@
16311711 if ( !$conds ) {
16321712 throw new DBUnexpectedError( $this, 'DatabaseBase::delete() called with no conditions' );
16331713 }
 1714+
16341715 $table = $this->tableName( $table );
16351716 $sql = "DELETE FROM $table";
 1717+
16361718 if ( $conds != '*' ) {
16371719 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
16381720 }
 1721+
16391722 return $this->query( $sql, $fname );
16401723 }
16411724
@@ -1649,25 +1732,33 @@
16501733 $insertOptions = array(), $selectOptions = array() )
16511734 {
16521735 $destTable = $this->tableName( $destTable );
 1736+
16531737 if ( is_array( $insertOptions ) ) {
16541738 $insertOptions = implode( ' ', $insertOptions );
16551739 }
1656 - if( !is_array( $selectOptions ) ) {
 1740+
 1741+ if ( !is_array( $selectOptions ) ) {
16571742 $selectOptions = array( $selectOptions );
16581743 }
 1744+
16591745 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
 1746+
16601747 if ( is_array( $srcTable ) ) {
16611748 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
16621749 } else {
16631750 $srcTable = $this->tableName( $srcTable );
16641751 }
 1752+
16651753 $sql = "INSERT $insertOptions INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
16661754 " SELECT $startOpts " . implode( ',', $varMap ) .
16671755 " FROM $srcTable $useIndex ";
 1756+
16681757 if ( $conds != '*' ) {
16691758 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
16701759 }
 1760+
16711761 $sql .= " $tailOpts";
 1762+
16721763 return $this->query( $sql, $fname );
16731764 }
16741765
@@ -1689,14 +1780,16 @@
16901781 * @param $limit Integer: the SQL limit
16911782 * @param $offset Integer the SQL offset (default false)
16921783 */
1693 - function limitResult( $sql, $limit, $offset=false ) {
1694 - if( !is_numeric( $limit ) ) {
 1784+ function limitResult( $sql, $limit, $offset = false ) {
 1785+ if ( !is_numeric( $limit ) ) {
16951786 throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" );
16961787 }
 1788+
16971789 return "$sql LIMIT "
1698 - . ( (is_numeric($offset) && $offset != 0) ? "{$offset}," : "" )
 1790+ . ( ( is_numeric( $offset ) && $offset != 0 ) ? "{$offset}," : "" )
16991791 . "{$limit} ";
17001792 }
 1793+
17011794 function limitResultForUpdate( $sql, $num ) {
17021795 return $this->limitResult( $sql, $num, 0 );
17031796 }
@@ -1718,9 +1811,9 @@
17191812 * @param $all Boolean: use UNION ALL
17201813 * @return String: SQL fragment
17211814 */
1722 - function unionQueries($sqls, $all) {
 1815+ function unionQueries( $sqls, $all ) {
17231816 $glue = $all ? ') UNION ALL (' : ') UNION (';
1724 - return '('.implode( $glue, $sqls ) . ')';
 1817+ return '(' . implode( $glue, $sqls ) . ')';
17251818 }
17261819
17271820 /**
@@ -1797,11 +1890,13 @@
17981891 $function = array_shift( $args );
17991892 $oldIgnore = $this->ignoreErrors( true );
18001893 $tries = DEADLOCK_TRIES;
 1894+
18011895 if ( is_array( $function ) ) {
18021896 $fname = $function[0];
18031897 } else {
18041898 $fname = $function;
18051899 }
 1900+
18061901 do {
18071902 $retVal = call_user_func_array( $function, $args );
18081903 $error = $this->lastError();
@@ -1817,7 +1912,9 @@
18181913 }
18191914 }
18201915 } while ( $this->wasDeadlock() && --$tries > 0 );
 1916+
18211917 $this->ignoreErrors( $oldIgnore );
 1918+
18221919 if ( $tries <= 0 ) {
18231920 $this->rollback( $myFname );
18241921 $this->reportQueryError( $error, $errno, $sql, $fname );
@@ -1844,7 +1941,8 @@
18451942 }
18461943
18471944 if ( !is_null( $this->mFakeSlaveLag ) ) {
1848 - $wait = intval( ( $pos->pos - microtime(true) + $this->mFakeSlaveLag ) * 1e6 );
 1945+ $wait = intval( ( $pos->pos - microtime( true ) + $this->mFakeSlaveLag ) * 1e6 );
 1946+
18491947 if ( $wait > $timeout * 1e6 ) {
18501948 wfDebug( "Fake slave timed out waiting for $pos ($wait us)\n" );
18511949 wfProfileOut( $fname );
@@ -1866,6 +1964,7 @@
18671965 $encPos = intval( $pos->pos );
18681966 $sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)";
18691967 $res = $this->doQuery( $sql );
 1968+
18701969 if ( $res && $row = $this->fetchRow( $res ) ) {
18711970 wfProfileOut( $fname );
18721971 return $row[0];
@@ -1880,14 +1979,16 @@
18811980 */
18821981 function getSlavePos() {
18831982 if ( !is_null( $this->mFakeSlaveLag ) ) {
1884 - $pos = new MySQLMasterPos( 'fake', microtime(true) - $this->mFakeSlaveLag );
1885 - wfDebug( __METHOD__.": fake slave pos = $pos\n" );
 1983+ $pos = new MySQLMasterPos( 'fake', microtime( true ) - $this->mFakeSlaveLag );
 1984+ wfDebug( __METHOD__ . ": fake slave pos = $pos\n" );
18861985 return $pos;
18871986 }
 1987+
18881988 $res = $this->query( 'SHOW SLAVE STATUS', 'DatabaseBase::getSlavePos' );
18891989 $row = $this->fetchObject( $res );
 1990+
18901991 if ( $row ) {
1891 - $pos = isset($row->Exec_master_log_pos) ? $row->Exec_master_log_pos : $row->Exec_Master_Log_Pos;
 1992+ $pos = isset( $row->Exec_master_log_pos ) ? $row->Exec_master_log_pos : $row->Exec_Master_Log_Pos;
18921993 return new MySQLMasterPos( $row->Relay_Master_Log_File, $pos );
18931994 } else {
18941995 return false;
@@ -1901,8 +2002,10 @@
19022003 if ( $this->mFakeMaster ) {
19032004 return new MySQLMasterPos( 'fake', microtime( true ) );
19042005 }
 2006+
19052007 $res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' );
19062008 $row = $this->fetchObject( $res );
 2009+
19072010 if ( $row ) {
19082011 return new MySQLMasterPos( $row->File, $row->Position );
19092012 } else {
@@ -1922,7 +2025,7 @@
19232026 * End a transaction
19242027 */
19252028 function commit( $fname = 'DatabaseBase::commit' ) {
1926 - if( $this->mTrxLevel ) {
 2029+ if ( $this->mTrxLevel ) {
19272030 $this->query( 'COMMIT', $fname );
19282031 $this->mTrxLevel = 0;
19292032 }
@@ -1933,7 +2036,7 @@
19342037 * No-op on non-transactional databases.
19352038 */
19362039 function rollback( $fname = 'DatabaseBase::rollback' ) {
1937 - if( $this->mTrxLevel ) {
 2040+ if ( $this->mTrxLevel ) {
19382041 $this->query( 'ROLLBACK', $fname, true );
19392042 $this->mTrxLevel = 0;
19402043 }
@@ -1976,8 +2079,8 @@
19772080 /**
19782081 * Return MW-style timestamp used for MySQL schema
19792082 */
1980 - function timestamp( $ts=0 ) {
1981 - return wfTimestamp(TS_MW,$ts);
 2083+ function timestamp( $ts = 0 ) {
 2084+ return wfTimestamp( TS_MW, $ts );
19822085 }
19832086
19842087 /**
@@ -2010,7 +2113,7 @@
20112114 /**
20122115 * Return aggregated value alias
20132116 */
2014 - function aggregateValue ($valuedata,$valuename='value') {
 2117+ function aggregateValue ( $valuedata, $valuename = 'value' ) {
20152118 return $valuename;
20162119 }
20172120
@@ -2036,12 +2139,14 @@
20372140 /**
20382141 * Get status information from SHOW STATUS in an associative array
20392142 */
2040 - function getStatus($which="%") {
 2143+ function getStatus( $which = "%" ) {
20412144 $res = $this->query( "SHOW STATUS LIKE '{$which}'" );
20422145 $status = array();
 2146+
20432147 while ( $row = $this->fetchObject( $res ) ) {
20442148 $status[$row->Variable_name] = $row->Value;
20452149 }
 2150+
20462151 return $status;
20472152 }
20482153
@@ -2052,11 +2157,11 @@
20532158 return 0;
20542159 }
20552160
2056 - function encodeBlob($b) {
 2161+ function encodeBlob( $b ) {
20572162 return $b;
20582163 }
20592164
2060 - function decodeBlob($b) {
 2165+ function decodeBlob( $b ) {
20612166 return $b;
20622167 }
20632168
@@ -2079,17 +2184,19 @@
20802185 */
20812186 function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) {
20822187 $fp = fopen( $filename, 'r' );
 2188+
20832189 if ( false === $fp ) {
2084 - if (!defined("MEDIAWIKI_INSTALL"))
 2190+ if ( !defined( "MEDIAWIKI_INSTALL" ) )
20852191 throw new MWException( "Could not open \"{$filename}\".\n" );
20862192 else
20872193 return "Could not open \"{$filename}\".\n";
20882194 }
 2195+
20892196 try {
20902197 $error = $this->sourceStream( $fp, $lineCallback, $resultCallback );
20912198 }
2092 - catch( MWException $e ) {
2093 - if ( defined("MEDIAWIKI_INSTALL") ) {
 2199+ catch ( MWException $e ) {
 2200+ if ( defined( "MEDIAWIKI_INSTALL" ) ) {
20942201 $error = $e->getMessage();
20952202 } else {
20962203 fclose( $fp );
@@ -2098,6 +2205,7 @@
20992206 }
21002207
21012208 fclose( $fp );
 2209+
21022210 return $error;
21032211 }
21042212
@@ -2111,6 +2219,7 @@
21122220 */
21132221 public static function patchPath( $patch ) {
21142222 global $wgDBtype, $IP;
 2223+
21152224 if ( file_exists( "$IP/maintenance/$wgDBtype/archives/$patch" ) ) {
21162225 return "$IP/maintenance/$wgDBtype/archives/$patch";
21172226 } else {
@@ -2134,19 +2243,21 @@
21352244 if ( $lineCallback ) {
21362245 call_user_func( $lineCallback );
21372246 }
 2247+
21382248 $line = trim( fgets( $fp, 1024 ) );
21392249 $sl = strlen( $line ) - 1;
21402250
21412251 if ( $sl < 0 ) {
21422252 continue;
21432253 }
2144 - if ( '-' == $line{0} && '-' == $line{1} ) {
 2254+
 2255+ if ( '-' == $line { 0 } && '-' == $line { 1 } ) {
21452256 continue;
21462257 }
21472258
2148 - ## Allow dollar quoting for function declarations
2149 - if (substr($line,0,4) == '$mw$') {
2150 - if ($dollarquote) {
 2259+ # # Allow dollar quoting for function declarations
 2260+ if ( substr( $line, 0, 4 ) == '$mw$' ) {
 2261+ if ( $dollarquote ) {
21512262 $dollarquote = false;
21522263 $done = true;
21532264 }
@@ -2154,8 +2265,8 @@
21552266 $dollarquote = true;
21562267 }
21572268 }
2158 - else if (!$dollarquote) {
2159 - if ( ';' == $line{$sl} && ($sl < 2 || ';' != $line{$sl - 1})) {
 2269+ else if ( !$dollarquote ) {
 2270+ if ( ';' == $line { $sl } && ( $sl < 2 || ';' != $line { $sl - 1 } ) ) {
21602271 $done = true;
21612272 $line = substr( $line, 0, $sl );
21622273 }
@@ -2164,12 +2275,14 @@
21652276 if ( $cmd != '' ) {
21662277 $cmd .= ' ';
21672278 }
 2279+
21682280 $cmd .= "$line\n";
21692281
21702282 if ( $done ) {
2171 - $cmd = str_replace(';;', ";", $cmd);
 2283+ $cmd = str_replace( ';;', ";", $cmd );
21722284 $cmd = $this->replaceVars( $cmd );
21732285 $res = $this->query( $cmd, __METHOD__ );
 2286+
21742287 if ( $resultCallback ) {
21752288 call_user_func( $resultCallback, $res, $this );
21762289 }
@@ -2183,10 +2296,10 @@
21842297 $done = false;
21852298 }
21862299 }
 2300+
21872301 return true;
21882302 }
21892303
2190 -
21912304 /**
21922305 * Replace variables in sourced SQL
21932306 */
@@ -2214,6 +2327,7 @@
22152328 // Index names
22162329 $ins = preg_replace_callback( '!/\*i\*/([a-zA-Z_0-9]*)!',
22172330 array( $this, 'indexNameCallback' ), $ins );
 2331+
22182332 return $ins;
22192333 }
22202334
@@ -2314,7 +2428,6 @@
23152429 }
23162430 }
23172431
2318 -
23192432 /******************************************************************************
23202433 * Utility classes
23212434 *****************************************************************************/
@@ -2326,7 +2439,7 @@
23272440 class DBObject {
23282441 public $mData;
23292442
2330 - function __construct($data) {
 2443+ function __construct( $data ) {
23312444 $this->mData = $data;
23322445 }
23332446
@@ -2347,9 +2460,11 @@
23482461 */
23492462 class Blob {
23502463 private $mData;
2351 - function __construct($data) {
 2464+
 2465+ function __construct( $data ) {
23522466 $this->mData = $data;
23532467 }
 2468+
23542469 function fetch() {
23552470 return $this->mData;
23562471 }
@@ -2362,7 +2477,8 @@
23632478 class MySQLField {
23642479 private $name, $tablename, $default, $max_length, $nullable,
23652480 $is_pk, $is_unique, $is_multiple, $is_key, $type;
2366 - function __construct ($info) {
 2481+
 2482+ function __construct ( $info ) {
23672483 $this->name = $info->name;
23682484 $this->tablename = $info->table;
23692485 $this->default = $info->def;
@@ -2371,7 +2487,7 @@
23722488 $this->is_pk = $info->primary_key;
23732489 $this->is_unique = $info->unique_key;
23742490 $this->is_multiple = $info->multiple_key;
2375 - $this->is_key = ($this->is_pk || $this->is_unique || $this->is_multiple);
 2491+ $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
23762492 $this->type = $info->type;
23772493 }
23782494
@@ -2431,10 +2547,13 @@
24322548
24332549 function getText() {
24342550 global $wgShowDBErrorBacktrace;
 2551+
24352552 $s = $this->getMessage() . "\n";
 2553+
24362554 if ( $wgShowDBErrorBacktrace ) {
24372555 $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
24382556 }
 2557+
24392558 return $s;
24402559 }
24412560 }
@@ -2447,10 +2566,13 @@
24482567
24492568 function __construct( DatabaseBase &$db, $error = 'unknown error' ) {
24502569 $msg = 'DB connection error';
 2570+
24512571 if ( trim( $error ) != '' ) {
24522572 $msg .= ": $error";
24532573 }
 2574+
24542575 $this->error = $error;
 2576+
24552577 parent::__construct( $db, $msg );
24562578 }
24572579
@@ -2471,7 +2593,9 @@
24722594
24732595 function getPageTitle() {
24742596 global $wgSitename, $wgLang;
 2597+
24752598 $header = "$wgSitename has a problem";
 2599+
24762600 if ( $wgLang instanceof Language ) {
24772601 $header = htmlspecialchars( $wgLang->getMessage( 'dberr-header' ) );
24782602 }
@@ -2498,7 +2622,7 @@
24992623 }
25002624
25012625 if ( trim( $this->error ) == '' ) {
2502 - $this->error = $this->db->getProperty('mServer');
 2626+ $this->error = $this->db->getProperty( 'mServer' );
25032627 }
25042628
25052629 $noconnect = "<p><strong>$sorry</strong><br />$again</p><p><small>$info</small></p>";
@@ -2510,33 +2634,38 @@
25112635
25122636 $extra = $this->searchForm();
25132637
2514 - if( $wgUseFileCache ) {
 2638+ if ( $wgUseFileCache ) {
25152639 try {
25162640 $cache = $this->fileCachedPage();
25172641 # Cached version on file system?
2518 - if( $cache !== null ) {
 2642+ if ( $cache !== null ) {
25192643 # Hack: extend the body for error messages
2520 - $cache = str_replace( array('</html>','</body>'), '', $cache );
 2644+ $cache = str_replace( array( '</html>', '</body>' ), '', $cache );
25212645 # Add cache notice...
25222646 $cachederror = "This is a cached copy of the requested page, and may not be up to date. ";
 2647+
25232648 # Localize it if possible...
2524 - if( $wgLang instanceof Language ) {
 2649+ if ( $wgLang instanceof Language ) {
25252650 $cachederror = htmlspecialchars( $wgLang->getMessage( 'dberr-cachederror' ) );
25262651 }
 2652+
25272653 $warning = "<div style='color:red;font-size:150%;font-weight:bold;'>$cachederror</div>";
 2654+
25282655 # Output cached page with notices on bottom and re-close body
25292656 return "{$cache}{$warning}<hr />$text<hr />$extra</body></html>";
25302657 }
2531 - } catch( MWException $e ) {
 2658+ } catch ( MWException $e ) {
25322659 // Do nothing, just use the default page
25332660 }
25342661 }
 2662+
25352663 # Headers needed here - output is just the error message
2536 - return $this->htmlHeader()."$text<hr />$extra".$this->htmlFooter();
 2664+ return $this->htmlHeader() . "$text<hr />$extra" . $this->htmlFooter();
25372665 }
25382666
25392667 function searchForm() {
25402668 global $wgSitename, $wgServer, $wgLang, $wgInputEncoding;
 2669+
25412670 $usegoogle = "You can try searching via Google in the meantime.";
25422671 $outofdate = "Note that their indexes of our content may be out of date.";
25432672 $googlesearch = "Search";
@@ -2547,7 +2676,7 @@
25482677 $googlesearch = htmlspecialchars( $wgLang->getMessage( 'searchbutton' ) );
25492678 }
25502679
2551 - $search = htmlspecialchars(@$_REQUEST['search']);
 2680+ $search = htmlspecialchars( @$_REQUEST['search'] );
25522681
25532682 $trygoogle = <<<EOT
25542683 <div style="margin: 1.5em">$usegoogle<br />
@@ -2573,22 +2702,27 @@
25742703
25752704 function fileCachedPage() {
25762705 global $wgTitle, $title, $wgLang, $wgOut;
2577 - if( $wgOut->isDisabled() ) return; // Done already?
 2706+
 2707+ if ( $wgOut->isDisabled() ) {
 2708+ return; // Done already?
 2709+ }
 2710+
25782711 $mainpage = 'Main Page';
 2712+
25792713 if ( $wgLang instanceof Language ) {
25802714 $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) );
25812715 }
25822716
2583 - if( $wgTitle ) {
 2717+ if ( $wgTitle ) {
25842718 $t =& $wgTitle;
2585 - } elseif( $title ) {
 2719+ } elseif ( $title ) {
25862720 $t = Title::newFromURL( $title );
25872721 } else {
25882722 $t = Title::newFromText( $mainpage );
25892723 }
25902724
25912725 $cache = new HTMLFileCache( $t );
2592 - if( $cache->isFileCached() ) {
 2726+ if ( $cache->isFileCached() ) {
25932727 return $cache->fetchPageText();
25942728 } else {
25952729 return '';
@@ -2598,7 +2732,6 @@
25992733 function htmlBodyOnly() {
26002734 return true;
26012735 }
2602 -
26032736 }
26042737
26052738 /**
@@ -2614,6 +2747,7 @@
26152748 "Error: $errno $error\n";
26162749
26172750 parent::__construct( $db, $message );
 2751+
26182752 $this->error = $error;
26192753 $this->errno = $errno;
26202754 $this->sql = $sql;
@@ -2622,12 +2756,15 @@
26232757
26242758 function getText() {
26252759 global $wgShowDBErrorBacktrace;
 2760+
26262761 if ( $this->useMessageCache() ) {
26272762 $s = wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
26282763 htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
 2764+
26292765 if ( $wgShowDBErrorBacktrace ) {
26302766 $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
26312767 }
 2768+
26322769 return $s;
26332770 } else {
26342771 return parent::getText();
@@ -2636,7 +2773,8 @@
26372774
26382775 function getSQL() {
26392776 global $wgShowSQLErrors;
2640 - if( !$wgShowSQLErrors ) {
 2777+
 2778+ if ( !$wgShowSQLErrors ) {
26412779 return $this->msg( 'sqlhidden', 'SQL hidden' );
26422780 } else {
26432781 return $this->sql;
@@ -2654,15 +2792,18 @@
26552793
26562794 function getHTML() {
26572795 global $wgShowDBErrorBacktrace;
 2796+
26582797 if ( $this->useMessageCache() ) {
26592798 $s = wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
26602799 htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) );
26612800 } else {
26622801 $s = nl2br( htmlspecialchars( $this->getMessage() ) );
26632802 }
 2803+
26642804 if ( $wgShowDBErrorBacktrace ) {
26652805 $s .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
26662806 }
 2807+
26672808 return $s;
26682809 }
26692810 }
@@ -2685,6 +2826,7 @@
26862827 */
26872828 function __construct( $database, $result ) {
26882829 $this->db = $database;
 2830+
26892831 if ( $result instanceof ResultWrapper ) {
26902832 $this->result = $result->result;
26912833 } else {
@@ -2746,8 +2888,8 @@
27472889 */
27482890
27492891 function rewind() {
2750 - if ($this->numRows()) {
2751 - $this->db->dataSeek($this, 0);
 2892+ if ( $this->numRows() ) {
 2893+ $this->db->dataSeek( $this, 0 );
27522894 }
27532895 $this->pos = 0;
27542896 $this->currentRow = null;
@@ -2775,17 +2917,17 @@
27762918 }
27772919 }
27782920
2779 -/* Overloads the relevant methods of the real ResultsWrapper so it
 2921+/**
 2922+ * Overloads the relevant methods of the real ResultsWrapper so it
27802923 * doesn't go anywhere near an actual database.
27812924 */
27822925 class FakeResultWrapper extends ResultWrapper {
2783 -
27842926 var $result = array();
27852927 var $db = null; // And it's going to stay that way :D
27862928 var $pos = 0;
27872929 var $currentRow = null;
27882930
2789 - function __construct( $array ){
 2931+ function __construct( $array ) {
27902932 $this->result = $array;
27912933 }
27922934
@@ -2805,7 +2947,7 @@
28062948 function free() {}
28072949
28082950 // Callers want to be able to access fields with $this->fieldName
2809 - function fetchObject(){
 2951+ function fetchObject() {
28102952 $this->currentRow = $this->result[$this->pos++];
28112953 return (object)$this->currentRow;
28122954 }
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -71,6 +71,7 @@
7272 $title = Title::makeTitle( NS_FILE, $row->img_name );
7373 $file = new self( $title, $repo );
7474 $file->loadFromRow( $row );
 75+
7576 return $file;
7677 }
7778
@@ -80,12 +81,15 @@
8182 */
8283 static function newFromKey( $sha1, $repo, $timestamp = false ) {
8384 $conds = array( 'img_sha1' => $sha1 );
84 - if( $timestamp ) {
 85+
 86+ if ( $timestamp ) {
8587 $conds['img_timestamp'] = $timestamp;
8688 }
 89+
8790 $dbr = $repo->getSlaveDB();
8891 $row = $dbr->selectRow( 'image', self::selectFields(), $conds, __METHOD__ );
89 - if( $row ) {
 92+
 93+ if ( $row ) {
9094 return self::newFromRow( $row, $repo );
9195 } else {
9296 return false;
@@ -119,10 +123,12 @@
120124 * Do not call this except from inside a repo class.
121125 */
122126 function __construct( $title, $repo ) {
123 - if( !is_object( $title ) ) {
 127+ if ( !is_object( $title ) ) {
124128 throw new MWException( __CLASS__ . ' constructor given bogus title.' );
125129 }
 130+
126131 parent::__construct( $title, $repo );
 132+
127133 $this->metadata = '';
128134 $this->historyLine = 0;
129135 $this->historyRes = null;
@@ -135,6 +141,7 @@
136142 */
137143 function getCacheKey() {
138144 $hashedName = md5( $this->getName() );
 145+
139146 return $this->repo->getSharedCacheKey( 'file', $hashedName );
140147 }
141148
@@ -143,13 +150,16 @@
144151 */
145152 function loadFromCache() {
146153 global $wgMemc;
 154+
147155 wfProfileIn( __METHOD__ );
148156 $this->dataLoaded = false;
149157 $key = $this->getCacheKey();
 158+
150159 if ( !$key ) {
151160 wfProfileOut( __METHOD__ );
152161 return false;
153162 }
 163+
154164 $cachedValues = $wgMemc->get( $key );
155165
156166 // Check if the key existed and belongs to this version of MediaWiki
@@ -161,6 +171,7 @@
162172 }
163173 $this->dataLoaded = true;
164174 }
 175+
165176 if ( $this->dataLoaded ) {
166177 wfIncrStats( 'image_cache_hit' );
167178 } else {
@@ -176,14 +187,18 @@
177188 */
178189 function saveToCache() {
179190 global $wgMemc;
 191+
180192 $this->load();
181193 $key = $this->getCacheKey();
 194+
182195 if ( !$key ) {
183196 return;
184197 }
 198+
185199 $fields = $this->getCacheFields( '' );
186200 $cache = array( 'version' => MW_FILE_VERSION );
187201 $cache['fileExists'] = $this->fileExists;
 202+
188203 if ( $this->fileExists ) {
189204 foreach ( $fields as $field ) {
190205 $cache[$field] = $this->$field;
@@ -204,9 +219,11 @@
205220 static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
206221 'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text', 'description' );
207222 static $results = array();
 223+
208224 if ( $prefix == '' ) {
209225 return $fields;
210226 }
 227+
211228 if ( !isset( $results[$prefix] ) ) {
212229 $prefixedFields = array();
213230 foreach ( $fields as $field ) {
@@ -214,6 +231,7 @@
215232 }
216233 $results[$prefix] = $prefixedFields;
217234 }
 235+
218236 return $results[$prefix];
219237 }
220238
@@ -232,6 +250,7 @@
233251
234252 $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
235253 array( 'img_name' => $this->getName() ), $fname );
 254+
236255 if ( $row ) {
237256 $this->loadFromRow( $row );
238257 } else {
@@ -248,15 +267,20 @@
249268 function decodeRow( $row, $prefix = 'img_' ) {
250269 $array = (array)$row;
251270 $prefixLength = strlen( $prefix );
 271+
252272 // Sanity check prefix once
253273 if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
254274 throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
255275 }
 276+
256277 $decoded = array();
 278+
257279 foreach ( $array as $name => $value ) {
258280 $decoded[substr( $name, $prefixLength )] = $value;
259281 }
 282+
260283 $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
 284+
261285 if ( empty( $decoded['major_mime'] ) ) {
262286 $decoded['mime'] = 'unknown/unknown';
263287 } else {
@@ -265,8 +289,10 @@
266290 }
267291 $decoded['mime'] = $decoded['major_mime'] . '/' . $decoded['minor_mime'];
268292 }
 293+
269294 # Trim zero padding from char/binary field
270295 $decoded['sha1'] = rtrim( $decoded['sha1'], "\0" );
 296+
271297 return $decoded;
272298 }
273299
@@ -276,9 +302,11 @@
277303 function loadFromRow( $row, $prefix = 'img_' ) {
278304 $this->dataLoaded = true;
279305 $array = $this->decodeRow( $row, $prefix );
 306+
280307 foreach ( $array as $name => $value ) {
281308 $this->$name = $value;
282309 }
 310+
283311 $this->fileExists = true;
284312 $this->maybeUpgradeRow();
285313 }
@@ -303,6 +331,7 @@
304332 if ( wfReadOnly() ) {
305333 return;
306334 }
 335+
307336 if ( is_null( $this->media_type ) ||
308337 $this->mime == 'image/svg'
309338 ) {
@@ -335,6 +364,7 @@
336365 wfProfileOut( __METHOD__ );
337366 return;
338367 }
 368+
339369 $dbw = $this->repo->getMasterDB();
340370 list( $major, $minor ) = self::splitMime( $this->mime );
341371
@@ -357,6 +387,7 @@
358388 ), array( 'img_name' => $this->getName() ),
359389 __METHOD__
360390 );
 391+
361392 $this->saveToCache();
362393 wfProfileOut( __METHOD__ );
363394 }
@@ -372,6 +403,7 @@
373404 $this->dataLoaded = true;
374405 $fields = $this->getCacheFields( '' );
375406 $fields[] = 'fileExists';
 407+
376408 foreach ( $fields as $field ) {
377409 if ( isset( $info[$field] ) ) {
378410 $this->$field = $info[$field];
@@ -396,7 +428,7 @@
397429 /** isVisible inhereted */
398430
399431 function isMissing() {
400 - if( $this->missing === null ) {
 432+ if ( $this->missing === null ) {
401433 list( $fileExists ) = $this->repo->fileExistsBatch( array( $this->getVirtualUrl() ), FileRepo::FILES_ONLY );
402434 $this->missing = !$fileExists;
403435 }
@@ -410,6 +442,7 @@
411443 */
412444 public function getWidth( $page = 1 ) {
413445 $this->load();
 446+
414447 if ( $this->isMultipage() ) {
415448 $dim = $this->getHandler()->getPageDimensions( $this, $page );
416449 if ( $dim ) {
@@ -429,6 +462,7 @@
430463 */
431464 public function getHeight( $page = 1 ) {
432465 $this->load();
 466+
433467 if ( $this->isMultipage() ) {
434468 $dim = $this->getHandler()->getPageDimensions( $this, $page );
435469 if ( $dim ) {
@@ -448,9 +482,10 @@
449483 */
450484 function getUser( $type = 'text' ) {
451485 $this->load();
452 - if( $type == 'text' ) {
 486+
 487+ if ( $type == 'text' ) {
453488 return $this->user_text;
454 - } elseif( $type == 'id' ) {
 489+ } elseif ( $type == 'id' ) {
455490 return $this->user;
456491 }
457492 }
@@ -521,6 +556,7 @@
522557 function migrateThumbFile( $thumbName ) {
523558 $thumbDir = $this->getThumbPath();
524559 $thumbPath = "$thumbDir/$thumbName";
 560+
525561 if ( is_dir( $thumbPath ) ) {
526562 // Directory where file should be
527563 // This happened occasionally due to broken migration code in 1.5
@@ -535,6 +571,7 @@
536572 // Doesn't exist anymore
537573 clearstatcache();
538574 }
 575+
539576 if ( is_file( $thumbDir ) ) {
540577 // File where directory should be
541578 unlink( $thumbDir );
@@ -552,6 +589,7 @@
553590 */
554591 function getThumbnails() {
555592 $this->load();
 593+
556594 $files = array();
557595 $dir = $this->getThumbPath();
558596
@@ -560,10 +598,11 @@
561599
562600 if ( $handle ) {
563601 while ( false !== ( $file = readdir( $handle ) ) ) {
564 - if ( $file{0} != '.' ) {
 602+ if ( $file { 0 } != '.' ) {
565603 $files[] = $file;
566604 }
567605 }
 606+
568607 closedir( $handle );
569608 }
570609 }
@@ -585,8 +624,10 @@
586625 */
587626 function purgeHistory() {
588627 global $wgMemc;
 628+
589629 $hashedName = md5( $this->getName() );
590630 $oldKey = $this->repo->getSharedCacheKey( 'oldfile', $hashedName );
 631+
591632 if ( $oldKey ) {
592633 $wgMemc->delete( $oldKey );
593634 }
@@ -611,10 +652,12 @@
612653 */
613654 function purgeThumbnails() {
614655 global $wgUseSquid;
 656+
615657 // Delete thumbnails
616658 $files = $this->getThumbnails();
617659 $dir = $this->getThumbPath();
618660 $urls = array();
 661+
619662 foreach ( $files as $file ) {
620663 # Check that the base file name is part of the thumb name
621664 # This is a basic sanity check to avoid erasing unrelated directories
@@ -641,15 +684,19 @@
642685 $conds = $opts = $join_conds = array();
643686 $eq = $inc ? '=' : '';
644687 $conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() );
645 - if( $start ) {
 688+
 689+ if ( $start ) {
646690 $conds[] = "oi_timestamp <$eq " . $dbr->addQuotes( $dbr->timestamp( $start ) );
647691 }
648 - if( $end ) {
 692+
 693+ if ( $end ) {
649694 $conds[] = "oi_timestamp >$eq " . $dbr->addQuotes( $dbr->timestamp( $end ) );
650695 }
651 - if( $limit ) {
 696+
 697+ if ( $limit ) {
652698 $opts['LIMIT'] = $limit;
653699 }
 700+
654701 // Search backwards for time > x queries
655702 $order = ( !$start && $end !== null ) ? 'ASC' : 'DESC';
656703 $opts['ORDER BY'] = "oi_timestamp $order";
@@ -660,16 +707,19 @@
661708
662709 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
663710 $r = array();
664 - while( $row = $dbr->fetchObject( $res ) ) {
 711+
 712+ while ( $row = $dbr->fetchObject( $res ) ) {
665713 if ( $this->repo->oldFileFromRowFactory ) {
666714 $r[] = call_user_func( $this->repo->oldFileFromRowFactory, $row, $this->repo );
667715 } else {
668716 $r[] = OldLocalFile::newFromRow( $row, $this->repo );
669717 }
670718 }
671 - if( $order == 'ASC' ) {
 719+
 720+ if ( $order == 'ASC' ) {
672721 $r = array_reverse( $r ); // make sure it ends up descending
673722 }
 723+
674724 return $r;
675725 }
676726
@@ -698,6 +748,7 @@
699749 array( 'img_name' => $this->title->getDBkey() ),
700750 $fname
701751 );
 752+
702753 if ( 0 == $dbr->numRows( $this->historyRes ) ) {
703754 $this->historyRes = null;
704755 return false;
@@ -719,6 +770,7 @@
720771 */
721772 public function resetHistory() {
722773 $this->historyLine = 0;
 774+
723775 if ( !is_null( $this->historyRes ) ) {
724776 $this->historyRes = null;
725777 }
@@ -757,12 +809,15 @@
758810 function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null ) {
759811 $this->lock();
760812 $status = $this->publish( $srcPath, $flags );
 813+
761814 if ( $status->ok ) {
762815 if ( !$this->recordUpload2( $status->value, $comment, $pageText, $props, $timestamp, $user ) ) {
763816 $status->fatal( 'filenotfound', $srcPath );
764817 }
765818 }
 819+
766820 $this->unlock();
 821+
767822 return $status;
768823 }
769824
@@ -774,9 +829,11 @@
775830 $watch = false, $timestamp = false )
776831 {
777832 $pageText = SpecialUpload::getInitialPageText( $desc, $license, $copyStatus, $source );
 833+
778834 if ( !$this->recordUpload2( $oldver, $desc, $pageText ) ) {
779835 return false;
780836 }
 837+
781838 if ( $watch ) {
782839 global $wgUser;
783840 $wgUser->addWatch( $this->getTitle() );
@@ -790,7 +847,7 @@
791848 */
792849 function recordUpload2( $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null )
793850 {
794 - if( is_null( $user ) ) {
 851+ if ( is_null( $user ) ) {
795852 global $wgUser;
796853 $user = $wgUser;
797854 }
@@ -801,6 +858,7 @@
802859 if ( !$props ) {
803860 $props = $this->repo->getFileProps( $this->getVirtualUrl() );
804861 }
 862+
805863 $props['description'] = $comment;
806864 $props['user'] = $user->getId();
807865 $props['user_text'] = $user->getName();
@@ -809,6 +867,7 @@
810868
811869 # Delete thumbnails
812870 $this->purgeThumbnails();
 871+
813872 # The file is already on its final location, remove it from the squid cache
814873 SquidUpdate::purge( array( $this->getURL() ) );
815874
@@ -819,6 +878,7 @@
820879 }
821880
822881 $reupload = false;
 882+
823883 if ( $timestamp === false ) {
824884 $timestamp = $dbw->timestamp();
825885 }
@@ -829,7 +889,7 @@
830890 $dbw->insert( 'image',
831891 array(
832892 'img_name' => $this->getName(),
833 - 'img_size'=> $this->size,
 893+ 'img_size' => $this->size,
834894 'img_width' => intval( $this->width ),
835895 'img_height' => intval( $this->height ),
836896 'img_bits' => $this->bits,
@@ -847,7 +907,7 @@
848908 'IGNORE'
849909 );
850910
851 - if( $dbw->affectedRows() == 0 ) {
 911+ if ( $dbw->affectedRows() == 0 ) {
852912 $reupload = true;
853913
854914 # Collision, this is an update of a file
@@ -908,11 +968,15 @@
909969 $action = $reupload ? 'overwrite' : 'upload';
910970 $log->addEntry( $action, $descTitle, $comment, array(), $user );
911971
912 - if( $descTitle->exists() ) {
 972+ if ( $descTitle->exists() ) {
913973 # Create a null revision
914974 $latest = $descTitle->getLatestRevID();
915 - $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(),
916 - $log->getRcComment(), false );
 975+ $nullRevision = Revision::newNullRevision(
 976+ $dbw,
 977+ $descTitle->getArticleId(),
 978+ $log->getRcComment(),
 979+ false
 980+ );
917981 $nullRevision->insertOn( $dbw );
918982
919983 wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $user ) );
@@ -937,16 +1001,18 @@
9381002 # in case of a rollback there is an usable file from memcached
9391003 # which in fact doesn't really exist (bug 24978)
9401004 $this->saveToCache();
941 -
 1005+
9421006 # Hooks, hooks, the magic of hooks...
9431007 wfRunHooks( 'FileUpload', array( $this, $reupload, $descTitle->exists() ) );
9441008
9451009 # Invalidate cache for all pages using this file
9461010 $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
9471011 $update->doUpdate();
 1012+
9481013 # Invalidate cache for all pages that redirects on this page
9491014 $redirs = $this->getTitle()->getRedirectsHere();
950 - foreach( $redirs as $redir ) {
 1015+
 1016+ foreach ( $redirs as $redir ) {
9511017 $update = new HTMLCacheUpdate( $redir, 'imagelinks' );
9521018 $update->doUpdate();
9531019 }
@@ -971,17 +1037,21 @@
9721038 */
9731039 function publish( $srcPath, $flags = 0 ) {
9741040 $this->lock();
 1041+
9751042 $dstRel = $this->getRel();
976 - $archiveName = gmdate( 'YmdHis' ) . '!'. $this->getName();
 1043+ $archiveName = gmdate( 'YmdHis' ) . '!' . $this->getName();
9771044 $archiveRel = 'archive/' . $this->getHashPath() . $archiveName;
9781045 $flags = $flags & File::DELETE_SOURCE ? LocalRepo::DELETE_SOURCE : 0;
9791046 $status = $this->repo->publish( $srcPath, $dstRel, $archiveRel, $flags );
 1047+
9801048 if ( $status->value == 'new' ) {
9811049 $status->value = '';
9821050 } else {
9831051 $status->value = $archiveName;
9841052 }
 1053+
9851054 $this->unlock();
 1055+
9861056 return $status;
9871057 }
9881058
@@ -1005,12 +1075,14 @@
10061076 function move( $target ) {
10071077 wfDebugLog( 'imagemove', "Got request to move {$this->name} to " . $target->getText() );
10081078 $this->lock();
 1079+
10091080 $batch = new LocalFileMoveBatch( $this, $target );
10101081 $batch->addCurrent();
10111082 $batch->addOlds();
10121083
10131084 $status = $batch->execute();
10141085 wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
 1086+
10151087 $this->purgeEverything();
10161088 $this->unlock();
10171089
@@ -1041,6 +1113,7 @@
10421114 */
10431115 function delete( $reason, $suppress = false ) {
10441116 $this->lock();
 1117+
10451118 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
10461119 $batch->addCurrent();
10471120
@@ -1062,6 +1135,7 @@
10631136 }
10641137
10651138 $this->unlock();
 1139+
10661140 return $status;
10671141 }
10681142
@@ -1079,16 +1153,20 @@
10801154 * @throws MWException or FSException on database or file store failure
10811155 * @return FileRepoStatus object.
10821156 */
1083 - function deleteOld( $archiveName, $reason, $suppress=false ) {
 1157+ function deleteOld( $archiveName, $reason, $suppress = false ) {
10841158 $this->lock();
 1159+
10851160 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
10861161 $batch->addOld( $archiveName );
10871162 $status = $batch->execute();
 1163+
10881164 $this->unlock();
 1165+
10891166 if ( $status->ok ) {
10901167 $this->purgeDescription();
10911168 $this->purgeHistory();
10921169 }
 1170+
10931171 return $status;
10941172 }
10951173
@@ -1105,12 +1183,15 @@
11061184 */
11071185 function restore( $versions = array(), $unsuppress = false ) {
11081186 $batch = new LocalFileRestoreBatch( $this, $unsuppress );
 1187+
11091188 if ( !$versions ) {
11101189 $batch->addAll();
11111190 } else {
11121191 $batch->addIds( $versions );
11131192 }
 1193+
11141194 $status = $batch->execute();
 1195+
11151196 if ( !$status->ok ) {
11161197 return $status;
11171198 }
@@ -1119,6 +1200,7 @@
11201201 $cleanupStatus->successCount = 0;
11211202 $cleanupStatus->failCount = 0;
11221203 $status->merge( $cleanupStatus );
 1204+
11231205 return $status;
11241206 }
11251207
@@ -1165,10 +1247,12 @@
11661248 */
11671249 function lock() {
11681250 $dbw = $this->repo->getMasterDB();
 1251+
11691252 if ( !$this->locked ) {
11701253 $dbw->begin();
11711254 $this->locked++;
11721255 }
 1256+
11731257 return $dbw->selectField( 'image', '1', array( 'img_name' => $this->getName() ), __METHOD__ );
11741258 }
11751259
@@ -1196,7 +1280,7 @@
11971281 }
11981282 } // LocalFile class
11991283
1200 -#------------------------------------------------------------------------------
 1284+# ------------------------------------------------------------------------------
12011285
12021286 /**
12031287 * Helper class for file deletion
@@ -1231,25 +1315,33 @@
12321316 unset( $oldRels['.'] );
12331317 $deleteCurrent = true;
12341318 }
 1319+
12351320 return array( $oldRels, $deleteCurrent );
12361321 }
12371322
12381323 /*protected*/ function getHashes() {
12391324 $hashes = array();
12401325 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
 1326+
12411327 if ( $deleteCurrent ) {
12421328 $hashes['.'] = $this->file->getSha1();
12431329 }
 1330+
12441331 if ( count( $oldRels ) ) {
12451332 $dbw = $this->file->repo->getMasterDB();
1246 - $res = $dbw->select( 'oldimage', array( 'oi_archive_name', 'oi_sha1' ),
1247 - 'oi_archive_name IN(' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
1248 - __METHOD__ );
 1333+ $res = $dbw->select(
 1334+ 'oldimage',
 1335+ array( 'oi_archive_name', 'oi_sha1' ),
 1336+ 'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
 1337+ __METHOD__
 1338+ );
 1339+
12491340 while ( $row = $dbw->fetchObject( $res ) ) {
12501341 if ( rtrim( $row->oi_sha1, "\0" ) === '' ) {
12511342 // Get the hash from the file
12521343 $oldUrl = $this->file->getArchiveVirtualUrl( $row->oi_archive_name );
12531344 $props = $this->file->repo->getFileProps( $oldUrl );
 1345+
12541346 if ( $props['fileExists'] ) {
12551347 // Upgrade the oldimage row
12561348 $dbw->update( 'oldimage',
@@ -1265,10 +1357,13 @@
12661358 }
12671359 }
12681360 }
 1361+
12691362 $missing = array_diff_key( $this->srcRels, $hashes );
 1363+
12701364 foreach ( $missing as $name => $rel ) {
12711365 $this->status->error( 'filedelete-old-unregistered', $name );
12721366 }
 1367+
12731368 foreach ( $hashes as $name => $hash ) {
12741369 if ( !$hash ) {
12751370 $this->status->error( 'filedelete-missing', $this->srcRels[$name] );
@@ -1281,6 +1376,7 @@
12821377
12831378 function doDBInserts() {
12841379 global $wgUser;
 1380+
12851381 $dbw = $this->file->repo->getMasterDB();
12861382 $encTimestamp = $dbw->addQuotes( $dbw->timestamp() );
12871383 $encUserId = $dbw->addQuotes( $wgUser->getId() );
@@ -1368,6 +1464,7 @@
13691465 function doDBDeletes() {
13701466 $dbw = $this->file->repo->getMasterDB();
13711467 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
 1468+
13721469 if ( count( $oldRels ) ) {
13731470 $dbw->delete( 'oldimage',
13741471 array(
@@ -1375,6 +1472,7 @@
13761473 'oi_archive_name' => array_keys( $oldRels )
13771474 ), __METHOD__ );
13781475 }
 1476+
13791477 if ( $deleteCurrent ) {
13801478 $dbw->delete( 'image', array( 'img_name' => $this->file->getName() ), __METHOD__ );
13811479 }
@@ -1392,14 +1490,16 @@
13931491 $privateFiles = array();
13941492 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
13951493 $dbw = $this->file->repo->getMasterDB();
1396 - if( !empty( $oldRels ) ) {
 1494+
 1495+ if ( !empty( $oldRels ) ) {
13971496 $res = $dbw->select( 'oldimage',
13981497 array( 'oi_archive_name' ),
13991498 array( 'oi_name' => $this->file->getName(),
1400 - 'oi_archive_name IN (' . $dbw->makeList( array_keys($oldRels) ) . ')',
1401 - $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE ),
 1499+ 'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
 1500+ $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE ),
14021501 __METHOD__ );
1403 - while( $row = $dbw->fetchObject( $res ) ) {
 1502+
 1503+ while ( $row = $dbw->fetchObject( $res ) ) {
14041504 $privateFiles[$row->oi_archive_name] = 1;
14051505 }
14061506 }
@@ -1408,6 +1508,7 @@
14091509 $this->deletionBatch = array();
14101510 $ext = $this->file->getExtension();
14111511 $dotExt = $ext === '' ? '' : ".$ext";
 1512+
14121513 foreach ( $this->srcRels as $name => $srcRel ) {
14131514 // Skip files that have no hash (missing source).
14141515 // Keep private files where they are.
@@ -1432,6 +1533,7 @@
14331534
14341535 // Execute the file deletion batch
14351536 $status = $this->file->repo->deleteBatch( $this->deletionBatch );
 1537+
14361538 if ( !$status->isGood() ) {
14371539 $this->status->merge( $status );
14381540 }
@@ -1448,6 +1550,7 @@
14491551 // Purge squid
14501552 if ( $wgUseSquid ) {
14511553 $urls = array();
 1554+
14521555 foreach ( $this->srcRels as $srcRel ) {
14531556 $urlRel = str_replace( '%2F', '/', rawurlencode( $srcRel ) );
14541557 $urls[] = $this->file->repo->getZoneUrl( 'public' ) . '/' . $urlRel;
@@ -1461,6 +1564,7 @@
14621565 // Commit and return
14631566 $this->file->unlock();
14641567 wfProfileOut( __METHOD__ );
 1568+
14651569 return $this->status;
14661570 }
14671571
@@ -1469,19 +1573,25 @@
14701574 */
14711575 function removeNonexistentFiles( $batch ) {
14721576 $files = $newBatch = array();
1473 - foreach( $batch as $batchItem ) {
 1577+
 1578+ foreach ( $batch as $batchItem ) {
14741579 list( $src, $dest ) = $batchItem;
14751580 $files[$src] = $this->file->repo->getVirtualUrl( 'public' ) . '/' . rawurlencode( $src );
14761581 }
 1582+
14771583 $result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
1478 - foreach( $batch as $batchItem )
1479 - if( $result[$batchItem[0]] )
 1584+
 1585+ foreach ( $batch as $batchItem ) {
 1586+ if ( $result[$batchItem[0]] ) {
14801587 $newBatch[] = $batchItem;
 1588+ }
 1589+ }
 1590+
14811591 return $newBatch;
14821592 }
14831593 }
14841594
1485 -#------------------------------------------------------------------------------
 1595+# ------------------------------------------------------------------------------
14861596
14871597 /**
14881598 * Helper class for file undeletion
@@ -1527,6 +1637,7 @@
15281638 */
15291639 function execute() {
15301640 global $wgLang;
 1641+
15311642 if ( !$this->all && !$this->ids ) {
15321643 // Do nothing
15331644 return $this->file->repo->newGood();
@@ -1539,7 +1650,8 @@
15401651 // Fetch all or selected archived revisions for the file,
15411652 // sorted from the most recent to the oldest.
15421653 $conditions = array( 'fa_name' => $this->file->getName() );
1543 - if( !$this->all ) {
 1654+
 1655+ if ( !$this->all ) {
15441656 $conditions[] = 'fa_id IN (' . $dbw->makeList( $this->ids ) . ')';
15451657 }
15461658
@@ -1556,7 +1668,8 @@
15571669 $deleteIds = array();
15581670 $first = true;
15591671 $archiveNames = array();
1560 - while( $row = $dbw->fetchObject( $result ) ) {
 1672+
 1673+ while ( $row = $dbw->fetchObject( $result ) ) {
15611674 $idsPresent[] = $row->fa_id;
15621675
15631676 if ( $row->fa_name != $this->file->getName() ) {
@@ -1564,6 +1677,7 @@
15651678 $status->failCount++;
15661679 continue;
15671680 }
 1681+
15681682 if ( $row->fa_storage_key == '' ) {
15691683 // Revision was missing pre-deletion
15701684 $status->error( 'undelete-bad-store-key', $wgLang->timeanddate( $row->fa_timestamp ) );
@@ -1575,12 +1689,13 @@
15761690 $deletedUrl = $this->file->repo->getVirtualUrl() . '/deleted/' . $deletedRel;
15771691
15781692 $sha1 = substr( $row->fa_storage_key, 0, strcspn( $row->fa_storage_key, '.' ) );
 1693+
15791694 # Fix leading zero
15801695 if ( strlen( $sha1 ) == 32 && $sha1[0] == '0' ) {
15811696 $sha1 = substr( $sha1, 1 );
15821697 }
15831698
1584 - if( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown'
 1699+ if ( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown'
15851700 || is_null( $row->fa_minor_mime ) || $row->fa_minor_mime == 'unknown'
15861701 || is_null( $row->fa_media_type ) || $row->fa_media_type == 'UNKNOWN'
15871702 || is_null( $row->fa_metadata ) ) {
@@ -1615,23 +1730,27 @@
16161731 'img_timestamp' => $row->fa_timestamp,
16171732 'img_sha1' => $sha1
16181733 );
 1734+
16191735 // The live (current) version cannot be hidden!
1620 - if( !$this->unsuppress && $row->fa_deleted ) {
 1736+ if ( !$this->unsuppress && $row->fa_deleted ) {
16211737 $storeBatch[] = array( $deletedUrl, 'public', $destRel );
16221738 $this->cleanupBatch[] = $row->fa_storage_key;
16231739 }
16241740 } else {
16251741 $archiveName = $row->fa_archive_name;
1626 - if( $archiveName == '' ) {
 1742+
 1743+ if ( $archiveName == '' ) {
16271744 // This was originally a current version; we
16281745 // have to devise a new archive name for it.
16291746 // Format is <timestamp of archiving>!<name>
16301747 $timestamp = wfTimestamp( TS_UNIX, $row->fa_deleted_timestamp );
 1748+
16311749 do {
16321750 $archiveName = wfTimestamp( TS_MW, $timestamp ) . '!' . $row->fa_name;
16331751 $timestamp++;
16341752 } while ( isset( $archiveNames[$archiveName] ) );
16351753 }
 1754+
16361755 $archiveNames[$archiveName] = true;
16371756 $destRel = $this->file->getArchiveRel( $archiveName );
16381757 $insertBatch[] = array(
@@ -1654,19 +1773,23 @@
16551774 }
16561775
16571776 $deleteIds[] = $row->fa_id;
1658 - if( !$this->unsuppress && $row->fa_deleted & File::DELETED_FILE ) {
 1777+
 1778+ if ( !$this->unsuppress && $row->fa_deleted & File::DELETED_FILE ) {
16591779 // private files can stay where they are
16601780 $status->successCount++;
16611781 } else {
16621782 $storeBatch[] = array( $deletedUrl, 'public', $destRel );
16631783 $this->cleanupBatch[] = $row->fa_storage_key;
16641784 }
 1785+
16651786 $first = false;
16661787 }
 1788+
16671789 unset( $result );
16681790
16691791 // Add a warning to the status object for missing IDs
16701792 $missingIds = array_diff( $this->ids, $idsPresent );
 1793+
16711794 foreach ( $missingIds as $id ) {
16721795 $status->error( 'undelete-missing-filearchive', $id );
16731796 }
@@ -1683,6 +1806,7 @@
16841807 // Store batch returned a critical error -- this usually means nothing was stored
16851808 // Stop now and return an error
16861809 $this->file->unlock();
 1810+
16871811 return $status;
16881812 }
16891813
@@ -1695,9 +1819,11 @@
16961820 if ( $insertCurrent ) {
16971821 $dbw->insert( 'image', $insertCurrent, __METHOD__ );
16981822 }
 1823+
16991824 if ( $insertBatch ) {
17001825 $dbw->insert( 'oldimage', $insertBatch, __METHOD__ );
17011826 }
 1827+
17021828 if ( $deleteIds ) {
17031829 $dbw->delete( 'filearchive',
17041830 array( 'fa_id IN (' . $dbw->makeList( $deleteIds ) . ')' ),
@@ -1705,8 +1831,8 @@
17061832 }
17071833
17081834 // If store batch is empty (all files are missing), deletion is to be considered successful
1709 - if( $status->successCount > 0 || !$storeBatch ) {
1710 - if( !$exists ) {
 1835+ if ( $status->successCount > 0 || !$storeBatch ) {
 1836+ if ( !$exists ) {
17111837 wfDebug( __METHOD__ . " restored {$status->successCount} items, creating a new current\n" );
17121838
17131839 // Update site_stats
@@ -1720,7 +1846,9 @@
17211847 $this->file->purgeHistory();
17221848 }
17231849 }
 1850+
17241851 $this->file->unlock();
 1852+
17251853 return $status;
17261854 }
17271855
@@ -1729,12 +1857,17 @@
17301858 */
17311859 function removeNonexistentFiles( $triplets ) {
17321860 $files = $filteredTriplets = array();
1733 - foreach( $triplets as $file )
 1861+ foreach ( $triplets as $file )
17341862 $files[$file[0]] = $file[0];
 1863+
17351864 $result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
1736 - foreach( $triplets as $file )
1737 - if( $result[$file[0]] )
 1865+
 1866+ foreach ( $triplets as $file ) {
 1867+ if ( $result[$file[0]] ) {
17381868 $filteredTriplets[] = $file;
 1869+ }
 1870+ }
 1871+
17391872 return $filteredTriplets;
17401873 }
17411874
@@ -1744,15 +1877,20 @@
17451878 function removeNonexistentFromCleanup( $batch ) {
17461879 $files = $newBatch = array();
17471880 $repo = $this->file->repo;
1748 - foreach( $batch as $file ) {
 1881+
 1882+ foreach ( $batch as $file ) {
17491883 $files[$file] = $repo->getVirtualUrl( 'deleted' ) . '/' .
17501884 rawurlencode( $repo->getDeletedHashPath( $file ) . $file );
17511885 }
17521886
17531887 $result = $repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
1754 - foreach( $batch as $file )
1755 - if( $result[$file] )
 1888+
 1889+ foreach ( $batch as $file ) {
 1890+ if ( $result[$file] ) {
17561891 $newBatch[] = $file;
 1892+ }
 1893+ }
 1894+
17571895 return $newBatch;
17581896 }
17591897
@@ -1764,13 +1902,16 @@
17651903 if ( !$this->cleanupBatch ) {
17661904 return $this->file->repo->newGood();
17671905 }
 1906+
17681907 $this->cleanupBatch = $this->removeNonexistentFromCleanup( $this->cleanupBatch );
 1908+
17691909 $status = $this->file->repo->cleanupDeletedBatch( $this->cleanupBatch );
 1910+
17701911 return $status;
17711912 }
17721913 }
17731914
1774 -#------------------------------------------------------------------------------
 1915+# ------------------------------------------------------------------------------
17751916
17761917 /**
17771918 * Helper class for file movement
@@ -1811,23 +1952,30 @@
18121953 array( 'oi_name' => $this->oldName ),
18131954 __METHOD__
18141955 );
1815 - while( $row = $this->db->fetchObject( $result ) ) {
 1956+
 1957+ while ( $row = $this->db->fetchObject( $result ) ) {
18161958 $oldName = $row->oi_archive_name;
18171959 $bits = explode( '!', $oldName, 2 );
1818 - if( count( $bits ) != 2 ) {
 1960+
 1961+ if ( count( $bits ) != 2 ) {
18191962 wfDebug( "Invalid old file name: $oldName \n" );
18201963 continue;
18211964 }
 1965+
18221966 list( $timestamp, $filename ) = $bits;
1823 - if( $this->oldName != $filename ) {
 1967+
 1968+ if ( $this->oldName != $filename ) {
18241969 wfDebug( "Invalid old file name: $oldName \n" );
18251970 continue;
18261971 }
 1972+
18271973 $this->oldCount++;
 1974+
18281975 // Do we want to add those to oldCount?
1829 - if( $row->oi_deleted & File::DELETED_FILE ) {
 1976+ if ( $row->oi_deleted & File::DELETED_FILE ) {
18301977 continue;
18311978 }
 1979+
18321980 $this->olds[] = array(
18331981 "{$archiveBase}/{$this->oldHash}{$oldName}",
18341982 "{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
@@ -1848,13 +1996,15 @@
18491997 wfDebugLog( 'imagemove', "Renamed {$this->file->name} in database: {$statusDb->successCount} successes, {$statusDb->failCount} failures" );
18501998 $statusMove = $repo->storeBatch( $triplets, FSRepo::DELETE_SOURCE );
18511999 wfDebugLog( 'imagemove', "Moved files for {$this->file->name}: {$statusMove->successCount} successes, {$statusMove->failCount} failures" );
1852 - if( !$statusMove->isOk() ) {
 2000+
 2001+ if ( !$statusMove->isOk() ) {
18532002 wfDebugLog( 'imagemove', "Error in moving files: " . $statusMove->getWikiText() );
18542003 $this->db->rollback();
18552004 }
18562005
18572006 $status->merge( $statusDb );
18582007 $status->merge( $statusMove );
 2008+
18592009 return $status;
18602010 }
18612011
@@ -1876,7 +2026,8 @@
18772027 array( 'img_name' => $this->oldName ),
18782028 __METHOD__
18792029 );
1880 - if( $dbw->affectedRows() ) {
 2030+
 2031+ if ( $dbw->affectedRows() ) {
18812032 $status->successCount++;
18822033 } else {
18832034 $status->failCount++;
@@ -1887,11 +2038,12 @@
18882039 'oldimage',
18892040 array(
18902041 'oi_name' => $this->newName,
1891 - 'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name', $dbw->addQuotes($this->oldName), $dbw->addQuotes($this->newName) ),
 2042+ 'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name', $dbw->addQuotes( $this->oldName ), $dbw->addQuotes( $this->newName ) ),
18922043 ),
18932044 array( 'oi_name' => $this->oldName ),
18942045 __METHOD__
18952046 );
 2047+
18962048 $affected = $dbw->affectedRows();
18972049 $total = $this->oldCount;
18982050 $status->successCount += $affected;
@@ -1906,12 +2058,14 @@
19072059 function getMoveTriplets() {
19082060 $moves = array_merge( array( $this->cur ), $this->olds );
19092061 $triplets = array(); // The format is: (srcUrl, destZone, destUrl)
1910 - foreach( $moves as $move ) {
 2062+
 2063+ foreach ( $moves as $move ) {
19112064 // $move: (oldRelativePath, newRelativePath)
19122065 $srcUrl = $this->file->repo->getVirtualUrl() . '/public/' . rawurlencode( $move[0] );
19132066 $triplets[] = array( $srcUrl, 'public', $move[1] );
19142067 wfDebugLog( 'imagemove', "Generated move triplet for {$this->file->name}: {$srcUrl} :: public :: {$move[1]}" );
19152068 }
 2069+
19162070 return $triplets;
19172071 }
19182072
@@ -1920,16 +2074,22 @@
19212075 */
19222076 function removeNonexistentFiles( $triplets ) {
19232077 $files = array();
1924 - foreach( $triplets as $file )
 2078+
 2079+ foreach ( $triplets as $file ) {
19252080 $files[$file[0]] = $file[0];
 2081+ }
 2082+
19262083 $result = $this->file->repo->fileExistsBatch( $files, FSRepo::FILES_ONLY );
19272084 $filteredTriplets = array();
1928 - foreach( $triplets as $file )
1929 - if( $result[$file[0]] ) {
 2085+
 2086+ foreach ( $triplets as $file ) {
 2087+ if ( $result[$file[0]] ) {
19302088 $filteredTriplets[] = $file;
19312089 } else {
19322090 wfDebugLog( 'imagemove', "File {$file[0]} does not exist" );
19332091 }
 2092+ }
 2093+
19342094 return $filteredTriplets;
19352095 }
19362096 }
Index: trunk/phase3/includes/installer/CliInstaller.php
@@ -101,14 +101,14 @@
102102 $this->showStatusMessage( $status );
103103 echo "\n";
104104 exit;
105 - } elseif ( count($warnings) !== 0 ) {
 105+ } elseif ( count( $warnings ) !== 0 ) {
106106 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
107107 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
108108 wfMsg( 'word-separator' ) );
109109 }
110110 }
111111
112 - $this->showMessage( wfMsg( 'config-install-step-done' ) ."\n");
 112+ $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
113113 }
114114
115115 public function showMessage( $msg /*, ... */ ) {
@@ -119,5 +119,4 @@
120120 public function showStatusMessage( Status $status ) {
121121 $this->showMessage( $status->getWikiText() );
122122 }
123 -
124 -}
\ No newline at end of file
 123+}
Index: trunk/phase3/includes/HttpFunctions.php
@@ -35,11 +35,14 @@
3636 $url = wfExpandUrl( $url );
3737 wfDebug( "HTTP: $method: $url\n" );
3838 $options['method'] = strtoupper( $method );
 39+
3940 if ( !isset( $options['timeout'] ) ) {
4041 $options['timeout'] = 'default';
4142 }
 43+
4244 $req = HttpRequest::factory( $url, $options );
4345 $status = $req->execute();
 46+
4447 if ( $status->isOK() ) {
4548 return $req->getContent();
4649 } else {
@@ -72,6 +75,7 @@
7376 */
7477 public static function isLocalURL( $url ) {
7578 global $wgCommandLineMode, $wgConf;
 79+
7680 if ( $wgCommandLineMode ) {
7781 return false;
7882 }
@@ -84,6 +88,7 @@
8589 $domainParts = explode( '.', $host );
8690 // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
8791 $domainParts = array_reverse( $domainParts );
 92+
8893 for ( $i = 0; $i < count( $domainParts ); $i++ ) {
8994 $domainPart = $domainParts[$i];
9095 if ( $i == 0 ) {
@@ -91,11 +96,13 @@
9297 } else {
9398 $domain = $domainPart . '.' . $domain;
9499 }
 100+
95101 if ( $wgConf->isLocalVHost( $domain ) ) {
96102 return true;
97103 }
98104 }
99105 }
 106+
100107 return false;
101108 }
102109
@@ -165,12 +172,12 @@
166173 $this->parsedUrl = parse_url( $url );
167174
168175 if ( !Http::isValidURI( $this->url ) ) {
169 - $this->status = Status::newFatal('http-invalid-url');
 176+ $this->status = Status::newFatal( 'http-invalid-url' );
170177 } else {
171178 $this->status = Status::newGood( 100 ); // continue
172179 }
173180
174 - if ( isset($options['timeout']) && $options['timeout'] != 'default' ) {
 181+ if ( isset( $options['timeout'] ) && $options['timeout'] != 'default' ) {
175182 $this->timeout = $options['timeout'];
176183 } else {
177184 $this->timeout = $wgHTTPTimeout;
@@ -178,8 +185,9 @@
179186
180187 $members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
181188 "method", "followRedirects", "maxRedirects", "sslVerifyCert" );
 189+
182190 foreach ( $members as $o ) {
183 - if ( isset($options[$o]) ) {
 191+ if ( isset( $options[$o] ) ) {
184192 $this->$o = $options[$o];
185193 }
186194 }
@@ -193,21 +201,21 @@
194202 if ( !Http::$httpEngine ) {
195203 Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
196204 } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
197 - throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but'.
 205+ throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
198206 ' Http::$httpEngine is set to "curl"' );
199207 }
200208
201209 switch( Http::$httpEngine ) {
202 - case 'curl':
203 - return new CurlHttpRequest( $url, $options );
204 - case 'php':
205 - if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
206 - throw new MWException( __METHOD__.': allow_url_fopen needs to be enabled for pure PHP'.
207 - ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' );
208 - }
209 - return new PhpHttpRequest( $url, $options );
210 - default:
211 - throw new MWException( __METHOD__.': The setting of Http::$httpEngine is not valid.' );
 210+ case 'curl':
 211+ return new CurlHttpRequest( $url, $options );
 212+ case 'php':
 213+ if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
 214+ throw new MWException( __METHOD__ . ': allow_url_fopen needs to be enabled for pure PHP' .
 215+ ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' );
 216+ }
 217+ return new PhpHttpRequest( $url, $options );
 218+ default:
 219+ throw new MWException( __METHOD__ . ': The setting of Http::$httpEngine is not valid.' );
212220 }
213221 }
214222
@@ -226,7 +234,7 @@
227235 * @param $args Array
228236 * @todo overload the args param
229237 */
230 - public function setData($args) {
 238+ public function setData( $args ) {
231239 $this->postData = $args;
232240 }
233241
@@ -242,6 +250,7 @@
243251 if ( $this->proxy ) {
244252 return;
245253 }
 254+
246255 if ( Http::isLocalURL( $this->url ) ) {
247256 $this->proxy = 'http://localhost:80/';
248257 } elseif ( $wgHTTPProxy ) {
@@ -255,20 +264,20 @@
256265 * Set the refererer header
257266 */
258267 public function setReferer( $url ) {
259 - $this->setHeader('Referer', $url);
 268+ $this->setHeader( 'Referer', $url );
260269 }
261270
262271 /**
263272 * Set the user agent
264273 */
265274 public function setUserAgent( $UA ) {
266 - $this->setHeader('User-Agent', $UA);
 275+ $this->setHeader( 'User-Agent', $UA );
267276 }
268277
269278 /**
270279 * Set an arbitrary header
271280 */
272 - public function setHeader($name, $value) {
 281+ public function setHeader( $name, $value ) {
273282 // I feel like I should normalize the case here...
274283 $this->reqHeaders[$name] = $value;
275284 }
@@ -279,14 +288,18 @@
280289 public function getHeaderList() {
281290 $list = array();
282291
283 - if( $this->cookieJar ) {
 292+ if ( $this->cookieJar ) {
284293 $this->reqHeaders['Cookie'] =
285 - $this->cookieJar->serializeToHttpRequest($this->parsedUrl['path'],
286 - $this->parsedUrl['host']);
 294+ $this->cookieJar->serializeToHttpRequest(
 295+ $this->parsedUrl['path'],
 296+ $this->parsedUrl['host']
 297+ );
287298 }
288 - foreach($this->reqHeaders as $name => $value) {
 299+
 300+ foreach ( $this->reqHeaders as $name => $value ) {
289301 $list[] = "$name: $value";
290302 }
 303+
291304 return $list;
292305 }
293306
@@ -321,7 +334,7 @@
322335
323336 $this->content = "";
324337
325 - if( strtoupper($this->method) == "HEAD" ) {
 338+ if ( strtoupper( $this->method ) == "HEAD" ) {
326339 $this->headersOnly = true;
327340 }
328341
@@ -329,7 +342,7 @@
330343 $this->postData = wfArrayToCGI( $this->postData );
331344 }
332345
333 - if ( is_object( $wgTitle ) && !isset($this->reqHeaders['Referer']) ) {
 346+ if ( is_object( $wgTitle ) && !isset( $this->reqHeaders['Referer'] ) ) {
334347 $this->setReferer( $wgTitle->getFullURL() );
335348 }
336349
@@ -341,8 +354,8 @@
342355 $this->setCallback( array( $this, 'read' ) );
343356 }
344357
345 - if ( !isset($this->reqHeaders['User-Agent']) ) {
346 - $this->setUserAgent(Http::userAgent());
 358+ if ( !isset( $this->reqHeaders['User-Agent'] ) ) {
 359+ $this->setUserAgent( Http::userAgent() );
347360 }
348361 }
349362
@@ -355,14 +368,15 @@
356369 */
357370 protected function parseHeader() {
358371 $lastname = "";
359 - foreach( $this->headerList as $header ) {
360 - if( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
 372+
 373+ foreach ( $this->headerList as $header ) {
 374+ if ( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
361375 $this->respVersion = $match[1];
362376 $this->respStatus = $match[2];
363 - } elseif( preg_match( "#^[ \t]#", $header ) ) {
364 - $last = count($this->respHeaders[$lastname]) - 1;
 377+ } elseif ( preg_match( "#^[ \t]#", $header ) ) {
 378+ $last = count( $this->respHeaders[$lastname] ) - 1;
365379 $this->respHeaders[$lastname][$last] .= "\r\n$header";
366 - } elseif( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
 380+ } elseif ( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
367381 $this->respHeaders[strtolower( $match[1] )][] = $match[2];
368382 $lastname = strtolower( $match[1] );
369383 }
@@ -378,13 +392,13 @@
379393 * @return nothing
380394 */
381395 protected function setStatus() {
382 - if( !$this->respHeaders ) {
 396+ if ( !$this->respHeaders ) {
383397 $this->parseHeader();
384398 }
385399
386 - if((int)$this->respStatus !== 200) {
387 - list( $code, $message ) = explode(" ", $this->respStatus, 2);
388 - $this->status->fatal("http-bad-status", $code, $message );
 400+ if ( (int)$this->respStatus !== 200 ) {
 401+ list( $code, $message ) = explode( " ", $this->respStatus, 2 );
 402+ $this->status->fatal( "http-bad-status", $code, $message );
389403 }
390404 }
391405
@@ -395,14 +409,16 @@
396410 * @return Boolean
397411 */
398412 public function isRedirect() {
399 - if( !$this->respHeaders ) {
 413+ if ( !$this->respHeaders ) {
400414 $this->parseHeader();
401415 }
402416
403417 $status = (int)$this->respStatus;
 418+
404419 if ( $status >= 300 && $status <= 303 ) {
405420 return true;
406421 }
 422+
407423 return false;
408424 }
409425
@@ -415,9 +431,10 @@
416432 * @return Array
417433 */
418434 public function getResponseHeaders() {
419 - if( !$this->respHeaders ) {
 435+ if ( !$this->respHeaders ) {
420436 $this->parseHeader();
421437 }
 438+
422439 return $this->respHeaders;
423440 }
424441
@@ -427,14 +444,16 @@
428445 * @param $header String
429446 * @return String
430447 */
431 - public function getResponseHeader($header) {
432 - if( !$this->respHeaders ) {
 448+ public function getResponseHeader( $header ) {
 449+ if ( !$this->respHeaders ) {
433450 $this->parseHeader();
434451 }
 452+
435453 if ( isset( $this->respHeaders[strtolower ( $header ) ] ) ) {
436454 $v = $this->respHeaders[strtolower ( $header ) ];
437455 return $v[count( $v ) - 1];
438456 }
 457+
439458 return null;
440459 }
441460
@@ -453,9 +472,10 @@
454473 * @returns CookieJar
455474 */
456475 public function getCookieJar() {
457 - if( !$this->respHeaders ) {
 476+ if ( !$this->respHeaders ) {
458477 $this->parseHeader();
459478 }
 479+
460480 return $this->cookieJar;
461481 }
462482
@@ -465,23 +485,25 @@
466486 * Set-Cookie headers.
467487 * @see Cookie::set
468488 */
469 - public function setCookie( $name, $value = null, $attr = null) {
470 - if( !$this->cookieJar ) {
 489+ public function setCookie( $name, $value = null, $attr = null ) {
 490+ if ( !$this->cookieJar ) {
471491 $this->cookieJar = new CookieJar;
472492 }
473 - $this->cookieJar->setCookie($name, $value, $attr);
 493+
 494+ $this->cookieJar->setCookie( $name, $value, $attr );
474495 }
475496
476497 /**
477498 * Parse the cookies in the response headers and store them in the cookie jar.
478499 */
479500 protected function parseCookies() {
480 - if( !$this->cookieJar ) {
 501+ if ( !$this->cookieJar ) {
481502 $this->cookieJar = new CookieJar;
482503 }
483 - if( isset( $this->respHeaders['set-cookie'] ) ) {
 504+
 505+ if ( isset( $this->respHeaders['set-cookie'] ) ) {
484506 $url = parse_url( $this->getFinalUrl() );
485 - foreach( $this->respHeaders['set-cookie'] as $cookie ) {
 507+ foreach ( $this->respHeaders['set-cookie'] as $cookie ) {
486508 $this->cookieJar->parseCookieResponseHeader( $cookie, $url['host'] );
487509 }
488510 }
@@ -493,7 +515,8 @@
494516 * @return String
495517 */
496518 public function getFinalUrl() {
497 - $location = $this->getResponseHeader("Location");
 519+ $location = $this->getResponseHeader( "Location" );
 520+
498521 if ( $location ) {
499522 return $location;
500523 }
@@ -541,21 +564,24 @@
542565 */
543566 public function set( $value, $attr ) {
544567 $this->value = $value;
545 - if( isset( $attr['expires'] ) ) {
 568+
 569+ if ( isset( $attr['expires'] ) ) {
546570 $this->isSessionKey = false;
547571 $this->expires = strtotime( $attr['expires'] );
548572 }
549 - if( isset( $attr['path'] ) ) {
 573+
 574+ if ( isset( $attr['path'] ) ) {
550575 $this->path = $attr['path'];
551576 } else {
552577 $this->path = "/";
553578 }
554 - if( isset( $attr['domain'] ) ) {
555 - if( self::validateCookieDomain( $attr['domain'] ) ) {
 579+
 580+ if ( isset( $attr['domain'] ) ) {
 581+ if ( self::validateCookieDomain( $attr['domain'] ) ) {
556582 $this->domain = $attr['domain'];
557583 }
558584 } else {
559 - throw new MWException("You must specify a domain.");
 585+ throw new MWException( "You must specify a domain." );
560586 }
561587 }
562588
@@ -571,39 +597,48 @@
572598 * @param $originDomain String: (optional) the domain the cookie originates from
573599 * @return Boolean
574600 */
575 - public static function validateCookieDomain( $domain, $originDomain = null) {
 601+ public static function validateCookieDomain( $domain, $originDomain = null ) {
576602 // Don't allow a trailing dot
577 - if( substr( $domain, -1 ) == "." ) return false;
 603+ if ( substr( $domain, -1 ) == "." ) {
 604+ return false;
 605+ }
578606
579 - $dc = explode(".", $domain);
 607+ $dc = explode( ".", $domain );
580608
581609 // Only allow full, valid IP addresses
582 - if( preg_match( '/^[0-9.]+$/', $domain ) ) {
583 - if( count( $dc ) != 4 ) return false;
 610+ if ( preg_match( '/^[0-9.]+$/', $domain ) ) {
 611+ if ( count( $dc ) != 4 ) {
 612+ return false;
 613+ }
584614
585 - if( ip2long( $domain ) === false ) return false;
 615+ if ( ip2long( $domain ) === false ) {
 616+ return false;
 617+ }
586618
587 - if( $originDomain == null || $originDomain == $domain ) return true;
 619+ if ( $originDomain == null || $originDomain == $domain ) {
 620+ return true;
 621+ }
588622
589623 }
590624
591625 // Don't allow cookies for "co.uk" or "gov.uk", etc, but allow "supermarket.uk"
592 - if( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) {
593 - if( (count($dc) == 2 && strlen( $dc[0] ) <= 2 )
594 - || (count($dc) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) {
 626+ if ( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) {
 627+ if ( ( count( $dc ) == 2 && strlen( $dc[0] ) <= 2 )
 628+ || ( count( $dc ) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) {
595629 return false;
596630 }
597 - if( (count($dc) == 2 || (count($dc) == 3 && $dc[0] == "") )
598 - && preg_match( '/(com|net|org|gov|edu)\...$/', $domain) ) {
 631+ if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == "" ) )
 632+ && preg_match( '/(com|net|org|gov|edu)\...$/', $domain ) ) {
599633 return false;
600634 }
601635 }
602636
603 - if( $originDomain != null ) {
604 - if( substr( $domain, 0, 1 ) != "." && $domain != $originDomain ) {
 637+ if ( $originDomain != null ) {
 638+ if ( substr( $domain, 0, 1 ) != "." && $domain != $originDomain ) {
605639 return false;
606640 }
607 - if( substr( $domain, 0, 1 ) == "."
 641+
 642+ if ( substr( $domain, 0, 1 ) == "."
608643 && substr_compare( $originDomain, $domain, -strlen( $domain ),
609644 strlen( $domain ), TRUE ) != 0 ) {
610645 return false;
@@ -623,40 +658,42 @@
624659 public function serializeToHttpRequest( $path, $domain ) {
625660 $ret = "";
626661
627 - if( $this->canServeDomain( $domain )
 662+ if ( $this->canServeDomain( $domain )
628663 && $this->canServePath( $path )
629664 && $this->isUnExpired() ) {
630 - $ret = $this->name ."=". $this->value;
 665+ $ret = $this->name . "=" . $this->value;
631666 }
632667
633668 return $ret;
634669 }
635670
636671 protected function canServeDomain( $domain ) {
637 - if( $domain == $this->domain
638 - || ( strlen( $domain) > strlen( $this->domain )
639 - && substr( $this->domain, 0, 1) == "."
 672+ if ( $domain == $this->domain
 673+ || ( strlen( $domain ) > strlen( $this->domain )
 674+ && substr( $this->domain, 0, 1 ) == "."
640675 && substr_compare( $domain, $this->domain, -strlen( $this->domain ),
641676 strlen( $this->domain ), TRUE ) == 0 ) ) {
642677 return true;
643678 }
 679+
644680 return false;
645681 }
646682
647683 protected function canServePath( $path ) {
648 - if( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 ) {
 684+ if ( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 ) {
649685 return true;
650686 }
 687+
651688 return false;
652689 }
653690
654691 protected function isUnExpired() {
655 - if( $this->isSessionKey || $this->expires > time() ) {
 692+ if ( $this->isSessionKey || $this->expires > time() ) {
656693 return true;
657694 }
 695+
658696 return false;
659697 }
660 -
661698 }
662699
663700 class CookieJar {
@@ -666,12 +703,13 @@
667704 * Set a cookie in the cookie jar. Make sure only one cookie per-name exists.
668705 * @see Cookie::set()
669706 */
670 - public function setCookie ($name, $value, $attr) {
 707+ public function setCookie ( $name, $value, $attr ) {
671708 /* cookies: case insensitive, so this should work.
672709 * We'll still send the cookies back in the same case we got them, though.
673710 */
674 - $index = strtoupper($name);
675 - if( isset( $this->cookie[$index] ) ) {
 711+ $index = strtoupper( $name );
 712+
 713+ if ( isset( $this->cookie[$index] ) ) {
676714 $this->cookie[$index]->set( $value, $attr );
677715 } else {
678716 $this->cookie[$index] = new Cookie( $name, $value, $attr );
@@ -684,12 +722,15 @@
685723 public function serializeToHttpRequest( $path, $domain ) {
686724 $cookies = array();
687725
688 - foreach( $this->cookie as $c ) {
 726+ foreach ( $this->cookie as $c ) {
689727 $serialized = $c->serializeToHttpRequest( $path, $domain );
690 - if ( $serialized ) $cookies[] = $serialized;
 728+
 729+ if ( $serialized ) {
 730+ $cookies[] = $serialized;
 731+ }
691732 }
692733
693 - return implode("; ", $cookies);
 734+ return implode( "; ", $cookies );
694735 }
695736
696737 /**
@@ -700,34 +741,37 @@
701742 */
702743 public function parseCookieResponseHeader ( $cookie, $domain ) {
703744 $len = strlen( "Set-Cookie:" );
 745+
704746 if ( substr_compare( "Set-Cookie:", $cookie, 0, $len, TRUE ) === 0 ) {
705747 $cookie = substr( $cookie, $len );
706748 }
707749
708750 $bit = array_map( 'trim', explode( ";", $cookie ) );
709 - if ( count($bit) >= 1 ) {
710 - list($name, $value) = explode( "=", array_shift( $bit ), 2 );
 751+
 752+ if ( count( $bit ) >= 1 ) {
 753+ list( $name, $value ) = explode( "=", array_shift( $bit ), 2 );
711754 $attr = array();
712 - foreach( $bit as $piece ) {
 755+
 756+ foreach ( $bit as $piece ) {
713757 $parts = explode( "=", $piece );
714 - if( count( $parts ) > 1 ) {
 758+ if ( count( $parts ) > 1 ) {
715759 $attr[strtolower( $parts[0] )] = $parts[1];
716760 } else {
717761 $attr[strtolower( $parts[0] )] = true;
718762 }
719763 }
720764
721 - if( !isset( $attr['domain'] ) ) {
 765+ if ( !isset( $attr['domain'] ) ) {
722766 $attr['domain'] = $domain;
723767 } elseif ( !Cookie::validateCookieDomain( $attr['domain'], $domain ) ) {
724768 return null;
725769 }
 770+
726771 $this->setCookie( $name, $value, $attr );
727772 }
728773 }
729774 }
730775
731 -
732776 /**
733777 * HttpRequest implemented using internal curl compiled into PHP
734778 */
@@ -747,19 +791,21 @@
748792
749793 public function execute() {
750794 parent::execute();
 795+
751796 if ( !$this->status->isOK() ) {
752797 return $this->status;
753798 }
 799+
754800 $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
755801 $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
756802 $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
757803 $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
758 - $this->curlOptions[CURLOPT_HEADERFUNCTION] = array($this, "readHeader");
 804+ $this->curlOptions[CURLOPT_HEADERFUNCTION] = array( $this, "readHeader" );
759805 $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
760806 $this->curlOptions[CURLOPT_ENCODING] = ""; # Enable compression
761807
762808 /* not sure these two are actually necessary */
763 - if(isset($this->reqHeaders['Referer'])) {
 809+ if ( isset( $this->reqHeaders['Referer'] ) ) {
764810 $this->curlOptions[CURLOPT_REFERER] = $this->reqHeaders['Referer'];
765811 }
766812 $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders['User-Agent'];
@@ -793,13 +839,15 @@
794840 $this->curlOptions[CURLOPT_HTTPHEADER] = $this->getHeaderList();
795841
796842 $curlHandle = curl_init( $this->url );
 843+
797844 if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
798 - throw new MWException("Error setting curl options.");
 845+ throw new MWException( "Error setting curl options." );
799846 }
 847+
800848 if ( $this->followRedirects && $this->canFollowRedirects() ) {
801849 if ( ! @curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) {
802 - wfDebug( __METHOD__.": Couldn't set CURLOPT_FOLLOWLOCATION. " .
803 - "Probably safe_mode or open_basedir is set.\n");
 850+ wfDebug( __METHOD__ . ": Couldn't set CURLOPT_FOLLOWLOCATION. " .
 851+ "Probably safe_mode or open_basedir is set.\n" );
804852 // Continue the processing. If it were in curl_setopt_array,
805853 // processing would have halted on its entry
806854 }
@@ -814,13 +862,14 @@
815863 $this->status->fatal( 'http-curl-error', curl_error( $curlHandle ) );
816864 }
817865 } else {
818 - $this->headerList = explode("\r\n", $this->headerText);
 866+ $this->headerList = explode( "\r\n", $this->headerText );
819867 }
820868
821869 curl_close( $curlHandle );
822870
823871 $this->parseHeader();
824872 $this->setStatus();
 873+
825874 return $this->status;
826875 }
827876
@@ -829,10 +878,12 @@
830879 wfDebug( "Cannot follow redirects in safe mode\n" );
831880 return false;
832881 }
 882+
833883 if ( !defined( 'CURLOPT_REDIR_PROTOCOLS' ) ) {
834884 wfDebug( "Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
835885 return false;
836886 }
 887+
837888 return true;
838889 }
839890 }
@@ -875,7 +926,7 @@
876927 }
877928
878929 $options['method'] = $this->method;
879 - $options['header'] = implode("\r\n", $this->getHeaderList());
 930+ $options['header'] = implode( "\r\n", $this->getHeaderList() );
880931 // Note that at some future point we may want to support
881932 // HTTP/1.1, but we'd have to write support for chunking
882933 // in version of PHP < 5.3.1
@@ -891,7 +942,7 @@
892943
893944 $oldTimeout = false;
894945 if ( version_compare( '5.2.1', phpversion(), '>' ) ) {
895 - $oldTimeout = ini_set('default_socket_timeout', $this->timeout);
 946+ $oldTimeout = ini_set( 'default_socket_timeout', $this->timeout );
896947 } else {
897948 $options['timeout'] = $this->timeout;
898949 }
@@ -901,17 +952,21 @@
902953 $this->headerList = array();
903954 $reqCount = 0;
904955 $url = $this->url;
 956+
905957 do {
906958 $reqCount++;
907959 wfSuppressWarnings();
908960 $fh = fopen( $url, "r", false, $context );
909961 wfRestoreWarnings();
 962+
910963 if ( !$fh ) {
911964 break;
912965 }
 966+
913967 $result = stream_get_meta_data( $fh );
914968 $this->headerList = $result['wrapper_data'];
915969 $this->parseHeader();
 970+
916971 if ( !$manuallyRedirect || !$this->followRedirects ) {
917972 break;
918973 }
@@ -921,16 +976,18 @@
922977 break;
923978 }
924979 # Check security of URL
925 - $url = $this->getResponseHeader("Location");
 980+ $url = $this->getResponseHeader( "Location" );
 981+
926982 if ( substr( $url, 0, 7 ) !== 'http://' ) {
927 - wfDebug( __METHOD__.": insecure redirection\n" );
 983+ wfDebug( __METHOD__ . ": insecure redirection\n" );
928984 break;
929985 }
930986 } while ( true );
931987
932988 if ( $oldTimeout !== false ) {
933 - ini_set('default_socket_timeout', $oldTimeout);
 989+ ini_set( 'default_socket_timeout', $oldTimeout );
934990 }
 991+
935992 $this->setStatus();
936993
937994 if ( $fh === false ) {
@@ -943,13 +1000,15 @@
9441001 return $this->status;
9451002 }
9461003
947 - if($this->status->isOK()) {
 1004+ if ( $this->status->isOK() ) {
9481005 while ( !feof( $fh ) ) {
9491006 $buf = fread( $fh, 8192 );
 1007+
9501008 if ( $buf === false ) {
9511009 $this->status->fatal( 'http-read-error' );
9521010 break;
9531011 }
 1012+
9541013 if ( strlen( $buf ) ) {
9551014 call_user_func( $this->callback, $fh, $buf );
9561015 }
Index: trunk/phase3/includes/Skin.php
@@ -40,20 +40,24 @@
4141 static function getSkinNames() {
4242 global $wgValidSkinNames;
4343 static $skinsInitialised = false;
 44+
4445 if ( !$skinsInitialised ) {
4546 # Get a list of available skins
4647 # Build using the regular expression '^(.*).php$'
4748 # Array keys are all lower case, array value keep the case used by filename
4849 #
4950 wfProfileIn( __METHOD__ . '-init' );
 51+
5052 global $wgStyleDirectory;
 53+
5154 $skinDir = dir( $wgStyleDirectory );
5255
5356 # while code from www.php.net
54 - while( false !== ( $file = $skinDir->read() ) ) {
 57+ while ( false !== ( $file = $skinDir->read() ) ) {
5558 // Skip non-PHP files, hidden files, and '.dep' includes
5659 $matches = array();
57 - if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
 60+
 61+ if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
5862 $aSkin = $matches[1];
5963 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
6064 }
@@ -73,10 +77,13 @@
7478 */
7579 public static function getUsableSkins() {
7680 global $wgSkipSkins;
 81+
7782 $usableSkins = self::getSkinNames();
 83+
7884 foreach ( $wgSkipSkins as $skip ) {
7985 unset( $usableSkins[$skip] );
8086 }
 87+
8188 return $usableSkins;
8289 }
8390
@@ -89,15 +96,16 @@
9097 */
9198 static function normalizeKey( $key ) {
9299 global $wgDefaultSkin;
 100+
93101 $skinNames = Skin::getSkinNames();
94102
95 - if( $key == '' ) {
 103+ if ( $key == '' ) {
96104 // Don't return the default immediately;
97105 // in a misconfiguration we need to fall back.
98106 $key = $wgDefaultSkin;
99107 }
100108
101 - if( isset( $skinNames[$key] ) ) {
 109+ if ( isset( $skinNames[$key] ) ) {
102110 return $key;
103111 }
104112
@@ -109,13 +117,13 @@
110118 2 => 'cologneblue'
111119 );
112120
113 - if( isset( $fallback[$key] ) ) {
 121+ if ( isset( $fallback[$key] ) ) {
114122 $key = $fallback[$key];
115123 }
116124
117 - if( isset( $skinNames[$key] ) ) {
 125+ if ( isset( $skinNames[$key] ) ) {
118126 return $key;
119 - } else if( isset( $skinNames[$wgDefaultSkin] ) ) {
 127+ } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
120128 return $wgDefaultSkin;
121129 } else {
122130 return 'vector';
@@ -140,13 +148,14 @@
141149 if ( !class_exists( $className ) ) {
142150 // Preload base classes to work around APC/PHP5 bug
143151 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
144 - if( file_exists( $deps ) ) {
 152+
 153+ if ( file_exists( $deps ) ) {
145154 include_once( $deps );
146155 }
147156 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
148157
149158 # Check if we got if not failback to default skin
150 - if( !class_exists( $className ) ) {
 159+ if ( !class_exists( $className ) ) {
151160 # DO NOT die if the class isn't found. This breaks maintenance
152161 # scripts and can cause a user account to be unrecoverable
153162 # except by SQL manipulation if a previously valid skin name
@@ -176,7 +185,9 @@
177186 if ( $wgOut->isQuickbarSuppressed() ) {
178187 return 0;
179188 }
 189+
180190 $q = $wgUser->getOption( 'quickbar', 0 );
 191+
181192 return $q;
182193 }
183194
@@ -189,11 +200,11 @@
190201 # should not matter, but Konqueror (3.5.9 at least) incorrectly
191202 # uses whichever one appears later in the HTML source. Make sure
192203 # apple-touch-icon is specified first to avoid this.
193 - if( false !== $wgAppleTouchIcon ) {
 204+ if ( false !== $wgAppleTouchIcon ) {
194205 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
195206 }
196207
197 - if( false !== $wgFavicon ) {
 208+ if ( false !== $wgFavicon ) {
198209 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
199210 }
200211
@@ -203,7 +214,7 @@
204215 'type' => 'application/opensearchdescription+xml',
205216 'href' => wfScript( 'opensearch_desc' ),
206217 'title' => wfMsgForContent( 'opensearch-desc' ),
207 - ));
 218+ ) );
208219
209220 $this->addMetadataLinks( $out );
210221
@@ -245,16 +256,17 @@
246257 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
247258 global $wgRightsPage, $wgRightsUrl;
248259
249 - if( $out->isArticleRelated() ) {
 260+ if ( $out->isArticleRelated() ) {
250261 # note: buggy CC software only reads first "meta" link
251 - if( $wgEnableCreativeCommonsRdf ) {
 262+ if ( $wgEnableCreativeCommonsRdf ) {
252263 $out->addMetadataLink( array(
253264 'title' => 'Creative Commons',
254265 'type' => 'application/rdf+xml',
255266 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) )
256267 );
257268 }
258 - if( $wgEnableDublinCoreRdf ) {
 269+
 270+ if ( $wgEnableDublinCoreRdf ) {
259271 $out->addMetadataLink( array(
260272 'title' => 'Dublin Core',
261273 'type' => 'application/rdf+xml',
@@ -263,16 +275,19 @@
264276 }
265277 }
266278 $copyright = '';
267 - if( $wgRightsPage ) {
 279+ if ( $wgRightsPage ) {
268280 $copy = Title::newFromText( $wgRightsPage );
269 - if( $copy ) {
 281+
 282+ if ( $copy ) {
270283 $copyright = $copy->getLocalURL();
271284 }
272285 }
273 - if( !$copyright && $wgRightsUrl ) {
 286+
 287+ if ( !$copyright && $wgRightsUrl ) {
274288 $copyright = $wgRightsUrl;
275289 }
276 - if( $copyright ) {
 290+
 291+ if ( $copyright ) {
277292 $out->addLink( array(
278293 'rel' => 'copyright',
279294 'href' => $copyright )
@@ -339,9 +354,9 @@
340355 $out->out( "\n</body></html>" );
341356 wfProfileOut( __METHOD__ );
342357 }
343 -
 358+
344359 static function makeVariablesScript( $data ) {
345 - if( $data ) {
 360+ if ( $data ) {
346361 return Html::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' );
347362 } else {
348363 return '';
@@ -359,6 +374,7 @@
360375 # Weird back-compat stuff.
361376 $skinName = $skinName['skinname'];
362377 }
 378+
363379 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
364380 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
365381 global $wgOut, $wgArticle;
@@ -422,32 +438,34 @@
423439 'wgSiteName' => $wgSitename,
424440 'wgCategories' => $wgOut->getCategories(),
425441 );
 442+
426443 if ( $wgContLang->hasVariants() ) {
427444 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
428445 }
429446
430447 // if on upload page output the extension list & js_upload
431 - if( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
 448+ if ( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
432449 global $wgFileExtensions;
433450 $vars['wgFileExtensions'] = $wgFileExtensions;
434451 }
435452
436 - if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
 453+ if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
437454 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
438455 $vars['wgDBname'] = $wgDBname;
439456 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
440457 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
441458 }
442459
443 - foreach( $wgRestrictionTypes as $type ) {
 460+ foreach ( $wgRestrictionTypes as $type ) {
444461 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
445462 }
446463
447464 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
448465 $msgs = (object)array();
 466+
449467 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
450468 'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
451 - $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
 469+ $msgs-> { $msgName . 'Msg' } = wfMsg( $msgName );
452470 }
453471 $vars['wgAjaxWatch'] = $msgs;
454472 }
@@ -471,18 +489,19 @@
472490 public function userCanPreview( $action ) {
473491 global $wgRequest, $wgUser;
474492
475 - if( $action != 'submit' ) {
 493+ if ( $action != 'submit' ) {
476494 return false;
477495 }
478 - if( !$wgRequest->wasPosted() ) {
 496+ if ( !$wgRequest->wasPosted() ) {
479497 return false;
480498 }
481 - if( !$this->mTitle->userCanEditCssSubpage() ) {
 499+ if ( !$this->mTitle->userCanEditCssSubpage() ) {
482500 return false;
483501 }
484 - if( !$this->mTitle->userCanEditJsSubpage() ) {
 502+ if ( !$this->mTitle->userCanEditJsSubpage() ) {
485503 return false;
486504 }
 505+
487506 return $wgUser->matchEditToken(
488507 $wgRequest->getVal( 'wpEditToken' ) );
489508 }
@@ -505,7 +524,8 @@
506525 global $wgStylePath;
507526
508527 wfProfileIn( __METHOD__ );
509 - if( !$skinName ) {
 528+
 529+ if ( !$skinName ) {
510530 $skinName = $this->getSkinName();
511531 }
512532
@@ -513,16 +533,20 @@
514534 $s .= "var skin = '" . Xml::escapeJsString( $skinName ) . "';\n";
515535 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
516536 $s .= "\n\n/* MediaWiki:Common.js */\n";
 537+
517538 $commonJs = wfMsgExt( 'common.js', 'content' );
 539+
518540 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
519541 $s .= $commonJs;
520542 }
521543
522544 $s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
 545+
523546 // avoid inclusion of non defined user JavaScript (with custom skins only)
524547 // by checking for default message content
525548 $msgKey = ucfirst( $skinName ) . '.js';
526549 $userJS = wfMsgExt( $msgKey, 'content' );
 550+
527551 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
528552 $s .= $userJS;
529553 }
@@ -536,8 +560,10 @@
537561 */
538562 public function generateUserStylesheet() {
539563 wfProfileIn( __METHOD__ );
 564+
540565 $s = "/* generated user stylesheet */\n" .
541566 $this->reallyGenerateUserStylesheet();
 567+
542568 wfProfileOut( __METHOD__ );
543569 return $s;
544570 }
@@ -548,12 +574,15 @@
549575 */
550576 protected function reallyGenerateUserStylesheet() {
551577 global $wgUser;
 578+
552579 $s = '';
553 - if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
 580+
 581+ if ( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
554582 $underline = $undopt ? 'underline' : 'none';
555583 $s .= "a { text-decoration: $underline; }\n";
556584 }
557 - if( $wgUser->getOption( 'highlightbroken' ) ) {
 585+
 586+ if ( $wgUser->getOption( 'highlightbroken' ) ) {
558587 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
559588 } else {
560589 $s .= <<<CSS
@@ -571,19 +600,25 @@
572601 }
573602 CSS;
574603 }
575 - if( $wgUser->getOption( 'justify' ) ) {
 604+
 605+ if ( $wgUser->getOption( 'justify' ) ) {
576606 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
577607 }
578 - if( !$wgUser->getOption( 'showtoc' ) ) {
 608+
 609+ if ( !$wgUser->getOption( 'showtoc' ) ) {
579610 $s .= "#toc { display: none; }\n";
580611 }
581 - if( !$wgUser->getOption( 'editsection' ) ) {
 612+
 613+ if ( !$wgUser->getOption( 'editsection' ) ) {
582614 $s .= ".editsection { display: none; }\n";
583615 }
 616+
584617 $fontstyle = $wgUser->getOption( 'editfont' );
 618+
585619 if ( $fontstyle !== 'default' ) {
586620 $s .= "textarea { font-family: $fontstyle; }\n";
587621 }
 622+
588623 return $s;
589624 }
590625
@@ -610,44 +645,51 @@
611646
612647 // If we use the site's dynamic CSS, throw that in, too
613648 // Per-site custom styles
614 - if( $wgUseSiteCss ) {
 649+ if ( $wgUseSiteCss ) {
615650 global $wgHandheldStyle;
 651+
616652 $query = wfArrayToCGI( self::getDynamicStylesheetQuery() );
617653 # Site settings must override extension css! (bug 15025)
618654 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
619655 $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
620 - if( $wgHandheldStyle ) {
 656+
 657+ if ( $wgHandheldStyle ) {
621658 $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
622659 }
623660 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
624661 }
625662
626663 global $wgAllowUserCssPrefs;
627 - if( $wgAllowUserCssPrefs ){
628 - if( $wgUser->isLoggedIn() ) {
 664+
 665+ if ( $wgAllowUserCssPrefs ) {
 666+ if ( $wgUser->isLoggedIn() ) {
629667 // Ensure that logged-in users' generated CSS isn't clobbered
630668 // by anons' publicly cacheable generated CSS.
631669 $siteargs['smaxage'] = '0';
632670 $siteargs['ts'] = $wgUser->mTouched;
633671 }
 672+
634673 // Per-user styles based on preferences
635674 $siteargs['gen'] = 'css';
636 - if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
 675+
 676+ if ( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
637677 $siteargs['useskin'] = $us;
638678 }
 679+
639680 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
640681 }
641682
642683 // Per-user custom style pages
643 - if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
 684+ if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
644685 $action = $wgRequest->getVal( 'action' );
 686+
645687 # If we're previewing the CSS page, use it
646 - if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
 688+ if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
647689 // @FIXME: properly escape the cdata!
648690 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
649691 } else {
650692 $names = array( 'common', $this->getSkinName() );
651 - foreach( $names as $name ) {
 693+ foreach ( $names as $name ) {
652694 $out->addStyle( self::makeUrl(
653695 $this->userpage . '/' . $name . '.css',
654696 'action=raw&ctype=text/css' )
@@ -666,6 +708,7 @@
667709 */
668710 public static function getDynamicStylesheetQuery() {
669711 global $wgSquidMaxage;
 712+
670713 return array(
671714 'action' => 'raw',
672715 'maxage' => $wgSquidMaxage,
@@ -689,14 +732,17 @@
690733
691734 function getPageClasses( $title ) {
692735 $numeric = 'ns-' . $title->getNamespace();
693 - if( $title->getNamespace() == NS_SPECIAL ) {
 736+
 737+ if ( $title->getNamespace() == NS_SPECIAL ) {
694738 $type = 'ns-special';
695 - } elseif( $title->isTalkPage() ) {
 739+ } elseif ( $title->isTalkPage() ) {
696740 $type = 'ns-talk';
697741 } else {
698742 $type = 'ns-subject';
699743 }
 744+
700745 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
 746+
701747 return "$numeric $type $name";
702748 }
703749
@@ -724,7 +770,7 @@
725771 $qb = $this->qbSetting();
726772
727773 $langlinks = $this->otherLanguages();
728 - if( $langlinks ) {
 774+ if ( $langlinks ) {
729775 $rows = 2;
730776 $borderhack = '';
731777 } else {
@@ -738,16 +784,18 @@
739785
740786 $shove = ( $qb != 0 );
741787 $left = ( $qb == 1 || $qb == 3 );
742 - if( $wgContLang->isRTL() ) {
 788+
 789+ if ( $wgContLang->isRTL() ) {
743790 $left = !$left;
744791 }
745792
746 - if( !$shove ) {
 793+ if ( !$shove ) {
747794 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
748795 $this->logoText() . '</td>';
749 - } elseif( $left ) {
 796+ } elseif ( $left ) {
750797 $s .= $this->getQuickbarCompensator( $rows );
751798 }
 799+
752800 $l = $wgContLang->alignStart();
753801 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
754802
@@ -766,16 +814,19 @@
767815 if ( $shove && !$left ) { # Right
768816 $s .= $this->getQuickbarCompensator( $rows );
769817 }
 818+
770819 $s .= "</tr>\n</table>\n</div>\n";
771820 $s .= "\n<div id='article'>\n";
772821
773822 $notice = wfGetSiteNotice();
774 - if( $notice ) {
 823+
 824+ if ( $notice ) {
775825 $s .= "\n<div id='siteNotice'>$notice</div>\n";
776826 }
777827 $s .= $this->pageTitle();
778828 $s .= $this->pageSubtitle();
779829 $s .= $this->getCategories();
 830+
780831 wfProfileOut( __METHOD__ );
781832 return $s;
782833 }
@@ -784,7 +835,7 @@
785836 global $wgOut, $wgUseCategoryBrowser;
786837 global $wgContLang, $wgUser;
787838
788 - if( count( $wgOut->mCategoryLinks ) == 0 ) {
 839+ if ( count( $wgOut->mCategoryLinks ) == 0 ) {
789840 return '';
790841 }
791842
@@ -800,6 +851,7 @@
801852 $allCats = $wgOut->getCategoryLinks();
802853 $s = '';
803854 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
 855+
804856 if ( !empty( $allCats['normal'] ) ) {
805857 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
806858
@@ -812,12 +864,13 @@
813865 # Hidden categories
814866 if ( isset( $allCats['hidden'] ) ) {
815867 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
816 - $class ='mw-hidden-cats-user-shown';
 868+ $class = 'mw-hidden-cats-user-shown';
817869 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
818870 $class = 'mw-hidden-cats-ns-shown';
819871 } else {
820872 $class = 'mw-hidden-cats-hidden';
821873 }
 874+
822875 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
823876 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
824877 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
@@ -826,7 +879,7 @@
827880
828881 # optional 'dmoz-like' category browser. Will be shown under the list
829882 # of categories an article belong to
830 - if( $wgUseCategoryBrowser ) {
 883+ if ( $wgUseCategoryBrowser ) {
831884 $s .= '<br /><hr />';
832885
833886 # get a big array of the parents tree
@@ -852,18 +905,21 @@
853906 */
854907 function drawCategoryBrowser( $tree, &$skin ) {
855908 $return = '';
856 - foreach( $tree as $element => $parent ) {
857 - if( empty( $parent ) ) {
 909+
 910+ foreach ( $tree as $element => $parent ) {
 911+ if ( empty( $parent ) ) {
858912 # element start a new list
859913 $return .= "\n";
860914 } else {
861915 # grab the others elements
862916 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
863917 }
 918+
864919 # add our current element to the list
865920 $eltitle = Title::newFromText( $element );
866921 $return .= $skin->link( $eltitle, $eltitle->getText() );
867922 }
 923+
868924 return $return;
869925 }
870926
@@ -872,13 +928,14 @@
873929
874930 $classes = 'catlinks';
875931
 932+ global $wgOut, $wgUser;
 933+
876934 // Check what we're showing
877 - global $wgOut, $wgUser;
878935 $allCats = $wgOut->getCategoryLinks();
879936 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
880937 $this->mTitle->getNamespace() == NS_CATEGORY;
881938
882 - if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
 939+ if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
883940 $classes .= ' catlinks-allhidden';
884941 }
885942
@@ -906,10 +963,10 @@
907964 protected function afterContentHook() {
908965 $data = '';
909966
910 - if( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
 967+ if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
911968 // adding just some spaces shouldn't toggle the output
912969 // of the whole <div/>, so we use trim() here
913 - if( trim( $data ) != '' ) {
 970+ if ( trim( $data ) != '' ) {
914971 // Doing this here instead of in the skins to
915972 // ensure that the div has the same ID in all
916973 // skins
@@ -931,11 +988,13 @@
932989 */
933990 protected function generateDebugHTML() {
934991 global $wgShowDebug, $wgOut;
 992+
935993 if ( $wgShowDebug ) {
936994 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
937995 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
938996 $listInternals . "</ul>\n";
939997 }
 998+
940999 return '';
9411000 }
9421001
@@ -943,7 +1002,8 @@
9441003 $lines = explode( "\n", $debugText );
9451004 $curIdent = 0;
9461005 $ret = '<li>';
947 - foreach( $lines as $line ) {
 1006+
 1007+ foreach ( $lines as $line ) {
9481008 $m = array();
9491009 $display = ltrim( $line );
9501010 $ident = strlen( $line ) - strlen( $display );
@@ -972,7 +1032,9 @@
9731033
9741034 $curIdent = $ident;
9751035 }
 1036+
9761037 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
 1038+
9771039 return $ret;
9781040 }
9791041
@@ -993,6 +1055,7 @@
9941056 function bottomScripts( $out ) {
9951057 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
9961058 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
 1059+
9971060 return $bottomScriptText;
9981061 }
9991062
@@ -1021,11 +1084,14 @@
10221085
10231086 $s[] = $this->printableLink();
10241087 $disclaimer = $this->disclaimerLink(); # may be empty
1025 - if( $disclaimer ) {
 1088+
 1089+ if ( $disclaimer ) {
10261090 $s[] = $disclaimer;
10271091 }
 1092+
10281093 $privacy = $this->privacyLink(); # may be empty too
1029 - if( $privacy ) {
 1094+
 1095+ if ( $privacy ) {
10301096 $s[] = $privacy;
10311097 }
10321098
@@ -1033,13 +1099,15 @@
10341100 if ( $this->mTitle->getNamespace() == NS_FILE ) {
10351101 $name = $this->mTitle->getDBkey();
10361102 $image = wfFindFile( $this->mTitle );
1037 - if( $image ) {
 1103+
 1104+ if ( $image ) {
10381105 $link = htmlspecialchars( $image->getURL() );
10391106 $style = $this->getInternalLinkAttributes( $link, $name );
10401107 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
10411108 }
10421109 }
10431110 }
 1111+
10441112 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
10451113 $s[] .= $this->link(
10461114 $this->mTitle,
@@ -1053,7 +1121,7 @@
10541122 if ( $wgUser->getNewtalk() ) {
10551123 # do not show "You have new messages" text when we are viewing our
10561124 # own talk page
1057 - if( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
 1125+ if ( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
10581126 $tl = $this->link(
10591127 $wgUser->getTalkPage(),
10601128 wfMsgHtml( 'newmessageslink' ),
@@ -1069,7 +1137,7 @@
10701138 array( 'diff' => 'cur' ),
10711139 array( 'known', 'noclasses' )
10721140 );
1073 - $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
 1141+ $s[] = '<strong>' . wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
10741142 # disable caching
10751143 $wgOut->setSquidMaxage( 0 );
10761144 $wgOut->enableClientCache( false );
@@ -1077,9 +1145,11 @@
10781146 }
10791147
10801148 $undelete = $this->getUndeleteLink();
1081 - if( !empty( $undelete ) ) {
 1149+
 1150+ if ( !empty( $undelete ) ) {
10821151 $s[] = $undelete;
10831152 }
 1153+
10841154 return $wgLang->pipeList( $s );
10851155 }
10861156
@@ -1091,12 +1161,14 @@
10921162 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
10931163 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
10941164 $n = $this->mTitle->isDeleted();
 1165+
10951166 if ( $n ) {
10961167 if ( $wgUser->isAllowed( 'undelete' ) ) {
10971168 $msg = 'thisisdeleted';
10981169 } else {
10991170 $msg = 'viewdeleted';
11001171 }
 1172+
11011173 return wfMsg(
11021174 $msg,
11031175 $this->link(
@@ -1109,6 +1181,7 @@
11101182 );
11111183 }
11121184 }
 1185+
11131186 return '';
11141187 }
11151188
@@ -1122,8 +1195,8 @@
11231196 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
11241197 }
11251198
1126 - if( $wgOut->isSyndicated() ) {
1127 - foreach( $wgFeedClasses as $format => $class ) {
 1199+ if ( $wgOut->isSyndicated() ) {
 1200+ foreach ( $wgFeedClasses as $format => $class ) {
11281201 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
11291202 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
11301203 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
@@ -1146,36 +1219,43 @@
11471220 global $wgOut;
11481221
11491222 $sub = $wgOut->getSubtitle();
 1223+
11501224 if ( $sub == '' ) {
11511225 global $wgExtraSubtitle;
11521226 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
11531227 }
 1228+
11541229 $subpages = $this->subPageSubtitle();
11551230 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
11561231 $s = "<p class='subtitle'>{$sub}</p>\n";
 1232+
11571233 return $s;
11581234 }
11591235
11601236 function subPageSubtitle() {
11611237 $subpages = '';
1162 - if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
 1238+
 1239+ if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
11631240 return $subpages;
11641241 }
11651242
11661243 global $wgOut;
1167 - if( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
 1244+
 1245+ if ( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
11681246 $ptext = $this->mTitle->getPrefixedText();
1169 - if( preg_match( '/\//', $ptext ) ) {
 1247+ if ( preg_match( '/\//', $ptext ) ) {
11701248 $links = explode( '/', $ptext );
11711249 array_pop( $links );
11721250 $c = 0;
11731251 $growinglink = '';
11741252 $display = '';
1175 - foreach( $links as $link ) {
 1253+
 1254+ foreach ( $links as $link ) {
11761255 $growinglink .= $link;
11771256 $display .= $link;
11781257 $linkObj = Title::newFromText( $growinglink );
1179 - if( is_object( $linkObj ) && $linkObj->exists() ) {
 1258+
 1259+ if ( is_object( $linkObj ) && $linkObj->exists() ) {
11801260 $getlink = $this->link(
11811261 $linkObj,
11821262 htmlspecialchars( $display ),
@@ -1183,12 +1263,15 @@
11841264 array(),
11851265 array( 'known', 'noclasses' )
11861266 );
 1267+
11871268 $c++;
1188 - if( $c > 1 ) {
 1269+
 1270+ if ( $c > 1 ) {
11891271 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
11901272 } else {
11911273 $subpages .= '&lt; ';
11921274 }
 1275+
11931276 $subpages .= $getlink;
11941277 $display = '';
11951278 } else {
@@ -1198,6 +1281,7 @@
11991282 }
12001283 }
12011284 }
 1285+
12021286 return $subpages;
12031287 }
12041288
@@ -1215,8 +1299,9 @@
12161300 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
12171301
12181302 $ret = '';
 1303+
12191304 if ( $wgUser->isAnon() ) {
1220 - if( $this->showIPinHeader() ) {
 1305+ if ( $this->showIPinHeader() ) {
12211306 $name = wfGetIP();
12221307
12231308 $talkLink = $this->link( $wgUser->getTalkPage(),
@@ -1229,6 +1314,7 @@
12301315
12311316 $returnTo = $this->mTitle->getPrefixedDBkey();
12321317 $query = array();
 1318+
12331319 if ( $logoutPage != $returnTo ) {
12341320 $query['returnto'] = $returnTo;
12351321 }
@@ -1256,6 +1342,7 @@
12571343 $this->specialLink( 'preferences' ),
12581344 ) );
12591345 }
 1346+
12601347 $ret = $wgLang->pipeList( array(
12611348 $ret,
12621349 $this->link(
@@ -1278,6 +1365,7 @@
12791366
12801367 function searchForm() {
12811368 global $wgRequest, $wgUseTwoButtonsSearchForm;
 1369+
12821370 $search = $wgRequest->getText( 'search' );
12831371
12841372 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
@@ -1286,7 +1374,7 @@
12871375 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
12881376 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
12891377
1290 - if( $wgUseTwoButtonsSearchForm ) {
 1378+ if ( $wgUseTwoButtonsSearchForm ) {
12911379 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
12921380 } else {
12931381 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
@@ -1312,18 +1400,19 @@
13131401 $s[] = $this->editThisPage();
13141402 $s[] = $this->historyLink();
13151403 }
 1404+
13161405 # Many people don't like this dropdown box
1317 - #$s[] = $this->specialPagesList();
 1406+ # $s[] = $this->specialPagesList();
13181407
1319 - if( $this->variantLinks() ) {
 1408+ if ( $this->variantLinks() ) {
13201409 $s[] = $this->variantLinks();
13211410 }
13221411
1323 - if( $this->extensionTabLinks() ) {
 1412+ if ( $this->extensionTabLinks() ) {
13241413 $s[] = $this->extensionTabLinks();
13251414 }
13261415
1327 - // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
 1416+ // @todo FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
13281417 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
13291418 }
13301419
@@ -1338,13 +1427,13 @@
13391428 $out = '';
13401429 $s = array();
13411430 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1342 - foreach( $tabs as $tab ) {
 1431+ foreach ( $tabs as $tab ) {
13431432 $s[] = Xml::element( 'a',
13441433 array( 'href' => $tab['href'] ),
13451434 $tab['text'] );
13461435 }
13471436
1348 - if( count( $s ) ) {
 1437+ if ( count( $s ) ) {
13491438 global $wgLang;
13501439
13511440 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
@@ -1360,13 +1449,17 @@
13611450 */
13621451 function variantLinks() {
13631452 $s = '';
 1453+
13641454 /* show links to different language variants */
13651455 global $wgDisableLangConversion, $wgLang, $wgContLang;
 1456+
13661457 $variants = $wgContLang->getVariants();
1367 - if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1368 - foreach( $variants as $code ) {
 1458+
 1459+ if ( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
 1460+ foreach ( $variants as $code ) {
13691461 $varname = $wgContLang->getVariantname( $code );
1370 - if( $varname == 'disable' ) {
 1462+
 1463+ if ( $varname == 'disable' ) {
13711464 continue;
13721465 }
13731466 $s = $wgLang->pipeList( array(
@@ -1375,6 +1468,7 @@
13761469 ) );
13771470 }
13781471 }
 1472+
13791473 return $s;
13801474 }
13811475
@@ -1385,31 +1479,33 @@
13861480 $s = '';
13871481 if ( $wgOut->isArticleRelated() ) {
13881482 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
 1483+
13891484 if ( $wgUser->isLoggedIn() ) {
13901485 $element[] = $this->watchThisPage();
13911486 }
 1487+
13921488 $element[] = $this->talkLink();
13931489 $element[] = $this->historyLink();
13941490 $element[] = $this->whatLinksHere();
13951491 $element[] = $this->watchPageLinksLink();
13961492
1397 - if( $wgUseTrackbacks ) {
 1493+ if ( $wgUseTrackbacks ) {
13981494 $element[] = $this->trackbackLink();
13991495 }
14001496
14011497 if (
14021498 $this->mTitle->getNamespace() == NS_USER ||
14031499 $this->mTitle->getNamespace() == NS_USER_TALK
1404 - )
1405 - {
 1500+ ) {
14061501 $id = User::idFromName( $this->mTitle->getText() );
14071502 $ip = User::isIP( $this->mTitle->getText() );
14081503
14091504 # Both anons and non-anons have contributions list
1410 - if( $id || $ip ) {
 1505+ if ( $id || $ip ) {
14111506 $element[] = $this->userContribsLink();
14121507 }
1413 - if( $this->showEmailUser( $id ) ) {
 1508+
 1509+ if ( $this->showEmailUser( $id ) ) {
14141510 $element[] = $this->emailUserLink();
14151511 }
14161512 }
@@ -1418,17 +1514,21 @@
14191515
14201516 if ( $this->mTitle->getArticleId() ) {
14211517 $s .= "\n<br />";
 1518+
14221519 // Delete/protect/move links for privileged users
1423 - if( $wgUser->isAllowed( 'delete' ) ) {
 1520+ if ( $wgUser->isAllowed( 'delete' ) ) {
14241521 $s .= $this->deleteThisPage();
14251522 }
1426 - if( $wgUser->isAllowed( 'protect' ) ) {
 1523+
 1524+ if ( $wgUser->isAllowed( 'protect' ) ) {
14271525 $s .= $sep . $this->protectThisPage();
14281526 }
1429 - if( $wgUser->isAllowed( 'move' ) ) {
 1527+
 1528+ if ( $wgUser->isAllowed( 'move' ) ) {
14301529 $s .= $sep . $this->moveThisPage();
14311530 }
14321531 }
 1532+
14331533 $s .= "<br />\n" . $this->otherLanguages();
14341534 }
14351535
@@ -1441,34 +1541,40 @@
14421542
14431543 $oldid = $wgRequest->getVal( 'oldid' );
14441544 $diff = $wgRequest->getVal( 'diff' );
 1545+
14451546 if ( !$wgOut->isArticle() ) {
14461547 return '';
14471548 }
1448 - if( !$wgArticle instanceof Article ) {
 1549+
 1550+ if ( !$wgArticle instanceof Article ) {
14491551 return '';
14501552 }
 1553+
14511554 if ( isset( $oldid ) || isset( $diff ) ) {
14521555 return '';
14531556 }
 1557+
14541558 if ( 0 == $wgArticle->getID() ) {
14551559 return '';
14561560 }
14571561
14581562 $s = '';
 1563+
14591564 if ( !$wgDisableCounters ) {
14601565 $count = $wgLang->formatNum( $wgArticle->getCount() );
 1566+
14611567 if ( $count ) {
14621568 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
14631569 }
14641570 }
14651571
1466 - if( $wgMaxCredits != 0 ) {
 1572+ if ( $wgMaxCredits != 0 ) {
14671573 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
14681574 } else {
14691575 $s .= $this->lastModified();
14701576 }
14711577
1472 - if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
 1578+ if ( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
14731579 $dbr = wfGetDB( DB_SLAVE );
14741580 $res = $dbr->select(
14751581 'watchlist',
@@ -1495,6 +1601,7 @@
14961602 if ( $type == 'detect' ) {
14971603 $diff = $wgRequest->getVal( 'diff' );
14981604 $isCur = $wgArticle && $wgArticle->isCurrent();
 1605+
14991606 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
15001607 $type = 'history';
15011608 } else {
@@ -1509,20 +1616,23 @@
15101617 }
15111618
15121619 $out = '';
1513 - if( $wgRightsPage ) {
 1620+
 1621+ if ( $wgRightsPage ) {
15141622 $title = Title::newFromText( $wgRightsPage );
15151623 $link = $this->linkKnown( $title, $wgRightsText );
1516 - } elseif( $wgRightsUrl ) {
 1624+ } elseif ( $wgRightsUrl ) {
15171625 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1518 - } elseif( $wgRightsText ) {
 1626+ } elseif ( $wgRightsText ) {
15191627 $link = $wgRightsText;
15201628 } else {
15211629 # Give up now
15221630 return $out;
15231631 }
 1632+
15241633 // Allow for site and per-namespace customization of copyright notice.
15251634 $forContent = true;
1526 - if( isset( $wgArticle ) ) {
 1635+
 1636+ if ( isset( $wgArticle ) ) {
15271637 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
15281638 }
15291639
@@ -1531,26 +1641,33 @@
15321642 } else {
15331643 $out .= wfMsg( $msg, $link );
15341644 }
 1645+
15351646 return $out;
15361647 }
15371648
15381649 function getCopyrightIcon() {
15391650 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
 1651+
15401652 $out = '';
 1653+
15411654 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
15421655 $out = $wgCopyrightIcon;
15431656 } elseif ( $wgRightsIcon ) {
15441657 $icon = htmlspecialchars( $wgRightsIcon );
 1658+
15451659 if ( $wgRightsUrl ) {
15461660 $url = htmlspecialchars( $wgRightsUrl );
1547 - $out .= '<a href="'.$url.'">';
 1661+ $out .= '<a href="' . $url . '">';
15481662 }
 1663+
15491664 $text = htmlspecialchars( $wgRightsText );
15501665 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
 1666+
15511667 if ( $wgRightsUrl ) {
15521668 $out .= '</a>';
15531669 }
15541670 }
 1671+
15551672 return $out;
15561673 }
15571674
@@ -1560,18 +1677,22 @@
15611678 */
15621679 function getPoweredBy() {
15631680 global $wgStylePath;
 1681+
15641682 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
15651683 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
 1684+
15661685 return $img;
15671686 }
15681687
15691688 function lastModified() {
15701689 global $wgLang, $wgArticle;
1571 - if( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
 1690+
 1691+ if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
15721692 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
15731693 } else {
15741694 $timestamp = $wgArticle->getTimestamp();
15751695 }
 1696+
15761697 if ( $timestamp ) {
15771698 $d = $wgLang->date( $timestamp, true );
15781699 $t = $wgLang->time( $timestamp, true );
@@ -1579,9 +1700,11 @@
15801701 } else {
15811702 $s = '';
15821703 }
 1704+
15831705 if ( wfGetLB()->getLaggedSlaveMode() ) {
15841706 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
15851707 }
 1708+
15861709 return $s;
15871710 }
15881711
@@ -1598,6 +1721,7 @@
15991722
16001723 $logourl = $this->getLogo();
16011724 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
 1725+
16021726 return $s;
16031727 }
16041728
@@ -1606,7 +1730,9 @@
16071731 */
16081732 function specialPagesList() {
16091733 global $wgContLang, $wgServer, $wgRedirectScript;
 1734+
16101735 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
 1736+
16111737 foreach ( $pages as $name => $page ) {
16121738 $pages[$name] = $page->getDescription();
16131739 }
@@ -1625,9 +1751,11 @@
16261752 $p = $wgContLang->specialPage( $name );
16271753 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
16281754 }
 1755+
16291756 $s .= "</select>\n";
16301757 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
16311758 $s .= "</form>\n";
 1759+
16321760 return $s;
16331761 }
16341762
@@ -1643,12 +1771,13 @@
16441772 array(),
16451773 array( 'known', 'noclasses' )
16461774 );
 1775+
16471776 return $s;
16481777 }
16491778
16501779 private function footerLink( $desc, $page ) {
16511780 // if the link description has been set to "-" in the default language,
1652 - if ( wfMsgForContent( $desc ) == '-') {
 1781+ if ( wfMsgForContent( $desc ) == '-' ) {
16531782 // then it is disabled, for all languages.
16541783 return '';
16551784 } else {
@@ -1656,6 +1785,7 @@
16571786 // language (which may or may not be the same as the default language),
16581787 // but we make the link target be the one site-wide page.
16591788 $title = Title::newFromText( wfMsgForContent( $page ) );
 1789+
16601790 return $this->linkKnown(
16611791 $title,
16621792 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
@@ -1690,9 +1820,9 @@
16911821 if ( !$wgOut->isArticleRelated() ) {
16921822 $s = wfMsg( 'protectedpage' );
16931823 } else {
1694 - if( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
 1824+ if ( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
16951825 $t = wfMsg( 'editthispage' );
1696 - } elseif( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
 1826+ } elseif ( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
16971827 $t = wfMsg( 'create-this-page' );
16981828 } else {
16991829 $t = wfMsg( 'viewsource' );
@@ -1706,6 +1836,7 @@
17071837 array( 'known', 'noclasses' )
17081838 );
17091839 }
 1840+
17101841 return $s;
17111842 }
17121843
@@ -1721,7 +1852,7 @@
17221853
17231854 $options = array( 'action' => 'edit' );
17241855
1725 - if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
 1856+ if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
17261857 $options['oldid'] = intval( $this->mRevisionId );
17271858 }
17281859
@@ -1732,6 +1863,7 @@
17331864 global $wgUser, $wgRequest;
17341865
17351866 $diff = $wgRequest->getVal( 'diff' );
 1867+
17361868 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
17371869 $t = wfMsg( 'deletethispage' );
17381870
@@ -1745,6 +1877,7 @@
17461878 } else {
17471879 $s = '';
17481880 }
 1881+
17491882 return $s;
17501883 }
17511884
@@ -1752,7 +1885,8 @@
17531886 global $wgUser, $wgRequest;
17541887
17551888 $diff = $wgRequest->getVal( 'diff' );
1756 - if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
 1889+
 1890+ if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed( 'protect' ) ) {
17571891 if ( $this->mTitle->isProtected() ) {
17581892 $text = wfMsg( 'unprotectthispage' );
17591893 $query = array( 'action' => 'unprotect' );
@@ -1771,6 +1905,7 @@
17721906 } else {
17731907 $s = '';
17741908 }
 1909+
17751910 return $s;
17761911 }
17771912
@@ -1799,6 +1934,7 @@
18001935 } else {
18011936 $s = wfMsg( 'notanarticle' );
18021937 }
 1938+
18031939 return $s;
18041940 }
18051941
@@ -1865,6 +2001,7 @@
18662002
18672003 function watchPageLinksLink() {
18682004 global $wgOut;
 2005+
18692006 if ( !$wgOut->isArticleRelated() ) {
18702007 return '(' . wfMsg( 'notanarticle' ) . ')';
18712008 } else {
@@ -1891,19 +2028,23 @@
18922029 }
18932030
18942031 $a = $wgOut->getLanguageLinks();
 2032+
18952033 if ( 0 == count( $a ) ) {
18962034 return '';
18972035 }
18982036
18992037 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
19002038 $first = true;
1901 - if( $wgContLang->isRTL() ) {
 2039+
 2040+ if ( $wgContLang->isRTL() ) {
19022041 $s .= '<span dir="LTR">';
19032042 }
1904 - foreach( $a as $l ) {
 2043+
 2044+ foreach ( $a as $l ) {
19052045 if ( !$first ) {
19062046 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
19072047 }
 2048+
19082049 $first = false;
19092050
19102051 $nt = Title::newFromText( $l );
@@ -1914,12 +2055,15 @@
19152056 if ( $text == '' ) {
19162057 $text = $l;
19172058 }
 2059+
19182060 $style = $this->getExternalLinkAttributes();
19192061 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
19202062 }
1921 - if( $wgContLang->isRTL() ) {
 2063+
 2064+ if ( $wgContLang->isRTL() ) {
19222065 $s .= '</span>';
19232066 }
 2067+
19242068 return $s;
19252069 }
19262070
@@ -1931,7 +2075,7 @@
19322076
19332077 $linkOptions = array();
19342078
1935 - if( $this->mTitle->isTalkPage() ) {
 2079+ if ( $this->mTitle->isTalkPage() ) {
19362080 $link = $this->mTitle->getSubjectPage();
19372081 switch( $link->getNamespace() ) {
19382082 case NS_MAIN:
@@ -1946,7 +2090,7 @@
19472091 case NS_FILE:
19482092 $text = wfMsg( 'imagepage' );
19492093 # Make link known if image exists, even if the desc. page doesn't.
1950 - if( wfFindFile( $link ) )
 2094+ if ( wfFindFile( $link ) )
19512095 $linkOptions[] = 'known';
19522096 break;
19532097 case NS_MEDIAWIKI:
@@ -1984,9 +2128,9 @@
19852129 # __NEWSECTIONLINK___ changes behaviour here
19862130 # If it is present, the link points to this page, otherwise
19872131 # it points to the talk page
1988 - if( $this->mTitle->isTalkPage() ) {
 2132+ if ( $this->mTitle->isTalkPage() ) {
19892133 $title = $this->mTitle;
1990 - } elseif( $wgOut->showNewSectionLink() ) {
 2134+ } elseif ( $wgOut->showNewSectionLink() ) {
19912135 $title = $this->mTitle;
19922136 } else {
19932137 $title = $this->mTitle->getTalkPage();
@@ -2007,12 +2151,12 @@
20082152 function getUploadLink() {
20092153 global $wgUploadNavigationUrl;
20102154
2011 - if( $wgUploadNavigationUrl ) {
 2155+ if ( $wgUploadNavigationUrl ) {
20122156 # Using an empty class attribute to avoid automatic setting of "external" class
2013 - return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '') );
 2157+ return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '' ) );
20142158 } else {
20152159 return $this->link(
2016 - SpecialPage::getTitleFor('Upload'),
 2160+ SpecialPage::getTitleFor( 'Upload' ),
20172161 wfMsgHtml( 'upload' ),
20182162 array(),
20192163 array(),
@@ -2025,6 +2169,7 @@
20262170 static function makeMainPageUrl( $urlaction = '' ) {
20272171 $title = Title::newMainPage();
20282172 self::checkTitle( $title, '' );
 2173+
20292174 return $title->getLocalURL( $urlaction );
20302175 }
20312176
@@ -2047,6 +2192,7 @@
20482193 static function makeUrl( $name, $urlaction = '' ) {
20492194 $title = Title::newFromText( $name );
20502195 self::checkTitle( $title, $name );
 2196+
20512197 return $title->getLocalURL( $urlaction );
20522198 }
20532199
@@ -2066,6 +2212,7 @@
20672213 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
20682214 $title = Title::makeTitleSafe( $namespace, $name );
20692215 self::checkTitle( $title, $name );
 2216+
20702217 return $title->getLocalURL( $urlaction );
20712218 }
20722219
@@ -2073,6 +2220,7 @@
20742221 static function makeUrlDetails( $name, $urlaction = '' ) {
20752222 $title = Title::newFromText( $name );
20762223 self::checkTitle( $title, $name );
 2224+
20772225 return array(
20782226 'href' => $title->getLocalURL( $urlaction ),
20792227 'exists' => $title->getArticleID() != 0 ? true : false
@@ -2085,6 +2233,7 @@
20862234 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
20872235 $title = Title::newFromText( $name );
20882236 self::checkTitle( $title, $name );
 2237+
20892238 return array(
20902239 'href' => $title->getLocalURL( $urlaction ),
20912240 'exists' => true
@@ -2093,9 +2242,9 @@
20942243
20952244 # make sure we have some title to operate on
20962245 static function checkTitle( &$title, $name ) {
2097 - if( !is_object( $title ) ) {
 2246+ if ( !is_object( $title ) ) {
20982247 $title = Title::newFromText( $name );
2099 - if( !is_object( $title ) ) {
 2248+ if ( !is_object( $title ) ) {
21002249 $title = Title::newFromText( '--error: link target missing--' );
21012250 }
21022251 }
@@ -2128,6 +2277,7 @@
21292278 if ( $wgEnableSidebarCache ) {
21302279 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
21312280 }
 2281+
21322282 wfProfileOut( __METHOD__ );
21332283 return $bar;
21342284 }
@@ -2155,29 +2305,35 @@
21562306 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
21572307
21582308 $heading = '';
2159 - foreach( $lines as $line ) {
2160 - if( strpos( $line, '*' ) !== 0 ) {
 2309+
 2310+ foreach ( $lines as $line ) {
 2311+ if ( strpos( $line, '*' ) !== 0 ) {
21612312 continue;
21622313 }
2163 - if( strpos( $line, '**') !== 0 ) {
 2314+
 2315+ if ( strpos( $line, '**' ) !== 0 ) {
21642316 $heading = trim( $line, '* ' );
2165 - if( !array_key_exists( $heading, $bar ) ) {
 2317+ if ( !array_key_exists( $heading, $bar ) ) {
21662318 $bar[$heading] = array();
21672319 }
21682320 } else {
21692321 $line = trim( $line, '* ' );
2170 - if( strpos( $line, '|' ) !== false ) { // sanity check
 2322+
 2323+ if ( strpos( $line, '|' ) !== false ) { // sanity check
21712324 $line = array_map( 'trim', explode( '|', $line, 2 ) );
21722325 $link = wfMsgForContent( $line[0] );
2173 - if( $link == '-' ) {
 2326+
 2327+ if ( $link == '-' ) {
21742328 continue;
21752329 }
21762330
21772331 $text = wfMsgExt( $line[1], 'parsemag' );
2178 - if( wfEmptyMsg( $line[1], $text ) ) {
 2332+
 2333+ if ( wfEmptyMsg( $line[1], $text ) ) {
21792334 $text = $line[1];
21802335 }
2181 - if( wfEmptyMsg( $line[0], $link ) ) {
 2336+
 2337+ if ( wfEmptyMsg( $line[0], $link ) ) {
21822338 $link = $line[0];
21832339 }
21842340
@@ -2185,6 +2341,7 @@
21862342 $href = $link;
21872343 } else {
21882344 $title = Title::newFromText( $link );
 2345+
21892346 if ( $title ) {
21902347 $title = $title->fixSpecialName();
21912348 $href = $title->getLocalURL();
@@ -2199,15 +2356,16 @@
22002357 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
22012358 'active' => false
22022359 );
2203 - } else if ( (substr($line, 0, 2) == '{{') && (substr($line, -2) == '}}') ) {
 2360+ } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
22042361 global $wgParser, $wgTitle;
22052362
2206 - $line = substr($line, 2, strlen($line) - 4 );
 2363+ $line = substr( $line, 2, strlen( $line ) - 4 );
22072364
2208 - if (is_null($wgParser->mOptions))
 2365+ if ( is_null( $wgParser->mOptions ) ) {
22092366 $wgParser->mOptions = new ParserOptions();
 2367+ }
22102368
2211 - $wgParser->mOptions->setEditSection(false);
 2369+ $wgParser->mOptions->setEditSection( false );
22122370 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions )->getText();
22132371 } else {
22142372 continue;
@@ -2215,8 +2373,9 @@
22162374 }
22172375 }
22182376
2219 - if ( count($wikiBar) > 0 )
2220 - $bar = array_merge($bar, $wikiBar);
 2377+ if ( count( $wikiBar ) > 0 ) {
 2378+ $bar = array_merge( $bar, $wikiBar );
 2379+ }
22212380
22222381 return $bar;
22232382 }
@@ -2239,14 +2398,15 @@
22402399 */
22412400 function getNewtalks() {
22422401 global $wgUser, $wgOut;
 2402+
22432403 $newtalks = $wgUser->getNewMessageLinks();
22442404 $ntl = '';
22452405
2246 - if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
 2406+ if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
22472407 $userTitle = $this->mUser->getUserPage();
22482408 $userTalkTitle = $userTitle->getTalkPage();
22492409
2250 - if( !$userTalkTitle->equals( $this->mTitle ) ) {
 2410+ if ( !$userTalkTitle->equals( $this->mTitle ) ) {
22512411 $newMessagesLink = $this->link(
22522412 $userTalkTitle,
22532413 wfMsgHtml( 'newmessageslink' ),
@@ -2271,11 +2431,12 @@
22722432 # Disable Squid cache
22732433 $wgOut->setSquidMaxage( 0 );
22742434 }
2275 - } elseif( count( $newtalks ) ) {
 2435+ } elseif ( count( $newtalks ) ) {
22762436 // _>" " for BC <= 1.16
22772437 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
22782438 $msgs = array();
2279 - foreach( $newtalks as $newtalk ) {
 2439+
 2440+ foreach ( $newtalks as $newtalk ) {
22802441 $msgs[] = Xml::element(
22812442 'a',
22822443 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
@@ -2285,7 +2446,7 @@
22862447 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
22872448 $wgOut->setSquidMaxage( 0 );
22882449 }
 2450+
22892451 return $ntl;
22902452 }
2291 -
22922453 }
Index: trunk/phase3/includes/Exception.php
@@ -32,11 +32,13 @@
3333 */
3434 function useMessageCache() {
3535 global $wgLang;
 36+
3637 foreach ( $this->getTrace() as $frame ) {
3738 if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) {
3839 return false;
3940 }
4041 }
 42+
4143 return is_object( $wgLang );
4244 }
4345
@@ -49,20 +51,26 @@
5052 */
5153 function runHooks( $name, $args = array() ) {
5254 global $wgExceptionHooks;
53 - if( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) )
 55+
 56+ if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) {
5457 return; // Just silently ignore
55 - if( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[ $name ] ) )
 58+ }
 59+
 60+ if ( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[ $name ] ) ) {
5661 return;
 62+ }
 63+
5764 $hooks = $wgExceptionHooks[ $name ];
5865 $callargs = array_merge( array( $this ), $args );
5966
60 - foreach( $hooks as $hook ) {
61 - if( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) { //'function' or array( 'class', hook' )
 67+ foreach ( $hooks as $hook ) {
 68+ if ( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) { // 'function' or array( 'class', hook' )
6269 $result = call_user_func_array( $hook, $callargs );
6370 } else {
6471 $result = null;
6572 }
66 - if( is_string( $result ) )
 73+
 74+ if ( is_string( $result ) )
6775 return $result;
6876 }
6977 }
@@ -78,6 +86,7 @@
7987 */
8088 function msg( $key, $fallback /*[, params...] */ ) {
8189 $args = array_slice( func_get_args(), 2 );
 90+
8291 if ( $this->useMessageCache() ) {
8392 return wfMsgReal( $key, $args );
8493 } else {
@@ -94,7 +103,8 @@
95104 */
96105 function getHTML() {
97106 global $wgShowExceptionDetails;
98 - if( $wgShowExceptionDetails ) {
 107+
 108+ if ( $wgShowExceptionDetails ) {
99109 return '<p>' . nl2br( htmlspecialchars( $this->getMessage() ) ) .
100110 '</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
101111 "</p>\n";
@@ -111,7 +121,8 @@
112122 */
113123 function getText() {
114124 global $wgShowExceptionDetails;
115 - if( $wgShowExceptionDetails ) {
 125+
 126+ if ( $wgShowExceptionDetails ) {
116127 return $this->getMessage() .
117128 "\nBacktrace:\n" . $this->getTraceAsString() . "\n";
118129 } else {
@@ -126,6 +137,7 @@
127138 return wfMsg( 'internalerror' );
128139 } else {
129140 global $wgSitename;
 141+
130142 return "$wgSitename error";
131143 }
132144 }
@@ -138,9 +150,11 @@
139151 */
140152 function getLogMessage() {
141153 global $wgRequest;
 154+
142155 $file = $this->getFile();
143156 $line = $this->getLine();
144157 $message = $this->getMessage();
 158+
145159 if ( isset( $wgRequest ) ) {
146160 $url = $wgRequest->getRequestURL();
147161 if ( !$url ) {
@@ -156,6 +170,7 @@
157171 /** Output the exception report using HTML */
158172 function reportHTML() {
159173 global $wgOut;
 174+
160175 if ( $this->useOutputPage() ) {
161176 $wgOut->setPageTitle( $this->getPageTitle() );
162177 $wgOut->setRobotPolicy( "noindex,nofollow" );
@@ -163,16 +178,19 @@
164179 $wgOut->enableClientCache( false );
165180 $wgOut->redirect( '' );
166181 $wgOut->clearHTML();
167 - if( $hookResult = $this->runHooks( get_class( $this ) ) ) {
 182+
 183+ if ( $hookResult = $this->runHooks( get_class( $this ) ) ) {
168184 $wgOut->addHTML( $hookResult );
169185 } else {
170186 $wgOut->addHTML( $this->getHTML() );
171187 }
 188+
172189 $wgOut->output();
173190 } else {
174 - if( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
 191+ if ( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
175192 die( $hookResult );
176193 }
 194+
177195 if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) {
178196 echo $this->getHTML();
179197 } else {
@@ -189,9 +207,11 @@
190208 */
191209 function report() {
192210 $log = $this->getLogMessage();
 211+
193212 if ( $log ) {
194213 wfDebugLog( 'exception', $log );
195214 }
 215+
196216 if ( self::isCommandLine() ) {
197217 wfPrintError( $this->getText() );
198218 } else {
@@ -208,11 +228,12 @@
209229
210230 if ( !headers_sent() ) {
211231 header( 'HTTP/1.0 500 Internal Server Error' );
212 - header( 'Content-type: text/html; charset='.$wgOutputEncoding );
 232+ header( 'Content-type: text/html; charset=' . $wgOutputEncoding );
213233 /* Don't cache error pages! They cause no end of trouble... */
214234 header( 'Cache-control: none' );
215235 header( 'Pragma: nocache' );
216236 }
 237+
217238 $title = $this->getPageTitle();
218239 return "<html>
219240 <head>
@@ -274,6 +295,7 @@
275296
276297 function report() {
277298 global $wgOut;
 299+
278300 $wgOut->showErrorPage( $this->title, $this->msg );
279301 $wgOut->output();
280302 }
@@ -293,6 +315,7 @@
294316 global $wgShowExceptionDetails;
295317
296318 $cmdLine = MWException::isCommandLine();
 319+
297320 if ( $e instanceof MWException ) {
298321 try {
299322 $e->report();
@@ -301,6 +324,7 @@
302325 // Show a simpler error message for the original exception,
303326 // don't try to invoke report()
304327 $message = "MediaWiki internal error.\n\n";
 328+
305329 if ( $wgShowExceptionDetails ) {
306330 $message .= 'Original exception: ' . $e->__toString() . "\n\n" .
307331 'Exception caught inside exception handler: ' . $e2->__toString();
@@ -309,23 +333,27 @@
310334 "Set \$wgShowExceptionDetails = true; at the bottom of LocalSettings.php " .
311335 "to show detailed debugging information.";
312336 }
 337+
313338 $message .= "\n";
 339+
314340 if ( $cmdLine ) {
315341 wfPrintError( $message );
316342 } else {
317 - echo nl2br( htmlspecialchars( $message ) ). "\n";
 343+ echo nl2br( htmlspecialchars( $message ) ) . "\n";
318344 }
319345 }
320346 } else {
321347 $message = "Unexpected non-MediaWiki exception encountered, of type \"" . get_class( $e ) . "\"\n" .
322348 $e->__toString() . "\n";
 349+
323350 if ( $wgShowExceptionDetails ) {
324 - $message .= "\n" . $e->getTraceAsString() ."\n";
 351+ $message .= "\n" . $e->getTraceAsString() . "\n";
325352 }
 353+
326354 if ( $cmdLine ) {
327355 wfPrintError( $message );
328356 } else {
329 - echo nl2br( htmlspecialchars( $message ) ). "\n";
 357+ echo nl2br( htmlspecialchars( $message ) ) . "\n";
330358 }
331359 }
332360 }
@@ -335,7 +363,7 @@
336364 * Use this in command line mode only (see isCommandLine)
337365 */
338366 function wfPrintError( $message ) {
339 - #NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602).
 367+ # NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602).
340368 # Try to produce meaningful output anyway. Using echo may corrupt output to STDOUT though.
341369 if ( defined( 'STDERR' ) ) {
342370 fwrite( STDERR, $message );
@@ -357,6 +385,7 @@
358386 */
359387 function wfExceptionHandler( $e ) {
360388 global $wgFullyInitialised;
 389+
361390 wfReportException( $e );
362391
363392 // Final cleanup, similar to wfErrorExit()

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72342w/s changesmah01:06, 4 September 2010

Status & tagging log