http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96824
Revision: 96824
Author: robin
Date: 2011-09-12 01:39:11 +0000 (Mon, 12 Sep 2011)
Log Message:
-----------
SpecialSearch: add two hooks, one to modify the power search box, one to change
the message pointing to the page title searched for
WikimediaIncubator:
* use these hooks and SpecialSearchSetupEngine to improve search usability
* use a different message for the language code in preferences, per suggestion
of Amir
Modified Paths:
--------------
trunk/extensions/WikimediaIncubator/IncubatorTest.php
trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
trunk/phase3/docs/hooks.txt
trunk/phase3/includes/specials/SpecialSearch.php
Modified: trunk/extensions/WikimediaIncubator/IncubatorTest.php
===================================================================
--- trunk/extensions/WikimediaIncubator/IncubatorTest.php 2011-09-12
01:15:45 UTC (rev 96823)
+++ trunk/extensions/WikimediaIncubator/IncubatorTest.php 2011-09-12
01:39:11 UTC (rev 96824)
@@ -35,7 +35,7 @@
$prefinsert[$wmincPref . '-code'] = array(
'type' => 'text',
'section' => 'personal/i18n',
- 'label-message' => 'wminc-testwiki',
+ 'label-message' => 'wminc-testwiki-code',
'id' => $wmincPref . '-code',
'maxlength' => (int)$wmincLangCodeLength,
'size' => (int)$wmincLangCodeLength,
@@ -695,6 +695,62 @@
return true;
}
+ /**
+ * Search: Adapt the default message to show a more descriptive one,
+ * along with an adapted link.
+ * @return true
+ */
+ public static function onSpecialSearchCreateLink( $title, &$params ) {
+ if( $title->isKnown() ) {
+ return true;
+ }
+ global $wmincProjectSite, $wmincTestWikiNamespaces;
+ $prefix = self::displayPrefix();
+
+ $newNs = $title->getNamespace();
+ $newTitle = $title->getText();
+ if( $prefix == $wmincProjectSite['short'] ) {
+ $newNs = NS_PROJECT;
+ } else {
+ if( !in_array( $title->getNamespace(),
$wmincTestWikiNamespaces ) ) {
+ $newNs = $wmincTestWikiNamespaces[0]; # no
"valid" NS, should be main NS
+ }
+ $newTitle = $prefix . '/' . $newTitle;
+ }
+
+ $t = Title::newFromText( $newTitle, $newNs );
+ if( $t->isKnown() ) {
+ # use the default message if the suggested title exists
+ $params[0] = 'searchmenu-exists';
+ $params[1] = wfEscapeWikiText( $t->getPrefixedText() );
+ return true;
+ }
+ $params[] = wfEscapeWikiText( $t->getPrefixedText() );
+ $params[0] = $prefix ? 'wminc-search-nocreate-suggest'
:'wminc-search-nocreate-nopref';
+ return true;
+ }
+
+ /**
+ * Search: Add an input form to enter a test wiki prefix.
+ * @return true
+ */
+ public static function onSpecialSearchPowerBox( &$showSections, $term,
$opts ) {
+ $showSections['testwiki'] = Xml::label( wfMsg( 'wminc-testwiki'
), 'testwiki' ) . ' ' .
+ Xml::input( 'testwiki', 20, self::displayPrefix(),
array( 'id' => 'testwiki' ) );
+ return true;
+ }
+
+ /**
+ * Search: Search by default in the test wiki of the user's preference
(or url &testwiki).
+ * @return true
+ */
+ public static function onSpecialSearchSetupEngine( $search, $profile,
$engine ) {
+ if( !isset( $search->prefix ) || !$search->prefix ) {
+ $search->prefix = self::displayPrefix();
+ }
+ return true;
+ }
+
private static function preg_quote_slash( $str ) {
return preg_quote( $str, '/' );
}
Modified: trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
===================================================================
--- trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
2011-09-12 01:15:45 UTC (rev 96823)
+++ trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
2011-09-12 01:39:11 UTC (rev 96824)
@@ -16,6 +16,7 @@
'wminc-manual' => 'Manual',
'wminc-listwikis' => 'List of wikis',
'wminc-testwiki' => 'Test wiki:',
+ 'wminc-testwiki-code' => 'Test wiki language:',
'wminc-testwiki-none' => 'None/All',
'wminc-recentchanges-all' => 'All recent changes',
@@ -57,6 +58,10 @@
# Special:ListUsers
'wminc-listusers-testwiki' => 'You are viewing users who have set their
test wiki preference to $1.',
+
+ # Search
+ 'wminc-search-nocreate-nopref' => 'You searched for "$1". Please set
your [[Special:Preferences|test wiki preference]] so we can tell you which page
you can create!',
+ 'wminc-search-nocreate-suggest' => 'You searched for "$1". You can
create a page in your wiki at <b>[[$2]]</b>!',
);
/** Message documentation (Message documentation)
Modified: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
===================================================================
--- trunk/extensions/WikimediaIncubator/WikimediaIncubator.php 2011-09-12
01:15:45 UTC (rev 96823)
+++ trunk/extensions/WikimediaIncubator/WikimediaIncubator.php 2011-09-12
01:39:11 UTC (rev 96824)
@@ -16,7 +16,7 @@
'path' => __FILE__,
'name' => 'Wikimedia Incubator',
'author' => 'SPQRobin',
- 'version' => '4.4',
+ 'version' => '4.5',
'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
'descriptionmsg' => 'wminc-desc',
);
@@ -149,3 +149,8 @@
$wgHooks['SpecialListusersHeaderForm'][] =
'ListUsersTestWiki::onSpecialListusersHeaderForm';
$wgHooks['SpecialListusersQueryInfo'][] =
'ListUsersTestWiki::onSpecialListusersQueryInfo';
$wgHooks['SpecialListusersHeader'][] =
'ListUsersTestWiki::onSpecialListusersHeader';
+
+/* Search in test wiki */
+$wgHooks['SpecialSearchCreateLink'][] =
'IncubatorTest::onSpecialSearchCreateLink';
+$wgHooks['SpecialSearchPowerBox'][] = 'IncubatorTest::onSpecialSearchPowerBox';
+$wgHooks['SpecialSearchSetupEngine'][] =
'IncubatorTest::onSpecialSearchSetupEngine';
Modified: trunk/phase3/docs/hooks.txt
===================================================================
--- trunk/phase3/docs/hooks.txt 2011-09-12 01:15:45 UTC (rev 96823)
+++ trunk/phase3/docs/hooks.txt 2011-09-12 01:39:11 UTC (rev 96824)
@@ -1741,6 +1741,11 @@
&$query_options: array of options for the database request
&$select: Array of columns to select
+'SpecialSearchCreateLink': called when making the message to create a page or
+go to the existing page
+$t: title object searched for
+&$params: an array of the default message name and page title (as parameter)
+
'SpecialSearchGo': called when user clicked the "Go"
&$title: title object generated from the text entered by the user
&$term: the search term entered by the user
@@ -1749,6 +1754,12 @@
target doesn't exist
&$title: title object generated from the text entered by the user
+'SpecialSearchPowerBox': the equivalent of SpecialSearchProfileForm for
+the advanced form, a.k.a. power search box
+&$showSections: an array to add values with more options to
+$term: the search term (not a title object)
+$opts: an array of hidden options (containing 'redirs' and 'profile')
+
'SpecialSearchProfiles': allows modification of search profiles
&$profiles: profiles, which can be modified.
Modified: trunk/phase3/includes/specials/SpecialSearch.php
===================================================================
--- trunk/phase3/includes/specials/SpecialSearch.php 2011-09-12 01:15:45 UTC
(rev 96823)
+++ trunk/phase3/includes/specials/SpecialSearch.php 2011-09-12 01:39:11 UTC
(rev 96824)
@@ -411,8 +411,11 @@
$messageName = 'searchmenu-new-nocreate';
}
}
+ $params = array( $messageName, wfEscapeWikiText(
$t->getPrefixedText() ) );
+ wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) );
+
if( $messageName ) {
- $this->getOutput()->wrapWikiMsg( "<p
class=\"mw-search-createlink\">\n$1</p>", array( $messageName,
wfEscapeWikiText( $t->getPrefixedText() ) ) );
+ $this->getOutput()->wrapWikiMsg( "<p
class=\"mw-search-createlink\">\n$1</p>", $params );
} else {
// preserve the paragraph for margins etc...
$this->getOutput()->addHtml( '<p></p>' );
@@ -871,13 +874,17 @@
}
$namespaceTables .= Xml::closeElement( 'table' );
}
+
+ $showSections = array( 'namespaceTables' => $namespaceTables );
+
// Show redirects check only if backend supports it
- $redirects = '';
if( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
- $redirects =
+ $showSections['redirects'] =
Xml::checkLabel( wfMsg( 'powersearch-redir' ),
'redirs', 'redirs', $this->searchRedirects );
}
+ wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections,
$term, $opts ) );
+
$hidden = '';
unset( $opts['redirs'] );
foreach( $opts as $key => $value ) {
@@ -913,9 +920,8 @@
)
) .
Xml::element( 'div', array( 'class' => 'divider' ), '',
false ) .
- $namespaceTables .
- Xml::element( 'div', array( 'class' => 'divider' ), '',
false ) .
- $redirects . $hidden .
+ implode( Xml::element( 'div', array( 'class' =>
'divider' ), '', false ), $showSections ) .
+ $hidden .
Xml::closeElement( 'fieldset' );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs