Пример #1
0
/**
 * Called to display the Special:Search page
 *
 * @param unknown_type $par
 * @param unknown_type $specialPage
 */
function wfSpecialSearch($par = NULL, $specialPage)
{
    global $wgOut, $wgRequest, $wgScriptPath, $wrSidebarHtml;
    $searchForm = new SearchForm();
    // read query parameters into variables
    $searchForm->readQueryParms($par);
    // check if we should redirect to a specific page
    $redirTitle = $searchForm->getRedirTitle();
    if ($redirTitle) {
        $wgOut->redirect($redirTitle->getFullURL());
        return;
    }
    $wgOut->setPageTitle($searchForm->target ? 'Search for possible matches' : 'Search WeRelate');
    $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/search.31.js\"></script>");
    $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/autocomplete.10.js\"></script>");
    // construct query to send to server
    $errMsg = $searchForm->validateQuery();
    $searchServerQuery = '';
    if (!$errMsg) {
        $searchServerQuery = $searchForm->getSearchServerQuery($par);
    }
    $formHtml = $searchForm->getFormHtml();
    if ($searchServerQuery || $errMsg) {
        if ($errMsg) {
            $sideText = '';
            $errMsg = htmlspecialchars($errMsg);
            $results = "<p><font color=\"red\">{$errMsg}</font></p>";
        } else {
            list($sideText, $results) = $searchForm->getSearchResultsHtml($searchServerQuery);
        }
        $wrSidebarHtml = "<div id=\"wr-search-sidebar\">{$sideText}</div>";
        $wgOut->addHTML(<<<END
<p>{$formHtml}</p>
{$results}
END
);
    } else {
        $sideText = $searchForm->getStatsHtml();
        $endText = wfMsgWikiHtml('searchend');
        $wrSidebarHtml = "<div id=\"wr-search-sidebar\">{$sideText}</div>";
        $wgOut->addHTML(<<<END
<p>{$formHtml}</p><p> </p>
{$endText}
END
);
    }
}