/** * @param $x null|WebRequest * @return WebRequest */ public function request(WebRequest $x = null) { $old = $this->context->getRequest(); $this->context->setRequest($x); return $old; }
/** * Performs the request. * - bad titles * - read restriction * - local interwiki redirects * - redirect loop * - special pages * - normal pages * * @throws MWException|PermissionsError|BadTitleError|HttpError * @return void */ private function performRequest() { global $wgTitle; $request = $this->context->getRequest(); $requestTitle = $title = $this->context->getTitle(); $output = $this->context->getOutput(); $user = $this->context->getUser(); if ($request->getVal('printable') === 'yes') { $output->setPrintable(); } $unused = null; // To pass it by reference Hooks::run('BeforeInitialize', [&$title, &$unused, &$output, &$user, $request, $this]); // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty. if (is_null($title) || $title->getDBkey() == '' && !$title->isExternal() || $title->isSpecial('Badtitle')) { $this->context->setTitle(SpecialPage::getTitleFor('Badtitle')); try { $this->parseTitle(); } catch (MalformedTitleException $ex) { throw new BadTitleError($ex); } throw new BadTitleError(); } // Check user's permissions to read this page. // We have to check here to catch special pages etc. // We will check again in Article::view(). $permErrors = $title->isSpecial('RunJobs') ? [] : $title->getUserPermissionsErrors('read', $user); if (count($permErrors)) { // Bug 32276: allowing the skin to generate output with $wgTitle or // $this->context->title set to the input title would allow anonymous users to // determine whether a page exists, potentially leaking private data. In fact, the // curid and oldid request parameters would allow page titles to be enumerated even // when they are not guessable. So we reset the title to Special:Badtitle before the // permissions error is displayed. // The skin mostly uses $this->context->getTitle() these days, but some extensions // still use $wgTitle. $badTitle = SpecialPage::getTitleFor('Badtitle'); $this->context->setTitle($badTitle); $wgTitle = $badTitle; throw new PermissionsError('read', $permErrors); } // Interwiki redirects if ($title->isExternal()) { $rdfrom = $request->getVal('rdfrom'); if ($rdfrom) { $url = $title->getFullURL(['rdfrom' => $rdfrom]); } else { $query = $request->getValues(); unset($query['title']); $url = $title->getFullURL($query); } // Check for a redirect loop if (!preg_match('/^' . preg_quote($this->config->get('Server'), '/') . '/', $url) && $title->isLocal()) { // 301 so google et al report the target as the actual url. $output->redirect($url, 301); } else { $this->context->setTitle(SpecialPage::getTitleFor('Badtitle')); try { $this->parseTitle(); } catch (MalformedTitleException $ex) { throw new BadTitleError($ex); } throw new BadTitleError(); } // Handle any other redirects. // Redirect loops, titleless URL, $wgUsePathInfo URLs, and URLs with a variant } elseif (!$this->tryNormaliseRedirect($title)) { // Prevent information leak via Special:MyPage et al (T109724) if ($title->isSpecialPage()) { $specialPage = SpecialPageFactory::getPage($title->getDBkey()); if ($specialPage instanceof RedirectSpecialPage) { $specialPage->setContext($this->context); if ($this->config->get('HideIdentifiableRedirects') && $specialPage->personallyIdentifiableTarget()) { list(, $subpage) = SpecialPageFactory::resolveAlias($title->getDBkey()); $target = $specialPage->getRedirect($subpage); // target can also be true. We let that case fall through to normal processing. if ($target instanceof Title) { $query = $specialPage->getRedirectQuery() ?: []; $request = new DerivativeRequest($this->context->getRequest(), $query); $request->setRequestURL($this->context->getRequest()->getRequestURL()); $this->context->setRequest($request); // Do not varnish cache these. May vary even for anons $this->context->getOutput()->lowerCdnMaxage(0); $this->context->setTitle($target); $wgTitle = $target; // Reset action type cache. (Special pages have only view) $this->action = null; $title = $target; $output->addJsConfigVars(['wgInternalRedirectTargetUrl' => $target->getFullURL($query)]); $output->addModules('mediawiki.action.view.redirect'); } } } } // Special pages ($title may have changed since if statement above) if (NS_SPECIAL == $title->getNamespace()) { // Actions that need to be made when we have a special pages SpecialPageFactory::executePath($title, $this->context); } else { // ...otherwise treat it as an article view. The article // may still be a wikipage redirect to another article or URL. $article = $this->initializeArticle(); if (is_object($article)) { $this->performAction($article, $requestTitle); } elseif (is_string($article)) { $output->redirect($article); } else { throw new MWException("Shouldn't happen: MediaWiki::initializeArticle()" . " returned neither an object nor a URL"); } } } }