2008-12-11 14:35:33 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Build file cache for content pages
|
|
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2008-12-11 14:35:33 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2009-08-03 21:56:41 +00:00
|
|
|
require_once( dirname(__FILE__) . '/Maintenance.php' );
|
2008-12-11 14:35:33 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
class RebuildFileCache extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = "Build file cache for content pages";
|
2009-08-18 23:06:24 +00:00
|
|
|
$this->addArg( 'start', 'Page_id to start from', true );
|
|
|
|
|
$this->addArg( 'overwrite', 'Refresh page cache', false );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->setBatchSize( 100 );
|
|
|
|
|
}
|
2008-12-11 14:35:33 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2010-04-03 08:56:07 +00:00
|
|
|
global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces, $wgRequestTime;
|
2009-08-17 02:46:18 +00:00
|
|
|
global $wgTitle, $wgArticle, $wgOut, $wgUser;
|
2009-08-02 19:35:17 +00:00
|
|
|
if( !$wgUseFileCache ) {
|
2009-08-02 21:55:10 +00:00
|
|
|
$this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
$wgDisableCounters = false;
|
2009-08-18 22:03:57 +00:00
|
|
|
$start = $this->getArg( 0, "0" );
|
2009-08-13 01:39:15 +00:00
|
|
|
if( !ctype_digit($start) ) {
|
|
|
|
|
$this->error( "Invalid value for start parameter.", true );
|
|
|
|
|
}
|
|
|
|
|
$start = intval($start);
|
2009-08-02 19:35:17 +00:00
|
|
|
$overwrite = $this->hasArg(1) && $this->getArg(1) === 'overwrite';
|
|
|
|
|
$this->output( "Building content page file cache from page {$start}!\n" );
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
|
|
|
|
|
$end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
|
|
|
|
|
if( !$start ) {
|
2009-08-02 21:55:10 +00:00
|
|
|
$this->error( "Nothing to do.", true );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
|
|
|
|
|
OutputPage::setEncodings(); # Not really used yet
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Do remaining chunk
|
|
|
|
|
$end += $this->mBatchSize - 1;
|
|
|
|
|
$blockStart = $start;
|
|
|
|
|
$blockEnd = $start + $this->mBatchSize - 1;
|
|
|
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
// Go through each page and save the output
|
|
|
|
|
while( $blockEnd <= $end ) {
|
|
|
|
|
// Get the pages
|
|
|
|
|
$res = $dbr->select( 'page', array('page_namespace','page_title','page_id'),
|
|
|
|
|
array('page_namespace' => $wgContentNamespaces,
|
|
|
|
|
"page_id BETWEEN $blockStart AND $blockEnd" ),
|
|
|
|
|
array('ORDER BY' => 'page_id ASC','USE INDEX' => 'PRIMARY')
|
|
|
|
|
);
|
2009-08-17 21:15:31 +00:00
|
|
|
foreach( $res as $row ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$rebuilt = false;
|
2010-04-03 08:56:07 +00:00
|
|
|
$wgRequestTime = wfTime(); # bug 22852
|
2009-08-02 19:35:17 +00:00
|
|
|
$wgTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
|
|
|
|
if( null == $wgTitle ) {
|
2009-08-17 02:46:18 +00:00
|
|
|
$this->output( "Page {$row->page_id} has bad title\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
continue; // broken title?
|
|
|
|
|
}
|
2009-08-17 02:46:18 +00:00
|
|
|
$wgOut->setTitle( $wgTitle ); // set display title
|
|
|
|
|
$wgUser->getSkin( $wgTitle ); // set skin title
|
2009-08-02 19:35:17 +00:00
|
|
|
$wgArticle = new Article( $wgTitle );
|
|
|
|
|
// If the article is cacheable, then load it
|
|
|
|
|
if( $wgArticle->isFileCacheable() ) {
|
|
|
|
|
$cache = new HTMLFileCache( $wgTitle );
|
|
|
|
|
if( $cache->isFileCacheGood() ) {
|
|
|
|
|
if( $overwrite ) {
|
|
|
|
|
$rebuilt = true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "Page {$row->page_id} already cached\n" );
|
|
|
|
|
continue; // done already!
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-03 08:56:07 +00:00
|
|
|
ob_start( array( &$cache, 'saveToFileCache' ) ); // save on ob_end_clean()
|
2009-08-02 19:35:17 +00:00
|
|
|
$wgUseFileCache = false; // hack, we don't want $wgArticle fiddling with filecache
|
|
|
|
|
$wgArticle->view();
|
|
|
|
|
@$wgOut->output(); // header notices
|
|
|
|
|
$wgUseFileCache = true;
|
|
|
|
|
ob_end_clean(); // clear buffer
|
|
|
|
|
$wgOut = new OutputPage(); // empty out any output page garbage
|
|
|
|
|
if( $rebuilt )
|
|
|
|
|
$this->output( "Re-cached page {$row->page_id}\n" );
|
|
|
|
|
else
|
|
|
|
|
$this->output( "Cached page {$row->page_id}\n" );
|
2008-12-11 18:59:11 +00:00
|
|
|
} else {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Page {$row->page_id} not cacheable\n" );
|
2008-12-11 18:59:11 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$dbw->commit(); // commit any changes
|
2008-12-11 14:35:33 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$blockStart += $this->mBatchSize;
|
|
|
|
|
$blockEnd += $this->mBatchSize;
|
|
|
|
|
wfWaitForSlaves( 5 );
|
2008-12-11 14:35:33 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Done!\n" );
|
|
|
|
|
|
|
|
|
|
// Remove these to be safe
|
|
|
|
|
if( isset($wgTitle) )
|
|
|
|
|
unset($wgTitle);
|
|
|
|
|
if( isset($wgArticle) )
|
|
|
|
|
unset($wgArticle);
|
2008-12-11 14:35:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$maintClass = "RebuildFileCache";
|
|
|
|
|
require_once( DO_MAINTENANCE );
|