r86856 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86855‎ | r86856 | r86857 >
Date:13:26, 25 April 2011
Author:robin
Status:ok
Tags:
Comment:
* Add $wmincProjects and $wmincProjectSite arrays that can be re-used in the code
* RandomByTest gives project/help pages when using project site (=incubator) preference
Modified paths:
  • /trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/SpecialRandomByTest.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
@@ -11,7 +11,7 @@
1212 'path' => __FILE__,
1313 'name' => 'Wikimedia Incubator',
1414 'author' => 'SPQRobin',
15 - 'version' => '2.3.3',
 15+ 'version' => '2.4',
1616 'url' => 'http://www.mediawiki.org/wiki/Extension:WikimediaIncubator',
1717 'descriptionmsg' => 'wminc-desc',
1818 );
@@ -20,9 +20,21 @@
2121 $wgGroupPermissions['*']['viewuserlang'] = false;
2222 $wgGroupPermissions['sysop']['viewuserlang'] = true;
2323
24 -/* General */
 24+/* General (kind of globals) */
2525 $wmincPref = 'incubatortestwiki'; // Name of the preference
2626 $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+
2739 $wgExtensionMessagesFiles['WikimediaIncubator'] = $dir . 'WikimediaIncubator.i18n.php';
2840
2941 /* Special:ViewUserLang */
Index: trunk/extensions/WikimediaIncubator/SpecialRandomByTest.php
@@ -7,11 +7,13 @@
88 class SpecialRandomByTest extends RandomPage
99 {
1010 public function __construct() {
11 - global $wgUser, $wmincPref;
 11+ global $wgUser, $wmincPref, $wmincProjectSite;
1212 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 );
1618 }
1719 parent::__construct( 'RandomByTest' );
1820 }
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php
@@ -1,14 +1,17 @@
22 <?php
33 /*
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)
69 */
710 class AutoTestWiki {
811 function onUserCreateForm( $template ) {
9 - global $wgRequest;
 12+ global $wgRequest, $wmincProjects;
1013 $projectvalue = strtolower( $wgRequest->getVal( 'testwikiproject', '' ) );
1114 $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 ) ) {
1316 $template->set( 'header', '<input type="hidden" name="testwiki-project" value="' . $projectvalue . '" />
1417 <input type="hidden" name="testwiki-code" value="' . $codevalue . '" />
1518 ' );
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -6,14 +6,14 @@
77 class IncubatorTest
88 {
99 static function onGetPreferences( $user, &$preferences ) {
10 - global $wmincPref, $wmincPrefProject, $wmincPrefNone, $wgDefaultUserOptions;
 10+ global $wmincPref, $wmincProjects, $wmincProjectSite, $wmincPrefProject, $wmincPrefNone, $wgDefaultUserOptions;
1111
1212 $preferences['language']['help-message'] = 'wminc-prefinfo-language';
1313
1414 $prefinsert[$wmincPref . '-project'] = array(
1515 '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'] ),
1818 'section' => 'personal/i18n',
1919 'label-message' => 'wminc-testwiki',
2020 'id' => $wmincPref . '-project',
@@ -38,9 +38,9 @@
3939 }
4040
4141 function codeValidation( $input, $alldata ) {
42 - global $wmincPref;
 42+ global $wmincPref, $wmincProjects;
4343 // 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 ) {
4545 return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'wminc-prefinfo-error' ) );
4646 } else {
4747 return true;
@@ -48,13 +48,14 @@
4949 }
5050
5151 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 {
5456 return false; // false because this is NOT a normal prefix
55 - } else {
56 - return true; // true because this is a normal prefix
5757 }
5858 }
 59+
5960 function displayPrefix() {
6061 // display the prefix of the user preference
6162 global $wgUser, $wmincPref;
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php
@@ -5,7 +5,7 @@
66
77 class TestWikiRC {
88 static function onRcQuery( &$conds, &$tables, &$join_conds, $opts ) {
9 - global $wgUser, $wgRequest, $wmincPref;
 9+ global $wgUser, $wgRequest, $wmincPref, $wmincProjectSite;
1010 $projectvalue = strtolower( $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') ) );
1111 $codevalue = strtolower( $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') ) );
1212 $fullprefix = 'W' . $projectvalue . '/' . $codevalue;
@@ -16,8 +16,8 @@
1717 if ( $projectvalue == 'none' OR $projectvalue == '' ) {
1818 // If "none" is selected, display normal recent changes
1919 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
2222 $conds[] = 'rc_title not like \'W_/%%\' OR \'W_/%%/%%\'';
2323 return true;
2424 } else {
@@ -32,7 +32,7 @@
3333 }
3434
3535 static function onRcForm( &$items, $opts ) {
36 - global $wgUser, $wgRequest, $wmincPref;
 36+ global $wgUser, $wgRequest, $wmincPref, $wmincProjects, $wmincProjectSite;
3737
3838 $projectvalue = $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') );
3939 $langcodevalue = $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') );
@@ -41,12 +41,10 @@
4242 $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' );
4343 $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue );
4444 $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'] );
5149 $langcode = Xml::input( 'rc-testwiki-code', 3, $langcodevalue, array( 'id' => 'rc-testwiki-code', 'maxlength' => 3 ) );
5250 $items['testwiki'] = array( $label, $select->getHTML() . ' ' . $langcode );
5351 return true;

Status & tagging log