63 if ( !$this->enabled ) {
64 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
67 $start = $this->
getOption(
'start',
"0" );
68 if ( !ctype_digit( $start ) ) {
69 $this->
fatalError(
"Invalid value for start parameter." );
71 $start = intval( $start );
74 if ( !ctype_digit( $end ) ) {
75 $this->
fatalError(
"Invalid value for end parameter." );
77 $end = intval( $end );
79 $this->
output(
"Building page file cache from page_id {$start}!\n" );
83 $overwrite = $this->
hasOption(
'overwrite' );
84 $start = ( $start > 0 )
86 :
$dbr->selectField(
'page',
'MIN(page_id)',
'', __METHOD__ );
89 :
$dbr->selectField(
'page',
'MAX(page_id)',
'', __METHOD__ );
98 $where[
'page_namespace'] =
99 MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
103 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
106 $end += $batchSize - 1;
107 $blockStart = $start;
108 $blockEnd = $start + $batchSize - 1;
112 while ( $blockEnd <= $end ) {
115 [
'page_namespace',
'page_title',
'page_id' ],
116 $where + [
"page_id BETWEEN " . (
int)$blockStart .
" AND " . (
int)$blockEnd ],
118 [
'ORDER BY' =>
'page_id ASC',
'USE INDEX' =>
'PRIMARY' ]
122 foreach (
$res as $row ) {
125 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
127 $this->
output(
"Page {$row->page_id} has bad title\n" );
132 $context->setTitle(
$title );
133 $article = Article::newFromTitle(
$title, $context );
134 $context->setWikiPage( $article->getPage() );
137 RequestContext::getMain()->setTitle(
$title );
143 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
147 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
152 Wikimedia\suppressWarnings();
156 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
159 $context->getOutput()->output();
160 $context->getOutput()->clearHTML();
161 $viewHtml = ob_get_clean();
162 $viewCache->saveToFileCache( $viewHtml );
166 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
168 Action::factory(
'history', $article, $context )->show();
169 $context->getOutput()->output();
170 $context->getOutput()->clearHTML();
171 $historyHtml = ob_get_clean();
172 $historyCache->saveToFileCache( $historyHtml );
174 Wikimedia\restoreWarnings();
177 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
179 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
181 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
182 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
184 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
189 $blockStart += $batchSize;
190 $blockEnd += $batchSize;
192 $this->
output(
"Done!\n" );