26require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
39 $this->
addOption(
'start',
'Page_id to start from',
false,
true );
40 $this->
addOption(
'end',
'Page_id to end on',
false,
true );
41 $this->
addOption(
'overwrite',
'Refresh page cache' );
52 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
53 ->setReason(
'Building cache' );
62 if ( !$this->enabled ) {
63 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
66 $start = $this->
getOption(
'start',
"0" );
67 if ( !ctype_digit( $start ) ) {
68 $this->
fatalError(
"Invalid value for start parameter." );
70 $start = intval( $start );
73 if ( !ctype_digit( $end ) ) {
74 $this->
fatalError(
"Invalid value for end parameter." );
76 $end = intval( $end );
78 $this->
output(
"Building content page file cache from page {$start}!\n" );
82 $overwrite = $this->
hasOption(
'overwrite' );
83 $start = ( $start > 0 )
85 :
$dbr->selectField(
'page',
'MIN(page_id)',
'', __METHOD__ );
88 :
$dbr->selectField(
'page',
'MAX(page_id)',
'', __METHOD__ );
94 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
97 $end += $batchSize - 1;
99 $blockEnd = $start + $batchSize - 1;
103 while ( $blockEnd <= $end ) {
106 [
'page_namespace',
'page_title',
'page_id' ],
107 [
'page_namespace' => MediaWikiServices::getInstance()->getNamespaceInfo()->
108 getContentNamespaces(),
109 "page_id BETWEEN " . (
int)$blockStart .
" AND " . (
int)$blockEnd ],
111 [
'ORDER BY' =>
'page_id ASC',
'USE INDEX' =>
'PRIMARY' ]
115 foreach (
$res as $row ) {
118 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
120 $this->
output(
"Page {$row->page_id} has bad title\n" );
127 $context->setWikiPage( $article->getPage() );
130 RequestContext::getMain()->setTitle(
$title );
136 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
140 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
145 Wikimedia\suppressWarnings();
149 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
154 $viewHtml = ob_get_clean();
155 $viewCache->saveToFileCache( $viewHtml );
159 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
161 Action::factory(
'history', $article,
$context )->show();
164 $historyHtml = ob_get_clean();
165 $historyCache->saveToFileCache( $historyHtml );
167 Wikimedia\restoreWarnings();
170 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
172 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
174 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
175 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
177 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
182 $blockStart += $batchSize;
183 $blockEnd += $batchSize;
185 $this->
output(
"Done!\n" );
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
const RUN_MAINTENANCE_IF_MAIN
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
Page view caching in the file system.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that builds file cache for content pages.
execute()
Do the actual work.
__construct()
Default constructor.
finalSetup()
Handle some last-minute setup here.
Group all the pieces relevant to the context of a request into one instance.