From 9046f2d981c388f184e1916687df9eca9ce67bba Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Thu, 15 Sep 2011 16:26:35 +0000 Subject: [PATCH] Re-do reverted r96824, but in SpecialSearch first return if the title object is invalid. --- docs/hooks.txt | 11 ++++++++ includes/specials/SpecialSearch.php | 42 ++++++++++++++++++----------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 364032b534..3955f413d7 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1742,6 +1742,11 @@ $opts: FormOptions for this request &$query_options: array of options for the database request &$select: Array of columns to select +'SpecialSearchCreateLink': called when making the message to create a page or +go to the existing page +$t: title object searched for +&$params: an array of the default message name and page title (as parameter) + 'SpecialSearchGo': called when user clicked the "Go" &$title: title object generated from the text entered by the user &$term: the search term entered by the user @@ -1750,6 +1755,12 @@ $opts: FormOptions for this request target doesn't exist &$title: title object generated from the text entered by the user +'SpecialSearchPowerBox': the equivalent of SpecialSearchProfileForm for +the advanced form, a.k.a. power search box +&$showSections: an array to add values with more options to +$term: the search term (not a title object) +$opts: an array of hidden options (containing 'redirs' and 'profile') + 'SpecialSearchProfiles': allows modification of search profiles &$profiles: profiles, which can be modified. diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 351972feba..e68584dad3 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -400,19 +400,28 @@ class SpecialSearch extends SpecialPage { */ protected function showCreateLink( $t ) { // show direct page/create link if applicable + // Check DBkey !== '' in case of fragment link only. - $messageName = null; - if( !is_null($t) && $t->getDBkey() !== '' ) { - if( $t->isKnown() ) { - $messageName = 'searchmenu-exists'; - } elseif( $t->userCan( 'create' ) ) { - $messageName = 'searchmenu-new'; - } else { - $messageName = 'searchmenu-new-nocreate'; - } + if( is_null( $t ) || $t->getDBkey() === '' ) { + // invalid title + // preserve the paragraph for margins etc... + $this->getOutput()->addHtml( '

' ); + return; } + $messageName = ''; + if( $t->isKnown() ) { + $messageName = 'searchmenu-exists'; + } elseif( $t->userCan( 'create' ) ) { + $messageName = 'searchmenu-new'; + } else { + $messageName = 'searchmenu-new-nocreate'; + } + $params = array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ); + wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) ); + + // Extensions using the hook might still return an empty $messageName if( $messageName ) { - $this->getOutput()->wrapWikiMsg( "

\n$1

", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) ); + $this->getOutput()->wrapWikiMsg( "

\n$1

", $params ); } else { // preserve the paragraph for margins etc... $this->getOutput()->addHtml( '

' ); @@ -871,13 +880,17 @@ class SpecialSearch extends SpecialPage { } $namespaceTables .= Xml::closeElement( 'table' ); } + + $showSections = array( 'namespaceTables' => $namespaceTables ); + // Show redirects check only if backend supports it - $redirects = ''; if( $this->getSearchEngine()->supports( 'list-redirects' ) ) { - $redirects = + $showSections['redirects'] = Xml::checkLabel( wfMsg( 'powersearch-redir' ), 'redirs', 'redirs', $this->searchRedirects ); } + wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) ); + $hidden = ''; unset( $opts['redirs'] ); foreach( $opts as $key => $value ) { @@ -913,9 +926,8 @@ class SpecialSearch extends SpecialPage { ) ) . Xml::element( 'div', array( 'class' => 'divider' ), '', false ) . - $namespaceTables . - Xml::element( 'div', array( 'class' => 'divider' ), '', false ) . - $redirects . $hidden . + implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) . + $hidden . Xml::closeElement( 'fieldset' ); } -- 2.20.1