本文整理匯總了PHP中HTMLFileCache::useFileCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTMLFileCache::useFileCache方法的具體用法?PHP HTMLFileCache::useFileCache怎麽用?PHP HTMLFileCache::useFileCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HTMLFileCache
的用法示例。
在下文中一共展示了HTMLFileCache::useFileCache方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isFileCacheable
/**
* Check if the page can be cached
* @return bool
*/
public function isFileCacheable()
{
$cacheable = false;
if (HTMLFileCache::useFileCache($this->getContext())) {
$cacheable = $this->mPage->getID() && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
// Extension may have reason to disable file caching on some pages.
if ($cacheable) {
$cacheable = Hooks::run('IsFileCacheable', array(&$this));
}
}
return $cacheable;
}
示例2: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
if ($request->getCookie('forceHTTPS') && $request->detectProtocol() == 'http' && $request->getMethod() == 'GET') {
$redirUrl = $request->getFullRequestURL();
$redirUrl = str_replace('http://', 'https://', $redirUrl);
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText(NS_MAIN, 'REDIR');
$this->context->setTitle($title);
$output = $this->context->getOutput();
$output->redirect($redirUrl);
$output->output();
wfProfileOut(__METHOD__);
return;
}
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_MAIN, 'AJAX');
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// 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();
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
// Output everything!
$this->context->getOutput()->output();
wfProfileOut(__METHOD__);
}
示例3: main
private function main()
{
global $wgTitle;
$output = $this->context->getOutput();
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($this->config->get('UseAjax') && $request->getVal('action') === 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_SPECIAL, 'Badtitle/performing an AJAX call in ' . __METHOD__);
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher($this->config);
$dispatcher->performAction($this->context->getUser());
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
// Set DB query expectations for this HTTP request
$trxLimits = $this->config->get('TrxProfilerLimits');
$trxProfiler = Profiler::instance()->getTransactionProfiler();
$trxProfiler->setLogger(LoggerFactory::getInstance('DBPerformance'));
if ($request->hasSafeMethod()) {
$trxProfiler->setExpectations($trxLimits['GET'], __METHOD__);
} else {
$trxProfiler->setExpectations($trxLimits['POST'], __METHOD__);
}
// If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
if ($request->getProtocol() == 'http' && preg_match('#^https://#', wfExpandUrl($request->getRequestURL(), PROTO_HTTPS)) && ($request->getSession()->shouldForceHTTPS() || $request->getCookie('forceHTTPS', '') || $request->getCookie('forceHTTPS') || $this->context->getUser()->isLoggedIn() && $this->context->getUser()->requiresHTTPS())) {
$oldUrl = $request->getFullRequestURL();
$redirUrl = preg_replace('#^http://#', 'https://', $oldUrl);
// ATTENTION: This hook is likely to be removed soon due to overall design of the system.
if (Hooks::run('BeforeHttpsRedirect', [$this->context, &$redirUrl])) {
if ($request->wasPosted()) {
// This is weird and we'd hope it almost never happens. This
// means that a POST came in via HTTP and policy requires us
// redirecting to HTTPS. It's likely such a request is going
// to fail due to post data being lost, but let's try anyway
// and just log the instance.
// @todo FIXME: See if we could issue a 307 or 308 here, need
// to see how clients (automated & browser) behave when we do
wfDebugLog('RedirectedPosts', "Redirected from HTTP to HTTPS: {$oldUrl}");
}
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText('REDIR', NS_MAIN);
$this->context->setTitle($title);
// Since we only do this redir to change proto, always send a vary header
$output->addVaryHeader('X-Forwarded-Proto');
$output->redirect($redirUrl);
$output->output();
return;
}
}
if ($title->canExist() && HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = new HTMLFileCache($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$output->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff, assuming user is viewing the
// latest revision (which should always be the case for file cache)
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$output->disable();
return;
}
}
// Actually do the work of the request and build up any output
$this->performRequest();
// GUI-ify and stash the page output in MediaWiki::doPreOutputCommit() while
// ChronologyProtector synchronizes DB positions or slaves accross all datacenters.
$buffer = null;
$outputWork = function () use($output, &$buffer) {
if ($buffer === null) {
$buffer = $output->output(true);
}
return $buffer;
};
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction and so that
// we avoid having both success and error text in the response
$this->doPreOutputCommit($outputWork);
// Now send the actual output
print $outputWork();
}
示例4: onView
/**
* Print the history page for an article.
*/
function onView()
{
$out = $this->getOutput();
$request = $this->getRequest();
/**
* Allow client caching.
*/
if ($out->checkLastModified($this->page->getTouched())) {
return;
// Client cache fresh and headers sent, nothing more to do.
}
wfProfileIn(__METHOD__);
$this->preCacheMessages();
$config = $this->context->getConfig();
# Fill in the file cache if not set already
$useFileCache = $config->get('UseFileCache');
if ($useFileCache && HTMLFileCache::useFileCache($this->getContext())) {
$cache = HTMLFileCache::newFromTitle($this->getTitle(), 'history');
if (!$cache->isCacheGood()) {
ob_start(array(&$cache, 'saveToFileCache'));
}
}
// Setup page variables.
$out->setFeedAppendQuery('action=history');
$out->addModules('mediawiki.action.history');
if ($config->get('UseMediaWikiUIEverywhere')) {
$out = $this->getOutput();
$out->addModuleStyles(array('mediawiki.ui.input', 'mediawiki.ui.checkbox'));
}
// Handle atom/RSS feeds.
$feedType = $request->getVal('feed');
if ($feedType) {
$this->feed($feedType);
wfProfileOut(__METHOD__);
return;
}
// Fail nicely if article doesn't exist.
if (!$this->page->exists()) {
$out->addWikiMsg('nohistory');
# show deletion/move log if there is an entry
LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice')));
wfProfileOut(__METHOD__);
return;
}
/**
* Add date selector to quickly get to a certain time
*/
$year = $request->getInt('year');
$month = $request->getInt('month');
$tagFilter = $request->getVal('tagfilter');
$tagSelector = ChangeTags::buildTagFilterSelector($tagFilter);
/**
* Option to show only revisions that have been (partially) hidden via RevisionDelete
*/
if ($request->getBool('deleted')) {
$conds = array('rev_deleted != 0');
} else {
$conds = array();
}
if ($this->getUser()->isAllowed('deletedhistory')) {
$checkDeleted = Xml::checkLabel($this->msg('history-show-deleted')->text(), 'deleted', 'mw-show-deleted-only', $request->getBool('deleted')) . "\n";
} else {
$checkDeleted = '';
}
// Add the general form
$action = htmlspecialchars(wfScript());
$out->addHTML("<form action=\"{$action}\" method=\"get\" id=\"mw-history-searchform\">" . Xml::fieldset($this->msg('history-fieldset-title')->text(), false, array('id' => 'mw-history-search')) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . "\n" . Html::hidden('action', 'history') . "\n" . Xml::dateMenu($year == null ? MWTimestamp::getLocalInstance()->format('Y') : $year, $month) . ' ' . ($tagSelector ? implode(' ', $tagSelector) . ' ' : '') . $checkDeleted . Xml::submitButton($this->msg('allpagessubmit')->text()) . "\n" . '</fieldset></form>');
wfRunHooks('PageHistoryBeforeList', array(&$this->page, $this->getContext()));
// Create and output the list.
$pager = new HistoryPager($this, $year, $month, $tagFilter, $conds);
$out->addHTML($pager->getNavigationBar() . $pager->getBody() . $pager->getNavigationBar());
$out->preventClickjacking($pager->getPreventClickjacking());
wfProfileOut(__METHOD__);
}
示例5: wfProfileOut
wfProfileOut('main-misc-setup');
#
# Send Ajax requests to the Ajax dispatcher.
#
if ($wgUseAjax && $action == 'ajax') {
require_once $IP . '/includes/AjaxDispatcher.php';
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
$mediaWiki->restInPeace();
exit;
}
if ($wgUseFileCache && isset($wgTitle)) {
wfProfileIn('main-try-filecache');
// Raw pages should handle cache control on their own,
// even when using file cache. This reduces hits from clients.
if ($action != 'raw' && 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 */
if (!$wgOut->checkLastModified($cache->fileCacheTime())) {
$cache->loadFromFileCache();
}
# Do any stats increment/watchlist stuff
$wgArticle = MediaWiki::articleFromTitle($wgTitle);
$wgArticle->viewUpdates();
# Tell $wgOut that output is taken care of
wfProfileOut('main-try-filecache');
$mediaWiki->restInPeace();
exit;
}
示例6: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_MAIN, 'AJAX');
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
// If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
if (($request->getCookie('forceHTTPS', '') || $request->getCookie('forceHTTPS') || $this->context->getUser()->isLoggedIn() && $this->context->getUser()->requiresHTTPS()) && $request->getProtocol() == 'http') {
$oldUrl = $request->getFullRequestURL();
$redirUrl = str_replace('http://', 'https://', $oldUrl);
if ($request->wasPosted()) {
// This is weird and we'd hope it almost never happens. This
// means that a POST came in via HTTP and policy requires us
// redirecting to HTTPS. It's likely such a request is going
// to fail due to post data being lost, but let's try anyway
// and just log the instance.
//
// @todo @fixme See if we could issue a 307 or 308 here, need
// to see how clients (automated & browser) behave when we do
wfDebugLog('RedirectedPosts', "Redirected from HTTP to HTTPS: {$oldUrl}");
}
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText(NS_MAIN, 'REDIR');
$this->context->setTitle($title);
$output = $this->context->getOutput();
// Since we only do this redir to change proto, always send a vary header
$output->addVaryHeader('X-Forwarded-Proto');
$output->redirect($redirUrl);
$output->output();
wfProfileOut(__METHOD__);
return;
}
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
// Assume we're viewing the latest revision (this should always be the case with file cache)
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$this->context->getOutput()->disable();
wfProfileOut('main-try-filecache');
wfProfileOut(__METHOD__);
return;
}
}
wfProfileOut('main-try-filecache');
}
// Actually do the work of the request and build up any output
$this->performRequest();
// Either all DB and deferred updates should happen or none.
// The later should not be cancelled due to client disconnect.
ignore_user_abort(true);
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
// Output everything!
$this->context->getOutput()->output();
wfProfileOut(__METHOD__);
}
示例7: view
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();
}
示例8: isFileCacheable
/**
* Check if the page can be cached
* @return bool
*/
public function isFileCacheable()
{
$cacheable = false;
if (HTMLFileCache::useFileCache()) {
$cacheable = $this->getID() && !$this->mRedirectedFrom;
// Extension may have reason to disable file caching on some pages.
if ($cacheable) {
$cacheable = wfRunHooks('IsFileCacheable', array(&$this));
}
}
return $cacheable;
}
示例9: view
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();
}
示例10: main
private function main()
{
global $wgUseFileCache, $wgTitle, $wgUseAjax;
wfProfileIn(__METHOD__);
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($wgUseAjax && $request->getVal('action', 'view') == 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
// Wikia change - start
// @author macbre, wladek
$title = Wikia::createTitleFromRequest($request);
// Wikia change - end
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher();
$dispatcher->performAction();
wfProfileOut(__METHOD__);
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
if ($wgUseFileCache && $title->getNamespace() >= 0) {
wfProfileIn('main-try-filecache');
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = HTMLFileCache::newFromTitle($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// 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__);
}
示例11: view
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();
}
示例12: main
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__);
}
示例13: main
private function main()
{
global $wgTitle;
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
if ($this->config->get('UseAjax') && $request->getVal('action') === 'ajax') {
// Set a dummy title, because $wgTitle == null might break things
$title = Title::makeTitle(NS_SPECIAL, 'Badtitle/performing an AJAX call in ' . __METHOD__);
$this->context->setTitle($title);
$wgTitle = $title;
$dispatcher = new AjaxDispatcher($this->config);
$dispatcher->performAction($this->context->getUser());
return;
}
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
$title = $this->getTitle();
$action = $this->getAction();
$wgTitle = $title;
$trxProfiler = Profiler::instance()->getTransactionProfiler();
$trxProfiler->setLogger(LoggerFactory::getInstance('DBPerformance'));
// Aside from rollback, master queries should not happen on GET requests.
// Periodic or "in passing" updates on GET should use the job queue.
if (!$request->wasPosted() && in_array($action, array('view', 'edit', 'history'))) {
$trxProfiler->setExpectation('masterConns', 0, __METHOD__);
$trxProfiler->setExpectation('writes', 0, __METHOD__);
} else {
$trxProfiler->setExpectation('maxAffected', 500, __METHOD__);
}
// If the user has forceHTTPS set to true, or if the user
// is in a group requiring HTTPS, or if they have the HTTPS
// preference set, redirect them to HTTPS.
// Note: Do this after $wgTitle is setup, otherwise the hooks run from
// isLoggedIn() will do all sorts of weird stuff.
if ($request->getProtocol() == 'http' && ($request->getCookie('forceHTTPS', '') || $request->getCookie('forceHTTPS') || $this->context->getUser()->isLoggedIn() && $this->context->getUser()->requiresHTTPS())) {
$oldUrl = $request->getFullRequestURL();
$redirUrl = preg_replace('#^http://#', 'https://', $oldUrl);
// ATTENTION: This hook is likely to be removed soon due to overall design of the system.
if (Hooks::run('BeforeHttpsRedirect', array($this->context, &$redirUrl))) {
if ($request->wasPosted()) {
// This is weird and we'd hope it almost never happens. This
// means that a POST came in via HTTP and policy requires us
// redirecting to HTTPS. It's likely such a request is going
// to fail due to post data being lost, but let's try anyway
// and just log the instance.
//
// @todo FIXME: See if we could issue a 307 or 308 here, need
// to see how clients (automated & browser) behave when we do
wfDebugLog('RedirectedPosts', "Redirected from HTTP to HTTPS: {$oldUrl}");
}
// Setup dummy Title, otherwise OutputPage::redirect will fail
$title = Title::newFromText('REDIR', NS_MAIN);
$this->context->setTitle($title);
$output = $this->context->getOutput();
// Since we only do this redir to change proto, always send a vary header
$output->addVaryHeader('X-Forwarded-Proto');
$output->redirect($redirUrl);
$output->output();
return;
}
}
if ($this->config->get('UseFileCache') && $title->getNamespace() >= 0) {
if (HTMLFileCache::useFileCache($this->context)) {
// Try low-level file cache hit
$cache = new HTMLFileCache($title, $action);
if ($cache->isCacheGood()) {
// Check incoming headers to see if client has this cached
$timestamp = $cache->cacheTimestamp();
if (!$this->context->getOutput()->checkLastModified($timestamp)) {
$cache->loadFromFileCache($this->context);
}
// Do any stats increment/watchlist stuff
// Assume we're viewing the latest revision (this should always be the case with file cache)
$this->context->getWikiPage()->doViewUpdates($this->context->getUser());
// Tell OutputPage that output is taken care of
$this->context->getOutput()->disable();
return;
}
}
}
// Actually do the work of the request and build up any output
$this->performRequest();
// Either all DB and deferred updates should happen or none.
// The later should not be cancelled due to client disconnect.
ignore_user_abort(true);
// Now commit any transactions, so that unreported errors after
// output() don't roll back the whole DB transaction
wfGetLBFactory()->commitMasterChanges();
// Output everything!
$this->context->getOutput()->output();
}