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