Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
    /**
     * Special:LSearch page entry point
     */
    public function execute($par = '')
    {
        global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgServer;
        global $wgLanguageCode, $wgUseLucene, $IP, $wgHooks;
        // Added this hack to test whether we can stop some usertype:logged(in|out)
        // queries can be removed from index. Remove this code eventually, say 6 mos.
        // from now. Added by Reuben originally on July 30, 2012.
        $queryString = @$_SERVER['REQUEST_URI'];
        if (strpos($queryString, 'usertype') !== false) {
            header('HTTP/1.0 404 Not Found');
            print "Page not found";
            exit;
        }
        $wgHooks['ShowBreadCrumbs'][] = array($this, 'removeBreadCrumbsCallback');
        $wgHooks['WrapBodyWithArticleInner'][] = array($this, 'wrapBodyWithArticleInner');
        $this->mStart = $wgRequest->getVal('start', 0);
        $this->mQ = $wgRequest->getVal('search');
        // special case search term filtering
        if (strtolower($this->mQ) == 'sat') {
            // searching for SAT, not sitting
            $this->mQ = "\"SAT\"";
        }
        $enc_q = htmlspecialchars($this->mQ);
        $wgOut->setRobotPolicy('noindex,nofollow');
        // Logged out search test
        if ($wgRequest->getVal('lo', 0)) {
            $wgHooks['ShowSideBar'][] = array($this, 'removeSideBarCallback');
            // We want to cache results of searches for 6 hours at the Varnish level
            // since logged out search receives a high volume of queries
            $wgHooks['AllowMaxageHeaders'][] = array($this, 'allowMaxageHeadersCallback');
            $this->setMaxageHeaders();
            $this->loggedOutSearch();
            $wgOut->setHTMLTitle(wfMsg('lsearch_title_q', $enc_q));
            $wgOut->addStyle(wfGetPad('/extensions/min/?f=/skins/owl/searchresults.css&' . WH_SITEREV));
            $wgOut->addHtml($this->getLoggedOutSearchHtml());
            return;
        }
        if ($wgLanguageCode != 'en' || !$wgUseLucene) {
            require_once "{$IP}/includes/SpecialSearch.php";
            wfSpecialSearch();
            return;
        }
        if ($wgRequest->getVal('rss') == 1) {
            $results = $this->googleSearchResultTitles($wgRequest->getVal('search'), $this->mStart, self::RESULTS_PER_PAGE, 0, self::SEARCH_RSS);
            $wgOut->disable();
            $pad = "           ";
            header("Content-type: text/xml;");
            echo '<GSP VER="3.2">
<TM>0.083190</TM>
<Q>' . htmlspecialchars($q) . '</Q>
<PARAM name="filter" value="0" original_value="0"/>
<PARAM name="num" value="16" original_value="30"/>
<PARAM name="access" value="p" original_value="p"/>
<PARAM name="entqr" value="0" original_value="0"/>
<PARAM name="start" value="0" original_value="0"/>
<PARAM name="output" value="xml" original_value="xml"/>
<PARAM name="sort" value="date:D:L:d1" original_value="date%3AD%3AL%3Ad1"/>
<PARAM name="site" value="main_en" original_value="main_en"/>
<PARAM name="ie" value="UTF-8" original_value="UTF-8"/>
<PARAM name="client" value="internal_frontend" original_value="internal_frontend"/>
<PARAM name="q" value="' . htmlspecialchars($q) . '" original_value="' . htmlspecialchars($q) . '"/>
<PARAM name="ip" value="192.168.100.100" original_value="192.168.100.100"/>
<RES SN="1" EN="' . sizeof($results) . '">
<M>' . sizeof($results) . '</M>
<XT/>';
            $count = 1;
            foreach ($results as $r) {
                echo "<R N=\"{$count}\">\n\t\t\t\t\t<U>{$r->getFullURL()}</U>\n\t\t\t\t\t<UE>{$r->getFullURL()}</UE>\n\t\t\t\t\t<T>How to " . htmlspecialchars($r->getFullText()) . "{$pad}</T>\n\t\t\t\t\t<RK>10</RK>\n\t\t\t\t\t<HAS></HAS>\n\t\t\t\t\t<LANG>en</LANG>\n\t\t\t</R>";
                $count++;
            }
            echo "</RES>\n</GSP>";
            return;
        }
        //show the gray article image at the bottom
        if (class_exists('WikihowCSSDisplay')) {
            WikihowCSSDisplay::setSpecialBackground(true);
        }
        $fname = "wfSpecialSearch";
        $me = Title::makeTitle(NS_SPECIAL, "LSearch");
        $sk = $wgUser->getSkin();
        if ($wgRequest->getVal('raw') == true) {
            $contents = $this->googleSearchResultTitles($this->mQ, $this->mStart, self::RESULTS_PER_PAGE, 0, self::SEARCH_RAW);
            header("Content-type: text/plain");
            $wgOut->disable(true);
            foreach ($contents as $t) {
                echo "{$t->getFullURL()}\n";
            }
            return;
        }
        if ($wgRequest->getVal('mobile') == true) {
            $this->mobileSearch($this->mQ, $this->mStart, $wgRequest->getVal('limit', 20));
            return;
        }
        // Logged in search is only for logged in users
        /*if ($wgUser->isAnon()) {
        			$wgOut->setRobotpolicy('noindex,nofollow');
        			$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
        			return;
        		}*/
        $contents = $this->googleSearchResults($this->mQ, $this->mStart, self::RESULTS_PER_PAGE, self::SEARCH_LOGGED_IN);
        if ($contents == null) {
            return;
        }
        wfLoadExtensionMessages('LSearch');
        $wgOut->setHTMLTitle(wfMsg('lsearch_title_q', $enc_q));
        $me = Title::makeTitle(NS_SPECIAL, "LSearch");
        $sk = $wgUser->getSkin();
        $suggestionLink = $this->getSpellingSuggestion($me->getPartialUrl());
        $results = $this->mResults['results'] ? $this->mResults['results'] : array();
        $results = $this->makeTitlesUniform($results);
        $results = $this->supplementResults($results);
        $mw = Title::makeTitle(NS_SPECIAL, "Search");
        $specialPageURL = $mw->getFullURL();
        $total = $this->mResults['totalresults'];
        $start = $this->mStart;
        $last = $this->mLast;
        $max_results = self::RESULTS_PER_PAGE;
        $q = $this->mQ;
        //buttons
        // - next
        $disabled = !($total > $start + $max_results && $last == $start + $max_results);
        $next_url = '/' . $me . '?search=' . urlencode($q) . '&start=' . ($start + $max_results);
        $next_button = '<a href="' . $next_url . '" class="button buttonright ' . ($disabled ? 'disabled' : '') . '" ' . ($disabled ? 'onClick="return false;"' : '') . '>' . wfMsg("lsearch_next") . '</a>';
        // - previous
        $disabled = !($start - $max_results >= 0);
        $prev_url = '/' . $me . '?search=' . urlencode($q) . ($start - $max_results !== 0 ? '&start=' . ($start - $max_results) : '');
        $prev_button = '<a href="' . $prev_url . '" class="button buttonleft ' . ($disabled ? 'disabled' : '') . '" ' . ($disabled ? 'onClick="return false;"' : '') . '>' . wfMsg("lsearch_previous") . '</a>';
        $vars = array('q' => $q, 'enc_q' => $enc_q, 'sk' => $sk, 'me' => $me, 'max_results' => $max_results, 'start' => $start, 'first' => $start + 1, 'last' => $last, 'suggestionLink' => $suggestionLink, 'results' => $results, 'specialPageURL' => $specialPageURL, 'total' => $total, 'BASE_URL' => $wgServer, 'next_button' => $next_button, 'prev_button' => $prev_button);
        EasyTemplate::set_path(dirname(__FILE__) . '/');
        $html = EasyTemplate::html('search-results.tmpl.php', $vars);
        $wgOut->addStyle(wfGetPad('/extensions/min/?f=/skins/owl/searchresults.css&' . WH_SITEREV));
        $wgOut->addHTML($html);
    }
Ejemplo n.º 3
0
    // Do this above the read whitelist check for security...
    $wgTitle = Title::makeTitle(NS_SPECIAL, 'Search');
}
# If the user is not logged in, the Namespace:title of the article must be in
# the Read array in order for the user to see it. (We have to check here to
# catch special pages etc. We check again in Article::view())
if (!is_null($wgTitle) && !$wgTitle->userCanRead()) {
    $wgOut->loginToUse();
    $wgOut->output();
    exit;
}
wfProfileIn('main-action');
if (!$wgDisableInternalSearch && !is_null($search) && $search !== '') {
    require_once 'includes/SpecialSearch.php';
    $wgTitle = Title::makeTitle(NS_SPECIAL, 'Search');
    wfSpecialSearch();
} else {
    if (!$wgTitle or $wgTitle->getDBkey() == '') {
        $wgTitle = Title::newFromText(wfMsgForContent('badtitle'));
        $wgOut->errorpage('badtitle', 'badtitletext');
    } else {
        if ($wgTitle->getInterwiki() != '') {
            if ($rdfrom = $wgRequest->getVal('rdfrom')) {
                $url = $wgTitle->getFullURL('rdfrom=' . urlencode($rdfrom));
            } else {
                $url = $wgTitle->getFullURL();
            }
            # Check for a redirect loop
            if (!preg_match('/^' . preg_quote($wgServer, '/') . '/', $url) && $wgTitle->isLocal()) {
                $wgOut->redirect($url);
            } else {
Ejemplo n.º 4
0
 /**
  * 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;
 }