* batch change for "while ( $row = $db->fetchObject( $res ) )" and similar to "foreac...
[lhc/web/wiklou.git] / maintenance / Maintenance.php
1 <?php
2 // Define this so scripts can easily find doMaintenance.php
3 define( 'DO_MAINTENANCE', dirname( __FILE__ ) . '/doMaintenance.php' );
4
5 // Make sure we're on PHP5 or better
6 if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) {
7 echo( "Sorry! This version of MediaWiki requires PHP 5; you are running " .
8 PHP_VERSION . ".\n\n" .
9 "If you are sure you already have PHP 5 installed, it may be installed\n" .
10 "in a different path from PHP 4. Check with your system administrator.\n" );
11 die();
12 }
13
14 /**
15 * Abstract maintenance class for quickly writing and churning out
16 * maintenance scripts with minimal effort. All that _must_ be defined
17 * is the execute() method. See docs/maintenance.txt for more info
18 * and a quick demo of how to use it.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 * http://www.gnu.org/copyleft/gpl.html
34 *
35 * @author Chad Horohoe <chad@anyonecanedit.org>
36 * @since 1.16
37 * @ingroup Maintenance
38 */
39 abstract class Maintenance {
40
41 /**
42 * Constants for DB access type
43 * @see Maintenance::getDbType()
44 */
45 const DB_NONE = 0;
46 const DB_STD = 1;
47 const DB_ADMIN = 2;
48
49 // Const for getStdin()
50 const STDIN_ALL = 'all';
51
52 // This is the desired params
53 private $mParams = array();
54
55 // Array of desired args
56 private $mArgList = array();
57
58 // This is the list of options that were actually passed
59 private $mOptions = array();
60
61 // This is the list of arguments that were actually passed
62 protected $mArgs = array();
63
64 // Name of the script currently running
65 protected $mSelf;
66
67 // Special vars for params that are always used
68 private $mQuiet = false;
69 private $mDbUser, $mDbPass;
70
71 // A description of the script, children should change this
72 protected $mDescription = '';
73
74 // Have we already loaded our user input?
75 private $mInputLoaded = false;
76
77 // Batch size. If a script supports this, they should set
78 // a default with setBatchSize()
79 protected $mBatchSize = null;
80
81 /**
82 * List of all the core maintenance scripts. This is added
83 * to scripts added by extensions in $wgMaintenanceScripts
84 * and returned by getMaintenanceScripts()
85 */
86 protected static $mCoreScripts = null;
87
88 /**
89 * Default constructor. Children should call this if implementing
90 * their own constructors
91 */
92 public function __construct() {
93 $this->addDefaultParams();
94 }
95
96 /**
97 * Do the actual work. All child classes will need to implement this
98 */
99 abstract public function execute();
100
101 /**
102 * Add a parameter to the script. Will be displayed on --help
103 * with the associated description
104 *
105 * @param $name String The name of the param (help, version, etc)
106 * @param $description String The description of the param to show on --help
107 * @param $required boolean Is the param required?
108 * @param $withArg Boolean Is an argument required with this option?
109 */
110 protected function addOption( $name, $description, $required = false, $withArg = false ) {
111 $this->mParams[$name] = array( 'desc' => $description, 'require' => $required, 'withArg' => $withArg );
112 }
113
114 /**
115 * Checks to see if a particular param exists.
116 * @param $name String The name of the param
117 * @return boolean
118 */
119 protected function hasOption( $name ) {
120 return isset( $this->mOptions[$name] );
121 }
122
123 /**
124 * Get an option, or return the default
125 * @param $name String The name of the param
126 * @param $default mixed Anything you want, default null
127 * @return mixed
128 */
129 protected function getOption( $name, $default = null ) {
130 if( $this->hasOption( $name ) ) {
131 return $this->mOptions[$name];
132 } else {
133 // Set it so we don't have to provide the default again
134 $this->mOptions[$name] = $default;
135 return $this->mOptions[$name];
136 }
137 }
138
139 /**
140 * Add some args that are needed. Used in formatting help
141 */
142 protected function addArgs( $args ) {
143 $this->mArgList = array_merge( $this->mArgList, $args );
144 }
145
146 /**
147 * Does a given argument exist?
148 * @param $argId int The integer value (from zero) for the arg
149 * @return boolean
150 */
151 protected function hasArg( $argId = 0 ) {
152 return isset( $this->mArgs[$argId] );
153 }
154
155 /**
156 * Get an argument.
157 * @param $argId int The integer value (from zero) for the arg
158 * @param $default mixed The default if it doesn't exist
159 * @return mixed
160 */
161 protected function getArg( $argId = 0, $default = null ) {
162 return $this->hasArg( $argId ) ? $this->mArgs[$argId] : $default;
163 }
164
165 /**
166 * Set the batch size.
167 * @param $s int The number of operations to do in a batch
168 */
169 protected function setBatchSize( $s = 0 ) {
170 $this->mBatchSize = $s;
171 }
172
173 /**
174 * Get the script's name
175 * @return String
176 */
177 public function getName() {
178 return $this->mSelf;
179 }
180
181 /**
182 * Return input from stdin.
183 * @param $length int The number of bytes to read. If null,
184 * just return the handle. Maintenance::STDIN_ALL returns
185 * the full length
186 * @return mixed
187 */
188 protected function getStdin( $len = null ) {
189 if ( $len == Maintenance::STDIN_ALL )
190 return file_get_contents( 'php://stdin' );
191 $f = fopen( 'php://stdin', 'rt' );
192 if( !$len )
193 return $f;
194 $input = fgets( $f, $len );
195 fclose( $f );
196 return rtrim( $input );
197 }
198
199 /**
200 * Throw some output to the user. Scripts can call this with no fears,
201 * as we handle all --quiet stuff here
202 * @param $out String The text to show to the user
203 */
204 protected function output( $out ) {
205 if( $this->mQuiet ) {
206 return;
207 }
208 $f = fopen( 'php://stdout', 'w' );
209 fwrite( $f, $out );
210 fclose( $f );
211 }
212
213 /**
214 * Throw an error to the user. Doesn't respect --quiet, so don't use
215 * this for non-error output
216 * @param $err String The error to display
217 * @param $die boolean If true, go ahead and die out.
218 */
219 protected function error( $err, $die = false ) {
220 $f = fopen( 'php://stderr', 'w' );
221 fwrite( $f, $err . "\n" );
222 fclose( $f );
223 if( $die ) die();
224 }
225
226 /**
227 * Does the script need different DB access? By default, we give Maintenance
228 * scripts normal rights to the DB. Sometimes, a script needs admin rights
229 * access for a reason and sometimes they want no access. Subclasses should
230 * override and return one of the following values, as needed:
231 * Maintenance::DB_NONE - For no DB access at all
232 * Maintenance::DB_STD - For normal DB access, default
233 * Maintenance::DB_ADMIN - For admin DB access
234 * @return int
235 */
236 protected function getDbType() {
237 return Maintenance::DB_STD;
238 }
239
240 /**
241 * Add the default parameters to the scripts
242 */
243 private function addDefaultParams() {
244 $this->addOption( 'help', "Display this help message" );
245 $this->addOption( 'quiet', "Whether to supress non-error output" );
246 $this->addOption( 'conf', "Location of LocalSettings.php, if not default", false, true );
247 $this->addOption( 'wiki', "For specifying the wiki ID", false, true );
248 $this->addOption( 'globals', "Output globals at the end of processing for debugging" );
249 // If we support a DB, show the options
250 if( $this->getDbType() > 0 ) {
251 $this->addOption( 'dbuser', "The DB user to use for this script", false, true );
252 $this->addOption( 'dbpass', "The password to use for this script", false, true );
253 }
254 // If we support $mBatchSize, show the option
255 if( $this->mBatchSize ) {
256 $this->addOption( 'batch-size', 'Run this many operations ' .
257 'per batch, default: ' . $this->mBatchSize , false, true );
258 }
259 }
260
261 /**
262 * Spawn a child maintenance script. Pass all of the current arguments
263 * to it.
264 * @param $maintClass String A name of a child maintenance class
265 * @param $classFile String Full path of where the child is
266 * @return Maintenance child
267 */
268 protected function spawnChild( $maintClass, $classFile = null ) {
269 // If we haven't already specified, kill setup procedures
270 // for child scripts, we've already got a sane environment
271 self::disableSetup();
272
273 // Make sure the class is loaded first
274 if( !class_exists( $maintClass ) ) {
275 if( $classFile ) {
276 require_once( $classFile );
277 }
278 if( !class_exists( $maintClass ) ) {
279 $this->error( "Cannot spawn child: $maintClass" );
280 }
281 }
282
283 $child = new $maintClass();
284 $child->loadParamsAndArgs( $this->mSelf, $this->mOptions, $this->mArgs );
285 return $child;
286 }
287
288 /**
289 * Disable Setup.php mostly
290 */
291 protected static function disableSetup() {
292 if( !defined( 'MW_NO_SETUP' ) )
293 define( 'MW_NO_SETUP', true );
294 }
295
296 /**
297 * Do some sanity checking and basic setup
298 */
299 public function setup() {
300 global $IP, $wgCommandLineMode, $wgUseNormalUser, $wgRequestTime;
301
302 # Abort if called from a web server
303 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
304 $this->error( "This script must be run from the command line", true );
305 }
306
307 # Make sure we can handle script parameters
308 if( !ini_get( 'register_argc_argv' ) ) {
309 $this->error( "Cannot get command line arguments, register_argc_argv is set to false", true );
310 }
311
312 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
313 // Send PHP warnings and errors to stderr instead of stdout.
314 // This aids in diagnosing problems, while keeping messages
315 // out of redirected output.
316 if( ini_get( 'display_errors' ) ) {
317 ini_set( 'display_errors', 'stderr' );
318 }
319
320 // Don't touch the setting on earlier versions of PHP,
321 // as setting it would disable output if you'd wanted it.
322
323 // Note that exceptions are also sent to stderr when
324 // command-line mode is on, regardless of PHP version.
325 }
326
327 # Set the memory limit
328 ini_set( 'memory_limit', -1 );
329
330 # Set max execution time to 0 (no limit). PHP.net says that
331 # "When running PHP from the command line the default setting is 0."
332 # But sometimes this doesn't seem to be the case.
333 ini_set( 'max_execution_time', 0 );
334
335 $wgRequestTime = microtime( true );
336
337 # Define us as being in MediaWiki
338 define( 'MEDIAWIKI', true );
339
340 # Setup $IP, using MW_INSTALL_PATH if it exists
341 $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
342 ? getenv( 'MW_INSTALL_PATH' )
343 : realpath( dirname( __FILE__ ) . '/..' );
344
345 $wgCommandLineMode = true;
346 # Turn off output buffering if it's on
347 @ob_end_flush();
348
349 if ( !isset( $wgUseNormalUser ) ) {
350 $wgUseNormalUser = false;
351 }
352
353 $this->loadParamsAndArgs();
354 $this->maybeHelp();
355 $this->validateParamsAndArgs();
356 }
357
358 /**
359 * Clear all params and arguments.
360 */
361 public function clearParamsAndArgs() {
362 $this->mOptions = array();
363 $this->mArgs = array();
364 $this->mInputLoaded = false;
365 }
366
367 /**
368 * Process command line arguments
369 * $mOptions becomes an array with keys set to the option names
370 * $mArgs becomes a zero-based array containing the non-option arguments
371 *
372 * @param $self String The name of the script, if any
373 * @param $opts Array An array of options, in form of key=>value
374 * @param $args Array An array of command line arguments
375 */
376 public function loadParamsAndArgs( $self = null, $opts = null, $args = null ) {
377 # If we were given opts or args, set those and return early
378 if( $self ) {
379 $this->mSelf = $self;
380 $this->mInputLoaded = true;
381 }
382 if( $opts ) {
383 $this->mOptions = $opts;
384 $this->mInputLoaded = true;
385 }
386 if( $args ) {
387 $this->mArgs = $args;
388 $this->mInputLoaded = true;
389 }
390
391 # If we've already loaded input (either by user values or from $argv)
392 # skip on loading it again. The array_shift() will corrupt values if
393 # it's run again and again
394 if( $this->mInputLoaded ) {
395 $this->loadSpecialVars();
396 return;
397 }
398
399 global $argv;
400 $this->mSelf = array_shift( $argv );
401
402 $options = array();
403 $args = array();
404
405 # Parse arguments
406 for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) {
407 if ( $arg == '--' ) {
408 # End of options, remainder should be considered arguments
409 $arg = next( $argv );
410 while( $arg !== false ) {
411 $args[] = $arg;
412 $arg = next( $argv );
413 }
414 break;
415 } elseif ( substr( $arg, 0, 2 ) == '--' ) {
416 # Long options
417 $option = substr( $arg, 2 );
418 if ( isset( $this->mParams[$option] ) && $this->mParams[$option]['withArg'] ) {
419 $param = next( $argv );
420 if ( $param === false ) {
421 $this->error( "\nERROR: $option needs a value after it\n" );
422 $this->maybeHelp( true );
423 }
424 $options[$option] = $param;
425 } else {
426 $bits = explode( '=', $option, 2 );
427 if( count( $bits ) > 1 ) {
428 $option = $bits[0];
429 $param = $bits[1];
430 } else {
431 $param = 1;
432 }
433 $options[$option] = $param;
434 }
435 } elseif ( substr( $arg, 0, 1 ) == '-' ) {
436 # Short options
437 for ( $p=1; $p<strlen( $arg ); $p++ ) {
438 $option = $arg{$p};
439 if ( $this->mParams[$option]['withArg'] ) {
440 $param = next( $argv );
441 if ( $param === false ) {
442 $this->error( "\nERROR: $option needs a value after it\n" );
443 $this->maybeHelp( true );
444 }
445 $options[$option] = $param;
446 } else {
447 $options[$option] = 1;
448 }
449 }
450 } else {
451 $args[] = $arg;
452 }
453 }
454
455 $this->mOptions = $options;
456 $this->mArgs = $args;
457 $this->loadSpecialVars();
458 $this->mInputLoaded = true;
459 }
460
461 /**
462 * Run some validation checks on the params, etc
463 */
464 private function validateParamsAndArgs() {
465 # Check to make sure we've got all the required ones
466 foreach( $this->mParams as $opt => $info ) {
467 if( $info['require'] && !$this->hasOption( $opt ) ) {
468 $this->error( "Param $opt required.", true );
469 }
470 }
471
472 # Also make sure we've got enough arguments
473 if ( count( $this->mArgs ) < count( $this->mArgList ) ) {
474 $this->error( "Not enough arguments passed", true );
475 }
476 }
477
478 /**
479 * Handle the special variables that are global to all scripts
480 */
481 private function loadSpecialVars() {
482 if( $this->hasOption( 'dbuser' ) )
483 $this->mDbUser = $this->getOption( 'dbuser' );
484 if( $this->hasOption( 'dbpass' ) )
485 $this->mDbPass = $this->getOption( 'dbpass' );
486 if( $this->hasOption( 'quiet' ) )
487 $this->mQuiet = true;
488 if( $this->hasOption( 'batch-size' ) )
489 $this->mBatchSize = $this->getOption( 'batch-size' );
490 }
491
492 /**
493 * Maybe show the help.
494 * @param $force boolean Whether to force the help to show, default false
495 */
496 private function maybeHelp( $force = false ) {
497 ksort( $this->mParams );
498 if( $this->hasOption( 'help' ) || in_array( 'help', $this->mArgs ) || $force ) {
499 $this->mQuiet = false;
500 if( $this->mDescription ) {
501 $this->output( "\n" . $this->mDescription . "\n" );
502 }
503 $this->output( "\nUsage: php " . $this->mSelf );
504 if( $this->mParams ) {
505 $this->output( " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]" );
506 }
507 if( $this->mArgList ) {
508 $this->output( " <" . implode( $this->mArgList, "> <" ) . ">" );
509 }
510 $this->output( "\n" );
511 foreach( $this->mParams as $par => $info ) {
512 $this->output( "\t$par : " . $info['desc'] . "\n" );
513 }
514 die( 1 );
515 }
516 }
517
518 /**
519 * Handle some last-minute setup here.
520 */
521 public function finalSetup() {
522 global $wgCommandLineMode, $wgUseNormalUser, $wgShowSQLErrors;
523 global $wgTitle, $wgProfiling, $IP, $wgDBadminuser, $wgDBadminpassword;
524 global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
525
526 # Turn off output buffering again, it might have been turned on in the settings files
527 if( ob_get_level() ) {
528 ob_end_flush();
529 }
530 # Same with these
531 $wgCommandLineMode = true;
532
533 # If these were passed, use them
534 if( $this->mDbUser )
535 $wgDBadminuser = $this->mDbUser;
536 if( $this->mDbPass )
537 $wgDBadminpassword = $this->mDbPass;
538
539 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
540 $wgDBuser = $wgDBadminuser;
541 $wgDBpassword = $wgDBadminpassword;
542
543 if( $wgDBservers ) {
544 foreach ( $wgDBservers as $i => $server ) {
545 $wgDBservers[$i]['user'] = $wgDBuser;
546 $wgDBservers[$i]['password'] = $wgDBpassword;
547 }
548 }
549 if( isset( $wgLBFactoryConf['serverTemplate'] ) ) {
550 $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser;
551 $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword;
552 }
553 }
554
555 if ( defined( 'MW_CMDLINE_CALLBACK' ) ) {
556 $fn = MW_CMDLINE_CALLBACK;
557 $fn();
558 }
559
560 $wgShowSQLErrors = true;
561 @set_time_limit( 0 );
562
563 $wgProfiling = false; // only for Profiler.php mode; avoids OOM errors
564 }
565
566 /**
567 * Potentially debug globals. Originally a feature only
568 * for refreshLinks
569 */
570 public function globals() {
571 if( $this->hasOption( 'globals' ) ) {
572 print_r( $GLOBALS );
573 }
574 }
575
576 /**
577 * Do setup specific to WMF
578 */
579 public function loadWikimediaSettings() {
580 global $IP, $wgNoDBParam, $wgUseNormalUser, $wgConf, $site, $lang;
581
582 if ( empty( $wgNoDBParam ) ) {
583 # Check if we were passed a db name
584 if ( isset( $this->mOptions['wiki'] ) ) {
585 $db = $this->mOptions['wiki'];
586 } else {
587 $db = array_shift( $this->mArgs );
588 }
589 list( $site, $lang ) = $wgConf->siteFromDB( $db );
590
591 # If not, work out the language and site the old way
592 if ( is_null( $site ) || is_null( $lang ) ) {
593 if ( !$db ) {
594 $lang = 'aa';
595 } else {
596 $lang = $db;
597 }
598 if ( isset( $this->mArgs[0] ) ) {
599 $site = array_shift( $this->mArgs );
600 } else {
601 $site = 'wikipedia';
602 }
603 }
604 } else {
605 $lang = 'aa';
606 $site = 'wikipedia';
607 }
608
609 # This is for the IRC scripts, which now run as the apache user
610 # The apache user doesn't have access to the wikiadmin_pass command
611 if ( $_ENV['USER'] == 'apache' ) {
612 #if ( posix_geteuid() == 48 ) {
613 $wgUseNormalUser = true;
614 }
615
616 putenv( 'wikilang=' . $lang );
617
618 $DP = $IP;
619 ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
620
621 if ( $lang == 'test' && $site == 'wikipedia' ) {
622 define( 'TESTWIKI', 1 );
623 }
624 }
625
626 /**
627 * Generic setup for most installs. Returns the location of LocalSettings
628 * @return String
629 */
630 public function loadSettings() {
631 global $wgWikiFarm, $wgCommandLineMode, $IP, $DP;
632
633 $wgWikiFarm = false;
634 if ( isset( $this->mOptions['conf'] ) ) {
635 $settingsFile = $this->mOptions['conf'];
636 } else {
637 $settingsFile = "$IP/LocalSettings.php";
638 }
639 if ( isset( $this->mOptions['wiki'] ) ) {
640 $bits = explode( '-', $this->mOptions['wiki'] );
641 if ( count( $bits ) == 1 ) {
642 $bits[] = '';
643 }
644 define( 'MW_DB', $bits[0] );
645 define( 'MW_PREFIX', $bits[1] );
646 }
647
648 if ( !is_readable( $settingsFile ) ) {
649 $this->error( "A copy of your installation's LocalSettings.php\n" .
650 "must exist and be readable in the source directory.", true );
651 }
652 $wgCommandLineMode = true;
653 $DP = $IP;
654 return $settingsFile;
655 }
656
657 /**
658 * Support function for cleaning up redundant text records
659 * @param $delete boolean Whether or not to actually delete the records
660 * @author Rob Church <robchur@gmail.com>
661 */
662 protected function purgeRedundantText( $delete = true ) {
663 # Data should come off the master, wrapped in a transaction
664 $dbw = wfGetDB( DB_MASTER );
665 $dbw->begin();
666
667 $tbl_arc = $dbw->tableName( 'archive' );
668 $tbl_rev = $dbw->tableName( 'revision' );
669 $tbl_txt = $dbw->tableName( 'text' );
670
671 # Get "active" text records from the revisions table
672 $this->output( "Searching for active text records in revisions table..." );
673 $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
674 foreach( $res as $row ) {
675 $cur[] = $row->rev_text_id;
676 }
677 $this->output( "done.\n" );
678
679 # Get "active" text records from the archive table
680 $this->output( "Searching for active text records in archive table..." );
681 $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
682 foreach( $res as $row ) {
683 $cur[] = $row->ar_text_id;
684 }
685 $this->output( "done.\n" );
686
687 # Get the IDs of all text records not in these sets
688 $this->output( "Searching for inactive text records..." );
689 $set = implode( ', ', $cur );
690 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
691 $old = array();
692 foreach( $res as $row ) {
693 $old[] = $row->old_id;
694 }
695 $this->output( "done.\n" );
696
697 # Inform the user of what we're going to do
698 $count = count( $old );
699 $this->output( "$count inactive items found.\n" );
700
701 # Delete as appropriate
702 if( $delete && $count ) {
703 $this->output( "Deleting..." );
704 $set = implode( ', ', $old );
705 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
706 $this->output( "done.\n" );
707 }
708
709 # Done
710 $dbw->commit();
711 }
712
713 /**
714 * Get the maintenance directory.
715 */
716 protected function getDir() {
717 return dirname( __FILE__ );
718 }
719
720 /**
721 * Get the list of available maintenance scripts. Note
722 * that if you call this _before_ calling doMaintenance
723 * you won't have any extensions in it yet
724 * @return array
725 */
726 public static function getMaintenanceScripts() {
727 global $wgMaintenanceScripts;
728 return $wgMaintenanceScripts + self::getCoreScripts();
729 }
730
731 /**
732 * Return all of the core maintenance scripts
733 * @return array
734 */
735 private static function getCoreScripts() {
736 if( !self::$mCoreScripts ) {
737 self::disableSetup();
738 $paths = array(
739 dirname( __FILE__ ),
740 dirname( __FILE__ ) . '/gearman',
741 dirname( __FILE__ ) . '/language',
742 dirname( __FILE__ ) . '/storage',
743 );
744 self::$mCoreScripts = array();
745 foreach( $paths as $p ) {
746 $handle = opendir( $p );
747 while( ( $file = readdir( $handle ) ) !== false ) {
748 if( $file == 'Maintenance.php' )
749 continue;
750 $file = $p . '/' . $file;
751 if( is_dir( $file ) || !strpos( $file, '.php' ) ||
752 ( strpos( file_get_contents( $file ), '$maintClass' ) === false ) ) {
753 continue;
754 }
755 require( $file );
756 $vars = get_defined_vars();
757 if( array_key_exists( 'maintClass', $vars ) ) {
758 self::$mCoreScripts[$vars['maintClass']] = $file;
759 }
760 }
761 closedir( $handle );
762 }
763 }
764 return self::$mCoreScripts;
765 }
766 }