75 if ( !$this->enabled ) {
76 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
79 $start = $this->
getOption(
'start',
"0" );
80 if ( !ctype_digit( $start ) ) {
81 $this->
fatalError(
"Invalid value for start parameter." );
83 $start = intval( $start );
86 if ( !ctype_digit( $end ) ) {
87 $this->
fatalError(
"Invalid value for end parameter." );
89 $end = intval( $end );
91 $this->
output(
"Building page file cache from page_id {$start}!\n" );
95 $overwrite = $this->
hasOption(
'overwrite' );
96 $start = ( $start > 0 )
98 : $dbr->newSelectQueryBuilder()
99 ->select(
'MIN(page_id)' )
101 ->caller( __METHOD__ )->fetchField();
104 : $dbr->newSelectQueryBuilder()
105 ->select(
'MAX(page_id)' )
107 ->caller( __METHOD__ )->fetchField();
116 $where[
'page_namespace'] =
121 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
124 $end += $batchSize - 1;
125 $blockStart = $start;
126 $blockEnd = $start + $batchSize - 1;
130 while ( $blockEnd <= $end ) {
132 $res = $dbr->newSelectQueryBuilder()
133 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
135 ->useIndex(
'PRIMARY' )
138 $dbr->expr(
'page_id',
'>=', (
int)$blockStart ),
139 $dbr->expr(
'page_id',
'<=', (
int)$blockEnd ),
141 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
142 ->caller( __METHOD__ )->fetchResultSet();
145 foreach ( $res as $row ) {
148 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
149 if ( $title ===
null ) {
150 $this->
output(
"Page {$row->page_id} has bad title\n" );
155 $context->setTitle( $title );
156 $article = Article::newFromTitle( $title, $context );
157 $context->setWikiPage( $article->getPage() );
160 RequestContext::getMain()->setTitle( $title );
163 if ( $article->isFileCacheable( HTMLFileCache::MODE_REBUILD ) ) {
166 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
170 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
175 AtEase::suppressWarnings();
179 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
182 $context->getOutput()->output();
183 $context->getOutput()->clearHTML();
184 $viewHtml = ob_get_clean();
185 $viewCache->saveToFileCache( $viewHtml );
189 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
191 Action::factory(
'history', $article, $context )->show();
192 $context->getOutput()->output();
193 $context->getOutput()->clearHTML();
194 $historyHtml = ob_get_clean();
195 $historyCache->saveToFileCache( $historyHtml );
197 AtEase::restoreWarnings();
200 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
202 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
204 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
205 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
207 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
212 $blockStart += $batchSize;
213 $blockEnd += $batchSize;
215 $this->
output(
"Done!\n" );