Пример #1
0
 function provideSearchOptionsTests()
 {
     $defaultNS = SearchEngine::defaultNamespaces();
     $EMPTY_REQUEST = array();
     $NO_USER_PREF = null;
     return array(array($EMPTY_REQUEST, $NO_USER_PREF, 'default', $defaultNS, 'Bug 33270: No request nor user preferences should give default profile'), array(array('ns5' => 1), $NO_USER_PREF, 'advanced', array(5), 'Web request with specific NS should override user preference'), array($EMPTY_REQUEST, array('searchNs2' => 1, 'searchNs14' => 1), 'advanced', array(2, 14), 'Bug 33583: search with no option should honor User search preferences'));
 }
/**
 * @return string
 */
function efOpenSearchXmlTemplate() {
	global $wgCanonicalServer, $wgScriptPath;
	$ns = implode( '|', SearchEngine::defaultNamespaces() );
	if( !$ns ) {
		$ns = '0';
	}
	return $wgCanonicalServer . $wgScriptPath . '/api.php?action=opensearch&format=xml&search={searchTerms}&namespace=' . $ns;
}
Пример #3
0
 public static function provideSearchOptionsTests()
 {
     $defaultNS = SearchEngine::defaultNamespaces();
     $EMPTY_REQUEST = array();
     $NO_USER_PREF = null;
     return array(array($EMPTY_REQUEST, $NO_USER_PREF, 'default', $defaultNS, 'Bug 33270: No request nor user preferences should give default profile'), array(array('ns5' => 1), $NO_USER_PREF, 'advanced', array(5), 'Web request with specific NS should override user preference'), array($EMPTY_REQUEST, array('searchNs2' => 1, 'searchNs14' => 1) + array_fill_keys(array_map(function ($ns) {
         return "searchNs{$ns}";
     }, $defaultNS), 0), 'advanced', array(2, 14), 'Bug 33583: search with no option should honor User search preferences' . ' and have all other namespace disabled'));
 }
Пример #4
0
 protected function getNamespaceFromRequest()
 {
     $user = $this->wg->User;
     $searchableNamespaces = SearchEngine::searchableNamespaces();
     $namespaces = array();
     foreach ($searchableNamespaces as $i => $name) {
         if ($this->getVal('ns' . $i, false)) {
             $namespaces[] = $i;
         }
     }
     if (empty($namespaces)) {
         if ($user->getGlobalPreference('searchAllNamespaces')) {
             $namespaces = array_keys($searchableNamespaces);
         } else {
             // this is mostly needed for unit testing
             $defaultProfile = !empty($this->wg->DefaultSearchProfile) ? $this->wg->DefaultSearchProfile : 'default';
             switch ($defaultProfile) {
                 case SEARCH_PROFILE_ADVANCED:
                     //There is no Config::setQuery call so it will always return default...
                 //There is no Config::setQuery call so it will always return default...
                 case SEARCH_PROFILE_DEFAULT:
                     $namespaces = \SearchEngine::defaultNamespaces();
                     break;
                 case SEARCH_PROFILE_IMAGES:
                     $namespaces = array(NS_FILE);
                     break;
                 case SEARCH_PROFILE_USERS:
                     $namespaces = array(NS_USER);
                     break;
                 case SEARCH_PROFILE_ALL:
                     $namespaces = \SearchEngine::searchableNamespaces();
                     break;
             }
         }
     }
     return $namespaces;
 }
Пример #5
0
	/**
	 * @return array
	 */
	protected function getSearchProfiles() {
		// Builds list of Search Types (profiles)
		$nsAllSet = array_keys( SearchEngine::searchableNamespaces() );

		$profiles = array(
			'default' => array(
				'message' => 'searchprofile-articles',
				'tooltip' => 'searchprofile-articles-tooltip',
				'namespaces' => SearchEngine::defaultNamespaces(),
				'namespace-messages' => SearchEngine::namespacesAsText(
					SearchEngine::defaultNamespaces()
				),
			),
			'images' => array(
				'message' => 'searchprofile-images',
				'tooltip' => 'searchprofile-images-tooltip',
				'namespaces' => array( NS_FILE ),
			),
			'help' => array(
				'message' => 'searchprofile-project',
				'tooltip' => 'searchprofile-project-tooltip',
				'namespaces' => SearchEngine::helpNamespaces(),
				'namespace-messages' => SearchEngine::namespacesAsText(
					SearchEngine::helpNamespaces()
				),
			),
			'all' => array(
				'message' => 'searchprofile-everything',
				'tooltip' => 'searchprofile-everything-tooltip',
				'namespaces' => $nsAllSet,
			),
			'advanced' => array(
				'message' => 'searchprofile-advanced',
				'tooltip' => 'searchprofile-advanced-tooltip',
				'namespaces' => self::NAMESPACES_CURRENT,
			)
		);

		wfRunHooks( 'SpecialSearchProfiles', array( &$profiles ) );

		foreach ( $profiles as &$data ) {
			if ( !is_array( $data['namespaces'] ) ) {
				continue;
			}
			sort( $data['namespaces'] );
		}

		return $profiles;
	}
 protected function getSearchProfiles()
 {
     // Builds list of Search Types (profiles)
     $nsAllSet = array_keys(SearchEngine::searchableNamespaces());
     $profiles = array('default' => array('message' => 'searchprofile-articles', 'tooltip' => 'searchprofile-articles-tooltip', 'namespaces' => SearchEngine::defaultNamespaces(), 'namespace-messages' => SearchEngine::namespacesAsText(SearchEngine::defaultNamespaces())), 'images' => array('message' => 'searchprofile-images', 'tooltip' => 'searchprofile-images-tooltip', 'namespaces' => array(NS_FILE)), 'help' => array('message' => 'searchprofile-project', 'tooltip' => 'searchprofile-project-tooltip', 'namespaces' => SearchEngine::helpNamespaces(), 'namespace-messages' => SearchEngine::namespacesAsText(SearchEngine::helpNamespaces())), 'all' => array('message' => 'searchprofile-everything', 'tooltip' => 'searchprofile-everything-tooltip', 'namespaces' => $nsAllSet), 'advanced' => array('message' => 'searchprofile-advanced', 'tooltip' => 'searchprofile-advanced-tooltip', 'namespaces' => $this->namespaces, 'parameters' => array('advanced' => 1)));
     wfRunHooks('SpecialSearchProfiles', array(&$profiles));
     foreach ($profiles as $key => &$data) {
         sort($data['namespaces']);
     }
     return $profiles;
 }
Пример #7
0
 /**
  * Get OpenSearch suggestion template
  *
  * @return String
  */
 public static function getOpenSearchTemplate()
 {
     global $wgOpenSearchTemplate, $wgCanonicalServer;
     if ($wgOpenSearchTemplate) {
         return $wgOpenSearchTemplate;
     } else {
         $ns = implode('|', SearchEngine::defaultNamespaces());
         if (!$ns) {
             $ns = "0";
         }
         return $wgCanonicalServer . wfScript('api') . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
     }
 }
Пример #8
0
 /**
  * Get OpenSearch suggestion template
  * 
  * @return String
  */
 public static function getOpenSearchTemplate()
 {
     global $wgOpenSearchTemplate, $wgServer, $wgScriptPath;
     if ($wgOpenSearchTemplate) {
         return $wgOpenSearchTemplate;
     } else {
         $ns = implode('|', SearchEngine::defaultNamespaces());
         if (!$ns) {
             $ns = "0";
         }
         return $wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}&namespace=' . $ns;
     }
 }
Пример #9
0
 /**
  * Fetch the template for a type.
  *
  * @param string $type MIME type
  * @return string
  * @throws MWException
  */
 public static function getOpenSearchTemplate($type)
 {
     global $wgOpenSearchTemplate, $wgCanonicalServer;
     if ($wgOpenSearchTemplate && $type === 'application/x-suggestions+json') {
         return $wgOpenSearchTemplate;
     }
     $ns = implode('|', SearchEngine::defaultNamespaces());
     if (!$ns) {
         $ns = "0";
     }
     switch ($type) {
         case 'application/x-suggestions+json':
             return $wgCanonicalServer . wfScript('api') . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
         case 'application/x-suggestions+xml':
             return $wgCanonicalServer . wfScript('api') . '?action=opensearch&format=xml&search={searchTerms}&namespace=' . $ns;
         default:
             throw new MWException(__METHOD__ . ": Unknown type '{$type}'");
     }
 }
Пример #10
0
 /**
  * Returns default namespaces from mediawiki.
  * @return array
  */
 public function getDefaultNamespacesFromSearchEngine()
 {
     return \SearchEngine::defaultNamespaces();
 }
Пример #11
0
 protected function formHeader($term)
 {
     global $wgContLang, $wgCanonicalNamespaceNames;
     $sep = '   ';
     $out = Xml::openElement('div', array('style' => 'padding-bottom:0.5em;'));
     $bareterm = $term;
     if ($this->startsWithImage($term)) {
         $bareterm = substr($term, strpos($term, ':') + 1);
     }
     // delete all/image prefix
     $nsAllSet = array_keys(SearchEngine::searchableNamespaces());
     // search profiles headers
     $m = wfMsg('searchprofile-articles');
     $tt = wfMsg('searchprofile-articles-tooltip', implode(', ', SearchEngine::namespacesAsText(SearchEngine::defaultNamespaces())));
     if ($this->active == 'default') {
         $out .= Xml::element('strong', array('title' => $tt), $m);
     } else {
         $out .= $this->makeSearchLink($bareterm, SearchEngine::defaultNamespaces(), $m, $tt);
     }
     $out .= $sep;
     $m = wfMsg('searchprofile-images');
     $tt = wfMsg('searchprofile-images-tooltip');
     if ($this->active == 'images') {
         $out .= Xml::element('strong', array('title' => $tt), $m);
     } else {
         $imageTextForm = $wgContLang->getFormattedNsText(NS_FILE) . ':' . $bareterm;
         $out .= $this->makeSearchLink($imageTextForm, array(NS_FILE), $m, $tt);
     }
     $out .= $sep;
     /*
     $m = wfMsg( 'searchprofile-articles-and-proj' );
     $tt = wfMsg( 'searchprofile-project-tooltip', 
     	implode( ', ', SearchEngine::namespacesAsText( SearchEngine::defaultAndProjectNamespaces() ) ) );
     if( $this->active == 'withproject' ) {
     	$out .= Xml::element( 'strong', array( 'title'=>$tt ), $m );	
     } else {
     	$out .= $this->makeSearchLink( $bareterm, SearchEngine::defaultAndProjectNamespaces(), $m, $tt );
     }
     $out .= $sep;
     */
     $m = wfMsg('searchprofile-project');
     $tt = wfMsg('searchprofile-project-tooltip', implode(', ', SearchEngine::namespacesAsText(SearchEngine::projectNamespaces())));
     if ($this->active == 'project') {
         $out .= Xml::element('strong', array('title' => $tt), $m);
     } else {
         $out .= $this->makeSearchLink($bareterm, SearchEngine::projectNamespaces(), $m, $tt);
     }
     $out .= $sep;
     $m = wfMsg('searchprofile-everything');
     $tt = wfMsg('searchprofile-everything-tooltip');
     if ($this->active == 'all') {
         $out .= Xml::element('strong', array('title' => $tt), $m);
     } else {
         $out .= $this->makeSearchLink($bareterm, $nsAllSet, $m, $tt);
     }
     $out .= $sep;
     $m = wfMsg('searchprofile-advanced');
     $tt = wfMsg('searchprofile-advanced-tooltip');
     if ($this->active == 'advanced') {
         $out .= Xml::element('strong', array('title' => $tt), $m);
     } else {
         $out .= $this->makeSearchLink($bareterm, $this->namespaces, $m, $tt, array('advanced' => '1'));
     }
     $out .= Xml::closeElement('div');
     return $out;
 }
Пример #12
0
 /**
  * These search profiles are used to figure out what tab we're on and how we should be searching based on that
  * While kind of a view concern, moved here so it can play nicely with the namespaces value
  * @return array
  */
 public function getSearchProfiles()
 {
     // Builds list of Search Types (profiles)
     $searchEngine = F::build('SearchEngine');
     $nsAllSet = array_keys($searchEngine->searchableNamespaces());
     $profiles = array('default' => array('message' => 'wikiasearch2-tabs-articles', 'tooltip' => 'searchprofile-articles-tooltip', 'namespaces' => SearchEngine::defaultNamespaces(), 'namespace-messages' => SearchEngine::namespacesAsText(SearchEngine::defaultNamespaces())), 'images' => array('message' => 'wikiasearch2-tabs-photos-and-videos', 'tooltip' => 'searchprofile-images-tooltip', 'namespaces' => array(NS_FILE)), 'users' => array('message' => 'wikiasearch2-users', 'tooltip' => 'wikiasearch2-users-tooltip', 'namespaces' => array(NS_USER)), 'all' => array('message' => 'searchprofile-everything', 'tooltip' => 'searchprofile-everything-tooltip', 'namespaces' => $nsAllSet), 'advanced' => array('message' => 'searchprofile-advanced', 'tooltip' => 'searchprofile-advanced-tooltip', 'namespaces' => $this->getNamespaces(), 'parameters' => array('advanced' => 1)));
     wfRunHooks('SpecialSearchProfiles', array(&$profiles));
     foreach ($profiles as $key => &$data) {
         sort($data['namespaces']);
     }
     return $profiles;
 }
Пример #13
0
 /**
  * @group Slow
  * @slowExecutionTime 0.08666 ms
  * @covers Wikia\Search\MediaWikiService::getDefaultNamespacesFromSearchEngine
  */
 public function testGetDefaultNamespacesFromSearchEngine()
 {
     $this->assertEquals(\SearchEngine::defaultNamespaces(), (new MediaWikiService())->getDefaultNamespacesFromSearchEngine());
 }