Index: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php |
— | — | @@ -200,4 +200,46 @@ |
201 | 201 | protected static function checkFileExtension( $ext, $list ) { |
202 | 202 | return in_array( strtolower( $ext ), $list ); |
203 | 203 | } |
| 204 | + |
| 205 | + /** |
| 206 | + * Get the category to add to this users page for working in |
| 207 | + * @return Array Associative mapping of the format: |
| 208 | + * (name => ('project' => x, 'userText' => y, 'grpUserText' => (request type => z))) |
| 209 | + * Any of the ultimative values can be empty string |
| 210 | + */ |
| 211 | + public static function getUserAreaConfig() { |
| 212 | + static $res; // process cache |
| 213 | + if ( $res !== null ) { |
| 214 | + return $res; |
| 215 | + } |
| 216 | + $res = array(); |
| 217 | + // Message describing the areas a user can be interested in, the corresponding wiki page, |
| 218 | + // and any text that is automatically appended to the userpage on account acceptance. |
| 219 | + // Format is <name> | <wikipage> [| <text for all>] [| <text group0>] [| <text group1>] ... |
| 220 | + $msg = wfMessage( 'requestaccount-areas' )->inContentLanguage(); |
| 221 | + if ( $msg->exists() ) { |
| 222 | + $areas = explode( "\n*", "\n" . $msg->text() ); |
| 223 | + foreach ( $areas as $n => $area ) { |
| 224 | + $set = explode( "|", $area ); |
| 225 | + if ( count( $set ) >= 2 ) { |
| 226 | + $name = trim( str_replace( '_', ' ', $set[0] ) ); |
| 227 | + $res[$name] = array(); |
| 228 | + |
| 229 | + $res[$name]['project'] = trim( $set[1] ); // name => WikiProject mapping |
| 230 | + if ( isset( $set[2] ) ) { |
| 231 | + $res[$name]['userText'] = trim( $set[2] ); // userpage text for all |
| 232 | + } else { |
| 233 | + $res[$name]['userText'] = ''; |
| 234 | + } |
| 235 | + |
| 236 | + $res[$name]['grpUserText'] = array(); // userpage text for certain request types |
| 237 | + $categories = array_slice( $set, 3 ); // keys start from 0 now |
| 238 | + foreach ( $categories as $i => $cat ) { |
| 239 | + $res[$name]['grpUserText'][$i] = trim( $cat ); |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + } |
| 244 | + return $res; |
| 245 | + } |
204 | 246 | } |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php |
— | — | @@ -96,32 +96,32 @@ |
97 | 97 | |
98 | 98 | $areaSet = UserAccountRequest::expandAreas( $row->acd_areas ); |
99 | 99 | |
100 | | - if ( wfMsg( 'requestaccount-areas' ) ) { |
| 100 | + $userAreas = ConfirmAccount::getUserAreaConfig(); |
| 101 | + if ( count( $userAreas ) > 0 ) { |
101 | 102 | $form .= '<fieldset>'; |
102 | 103 | $form .= '<legend>' . wfMsgHtml( 'confirmaccount-leg-areas' ) . '</legend>'; |
103 | 104 | |
104 | | - $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) ); |
105 | 105 | $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>"; |
106 | 106 | $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>"; |
107 | 107 | $count = 0; |
108 | 108 | |
109 | 109 | $att = array( 'disabled' => 'disabled' ); |
110 | | - foreach ( $areas as $area ) { |
111 | | - $set = explode( "|", $area, 3 ); |
112 | | - if ( $set[0] && isset( $set[1] ) ) { |
113 | | - $count++; |
114 | | - if ( $count > 5 ) { |
115 | | - $form .= "</tr><tr valign='top'>"; |
116 | | - $count = 1; |
117 | | - } |
118 | | - $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $set[0] ) ); |
119 | | - if ( isset( $set[1] ) ) { |
120 | | - $pg = Linker::link( Title::newFromText( $set[1] ), wfMsgHtml( 'requestaccount-info' ), array(), array(), "known" ); |
121 | | - } else { |
122 | | - $pg = ''; |
123 | | - } |
124 | | - $form .= "<td>" . Xml::checkLabel( $set[0], $formName, $formName, in_array( $formName, $areaSet ), $att ) . " {$pg}</td>\n"; |
| 110 | + foreach ( $userAreas as $name => $conf ) { |
| 111 | + $count++; |
| 112 | + if ( $count > 5 ) { |
| 113 | + $form .= "</tr><tr valign='top'>"; |
| 114 | + $count = 1; |
125 | 115 | } |
| 116 | + $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $name ) ); |
| 117 | + if ( $conf['project'] != '' ) { |
| 118 | + $pg = Linker::link( Title::newFromText( $name ), |
| 119 | + wfMsgHtml( 'requestaccount-info' ), array(), array(), "known" ); |
| 120 | + } else { |
| 121 | + $pg = ''; |
| 122 | + } |
| 123 | + $form .= "<td>" . |
| 124 | + Xml::checkLabel( $name, $formName, $formName, in_array( $formName, $areaSet ), $att ) . |
| 125 | + " {$pg}</td>\n"; |
126 | 126 | } |
127 | 127 | $form .= "</tr></table></div>"; |
128 | 128 | $form .= '</fieldset>'; |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php |
— | — | @@ -57,17 +57,12 @@ |
58 | 58 | $this->mType = isset( $wgAccountRequestTypes[$this->mType] ) ? $this->mType : 0; |
59 | 59 | # Load areas user plans to be active in... |
60 | 60 | $this->mAreas = $this->mAreaSet = array(); |
61 | | - if ( wfMsg( 'requestaccount-areas' ) ) { |
62 | | - $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) ); |
63 | | - foreach ( $areas as $area ) { |
64 | | - $set = explode( "|", $area, 2 ); |
65 | | - if ( $set[0] && isset( $set[1] ) ) { |
66 | | - $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $set[0] ) ); |
67 | | - $this->mAreas[$formName] = $request->getInt( $formName, - 1 ); |
68 | | - # Make a simple list of interests |
69 | | - if ( $this->mAreas[$formName] > 0 ) |
70 | | - $this->mAreaSet[] = str_replace( '_', ' ', $set[0] ); |
71 | | - } |
| 61 | + foreach ( ConfirmAccount::getUserAreaConfig() as $name => $conf ) { |
| 62 | + $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $name ) ); |
| 63 | + $this->mAreas[$formName] = $request->getInt( $formName, -1 ); |
| 64 | + # Make a simple list of interests |
| 65 | + if ( $this->mAreas[$formName] > 0 ) { |
| 66 | + $this->mAreaSet[] = $name; |
72 | 67 | } |
73 | 68 | } |
74 | 69 | # We may be confirming an email address here |
— | — | @@ -136,31 +131,31 @@ |
137 | 132 | } |
138 | 133 | $form .= '</table></fieldset>'; |
139 | 134 | |
140 | | - if ( wfMsg( 'requestaccount-areas' ) ) { |
| 135 | + $userAreas = ConfirmAccount::getUserAreaConfig(); |
| 136 | + if ( count( $userAreas ) > 0 ) { |
141 | 137 | $form .= '<fieldset>'; |
142 | 138 | $form .= '<legend>' . wfMsgHtml( 'requestaccount-leg-areas' ) . '</legend>'; |
143 | 139 | $form .= wfMsgExt( 'requestaccount-areas-text', array( 'parse' ) ) . "\n"; |
144 | 140 | |
145 | | - $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) ); |
146 | 141 | $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>"; |
147 | 142 | $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>"; |
148 | 143 | $count = 0; |
149 | | - foreach ( $areas as $area ) { |
150 | | - $set = explode( "|", $area, 3 ); |
151 | | - if ( $set[0] && isset( $set[1] ) ) { |
152 | | - $count++; |
153 | | - if ( $count > 5 ) { |
154 | | - $form .= "</tr><tr valign='top'>"; |
155 | | - $count = 1; |
156 | | - } |
157 | | - $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $set[0] ) ); |
158 | | - if ( isset( $set[1] ) ) { |
159 | | - $pg = Linker::link( Title::newFromText( $set[1] ), wfMsgHtml( 'requestaccount-info' ), array(), array(), "known" ); |
160 | | - } else { |
161 | | - $pg = ''; |
162 | | - } |
163 | | - $form .= "<td>" . Xml::checkLabel( $set[0], $formName, $formName, $this->mAreas[$formName] > 0 ) . " {$pg}</td>\n"; |
| 144 | + foreach ( $userAreas as $name => $conf ) { |
| 145 | + $count++; |
| 146 | + if ( $count > 5 ) { |
| 147 | + $form .= "</tr><tr valign='top'>"; |
| 148 | + $count = 1; |
164 | 149 | } |
| 150 | + $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $name ) ); |
| 151 | + if ( $conf['project'] != '' ) { |
| 152 | + $pg = Linker::link( Title::newFromText( $conf['project'] ), |
| 153 | + wfMsgHtml( 'requestaccount-info' ), array(), array(), "known" ); |
| 154 | + } else { |
| 155 | + $pg = ''; |
| 156 | + } |
| 157 | + $form .= "<td>" . |
| 158 | + Xml::checkLabel( $name, $formName, $formName, $this->mAreas[$formName] > 0 ) . |
| 159 | + " {$pg}</td>\n"; |
165 | 160 | } |
166 | 161 | $form .= "</tr></table></div>"; |
167 | 162 | $form .= '</fieldset>'; |
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php |
— | — | @@ -52,30 +52,22 @@ |
53 | 53 | # Attachment file name to view |
54 | 54 | $this->file = $request->getVal( 'file' ); |
55 | 55 | |
56 | | - # Load areas user plans to be active in... |
57 | | - # @FIXME: move this down and refactor |
58 | | - $this->reqAreas = $this->reqAreaSet = array(); |
59 | | - if ( wfMsgForContent( 'requestaccount-areas' ) ) { |
60 | | - $areas = explode("\n*","\n".wfMsg('requestaccount-areas')); |
61 | | - foreach( $areas as $area ) { |
62 | | - $set = explode("|",$area,2); |
63 | | - if ( $set[0] && isset($set[1]) ) { |
64 | | - $formName = "wpArea-" . htmlspecialchars(str_replace(' ','_',$set[0])); |
65 | | - $this->reqAreas[$formName] = $request->getInt( $formName, -1 ); |
66 | | - # Make a simple list of interests |
67 | | - if ( $this->reqAreas[$formName] > 0 ) { |
68 | | - $this->reqAreaSet[] = str_replace( '_', ' ', $set[0] ); |
69 | | - } |
70 | | - } |
71 | | - } |
72 | | - } |
73 | | - |
74 | 56 | // Showing a file |
75 | 57 | if ( $this->file ) { |
76 | 58 | $this->showFile( $this->file ); |
77 | 59 | return; // nothing else to do |
78 | 60 | // Showing or confirming an account request |
79 | 61 | } elseif ( $this->acrID ) { |
| 62 | + # Load areas user plans to be active in... |
| 63 | + $this->reqAreas = $this->reqAreaSet = array(); |
| 64 | + foreach ( ConfirmAccount::getUserAreaConfig() as $name => $conf ) { |
| 65 | + $formName = "wpArea-" . htmlspecialchars( str_replace(' ','_', $name ) ); |
| 66 | + $this->reqAreas[$formName] = $request->getInt( $formName, -1 ); |
| 67 | + # Make a simple list of interests |
| 68 | + if ( $this->reqAreas[$formName] > 0 ) { |
| 69 | + $this->reqAreaSet[] = $name; |
| 70 | + } |
| 71 | + } |
80 | 72 | if ( $request->wasPosted() ) { |
81 | 73 | # For renaming to alot for collisions with other local requests |
82 | 74 | # that were added to some global $wgAuth system first. |
— | — | @@ -299,31 +291,30 @@ |
300 | 292 | |
301 | 293 | $form .= '</table></fieldset>'; |
302 | 294 | |
303 | | - if( wfMsgForContent( 'requestaccount-areas' ) ) { |
| 295 | + $userAreas = ConfirmAccount::getUserAreaConfig(); |
| 296 | + if ( count( $userAreas ) > 0 ) { |
304 | 297 | $form .= '<fieldset>'; |
305 | 298 | $form .= '<legend>' . wfMsgHtml('confirmaccount-leg-areas') . '</legend>'; |
306 | 299 | |
307 | | - $areas = explode("\n*","\n".wfMsg('requestaccount-areas')); |
308 | 300 | $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>"; |
309 | 301 | $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>"; |
310 | 302 | $count = 0; |
311 | | - foreach( $areas as $area ) { |
312 | | - $set = explode("|",$area,3); |
313 | | - if( $set[0] && isset($set[1]) ) { |
314 | | - $count++; |
315 | | - if( $count > 5 ) { |
316 | | - $form .= "</tr><tr valign='top'>"; |
317 | | - $count = 1; |
318 | | - } |
319 | | - $formName = "wpArea-" . htmlspecialchars(str_replace(' ','_',$set[0])); |
320 | | - if( isset($set[1]) ) { |
321 | | - $pg = Linker::link( Title::newFromText( $set[1] ), wfMsgHtml('requestaccount-info'), array(), array(), "known" ); |
322 | | - } else { |
323 | | - $pg = ''; |
324 | | - } |
325 | | - |
326 | | - $form .= "<td>".Xml::checkLabel( $set[0], $formName, $formName, $this->reqAreas[$formName] > 0 )." {$pg}</td>\n"; |
| 303 | + foreach ( $userAreas as $name => $conf ) { |
| 304 | + $count++; |
| 305 | + if ( $count > 5 ) { |
| 306 | + $form .= "</tr><tr valign='top'>"; |
| 307 | + $count = 1; |
327 | 308 | } |
| 309 | + $formName = "wpArea-" . htmlspecialchars( str_replace(' ','_', $name ) ); |
| 310 | + if ( $conf['project'] != '' ) { |
| 311 | + $pg = Linker::link( Title::newFromText( $conf['project'] ), |
| 312 | + wfMsgHtml('requestaccount-info'), array(), array(), "known" ); |
| 313 | + } else { |
| 314 | + $pg = ''; |
| 315 | + } |
| 316 | + $form .= "<td>" . |
| 317 | + Xml::checkLabel( $name, $formName, $formName, $this->reqAreas[$formName] > 0 ) . |
| 318 | + " {$pg}</td>\n"; |
328 | 319 | } |
329 | 320 | $form .= "</tr></table></div>"; |
330 | 321 | $form .= '</fieldset>'; |
— | — | @@ -666,8 +657,8 @@ |
667 | 658 | |
668 | 659 | # Start up the user's (presumedly brand new) userpages |
669 | 660 | # Will not append, so previous content will be blanked |
670 | | - global $wgMakeUserPageFroreqBio, $wgAutoUserBioText; |
671 | | - if( $wgMakeUserPageFroreqBio ) { |
| 661 | + global $wgMakeUserPageFromBio, $wgAutoUserBioText; |
| 662 | + if( $wgMakeUserPageFromBio ) { |
672 | 663 | $usertitle = $user->getUserPage(); |
673 | 664 | $userpage = new Article( $usertitle ); |
674 | 665 | |
— | — | @@ -675,30 +666,30 @@ |
676 | 667 | $body = $autotext ? "{$this->reqBio}\n\n{$autotext}" : $this->reqBio; |
677 | 668 | $body = $grouptext ? "{$body}\n\n{$grouptext}" : $body; |
678 | 669 | |
679 | | - # Add any interest categories |
680 | | - if( wfMsgForContent( 'requestaccount-areas' ) ) { |
681 | | - $areas = explode("\n*","\n".wfMsg('requestaccount-areas')); |
682 | | - foreach( $areas as $line ) { |
683 | | - $set = explode("|",$line); |
684 | | - //$name = str_replace("_"," ",$set[0]); |
685 | | - if( in_array($set[0],$this->reqAreaSet) ) { |
686 | | - # General userpage text for anyone with this interest |
687 | | - if( isset($set[2]) ) { |
688 | | - $body .= $set[2]; |
689 | | - } |
690 | | - # Message for users with this interested with the given account type |
691 | | - # MW: message of format <name>|<wiki page>|<anyone>|<group0>|<group1>... |
692 | | - if( isset($set[3+$this->reqType]) && $set[3+$this->reqType] ) { |
693 | | - $body .= $set[3+$this->reqType]; |
694 | | - } |
| 670 | + # Add any areas of interest categories... |
| 671 | + foreach ( ConfirmAccount::getUserAreaConfig() as $name => $conf ) { |
| 672 | + if ( in_array( $name, $this->reqAreaSet ) ) { |
| 673 | + # General userpage text for anyone with this interest |
| 674 | + if ( $conf['userText'] != '' ) { |
| 675 | + $body .= $conf['userText']; |
695 | 676 | } |
| 677 | + # Message for users with this interested with the given account type |
| 678 | + if ( isset( $conf['grpUserText'][$this->reqType] ) |
| 679 | + && $conf['grpUserText'][$this->reqType] != '' ) |
| 680 | + { |
| 681 | + $body .= $conf['grpUserText']; |
| 682 | + } |
696 | 683 | } |
697 | 684 | } |
698 | 685 | |
699 | 686 | # Set sortkey and use it on bio |
700 | 687 | global $wgConfirmAccountSortkey, $wgContLang; |
701 | 688 | if( !empty($wgConfirmAccountSortkey) ) { |
702 | | - $sortKey = preg_replace($wgConfirmAccountSortkey[0],$wgConfirmAccountSortkey[1],$usertitle->getText()); |
| 689 | + $sortKey = preg_replace( |
| 690 | + $wgConfirmAccountSortkey[0], |
| 691 | + $wgConfirmAccountSortkey[1], |
| 692 | + $usertitle->getText() |
| 693 | + ); |
703 | 694 | $body .= "\n{{DEFAULTSORT:{$sortKey}}}"; |
704 | 695 | # Clean up any other categories... |
705 | 696 | $catNS = $wgContLang->getNSText(NS_CATEGORY); |