Example #1
0
 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();
 }
Example #2
0
 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__);
 }
Example #3
0
 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__);
 }
Example #4
0
}
# Query string fields
$action = $wgRequest->getVal('action', 'view');
$title = $wgRequest->getVal('title');
# Set title from request parameters
$wgTitle = $mediaWiki->checkInitialQueries($title, $action);
if ($wgTitle === null) {
    unset($wgTitle);
}
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();
Example #5
0
 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__);
 }
Example #6
0
 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__);
 }
 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();
 }