fixed Special:Userrights log, and a few other Special:Userrights problems
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 14 May 2005 05:42:47 +0000 (05:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 14 May 2005 05:42:47 +0000 (05:42 +0000)
includes/HTMLForm.php
includes/SpecialUserrights.php
languages/Language.php

index 54bbb81..b15e70d 100644 (file)
  */
 class HTMLForm {
        /** name of our form. Used as prefix for labels */
-       var $mName;
+       var $mName, $mRequest;
+
+       function HTMLForm( &$request ) {
+               $this->mRequest = $request;
+       }
 
        /**
         * @access private
@@ -32,7 +36,9 @@ class HTMLForm {
         * @param boolean $checked Set true to check the box (default False).
         */
        function checkbox( $varname, $checked=false ) {
-               $checked = isset( $_POST[$varname] ) && $_POST[$varname] ;
+               if ( $this->mRequest->wasPosted() && !is_null( $this->mRequest->getVal( $varname ) ) ) {
+                       $checked = $this->mRequest->getCheck( $varname );
+               }
                return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
                        ( $checked ? ' checked="checked"' : '' ) .
                        " /><label for=\"{$varname}\">". wfMsg( $this->mName.'-'.$varname ) .
@@ -46,7 +52,10 @@ class HTMLForm {
         * @param integer $size Optional size of the textbox (default 20)
         */
        function textbox( $varname, $value='', $size=20 ) {
-               $value = isset( $_POST[$varname] ) ? $_POST[$varname] : $value;
+               if ( $this->mRequest->wasPosted() ) {
+                       $value = $this->mRequest->getText( $varname, $value );
+               }
+               $value = htmlspecialchars( $value );
                return "<div><label>". wfMsg( $this->mName.'-'.$varname ) .
                        "<input type='text' name=\"{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
        }
@@ -72,7 +81,10 @@ class HTMLForm {
         * @param integer $size Optional size of the textarea (default 20)
         */
        function textareabox ( $varname, $value='', $size=20 ) {
-               $value = isset( $_POST[$varname] ) ? $_POST[$varname] : $value;
+               if ( $this->mRequest->wasPosted() ) {
+                       $value = $this->mRequest->getText( $varname, $value );
+               }       
+               $value = htmlspecialchars( $value );
                return '<div><label>'.wfMsg( $this->mName.'-'.$varname ).
                       "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea></label></div>\n";
        }
@@ -84,9 +96,12 @@ class HTMLForm {
         */
        function arraybox( $varname , $size=20 ) {
                $s = '';
-               if ( isset( $_POST[$varname] ) && is_array( $_POST[$varname] ) ) {
-                       foreach ( $_POST[$varname] as $index=>$element ) {
-                               $s .= $element."\n";
+               if ( $this->mRequest->wasPosted() ) {
+                       $arr = $this->mRequest->getArray( $varname );
+                       if ( is_array( $arr ) ) {
+                               foreach ( $_POST[$varname] as $index=>$element ) {
+                                       $s .= htmlspecialchars( $element )."\n";
+                               }
                        }
                }
                return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
@@ -99,12 +114,13 @@ class HTMLForm {
 
 /** Build a select with all defined groups
  * @param string $selectname Name of this element. Name of form is automaticly prefixed.
- * @param array $selected Array of element selected when posted. Multiples will only show them.
+ * @param array $selected Array of element selected when posted. Only multiples will show them.
  * @param boolean $multiple A multiple elements select.
- * @param integer $size Number of element to be shown ignored for non multiple (default 6).
+ * @param integer $size Number of elements to be shown ignored for non-multiple (default 6).
  * @param boolean $reverse If true, multiple select will hide selected elements (default false).
 */
 function HTMLSelectGroups($selectname, $selectmsg, $selected=array(), $multiple=false, $size=6, $reverse=false) {
+       global $wgOut;
        $groups =& Group::getAllGroups();
        
        $out = wfMsg($selectmsg);
@@ -116,12 +132,12 @@ function HTMLSelectGroups($selectname, $selectmsg, $selected=array(), $multiple=
                if($multiple) {
                        // for multiple will only show the things we want
                        if(in_array($id, $selected) xor $reverse) { 
-                               $out .= '<option value="'.$id.'">'.$g->getExpandedName()."</option>\n";
+                               $out .= '<option value="'.$id.'">'.$wgOut->parse( $g->getExpandedName() )."</option>\n";
                        }
                } else {
                        $out .= '<option ';
                        if(in_array($id, $selected)) { $out .= 'selected="selected" '; }
-                       $out .= 'value="'.$id.'">'.$g->getExpandedName()."</option>\n";
+                       $out .= 'value="'.$id.'">'.$wgOut->parse( $g->getExpandedName() )."</option>\n";
                }
        }
        $out .= "</select>\n";
index 5e00665..43d0b26 100644 (file)
@@ -32,7 +32,7 @@ class UserrightsForm extends HTMLForm {
        /** Constructor*/
        function UserrightsForm ( &$request ) {
                $this->mPosted = $request->wasPosted();
-               $this->mRequest = $request;
+               $this->mRequest =& $request;
                $this->mName = 'userrights';
                
                $titleObj = Title::makeTitle( NS_SPECIAL, 'Userrights' );
@@ -40,8 +40,8 @@ class UserrightsForm extends HTMLForm {
        }
 
        /**
-        * Manage forms to be shown according to posted datas.
-        * Depending on the submit button used : Call a form or a saving function.
+        * Manage forms to be shown according to posted data.
+        * Depending on the submit button used, call a form or a save function.
         */
        function execute() {
                // show the general form
@@ -60,7 +60,6 @@ class UserrightsForm extends HTMLForm {
                }
        }
 
-// save things !!
        /**
         * Save user groups changes in the database.
         * Datas comes from the editUserGroupsForm() form function
@@ -69,7 +68,6 @@ class UserrightsForm extends HTMLForm {
         * @param array $removegroup id of groups to be removed.
         * @param array $addgroup id of groups to be added.
         *
-        * @todo Log groupname instead of group id.
         */
        function saveUserGroups($username,$removegroup,$addgroup) {
                $u = User::NewFromName($username);
@@ -84,23 +82,37 @@ class UserrightsForm extends HTMLForm {
                        return;
                }               
 
-               $groups = $u->getGroups();
+               $oldGroups = $u->getGroups();
+               $newGroups = $oldGroups;
                $logcomment = ' ';
                // remove then add groups               
                if(isset($removegroup)) {
-                       $groups = array_diff($groups, $removegroup);
-                       $logcomment .= implode( ' -', $removegroup);
-                       }
+                       $newGroups = array_diff($newGroups, $removegroup);
+               }
                if(isset($addgroup)) {
-                       $groups = array_merge($groups, $addgroup);
-                       $logcomment .= implode( ' +', $addgroup );
-                       }
+                       $newGroups = array_merge($newGroups, $addgroup);
+               }
+               $newGroups = array_unique( $newGroups );
+
                // save groups in user object and database
-               $u->setGroups($groups);
+               $u->setGroups($newGroups);
                $u->saveSettings();
 
                $log = new LogPage( 'rights' );
-               $log->addEntry( 'rights', Title::makeTitle( NS_USER, $u->getName() ), $logcomment );
+               $log->addEntry( 'rights', Title::makeTitle( NS_USER, $u->getName() ), '', array( $this->makeGroupNameList( $oldGroups ),
+                       $this->makeGroupNameList( $newGroups ) ) );
+       }
+
+       function makeGroupNameList( $ids ) {
+               $s = '';
+               foreach( $ids as $id ) {
+                       if ( $s != '' ) {
+                               $s .= ', ';
+                       }
+                       $groupObj = Group::newFromId( $id );
+                       $s .= $groupObj->getExpandedName();
+               }
+               return $s;
        }
 
        /**
@@ -127,20 +139,21 @@ class UserrightsForm extends HTMLForm {
                global $wgOut;
                
                $user = User::newFromName($username);
+               $encUser = htmlspecialchars( $username );
                if(is_null($user)) {
-                       $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
+                       $wgOut->addHTML('<p>'.wfMsg('nosuchusershort', $encUser).'</p>');
                        return;
                }
 
                if($user->getID() == 0) {
-                       $wgOut->addHTML('<p>'.wfMsg('nosuchusershort',$username).'</p>');
+                       $wgOut->addHTML('<p>'.wfMsg('nosuchusershort', $encUser).'</p>');
                        return;
                }               
                
                $groups = $user->getGroups();
 
                $wgOut->addHTML( "<form name=\"editGroup\" action=\"$this->action\" method=\"post\">\n".
-                                                '<input type="hidden" name="user-editname" value="'.$username.'" />');
+                                                '<input type="hidden" name="user-editname" value="'.$encUser.'" />');
                $wgOut->addHTML( $this->fieldset( 'editusergroup',
                        wfMsg('editing', $this->mRequest->getVal('user-editname')).".<br />\n" .
                        '<table border="0" align="center"><tr><td>'.
index fdab2db..73b0dc3 100644 (file)
@@ -918,6 +918,7 @@ using the MediaWiki namespace',
 'userrights-groupsavailable' => 'Available groups:',
 'userrights-groupshelp' => 'Select groups you want the user to be removed from or added to.
 Unselected groups will not be changed. You can deselect a group with CTRL + Left Click',
+'userrights-logcomment' => 'Changed group membership from $1 to $2',
 
 # Default group names and descriptions
 # 
@@ -1248,16 +1249,19 @@ You will be notified by email when someone changes a page which is listed in you
 'email_notification_reset'                     => 'Reset all notification flags (set their status to "visited")',
 'email_notification_newpagetext'=> 'This is a new page.',
 'email_notification_to'        => '$WATCHINGUSERNAME_QP <$WATCHINGUSEREMAILADDR>',
-'email_notification_subject'   => '{{SITENAME}} page $PAGETITLE has been changed by $PAGEEDITOR',
+'changed'                      => 'changed',
+'created'                      => 'created',
+'email_notification_subject'   => '{{SITENAME}} page $PAGETITLE has been $CHANGEDORCREATED by $PAGEEDITOR',
 'email_notification_lastvisitedrevisiontext' => 'See {{SERVER}}{{localurl:$PAGETITLE_RAWURL|diff=0&oldid=$OLDID}} for all changes since your last visit.',
 'email_notification_body' => 'Dear $WATCHINGUSERNAME,
 
-the {{SITENAME}} page $PAGETITLE has been changed on $PAGEEDITDATE by $PAGEEDITOR,
+the {{SITENAME}} page $PAGETITLE has been $CHANGEDORCREATED on $PAGEEDITDATE by $PAGEEDITOR,
 see {{SERVER}}{{localurl:$PAGETITLE_RAWURL}} for the current version.
 
 $NEWPAGE
 
 Editor\'s summary: $PAGESUMMARY $PAGEMINOREDIT
+
 Contact the editor:
 mail {{SERVER}}{{localurl:Special:Emailuser|target=$PAGEEDITOR_RAWURL}}
 wiki {{SERVER}}{{localurl:User:$PAGEEDITOR_RAWURL}}
@@ -1468,7 +1472,7 @@ Type the name of the user in the box and press the button to make the user an ad
 'setbureaucratflag' => 'Set bureaucrat flag',
 'bureaucratlog'                => 'Bureaucrat_log',
 'rightslogtext'                => 'This is a log of changes to user rights.',
-'bureaucratlogentry'   => "Rights for user \"$1\" set \"$2\"",
+'bureaucratlogentry'   => "Changed group membership for $1 from $2 to $3",
 'rights'                       => 'Rights:',
 'set_user_rights'      => 'Set user rights',
 'user_rights_set'      => "<b>User rights for \"$1\" updated</b>",