Save advanced search namespace prefs on Special:Search itself
* Checkbox on own row below power search checkboxes per MatmaRex;
avoiding a mw-search-ns* id leaves it untouched by All/None JS.
* The option searcheverything is removed: a "shortcut" which is no
longer necessary now that options can be (un)selected at once
with All/None buttons on search page itself.
* Require a token for saving: no accidental preferences changes.
* Keep the searchoptions/advancedsearchoptions prefs section in case
something is using it (no known extension does though); options
are converted to "api" type so it's empty and hidden by default.
* Add minimal documentation for saveSettings() and friends
(@todo since 155ddf6de, 2009!).
Bug: 52817
Change-Id: I514cee835988600cc013658049e88a10b670e64a
This commit is contained in:
parent
77eade6f9b
commit
5dc4dc099d
8 changed files with 67 additions and 45 deletions
|
|
@ -14,6 +14,9 @@ production.
|
|||
* Introduced $wgPagePropsHaveSortkey as a backwards-compatibility switch,
|
||||
for using the old schema of the page_props table, in case the respective
|
||||
schema update was not applied.
|
||||
* $wgSearchEverythingOnlyLoggedIn was removed as the 'searcheverything'
|
||||
user option was removed. Use $wgNamespacesToBeSearchedDefault instead or
|
||||
if you used to have $wgDefaultUserOptions['searcheverything'] = 1.
|
||||
|
||||
=== New features in 1.24 ===
|
||||
* Added a new hook, "WhatLinksHereProps", to allow extensions to annotate
|
||||
|
|
@ -52,6 +55,8 @@ production.
|
|||
* New methods setVolatile and isVolatile are added to PPFrame, so that
|
||||
extensions such as Cite.php can mark that their output is volatile and
|
||||
shouldn't be cached.
|
||||
* (bug 52817) Advanced search options are now saved on the search page itself, rather
|
||||
than in a dedicated pane in the preferences panel.
|
||||
|
||||
=== Bug fixes in 1.24 ===
|
||||
* (bug 49116) Footer copyright notice is now always displayed in user language
|
||||
|
|
|
|||
|
|
@ -5322,14 +5322,6 @@ $wgNamespacesToBeSearchedDefault = array(
|
|||
NS_MAIN => true,
|
||||
);
|
||||
|
||||
/**
|
||||
* If set to true the 'searcheverything' preference will be effective only for
|
||||
* logged-in users.
|
||||
* Useful for big wikis to maintain different search profiles for anonymous and
|
||||
* logged-in users.
|
||||
*/
|
||||
$wgSearchEverythingOnlyLoggedIn = false;
|
||||
|
||||
/**
|
||||
* Disable the internal MySQL-based search, to allow it to be
|
||||
* implemented by an extension instead.
|
||||
|
|
|
|||
|
|
@ -1010,29 +1010,13 @@ class Preferences {
|
|||
* @param array $defaultPreferences
|
||||
*/
|
||||
static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) {
|
||||
global $wgContLang;
|
||||
|
||||
$defaultPreferences['searcheverything'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'searcheverything-enable',
|
||||
'section' => 'searchoptions/advancedsearchoptions',
|
||||
);
|
||||
|
||||
$nsOptions = $wgContLang->getFormattedNamespaces();
|
||||
$nsOptions[0] = $context->msg( 'blanknamespace' )->text();
|
||||
foreach ( $nsOptions as $ns => $name ) {
|
||||
if ( $ns < 0 ) {
|
||||
unset( $nsOptions[$ns] );
|
||||
foreach ( MWNamespace::getValidNamespaces() as $n ) {
|
||||
if ( $n >= 0 ) {
|
||||
$defaultPreferences[ 'searchNs' . $n ] = array(
|
||||
'type' => 'api',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$defaultPreferences['searchnamespaces'] = array(
|
||||
'type' => 'multiselect',
|
||||
'label-message' => 'defaultns',
|
||||
'options' => array_flip( $nsOptions ),
|
||||
'section' => 'searchoptions/advancedsearchoptions',
|
||||
'prefix' => 'searchNs',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2552,6 +2552,8 @@ class User {
|
|||
/**
|
||||
* Set the given option for a user.
|
||||
*
|
||||
* You need to call saveSettings() to actually write to the database.
|
||||
*
|
||||
* @param string $oname The option to set
|
||||
* @param mixed $val New value to set
|
||||
*/
|
||||
|
|
@ -4807,7 +4809,9 @@ class User {
|
|||
}
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* Saves the non-default options for this user, as previously set e.g. via
|
||||
* setOption(), in the database's "user_properties" (preferences) table.
|
||||
* Usually used via saveSettings().
|
||||
*/
|
||||
protected function saveOptions() {
|
||||
$this->loadOptions();
|
||||
|
|
|
|||
|
|
@ -368,20 +368,8 @@ class SearchEngine {
|
|||
* @return array
|
||||
*/
|
||||
public static function userNamespaces( $user ) {
|
||||
global $wgSearchEverythingOnlyLoggedIn;
|
||||
|
||||
$searchableNamespaces = SearchEngine::searchableNamespaces();
|
||||
|
||||
// get search everything preference, that can be set to be read for logged-in users
|
||||
// it overrides other options
|
||||
if ( !$wgSearchEverythingOnlyLoggedIn || $user->isLoggedIn() ) {
|
||||
if ( $user->getOption( 'searcheverything' ) ) {
|
||||
return array_keys( $searchableNamespaces );
|
||||
}
|
||||
}
|
||||
|
||||
$arr = array();
|
||||
foreach ( $searchableNamespaces as $ns => $name ) {
|
||||
foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) {
|
||||
if ( $user->getOption( 'searchNs' . $ns ) ) {
|
||||
$arr[] = $ns;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ class SpecialSearch extends SpecialPage {
|
|||
$search = $this->getSearchEngine();
|
||||
$search->setLimitOffset( $this->limit, $this->offset );
|
||||
$search->setNamespaces( $this->namespaces );
|
||||
$this->saveNamespaces();
|
||||
$search->prefix = $this->mPrefix;
|
||||
$term = $search->transformSearchTerm( $term );
|
||||
|
||||
|
|
@ -522,6 +523,39 @@ class SpecialSearch extends SpecialPage {
|
|||
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 ) {
|
||||
if ( $n >= 0 ) {
|
||||
$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
|
||||
*
|
||||
|
|
@ -940,6 +974,19 @@ class SpecialSearch extends SpecialPage {
|
|||
$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',
|
||||
|
|
@ -951,6 +998,8 @@ class SpecialSearch extends SpecialPage {
|
|||
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' );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -901,7 +901,6 @@
|
|||
"search-interwiki-custom": "",
|
||||
"search-interwiki-more": "(more)",
|
||||
"search-relatedarticle": "Related",
|
||||
"searcheverything-enable": "Search in all namespaces",
|
||||
"searchrelated": "related",
|
||||
"searchall": "all",
|
||||
"showingresults": "Showing below up to {{PLURAL:$1|<strong>1</strong> result|<strong>$1</strong> results}} starting with #<strong>$2</strong>.",
|
||||
|
|
@ -914,6 +913,7 @@
|
|||
"powersearch-togglelabel": "Check:",
|
||||
"powersearch-toggleall": "All",
|
||||
"powersearch-togglenone": "None",
|
||||
"powersearch-remember": "Remember selection for future searches",
|
||||
"search-external": "External search",
|
||||
"searchdisabled": "{{SITENAME}} search is disabled.\nYou can search via Google in the meantime.\nNote that their indexes of {{SITENAME}} content may be out of date.",
|
||||
"googlesearch": "<form method=\"get\" action=\"//www.google.com/search\" id=\"googlesearch\">\n\t<input type=\"hidden\" name=\"domains\" value=\"{{SERVER}}\" />\n\t<input type=\"hidden\" name=\"num\" value=\"50\" />\n\t<input type=\"hidden\" name=\"ie\" value=\"$2\" />\n\t<input type=\"hidden\" name=\"oe\" value=\"$2\" />\n\n\t<input type=\"text\" name=\"q\" size=\"31\" maxlength=\"255\" value=\"$1\" />\n\t<input type=\"submit\" name=\"btnG\" value=\"$3\" />\n <div>\n\t<input type=\"radio\" name=\"sitesearch\" id=\"gwiki\" value=\"{{SERVER}}\" checked=\"checked\" /><label for=\"gwiki\">{{SITENAME}}</label>\n\t<input type=\"radio\" name=\"sitesearch\" id=\"gWWW\" value=\"\" /><label for=\"gWWW\">WWW</label>\n </div>\n</form>",
|
||||
|
|
@ -976,7 +976,6 @@
|
|||
"allowemail": "Enable email from other users",
|
||||
"prefs-searchoptions": "Search",
|
||||
"prefs-namespaces": "Namespaces",
|
||||
"defaultns": "Otherwise search in these namespaces:",
|
||||
"default": "default",
|
||||
"prefs-files": "Files",
|
||||
"prefs-custom-css": "Custom CSS",
|
||||
|
|
|
|||
|
|
@ -1076,6 +1076,7 @@
|
|||
"powersearch-togglelabel": "Used in [{{canonicalurl:Special:Search|advanced=1}} Advanced search]. Synonym: \"Select\" as verb.\n{{Identical|Check}}",
|
||||
"powersearch-toggleall": "\"All\" refers to namespaces. It is used in Advanced search: {{canonicalurl:Special:Search|advanced=1}}\n{{Identical|All}}",
|
||||
"powersearch-togglenone": "\"None\" refers to namespaces. It is used in Advanced search: {{canonicalurl:Special:Search|advanced=1}}\n{{Identical|None}}",
|
||||
"powersearch-remember": "Label for a checkbox to save namespace choice for advanced search to user preferences.",
|
||||
"search-external": "Legend of the fieldset for the input form when the internal search is disabled. Inside the fieldset [[MediaWiki:Searchdisabled]] and [[MediaWiki:Googlesearch]] is shown.",
|
||||
"searchdisabled": "{{doc-singularthey}}\nIn this sentence, \"their indexes\" refers to \"Google's indexes\".\n\nShown on [[Special:Search]] when the internal search is disabled.",
|
||||
"googlesearch": "{{notranslate}}\nShown when [[mw:Manual:$wgDisableTextSearch|$wgDisableTextSearch]] is set to true and no [[mw:Manual:$wgSearchForwardUrl|$wgSearchForwardUrl]] is set.\n\nParameters:\n* $1 - the search term\n* $2 - \"UTF-8\" (hard-coded)\n* $3 - the message {{msg-mw|Searchbutton}}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue