67 if ( !$this->enabled ) {
68 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
71 $start = $this->
getOption(
'start',
"0" );
72 if ( !ctype_digit( $start ) ) {
73 $this->
fatalError(
"Invalid value for start parameter." );
75 $start = intval( $start );
78 if ( !ctype_digit( $end ) ) {
79 $this->
fatalError(
"Invalid value for end parameter." );
81 $end = intval( $end );
83 $this->
output(
"Building page file cache from page_id {$start}!\n" );
87 $overwrite = $this->
hasOption(
'overwrite' );
88 $start = ( $start > 0 )
90 : $dbr->newSelectQueryBuilder()
91 ->select(
'MIN(page_id)' )
93 ->caller( __METHOD__ )->fetchField();
96 : $dbr->newSelectQueryBuilder()
97 ->select(
'MAX(page_id)' )
99 ->caller( __METHOD__ )->fetchField();
108 $where[
'page_namespace'] =
113 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
116 $end += $batchSize - 1;
117 $blockStart = $start;
118 $blockEnd = $start + $batchSize - 1;
122 while ( $blockEnd <= $end ) {
124 $res = $dbr->newSelectQueryBuilder()
125 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
127 ->useIndex(
'PRIMARY' )
129 ->andWhere( [
"page_id BETWEEN " . (
int)$blockStart .
" AND " . (
int)$blockEnd ] )
130 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
131 ->caller( __METHOD__ )->fetchResultSet();
134 foreach ( $res as $row ) {
137 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
138 if ( $title ===
null ) {
139 $this->
output(
"Page {$row->page_id} has bad title\n" );
144 $context->setTitle( $title );
145 $article = Article::newFromTitle( $title, $context );
146 $context->setWikiPage( $article->getPage() );
149 RequestContext::getMain()->setTitle( $title );
152 if ( $article->isFileCacheable( HTMLFileCache::MODE_REBUILD ) ) {
155 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
159 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
164 AtEase::suppressWarnings();
168 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
171 $context->getOutput()->output();
172 $context->getOutput()->clearHTML();
173 $viewHtml = ob_get_clean();
174 $viewCache->saveToFileCache( $viewHtml );
178 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
180 Action::factory(
'history', $article, $context )->show();
181 $context->getOutput()->output();
182 $context->getOutput()->clearHTML();
183 $historyHtml = ob_get_clean();
184 $historyCache->saveToFileCache( $historyHtml );
186 AtEase::restoreWarnings();
189 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
191 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
193 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
194 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
196 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
201 $blockStart += $batchSize;
202 $blockEnd += $batchSize;
204 $this->
output(
"Done!\n" );