EBernhardson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322013

Change subject: [WIP] Cleanup execution flow through SpecialSearch::execute()
......................................................................

[WIP] Cleanup execution flow through SpecialSearch::execute()

Not a big change, but makes it so there is only one path
into SpecialSearch::showResults(). Makes things a little
easier to follow. Also moves the code for checking if
full text search is disabled into execute(), makes sense
to check before even trying to make a search engine.

Change-Id: Ib527fc3a3c39eb2e56985e5d1e4905fc4562353c
---
M includes/specials/SpecialSearch.php
1 file changed, 71 insertions(+), 78 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/13/322013/1

diff --git a/includes/specials/SpecialSearch.php 
b/includes/specials/SpecialSearch.php
index 9994839..fe6a206 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -143,14 +143,44 @@
 
                $out->addJsConfigVars( [ 'searchTerm' => $search ] );
                $this->searchEngineType = $request->getVal( 'srbackend' );
-
-               if ( $request->getVal( 'fulltext' )
-                       || !is_null( $request->getVal( 'offset' ) )
+               if (
+                       !$request->getVal( 'fulltext' ) &&
+                       !is_null( $request->getVal( 'offset' ) ) &&
+                       $this->goResult( $search )
                ) {
-                       $this->showResults( $search );
-               } else {
-                       $this->goResult( $search );
+                       // succesfull 'go'
+                       return;
                }
+
+               $this->setupPage( $term );
+
+               if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
+                       $searchFowardUrl = $this->getConfig()->get( 
'SearchForwardUrl' );
+                       if ( $searchFowardUrl ) {
+                               $url = str_replace( '$1', urlencode( $term ), 
$searchFowardUrl );
+                               $out->redirect( $url );
+                       } else {
+                               $out->addHTML(
+                                       Xml::openElement( 'fieldset' ) .
+                                       Xml::element( 'legend', null, 
$this->msg( 'search-external' )->text() ) .
+                                       Xml::element(
+                                               'p',
+                                               [ 'class' => 
'mw-searchdisabled' ],
+                                               $this->msg( 'searchdisabled' 
)->text()
+                                       ) .
+                                       $this->msg( 'googlesearch' )->rawParams(
+                                               htmlspecialchars( $term ),
+                                               'UTF-8',
+                                               $this->msg( 'searchbutton' 
)->escaped()
+                                       )->text() .
+                                       Xml::closeElement( 'fieldset' )
+                               );
+                       }
+
+                       return;
+               }
+
+               $this->showResults( $search );
        }
 
        /**
@@ -211,30 +241,26 @@
         * @param string $term
         */
        public function goResult( $term ) {
-               $this->setupPage( $term );
-               # Try to go to page as entered.
-               $title = Title::newFromText( $term );
                # If the string cannot be used to create a title
-               if ( is_null( $title ) ) {
-                       $this->showResults( $term );
-
-                       return;
+               if ( is_null( Title::newFromText( $term ) ) ) {
+                       return false;
                }
                # If there's an exact or very near match, jump right there.
                $title = $this->getSearchEngine()
                        ->getNearMatcher( $this->getConfig() )->getNearMatch( 
$term );
-
-               if ( !is_null( $title ) &&
-                       Hooks::run( 'SpecialSearchGoResult', [ $term, $title, 
&$url ] )
-               ) {
-                       if ( $url === null ) {
-                               $url = $title->getFullURL();
-                       }
-                       $this->getOutput()->redirect( $url );
-
-                       return;
+               if ( is_null( $title ) ) {
+                       return false;
                }
-               $this->showResults( $term );
+               $url = null;
+               if ( !Hooks::run( 'SpecialSearchGoResult', [ $term, $title, 
&$url ] ) ) {
+                       return false;
+               }
+               if ( $url === null ) {
+                       $url = $title->getFullURL();
+               }
+               $this->getOutput()->redirect( $url );
+
+               return true;
        }
 
        /**
@@ -249,36 +275,11 @@
                $search->setNamespaces( $this->namespaces );
                $search->prefix = $this->mPrefix;
                $term = $search->transformSearchTerm( $term );
-
-               Hooks::run( 'SpecialSearchSetupEngine', [ $this, 
$this->profile, $search ] );
-
-               $this->setupPage( $term );
-
                $out = $this->getOutput();
 
-               if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
-                       $searchFowardUrl = $this->getConfig()->get( 
'SearchForwardUrl' );
-                       if ( $searchFowardUrl ) {
-                               $url = str_replace( '$1', urlencode( $term ), 
$searchFowardUrl );
-                               $out->redirect( $url );
-                       } else {
-                               $out->addHTML(
-                                       Xml::openElement( 'fieldset' ) .
-                                       Xml::element( 'legend', null, 
$this->msg( 'search-external' )->text() ) .
-                                       Xml::element(
-                                               'p',
-                                               [ 'class' => 
'mw-searchdisabled' ],
-                                               $this->msg( 'searchdisabled' 
)->text()
-                                       ) .
-                                       $this->msg( 'googlesearch' )->rawParams(
-                                               htmlspecialchars( $term ),
-                                               'UTF-8',
-                                               $this->msg( 'searchbutton' 
)->escaped()
-                                       )->text() .
-                                       Xml::closeElement( 'fieldset' )
-                               );
-                       }
-
+               Hooks::run( 'SpecialSearchSetupEngine', [ $this, 
$this->profile, $search ] );
+               if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, 
$term ] ) ) {
+                       # Hook requested termination
                        return;
                }
 
@@ -308,23 +309,6 @@
                        }
                }
 
-               if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, 
$term ] ) ) {
-                       # Hook requested termination
-                       return;
-               }
-
-               // start rendering the page
-               $out->addHTML(
-                       Xml::openElement(
-                               'form',
-                               [
-                                       'id' => ( $this->isPowerSearch() ? 
'powersearch' : 'search' ),
-                                       'method' => 'get',
-                                       'action' => wfScript(),
-                               ]
-                       )
-               );
-
                // Get number of results
                $titleMatchesNum = $textMatchesNum = $numTitleMatches = 
$numTextMatches = 0;
                if ( $titleMatches ) {
@@ -338,17 +322,26 @@
                $num = $titleMatchesNum + $textMatchesNum;
                $totalRes = $numTitleMatches + $numTextMatches;
 
+               // start rendering the page
                $out->enableOOUI();
                $out->addHTML(
-                       # This is an awful awful ID name. It's not a table, but 
we
-                       # named it poorly from when this was a table so now 
we're
-                       # stuck with it
-                       Xml::openElement( 'div', [ 'id' => 
'mw-search-top-table' ] ) .
-                       $this->shortDialog( $term, $num, $totalRes ) .
-                       Xml::closeElement( 'div' ) .
-                       $this->searchProfileTabs( $term ) .
-                       $this->searchOptions( $term ) .
-                       Xml::closeElement( 'form' ) .
+                       Xml::openElement(
+                               'form',
+                               [
+                                       'id' => ( $this->isPowerSearch() ? 
'powersearch' : 'search' ),
+                                       'method' => 'get',
+                                       'action' => wfScript(),
+                               ]
+                       ) .
+                               # This is an awful awful ID name. It's not a 
table, but we
+                               # named it poorly from when this was a table so 
now we're
+                               # stuck with it
+                               "<div id='mw-search-top-table'>" .
+                                       $this->shortDialog( $term, $num, 
$totalRes ) .
+                               "</div>" .
+                               $this->searchProfileTabs( $term ) .
+                               $this->searchOptions( $term ) .
+                       '</form>' .
                        $didYouMeanHtml
                );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/322013
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib527fc3a3c39eb2e56985e5d1e4905fc4562353c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to