while ($blockEnd <= $end) { // Get the pages $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_id'), array('page_namespace' => $wgContentNamespaces, "page_id BETWEEN {$blockStart} AND {$blockEnd}"), array('ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY')); while ($row = $dbr->fetchObject($res)) { $rebuilt = false; $wgTitle = Title::makeTitleSafe($row->page_namespace, $row->page_title); if (null == $wgTitle) { echo "Page {$row->page_id} bad title\n"; continue; // broken title? } $wgArticle = new Article($wgTitle); // If the article is cacheable, then load it if ($wgArticle->isFileCacheable()) { $cache = new HTMLFileCache($wgTitle); if ($cache->isFileCacheGood()) { if ($overwrite) { $rebuilt = true; } else { echo "Page {$row->page_id} already cached\n"; continue; // done already! } } ob_start(array(&$cache, 'saveToFileCache')); // save on ob_end_clean() $wgUseFileCache = false; // hack, we don't want $wgArticle fiddling with filecache $wgArticle->view(); @$wgOut->output(); // header notices
/** * checkLastModified returns true if it has taken care of all * output to the client that is necessary for this request. * (that is, it has sent a cached version of the page) * * @return boolean true if cached version send, false otherwise */ protected function tryFileCache() { static $called = false; if ($called) { wfDebug("Article::tryFileCache(): called twice!?\n"); return false; } $called = true; if ($this->isFileCacheable()) { $cache = new HTMLFileCache($this->mTitle); if ($cache->isFileCacheGood($this->mTouched)) { wfDebug("Article::tryFileCache(): about to load file\n"); $cache->loadFromFileCache(); return true; } else { wfDebug("Article::tryFileCache(): starting buffer\n"); ob_start(array(&$cache, 'saveToFileCache')); } } else { wfDebug("Article::tryFileCache(): not cacheable\n"); } return false; }
public function execute() { global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces, $wgRequestTime; global $wgTitle, $wgArticle, $wgOut, $wgUser; if (!$wgUseFileCache) { $this->error("Nothing to do -- \$wgUseFileCache is disabled.", true); } $wgDisableCounters = false; $start = $this->getArg(0, "0"); if (!ctype_digit($start)) { $this->error("Invalid value for start parameter.", true); } $start = intval($start); $overwrite = $this->hasArg(1) && $this->getArg(1) === 'overwrite'; $this->output("Building content page file cache from page {$start}!\n"); $dbr = wfGetDB(DB_SLAVE); $start = $start > 0 ? $start : $dbr->selectField('page', 'MIN(page_id)', false, __FUNCTION__); $end = $dbr->selectField('page', 'MAX(page_id)', false, __FUNCTION__); if (!$start) { $this->error("Nothing to do.", true); } $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client OutputPage::setEncodings(); # Not really used yet # Do remaining chunk $end += $this->mBatchSize - 1; $blockStart = $start; $blockEnd = $start + $this->mBatchSize - 1; $dbw = wfGetDB(DB_MASTER); // Go through each page and save the output while ($blockEnd <= $end) { // Get the pages $res = $dbr->select('page', array('page_namespace', 'page_title', 'page_id'), array('page_namespace' => $wgContentNamespaces, "page_id BETWEEN {$blockStart} AND {$blockEnd}"), array('ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY')); foreach ($res as $row) { $rebuilt = false; $wgRequestTime = wfTime(); # bug 22852 $wgTitle = Title::makeTitleSafe($row->page_namespace, $row->page_title); if (null == $wgTitle) { $this->output("Page {$row->page_id} has bad title\n"); continue; // broken title? } $wgOut->setTitle($wgTitle); // set display title $wgUser->getSkin($wgTitle); // set skin title $wgArticle = new Article($wgTitle); // If the article is cacheable, then load it if ($wgArticle->isFileCacheable()) { $cache = new HTMLFileCache($wgTitle); if ($cache->isFileCacheGood()) { if ($overwrite) { $rebuilt = true; } else { $this->output("Page {$row->page_id} already cached\n"); continue; // done already! } } ob_start(array(&$cache, 'saveToFileCache')); // save on ob_end_clean() $wgUseFileCache = false; // hack, we don't want $wgArticle fiddling with filecache $wgArticle->view(); @$wgOut->output(); // header notices $wgUseFileCache = true; ob_end_clean(); // clear buffer $wgOut = new OutputPage(); // empty out any output page garbage if ($rebuilt) { $this->output("Re-cached page {$row->page_id}\n"); } else { $this->output("Cached page {$row->page_id}\n"); } } else { $this->output("Page {$row->page_id} not cacheable\n"); } $dbw->commit(); // commit any changes } $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; wfWaitForSlaves(5); } $this->output("Done!\n"); // Remove these to be safe if (isset($wgTitle)) { unset($wgTitle); } if (isset($wgArticle)) { unset($wgArticle); } }
function view() { global $wgOut, $wgScript; if (isset($_SERVER['SCRIPT_URL'])) { # Normally we use PHP_SELF to get the URL to the script # as it was called, minus the query string. # # Some sites use Apache rewrite rules to handle subdomains, # and have PHP set up in a weird way that causes PHP_SELF # to contain the rewritten URL instead of the one that the # outside world sees. # # If in this mode, use SCRIPT_URL instead, which mod_rewrite # provides containing the "before" URL. $url = $_SERVER['SCRIPT_URL']; } else { $url = $_SERVER['PHP_SELF']; } if (strcmp($wgScript, $url)) { # Internet Explorer will ignore the Content-Type header if it # thinks it sees a file extension it recognizes. Make sure that # all raw requests are done through the script node, which will # have eg '.php' and should remain safe. # # We used to redirect to a canonical-form URL as a general # backwards-compatibility / good-citizen nice thing. However # a lot of servers are set up in buggy ways, resulting in # redirect loops which hang the browser until the CSS load # times out. # # Just return a 403 Forbidden and get it over with. wfHttpError(403, 'Forbidden', 'Raw pages must be accessed through the primary script entry point.'); return; } header("Content-type: " . $this->mContentType . '; charset=' . $this->mCharset); # allow the client to cache this for 24 hours $mode = $this->mPrivateCache ? 'private' : 'public'; header('Cache-Control: ' . $mode . ', s-maxage=' . $this->mSmaxage . ', max-age=' . $this->mMaxage); if (HTMLFileCache::useFileCache()) { $cache = new HTMLFileCache($this->mTitle, 'raw'); if ($cache->isFileCacheGood()) { $cache->loadFromFileCache(); $wgOut->disable(); return; } else { ob_start(array(&$cache, 'saveToFileCache')); } } $text = $this->getRawText(); if (!wfRunHooks('RawPageViewBeforeOutput', array(&$this, &$text))) { wfDebug(__METHOD__ . ': RawPageViewBeforeOutput hook broke raw page output.'); } echo $text; $wgOut->disable(); }
function view() { global $wgOut, $wgScript, $wgRequest; if ($wgRequest->isPathInfoBad()) { # Internet Explorer will ignore the Content-Type header if it # thinks it sees a file extension it recognizes. Make sure that # all raw requests are done through the script node, which will # have eg '.php' and should remain safe. # # We used to redirect to a canonical-form URL as a general # backwards-compatibility / good-citizen nice thing. However # a lot of servers are set up in buggy ways, resulting in # redirect loops which hang the browser until the CSS load # times out. # # Just return a 403 Forbidden and get it over with. wfHttpError(403, 'Forbidden', 'Invalid file extension found in PATH_INFO or QUERY_STRING. ' . 'Raw pages must be accessed through the primary script entry point.'); return; } header("Content-type: " . $this->mContentType . '; charset=' . $this->mCharset); # allow the client to cache this for 24 hours $mode = $this->mPrivateCache ? 'private' : 'public'; header('Cache-Control: ' . $mode . ', s-maxage=' . $this->mSmaxage . ', max-age=' . $this->mMaxage); global $wgUseFileCache; if ($wgUseFileCache and HTMLFileCache::useFileCache()) { $cache = new HTMLFileCache($this->mTitle, 'raw'); if ($cache->isFileCacheGood()) { $cache->loadFromFileCache(); $wgOut->disable(); return; } else { ob_start(array(&$cache, 'saveToFileCache')); } } $text = $this->getRawText(); if (!wfRunHooks('RawPageViewBeforeOutput', array(&$this, &$text))) { wfDebug(__METHOD__ . ": RawPageViewBeforeOutput hook broke raw page output.\n"); } echo $text; $wgOut->disable(); }
function view() { global $wgOut, $wgRequest; if (!$wgRequest->checkUrlExtension()) { $wgOut->disable(); return; } header('Content-type: ' . $this->mContentType . '; charset=' . $this->mCharset); # allow the client to cache this for 24 hours $mode = $this->mPrivateCache ? 'private' : 'public'; header('Cache-Control: ' . $mode . ', s-maxage=' . $this->mSmaxage . ', max-age=' . $this->mMaxage); global $wgUseFileCache; if ($wgUseFileCache && HTMLFileCache::useFileCache()) { $cache = new HTMLFileCache($this->mTitle, 'raw'); if ($cache->isFileCacheGood()) { $cache->loadFromFileCache(); $wgOut->disable(); return; } else { ob_start(array(&$cache, 'saveToFileCache')); } } $text = $this->getRawText(); if (!wfRunHooks('RawPageViewBeforeOutput', array(&$this, &$text))) { wfDebug(__METHOD__ . ": RawPageViewBeforeOutput hook broke raw page output.\n"); } echo $text; $wgOut->disable(); }
private function main() { global $wgUseFileCache, $wgTitle, $wgUseAjax; wfProfileIn(__METHOD__); # Set title from request parameters $wgTitle = $this->getTitle(); $action = $this->getAction(); $user = $this->context->getUser(); # Send Ajax requests to the Ajax dispatcher. if ($wgUseAjax && $action == 'ajax') { $dispatcher = new AjaxDispatcher(); $dispatcher->performAction(); wfProfileOut(__METHOD__); return; } if ($wgUseFileCache && $wgTitle->getNamespace() != NS_SPECIAL) { wfProfileIn('main-try-filecache'); // Raw pages should handle cache control on their own, // even when using file cache. This reduces hits from clients. if (HTMLFileCache::useFileCache()) { /* Try low-level file cache hit */ $cache = new HTMLFileCache($wgTitle, $action); if ($cache->isFileCacheGood()) { /* Check incoming headers to see if client has this cached */ $timestamp = $cache->fileCacheTime(); if (!$this->context->getOutput()->checkLastModified($timestamp)) { $cache->loadFromFileCache(); } # Do any stats increment/watchlist stuff $article = WikiPage::factory($wgTitle); $article->doViewUpdates($user); # Tell OutputPage that output is taken care of $this->context->getOutput()->disable(); wfProfileOut('main-try-filecache'); wfProfileOut(__METHOD__); return; } } wfProfileOut('main-try-filecache'); } $this->performRequest(); $this->finalCleanup(); wfProfileOut(__METHOD__); }