From 9767ef7f08ca41aee91ccfeacdae690e99230219 Mon Sep 17 00:00:00 2001 From: harej Date: Tue, 6 Jun 2017 11:45:30 -0700 Subject: [PATCH] Allow appending searchfilters to terms For search-style inputboxes, if you have `searchfilter=foo` as a parameter, it will append `foo` after the search term. This is useful for leveraging search filters in custom search boxes without exposing it to the user. Bug: T147951 Change-Id: Ie23ce220ff9657c38fe5b41195e297ca7cebf7f1 --- InputBox.classes.php | 6 ++++++ InputBox.hooks.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/InputBox.classes.php b/InputBox.classes.php index e5a42900..1ee1931b 100644 --- a/InputBox.classes.php +++ b/InputBox.classes.php @@ -36,6 +36,7 @@ class InputBox { private $mInline = false; private $mPrefix = ''; private $mDir = ''; + private $mSearchFilter = ''; /* Functions */ @@ -169,6 +170,10 @@ class InputBox { $htmlOut .= Html::hidden( 'prefix', $this->mPrefix ); } + if ( $this->mSearchFilter != '' ) { + $htmlOut .= Html::hidden( 'searchfilter', $this->mSearchFilter ); + } + $htmlOut .= $this->mBR; // Determine namespace checkboxes @@ -599,6 +604,7 @@ class InputBox { 'inline' => 'mInline', 'prefix' => 'mPrefix', 'dir' => 'mDir', + 'searchfilter' => 'mSearchFilter' ]; foreach ( $options as $name => $var ) { if ( isset( $values[$name] ) ) { diff --git a/InputBox.hooks.php b/InputBox.hooks.php index 9bdae135..60c16d1b 100644 --- a/InputBox.hooks.php +++ b/InputBox.hooks.php @@ -22,10 +22,15 @@ class InputBoxHooks { $request = $special->getRequest(); $prefix = $request->getText( 'prefix', '' ); $title = $request->getText( 'wpNewTitle', '' ); + $search = $request->getText( 'search', '' ); + $searchfilter = $request->getText( 'searchfilter', '' ); if ( $special->getName() == 'Movepage' && $prefix !== '' && $title !== '' ) { $request->setVal( 'wpNewTitle', $prefix . $title ); $request->unsetVal( 'prefix' ); } + if ( $special->getName() == 'Search' && $searchfilter !== '' ) { + $request->setVal( 'search', $search . ' ' . $searchfilter ); + } return true; }