* @param string $par
*/
public function execute( $par ) {
+ $request = $this->getRequest();
+
+ // Fetch the search term
+ $search = str_replace( "\n", " ", $request->getText( 'search' ) );
+
+ // Historically search terms have been accepted not only in the search query
+ // parameter, but also as part of the primary url. This can have PII implications
+ // in releasing page view data. As such issue a 301 redirect to the correct
+ // URL.
+ if ( strlen( $par ) && !strlen( $search ) ) {
+ $query = $request->getValues();
+ unset( $query['title'] );
+ // Strip underscores from title parameter; most of the time we'll want
+ // text form here. But don't strip underscores from actual text params!
+ $query['search'] = str_replace( '_', ' ', $par );
+ $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
+ return;
+ }
+
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
] );
$this->addHelpLink( 'Help:Searching' );
- // Strip underscores from title parameter; most of the time we'll want
- // text form here. But don't strip underscores from actual text params!
- $titleParam = str_replace( '_', ' ', $par );
-
- $request = $this->getRequest();
-
- // Fetch the search term
- $search = str_replace( "\n", " ", $request->getText( 'search', $titleParam ) );
-
$this->load();
if ( !is_null( $request->getVal( 'nsRemember' ) ) ) {
$this->saveNamespaces();
--- /dev/null
+<?php
+
+class SpecialSearchText extends \PHPUnit_Framework_TestCase {
+ public function testSubPageRedirect() {
+ $ctx = new RequestContext;
+
+ SpecialPageFactory::executePath(
+ Title::newFromText( 'Special:Search/foo_bar' ),
+ $ctx
+ );
+ $url = $ctx->getOutput()->getRedirect();
+ // some older versions of hhvm have a bug that doesn't parse relative
+ // urls with a port, so help it out a little bit.
+ // https://github.com/facebook/hhvm/issues/7136
+ $url = wfExpandUrl( $url, PROTO_CURRENT );
+
+ $parts = parse_url( $url );
+ $this->assertEquals( '/w/index.php', $parts['path'] );
+ parse_str( $parts['query'], $query );
+ $this->assertEquals( 'Special:Search', $query['title'] );
+ $this->assertEquals( 'foo bar', $query['search'] );
+ }
+}