r95582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95581‎ | r95582 | r95583 >
Date:23:24, 26 August 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Ability to filter list of users based on their test wiki preference
Modified paths:
  • /trunk/extensions/WikimediaIncubator/ListUsersTestWiki.php (added) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
@@ -14,7 +14,7 @@
1515 'path' => __FILE__,
1616 'name' => 'Wikimedia Incubator',
1717 'author' => 'SPQRobin',
18 - 'version' => '4.2',
 18+ 'version' => '4.3',
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
2020 'descriptionmsg' => 'wminc-desc',
2121 );
@@ -141,3 +141,9 @@
142142
143143 /* Set page content language depending on the prefix */
144144 $wgHooks['PageContentLanguage'][] = 'IncubatorTest::onPageContentLanguage';
 145+
 146+/* List of users */
 147+$wgAutoloadClasses['ListUsersTestWiki'] = $dir . 'ListUsersTestWiki.php';
 148+$wgHooks['SpecialListusersHeaderForm'][] = 'ListUsersTestWiki::onSpecialListusersHeaderForm';
 149+$wgHooks['SpecialListusersQueryInfo'][] = 'ListUsersTestWiki::onSpecialListusersQueryInfo';
 150+$wgHooks['SpecialListusersHeader'][] = 'ListUsersTestWiki::onSpecialListusersHeader';
\ No newline at end of file
Index: trunk/extensions/WikimediaIncubator/ListUsersTestWiki.php
@@ -0,0 +1,58 @@
 2+<?php
 3+
 4+/**
 5+ * Ability to filter list of users based on their test wiki preference
 6+ */
 7+class ListUsersTestWiki {
 8+ /**
 9+ * Get the &testwiki=wx/xyz parameter and validate it
 10+ * @return Array
 11+ */
 12+ static function getTestWiki() {
 13+ global $wgRequest;
 14+ return IncubatorTest::analyzePrefix( $wgRequest->getVal( 'testwiki' ), true );
 15+ }
 16+
 17+ /**
 18+ * Input form
 19+ */
 20+ static function onSpecialListusersHeaderForm( $pager, &$out ) {
 21+ $testwiki = self::getTestWiki();
 22+ $out .= Xml::label( wfMsg( 'wminc-testwiki' ), 'testwiki' ) . ' ' .
 23+ Xml::input( 'testwiki', 20, ( $testwiki['error'] ? null : $testwiki['prefix'] ), array( 'id' => 'testwiki' ) ) . '<br />';
 24+ return true;
 25+ }
 26+
 27+ /**
 28+ * Show a message that you are viewing a list of users of a certain test wiki
 29+ */
 30+ static function onSpecialListusersHeader( $pager, &$out ) {
 31+ $testwiki = self::getTestWiki();
 32+ if( !$testwiki['error'] ) {
 33+ $out .= wfMsgWikiHtml( 'wminc-listusers-testwiki', $testwiki['prefix'] );
 34+ }
 35+ return true;
 36+ }
 37+
 38+ /**
 39+ * Query
 40+ */
 41+ static function onSpecialListusersQueryInfo( $pager, &$query ) {
 42+ $testwiki = self::getTestWiki();
 43+ if( !$testwiki['error'] ) {
 44+ global $wmincPref;
 45+ $dbr = wfGetDB( DB_SLAVE );
 46+ $projectPrefName = $dbr->addQuotes( "$wmincPref-project" );
 47+ $projectPrefVal = $dbr->addQuotes( $testwiki['project'] );
 48+ $langPrefName = $dbr->addQuotes( "$wmincPref-code" );
 49+ $langPrefVal = $dbr->addQuotes( $testwiki['lang'] );
 50+ $query['tables']['p1'] = 'user_properties';
 51+ $query['tables']['p2'] = 'user_properties';
 52+ $query['join_conds']['p1'] = array( 'JOIN',
 53+ "user_id=p1.up_user AND (p1.up_property=$projectPrefName AND p1.up_value=$projectPrefVal)" );
 54+ $query['join_conds']['p2'] = array( 'JOIN',
 55+ "user_id=p2.up_user AND (p2.up_property=$langPrefName AND p2.up_value=$langPrefVal)" );
 56+ }
 57+ return true;
 58+ }
 59+}
\ No newline at end of file
Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.i18n.php
@@ -53,6 +53,9 @@
5454 'wminc-code-macrolanguage' => 'The [[wikipedia:$2 language|"$3" language]] is a [[wikipedia:ISO 639 macrolanguage|macrolanguage]], consisting of the following member languages:',
5555 'wminc-code-collective' => 'The code "$1" does not refer to a specific language, but to a collection of languages, namely the [[wikipedia:$2 language|"$3" languages]].',
5656 'wminc-code-retired' => 'This language code has been changed and no longer refers to the original language.',
 57+
 58+ # Special:ListUsers
 59+ 'wminc-listusers-testwiki' => 'You are viewing users who have set their test wiki preference to [[$1]].',
5760 );
5861
5962 /** Message documentation (Message documentation)

Follow-up revisions

RevisionCommit summaryAuthorDate
r95583follow-up r95582: add newlines at the end of the files and svn:eol-style=nativerobin23:27, 26 August 2011
r96122* Use more specific css for .subpages and mark it important, because it's ove...robin16:43, 2 September 2011
r96138* Call core function Language::getTranslatedLanguageName() if found, instead ...robin18:18, 2 September 2011
r105776MFT for WikimediaIncubator: r95582, r96122, r96138, r96141, r97175, r98670, r...siebrand00:32, 11 December 2011

Comments

#Comment by Catrope (talk | contribs)   14:04, 31 August 2011
+				"user_id=p1.up_user AND (p1.up_property=$projectPrefName AND p1.up_value=$projectPrefVal)" );<

This isn't wrong, per se, but you can also use something like:

$query['join_conds']['p1'] = array( 'JOIN', array( 'user_id=p1.up_user', 'p1.up_property' => $projectPrefName, 'p1.up_value' => $projectPrefVal ) );

(of course you'd have to drop the escaping on $projectPrefName and $projectPrefVal in that case because the Database class will do the escaping for you).

#Comment by SPQRobin (talk | contribs)   17:52, 31 August 2011

Works on trunk, doesn't work on 1.17wmf1. Don't have 1.18 branch around to test it. Will have to investigate & fix it, or do a version check.

As reference:

SELECT user_name,MAX(user_id) AS user_id,MAX(user_editcount) AS edits,COUNT(ug_group) AS numgroups,MAX(ug_group) AS singlegroup,MIN(user_registration) AS creation,MAX(ipb_deleted) AS ipb_deleted FROM u`mw_user` FORCE INDEX (user_name) LEFT JOIN `mw_user_groups` ON user_id=ug_user LEFT JOIN `mw_ipblocks` ON user_id=ipb_user AND ipb_deleted=1 AND ipb_auto=0 WHERE (ipb_deleted IS NULL) GROUP BY user_name ORDER BY user_name LIMIT 101

from within function "IndexPager::reallyDoQuery (UsersPager)". Database returned error "1146: Table 'wikidb.u' doesn't exist (localhost)".

#Comment by SPQRobin (talk | contribs)   18:20, 2 September 2011

Catrope's comment done in r96122. Version check done in r96138. Should be OK now.

Status & tagging log