Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php |
— | — | @@ -19,21 +19,22 @@ |
20 | 20 | 'descriptionmsg' => 'wminc-desc', |
21 | 21 | ); |
22 | 22 | |
23 | | -/* Config */ |
24 | | -$wgGroupPermissions['*']['viewuserlang'] = false; |
25 | | -$wgGroupPermissions['sysop']['viewuserlang'] = true; |
26 | | - |
27 | 23 | /* General (globals and/or configuration) */ |
28 | 24 | $wmincPref = 'incubatortestwiki'; // Name of the preference |
29 | 25 | $dir = dirname( __FILE__ ) . '/'; |
30 | 26 | // only one-letter codes can be used for projects |
31 | 27 | $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', |
37 | 33 | ); |
| 34 | +# Sister projects is here defined as projects that are not on Incubator |
| 35 | +$wmincSisterProjects = array( |
| 36 | + 's' => 'Wikisource', |
| 37 | + 'v' => 'Wikiversity', |
| 38 | +); |
38 | 39 | $wmincProjectSite = array( |
39 | 40 | 'name' => 'Incubator', |
40 | 41 | 'short' => 'inc', |
— | — | @@ -67,6 +68,8 @@ |
68 | 69 | $wgSpecialPageGroups['ViewUserLang'] = 'users'; |
69 | 70 | $wgAvailableRights[] = 'viewuserlang'; |
70 | 71 | $wgHooks['ContributionsToolLinks'][] = 'IncubatorTest::efLoadViewUserLangLink'; |
| 72 | +$wgGroupPermissions['*']['viewuserlang'] = false; |
| 73 | +$wgGroupPermissions['sysop']['viewuserlang'] = true; |
71 | 74 | |
72 | 75 | /* TestWiki preference */ |
73 | 76 | $wgAutoloadClasses['IncubatorTest'] = $dir . 'IncubatorTest.php'; |
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | global $wgRequest, $wmincProjects; |
18 | 18 | $projectvalue = strtolower( $wgRequest->getVal( 'testwikiproject', '' ) ); |
19 | 19 | $codevalue = strtolower( $wgRequest->getVal( 'testwikicode', '' ) ); |
20 | | - if ( IncubatorTest::validateLanguageCode( $codevalue ) && in_array( $projectvalue, (array)$wmincProjects ) ) { |
| 20 | + if ( IncubatorTest::validateLanguageCode( $codevalue ) && isset( $wmincProjects[$projectvalue] ) ) { |
21 | 21 | $template->set( 'header', |
22 | 22 | Html::hidden('testwiki-project', $projectvalue). |
23 | 23 | Html::hidden('testwiki-code', $codevalue) |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | global $wgRequest, $wmincProjects, $wmincPref; |
31 | 31 | $projectvalue = $wgRequest->getVal( 'testwiki-project' ); |
32 | 32 | $codevalue = $wgRequest->getVal( 'testwiki-code' ); |
33 | | - if ( IncubatorTest::validateLanguageCode( $codevalue ) && in_array( $projectvalue, (array)$wmincProjects ) ) { |
| 33 | + if ( IncubatorTest::validateLanguageCode( $codevalue ) && isset( $wmincProjects[$projectvalue] ) ) { |
34 | 34 | $user->setOption( $wmincPref . '-project', $projectvalue ); |
35 | 35 | $user->setOption( $wmincPref . '-code', $codevalue ); |
36 | 36 | $user->saveSettings(); |
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'type' => 'select', |
27 | 27 | 'options' => |
28 | 28 | array( wfMsg( 'wminc-testwiki-none' ) => 'none' ) + |
29 | | - (array)$wmincProjects + |
| 29 | + array_flip( $wmincProjects ) + |
30 | 30 | array( $wmincProjectSite['name'] => $wmincProjectSite['short'] ), |
31 | 31 | 'section' => 'personal/i18n', |
32 | 32 | 'label-message' => 'wminc-testwiki', |
— | — | @@ -56,9 +56,13 @@ |
57 | 57 | */ |
58 | 58 | static function validateCodePreference( $input, $alldata ) { |
59 | 59 | 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' ) ); |
63 | 67 | } else { |
64 | 68 | return true; |
65 | 69 | } |
— | — | @@ -106,7 +110,7 @@ |
107 | 111 | } |
108 | 112 | } |
109 | 113 | global $wmincProjects; |
110 | | - $listProjects = implode( '', $wmincProjects ); // something like: pbtqn |
| 114 | + $listProjects = implode( '', array_keys( $wmincProjects ) ); # something like: pbtqn |
111 | 115 | if( !preg_match( '/^W['.$listProjects.']\/[a-z-]+' . |
112 | 116 | ($onlyprefix ? '$/' : '(\/.+)?$/' ), $title ) ) { |
113 | 117 | $data['error'] = 'invalidprefix'; |
— | — | @@ -159,20 +163,35 @@ |
160 | 164 | */ |
161 | 165 | static function isContentProject( $project = '' ) { |
162 | 166 | 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 ); |
165 | 176 | } |
166 | 177 | |
167 | 178 | /** |
168 | 179 | * 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) |
170 | 181 | * @return String |
171 | 182 | */ |
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 ) { |
177 | 196 | // if parameters are set OR it falls back to user pref and |
178 | 197 | // he has a content project pref set -> return the prefix |
179 | 198 | return 'W' . $projectvalue . '/' . $codevalue; // return the prefix |
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' ); |
56 | 56 | $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue ); |
57 | 57 | $select->addOption( wfMsg( 'wminc-testwiki-none' ), 'none' ); |
58 | | - foreach( $wmincProjects as $name => $prefix ) { |
| 58 | + foreach( $wmincProjects as $prefix => $name ) { |
59 | 59 | $select->addOption( $name, $prefix ); |
60 | 60 | } |
61 | 61 | $select->addOption( $wmincProjectSite['name'], $wmincProjectSite['short'] ); |