Index: branches/maintenance-work/maintenance/protect.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup Maintenance |
| 6 | + */ |
| 7 | + |
| 8 | +require_once( "Maintenance.php" ); |
| 9 | + |
| 10 | +class Protect extends Maintenance { |
| 11 | + public function __construct() { |
| 12 | + parent::__construct(); |
| 13 | + $this->mDescription = "Protect or unprotect an article from the command line."; |
| 14 | + $this->addOption( 'unprotect', 'Removes protection' ); |
| 15 | + $this->addOption( 'semiprotect', 'Adds semi-protection' ); |
| 16 | + $this->addOption( 'u', 'Username to protect with', false, true ); |
| 17 | + $this->addOption( 'r', 'Reason for un/protection', false, true ); |
| 18 | + } |
| 19 | + |
| 20 | + public function execute() { |
| 21 | + global $wgUser, $wgTitle, $wgArticle; |
| 22 | + |
| 23 | + $userName = $this->getOption( 'u', 'Maintenance script' ); |
| 24 | + $reason = $this->getOption( 'r', '' ); |
| 25 | + |
| 26 | + $protection = "sysop"; |
| 27 | + if ( $this->hasOption('semiprotect') ) { |
| 28 | + $protection = "autoconfirmed"; |
| 29 | + } elseif ( $this->hasOption('unprotect') ) { |
| 30 | + $protection = ""; |
| 31 | + } |
| 32 | + |
| 33 | + $wgUser = User::newFromName( $userName ); |
| 34 | + $restrictions = array( 'edit' => $protection, 'move' => $protection ); |
| 35 | + |
| 36 | + $wgTitle = Title::newFromText( $args[0] ); |
| 37 | + if ( !$wgTitle ) { |
| 38 | + $this->error( "Invalid title\n", true ); |
| 39 | + } |
| 40 | + |
| 41 | + $wgArticle = new Article( $wgTitle ); |
| 42 | + |
| 43 | + # un/protect the article |
| 44 | + $this->output( "Updating protection status... " ); |
| 45 | + $success = $wgArticle->updateRestrictions($restrictions, $reason); |
| 46 | + if ( $success ) { |
| 47 | + $this->output( "done\n" ); |
| 48 | + } else { |
| 49 | + $this->output( "failed\n" ); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +$maintClass = "Protect"; |
| 55 | +require_once( DO_MAINTENANCE ); |
Property changes on: branches/maintenance-work/maintenance/protect.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 56 | + native |
Index: branches/maintenance-work/maintenance/generateSitemap.php |
— | — | @@ -16,7 +16,9 @@ |
17 | 17 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
18 | 18 | */ |
19 | 19 | |
20 | | -class GenerateSitemap { |
| 20 | +require_once( "Maintenance.php" ); |
| 21 | + |
| 22 | +class GenerateSitemap extends Maintenance { |
21 | 23 | /** |
22 | 24 | * The maximum amount of urls in a sitemap file |
23 | 25 | * |
— | — | @@ -129,36 +131,34 @@ |
130 | 132 | var $file; |
131 | 133 | |
132 | 134 | /** |
133 | | - * A resource pointing to php://stderr |
134 | | - * |
135 | | - * @var resource |
| 135 | + * Constructor |
136 | 136 | */ |
137 | | - var $stderr; |
| 137 | + public function __construct() { |
| 138 | + parent::__construct(); |
| 139 | + $this->mDescription = "Creates a sitemap for the site"; |
| 140 | + $this->addOption( 'fspath', 'The file system path to save to, e.g. /tmp/sitemap' . |
| 141 | + "\n\t\tdefaults to current directory", false, true ); |
| 142 | + $this->addOption( 'server', "The protocol and server name to use in URLs, e.g.\n" . |
| 143 | + "\t\thttp://en.wikipedia.org. This is sometimes necessary because\n" . |
| 144 | + "\t\tserver name detection may fail in command line scripts.", false, true ); |
| 145 | + $this->addOption( 'compress', 'Compress the sitemap files, can take value yes|no, default yes' ); |
| 146 | + } |
138 | 147 | |
139 | 148 | /** |
140 | | - * Constructor |
141 | | - * |
142 | | - * @param string $fspath The path to prepend to the filenames, used to |
143 | | - * save them somewhere else than in the root directory |
144 | | - * @param string $path The path to append to the domain name |
145 | | - * @param bool $compress Whether to compress the sitemap files |
| 149 | + * Execute |
146 | 150 | */ |
147 | | - function GenerateSitemap( $fspath, $compress ) { |
| 151 | + public function execute() { |
148 | 152 | global $wgScriptPath; |
149 | 153 | |
150 | 154 | $this->url_limit = 50000; |
151 | 155 | $this->size_limit = pow( 2, 20 ) * 10; |
152 | | - $this->fspath = self::init_path( $fspath ); |
153 | | - |
154 | | - $this->compress = $compress; |
155 | | - |
156 | | - $this->stderr = fopen( 'php://stderr', 'wt' ); |
| 156 | + $this->fspath = self::init_path( $this->getOption( 'fspath', getcwd() ) ); |
| 157 | + $this->compress = $this->getOption( 'compress', 'yes' ) !== 'no'; |
157 | 158 | $this->dbr = wfGetDB( DB_SLAVE ); |
158 | 159 | $this->generateNamespaces(); |
159 | 160 | $this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() ); |
160 | | - |
161 | | - |
162 | 161 | $this->findex = fopen( "{$this->fspath}sitemap-index-" . wfWikiID() . ".xml", 'wb' ); |
| 162 | + $this->main(); |
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
— | — | @@ -170,7 +170,7 @@ |
171 | 171 | } |
172 | 172 | # Create directory if needed |
173 | 173 | if( $fspath && !is_dir( $fspath ) ) { |
174 | | - mkdir( $fspath, 0755 ) or die("Can not create directory $fspath.\n"); |
| 174 | + wfMkdirParents( $fspath ) or die("Can not create directory $fspath.\n"); |
175 | 175 | } |
176 | 176 | |
177 | 177 | return realpath( $fspath ). DIRECTORY_SEPARATOR ; |
— | — | @@ -180,8 +180,6 @@ |
181 | 181 | * Generate a one-dimensional array of existing namespaces |
182 | 182 | */ |
183 | 183 | function generateNamespaces() { |
184 | | - $fname = 'GenerateSitemap::generateNamespaces'; |
185 | | - |
186 | 184 | // Only generate for specific namespaces if $wgSitemapNamespaces is an array. |
187 | 185 | global $wgSitemapNamespaces; |
188 | 186 | if( is_array( $wgSitemapNamespaces ) ) { |
— | — | @@ -192,7 +190,7 @@ |
193 | 191 | $res = $this->dbr->select( 'page', |
194 | 192 | array( 'page_namespace' ), |
195 | 193 | array(), |
196 | | - $fname, |
| 194 | + __METHOD__, |
197 | 195 | array( |
198 | 196 | 'GROUP BY' => 'page_namespace', |
199 | 197 | 'ORDER BY' => 'page_namespace', |
— | — | @@ -236,8 +234,6 @@ |
237 | 235 | * @return resource |
238 | 236 | */ |
239 | 237 | function getPageRes( $namespace ) { |
240 | | - $fname = 'GenerateSitemap::getPageRes'; |
241 | | - |
242 | 238 | return $this->dbr->select( 'page', |
243 | 239 | array( |
244 | 240 | 'page_namespace', |
— | — | @@ -245,7 +241,7 @@ |
246 | 242 | 'page_touched', |
247 | 243 | ), |
248 | 244 | array( 'page_namespace' => $namespace ), |
249 | | - $fname |
| 245 | + __METHOD__ |
250 | 246 | ); |
251 | 247 | } |
252 | 248 | |
— | — | @@ -267,7 +263,7 @@ |
268 | 264 | $i = $smcount = 0; |
269 | 265 | |
270 | 266 | $fns = $wgContLang->getFormattedNsText( $namespace ); |
271 | | - $this->debug( "$namespace ($fns)" ); |
| 267 | + $this->output( "$namespace ($fns)" ); |
272 | 268 | while ( $row = $this->dbr->fetchObject( $res ) ) { |
273 | 269 | if ( $i++ === 0 || $i === $this->url_limit + 1 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit ) { |
274 | 270 | if ( $this->file !== false ) { |
— | — | @@ -278,7 +274,7 @@ |
279 | 275 | $this->file = $this->open( $this->fspath . $filename, 'wb' ); |
280 | 276 | $this->write( $this->file, $this->openFile() ); |
281 | 277 | fwrite( $this->findex, $this->indexEntry( $filename ) ); |
282 | | - $this->debug( "\t$this->fspath$filename" ); |
| 278 | + $this->output( "\t$this->fspath$filename" ); |
283 | 279 | $length = $this->limit[0]; |
284 | 280 | $i = 1; |
285 | 281 | } |
— | — | @@ -450,13 +446,6 @@ |
451 | 447 | } |
452 | 448 | |
453 | 449 | /** |
454 | | - * Write a string to stderr followed by a UNIX newline |
455 | | - */ |
456 | | - function debug( $str ) { |
457 | | - fwrite( $this->stderr, "$str\n" ); |
458 | | - } |
459 | | - |
460 | | - /** |
461 | 450 | * Populate $this->limit |
462 | 451 | */ |
463 | 452 | function generateLimit( $namespace ) { |
— | — | @@ -470,31 +459,5 @@ |
471 | 460 | } |
472 | 461 | } |
473 | 462 | |
474 | | -if ( in_array( '--help', $argv ) ) { |
475 | | - echo <<<EOT |
476 | | -Usage: php generateSitemap.php [options] |
477 | | - --help show this message |
478 | | - |
479 | | - --fspath=<path> The file system path to save to, e.g /tmp/sitemap |
480 | | - Saves to current directory if not given. |
481 | | - |
482 | | - --server=<server> The protocol and server name to use in URLs, e.g. |
483 | | - http://en.wikipedia.org. This is sometimes necessary because |
484 | | - server name detection may fail in command line scripts. |
485 | | - |
486 | | - --compress=[yes|no] compress the sitemap files, default yes |
487 | | - |
488 | | -EOT; |
489 | | - die( -1 ); |
490 | | -} |
491 | | - |
492 | | -$optionsWithArgs = array( 'fspath', 'server', 'compress' ); |
493 | | -require_once( dirname( __FILE__ ) . '/commandLine.inc' ); |
494 | | - |
495 | | -if ( isset( $options['server'] ) ) { |
496 | | - $wgServer = $options['server']; |
497 | | -} |
498 | | - |
499 | | -$gs = new GenerateSitemap( @$options['fspath'], @$options['compress'] !== 'no' ); |
500 | | -$gs->main(); |
501 | | - |
| 463 | +$maintClass = "GenerateSitemap"; |
| 464 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/rebuildLocalisationCache.php |
— | — | @@ -10,32 +10,45 @@ |
11 | 11 | * Use --force to rebuild all files, even the ones that are not out of date. |
12 | 12 | */ |
13 | 13 | |
14 | | -require( dirname(__FILE__).'/commandLine.inc' ); |
15 | | -ini_set( 'memory_limit', '200M' ); |
| 14 | +require_once( "Maintenance.php" ); |
16 | 15 | |
17 | | -$force = isset( $options['force'] ); |
| 16 | +class RebuildLocalisationCache extends Maintenance { |
| 17 | + public function __construct() { |
| 18 | + parent::__construct(); |
| 19 | + $this->mDescription = "Rebuild the localisation cache"; |
| 20 | + $this->addOption( 'force', 'Rebuild all files, even ones not out of date' ); |
| 21 | + } |
18 | 22 | |
19 | | -$conf = $wgLocalisationCacheConf; |
20 | | -$conf['manualRecache'] = false; // Allow fallbacks to create CDB files |
21 | | -if ( $force ) { |
22 | | - $conf['forceRecache'] = true; |
23 | | -} |
24 | | -$lc = new LocalisationCache_BulkLoad( $conf ); |
| 23 | + public function execute() { |
| 24 | + global $wgLocalisationCacheConf; |
25 | 25 | |
26 | | -$codes = array_keys( Language::getLanguageNames( true ) ); |
27 | | -sort( $codes ); |
28 | | -$numRebuilt = 0; |
29 | | -foreach ( $codes as $code ) { |
30 | | - if ( $force || $lc->isExpired( $code ) ) { |
31 | | - echo "Rebuilding $code...\n"; |
32 | | - $lc->recache( $code ); |
33 | | - $numRebuilt++; |
| 26 | + ini_set( 'memory_limit', '200M' ); |
| 27 | + |
| 28 | + $force = $this->hasOption('force'); |
| 29 | + |
| 30 | + $conf = $wgLocalisationCacheConf; |
| 31 | + $conf['manualRecache'] = false; // Allow fallbacks to create CDB files |
| 32 | + if ( $force ) { |
| 33 | + $conf['forceRecache'] = true; |
| 34 | + } |
| 35 | + $lc = new LocalisationCache_BulkLoad( $conf ); |
| 36 | + |
| 37 | + $codes = array_keys( Language::getLanguageNames( true ) ); |
| 38 | + sort( $codes ); |
| 39 | + $numRebuilt = 0; |
| 40 | + foreach ( $codes as $code ) { |
| 41 | + if ( $force || $lc->isExpired( $code ) ) { |
| 42 | + $this->output( "Rebuilding $code...\n" ); |
| 43 | + $lc->recache( $code ); |
| 44 | + $numRebuilt++; |
| 45 | + } |
| 46 | + } |
| 47 | + $this->output( "$numRebuilt languages rebuilt out of " . count( $codes ) . ".\n" ); |
| 48 | + if ( $numRebuilt == 0 ) { |
| 49 | + $this->output( "Use --force to rebuild the caches which are still fresh.\n" ); |
| 50 | + } |
34 | 51 | } |
35 | 52 | } |
36 | | -echo "$numRebuilt languages rebuilt out of " . count( $codes ) . ".\n"; |
37 | | -if ( $numRebuilt == 0 ) { |
38 | | - echo "Use --force to rebuild the caches which are still fresh.\n"; |
39 | | -} |
40 | 53 | |
41 | | - |
42 | | - |
| 54 | +$maintClass = "RebuildLocalisationCache"; |
| 55 | +require_once( DO_MAINTENANCE ); |