Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | 'path' => __FILE__, |
13 | 13 | 'name' => 'Wikimedia Incubator', |
14 | 14 | 'author' => 'SPQRobin', |
15 | | - 'version' => '2.3.3', |
| 15 | + 'version' => '2.4', |
16 | 16 | 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator', |
17 | 17 | 'descriptionmsg' => 'wminc-desc', |
18 | 18 | ); |
— | — | @@ -20,9 +20,21 @@ |
21 | 21 | $wgGroupPermissions['*']['viewuserlang'] = false; |
22 | 22 | $wgGroupPermissions['sysop']['viewuserlang'] = true; |
23 | 23 | |
24 | | -/* General */ |
| 24 | +/* General (kind of globals) */ |
25 | 25 | $wmincPref = 'incubatortestwiki'; // Name of the preference |
26 | 26 | $dir = dirname( __FILE__ ) . '/'; |
| 27 | +$wmincProjects = array( |
| 28 | + 'Wikipedia' => 'p', |
| 29 | + 'Wikibooks' => 'b', |
| 30 | + 'Wiktionary' => 't', |
| 31 | + 'Wikiquote' => 'q', |
| 32 | + 'Wikinews' => 'n', |
| 33 | +); |
| 34 | +$wmincProjectSite = array( |
| 35 | + 'name' => 'Incubator', |
| 36 | + 'short' => 'inc', |
| 37 | +); |
| 38 | + |
27 | 39 | $wgExtensionMessagesFiles['WikimediaIncubator'] = $dir . 'WikimediaIncubator.i18n.php'; |
28 | 40 | |
29 | 41 | /* Special:ViewUserLang */ |
Index: trunk/extensions/WikimediaIncubator/SpecialRandomByTest.php |
— | — | @@ -7,11 +7,13 @@ |
8 | 8 | class SpecialRandomByTest extends RandomPage |
9 | 9 | { |
10 | 10 | public function __construct() { |
11 | | - global $wgUser, $wmincPref; |
| 11 | + global $wgUser, $wmincPref, $wmincProjectSite; |
12 | 12 | if(IncubatorTest::isNormalPrefix()) { |
13 | | - $this->extra[] = 'page_title like "W'.$wgUser->getOption($wmincPref . '-project').'/'.$wgUser->getOption($wmincPref . '-code').'/%%"'; |
14 | | - } elseif($wgUser->getOption($wmincPref . '-project') == 'inc') { |
15 | | - $this->extra[] = 'page_title not like "W_/%%" OR "W_/%%/%%"'; |
| 13 | + $this->extra[] = 'page_title like "W' . $wgUser->getOption($wmincPref . '-project') . |
| 14 | + '/' . $wgUser->getOption($wmincPref . '-code') . '/%%"'; |
| 15 | + } elseif($wgUser->getOption($wmincPref . '-project') == $wmincProjectSite['short'] ) { |
| 16 | + // project or help namespace |
| 17 | + $this->extra['page_namespace'] = array( 4, 12 ); |
16 | 18 | } |
17 | 19 | parent::__construct( 'RandomByTest' ); |
18 | 20 | } |
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php |
— | — | @@ -1,14 +1,17 @@ |
2 | 2 | <?php |
3 | 3 | /* |
4 | | -* If URL parameters "testwikiproject" and "testwikicode" are set on page creation form, set them as user preference |
5 | | -* This can be used to work with my toolserver project (http://toolserver.org/~robin/?tool=proposewiki), so users don't *have* to change their preferences (automatically is always better :p) |
| 4 | +* If URL parameters "testwikiproject" and "testwikicode" are set |
| 5 | +* on account creation form, set them as user preference. |
| 6 | +* This can be used to work with links on other sites |
| 7 | +* referring to the account creation form so users don't *have* to |
| 8 | +* change their preferences (automatically is always better :p) |
6 | 9 | */ |
7 | 10 | class AutoTestWiki { |
8 | 11 | function onUserCreateForm( $template ) { |
9 | | - global $wgRequest; |
| 12 | + global $wgRequest, $wmincProjects; |
10 | 13 | $projectvalue = strtolower( $wgRequest->getVal( 'testwikiproject', '' ) ); |
11 | 14 | $codevalue = strtolower( $wgRequest->getVal( 'testwikicode', '' ) ); |
12 | | - if ( preg_match( '/[a-z][a-z][a-z]?/', $codevalue ) && in_array( $projectvalue, array( 'p', 'b', 't', 'q', 'n' ) ) ) { |
| 15 | + if ( preg_match( '/[a-z][a-z][a-z]?/', $codevalue ) && in_array( $projectvalue, (array)$wmincProjects ) ) { |
13 | 16 | $template->set( 'header', '<input type="hidden" name="testwiki-project" value="' . $projectvalue . '" /> |
14 | 17 | <input type="hidden" name="testwiki-code" value="' . $codevalue . '" /> |
15 | 18 | ' ); |
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php |
— | — | @@ -6,14 +6,14 @@ |
7 | 7 | class IncubatorTest |
8 | 8 | { |
9 | 9 | static function onGetPreferences( $user, &$preferences ) { |
10 | | - global $wmincPref, $wmincPrefProject, $wmincPrefNone, $wgDefaultUserOptions; |
| 10 | + global $wmincPref, $wmincProjects, $wmincProjectSite, $wmincPrefProject, $wmincPrefNone, $wgDefaultUserOptions; |
11 | 11 | |
12 | 12 | $preferences['language']['help-message'] = 'wminc-prefinfo-language'; |
13 | 13 | |
14 | 14 | $prefinsert[$wmincPref . '-project'] = array( |
15 | 15 | 'type' => 'select', |
16 | | - 'options' => array( wfMsg( 'wminc-testwiki-none' ) => 'none', 'wikipedia' => 'p', 'wikibooks' => 'b', |
17 | | - 'wiktionary' => 't', 'wikiquote' => 'q', 'wikinews' => 'n', 'incubator' => 'inc' ), |
| 16 | + 'options' => array( wfMsg( 'wminc-testwiki-none' ) => 'none' ) + |
| 17 | + (array)$wmincProjects + array( $wmincProjectSite['name'] => $wmincProjectSite['short'] ), |
18 | 18 | 'section' => 'personal/i18n', |
19 | 19 | 'label-message' => 'wminc-testwiki', |
20 | 20 | 'id' => $wmincPref . '-project', |
— | — | @@ -38,9 +38,9 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | function codeValidation( $input, $alldata ) { |
42 | | - global $wmincPref; |
| 42 | + global $wmincPref, $wmincProjects; |
43 | 43 | // If the user selected a project that NEEDS a language code, but the user DID NOT enter a language code, give an error |
44 | | - if ( !in_array( $alldata[$wmincPref . '-project'], array( '', 'none', 'inc' ) ) && !$input ) { |
| 44 | + if ( isset( $alldata[$wmincPref.'-project'] ) && in_array( $alldata[$wmincPref.'-project'], $wmincProjects ) && !$input ) { |
45 | 45 | return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'wminc-prefinfo-error' ) ); |
46 | 46 | } else { |
47 | 47 | return true; |
— | — | @@ -48,13 +48,14 @@ |
49 | 49 | } |
50 | 50 | |
51 | 51 | function isNormalPrefix() { |
52 | | - global $wgUser, $wmincPref; |
53 | | - if ( in_array( $wgUser->getOption($wmincPref . '-project'), array( '', 'none', 'inc' ) ) ) { |
| 52 | + global $wgUser, $wmincPref, $wmincProjects; |
| 53 | + if ( in_array( $wgUser->getOption($wmincPref . '-project'), $wmincProjects ) ) { |
| 54 | + return true; // true because this is a normal prefix |
| 55 | + } else { |
54 | 56 | return false; // false because this is NOT a normal prefix |
55 | | - } else { |
56 | | - return true; // true because this is a normal prefix |
57 | 57 | } |
58 | 58 | } |
| 59 | + |
59 | 60 | function displayPrefix() { |
60 | 61 | // display the prefix of the user preference |
61 | 62 | global $wgUser, $wmincPref; |
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | |
7 | 7 | class TestWikiRC { |
8 | 8 | static function onRcQuery( &$conds, &$tables, &$join_conds, $opts ) { |
9 | | - global $wgUser, $wgRequest, $wmincPref; |
| 9 | + global $wgUser, $wgRequest, $wmincPref, $wmincProjectSite; |
10 | 10 | $projectvalue = strtolower( $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') ) ); |
11 | 11 | $codevalue = strtolower( $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') ) ); |
12 | 12 | $fullprefix = 'W' . $projectvalue . '/' . $codevalue; |
— | — | @@ -16,8 +16,8 @@ |
17 | 17 | if ( $projectvalue == 'none' OR $projectvalue == '' ) { |
18 | 18 | // If "none" is selected, display normal recent changes |
19 | 19 | return true; |
20 | | - } elseif ( $projectvalue == 'inc' ) { |
21 | | - // If "inc" (incubator) is selected, display all changes except test wiki changes |
| 20 | + } elseif ( $projectvalue == $wmincProjectSite['short'] ) { |
| 21 | + // If project site is selected, display all changes except test wiki changes |
22 | 22 | $conds[] = 'rc_title not like \'W_/%%\' OR \'W_/%%/%%\''; |
23 | 23 | return true; |
24 | 24 | } else { |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | } |
34 | 34 | |
35 | 35 | static function onRcForm( &$items, $opts ) { |
36 | | - global $wgUser, $wgRequest, $wmincPref; |
| 36 | + global $wgUser, $wgRequest, $wmincPref, $wmincProjects, $wmincProjectSite; |
37 | 37 | |
38 | 38 | $projectvalue = $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') ); |
39 | 39 | $langcodevalue = $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') ); |
— | — | @@ -41,12 +41,10 @@ |
42 | 42 | $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' ); |
43 | 43 | $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue ); |
44 | 44 | $select->addOption( wfMsg( 'wminc-testwiki-none' ), 'none' ); |
45 | | - $select->addOption( 'wikipedia', 'p' ); |
46 | | - $select->addOption( 'wikibooks', 'b' ); |
47 | | - $select->addOption( 'wiktionary', 't' ); |
48 | | - $select->addOption( 'wikiquote', 'q' ); |
49 | | - $select->addOption( 'wikinews', 'n' ); |
50 | | - $select->addOption( 'incubator', 'inc' ); |
| 45 | + foreach( $wmincProjects as $name => $prefix) { |
| 46 | + $select->addOption( $name, $prefix ); |
| 47 | + } |
| 48 | + $select->addOption( $wmincProjectSite['name'], $wmincProjectSite['short'] ); |
51 | 49 | $langcode = Xml::input( 'rc-testwiki-code', 3, $langcodevalue, array( 'id' => 'rc-testwiki-code', 'maxlength' => 3 ) ); |
52 | 50 | $items['testwiki'] = array( $label, $select->getHTML() . ' ' . $langcode ); |
53 | 51 | return true; |