72 if ( !$this->enabled ) {
73 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
76 $start = $this->
getOption(
'start',
"0" );
77 if ( !ctype_digit( $start ) ) {
78 $this->
fatalError(
"Invalid value for start parameter." );
80 $start = intval( $start );
83 if ( !ctype_digit( $end ) ) {
84 $this->
fatalError(
"Invalid value for end parameter." );
86 $end = intval( $end );
88 $this->
output(
"Building page file cache from page_id {$start}!\n" );
92 $overwrite = $this->
hasOption(
'overwrite' );
93 $start = ( $start > 0 )
95 : $dbr->newSelectQueryBuilder()
96 ->select(
'MIN(page_id)' )
98 ->caller( __METHOD__ )->fetchField();
101 : $dbr->newSelectQueryBuilder()
102 ->select(
'MAX(page_id)' )
104 ->caller( __METHOD__ )->fetchField();
113 $where[
'page_namespace'] =
118 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
121 $end += $batchSize - 1;
122 $blockStart = $start;
123 $blockEnd = $start + $batchSize - 1;
127 while ( $blockEnd <= $end ) {
129 $res = $dbr->newSelectQueryBuilder()
130 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
132 ->useIndex(
'PRIMARY' )
135 $dbr->expr(
'page_id',
'>=', (
int)$blockStart ),
136 $dbr->expr(
'page_id',
'<=', (
int)$blockEnd ),
138 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
139 ->caller( __METHOD__ )->fetchResultSet();
142 foreach ( $res as $row ) {
145 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
146 if ( $title ===
null ) {
147 $this->
output(
"Page {$row->page_id} has bad title\n" );
152 $context->setTitle( $title );
153 $article = Article::newFromTitle( $title, $context );
154 $context->setWikiPage( $article->getPage() );
157 RequestContext::getMain()->setTitle( $title );
160 if ( $article->isFileCacheable( HTMLFileCache::MODE_REBUILD ) ) {
163 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
167 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
172 AtEase::suppressWarnings();
176 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
179 $context->getOutput()->output();
180 $context->getOutput()->clearHTML();
181 $viewHtml = ob_get_clean();
182 $viewCache->saveToFileCache( $viewHtml );
186 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
188 Action::factory(
'history', $article, $context )->show();
189 $context->getOutput()->output();
190 $context->getOutput()->clearHTML();
191 $historyHtml = ob_get_clean();
192 $historyCache->saveToFileCache( $historyHtml );
194 AtEase::restoreWarnings();
197 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
199 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
201 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
202 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
204 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
209 $blockStart += $batchSize;
210 $blockEnd += $batchSize;
212 $this->
output(
"Done!\n" );