r92554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92553‎ | r92554 | r92555 >
Date:19:27, 19 July 2011
Author:robin
Status:ok
Tags:
Comment:
Some formatting/documentation updates. For TestWikiRC, move parameter defining to separate function.
No functional changes.
Modified paths:
  • /trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/IncubatorTest.php (modified) (history)
  • /trunk/extensions/WikimediaIncubator/SpecialMyMainPage.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
@@ -7,6 +7,7 @@
88 *
99 * @file
1010 * @ingroup Extensions
 11+ * @author Robin Pepermans (SPQRobin)
1112 */
1213
1314 $wgExtensionCredits['other'][] = array(
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php
@@ -1,11 +1,16 @@
22 <?php
3 -/*
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)
9 -*/
 3+/**
 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)
 9+ *
 10+ * @file
 11+ * @ingroup Extensions
 12+ * @author Robin Pepermans (SPQRobin)
 13+ */
 14+
1015 class AutoTestWiki {
1116 public static function onUserCreateForm( $template ) {
1217 global $wgRequest, $wmincProjects;
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php
@@ -1,10 +1,20 @@
22 <?php
3 -/*
4 -* Implement test wiki preference, magic word and prefix check on edit page
5 -*/
 3+/**
 4+ * Main class of the WikimediaIncubator extension.
 5+ * Implement test wiki preference, magic word and prefix check on edit page,
 6+ * and contains general functions for other classes.
 7+ *
 8+ * @file
 9+ * @ingroup Extensions
 10+ * @author Robin Pepermans (SPQRobin)
 11+ */
612
7 -class IncubatorTest
8 -{
 13+class IncubatorTest {
 14+
 15+ /**
 16+ * Add preferences
 17+ * @return True
 18+ */
919 static function onGetPreferences( $user, &$preferences ) {
1020 global $wmincPref, $wmincProjects, $wmincProjectSite,
1121 $wmincLangCodeLength, $wgDefaultUserOptions;
@@ -13,8 +23,10 @@
1424
1525 $prefinsert[$wmincPref . '-project'] = array(
1626 'type' => 'select',
17 - 'options' => array( wfMsg( 'wminc-testwiki-none' ) => 'none' ) +
18 - (array)$wmincProjects + array( $wmincProjectSite['name'] => $wmincProjectSite['short'] ),
 27+ 'options' =>
 28+ array( wfMsg( 'wminc-testwiki-none' ) => 'none' ) +
 29+ (array)$wmincProjects +
 30+ array( $wmincProjectSite['name'] => $wmincProjectSite['short'] ),
1931 'section' => 'personal/i18n',
2032 'label-message' => 'wminc-testwiki',
2133 'id' => $wmincPref . '-project',
@@ -38,6 +50,10 @@
3951 return true;
4052 }
4153
 54+ /**
 55+ * For the preferences above
 56+ * @return String or true
 57+ */
4258 static function validateCodePreference( $input, $alldata ) {
4359 global $wmincPref, $wmincProjects;
4460 // If the user selected a project that NEEDS a language code, but the user DID NOT enter a language code, give an error
@@ -48,10 +64,11 @@
4965 }
5066 }
5167
52 - /*
53 - * This validates a given language code.
54 - * Only "xx[x]" and "xx[x]-x[xxxxxxxx]" are allowed.
55 - */
 68+ /**
 69+ * This validates a given language code.
 70+ * Only "xx[x]" and "xx[x]-x[xxxxxxxx]" are allowed.
 71+ * @return Boolean
 72+ */
5673 static function validateLanguageCode( $code ) {
5774 global $wmincLangCodeLength;
5875 if( strlen( $code ) > $wmincLangCodeLength ) { return false; }
@@ -59,16 +76,20 @@
6077 return (bool) preg_match( '/^[a-z][a-z][a-z]?(-[a-z]+)?$/', $code );
6178 }
6279
63 - /*
64 - * This validates a full prefix in a given title.
65 - * It gives an array with the project and language code, containing
66 - * the key 'error' if it is invalid.
67 - * Use validatePrefix() if you just want true or false.
68 - * Use displayPrefixedTitle() to make a prefix page title!
69 - *
70 - * @param $onlyprefix Bool Whether to validate only the prefix, or
71 - * also allow other text within the page title (Wx/xxx vs Wx/xxx/Text)
72 - */
 80+ /**
 81+ * This validates a full prefix in a given title.
 82+ * Do not include namespaces!
 83+ * It gives an array with the project and language code, containing
 84+ * the key 'error' if it is invalid.
 85+ * Use validatePrefix() if you just want true or false.
 86+ * Use displayPrefixedTitle() to make a prefix page title!
 87+ *
 88+ * @param $title String The given title (often $wgTitle->getText() )
 89+ * @param $onlyInfoPage Bool Whether to validate only the prefix, or
 90+ * also allow other text within the page title (Wx/xxx vs Wx/xxx/Text)
 91+ * @return Array with 'error' or 'project', 'lang', 'prefix' and
 92+ * optionally 'realtitle'
 93+ */
7394 static function analyzePrefix( $title, $onlyprefix = false ) {
7495 $data = array();
7596 // split title into parts
@@ -99,30 +120,33 @@
100121 return $data; // return an array with information
101122 }
102123
103 - /*
104 - * This returns simply true or false based on analyzePrefix().
105 - */
 124+ /**
 125+ * This returns simply true or false based on analyzePrefix().
 126+ * @return Boolean
 127+ */
106128 static function validatePrefix( $title, $onlyprefix = false ) {
107129 $data = self::analyzePrefix( $title, $onlyprefix );
108130 if( !isset( $data['error'] ) ) { return true; }
109131 return false;
110132 }
111133
112 - /*
113 - * Returns true if the given project (or preference
114 - * by default) is one of the projects using the
115 - * format Wx/xxx (as defined in $wmincProjects)
116 - */
 134+ /**
 135+ * Whether the given project (or preference by default) is one of the
 136+ * projects using the format Wx/xxx (as defined in $wmincProjects)
 137+ * @param $project the project code
 138+ * @return Boolean
 139+ */
117140 static function isContentProject( $project = '' ) {
118141 global $wgUser, $wmincPref, $wmincProjects;
119142 $project = ($project ? $project : $wgUser->getOption($wmincPref . '-project') );
120143 return (bool) in_array( $project, $wmincProjects );
121144 }
122145
123 - /*
124 - * display the prefix by the given project and code
125 - * (or the user preference if no parameters are given)
126 - */
 146+ /**
 147+ * display the prefix by the given project and code
 148+ * (or the user preference if no parameters are given)
 149+ * @return String
 150+ */
127151 static function displayPrefix( $project = '', $code = '' ) {
128152 global $wgUser, $wmincPref;
129153 $projectvalue = ( $project ? $project : $wgUser->getOption($wmincPref . '-project') );
@@ -138,10 +162,11 @@
139163 }
140164 }
141165
142 - /*
143 - * Makes a full prefixed title of a given page title and namespace
144 - * @param $ns Int numeric value of namespace
145 - */
 166+ /**
 167+ * Makes a full prefixed title of a given page title and namespace
 168+ * @param $ns Int numeric value of namespace
 169+ * @return object Title
 170+ */
146171 static function displayPrefixedTitle( $title, $ns = 0 ) {
147172 global $wgLang, $wmincTestWikiNamespaces;
148173 if( in_array( $ns, $wmincTestWikiNamespaces ) ) {
@@ -180,8 +205,10 @@
181206 return true;
182207 }
183208
184 - /* Return an error if the user wants to create an unprefixed page
185 - */
 209+ /**
 210+ * Return an error if the user wants to create an unprefixed page
 211+ * @return Boolean
 212+ */
186213 static function checkPrefixCreatePermissions( $title, $user, $action, &$result ) {
187214 global $wmincProjectSite, $wmincTestWikiNamespaces, $wmincPseudoCategoryNSes;
188215 $titletext = $title->getText();
@@ -221,9 +248,11 @@
222249 return false;
223250 }
224251
225 - /* Return an error if the user wants to move
226 - * an existing page to an unprefixed title
227 - */
 252+ /**
 253+ * Return an error if the user wants to move
 254+ * an existing page to an unprefixed title
 255+ * @return Boolean
 256+ */
228257 static function checkPrefixMovePermissions( $oldtitle, $newtitle, $user, &$error ) {
229258 global $wmincProjectSite, $wmincTestWikiNamespaces;
230259 $prefixdata = self::analyzePrefix( $newtitle->getText() );
@@ -244,11 +273,11 @@
245274 }
246275
247276 /**
248 - * Add a link to Special:ViewUserLang from Special:Contributions/USERNAME
249 - * if the user has 'viewuserlang' permission
250 - * Based on code from extension LookupUser made by Tim Starling
251 - * @return true
252 - */
 277+ * Add a link to Special:ViewUserLang from Special:Contributions/USERNAME
 278+ * if the user has 'viewuserlang' permission
 279+ * Based on code from extension LookupUser made by Tim Starling
 280+ * @return True
 281+ */
253282 static function efLoadViewUserLangLink( $id, $nt, &$links ) {
254283 global $wgUser;
255284 if ( $wgUser->isAllowed( 'viewuserlang' ) ) {
Index: trunk/extensions/WikimediaIncubator/SpecialMyMainPage.php
@@ -6,6 +6,7 @@
77 *
88 * @file
99 * @ingroup SpecialPage
 10+ * @author Robin Pepermans (SPQRobin)
1011 */
1112
1213 class SpecialMyMainPage extends UnlistedSpecialPage {
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php
@@ -1,13 +1,25 @@
22 <?php
3 -/*
4 -* Recent changes for a specific test wiki, or for all project changes (or normal display)
5 -*/
 3+/**
 4+ * Recent changes for a specific test wiki, or for all project changes (or normal display)
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @author Robin Pepermans (SPQRobin)
 9+ */
610
711 class TestWikiRC {
 12+ static function getValues() {
 13+ global $wgUser, $wmincPref, $wgRequest;
 14+ $projectvalue = $wgUser->getOption( $wmincPref . '-project' );
 15+ $codevalue = $wgUser->getOption( $wmincPref . '-code' );
 16+ $projectvalue = strtolower( $wgRequest->getVal( 'rc-testwiki-project', $projectvalue ) );
 17+ $codevalue = strtolower( $wgRequest->getVal( 'rc-testwiki-code', $codevalue ) );
 18+ return array( $projectvalue, $codevalue );
 19+ }
 20+
821 static function onRcQuery( &$conds, &$tables, &$join_conds, $opts ) {
9 - global $wgUser, $wgRequest, $wmincPref, $wmincProjectSite, $wmincTestWikiNamespaces;
10 - $projectvalue = strtolower( $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') ) );
11 - $codevalue = strtolower( $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') ) );
 22+ global $wmincProjectSite, $wmincTestWikiNamespaces;
 23+ list( $projectvalue, $codevalue ) = self::getValues();
1224 $prefix = IncubatorTest::displayPrefix( $projectvalue, $codevalue );
1325 $opts->add( 'rc-testwiki-project', false );
1426 $opts->setValue( 'rc-testwiki-project', $projectvalue );
@@ -33,20 +45,19 @@
3446 }
3547
3648 static function onRcForm( &$items, $opts ) {
37 - global $wgUser, $wgRequest, $wmincPref, $wmincProjects, $wmincProjectSite, $wmincLangCodeLength;
 49+ global $wmincProjects, $wmincProjectSite, $wmincLangCodeLength;
3850
39 - $projectvalue = $wgRequest->getVal( 'rc-testwiki-project', $wgUser->getOption($wmincPref . '-project') );
40 - $langcodevalue = $wgRequest->getVal( 'rc-testwiki-code', $wgUser->getOption($wmincPref . '-code') );
 51+ list( $projectvalue, $codevalue ) = self::getValues();
4152 $opts->consumeValue( 'rc-testwiki-project' );
4253 $opts->consumeValue( 'rc-testwiki-code' );
4354 $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' );
4455 $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue );
4556 $select->addOption( wfMsg( 'wminc-testwiki-none' ), 'none' );
46 - foreach( $wmincProjects as $name => $prefix) {
 57+ foreach( $wmincProjects as $name => $prefix ) {
4758 $select->addOption( $name, $prefix );
4859 }
4960 $select->addOption( $wmincProjectSite['name'], $wmincProjectSite['short'] );
50 - $langcode = Xml::input( 'rc-testwiki-code', (int)$wmincLangCodeLength, $langcodevalue,
 61+ $langcode = Xml::input( 'rc-testwiki-code', (int)$wmincLangCodeLength, $codevalue,
5162 array( 'id' => 'rc-testwiki-code', 'maxlength' => (int)$wmincLangCodeLength ) );
5263 $items['testwiki'] = array( $label, $select->getHTML() . ' ' . $langcode );
5364 return true;

Status & tagging log