Stop expanding search term in <title> of the search results page
When entering a search term such as {{SITENAME}} on Special:Search,
the <title> was generated with template expansion.
This patch prevents transformation by using search term as rawParams
of the 'searchresults-title' and 'pagetitle' messages.
Change-Id: Ief0bdd10ad882ebfaeefd11bf4217e70dd922d9d
This commit is contained in:
parent
b9f7fe0bcf
commit
9299bab032
2 changed files with 36 additions and 1 deletions
|
|
@ -449,7 +449,9 @@ class SpecialSearch extends SpecialPage {
|
|||
$out = $this->getOutput();
|
||||
if( strval( $term ) !== '' ) {
|
||||
$out->setPageTitle( $this->msg( 'searchresults' ) );
|
||||
$out->setHTMLTitle( $this->msg( 'pagetitle', $this->msg( 'searchresults-title', $term )->plain() ) );
|
||||
$out->setHTMLTitle( $this->msg( 'pagetitle' )->rawParams(
|
||||
$this->msg( 'searchresults-title' )->rawParams( $term )->text()
|
||||
) );
|
||||
}
|
||||
// add javascript specific to special:search
|
||||
$out->addModules( 'mediawiki.special.search' );
|
||||
|
|
|
|||
|
|
@ -107,5 +107,38 @@ class SpecialSearchTest extends MediaWikiTestCase {
|
|||
}
|
||||
return $u;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we do not expand search term in <title> on search result page
|
||||
* https://gerrit.wikimedia.org/r/4841
|
||||
*/
|
||||
function testSearchTermIsNotExpanded() {
|
||||
|
||||
# Initialize [[Special::Search]]
|
||||
$search = new SpecialSearch();
|
||||
$search->getContext()->setTitle( Title::newFromText('Special:Search' ) );
|
||||
$search->load();
|
||||
|
||||
# Simulate a user searching for a given term
|
||||
$term = '{{SITENAME}}';
|
||||
$search->showResults( $term );
|
||||
|
||||
# Lookup the HTML page title set for that page
|
||||
$pageTitle = $search
|
||||
->getContext()
|
||||
->getOutput()
|
||||
->getHTMLTitle();
|
||||
|
||||
# Craft the expected, plain, text:
|
||||
$aPlainSearchTerm =
|
||||
wfMessage( 'searchresults-title', $term )
|
||||
->plain();
|
||||
|
||||
# Compare :-]
|
||||
$this->assertStringStartsWith( $aPlainSearchTerm,
|
||||
$pageTitle,
|
||||
"Search term should not be expanded in Special:Search <title>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue