68 if ( !$this->enabled ) {
69 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
72 $start = $this->
getOption(
'start',
"0" );
73 if ( !ctype_digit( $start ) ) {
74 $this->
fatalError(
"Invalid value for start parameter." );
76 $start = intval( $start );
79 if ( !ctype_digit( $end ) ) {
80 $this->
fatalError(
"Invalid value for end parameter." );
82 $end = intval( $end );
84 $this->
output(
"Building page file cache from page_id {$start}!\n" );
88 $overwrite = $this->
hasOption(
'overwrite' );
89 $start = ( $start > 0 )
91 : $dbr->newSelectQueryBuilder()
92 ->select(
'MIN(page_id)' )
94 ->caller( __METHOD__ )->fetchField();
97 : $dbr->newSelectQueryBuilder()
98 ->select(
'MAX(page_id)' )
100 ->caller( __METHOD__ )->fetchField();
109 $where[
'page_namespace'] =
114 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
117 $end += $batchSize - 1;
118 $blockStart = $start;
119 $blockEnd = $start + $batchSize - 1;
123 while ( $blockEnd <= $end ) {
125 $res = $dbr->newSelectQueryBuilder()
126 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
128 ->useIndex(
'PRIMARY' )
131 $dbr->expr(
'page_id',
'>=', (
int)$blockStart ),
132 $dbr->expr(
'page_id',
'<=', (
int)$blockEnd ),
134 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
135 ->caller( __METHOD__ )->fetchResultSet();
138 foreach ( $res as $row ) {
141 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
142 if ( $title ===
null ) {
143 $this->
output(
"Page {$row->page_id} has bad title\n" );
148 $context->setTitle( $title );
149 $article = Article::newFromTitle( $title, $context );
150 $context->setWikiPage( $article->getPage() );
153 RequestContext::getMain()->setTitle( $title );
156 if ( $article->isFileCacheable( HTMLFileCache::MODE_REBUILD ) ) {
159 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
163 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
168 AtEase::suppressWarnings();
172 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
175 $context->getOutput()->output();
176 $context->getOutput()->clearHTML();
177 $viewHtml = ob_get_clean();
178 $viewCache->saveToFileCache( $viewHtml );
182 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
184 Action::factory(
'history', $article, $context )->show();
185 $context->getOutput()->output();
186 $context->getOutput()->clearHTML();
187 $historyHtml = ob_get_clean();
188 $historyCache->saveToFileCache( $historyHtml );
190 AtEase::restoreWarnings();
193 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
195 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
197 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
198 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
200 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
205 $blockStart += $batchSize;
206 $blockEnd += $batchSize;
208 $this->
output(
"Done!\n" );