r98843 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98842‎ | r98843 | r98844 >
Date:01:24, 4 October 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Fixed misspelt $wgMakeUserPageFromBio instances
* Reduced legally obscene amount of code duplication around mangling requestacount-areas.
* Added FIXME comment
Modified paths:
  • /trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php
@@ -200,4 +200,46 @@
201201 protected static function checkFileExtension( $ext, $list ) {
202202 return in_array( strtolower( $ext ), $list );
203203 }
 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+ }
204246 }
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php
@@ -96,32 +96,32 @@
9797
9898 $areaSet = UserAccountRequest::expandAreas( $row->acd_areas );
9999
100 - if ( wfMsg( 'requestaccount-areas' ) ) {
 100+ $userAreas = ConfirmAccount::getUserAreaConfig();
 101+ if ( count( $userAreas ) > 0 ) {
101102 $form .= '<fieldset>';
102103 $form .= '<legend>' . wfMsgHtml( 'confirmaccount-leg-areas' ) . '</legend>';
103104
104 - $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) );
105105 $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>";
106106 $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>";
107107 $count = 0;
108108
109109 $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;
125115 }
 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";
126126 }
127127 $form .= "</tr></table></div>";
128128 $form .= '</fieldset>';
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
@@ -57,17 +57,12 @@
5858 $this->mType = isset( $wgAccountRequestTypes[$this->mType] ) ? $this->mType : 0;
5959 # Load areas user plans to be active in...
6060 $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;
7267 }
7368 }
7469 # We may be confirming an email address here
@@ -136,31 +131,31 @@
137132 }
138133 $form .= '</table></fieldset>';
139134
140 - if ( wfMsg( 'requestaccount-areas' ) ) {
 135+ $userAreas = ConfirmAccount::getUserAreaConfig();
 136+ if ( count( $userAreas ) > 0 ) {
141137 $form .= '<fieldset>';
142138 $form .= '<legend>' . wfMsgHtml( 'requestaccount-leg-areas' ) . '</legend>';
143139 $form .= wfMsgExt( 'requestaccount-areas-text', array( 'parse' ) ) . "\n";
144140
145 - $areas = explode( "\n*", "\n" . wfMsg( 'requestaccount-areas' ) );
146141 $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>";
147142 $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>";
148143 $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;
164149 }
 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";
165160 }
166161 $form .= "</tr></table></div>";
167162 $form .= '</fieldset>';
Index: trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
@@ -52,30 +52,22 @@
5353 # Attachment file name to view
5454 $this->file = $request->getVal( 'file' );
5555
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 -
7456 // Showing a file
7557 if ( $this->file ) {
7658 $this->showFile( $this->file );
7759 return; // nothing else to do
7860 // Showing or confirming an account request
7961 } 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+ }
8072 if ( $request->wasPosted() ) {
8173 # For renaming to alot for collisions with other local requests
8274 # that were added to some global $wgAuth system first.
@@ -299,31 +291,30 @@
300292
301293 $form .= '</table></fieldset>';
302294
303 - if( wfMsgForContent( 'requestaccount-areas' ) ) {
 295+ $userAreas = ConfirmAccount::getUserAreaConfig();
 296+ if ( count( $userAreas ) > 0 ) {
304297 $form .= '<fieldset>';
305298 $form .= '<legend>' . wfMsgHtml('confirmaccount-leg-areas') . '</legend>';
306299
307 - $areas = explode("\n*","\n".wfMsg('requestaccount-areas'));
308300 $form .= "<div style='height:150px; overflow:scroll; background-color:#f9f9f9;'>";
309301 $form .= "<table cellspacing='5' cellpadding='0' style='background-color:#f9f9f9;'><tr valign='top'>";
310302 $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;
327308 }
 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";
328319 }
329320 $form .= "</tr></table></div>";
330321 $form .= '</fieldset>';
@@ -666,8 +657,8 @@
667658
668659 # Start up the user's (presumedly brand new) userpages
669660 # Will not append, so previous content will be blanked
670 - global $wgMakeUserPageFroreqBio, $wgAutoUserBioText;
671 - if( $wgMakeUserPageFroreqBio ) {
 661+ global $wgMakeUserPageFromBio, $wgAutoUserBioText;
 662+ if( $wgMakeUserPageFromBio ) {
672663 $usertitle = $user->getUserPage();
673664 $userpage = new Article( $usertitle );
674665
@@ -675,30 +666,30 @@
676667 $body = $autotext ? "{$this->reqBio}\n\n{$autotext}" : $this->reqBio;
677668 $body = $grouptext ? "{$body}\n\n{$grouptext}" : $body;
678669
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'];
695676 }
 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+ }
696683 }
697684 }
698685
699686 # Set sortkey and use it on bio
700687 global $wgConfirmAccountSortkey, $wgContLang;
701688 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+ );
703694 $body .= "\n{{DEFAULTSORT:{$sortKey}}}";
704695 # Clean up any other categories...
705696 $catNS = $wgContLang->getNSText(NS_CATEGORY);

Status & tagging log