Fix script for bug 20757.
[lhc/web/wiklou.git] / maintenance / rebuildFileCache.php
index 0b48f9a..2a4e488 100644 (file)
  * @ingroup Maintenance
  */
 
-require_once( "Maintenance.php" );
+require_once( dirname(__FILE__) . '/Maintenance.php' );
 
 class RebuildFileCache extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Build file cache for content pages";
-               $this->addArgs( array( 'start', 'overwrite' ) );
+               $this->addArg( 'start', 'Page_id to start from', true );
+               $this->addArg( 'overwrite', 'Refresh page cache', false );
                $this->setBatchSize( 100 );
        }
 
        public function execute() {
-               global $wgUseFileCache, $wgDisableCounters, $wgTitle, $wgArticle, $wgOut;
+               global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces;
+               global $wgTitle, $wgArticle, $wgOut, $wgUser;
                if( !$wgUseFileCache ) {
-                       $this->error( "Nothing to do -- \$wgUseFileCache is disabled.\n", true );
+                       $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
                }
                $wgDisableCounters = false;
-               $start = intval( $this->getArg( 0, 0 ) );
+               $start = $this->getArg( 0, "0" );
+               if( !ctype_digit($start) ) {
+                       $this->error( "Invalid value for start parameter.", true );
+               }
+               $start = intval($start);
                $overwrite = $this->hasArg(1) && $this->getArg(1) === 'overwrite';
                $this->output( "Building content page file cache from page {$start}!\n" );
 
@@ -44,7 +50,7 @@ class RebuildFileCache extends Maintenance {
                $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
                $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
                if( !$start ) {
-                       $this->error( "Nothing to do.\n", true );
+                       $this->error( "Nothing to do.", true );
                }
 
                $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
@@ -64,13 +70,15 @@ class RebuildFileCache extends Maintenance {
                                        "page_id BETWEEN $blockStart AND $blockEnd" ),
                                array('ORDER BY' => 'page_id ASC','USE INDEX' => 'PRIMARY')
                        );
-                       while( $row = $dbr->fetchObject( $res ) ) {
+                       foreach( $res as $row ) {
                                $rebuilt = false;
                                $wgTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
                                if( null == $wgTitle ) {
-                                       $this->output( "Page {$row->page_id} bad title\n" );
+                                       $this->output( "Page {$row->page_id} has bad title\n" );
                                        continue; // broken title?
                                }
+                               $wgOut->setTitle( $wgTitle ); // set display title
+                               $wgUser->getSkin( $wgTitle ); // set skin title
                                $wgArticle = new Article( $wgTitle );
                                // If the article is cacheable, then load it
                                if( $wgArticle->isFileCacheable() ) {