Index: trunk/extensions/WikimediaIncubator/WikimediaIncubator.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | * |
9 | 9 | * @file |
10 | 10 | * @ingroup Extensions |
| 11 | + * @author Robin Pepermans (SPQRobin) |
11 | 12 | */ |
12 | 13 | |
13 | 14 | $wgExtensionCredits['other'][] = array( |
Index: trunk/extensions/WikimediaIncubator/CreateAccountTestWiki.php |
— | — | @@ -1,11 +1,16 @@ |
2 | 2 | <?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 | + |
10 | 15 | class AutoTestWiki { |
11 | 16 | public static function onUserCreateForm( $template ) { |
12 | 17 | global $wgRequest, $wmincProjects; |
Index: trunk/extensions/WikimediaIncubator/IncubatorTest.php |
— | — | @@ -1,10 +1,20 @@ |
2 | 2 | <?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 | + */ |
6 | 12 | |
7 | | -class IncubatorTest |
8 | | -{ |
| 13 | +class IncubatorTest { |
| 14 | + |
| 15 | + /** |
| 16 | + * Add preferences |
| 17 | + * @return True |
| 18 | + */ |
9 | 19 | static function onGetPreferences( $user, &$preferences ) { |
10 | 20 | global $wmincPref, $wmincProjects, $wmincProjectSite, |
11 | 21 | $wmincLangCodeLength, $wgDefaultUserOptions; |
— | — | @@ -13,8 +23,10 @@ |
14 | 24 | |
15 | 25 | $prefinsert[$wmincPref . '-project'] = array( |
16 | 26 | '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'] ), |
19 | 31 | 'section' => 'personal/i18n', |
20 | 32 | 'label-message' => 'wminc-testwiki', |
21 | 33 | 'id' => $wmincPref . '-project', |
— | — | @@ -38,6 +50,10 @@ |
39 | 51 | return true; |
40 | 52 | } |
41 | 53 | |
| 54 | + /** |
| 55 | + * For the preferences above |
| 56 | + * @return String or true |
| 57 | + */ |
42 | 58 | static function validateCodePreference( $input, $alldata ) { |
43 | 59 | global $wmincPref, $wmincProjects; |
44 | 60 | // 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 @@ |
49 | 65 | } |
50 | 66 | } |
51 | 67 | |
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 | + */ |
56 | 73 | static function validateLanguageCode( $code ) { |
57 | 74 | global $wmincLangCodeLength; |
58 | 75 | if( strlen( $code ) > $wmincLangCodeLength ) { return false; } |
— | — | @@ -59,16 +76,20 @@ |
60 | 77 | return (bool) preg_match( '/^[a-z][a-z][a-z]?(-[a-z]+)?$/', $code ); |
61 | 78 | } |
62 | 79 | |
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 | + */ |
73 | 94 | static function analyzePrefix( $title, $onlyprefix = false ) { |
74 | 95 | $data = array(); |
75 | 96 | // split title into parts |
— | — | @@ -99,30 +120,33 @@ |
100 | 121 | return $data; // return an array with information |
101 | 122 | } |
102 | 123 | |
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 | + */ |
106 | 128 | static function validatePrefix( $title, $onlyprefix = false ) { |
107 | 129 | $data = self::analyzePrefix( $title, $onlyprefix ); |
108 | 130 | if( !isset( $data['error'] ) ) { return true; } |
109 | 131 | return false; |
110 | 132 | } |
111 | 133 | |
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 | + */ |
117 | 140 | static function isContentProject( $project = '' ) { |
118 | 141 | global $wgUser, $wmincPref, $wmincProjects; |
119 | 142 | $project = ($project ? $project : $wgUser->getOption($wmincPref . '-project') ); |
120 | 143 | return (bool) in_array( $project, $wmincProjects ); |
121 | 144 | } |
122 | 145 | |
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 | + */ |
127 | 151 | static function displayPrefix( $project = '', $code = '' ) { |
128 | 152 | global $wgUser, $wmincPref; |
129 | 153 | $projectvalue = ( $project ? $project : $wgUser->getOption($wmincPref . '-project') ); |
— | — | @@ -138,10 +162,11 @@ |
139 | 163 | } |
140 | 164 | } |
141 | 165 | |
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 | + */ |
146 | 171 | static function displayPrefixedTitle( $title, $ns = 0 ) { |
147 | 172 | global $wgLang, $wmincTestWikiNamespaces; |
148 | 173 | if( in_array( $ns, $wmincTestWikiNamespaces ) ) { |
— | — | @@ -180,8 +205,10 @@ |
181 | 206 | return true; |
182 | 207 | } |
183 | 208 | |
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 | + */ |
186 | 213 | static function checkPrefixCreatePermissions( $title, $user, $action, &$result ) { |
187 | 214 | global $wmincProjectSite, $wmincTestWikiNamespaces, $wmincPseudoCategoryNSes; |
188 | 215 | $titletext = $title->getText(); |
— | — | @@ -221,9 +248,11 @@ |
222 | 249 | return false; |
223 | 250 | } |
224 | 251 | |
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 | + */ |
228 | 257 | static function checkPrefixMovePermissions( $oldtitle, $newtitle, $user, &$error ) { |
229 | 258 | global $wmincProjectSite, $wmincTestWikiNamespaces; |
230 | 259 | $prefixdata = self::analyzePrefix( $newtitle->getText() ); |
— | — | @@ -244,11 +273,11 @@ |
245 | 274 | } |
246 | 275 | |
247 | 276 | /** |
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 | + */ |
253 | 282 | static function efLoadViewUserLangLink( $id, $nt, &$links ) { |
254 | 283 | global $wgUser; |
255 | 284 | if ( $wgUser->isAllowed( 'viewuserlang' ) ) { |
Index: trunk/extensions/WikimediaIncubator/SpecialMyMainPage.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | * |
8 | 8 | * @file |
9 | 9 | * @ingroup SpecialPage |
| 10 | + * @author Robin Pepermans (SPQRobin) |
10 | 11 | */ |
11 | 12 | |
12 | 13 | class SpecialMyMainPage extends UnlistedSpecialPage { |
Index: trunk/extensions/WikimediaIncubator/TestWikiRC.php |
— | — | @@ -1,13 +1,25 @@ |
2 | 2 | <?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 | + */ |
6 | 10 | |
7 | 11 | 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 | + |
8 | 21 | 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(); |
12 | 24 | $prefix = IncubatorTest::displayPrefix( $projectvalue, $codevalue ); |
13 | 25 | $opts->add( 'rc-testwiki-project', false ); |
14 | 26 | $opts->setValue( 'rc-testwiki-project', $projectvalue ); |
— | — | @@ -33,20 +45,19 @@ |
34 | 46 | } |
35 | 47 | |
36 | 48 | static function onRcForm( &$items, $opts ) { |
37 | | - global $wgUser, $wgRequest, $wmincPref, $wmincProjects, $wmincProjectSite, $wmincLangCodeLength; |
| 49 | + global $wmincProjects, $wmincProjectSite, $wmincLangCodeLength; |
38 | 50 | |
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(); |
41 | 52 | $opts->consumeValue( 'rc-testwiki-project' ); |
42 | 53 | $opts->consumeValue( 'rc-testwiki-code' ); |
43 | 54 | $label = Xml::label( wfMsg( 'wminc-testwiki' ), 'rc-testwiki' ); |
44 | 55 | $select = new XmlSelect( 'rc-testwiki-project', 'rc-testwiki-project', $projectvalue ); |
45 | 56 | $select->addOption( wfMsg( 'wminc-testwiki-none' ), 'none' ); |
46 | | - foreach( $wmincProjects as $name => $prefix) { |
| 57 | + foreach( $wmincProjects as $name => $prefix ) { |
47 | 58 | $select->addOption( $name, $prefix ); |
48 | 59 | } |
49 | 60 | $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, |
51 | 62 | array( 'id' => 'rc-testwiki-code', 'maxlength' => (int)$wmincLangCodeLength ) ); |
52 | 63 | $items['testwiki'] = array( $label, $select->getHTML() . ' ' . $langcode ); |
53 | 64 | return true; |