/** * Initialize the object to be known as $wgArticle for special cases */ function initializeSpecialCases(&$title, &$output, $request) { wfProfileIn('MediaWiki::initializeSpecialCases'); $search = $this->getVal('Search'); $action = $this->getVal('Action'); if (!$this->getVal('DisableInternalSearch') && !is_null($search) && $search !== '') { require_once 'includes/SpecialSearch.php'; $title = Title::makeTitle(NS_SPECIAL, 'Search'); wfSpecialSearch(); } else { if (!$title or $title->getDBkey() == '') { $title = Title::makeTitle(NS_SPECIAL, 'Badtitle'); # Die now before we mess up $wgArticle and the skin stops working throw new ErrorPageError('badtitle', 'badtitletext'); } else { if ($title->getInterwiki() != '') { if ($rdfrom = $request->getVal('rdfrom')) { $url = $title->getFullURL('rdfrom=' . urlencode($rdfrom)); } else { $url = $title->getFullURL(); } /* Check for a redirect loop */ if (!preg_match('/^' . preg_quote($this->getVal('Server'), '/') . '/', $url) && $title->isLocal()) { $output->redirect($url); } else { $title = Title::makeTitle(NS_SPECIAL, 'Badtitle'); throw new ErrorPageError('badtitle', 'badtitletext'); } } else { if ($action == 'view' && (!isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title']) && !count(array_diff(array_keys($this->GET), array('action', 'title')))) { /* Redirect to canonical url, make it a 301 to allow caching */ $output->setSquidMaxage(1200); $output->redirect($title->getFullURL(), '301'); } else { if (NS_SPECIAL == $title->getNamespace()) { /* actions that need to be made when we have a special pages */ SpecialPage::executePath($title); } else { /* No match to special cases */ wfProfileOut('MediaWiki::initializeSpecialCases'); return false; } } } } } /* Did match a special case */ wfProfileOut('MediaWiki::initializeSpecialCases'); return true; }
/** * Initialize some special cases: * - bad titles * - local interwiki redirects * - redirect loop * - special pages * * @param $title Title * @param $output OutputPage * @param $request WebRequest * @return bool true if the request is already executed */ function handleSpecialCases(&$title, &$output, $request) { wfProfileIn(__METHOD__); $action = $this->getVal('Action'); // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty. if (is_null($title) || $title->getDBkey() == '' && $title->getInterwiki() == '') { $title = SpecialPage::getTitleFor('Badtitle'); $output->setTitle($title); // bug 21456 // Die now before we mess up $wgArticle and the skin stops working throw new ErrorPageError('badtitle', 'badtitletext'); // Interwiki redirects } else { if ($title->getInterwiki() != '') { $rdfrom = $request->getVal('rdfrom'); if ($rdfrom) { $url = $title->getFullURL('rdfrom=' . urlencode($rdfrom)); } else { $query = $request->getValues(); unset($query['title']); $url = $title->getFullURL($query); } /* Check for a redirect loop */ if (!preg_match('/^' . preg_quote($this->getVal('Server'), '/') . '/', $url) && $title->isLocal()) { // 301 so google et al report the target as the actual url. $output->redirect($url, 301); } else { $title = SpecialPage::getTitleFor('Badtitle'); $output->setTitle($title); // bug 21456 wfProfileOut(__METHOD__); throw new ErrorPageError('badtitle', 'badtitletext'); } // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant } else { if ($action == 'view' && !$request->wasPosted() && ($request->getVal('title') === null || $title->getPrefixedDBKey() != $request->getVal('title')) && !count(array_diff(array_keys($request->getValues()), array('action', 'title')))) { if ($title->getNamespace() == NS_SPECIAL) { list($name, $subpage) = SpecialPage::resolveAliasWithSubpage($title->getDBkey()); if ($name) { $title = SpecialPage::getTitleFor($name, $subpage); } } $targetUrl = $title->getFullURL(); // Redirect to canonical url, make it a 301 to allow caching if ($targetUrl == $request->getFullRequestURL()) { $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . "to a new server or changing the server configuration.\n\n"; if ($this->getVal('UsePathInfo')) { $message .= "The wiki is trying to interpret the page " . "title from the URL path portion (PATH_INFO), which " . "sometimes fails depending on the web server. Try " . "setting \"\$wgUsePathInfo = false;\" in your " . "LocalSettings.php, or check that \$wgArticlePath " . "is correct."; } else { $message .= "Your web server was detected as possibly not " . "supporting URL path components (PATH_INFO) correctly; " . "check your LocalSettings.php for a customized " . "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . "to true."; } wfHttpError(500, "Internal error", $message); wfProfileOut(__METHOD__); return false; } else { $output->setSquidMaxage(1200); $output->redirect($targetUrl, '301'); } // Special pages } else { if (NS_SPECIAL == $title->getNamespace()) { /* actions that need to be made when we have a special pages */ SpecialPage::executePath($title); } else { /* No match to special cases */ wfProfileOut(__METHOD__); return false; } } } } /* Did match a special case */ wfProfileOut(__METHOD__); return true; }
# Check for a redirect loop if (!preg_match('/^' . preg_quote($wgServer, '/') . '/', $url) && $wgTitle->isLocal()) { $wgOut->redirect($url); } else { $wgTitle = Title::newFromText(wfMsgForContent('badtitle')); $wgOut->errorpage('badtitle', 'badtitletext'); } } else { if ($action == 'view' && (!isset($_GET['title']) || $wgTitle->getPrefixedDBKey() != $_GET['title']) && !count(array_diff(array_keys($_GET), array('action', 'title')))) { /* redirect to canonical url, make it a 301 to allow caching */ $wgOut->setSquidMaxage(1200); $wgOut->redirect($wgTitle->getFullURL(), '301'); } else { if (NS_SPECIAL == $wgTitle->getNamespace()) { # actions that need to be made when we have a special pages SpecialPage::executePath($wgTitle); } else { if (NS_MEDIA == $wgTitle->getNamespace()) { $wgTitle = Title::makeTitle(NS_IMAGE, $wgTitle->getDBkey()); } $ns = $wgTitle->getNamespace(); if ($ns == NS_IMAGE) { require_once 'includes/ImagePage.php'; $wgArticle = new ImagePage($wgTitle); } elseif ($wgUseCategoryMagic && $ns == NS_CATEGORY) { require_once 'includes/CategoryPage.php'; $wgArticle = new CategoryPage($wgTitle); } else { $wgArticle = new Article($wgTitle); } if (in_array($action, $wgDisabledActions)) {
/** * Just like executePath() except it returns the HTML instead of outputting it * Returns false if there was no such special page, or a title object if it was * a redirect. * @static */ static function capturePath(&$title) { global $wgOut, $wgTitle; $oldTitle = $wgTitle; $oldOut = $wgOut; $wgOut = new OutputPage(); $ret = SpecialPage::executePath($title, true); if ($ret === true) { $ret = $wgOut->getHTML(); } $wgTitle = $oldTitle; $wgOut = $oldOut; return $ret; }
/** * Initialize the object to be known as $wgArticle for special cases */ function initializeSpecialCases(&$title, &$output, $request) { global $wgRequest, $wgUseGoogleMini, $IP; wfProfileIn('MediaWiki::initializeSpecialCases'); $action = $this->getVal('Action'); $search = $request->getVal('search'); if ($this->getVal('Server') != "http://" . $_SERVER['HTTP_HOST'] && !preg_match("@[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+@", $_SERVER['HTTP_HOST']) && !IS_SPARE_HOST && !IS_CLOUD_SITE) { $output->redirect($this->getVal('Server') . $_SERVER['REQUEST_URI'], 301); return; } if (!$title or $title->getDBkey() == '') { $title = SpecialPage::getTitleFor('Badtitle'); # Die now before we mess up $wgArticle and the skin stops working throw new ErrorPageError('badtitle', 'badtitletext'); } else { if (!is_null($search) && $search !== '' && $wgUseGoogleMini) { //XXCHANGED if ($wgRequest->getVal('advanced', null) == null && $wgUseGoogleMini) { $title = Title::makeTitle(NS_SPECIAL, 'LSearch'); require_once "{$IP}/extensions/wikihow/LSearch.body.php"; $s = new LSearch(); $s->execute(''); } else { require_once "{$IP}/includes/SpecialSearch.php"; $title = Title::makeTitle(NS_SPECIAL, 'Search'); #$s = new SpecialSearch(); #$s->execute(''); wfSpecialSearch(); } } else { if ($title->getInterwiki() != '') { if ($rdfrom = $request->getVal('rdfrom')) { $url = $title->getFullURL('rdfrom=' . urlencode($rdfrom)); } else { $url = $title->getFullURL(); } /* Check for a redirect loop */ if (!preg_match('/^' . preg_quote($this->getVal('Server'), '/') . '/', $url) && $title->isLocal()) { $output->redirect($url); } else { $title = SpecialPage::getTitleFor('Badtitle'); throw new ErrorPageError('badtitle', 'badtitletext'); } } else { if ($action == 'view' && !$wgRequest->wasPosted() && (!isset($this->GET['title']) || $title->getPrefixedDBKey() != $this->GET['title']) && !count(array_diff(array_keys($this->GET), array('action', 'title')))) { $targetUrl = $title->getFullURL(); // Redirect to canonical url, make it a 301 to allow caching global $wgUsePathInfo; if ($targetUrl == $wgRequest->getFullRequestURL()) { $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . "to a new server or changing the server configuration.\n\n"; if ($wgUsePathInfo) { $message .= "The wiki is trying to interpret the page " . "title from the URL path portion (PATH_INFO), which " . "sometimes fails depending on the web server. Try " . "setting \"\$wgUsePathInfo = false;\" in your " . "LocalSettings.php, or check that \$wgArticlePath " . "is correct."; } else { $message .= "Your web server was detected as possibly not " . "supporting URL path components (PATH_INFO) correctly; " . "check your LocalSettings.php for a customized " . "\$wgArticlePath setting and/or toggle \$wgUsePathInfo " . "to true."; } wfHttpError(500, "Internal error", $message); return false; } else { $output->setSquidMaxage(1200); $output->redirect($targetUrl, '301'); } } else { if (NS_SPECIAL == $title->getNamespace()) { /* actions that need to be made when we have a special pages */ SpecialPage::executePath($title); } else { /* No match to special cases */ wfProfileOut('MediaWiki::initializeSpecialCases'); return false; } } } } } /* Did match a special case */ wfProfileOut('MediaWiki::initializeSpecialCases'); return true; }