From 4e3e752a9ecf985a2bf0d1db0028e4492f03de3a Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 4 Feb 2014 13:22:37 -0500 Subject: [PATCH] Don't offer create link for searches with syntax 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 | 9 +++++++++ includes/specials/SpecialSearch.php | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 51cc539f71..882919feba 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -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; + } } /** diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 9e5143f087..c06f85e0df 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -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( "

\n$1

", array( 'search-nonefound', wfEscapeWikiText( $term ) ) ); - $this->showCreateLink( $t, $num ); + $this->showCreateLink( $t, $num, $titleMatches, $textMatches ); } } $out->addHtml( "" ); @@ -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( '

' ); -- 2.20.1