From: Aaron Schulz Date: Wed, 19 Nov 2008 08:35:04 +0000 (+0000) Subject: * Checkbox fix X-Git-Tag: 1.31.0-rc.0~44268 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=fb2959284488d0e684073f010deb778a7a754214;p=lhc%2Fweb%2Fwiklou.git * Checkbox fix * Remove unused var * Add $this->sk field * Tweak code style * Adding missing wfProfileOut( __METHOD__ ); --- diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 808ec35b18..4a8503dc57 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -30,11 +30,10 @@ */ function wfSpecialSearch( $par = '' ) { global $wgRequest, $wgUser, $wgUseOldSearchUI; - // 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 ) ); $class = $wgUseOldSearchUI ? 'SpecialSearchOld' : 'SpecialSearch'; $searchPage = new $class( $wgRequest, $wgUser ); @@ -64,44 +63,40 @@ class SpecialSearch { */ function __construct( &$request, &$user ) { list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' ); - + # Extract requested namespaces $this->namespaces = $this->powerSearch( $request ); if( empty( $this->namespaces ) ) { $this->namespaces = SearchEngine::userNamespaces( $user ); } - $this->searchRedirects = $request->getcheck( 'redirs' ) ? true : false; - $this->searchAdvanced = $request->getVal('advanced'); + $this->searchAdvanced = $request->getVal( 'advanced' ); + $this->active = 'advanced'; + $this->sk = $user->getSkin(); } /** * If an exact title match can be found, jump straight ahead to it. * @param string $term - * @public */ - function goResult( $term ) { - global $wgOut, $wgGoToEdit; - + public function goResult( $term ) { + global $wgOut; $this->setupPage( $term ); - # Try to go to page as entered. $t = Title::newFromText( $term ); - # If the string cannot be used to create a title if( is_null( $t ) ) { return $this->showResults( $term ); } - # If there's an exact or very near match, jump right there. $t = SearchEngine::getNearMatch( $term ); if( !is_null( $t ) ) { $wgOut->redirect( $t->getFullURL() ); return; } - # No match, generate an edit URL $t = Title::newFromText( $term ); - if( ! is_null( $t ) ) { + if( !is_null( $t ) ) { + global $wgGoToEdit; wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) ); # If the feature is enabled, go straight to the edit page if( $wgGoToEdit ) { @@ -109,18 +104,15 @@ class SpecialSearch { return; } } - return $this->showResults( $term ); } /** * @param string $term - * @public */ - function showResults( $term ) { + public function showResults( $term ) { + global $wgOut, $wgDisableTextSearch; wfProfileIn( __METHOD__ ); - global $wgOut, $wgUser; - $sk = $wgUser->getSkin(); $this->setupPage( $term ); $this->searchEngine = SearchEngine::create(); @@ -130,16 +122,8 @@ class SpecialSearch { $wgOut->addHtml( Xml::openElement( 'table', array( 'border'=>0, 'cellpadding'=>0, 'cellspacing'=>0 ) ) . Xml::openElement( 'tr' ) . - Xml::openElement( 'td' ) . "\n" - ); - if( $this->searchAdvanced ) { - $wgOut->addHTML( $this->powerSearchBox( $term ) ); - $showMenu = false; - } else { - $wgOut->addHTML( $this->shortDialog( $term ) ); - $showMenu = true; - } - $wgOut->addHtml( + Xml::openElement( 'td' ) . "\n" . + ( $this->searchAdvanced ? $this->powerSearchBox( $term ) : $this->shortDialog( $term ) ) . Xml::closeElement('td') . Xml::closeElement('tr') . Xml::closeElement('table') @@ -151,12 +135,12 @@ class SpecialSearch { return; } - global $wgDisableTextSearch; if( $wgDisableTextSearch ) { global $wgSearchForwardUrl; if( $wgSearchForwardUrl ) { $url = str_replace( '$1', urlencode( $term ), $wgSearchForwardUrl ); $wgOut->redirect( $url ); + wfProfileOut( __METHOD__ ); return; } global $wgInputEncoding; @@ -189,9 +173,9 @@ class SpecialSearch { wfProfileOut( __METHOD__ ); return; } - + $textMatches = $search->searchText( $rewritten ); - + // did you mean... suggestions if( $textMatches && $textMatches->hasSuggestion() ) { $st = SpecialPage::getTitleFor( 'Search' ); @@ -204,7 +188,7 @@ class SpecialSearch { $wgOut->addHTML('
'.wfMsg('search-suggest',$suggestLink).'
'); } - + // show direct page/create link if( !is_null($t) ) { if( !$t->exists() ) { @@ -213,7 +197,7 @@ class SpecialSearch { $wgOut->addWikiMsg( 'searchmenu-exists', wfEscapeWikiText( $t->getPrefixedText() ) ); } } - + // show number of results $numTitleMatches = $titleMatches ? $titleMatches->numRows() : 0; $numTextMatches = $textMatches ? $textMatches->numRows() : 0; @@ -252,7 +236,6 @@ class SpecialSearch { } $wgOut->addHtml( "
" ); - if( $titleMatches ) { if( $numTitleMatches > 0 ) { $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' ); @@ -260,7 +243,6 @@ class SpecialSearch { } $titleMatches->free(); } - if( $textMatches ) { // output appropriate heading if( $numTextMatches > 0 && $numTitleMatches > 0 ) { @@ -279,11 +261,9 @@ class SpecialSearch { $textMatches->free(); } - - if( $num == 0 ) { + if( $totalNum == 0 ) { $wgOut->addWikiMsg( 'search-nonefound' ); } - $wgOut->addHtml( "
" ); if( $num || $this->offset ) { @@ -297,9 +277,27 @@ class SpecialSearch { */ protected function setupPage( $term ) { global $wgOut; + // Figure out the active search profile header + $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); + if( $this->searchAdvanced ) + $this->active = 'advanced'; + else if( $this->namespaces === NS_IMAGE || $this->startsWithImage( $term ) ) + $this->active = 'images'; + elseif( $this->namespaces === $nsAllSet ) + $this->active = 'all'; + elseif( $this->namespaces === SearchEngine::defaultNamespaces() ) + $this->active = 'default'; + elseif( $this->namespaces === SearchEngine::defaultAndProjectNamespaces() ) + $this->active = 'withproject'; + elseif( $this->namespaces === SearchEngine::projectNamespaces() ) + $this->active = 'project'; + else + $this->active = 'advanced'; + # Should advanced UI be used? + $this->searchAdvanced = ($this->active === 'advanced'); if( !empty( $term ) ) { $wgOut->setPageTitle( wfMsg( 'searchresults') ); - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term) ) ); + $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) ); } $wgOut->setArticleRelated( false ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); @@ -332,8 +330,9 @@ class SpecialSearch { $opt['ns' . $n] = 1; } $opt['redirs'] = $this->searchRedirects ? 1 : 0; - if( $this->searchAdvanced ) + if( $this->searchAdvanced ) { $opt['advanced'] = $this->searchAdvanced; + } return $opt; } @@ -349,12 +348,10 @@ class SpecialSearch { $terms = $wgContLang->convertForSearchResult( $matches->termMatches() ); $out = ""; - $infoLine = $matches->getInfo(); - if( !is_null($infoLine) ) + if( !is_null($infoLine) ) { $out .= "\n\n"; - - + } $off = $this->offset + 1; $out .= "\n"; // convert the whole thing to desired language variant - global $wgContLang; $out = $wgContLang->convert( $out ); wfProfileOut( __METHOD__ ); return $out; @@ -542,7 +533,7 @@ class SpecialSearch { */ protected function showInterwikiHit( $result, $lastInterwiki, $terms, $query, $customCaptions) { wfProfileIn( __METHOD__ ); - global $wgUser, $wgContLang, $wgLang; + global $wgContLang, $wgLang; if( $result->isBrokenTitle() ) { wfProfileOut( __METHOD__ ); @@ -550,17 +541,16 @@ class SpecialSearch { } $t = $result->getTitle(); - $sk = $wgUser->getSkin(); - - $link = $sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms)); - + + $link = $this->sk->makeKnownLinkObj( $t, $result->getTitleSnippet($terms)); + // format redirect if any $redirectTitle = $result->getRedirectTitle(); $redirectText = $result->getRedirectSnippet($terms); $redirect = ''; if( !is_null($redirectTitle) ) $redirect = "" - .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText)) + .wfMsg('search-redirect',$this->sk->makeKnownLinkObj( $redirectTitle, $redirectText)) .""; $out = ""; @@ -577,7 +567,7 @@ class SpecialSearch { } // "more results" link (special page stuff could be localized, but we might not know target lang) $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search"); - $searchLink = $sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'), + $searchLink = $this->sk->makeKnownLinkObj( $searchTitle, wfMsg('search-interwiki-more'), wfArrayToCGI(array('search' => $query, 'fulltext' => 'Search'))); $out .= "
{$searchLink}{$caption}
\n