http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98843

Revision: 98843
Author:   aaron
Date:     2011-10-04 01:24:05 +0000 (Tue, 04 Oct 2011)
Log Message:
-----------
* 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
    
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
    
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
    
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php

Modified: trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php
===================================================================
--- trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php        
2011-10-04 00:42:08 UTC (rev 98842)
+++ trunk/extensions/ConfirmAccount/dataclasses/ConfirmAccount.class.php        
2011-10-04 01:24:05 UTC (rev 98843)
@@ -200,4 +200,46 @@
        protected static function checkFileExtension( $ext, $list ) {
                return in_array( strtolower( $ext ), $list );
        }
+
+       /**
+        * Get the category to add to this users page for working in
+        * @return Array Associative mapping of the format:
+        *    (name => ('project' => x, 'userText' => y, 'grpUserText' => 
(request type => z)))
+        * Any of the ultimative values can be empty string
+        */
+       public static function getUserAreaConfig() {
+               static $res; // process cache
+               if ( $res !== null ) {
+                       return $res;
+               }
+               $res = array();
+               // Message describing the areas a user can be interested in, 
the corresponding wiki page,
+               // and any text that is automatically appended to the userpage 
on account acceptance.
+               // Format is <name> | <wikipage> [| <text for all>] [| <text 
group0>] [| <text group1>] ...
+               $msg = wfMessage( 'requestaccount-areas' )->inContentLanguage();
+               if ( $msg->exists() ) {
+                       $areas = explode( "\n*", "\n" . $msg->text() );
+                       foreach ( $areas as $n => $area ) {
+                               $set = explode( "|", $area );
+                               if ( count( $set ) >= 2 ) {
+                                       $name = trim( str_replace( '_', ' ', 
$set[0] ) );
+                                       $res[$name] = array();
+
+                                       $res[$name]['project'] = trim( $set[1] 
); // name => WikiProject mapping
+                                       if ( isset( $set[2] ) ) {
+                                               $res[$name]['userText'] = trim( 
$set[2] ); // userpage text for all
+                                       } else {
+                                               $res[$name]['userText'] = '';
+                                       }
+
+                                       $res[$name]['grpUserText'] = array(); 
// userpage text for certain request types
+                                       $categories = array_slice( $set, 3 ); 
// keys start from 0 now
+                                       foreach ( $categories as $i => $cat ) {
+                                               $res[$name]['grpUserText'][$i] 
= trim( $cat );
+                                       }
+                               }
+                       }
+               }
+               return $res;
+       }
 }

Modified: 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
===================================================================
--- 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
   2011-10-04 00:42:08 UTC (rev 98842)
+++ 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/ConfirmAccount_body.php
   2011-10-04 01:24:05 UTC (rev 98843)
@@ -52,30 +52,22 @@
                # Attachment file name to view
                $this->file = $request->getVal( 'file' );
 
-               # Load areas user plans to be active in...
-               # @FIXME: move this down and refactor
-               $this->reqAreas = $this->reqAreaSet = array();
-               if ( wfMsgForContent( 'requestaccount-areas' ) ) {
-                       $areas = 
explode("\n*","\n".wfMsg('requestaccount-areas'));
-                       foreach( $areas as $area ) {
-                               $set = explode("|",$area,2);
-                               if ( $set[0] && isset($set[1]) ) {
-                                       $formName = "wpArea-" . 
htmlspecialchars(str_replace(' ','_',$set[0]));
-                                       $this->reqAreas[$formName] = 
$request->getInt( $formName, -1 );
-                                       # Make a simple list of interests
-                                       if ( $this->reqAreas[$formName] > 0 ) {
-                                               $this->reqAreaSet[] = 
str_replace( '_', ' ', $set[0] );
-                                       }
-                               }
-                       }
-               }
-
                // Showing a file
                if ( $this->file ) {
                        $this->showFile( $this->file );
                        return; // nothing else to do
                // Showing or confirming an account request
                } elseif ( $this->acrID ) {
+                       # Load areas user plans to be active in...
+                       $this->reqAreas = $this->reqAreaSet = array();
+                       foreach ( ConfirmAccount::getUserAreaConfig() as $name 
=> $conf ) {
+                               $formName = "wpArea-" . htmlspecialchars( 
str_replace(' ','_', $name ) );
+                               $this->reqAreas[$formName] = $request->getInt( 
$formName, -1 );
+                               # Make a simple list of interests
+                               if ( $this->reqAreas[$formName] > 0 ) {
+                                       $this->reqAreaSet[] = $name;
+                               }
+                       }
                        if ( $request->wasPosted() ) {
                                # For renaming to alot for collisions with 
other local requests
                                # that were added to some global $wgAuth system 
first.
@@ -299,31 +291,30 @@
 
                $form .= '</table></fieldset>';
 
-               if( wfMsgForContent( 'requestaccount-areas' ) ) {
+               $userAreas = ConfirmAccount::getUserAreaConfig();
+               if ( count( $userAreas ) > 0 ) {
                        $form .= '<fieldset>';
                        $form .= '<legend>' . 
wfMsgHtml('confirmaccount-leg-areas') . '</legend>';
 
-                       $areas = 
explode("\n*","\n".wfMsg('requestaccount-areas'));
                        $form .= "<div style='height:150px; overflow:scroll; 
background-color:#f9f9f9;'>";
                        $form .= "<table cellspacing='5' cellpadding='0' 
style='background-color:#f9f9f9;'><tr valign='top'>";
                        $count = 0;
-                       foreach( $areas as $area ) {
-                               $set = explode("|",$area,3);
-                               if( $set[0] && isset($set[1]) ) {
-                                       $count++;
-                                       if( $count > 5 ) {
-                                               $form .= "</tr><tr 
valign='top'>";
-                                               $count = 1;
-                                       }
-                                       $formName = "wpArea-" . 
htmlspecialchars(str_replace(' ','_',$set[0]));
-                                       if( isset($set[1]) ) {
-                                               $pg = Linker::link( 
Title::newFromText( $set[1] ), wfMsgHtml('requestaccount-info'), array(), 
array(), "known" );
-                                       } else {
-                                               $pg = '';
-                                       }
-
-                                       $form .= "<td>".Xml::checkLabel( 
$set[0], $formName, $formName, $this->reqAreas[$formName] > 0 )." {$pg}</td>\n";
+                       foreach ( $userAreas as $name => $conf ) {
+                               $count++;
+                               if ( $count > 5 ) {
+                                       $form .= "</tr><tr valign='top'>";
+                                       $count = 1;
                                }
+                               $formName = "wpArea-" . htmlspecialchars( 
str_replace(' ','_', $name ) );
+                               if ( $conf['project'] != '' ) {
+                                       $pg = Linker::link( Title::newFromText( 
$conf['project'] ),
+                                               
wfMsgHtml('requestaccount-info'), array(), array(), "known" );
+                               } else {
+                                       $pg = '';
+                               }
+                               $form .= "<td>" .
+                                       Xml::checkLabel( $name, $formName, 
$formName, $this->reqAreas[$formName] > 0 ) .
+                                       " {$pg}</td>\n";
                        }
                        $form .= "</tr></table></div>";
                        $form .= '</fieldset>';
@@ -666,8 +657,8 @@
 
                        # Start up the user's (presumedly brand new) userpages
                        # Will not append, so previous content will be blanked
-                       global $wgMakeUserPageFroreqBio, $wgAutoUserBioText;
-                       if( $wgMakeUserPageFroreqBio ) {
+                       global $wgMakeUserPageFromBio, $wgAutoUserBioText;
+                       if( $wgMakeUserPageFromBio ) {
                                $usertitle = $user->getUserPage();
                                $userpage = new Article( $usertitle );
 
@@ -675,30 +666,30 @@
                                $body = $autotext ? 
"{$this->reqBio}\n\n{$autotext}" : $this->reqBio;
                                $body = $grouptext ? "{$body}\n\n{$grouptext}" 
: $body;
 
-                               # Add any interest categories
-                               if( wfMsgForContent( 'requestaccount-areas' ) ) 
{
-                                       $areas = 
explode("\n*","\n".wfMsg('requestaccount-areas'));
-                                       foreach( $areas as $line ) {
-                                               $set = explode("|",$line);
-                                               //$name = str_replace("_"," 
",$set[0]);
-                                               if( 
in_array($set[0],$this->reqAreaSet) ) {
-                                                       # General userpage text 
for anyone with this interest
-                                                       if( isset($set[2]) ) {
-                                                               $body .= 
$set[2];
-                                                       }
-                                                       # Message for users 
with this interested with the given account type
-                                                       # MW: message of format 
<name>|<wiki page>|<anyone>|<group0>|<group1>...
-                                                       if( 
isset($set[3+$this->reqType]) && $set[3+$this->reqType] ) {
-                                                               $body .= 
$set[3+$this->reqType];
-                                                       }
+                               # Add any areas of interest categories...
+                               foreach ( ConfirmAccount::getUserAreaConfig() 
as $name => $conf ) {
+                                       if ( in_array( $name, $this->reqAreaSet 
) ) {
+                                               # General userpage text for 
anyone with this interest
+                                               if ( $conf['userText'] != '' ) {
+                                                       $body .= 
$conf['userText'];
                                                }
+                                               # Message for users with this 
interested with the given account type
+                                               if ( isset( 
$conf['grpUserText'][$this->reqType] )
+                                                       && 
$conf['grpUserText'][$this->reqType] != '' )
+                                               {
+                                                       $body .= 
$conf['grpUserText'];
+                                               }
                                        }
                                }
 
                                # Set sortkey and use it on bio
                                global $wgConfirmAccountSortkey, $wgContLang;
                                if( !empty($wgConfirmAccountSortkey) ) {
-                                       $sortKey = 
preg_replace($wgConfirmAccountSortkey[0],$wgConfirmAccountSortkey[1],$usertitle->getText());
+                                       $sortKey = preg_replace(
+                                               $wgConfirmAccountSortkey[0],
+                                               $wgConfirmAccountSortkey[1],
+                                               $usertitle->getText()
+                                       );
                                        $body .= "\n{{DEFAULTSORT:{$sortKey}}}";
                                        # Clean up any other categories...
                                        $catNS = 
$wgContLang->getNSText(NS_CATEGORY);

Modified: 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
===================================================================
--- 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
   2011-10-04 00:42:08 UTC (rev 98842)
+++ 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/RequestAccount_body.php
   2011-10-04 01:24:05 UTC (rev 98843)
@@ -57,17 +57,12 @@
                $this->mType = isset( $wgAccountRequestTypes[$this->mType] ) ? 
$this->mType : 0;
                # Load areas user plans to be active in...
                $this->mAreas = $this->mAreaSet = array();
-               if ( wfMsg( 'requestaccount-areas' ) ) {
-                       $areas = explode( "\n*", "\n" . wfMsg( 
'requestaccount-areas' ) );
-                       foreach ( $areas as $area ) {
-                               $set = explode( "|", $area, 2 );
-                               if ( $set[0] && isset( $set[1] ) ) {
-                                       $formName = "wpArea-" . 
htmlspecialchars( str_replace( ' ', '_', $set[0] ) );
-                                       $this->mAreas[$formName] = 
$request->getInt( $formName, - 1 );
-                                       # Make a simple list of interests
-                                       if ( $this->mAreas[$formName] > 0 )
-                                               $this->mAreaSet[] = 
str_replace( '_', ' ', $set[0] );
-                               }
+               foreach ( ConfirmAccount::getUserAreaConfig() as $name => $conf 
) {
+                       $formName = "wpArea-" . htmlspecialchars( str_replace( 
' ', '_', $name ) );
+                       $this->mAreas[$formName] = $request->getInt( $formName, 
-1 );
+                       # Make a simple list of interests
+                       if ( $this->mAreas[$formName] > 0 ) {
+                               $this->mAreaSet[] = $name;
                        }
                }
                # We may be confirming an email address here
@@ -136,31 +131,31 @@
                }
                $form .= '</table></fieldset>';
 
-               if ( wfMsg( 'requestaccount-areas' ) ) {
+               $userAreas = ConfirmAccount::getUserAreaConfig();
+               if ( count( $userAreas ) > 0 ) {
                        $form .= '<fieldset>';
                        $form .= '<legend>' . wfMsgHtml( 
'requestaccount-leg-areas' ) . '</legend>';
                        $form .=  wfMsgExt( 'requestaccount-areas-text', array( 
'parse' ) ) . "\n";
 
-                       $areas = explode( "\n*", "\n" . wfMsg( 
'requestaccount-areas' ) );
                        $form .= "<div style='height:150px; overflow:scroll; 
background-color:#f9f9f9;'>";
                        $form .= "<table cellspacing='5' cellpadding='0' 
style='background-color:#f9f9f9;'><tr valign='top'>";
                        $count = 0;
-                       foreach ( $areas as $area ) {
-                               $set = explode( "|", $area, 3 );
-                               if ( $set[0] && isset( $set[1] ) ) {
-                                       $count++;
-                                       if ( $count > 5 ) {
-                                               $form .= "</tr><tr 
valign='top'>";
-                                               $count = 1;
-                                       }
-                                       $formName = "wpArea-" . 
htmlspecialchars( str_replace( ' ', '_', $set[0] ) );
-                                       if ( isset( $set[1] ) ) {
-                                               $pg = Linker::link( 
Title::newFromText( $set[1] ), wfMsgHtml( 'requestaccount-info' ), array(), 
array(), "known" );
-                                       } else {
-                                               $pg = '';
-                                       }
-                                       $form .= "<td>" . Xml::checkLabel( 
$set[0], $formName, $formName, $this->mAreas[$formName] > 0 ) . " {$pg}</td>\n";
+                       foreach ( $userAreas as $name => $conf ) {
+                               $count++;
+                               if ( $count > 5 ) {
+                                       $form .= "</tr><tr valign='top'>";
+                                       $count = 1;
                                }
+                               $formName = "wpArea-" . htmlspecialchars( 
str_replace( ' ', '_', $name ) );
+                               if ( $conf['project'] != '' ) {
+                                       $pg = Linker::link( Title::newFromText( 
$conf['project'] ),
+                                               wfMsgHtml( 
'requestaccount-info' ), array(), array(), "known" );
+                               } else {
+                                       $pg = '';
+                               }
+                               $form .= "<td>" .
+                                       Xml::checkLabel( $name, $formName, 
$formName, $this->mAreas[$formName] > 0 ) .
+                                       " {$pg}</td>\n";
                        }
                        $form .= "</tr></table></div>";
                        $form .= '</fieldset>';

Modified: 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php
===================================================================
--- 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php
  2011-10-04 00:42:08 UTC (rev 98842)
+++ 
trunk/extensions/ConfirmAccount/presentation/specialpages/actions/UserCredentials_body.php
  2011-10-04 01:24:05 UTC (rev 98843)
@@ -96,32 +96,32 @@
 
                $areaSet = UserAccountRequest::expandAreas( $row->acd_areas );
 
-               if ( wfMsg( 'requestaccount-areas' ) ) {
+               $userAreas = ConfirmAccount::getUserAreaConfig();
+               if ( count( $userAreas ) > 0 ) {
                        $form .= '<fieldset>';
                        $form .= '<legend>' . wfMsgHtml( 
'confirmaccount-leg-areas' ) . '</legend>';
 
-                       $areas = explode( "\n*", "\n" . wfMsg( 
'requestaccount-areas' ) );
                        $form .= "<div style='height:150px; overflow:scroll; 
background-color:#f9f9f9;'>";
                        $form .= "<table cellspacing='5' cellpadding='0' 
style='background-color:#f9f9f9;'><tr valign='top'>";
                        $count = 0;
 
                        $att = array( 'disabled' => 'disabled' );
-                       foreach ( $areas as $area ) {
-                               $set = explode( "|", $area, 3 );
-                               if ( $set[0] && isset( $set[1] ) ) {
-                                       $count++;
-                                       if ( $count > 5 ) {
-                                               $form .= "</tr><tr 
valign='top'>";
-                                               $count = 1;
-                                       }
-                                       $formName = "wpArea-" . 
htmlspecialchars( str_replace( ' ', '_', $set[0] ) );
-                                       if ( isset( $set[1] ) ) {
-                                               $pg = Linker::link( 
Title::newFromText( $set[1] ), wfMsgHtml( 'requestaccount-info' ), array(), 
array(), "known" );
-                                       } else {
-                                               $pg = '';
-                                       }
-                                       $form .= "<td>" . Xml::checkLabel( 
$set[0], $formName, $formName, in_array( $formName, $areaSet ), $att ) . " 
{$pg}</td>\n";
+                       foreach ( $userAreas as $name => $conf ) {
+                               $count++;
+                               if ( $count > 5 ) {
+                                       $form .= "</tr><tr valign='top'>";
+                                       $count = 1;
                                }
+                               $formName = "wpArea-" . htmlspecialchars( 
str_replace( ' ', '_', $name ) );
+                               if ( $conf['project'] != '' ) {
+                                       $pg = Linker::link( Title::newFromText( 
$name ),
+                                               wfMsgHtml( 
'requestaccount-info' ), array(), array(), "known" );
+                               } else {
+                                       $pg = '';
+                               }
+                               $form .= "<td>" .
+                                       Xml::checkLabel( $name, $formName, 
$formName, in_array( $formName, $areaSet ), $att ) .
+                                       " {$pg}</td>\n";
                        }
                        $form .= "</tr></table></div>";
                        $form .= '</fieldset>';


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to