66 if ( !$this->enabled ) {
67 $this->
fatalError(
"Nothing to do -- \$wgUseFileCache is disabled." );
70 $start = $this->
getOption(
'start',
"0" );
71 if ( !ctype_digit( $start ) ) {
72 $this->
fatalError(
"Invalid value for start parameter." );
74 $start = intval( $start );
77 if ( !ctype_digit( $end ) ) {
78 $this->
fatalError(
"Invalid value for end parameter." );
80 $end = intval( $end );
82 $this->
output(
"Building page file cache from page_id {$start}!\n" );
86 $overwrite = $this->
hasOption(
'overwrite' );
87 $start = ( $start > 0 )
89 : $dbr->newSelectQueryBuilder()
90 ->select(
'MIN(page_id)' )
92 ->caller( __METHOD__ )->fetchField();
95 : $dbr->newSelectQueryBuilder()
96 ->select(
'MAX(page_id)' )
98 ->caller( __METHOD__ )->fetchField();
107 $where[
'page_namespace'] =
112 $_SERVER[
'HTTP_ACCEPT_ENCODING'] =
'bgzip';
115 $end += $batchSize - 1;
116 $blockStart = $start;
117 $blockEnd = $start + $batchSize - 1;
121 while ( $blockEnd <= $end ) {
123 $res = $dbr->newSelectQueryBuilder()
124 ->select( [
'page_namespace',
'page_title',
'page_id' ] )
126 ->useIndex(
'PRIMARY' )
128 ->andWhere( [
"page_id BETWEEN " . (
int)$blockStart .
" AND " . (
int)$blockEnd ] )
129 ->orderBy(
'page_id', SelectQueryBuilder::SORT_ASC )
130 ->caller( __METHOD__ )->fetchResultSet();
133 foreach ( $res as $row ) {
136 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
137 if ( $title ===
null ) {
138 $this->
output(
"Page {$row->page_id} has bad title\n" );
143 $context->setTitle( $title );
144 $article = Article::newFromTitle( $title, $context );
145 $context->setWikiPage( $article->getPage() );
148 RequestContext::getMain()->setTitle( $title );
154 if ( $viewCache->isCacheGood() && $historyCache->isCacheGood() ) {
158 $this->
output(
"Page '$title' (id {$row->page_id}) already cached\n" );
163 AtEase::suppressWarnings();
167 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
170 $context->getOutput()->output();
171 $context->getOutput()->clearHTML();
172 $viewHtml = ob_get_clean();
173 $viewCache->saveToFileCache( $viewHtml );
177 $_SERVER[
'REQUEST_TIME_FLOAT'] = microtime(
true );
179 Action::factory(
'history', $article, $context )->show();
180 $context->getOutput()->output();
181 $context->getOutput()->clearHTML();
182 $historyHtml = ob_get_clean();
183 $historyCache->saveToFileCache( $historyHtml );
185 AtEase::restoreWarnings();
188 $this->
output(
"Re-cached page '$title' (id {$row->page_id})..." );
190 $this->
output(
"Cached page '$title' (id {$row->page_id})..." );
192 $this->
output(
"[view: " . strlen( $viewHtml ) .
" bytes; " .
193 "history: " . strlen( $historyHtml ) .
" bytes]\n" );
195 $this->
output(
"Page '$title' (id {$row->page_id}) not cacheable\n" );
200 $blockStart += $batchSize;
201 $blockEnd += $batchSize;
203 $this->
output(
"Done!\n" );