r92558 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92557‎ | r92558 | r92559 >
Date:19:46, 19 July 2011
Author:robin
Status:ok
Tags:
Comment:
Flip $wmincProjects, that is more logical (key => name). Add $wmincSisterProjects for future code. Make displayPrefix() and isContentPrefix() use getUrlParam()
Modified paths:
  • /trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/TestWikiRC.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/WikimediaIncubator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php
@@ -19,21 +19,22 @@
2020 'descriptionmsg' => 'wminc-desc',
2121 );
2222
23 -/* Config */
24 -$wgGroupPermissions['*']['viewuserlang'] = false;
25 -$wgGroupPermissions['sysop']['viewuserlang'] = true;
26 -
2723 /* General (globals and/or configuration) */
2824 $wmincPref = 'incubatortestwiki'; // Name of the preference
2925 $dir = dirname( __FILE__ ) . '/';
3026 // only one-letter codes can be used for projects
3127 $wmincProjects = array(
32 - 'Wikipedia' => 'p',
33 - 'Wikibooks' => 'b',
34 - 'Wiktionary' => 't',
35 - 'Wikiquote' => 'q',
36 - 'Wikinews' => 'n',
 28+ 'p' => 'Wikipedia',
 29+ 'b' => 'Wikibooks',
 30+ 't' => 'Wiktionary',
 31+ 'q' => 'Wikiquote',
 32+ 'n' => 'Wikinews',
3733 );
 34+# Sister projects is here defined as projects that are not on Incubator
 35+$wmincSisterProjects = array(
 36+ 's' => 'Wikisource',
 37+ 'v' => 'Wikiversity',
 38+);
3839 $wmincProjectSite = array(
3940 'name' => 'Incubator',
4041 'short' => 'inc',
@@ -67,6 +68,8 @@
6869 $wgSpecialPageGroups['ViewUserLang'] = 'users';
6970 $wgAvailableRights[] = 'viewuserlang';
7071 $wgHooks['ContributionsToolLinks'][] = 'IncubatorTest::efLoadViewUserLangLink';
 72+$wgGroupPermissions['*']['viewuserlang'] = false;
 73+$wgGroupPermissions['sysop']['viewuserlang'] = true;
7174
7275 /* TestWiki preference */
7376 $wgAutoloadClasses['IncubatorTest'] = $dir . 'IncubatorTest.php';
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php
@@ -16,7 +16,7 @@
1717 global $wgRequest, $wmincProjects;
1818 $projectvalue = strtolower( $wgRequest->getVal( 'testwikiproject', '' ) );
1919 $codevalue = strtolower( $wgRequest->getVal( 'testwikicode', '' ) );
20 - if ( IncubatorTest::validateLanguageCode( $codevalue ) && in_array( $projectvalue, (array)$wmincProjects ) ) {
 20+ if ( IncubatorTest::validateLanguageCode( $codevalue ) && isset( $wmincProjects[$projectvalue] ) ) {
2121 $template->set( 'header',
2222 Html::hidden('testwiki-project', $projectvalue).
2323 Html::hidden('testwiki-code', $codevalue)
@@ -29,7 +29,7 @@
3030 global $wgRequest, $wmincProjects, $wmincPref;
3131 $projectvalue = $wgRequest->getVal( 'testwiki-project' );
3232 $codevalue = $wgRequest->getVal( 'testwiki-code' );
33 - if ( IncubatorTest::validateLanguageCode( $codevalue ) && in_array( $projectvalue, (array)$wmincProjects ) ) {
 33+ if ( IncubatorTest::validateLanguageCode( $codevalue ) && isset( $wmincProjects[$projectvalue] ) ) {
3434 $user->setOption( $wmincPref . '-project', $projectvalue );
3535 $user->setOption( $wmincPref . '-code', $codevalue );
3636 $user->saveSettings();
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -25,7 +25,7 @@
2626 'type' => 'select',
2727 'options' =>
2828 array( wfMsg( 'wminc-testwiki-none' ) => 'none' ) +
29 - (array)$wmincProjects +
 29+ array_flip( $wmincProjects ) +
3030 array( $wmincProjectSite['name'] => $wmincProjectSite['short'] ),
3131 'section' => 'personal/i18n',
3232 'label-message' => 'wminc-testwiki',
@@ -56,9 +56,13 @@
5757 */
5858 static function validateCodePreference( $input, $alldata ) {
5959 global $wmincPref, $wmincProjects;
60 - // If the user selected a project that NEEDS a language code, but the user DID NOT enter a language code, give an error
61 - if ( isset( $alldata[$wmincPref.'-project'] ) && in_array( $alldata[$wmincPref.'-project'], $wmincProjects ) && !$input ) {
62 - return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'wminc-prefinfo-error' ) );
 60+ # If the user selected a project that NEEDS a language code,
 61+ # but the user DID NOT enter a language code, give an error
 62+ if ( isset( $alldata[$wmincPref.'-project'] ) &&
 63+ array_key_exists( $alldata[$wmincPref.'-project'], $wmincProjects ) &&
 64+ !$input ) {
 65+ return Xml::element( 'span', array( 'class' => 'error' ),
 66+ wfMsg( 'wminc-prefinfo-error' ) );
6367 } else {
6468 return true;
6569 }
@@ -106,7 +110,7 @@
107111 }
108112 }
109113 global $wmincProjects;
110 - $listProjects = implode( '', $wmincProjects ); // something like: pbtqn
 114+ $listProjects = implode( '', array_keys( $wmincProjects ) ); # something like: pbtqn
111115 if( !preg_match( '/^W['.$listProjects.']\/[a-z-]+' .
112116 ($onlyprefix ? '$/' : '(\/.+)?$/' ), $title ) ) {
113117 $data['error'] = 'invalidprefix';
@@ -159,20 +163,35 @@
160164 */
161165 static function isContentProject( $project = '' ) {
162166 global $wgUser, $wmincPref, $wmincProjects;
163 - $project = ($project ? $project : $wgUser->getOption($wmincPref . '-project') );
164 - return (bool) in_array( $project, $wmincProjects );
 167+ $url = self::getUrlParam();
 168+ if( $project ) {
 169+ $r = $project; # Precedence to given value
 170+ } elseif( $url ) {
 171+ $r = $url['project']; # Otherwise URL &testwiki= if set
 172+ } else {
 173+ $r = $wgUser->getOption( $wmincPref . '-project' ); # Defaults to preference
 174+ }
 175+ return (bool) array_key_exists( $r, $wmincProjects );
165176 }
166177
167178 /**
168179 * display the prefix by the given project and code
169 - * (or the user preference if no parameters are given)
 180+ * (or the URL &testwiki= or user preference if no parameters are given)
170181 * @return String
171182 */
172 - static function displayPrefix( $project = '', $code = '' ) {
173 - global $wgUser, $wmincPref;
174 - $projectvalue = ( $project ? $project : $wgUser->getOption($wmincPref . '-project') );
175 - $codevalue = ( $code ? $code : $wgUser->getOption($wmincPref . '-code') );
176 - if ( self::isContentProject( $projectvalue ) ) {
 183+ static function displayPrefix( $project = '', $code = '', $allowSister = false ) {
 184+ global $wmincSisterProjects;
 185+ if( $project && $code ) {
 186+ $projectvalue = $project;
 187+ $codevalue = $code;
 188+ } else {
 189+ global $wgUser, $wmincPref;
 190+ $url = self::getUrlParam();
 191+ $projectvalue = ( $url ? $url['project'] : $wgUser->getOption($wmincPref . '-project') );
 192+ $codevalue = ( $url ? $url['lang'] : $wgUser->getOption($wmincPref . '-code') );
 193+ }
 194+ $sister = (bool)( $allowSister && isset( $wmincSisterProjects[$projectvalue] ) );
 195+ if ( self::isContentProject( $projectvalue ) || $sister ) {
177196 // if parameters are set OR it falls back to user pref and
178197 // he has a content project pref set -> return the prefix
179198 return 'W' . $projectvalue . '/' . $codevalue; // return the prefix
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php
@@ -54,7 +54,7 @@
5555 $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' );
5656 $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue );
5757 $select->addOption( wfMsg( 'wminc-testwiki-none' ), 'none' );
58 - foreach( $wmincProjects as $name => $prefix ) {
 58+ foreach( $wmincProjects as $prefix => $name ) {
5959 $select->addOption( $name, $prefix );
6060 }
6161 $select->addOption( $wmincProjectSite['name'], $wmincProjectSite['short'] );

Sign-offs

UserFlagDate
Nikerabbitinspected05:56, 20 July 2011

Status & tagging log