71 if ( !$this->enabled ) {
72 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
75 $start = $this->
getOption(
'start',
"0" );
76 if ( !ctype_digit( $start ) ) {
77 $this->
fatalError(
"Invalid value for start parameter." );
79 $start = intval( $start );
82 if ( !ctype_digit( $end ) ) {
83 $this->
fatalError(
"Invalid value for end parameter." );
85 $end = intval( $end );
87 $this->
output(
"Building page file cache from page_id {$start}!\n" );
91 $overwrite = $this->
hasOption(
'overwrite' );
92 $start = ( $start > 0 )
94 : $dbr->newSelectQueryBuilder()
95 ->select(
'MIN(page_id)' )
97 ->caller( __METHOD__ )->fetchField();
100 : $dbr->newSelectQueryBuilder()
101 ->select(
'MAX(page_id)' )
103 ->caller( __METHOD__ )->fetchField();
112 $where[
'page_namespace'] =
117 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
120 $end += $batchSize - 1;
121 $blockStart = $start;
122 $blockEnd = $start + $batchSize - 1;
126 while ( $blockEnd <= $end ) {
128 $res = $dbr->newSelectQueryBuilder()
129 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
131 ->useIndex(
'PRIMARY' )
134 $dbr->expr(
'page_id',
'>=', (
int)$blockStart ),
135 $dbr->expr(
'page_id',
'<=', (
int)$blockEnd ),
137 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
138 ->caller( __METHOD__ )->fetchResultSet();
141 foreach ( $res as $row ) {
144 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
145 if ( $title ===
null ) {
146 $this->
output(
"Page {$row->page_id} has bad title\n" );
151 $context->setTitle( $title );
152 $article = Article::newFromTitle( $title, $context );
153 $context->setWikiPage( $article->getPage() );
156 RequestContext::getMain()->setTitle( $title );
159 if ( $article->isFileCacheable( HTMLFileCache::MODE_REBUILD ) ) {
162 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
166 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
171 AtEase::suppressWarnings();
175 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
178 $context->getOutput()->output();
179 $context->getOutput()->clearHTML();
180 $viewHtml = ob_get_clean();
181 $viewCache->saveToFileCache( $viewHtml );
185 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
187 Action::factory(
'history', $article, $context )->show();
188 $context->getOutput()->output();
189 $context->getOutput()->clearHTML();
190 $historyHtml = ob_get_clean();
191 $historyCache->saveToFileCache( $historyHtml );
193 AtEase::restoreWarnings();
196 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
198 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
200 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
201 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
203 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
208 $blockStart += $batchSize;
209 $blockEnd += $batchSize;
211 $this->
output(
"Done!\n" );