class SpecialSearch extends SpecialPage {
/**
* Current search profile. Search profile is just a name that identifies
- * the active search tab on the search page (content, help, discussions...)
+ * the active search tab on the search page (content, discussions...)
* For users tt replaces the set of enabled namespaces from the query
* string when applicable. Extensions can add new profiles with hooks
* with custom search options just for that profile.
$search = $this->getSearchEngine();
$search->setLimitOffset( $this->limit, $this->offset );
$search->setNamespaces( $this->namespaces );
+ $this->saveNamespaces();
$search->prefix = $this->mPrefix;
$term = $search->transformSearchTerm( $term );
return $opt + $this->extraParams;
}
+ /**
+ * Save namespace preferences when we're supposed to
+ *
+ * @return bool Whether we wrote something
+ */
+ protected function saveNamespaces() {
+ $user = $this->getUser();
+ $request = $this->getRequest();
+
+ if ( $user->isLoggedIn() &&
+ !is_null( $request->getVal( 'nsRemember' ) ) &&
+ $user->matchEditToken( $request->getVal( 'nsToken' ) )
+ ) {
+ // Reset namespace preferences: namespaces are not searched
+ // when they're not mentioned in the URL parameters.
+ foreach ( MWNamespace::getValidNamespaces() as $n ) {
+ $user->setOption( 'searchNs' . $n, false );
+ }
+ // The request parameters include all the namespaces we just searched.
+ // Even if they're the same as an existing profile, they're not eaten.
+ foreach ( $this->namespaces as $n ) {
+ $user->setOption( 'searchNs' . $n, true );
+ }
+
+ $user->saveSettings();
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Show whole set of results
*
$hidden .= Html::hidden( $key, $value );
}
+ # Stuff to feed saveNamespaces()
+ $remember = '';
+ $user = $this->getUser();
+ if ( $user->isLoggedIn() ) {
+ $remember .= Html::hidden( 'nsToken', $user->getEditToken() ) .
+ Xml::checkLabel(
+ wfMessage( 'powersearch-remember' )->text(),
+ 'nsRemember',
+ 'mw-search-powersearch-remember',
+ false
+ );
+ }
+
// Return final output
return Xml::openElement(
'fieldset',
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
$hidden .
+ Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
+ $remember .
Xml::closeElement( 'fieldset' );
}
'tooltip' => 'searchprofile-images-tooltip',
'namespaces' => array( NS_FILE ),
),
- 'help' => array(
- 'message' => 'searchprofile-project',
- 'tooltip' => 'searchprofile-project-tooltip',
- 'namespaces' => SearchEngine::helpNamespaces(),
- 'namespace-messages' => SearchEngine::namespacesAsText(
- SearchEngine::helpNamespaces()
- ),
- ),
'all' => array(
'message' => 'searchprofile-everything',
'tooltip' => 'searchprofile-everything-tooltip',