Don't offer create link for searches with syntax
authorNik Everett <neverett@wikimedia.org>
Tue, 4 Feb 2014 18:22:37 +0000 (13:22 -0500)
committerNik Everett <neverett@wikimedia.org>
Tue, 4 Feb 2014 18:28:19 +0000 (13:28 -0500)
Rather, create a hook that search implementations can override to specify
that the search contained advanced syntax and core will read it in
Special:Search and only offer the link if it is false.  It'll default
false.

Change-Id: Ic4ce6361d0e602ed9a812dfbbd15ce11a762f5f8

includes/search/SearchEngine.php
includes/specials/SpecialSearch.php

index 51cc539..882919f 100644 (file)
@@ -672,6 +672,15 @@ class SearchResultSet {
        function free() {
                // ...
        }
+
+       /**
+        * Did the search contain search syntax?  If so, Special:Search won't offer
+        * the user a link to a create a page named by the search string because the
+        * name would contain the search syntax.
+        */
+       public function searchContainedSyntax() {
+               return false;
+       }
 }
 
 /**
index 9e5143f..c06f85e 100644 (file)
@@ -376,7 +376,7 @@ class SpecialSearch extends SpecialPage {
                // prev/next links
                if ( $num || $this->offset ) {
                        // Show the create link ahead
-                       $this->showCreateLink( $t, $num );
+                       $this->showCreateLink( $t, $num, $titleMatches, $textMatches );
                        $prevnext = $this->getLanguage()->viewPrevNext( $this->getPageTitle(), $this->offset, $this->limit,
                                $this->powerSearchOptions() + array( 'search' => $term ),
                                max( $titleMatchesNum, $textMatchesNum ) < $this->limit
@@ -422,7 +422,7 @@ class SpecialSearch extends SpecialPage {
                        } else {
                                $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
                                        array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
-                               $this->showCreateLink( $t, $num );
+                               $this->showCreateLink( $t, $num, $titleMatches, $textMatches );
                        }
                }
                $out->addHtml( "</div>" );
@@ -437,12 +437,16 @@ class SpecialSearch extends SpecialPage {
        /**
         * @param $t Title
         * @param int $num The number of search results found
+        * @param $titleMatches null|SearchResultSet results from title search
+        * @param $textMatches null|SearchResultSet results from text search
         */
-       protected function showCreateLink( $t, $num ) {
+       protected function showCreateLink( $t, $num, $titleMatches, $textMatches ) {
                // show direct page/create link if applicable
 
                // Check DBkey !== '' in case of fragment link only.
-               if ( is_null( $t ) || $t->getDBkey() === '' ) {
+               if ( is_null( $t ) || $t->getDBkey() === '' ||
+                               ( $titleMatches !== null && $titleMatches->searchContainedSyntax() ) ||
+                               ( $textMatches !== null && $textMatches->searchContainedSyntax() ) ) {
                        // invalid title
                        // preserve the paragraph for margins etc...
                        $this->getOutput()->addHtml( '<p></p>' );