X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialSearch.php;h=64394b688879f64f231bb099204ce0951dd2cfeb;hb=90c703d61c485c633b214f78f48102c2848b82d8;hp=4b565e8196cfc2479a79acfe177e98352f384692;hpb=ef666357bd918cc05ce1af95442cf662f30a68d5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 4b565e8196..64394b6888 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -1,56 +1,68 @@ -# http://www.mediawiki.org/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# http://www.gnu.org/copyleft/gpl.html - /** - * Run text & title search and display the output + * Implements Special:Search + * + * Copyright © 2004 Brion Vibber + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup SpecialPage */ -/** - * 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 ); - } -} - /** * implements Special:Search - Run text & title search and display the output * @ingroup SpecialPage */ -class SpecialSearch { +class SpecialSearch extends SpecialPage { + + public function __construct() { + parent::__construct( 'Search' ); + } + + /** + * Entry point + * + * @param $par String or null + */ + public function execute( $par ) { + global $wgRequest, $wgUser, $wgOut; + + $this->setHeaders(); + $this->outputHeader(); + $wgOut->allowClickjacking(); + + // 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 ) ); + + $this->load( $wgRequest, $wgUser ); + + if ( $wgRequest->getVal( 'fulltext' ) + || !is_null( $wgRequest->getVal( 'offset' ) ) + || !is_null( $wgRequest->getVal( 'searchx' ) ) ) + { + $this->showResults( $search ); + } else { + $this->goResult( $search ); + } + } /** * Set up basic search parameters from the request and user settings. @@ -59,7 +71,7 @@ class SpecialSearch { * @param $request WebRequest * @param $user User */ - public function __construct( &$request, &$user ) { + public function load( &$request, &$user ) { list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' ); $this->mPrefix = $request->getVal('prefix', ''); # Extract requested namespaces @@ -67,7 +79,7 @@ class SpecialSearch { if( empty( $this->namespaces ) ) { $this->namespaces = SearchEngine::userNamespaces( $user ); } - $this->searchRedirects = $request->getcheck( 'redirs' ) ? true : false; + $this->searchRedirects = $request->getCheck( 'redirs' ); $this->searchAdvanced = $request->getVal( 'advanced' ); $this->active = 'advanced'; $this->sk = $user->getSkin(); @@ -91,8 +103,13 @@ class SpecialSearch { } # If there's an exact or very near match, jump right there. $t = SearchEngine::getNearMatch( $term ); + + if ( !wfRunHooks( 'SpecialSearchGo', array( &$t, &$term ) ) ) { + # Hook requested termination + return; + } + if( !is_null( $t ) ) { - wfRunHooks( 'SpecialSearchGomatch', array( &$t ) ); $wgOut->redirect( $t->getFullURL() ); return; } @@ -221,7 +238,6 @@ class SpecialSearch { $filePrefix = $wgContLang->getFormattedNsText(NS_FILE).':'; if( trim( $term ) === '' || $filePrefix === trim( $term ) ) { - $wgOut->addHTML( $this->searchFocus() ); $wgOut->addHTML( $this->formHeader($term, 0, 0)); if( $this->searchAdvanced ) { $wgOut->addHTML( $this->powerSearchBox( $term ) ); @@ -275,6 +291,7 @@ class SpecialSearch { wfRunHooks( 'SpecialSearchNoResults', array( $term ) ); } + $wgOut->parserOptions()->setEditSection( false ); if( $titleMatches ) { if( $numTitleMatches > 0 ) { $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' ); @@ -303,13 +320,10 @@ class SpecialSearch { $textMatches->free(); } if( $num === 0 ) { - $wgOut->addWikiMsg( 'search-nonefound', wfEscapeWikiText( $term ) ); + $wgOut->wrapWikiMsg( "

\n$1

", array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); $this->showCreateLink( $t ); } $wgOut->addHtml( "" ); - if( $num === 0 ) { - $wgOut->addHTML( $this->searchFocus() ); - } if( $num || $this->offset ) { $wgOut->addHTML( "

{$prevnext}

\n" ); @@ -327,10 +341,12 @@ class SpecialSearch { $messageName = 'searchmenu-exists'; } elseif( $t->userCan( 'create' ) ) { $messageName = 'searchmenu-new'; + } else { + $messageName = 'searchmenu-new-nocreate'; } } if( $messageName ) { - $wgOut->addWikiMsg( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ); + $wgOut->wrapWikiMsg( "

\n$1

", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) ); } else { // preserve the paragraph for margins etc... $wgOut->addHtml( '

' ); @@ -343,10 +359,9 @@ class SpecialSearch { protected function setupPage( $term ) { global $wgOut; // Figure out the active search profile header - $nsAllSet = array_keys( SearchEngine::searchableNamespaces() ); - if( $this->searchAdvanced ) + if( $this->searchAdvanced ) { $this->active = 'advanced'; - else { + } else { $profiles = $this->getSearchProfiles(); foreach( $profiles as $key => $data ) { @@ -361,10 +376,9 @@ class SpecialSearch { $wgOut->setPageTitle( wfMsg( 'searchresults') ); $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $term ) ) ); } - $wgOut->setArticleRelated( false ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); // add javascript specific to special:search - $wgOut->addScriptFile( 'search.js' ); + $wgOut->addModules( 'mediawiki.legacy.search' ); + $wgOut->addModules( 'mediawiki.special.search' ); } /** @@ -417,7 +431,6 @@ class SpecialSearch { if( !is_null($infoLine) ) { $out .= "\n\n"; } - $off = $this->offset + 1; $out .= "