3 * Build file cache for content pages
10 require_once( "commandLine.inc" );
11 if( !$wgUseFileCache ) {
12 echo "Nothing to do -- \$wgUseFileCache is disabled.\n";
15 $wgDisableCounters = false; // no real hits here
17 $start = isset($args[0]) ? intval($args[0]) : 0;
18 $overwrite = isset( $args[1] ) && $args[1] === 'overwrite';
19 echo "Building content page file cache from page {$start}!\n";
20 echo "Format: <start> [overwrite]\n";
22 $dbr = wfGetDB( DB_SLAVE );
23 $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
24 $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
26 die("Nothing to do.\n");
29 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
30 OutputPage::setEncodings(); # Not really used yet
34 $end += $BATCH_SIZE - 1;
36 $blockEnd = $start + $BATCH_SIZE - 1;
38 $dbw = wfGetDB( DB_MASTER );
39 // Go through each page and save the output
40 while( $blockEnd <= $end ) {
42 $res = $dbr->select( 'page', array('page_namespace','page_title','page_id'),
43 array('page_namespace' => $wgContentNamespaces,
44 "page_id BETWEEN $blockStart AND $blockEnd" ),
45 array('ORDER BY' => 'page_id ASC','USE INDEX' => 'PRIMARY')
47 while( $row = $dbr->fetchObject( $res ) ) {
49 $wgTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
50 if( null == $wgTitle ) {
51 echo "Page {$row->page_id} bad title\n";
52 continue; // broken title?
54 $wgArticle = new Article( $wgTitle );
55 // If the article is cacheable, then load it
56 if( $wgArticle->isFileCacheable() ) {
57 $cache = new HTMLFileCache( $wgTitle );
58 if( $cache->isFileCacheGood() ) {
62 echo "Page {$row->page_id} already cached\n";
63 continue; // done already!
66 ob_start( array(&$cache, 'saveToFileCache' ) ); // save on ob_end_clean()
67 $wgUseFileCache = false; // hack, we don't want $wgArticle fiddling with filecache
69 @$wgOut->output(); // header notices
70 $wgUseFileCache = true;
71 ob_end_clean(); // clear buffer
72 $wgOut = new OutputPage(); // empty out any output page garbage
74 echo "Re-cached page {$row->page_id}\n";
76 echo "Cached page {$row->page_id}\n";
78 echo "Page {$row->page_id} not cacheable\n";
80 $dbw->commit(); // commit any changes
82 $blockStart += $BATCH_SIZE;
83 $blockEnd += $BATCH_SIZE;
88 // Remove these to be safe
91 if( isset($wgArticle) )