Merge "TitleSearchWidget: Use OO.ui.mixin.RequestManager"
[lhc/web/wiklou.git] / maintenance / rebuildFileCache.php
index b725f03..924457a 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
+/**
+ * Maintenance script that builds file cache for content pages.
+ *
+ * @ingroup Maintenance
+ */
 class RebuildFileCache extends Maintenance {
        public function __construct() {
                parent::__construct();
@@ -32,12 +38,22 @@ class RebuildFileCache extends Maintenance {
                $this->setBatchSize( 100 );
        }
 
+       public function finalSetup() {
+               global $wgDebugToolbar;
+
+               // Debug toolbar makes content uncacheable so we disable it.
+               // Has to be done before Setup.php initialize MWDebug
+               $wgDebugToolbar = false;
+               parent::finalSetup();
+       }
+
        public function execute() {
                global $wgUseFileCache, $wgReadOnly, $wgContentNamespaces, $wgRequestTime;
-               global $wgTitle, $wgOut;
+               global $wgOut;
                if ( !$wgUseFileCache ) {
                        $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
                }
+
                $wgReadOnly = 'Building cache'; // avoid DB writes (like enotif/counters)
 
                $start = $this->getOption( 'start', "0" );
@@ -83,27 +99,27 @@ class RebuildFileCache extends Maintenance {
                                array( 'ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY' )
                        );
 
-                       $dbw->begin(); // for any changes
+                       $dbw->begin( __METHOD__ ); // for any changes
                        foreach ( $res as $row ) {
                                $rebuilt = false;
                                $wgRequestTime = microtime( true ); # bug 22852
-                               
-                               $wgTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
-                               if ( null == $wgTitle ) {
+
+                               $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
+                               if ( null == $title ) {
                                        $this->output( "Page {$row->page_id} has bad title\n" );
                                        continue; // broken title?
                                }
 
                                $context = new RequestContext;
-                               $context->setTitle( $wgTitle );
-                               $article = Article::newFromTitle( $wgTitle, $context );
+                               $context->setTitle( $title );
+                               $article = Article::newFromTitle( $title, $context );
                                $context->setWikiPage( $article->getPage() );
 
                                $wgOut = $context->getOutput(); // set display title
 
                                // If the article is cacheable, then load it
                                if ( $article->isFileCacheable() ) {
-                                       $cache = HTMLFileCache::newFromTitle( $wgTitle, 'view' );
+                                       $cache = HTMLFileCache::newFromTitle( $title, 'view' );
                                        if ( $cache->isCacheGood() ) {
                                                if ( $overwrite ) {
                                                        $rebuilt = true;
@@ -115,9 +131,9 @@ class RebuildFileCache extends Maintenance {
                                        ob_start( array( &$cache, 'saveToFileCache' ) ); // save on ob_end_clean()
                                        $wgUseFileCache = false; // hack, we don't want $article fiddling with filecache
                                        $article->view();
-                                       wfSuppressWarnings(); // header notices
+                                       MediaWiki\suppressWarnings(); // header notices
                                        $wgOut->output();
-                                       wfRestoreWarnings();
+                                       MediaWiki\restoreWarnings();
                                        $wgUseFileCache = true;
                                        ob_end_clean(); // clear buffer
                                        if ( $rebuilt ) {
@@ -129,18 +145,14 @@ class RebuildFileCache extends Maintenance {
                                        $this->output( "Page {$row->page_id} not cacheable\n" );
                                }
                        }
-                       $dbw->commit(); // commit any changes (just for sanity)
+                       $dbw->commit( __METHOD__ ); // commit any changes (just for sanity)
 
                        $blockStart += $this->mBatchSize;
                        $blockEnd += $this->mBatchSize;
                }
                $this->output( "Done!\n" );
-
-               // Remove these to be safe
-               if ( isset( $wgTitle ) )
-                       unset( $wgTitle );
        }
 }
 
 $maintClass = "RebuildFileCache";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;