Index: trunk/phase3/maintenance/nukeNS.php |
— | — | @@ -80,7 +80,7 @@ |
81 | 81 | $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" ); |
82 | 82 | $dbw->commit(); |
83 | 83 | // Delete revisions as appropriate |
84 | | - $child = $this->spawnChild( 'NukePage', 'NukePage.php' ); |
| 84 | + $child = $this->runChild( 'NukePage', 'NukePage.php' ); |
85 | 85 | $child->deleteRevisions( $revs ); |
86 | 86 | $this->purgeRedundantText( true ); |
87 | 87 | $n_deleted ++; |
Index: trunk/phase3/maintenance/rebuildall.php |
— | — | @@ -34,18 +34,18 @@ |
35 | 35 | // Rebuild the text index |
36 | 36 | if ( $wgDBtype == 'mysql' ) { |
37 | 37 | $this->output( "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n" ); |
38 | | - $rebuildText = $this->spawnChild( 'RebuildTextIndex', 'rebuildtextindex.php' ); |
| 38 | + $rebuildText = $this->runChild( 'RebuildTextIndex', 'rebuildtextindex.php' ); |
39 | 39 | $rebuildText->execute(); |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Rebuild RC |
43 | 43 | $this->output( "\n\n** Rebuilding recentchanges table:\n" ); |
44 | | - $rebuildRC = $this->spawnChild( 'RebuildRecentchanges', 'rebuildrecentchanges.php' ); |
| 44 | + $rebuildRC = $this->runChild( 'RebuildRecentchanges', 'rebuildrecentchanges.php' ); |
45 | 45 | $rebuildRC->execute(); |
46 | 46 | |
47 | 47 | // Rebuild link tables |
48 | 48 | $this->output( "\n\n** Rebuilding links tables -- this can take a long time. It should be safe to abort via ctrl+C if you get bored.\n" ); |
49 | | - $rebuildLinks = $this->spawnChild( 'RefreshLinks', 'refreshLinks.php' ); |
| 49 | + $rebuildLinks = $this->runChild( 'RefreshLinks', 'refreshLinks.php' ); |
50 | 50 | $rebuildLinks->execute(); |
51 | 51 | |
52 | 52 | $this->output( "Done.\n" ); |
Index: trunk/phase3/maintenance/doMaintenance.php |
— | — | @@ -31,8 +31,6 @@ |
32 | 32 | exit( 1 ); |
33 | 33 | } |
34 | 34 | |
35 | | -error_reporting( E_ALL | E_STRICT ); |
36 | | - |
37 | 35 | if( !$maintClass || !class_exists( $maintClass ) ) { |
38 | 36 | echo "\$maintClass is not set or is set to a non-existent class."; |
39 | 37 | exit( 1 ); |
Index: trunk/phase3/maintenance/commandLine.inc |
— | — | @@ -1,264 +1,30 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * @file |
5 | | - * @todo document |
6 | | - * @ingroup Maintenance |
7 | | - * @defgroup Maintenance Maintenance |
| 5 | + * Backwards-compatibility wrapper for old-style maintenance scripts |
8 | 6 | */ |
| 7 | +require( dirname(__FILE__) . '/Maintenance.php' ); |
| 8 | +$optionsWithArgs = array(); |
9 | 9 | |
10 | | -$wgRequestTime = microtime(true); |
11 | | - |
12 | | -/** */ |
13 | | -# Abort if called from a web server |
14 | | -if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) { |
15 | | - print "This script must be run from the command line\n"; |
16 | | - exit(); |
17 | | -} |
18 | | - |
19 | | -if( version_compare( PHP_VERSION, '5.0.0' ) < 0 ) { |
20 | | - print "Sorry! This version of MediaWiki requires PHP 5; you are running " . |
21 | | - PHP_VERSION . ".\n\n" . |
22 | | - "If you are sure you already have PHP 5 installed, it may be " . |
23 | | - "installed\n" . |
24 | | - "in a different path from PHP 4. Check with your system administrator.\n"; |
25 | | - die( -1 ); |
26 | | -} |
27 | | - |
28 | | -define('MEDIAWIKI',true); |
29 | | - |
30 | | -# Process command line arguments |
31 | | -# $options becomes an array with keys set to the option names |
32 | | -# $optionsWithArgs is an array of GNU-style options that take an argument. The arguments are returned |
33 | | -# in the values of $options. |
34 | | -# $args becomes a zero-based array containing the non-option arguments |
35 | | - |
36 | | -if ( !isset( $optionsWithArgs ) ) { |
37 | | - $optionsWithArgs = array(); |
38 | | -} |
39 | | -$optionsWithArgs[] = 'conf'; # For specifying the location of LocalSettings.php |
40 | | -$optionsWithArgs[] = 'aconf'; # As above for AdminSettings.php |
41 | | -$optionsWithArgs[] = 'wiki'; # For specifying the wiki ID |
42 | | - |
43 | | -$self = array_shift( $argv ); |
44 | | -$IP = strval( getenv('MW_INSTALL_PATH') ) !== '' |
45 | | - ? getenv('MW_INSTALL_PATH') |
46 | | - : realpath( dirname( __FILE__ ) . '/..' ); |
47 | | -#chdir( $IP ); |
48 | | -if ( file_exists( "$IP/StartProfiler.php" ) ) { |
49 | | - require_once( "$IP/StartProfiler.php" ); |
50 | | -} else { |
51 | | - require_once( "$IP/includes/ProfilerStub.php" ); |
52 | | -} |
53 | | - |
54 | | -$options = array(); |
55 | | -$args = array(); |
56 | | - |
57 | | - |
58 | | -# Parse arguments |
59 | | -for( $arg = reset( $argv ); $arg !== false; $arg = next( $argv ) ) { |
60 | | - if ( $arg == '--' ) { |
61 | | - # End of options, remainder should be considered arguments |
62 | | - $arg = next( $argv ); |
63 | | - while( $arg !== false ) { |
64 | | - $args[] = $arg; |
65 | | - $arg = next( $argv ); |
| 10 | +class CommandLineInc extends Maintenance { |
| 11 | + public function __construct() { |
| 12 | + global $optionsWithArgs; |
| 13 | + parent::__construct(); |
| 14 | + foreach ( $optionsWithArgs as $name ) { |
| 15 | + $this->addOption( $name, '', false, true ); |
66 | 16 | } |
67 | | - break; |
68 | | - } elseif ( substr( $arg, 0, 2 ) == '--' ) { |
69 | | - # Long options |
70 | | - $option = substr( $arg, 2 ); |
71 | | - if ( in_array( $option, $optionsWithArgs ) ) { |
72 | | - $param = next( $argv ); |
73 | | - if ( $param === false ) { |
74 | | - echo "$arg needs a value after it\n"; |
75 | | - die( -1 ); |
76 | | - } |
77 | | - $options[$option] = $param; |
78 | | - } else { |
79 | | - $bits = explode( '=', $option, 2 ); |
80 | | - if( count( $bits ) > 1 ) { |
81 | | - $option = $bits[0]; |
82 | | - $param = $bits[1]; |
83 | | - } else { |
84 | | - $param = 1; |
85 | | - } |
86 | | - $options[$option] = $param; |
87 | | - } |
88 | | - } elseif ( substr( $arg, 0, 1 ) == '-' ) { |
89 | | - # Short options |
90 | | - for ( $p=1; $p<strlen( $arg ); $p++ ) { |
91 | | - $option = $arg{$p}; |
92 | | - if ( in_array( $option, $optionsWithArgs ) ) { |
93 | | - $param = next( $argv ); |
94 | | - if ( $param === false ) { |
95 | | - echo "$arg needs a value after it\n"; |
96 | | - die( -1 ); |
97 | | - } |
98 | | - $options[$option] = $param; |
99 | | - } else { |
100 | | - $options[$option] = 1; |
101 | | - } |
102 | | - } |
103 | | - } else { |
104 | | - $args[] = $arg; |
105 | | - } |
106 | | -} |
107 | 17 | |
108 | | - |
109 | | -# General initialisation |
110 | | - |
111 | | -$wgCommandLineMode = true; |
112 | | -# Turn off output buffering if it's on |
113 | | -@ob_end_flush(); |
114 | | -$sep = PATH_SEPARATOR; |
115 | | - |
116 | | -if (!isset( $wgUseNormalUser ) ) { |
117 | | - $wgUseNormalUser = false; |
118 | | -} |
119 | | - |
120 | | -if ( file_exists( dirname(__FILE__).'/wikimedia-mode' ) ) { |
121 | | - $wgWikiFarm = true; |
122 | | - $cluster = 'pmtpa'; |
123 | | - require_once( "$IP/includes/AutoLoader.php" ); |
124 | | - require_once( "$IP/includes/SiteConfiguration.php" ); |
125 | | - |
126 | | - # Get $wgConf |
127 | | - require( "$IP/wgConf.php" ); |
128 | | - |
129 | | - if ( empty( $wgNoDBParam ) ) { |
130 | | - # Check if we were passed a db name |
131 | | - if ( isset( $options['wiki'] ) ) { |
132 | | - $db = $options['wiki']; |
133 | | - } else { |
134 | | - $db = array_shift( $args ); |
135 | | - } |
136 | | - list( $site, $lang ) = $wgConf->siteFromDB( $db ); |
137 | | - |
138 | | - # If not, work out the language and site the old way |
139 | | - if ( is_null( $site ) || is_null( $lang ) ) { |
140 | | - if ( !$db ) { |
141 | | - $lang = 'aa'; |
142 | | - } else { |
143 | | - $lang = $db; |
144 | | - } |
145 | | - if ( isset( $args[0] ) ) { |
146 | | - $site = array_shift( $args ); |
147 | | - } else { |
148 | | - $site = 'wikipedia'; |
149 | | - } |
150 | | - } |
151 | | - } else { |
152 | | - $lang = 'aa'; |
153 | | - $site = 'wikipedia'; |
| 18 | + # No help, it would just be misleading since it misses custom options |
| 19 | + unset( $this->mParams['help'] ); |
154 | 20 | } |
155 | 21 | |
156 | | - # This is for the IRC scripts, which now run as the apache user |
157 | | - # The apache user doesn't have access to the wikiadmin_pass command |
158 | | - if ( $_ENV['USER'] == 'apache' ) { |
159 | | - #if ( posix_geteuid() == 48 ) { |
160 | | - $wgUseNormalUser = true; |
| 22 | + public function execute() { |
| 23 | + global $args, $options; |
| 24 | + $args = $this->mArgs; |
| 25 | + $options = $this->mOptions; |
161 | 26 | } |
162 | | - |
163 | | - putenv( 'wikilang='.$lang); |
164 | | - |
165 | | - $DP = $IP; |
166 | | - ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" ); |
167 | | - |
168 | | - if ( $lang == 'test' && $site == 'wikipedia' ) { |
169 | | - define( 'TESTWIKI', 1 ); |
170 | | - } |
171 | | - |
172 | | - #require_once( $IP.'/includes/ProfilerStub.php' ); |
173 | | - require( $IP.'/includes/Defines.php' ); |
174 | | - require( $IP.'/CommonSettings.php' ); |
175 | | - if ( !$wgUseNormalUser && is_readable( "$IP/AdminSettings.php" ) ) { |
176 | | - require( "$IP/AdminSettings.php" ); |
177 | | - } |
178 | | -} else { |
179 | | - $wgWikiFarm = false; |
180 | | - if ( isset( $options['conf'] ) ) { |
181 | | - $settingsFile = $options['conf']; |
182 | | - } else { |
183 | | - $settingsFile = "$IP/LocalSettings.php"; |
184 | | - } |
185 | | - if ( isset( $options['wiki'] ) ) { |
186 | | - $bits = explode( '-', $options['wiki'] ); |
187 | | - if ( count( $bits ) == 1 ) { |
188 | | - $bits[] = ''; |
189 | | - } |
190 | | - define( 'MW_DB', $bits[0] ); |
191 | | - define( 'MW_PREFIX', $bits[1] ); |
192 | | - } |
193 | | - |
194 | | - if ( ! is_readable( $settingsFile ) ) { |
195 | | - print "A copy of your installation's LocalSettings.php\n" . |
196 | | - "must exist and be readable in the source directory.\n"; |
197 | | - exit( 1 ); |
198 | | - } |
199 | | - $wgCommandLineMode = true; |
200 | | - $DP = $IP; |
201 | | - require_once( "$IP/includes/AutoLoader.php" ); |
202 | | - require_once( "$IP/includes/Defines.php" ); |
203 | | - require_once( $settingsFile ); |
204 | | - /* ini_set( 'include_path', ".$sep$IP$sep$IP/includes$sep$IP/languages$sep$IP/maintenance" ); */ |
205 | | - |
206 | | - $adminSettings = isset( $options['aconf'] ) |
207 | | - ? $options['aconf'] |
208 | | - : "{$IP}/AdminSettings.php"; |
209 | | - if( is_readable( $adminSettings ) ) |
210 | | - require_once( $adminSettings ); |
211 | | - |
212 | 27 | } |
213 | 28 | |
214 | | -# Turn off output buffering again, it might have been turned on in the settings files |
215 | | -if( ob_get_level() ) { |
216 | | - ob_end_flush(); |
217 | | -} |
218 | | -# Same with these |
219 | | -$wgCommandLineMode = true; |
| 29 | +$maintClass = 'CommandLineInc'; |
| 30 | +require( DO_MAINTENANCE ); |
220 | 31 | |
221 | | -if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) { |
222 | | - $wgDBuser = $wgDBadminuser; |
223 | | - $wgDBpassword = $wgDBadminpassword; |
224 | | - |
225 | | - if( $wgDBservers ) { |
226 | | - foreach ( $wgDBservers as $i => $server ) { |
227 | | - $wgDBservers[$i]['user'] = $wgDBuser; |
228 | | - $wgDBservers[$i]['password'] = $wgDBpassword; |
229 | | - } |
230 | | - } |
231 | | - if( isset( $wgLBFactoryConf['serverTemplate'] ) ) { |
232 | | - $wgLBFactoryConf['serverTemplate']['user'] = $wgDBuser; |
233 | | - $wgLBFactoryConf['serverTemplate']['password'] = $wgDBpassword; |
234 | | - } |
235 | | -} |
236 | | - |
237 | | -if ( defined( 'MW_CMDLINE_CALLBACK' ) ) { |
238 | | - $fn = MW_CMDLINE_CALLBACK; |
239 | | - $fn(); |
240 | | -} |
241 | | - |
242 | | -ini_set( 'memory_limit', -1 ); |
243 | | - |
244 | | -if( version_compare( phpversion(), '5.2.4' ) >= 0 ) { |
245 | | - // Send PHP warnings and errors to stderr instead of stdout. |
246 | | - // This aids in diagnosing problems, while keeping messages |
247 | | - // out of redirected output. |
248 | | - if( ini_get( 'display_errors' ) ) { |
249 | | - ini_set( 'display_errors', 'stderr' ); |
250 | | - } |
251 | | - |
252 | | - // Don't touch the setting on earlier versions of PHP, |
253 | | - // as setting it would disable output if you'd wanted it. |
254 | | - |
255 | | - // Note that exceptions are also sent to stderr when |
256 | | - // command-line mode is on, regardless of PHP version. |
257 | | -} |
258 | | -$wgShowSQLErrors = true; |
259 | | - |
260 | | -require_once( "$IP/includes/Setup.php" ); |
261 | | -require_once( "$IP/maintenance/install-utils.inc" ); |
262 | | -$wgTitle = null; # Much much faster startup than creating a title object |
263 | | -@set_time_limit(0); |
264 | | - |
265 | | -$wgProfiling = false; // only for Profiler.php mode; avoids OOM errors |
Index: trunk/phase3/maintenance/Maintenance.php |
— | — | @@ -51,13 +51,13 @@ |
52 | 52 | const STDIN_ALL = 'all'; |
53 | 53 | |
54 | 54 | // This is the desired params |
55 | | - private $mParams = array(); |
| 55 | + protected $mParams = array(); |
56 | 56 | |
57 | 57 | // Array of desired args |
58 | | - private $mArgList = array(); |
| 58 | + protected $mArgList = array(); |
59 | 59 | |
60 | 60 | // This is the list of options that were actually passed |
61 | | - private $mOptions = array(); |
| 61 | + protected $mOptions = array(); |
62 | 62 | |
63 | 63 | // This is the list of arguments that were actually passed |
64 | 64 | protected $mArgs = array(); |
— | — | @@ -66,14 +66,14 @@ |
67 | 67 | protected $mSelf; |
68 | 68 | |
69 | 69 | // Special vars for params that are always used |
70 | | - private $mQuiet = false; |
71 | | - private $mDbUser, $mDbPass; |
| 70 | + protected $mQuiet = false; |
| 71 | + protected $mDbUser, $mDbPass; |
72 | 72 | |
73 | 73 | // A description of the script, children should change this |
74 | 74 | protected $mDescription = ''; |
75 | 75 | |
76 | 76 | // Have we already loaded our user input? |
77 | | - private $mInputLoaded = false; |
| 77 | + protected $mInputLoaded = false; |
78 | 78 | |
79 | 79 | // Batch size. If a script supports this, they should set |
80 | 80 | // a default with setBatchSize() |
— | — | @@ -248,7 +248,7 @@ |
249 | 249 | /** |
250 | 250 | * Add the default parameters to the scripts |
251 | 251 | */ |
252 | | - private function addDefaultParams() { |
| 252 | + protected function addDefaultParams() { |
253 | 253 | $this->addOption( 'help', "Display this help message" ); |
254 | 254 | $this->addOption( 'quiet', "Whether to supress non-error output" ); |
255 | 255 | $this->addOption( 'conf', "Location of LocalSettings.php, if not default", false, true ); |
— | — | @@ -267,13 +267,13 @@ |
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
271 | | - * Spawn a child maintenance script. Pass all of the current arguments |
| 271 | + * Run a child maintenance script. Pass all of the current arguments |
272 | 272 | * to it. |
273 | 273 | * @param $maintClass String A name of a child maintenance class |
274 | 274 | * @param $classFile String Full path of where the child is |
275 | 275 | * @return Maintenance child |
276 | 276 | */ |
277 | | - protected function spawnChild( $maintClass, $classFile = null ) { |
| 277 | + protected function runChild( $maintClass, $classFile = null ) { |
278 | 278 | // If we haven't already specified, kill setup procedures |
279 | 279 | // for child scripts, we've already got a sane environment |
280 | 280 | self::disableSetup(); |
— | — | @@ -469,7 +469,7 @@ |
470 | 470 | /** |
471 | 471 | * Run some validation checks on the params, etc |
472 | 472 | */ |
473 | | - private function validateParamsAndArgs() { |
| 473 | + protected function validateParamsAndArgs() { |
474 | 474 | $die = false; |
475 | 475 | # Check to make sure we've got all the required options |
476 | 476 | foreach( $this->mParams as $opt => $info ) { |
— | — | @@ -492,7 +492,7 @@ |
493 | 493 | /** |
494 | 494 | * Handle the special variables that are global to all scripts |
495 | 495 | */ |
496 | | - private function loadSpecialVars() { |
| 496 | + protected function loadSpecialVars() { |
497 | 497 | if( $this->hasOption( 'dbuser' ) ) |
498 | 498 | $this->mDbUser = $this->getOption( 'dbuser' ); |
499 | 499 | if( $this->hasOption( 'dbpass' ) ) |
— | — | @@ -507,9 +507,9 @@ |
508 | 508 | * Maybe show the help. |
509 | 509 | * @param $force boolean Whether to force the help to show, default false |
510 | 510 | */ |
511 | | - private function maybeHelp( $force = false ) { |
| 511 | + protected function maybeHelp( $force = false ) { |
512 | 512 | ksort( $this->mParams ); |
513 | | - if( $this->hasOption( 'help' ) || in_array( 'help', $this->mArgs ) || $force ) { |
| 513 | + if( $this->hasOption( 'help' ) || $force ) { |
514 | 514 | $this->mQuiet = false; |
515 | 515 | if( $this->mDescription ) { |
516 | 516 | $this->output( "\n" . $this->mDescription . "\n" ); |
— | — | @@ -754,7 +754,7 @@ |
755 | 755 | * Return all of the core maintenance scripts |
756 | 756 | * @return array |
757 | 757 | */ |
758 | | - private static function getCoreScripts() { |
| 758 | + protected static function getCoreScripts() { |
759 | 759 | if( !self::$mCoreScripts ) { |
760 | 760 | self::disableSetup(); |
761 | 761 | $paths = array( |