/** * Entry point * * @param string $par (default '') */ function wfSpecialSearch($par = '') { global $wgRequest, $wgUser; $search = $wgRequest->getText('search', $par); $searchPage = new SpecialSearch($wgRequest, $wgUser); if ($wgRequest->getVal('fulltext') || !is_null($wgRequest->getVal('offset')) || !is_null($wgRequest->getVal('searchx'))) { $searchPage->showResults($search); } else { $searchPage->goResult($search); } }
/** * Verify we do not expand search term in <title> on search result page * https://gerrit.wikimedia.org/r/4841 */ function testSearchTermIsNotExpanded() { # Initialize [[Special::Search]] $search = new SpecialSearch(); $search->getContext()->setTitle(Title::newFromText('Special:Search')); $search->load(); # Simulate a user searching for a given term $term = '{{SITENAME}}'; $search->showResults($term); # Lookup the HTML page title set for that page $pageTitle = $search->getContext()->getOutput()->getHTMLTitle(); # Compare :-] $this->assertRegExp('/' . preg_quote($term) . '/', $pageTitle, "Search term '{$term}' should not be expanded in Special:Search <title>"); }
/** * Entry point * * @param $par String: (default '') */ function wfSpecialSearch($par = '') { global $wgRequest, $wgUser; // Strip underscores from title parameter; most of the time we'll want // text form here. But don't strip underscores from actual text params! $titleParam = str_replace('_', ' ', $par); // Fetch the search term $search = str_replace("\n", " ", $wgRequest->getText('search', $titleParam)); $searchPage = new SpecialSearch($wgRequest, $wgUser); if ($wgRequest->getVal('fulltext') || !is_null($wgRequest->getVal('offset')) || !is_null($wgRequest->getVal('searchx'))) { $searchPage->showResults($search); } else { $searchPage->goResult($search); } }
/** * Entry point * * @param $par String: (default '') */ function wfSpecialSearch($par = '') { global $wgRequest, $wgUser, $wgOut; if ($wgUser->isAnon()) { $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext'); return; } $search = $wgRequest->getText('search', $par); $searchPage = new SpecialSearch($wgRequest, $wgUser); if ($wgRequest->getVal('fulltext') || !is_null($wgRequest->getVal('offset')) || !is_null($wgRequest->getVal('searchx'))) { $searchPage->showResults($search); } else { $searchPage->goResult($search); } }
/** * @covers SpecialSearch::load * @dataProvider provideSearchOptionsTests * @param $requested Array Request parameters. For example array( 'ns5' => true, 'ns6' => true). NULL to use default options. * @param $userOptions Array User options to test with. For example array('searchNs5' => 1 );. NULL to use default options. * @param $expectedProfile An expected search profile name * @param $expectedNs Array Expected namespaces */ function testProfileAndNamespaceLoading($requested, $userOptions, $expectedProfile, $expectedNS, $message = 'Profile name and namespaces mismatches!') { $context = new RequestContext(); $context->setUser($this->newUserWithSearchNS($userOptions)); /* $context->setRequest( new FauxRequest( array( 'ns5'=>true, 'ns6'=>true, ) )); */ $context->setRequest(new FauxRequest($requested)); $search = new SpecialSearch(); $search->setContext($context); $search->load(); /** * Verify profile name and namespace in the same assertion to make * sure we will be able to fully compare the above code. PHPUnit stop * after an assertion fail. */ $this->assertEquals(array('ProfileName' => $expectedProfile, 'Namespaces' => $expectedNS), array('ProfileName' => $search->getProfile(), 'Namespaces' => $search->getNamespaces()), $message); }
/** * Hook: SpecialSearchProfileForm */ public static function searchProfileForm( SpecialSearch $search, &$form, /*string*/ $profile, $term, array $opts ) { if ( $profile !== 'translation' ) { return true; } if ( !$search->getSearchEngine()->supports( 'title-suffix-filter' ) ) { return false; } $hidden = ''; foreach ( $opts as $key => $value ) { $hidden .= Html::hidden( $key, $value ); } $context = $search->getContext(); $code = $context->getLanguage()->getCode(); $selected = $context->getRequest()->getVal( 'languagefilter' ); if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) { $languages = LanguageNames::getNames( $code, LanguageNames::FALLBACK_NORMAL, LanguageNames::LIST_MW ); } else { $languages = Language::getLanguageNames( false ); } ksort( $languages ); $selector = new XmlSelect( 'languagefilter', 'languagefilter' ); $selector->setDefault( $selected ); $selector->addOption( wfMessage( 'translate-search-nofilter' )->text(), '-' ); foreach ( $languages as $code => $name ) { $selector->addOption( "$code - $name", $code ); } $selector = $selector->getHTML(); $label = Xml::label( wfMessage( 'translate-search-languagefilter' )->text(), 'languagefilter' ) . ' '; $params = array( 'id' => 'mw-searchoptions' ); $form = Xml::fieldset( false, false, $params ) . $hidden . $label . $selector . Html::closeElement( 'fieldset' ); return false; }
public static function searchProfileSetupEngine(SpecialSearch $search, $profile, SearchEngine $engine) { if ($profile !== 'translation') { return true; } $context = $search->getContext(); $selected = $context->getRequest()->getVal('languagefilter'); if ($selected !== '-' && $selected) { $engine->setFeatureData('title-suffix-filter', "/{$selected}"); $search->setExtraParam('languagefilter', $selected); } return true; }