Go to the documentation of this file.
26 require_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' );
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 ) {
120 $this->
output(
"Page {$row->page_id} has bad title\n" );
127 $context->setWikiPage( $article->getPage() );
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 );
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" );
const RUN_MAINTENANCE_IF_MAIN
Page view caching in the file system.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Maintenance script that builds file cache for content pages.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
__construct()
Default constructor.
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Group all the pieces relevant to the context of a request into one instance.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
static deinit()
Disable the debugger.
static getMain()
Get the RequestContext object associated with the main request.
getOption( $name, $default=null)
Get an option, or return the default.
execute()
Do the actual work.
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
static factory( $action, Page $page, IContextSource $context=null)
Get an appropriate Action subclass for the given action.
setBatchSize( $s=0)
Set the batch size.
static newFromTitle( $title, IContextSource $context)
Create an Article object of the appropriate class for the given page.
finalSetup()
Handle some last-minute setup here.