r97175 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97174‎ | r97175 | r97176 >
Date:16:26, 15 September 2011
Author:robin
Status:ok (Comments)
Tags:
Comment:
Re-do reverted r96824, but in SpecialSearch first return if the title object is invalid.
Modified paths:
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1742,6 +1742,11 @@
17431743 &$query_options: array of options for the database request
17441744 &$select: Array of columns to select
17451745
 1746+'SpecialSearchCreateLink': called when making the message to create a page or
 1747+go to the existing page
 1748+$t: title object searched for
 1749+&$params: an array of the default message name and page title (as parameter)
 1750+
17461751 'SpecialSearchGo': called when user clicked the "Go"
17471752 &$title: title object generated from the text entered by the user
17481753 &$term: the search term entered by the user
@@ -1750,6 +1755,12 @@
17511756 target doesn't exist
17521757 &$title: title object generated from the text entered by the user
17531758
 1759+'SpecialSearchPowerBox': the equivalent of SpecialSearchProfileForm for
 1760+the advanced form, a.k.a. power search box
 1761+&$showSections: an array to add values with more options to
 1762+$term: the search term (not a title object)
 1763+$opts: an array of hidden options (containing 'redirs' and 'profile')
 1764+
17541765 'SpecialSearchProfiles': allows modification of search profiles
17551766 &$profiles: profiles, which can be modified.
17561767
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -400,19 +400,28 @@
401401 */
402402 protected function showCreateLink( $t ) {
403403 // show direct page/create link if applicable
 404+
404405 // Check DBkey !== '' in case of fragment link only.
405 - $messageName = null;
406 - if( !is_null($t) && $t->getDBkey() !== '' ) {
407 - if( $t->isKnown() ) {
408 - $messageName = 'searchmenu-exists';
409 - } elseif( $t->userCan( 'create' ) ) {
410 - $messageName = 'searchmenu-new';
411 - } else {
412 - $messageName = 'searchmenu-new-nocreate';
413 - }
 406+ if( is_null( $t ) || $t->getDBkey() === '' ) {
 407+ // invalid title
 408+ // preserve the paragraph for margins etc...
 409+ $this->getOutput()->addHtml( '<p></p>' );
 410+ return;
414411 }
 412+ $messageName = '';
 413+ if( $t->isKnown() ) {
 414+ $messageName = 'searchmenu-exists';
 415+ } elseif( $t->userCan( 'create' ) ) {
 416+ $messageName = 'searchmenu-new';
 417+ } else {
 418+ $messageName = 'searchmenu-new-nocreate';
 419+ }
 420+ $params = array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) );
 421+ wfRunHooks( 'SpecialSearchCreateLink', array( $t, &$params ) );
 422+
 423+ // Extensions using the hook might still return an empty $messageName
415424 if( $messageName ) {
416 - $this->getOutput()->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
 425+ $this->getOutput()->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>", $params );
417426 } else {
418427 // preserve the paragraph for margins etc...
419428 $this->getOutput()->addHtml( '<p></p>' );
@@ -871,13 +880,17 @@
872881 }
873882 $namespaceTables .= Xml::closeElement( 'table' );
874883 }
 884+
 885+ $showSections = array( 'namespaceTables' => $namespaceTables );
 886+
875887 // Show redirects check only if backend supports it
876 - $redirects = '';
877888 if( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
878 - $redirects =
 889+ $showSections['redirects'] =
879890 Xml::checkLabel( wfMsg( 'powersearch-redir' ), 'redirs', 'redirs', $this->searchRedirects );
880891 }
881892
 893+ wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) );
 894+
882895 $hidden = '';
883896 unset( $opts['redirs'] );
884897 foreach( $opts as $key => $value ) {
@@ -913,9 +926,8 @@
914927 )
915928 ) .
916929 Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
917 - $namespaceTables .
918 - Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
919 - $redirects . $hidden .
 930+ implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
 931+ $hidden .
920932 Xml::closeElement( 'fieldset' );
921933 }
922934
Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
@@ -16,7 +16,7 @@
1717 'path' => __FILE__,
1818 'name' => 'Wikimedia Incubator',
1919 'author' => 'SPQRobin',
20 - 'version' => '4.4',
 20+ 'version' => '4.5',
2121 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
2222 'descriptionmsg' => 'wminc-desc',
2323 );
@@ -149,3 +149,8 @@
150150 $wgHooks['SpecialListusersHeaderForm'][] = 'ListUsersTestWiki::onSpecialListusersHeaderForm';
151151 $wgHooks['SpecialListusersQueryInfo'][] = 'ListUsersTestWiki::onSpecialListusersQueryInfo';
152152 $wgHooks['SpecialListusersHeader'][] = 'ListUsersTestWiki::onSpecialListusersHeader';
 153+
 154+/* Search in test wiki */
 155+$wgHooks['SpecialSearchCreateLink'][] = 'IncubatorTest::onSpecialSearchCreateLink';
 156+$wgHooks['SpecialSearchPowerBox'][] = 'IncubatorTest::onSpecialSearchPowerBox';
 157+$wgHooks['SpecialSearchSetupEngine'][] = 'IncubatorTest::onSpecialSearchSetupEngine';
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -35,7 +35,7 @@
3636 $prefinsert[$wmincPref . '-code'] = array(
3737 'type' => 'text',
3838 'section' => 'personal/i18n',
39 - 'label-message' => 'wminc-testwiki',
 39+ 'label-message' => 'wminc-testwiki-code',
4040 'id' => $wmincPref . '-code',
4141 'maxlength' => (int)$wmincLangCodeLength,
4242 'size' => (int)$wmincLangCodeLength,
@@ -695,6 +695,62 @@
696696 return true;
697697 }
698698
 699+ /**
 700+ * Search: Adapt the default message to show a more descriptive one,
 701+ * along with an adapted link.
 702+ * @return true
 703+ */
 704+ public static function onSpecialSearchCreateLink( $title, &$params ) {
 705+ if( $title->isKnown() ) {
 706+ return true;
 707+ }
 708+ global $wmincProjectSite, $wmincTestWikiNamespaces;
 709+ $prefix = self::displayPrefix();
 710+
 711+ $newNs = $title->getNamespace();
 712+ $newTitle = $title->getText();
 713+ if( $prefix == $wmincProjectSite['short'] ) {
 714+ $newNs = NS_PROJECT;
 715+ } else {
 716+ if( !in_array( $title->getNamespace(), $wmincTestWikiNamespaces ) ) {
 717+ $newNs = $wmincTestWikiNamespaces[0]; # no "valid" NS, should be main NS
 718+ }
 719+ $newTitle = $prefix . '/' . $newTitle;
 720+ }
 721+
 722+ $t = Title::newFromText( $newTitle, $newNs );
 723+ if( $t->isKnown() ) {
 724+ # use the default message if the suggested title exists
 725+ $params[0] = 'searchmenu-exists';
 726+ $params[1] = wfEscapeWikiText( $t->getPrefixedText() );
 727+ return true;
 728+ }
 729+ $params[] = wfEscapeWikiText( $t->getPrefixedText() );
 730+ $params[0] = $prefix ? 'wminc-search-nocreate-suggest' :'wminc-search-nocreate-nopref';
 731+ return true;
 732+ }
 733+
 734+ /**
 735+ * Search: Add an input form to enter a test wiki prefix.
 736+ * @return true
 737+ */
 738+ public static function onSpecialSearchPowerBox( &$showSections, $term, $opts ) {
 739+ $showSections['testwiki'] = Xml::label( wfMsg( 'wminc-testwiki' ), 'testwiki' ) . ' ' .
 740+ Xml::input( 'testwiki', 20, self::displayPrefix(), array( 'id' => 'testwiki' ) );
 741+ return true;
 742+ }
 743+
 744+ /**
 745+ * Search: Search by default in the test wiki of the user's preference (or url &testwiki).
 746+ * @return true
 747+ */
 748+ public static function onSpecialSearchSetupEngine( $search, $profile, $engine ) {
 749+ if( !isset( $search->prefix ) || !$search->prefix ) {
 750+ $search->prefix = self::displayPrefix();
 751+ }
 752+ return true;
 753+ }
 754+
699755 private static function preg_quote_slash( $str ) {
700756 return preg_quote( $str, '/' );
701757 }
Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
@@ -16,6 +16,7 @@
1717 'wminc-manual' => 'Manual',
1818 'wminc-listwikis' => 'List of wikis',
1919 'wminc-testwiki' => 'Test wiki:',
 20+ 'wminc-testwiki-code' => 'Test wiki language:',
2021 'wminc-testwiki-none' => 'None/All',
2122 'wminc-recentchanges-all' => 'All recent changes',
2223
@@ -57,6 +58,10 @@
5859
5960 # Special:ListUsers
6061 'wminc-listusers-testwiki' => 'You are viewing users who have set their test wiki preference to $1.',
 62+
 63+ # Search
 64+ '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!',
 65+ 'wminc-search-nocreate-suggest' => 'You searched for "$1". You can create a page in your wiki at <b>[[$2]]</b>!',
6166 );
6267
6368 /** Message documentation (Message documentation)

Sign-offs

UserFlagDate
Nikerabbitinspected08:23, 21 September 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r102560REL1_18 Partial MFT for r97175reedy19:32, 9 November 2011
r102561Delete WikimediaIncubator for rebranch from trunk (per r97175)reedy19:33, 9 November 2011
r105776MFT for WikimediaIncubator: r95582, r96122, r96138, r96141, r97175, r98670, r...siebrand00:32, 11 December 2011
r105888Merge r102560, essentially merging r97175 into 1.18wmf1reedy15:25, 12 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96824SpecialSearch: add two hooks, one to modify the power search box, one to chan...robin01:39, 12 September 2011

Comments

#Comment by Reedy (talk | contribs)   15:15, 9 November 2011

Merging the phase3 changes conflict slightly, but works

Merging the Incubator stuff conflicts a lot more...

It's also a jump from version 3 to 4.5...

Would it be easier just to merge the trunk changes, and then rebranch Incubator from trunk? As I'm guessing it's not going to be the same 4.5 due to other changes that presumably haven't been merged

#Comment by SPQRobin (talk | contribs)   18:27, 9 November 2011

My intention is that the Incubator extension on WMF should follow trunk. The development version is elsewhere; trunk is meant to be stable and to work for WMF.

#Comment by Reedy (talk | contribs)   18:49, 9 November 2011

So that's a yes?

#Comment by SPQRobin (talk | contribs)   19:26, 9 November 2011

Yes :)

Status & tagging log