Add logging to password resets per request on code review. Also a little javascript...
authorChad Horohoe <demon@users.mediawiki.org>
Sat, 21 Feb 2009 22:27:43 +0000 (22:27 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sat, 21 Feb 2009 22:27:43 +0000 (22:27 +0000)
includes/DefaultSettings.php
includes/specials/SpecialResetpass.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc
skins/common/changepassword.js [new file with mode: 0644]

index c54427b..40f88ae 100644 (file)
@@ -1469,7 +1469,7 @@ $wgCacheEpoch = '20030516000000';
  * to ensure that client-side caches don't keep obsolete copies of global
  * styles.
  */
-$wgStyleVersion = '206';
+$wgStyleVersion = '207';
 
 
 # Server-side caching:
@@ -2843,6 +2843,7 @@ $wgLogTypes = array( '',
        'patrol',
        'merge',
        'suppress',
+       'password',
 );
 
 /**
@@ -2897,6 +2898,7 @@ $wgLogNames = array(
        'patrol'  => 'patrol-log-page',
        'merge'   => 'mergelog',
        'suppress' => 'suppressionlog',
+       'password' => 'resetpass-log'
 );
 
 /**
@@ -2917,6 +2919,7 @@ $wgLogHeaders = array(
        'patrol'  => 'patrol-log-header',
        'merge'   => 'mergelogpagetext',
        'suppress' => 'suppressionlogtext',
+       'password' => 'resetpass-logtext',
 );
 
 /**
@@ -2952,6 +2955,7 @@ $wgLogActions = array(
        'suppress/delete'   => 'suppressedarticle',
        'suppress/block'        => 'blocklogentry',
        'suppress/reblock'  => 'reblock-logentry',
+       'password/reset'    => 'resetpass-logentry'
 );
 
 /**
index 49e2530..1678fc3 100644 (file)
@@ -26,6 +26,7 @@ class SpecialResetpass extends SpecialPage {
                $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
                $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
                $this->mRetype = $wgRequest->getVal( 'wpRetype' );
+               $this->mComment = $wgRequest->getVal( 'wpComment' );
                
                $this->setHeaders();
                $this->outputHeader();
@@ -94,6 +95,10 @@ class SpecialResetpass extends SpecialPage {
                global $wgOut, $wgUser, $wgRequest;
 
                $wgOut->disallowUserJs();
+               
+               if ( $wgUser->isAllowed( 'reset-passwords') ) {
+                       $wgOut->addScriptFile( 'changepassword.js' );
+               }
 
                $self = SpecialPage::getTitleFor( 'Resetpass' );
 
@@ -113,8 +118,7 @@ class SpecialResetpass extends SpecialPage {
                        $oldpassMsg = 'oldpassword';
                        $submitMsg = 'resetpass-submit-loggedin';
                }
-               $wgOut->addHTML(
-                       Xml::fieldset( wfMsg( 'resetpass_header' ) ) .
+               $s = Xml::fieldset( wfMsg( 'resetpass_header' ) ) .
                        Xml::openElement( 'form',
                                array(
                                        'method' => 'post',
@@ -123,13 +127,15 @@ class SpecialResetpass extends SpecialPage {
                        Xml::hidden( 'token', $wgUser->editToken() ) .
                        Xml::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
                        wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
-                       Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) .
-                       $this->pretty( array(
+                       Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) );
+               $formElements = array(
                                array( 'wpName', 'username', 'text', $this->mUserName, $wgUser->isAllowed( 'reset-passwords' ) ),
                                array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass, $this->mSelfChange ),
                                array( 'wpNewPassword', 'newpassword', 'password', '', true ),
-                               array( 'wpRetype', 'retypenew', 'password', '', true ),
-                       ) ) .
+                               array( 'wpRetype', 'retypenew', 'password', '', true ) );
+               if ( $wgUser->isAllowed( 'reset-passwords' ) && $this->mSelfChange )
+                       $formElements[] = array( 'wpComment', 'resetpass-comment', 'text', $this->mComment, true );
+               $s .= $this->pretty( $formElements ) .
                        $rememberMe .
                        '<tr>' .
                                '<td></td>' .
@@ -139,8 +145,8 @@ class SpecialResetpass extends SpecialPage {
                        '</tr>' .
                        Xml::closeElement( 'table' ) .
                        Xml::closeElement( 'form' ) .
-                       Xml::closeElement( 'fieldset' )
-               );
+                       Xml::closeElement( 'fieldset' );
+               $wgOut->addHtml( $s );
        }
 
        function pretty( $fields ) {
@@ -183,7 +189,7 @@ class SpecialResetpass extends SpecialPage {
                                throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
                        }
                }
-               
+
                try {
                        $user->setPassword( $this->mNewpass );
                        wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) );
@@ -194,6 +200,11 @@ class SpecialResetpass extends SpecialPage {
                        return;
                }
                
+               if ( !$this->mSelfChange ) {
+                       $log = new LogPage( 'password' );
+                       $log->addEntry( 'reset', $user->getUserPage(), $this->mComment );
+               }
+               
                $user->setCookies();
                $user->saveSettings();
        }
index 357b0a8..e521010 100644 (file)
@@ -1017,6 +1017,10 @@ You may have already successfully changed your password or requested a new tempo
 You may have already successfully changed your password or requested a new temporary password.',
 'resetpass-temp-password'   => 'Temporary password:',
 'resetpass-no-others'       => 'You cannot reset the password for other users.',
+'resetpass-log'             => 'Password resets',
+'resetpass-logtext'         => 'Below is a log of users who have had their password reset by a bureaucrat',
+'resetpass-logentry'        => 'changed the password for $1',
+'resetpass-comment'         => 'Reason for password reset',
 
 # Edit page toolbar
 'bold_sample'     => 'Bold text',
index 8e97328..d30d998 100644 (file)
@@ -462,6 +462,10 @@ $wgMessageStructure = array(
                'resetpass-wrong-oldpass',
                'resetpass-temp-password',
                'resetpass-no-others',
+               'resetpass-log',
+               'resetpass-logtext',
+               'resetpass-logentry',
+               'resetpass-comment',
        ),
        'toolbar' => array(
                'bold_sample',
diff --git a/skins/common/changepassword.js b/skins/common/changepassword.js
new file mode 100644 (file)
index 0000000..1ea09d2
--- /dev/null
@@ -0,0 +1,32 @@
+\r
+function onNameChange() {\r
+       if ( wgUserName != document.getElementById('wpName').value ) {\r
+               document.getElementById('wpPassword').disabled = true;\r
+               document.getElementById('wpComment').disabled = false;\r
+       } else {\r
+               document.getElementById('wpPassword').disabled = false;\r
+               document.getElementById('wpComment').disabled = true;\r
+       }\r
+}\r
+\r
+function onNameChangeHook() {\r
+       document.getElementById( 'wpName' ).onblur = onNameChange;\r
+}\r
+\r
+addOnloadHook( onNameChangeHook );\r
+\r
+function onNameChange() {\r
+       if ( wgUserName != document.getElementById('wpName').value ) {\r
+               document.getElementById('wpPassword').disabled = true;\r
+               document.getElementById('wpComment').disabled = false;\r
+       } else {\r
+               document.getElementById('wpPassword').disabled = false;\r
+               document.getElementById('wpComment').disabled = true;\r
+       }\r
+}\r
+\r
+function onNameChangeHook() {\r
+       document.getElementById( 'wpName' ).onblur = onNameChange;\r
+}\r
+\r
+addOnloadHook( onNameChangeHook );\r