3 * Build file cache for content pages
9 require_once( "Maintenance.php" );
11 class RebuildFileCache
extends Maintenance
{
12 public function __construct() {
13 parent
::__construct();
14 $this->mDescription
= "Build file cache for content pages";
15 $this->addArgs( array( 'start', 'overwrite' ) );
18 public function execute() {
19 global $wgUseFileCache, $wgDisableCounters, $wgTitle, $wgArticle, $wgOut;
20 if( !$wgUseFileCache ) {
21 $this->error( "Nothing to do -- \$wgUseFileCache is disabled.\n", true );
23 $wgDisableCounters = false;
24 $start = intval( $this->getArg( 0, 0 ) );
25 $overwrite = $this->hasArg(1) && $this->getArg(1) === 'overwrite';
26 $this->output( "Building content page file cache from page {$start}!\n" );
28 $dbr = wfGetDB( DB_SLAVE
);
29 $start = $start > 0 ?
$start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__
);
30 $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__
);
32 $this->error( "Nothing to do.\n", true );
35 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
36 OutputPage
::setEncodings(); # Not really used yet
40 $end +
= $BATCH_SIZE - 1;
42 $blockEnd = $start +
$BATCH_SIZE - 1;
44 $dbw = wfGetDB( DB_MASTER
);
45 // Go through each page and save the output
46 while( $blockEnd <= $end ) {
48 $res = $dbr->select( 'page', array('page_namespace','page_title','page_id'),
49 array('page_namespace' => $wgContentNamespaces,
50 "page_id BETWEEN $blockStart AND $blockEnd" ),
51 array('ORDER BY' => 'page_id ASC','USE INDEX' => 'PRIMARY')
53 while( $row = $dbr->fetchObject( $res ) ) {
55 $wgTitle = Title
::makeTitleSafe( $row->page_namespace
, $row->page_title
);
56 if( null == $wgTitle ) {
57 $this->output( "Page {$row->page_id} bad title\n" );
58 continue; // broken title?
60 $wgArticle = new Article( $wgTitle );
61 // If the article is cacheable, then load it
62 if( $wgArticle->isFileCacheable() ) {
63 $cache = new HTMLFileCache( $wgTitle );
64 if( $cache->isFileCacheGood() ) {
68 $this->output( "Page {$row->page_id} already cached\n" );
69 continue; // done already!
72 ob_start( array(&$cache, 'saveToFileCache' ) ); // save on ob_end_clean()
73 $wgUseFileCache = false; // hack, we don't want $wgArticle fiddling with filecache
75 @$wgOut->output(); // header notices
76 $wgUseFileCache = true;
77 ob_end_clean(); // clear buffer
78 $wgOut = new OutputPage(); // empty out any output page garbage
80 $this->output( "Re-cached page {$row->page_id}\n" );
82 $this->output( "Cached page {$row->page_id}\n" );
84 $this->output( "Page {$row->page_id} not cacheable\n" );
86 $dbw->commit(); // commit any changes
88 $blockStart +
= $BATCH_SIZE;
89 $blockEnd +
= $BATCH_SIZE;
92 $this->output( "Done!\n" );
94 // Remove these to be safe
97 if( isset($wgArticle) )
101 require_once( "commandLine.inc" );