Index: trunk/extensions/PasswordReset/PasswordReset_body.php |
— | — | @@ -0,0 +1,121 @@ |
| 2 | +<?php |
| 3 | +class PasswordReset extends SpecialPage |
| 4 | +{ |
| 5 | + function PasswordReset() { |
| 6 | + SpecialPage::SpecialPage("PasswordReset","userrights"); |
| 7 | + self::loadMessages(); |
| 8 | + } |
| 9 | + |
| 10 | + function execute( $par ) { |
| 11 | + global $wgRequest, $wgOut, $wgUser, $wgTitle; |
| 12 | + |
| 13 | + $this->setHeaders(); |
| 14 | + |
| 15 | + if ( !$wgUser->isAllowed( 'userrights' ) ) { |
| 16 | + $wgOut->permissionRequired( 'userrights' ); |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + $username = Title::newFromText( $wgRequest->getText( 'username' ) ); |
| 21 | + $username_text = is_object( $username ) ? $username->getText() : ''; |
| 22 | + |
| 23 | + if (strlen($wgRequest->getText('username').$wgRequest->getText('newpass').$wgRequest->getText('confirmpass'))>0) { |
| 24 | + //POST data found |
| 25 | + if (strlen($username_text)>0) { |
| 26 | + $objUser = User::newFromName( $username->getText() ); |
| 27 | + $userID = $objUser->idForName(); |
| 28 | + |
| 29 | + if ( !is_object( $objUser ) || $userID == 0 ) { |
| 30 | + $validUser = false; |
| 31 | + $wgOut->addHTML( "<span style=\"color: red;\">Invalid Username</span><br>\n" ); |
| 32 | + } else { |
| 33 | + $validUser = true; |
| 34 | + } |
| 35 | + } else { |
| 36 | + $validUser = false; |
| 37 | + $wgOut->addHTML( "<span style=\"color: red;\">Empty Username</span><br>\n" ); |
| 38 | + } |
| 39 | + |
| 40 | + $newpass = $wgRequest->getText( 'newpass' ); |
| 41 | + $confirmpass = $wgRequest->getText( 'confirmpass' ); |
| 42 | + |
| 43 | + if ($newpass==$confirmpass && strlen($newpass.$oldpass)>0) { |
| 44 | + //Passwords match |
| 45 | + $passMatch = true; |
| 46 | + } else { |
| 47 | + //Passwords DO NOT match |
| 48 | + $passMatch = false; |
| 49 | + $wgOut->addHTML( "<span style=\"color: red;\">Passwords do not match.</span><br>\n" ); |
| 50 | + } |
| 51 | + |
| 52 | + if (!$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { |
| 53 | + $validUser = false; |
| 54 | + $passMatch = false; |
| 55 | + $wgOut->addHTML( "<span style=\"color: red;\">Invalid Edit Token.</span><br>\n" ); |
| 56 | + |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + $action = $wgTitle->escapeLocalUrl(); |
| 61 | + $token = $wgUser->editToken(); |
| 62 | + |
| 63 | + $wgOut->addHTML( " |
| 64 | +<form id='passwordresetform' method='post' action=\"$action\"> |
| 65 | +<table> |
| 66 | + <tr> |
| 67 | + <td align='right'>Username</td> |
| 68 | + <td align='left'><input tabindex='1' type='text' size='20' name='username' id='username' value=\"$username_text\" onFocus=\"document.getElementById('username').select;\" /></td> |
| 69 | + </tr> |
| 70 | + <tr> |
| 71 | + <td align='right'>New Password</td> |
| 72 | + <td align='left'><input tabindex='2' type='password' size='20' name='newpass' id='newpass' value=\"$newpass\" onFocus=\"document.getElementById('newpass').select;\" /></td> |
| 73 | + </tr> |
| 74 | + <tr> |
| 75 | + <td align='right'>Confirm Password</td> |
| 76 | + <td align='left'><input tabindex='3' type='password' size='20' name='confirmpass' id='confirmpass' value=\"$confirmpass\" onFocus=\"document.getElementById('confirmpass').select;\" /></td> |
| 77 | + </tr> |
| 78 | + <tr> |
| 79 | + <td> </td> |
| 80 | + <td align='right'><input type='submit' name='submit' value=\"Reset Password\" /></td> |
| 81 | + </tr> |
| 82 | +</table> |
| 83 | +<input type='hidden' name='token' value='$token' /> |
| 84 | +</form>"); |
| 85 | + |
| 86 | + if ($validUser && $passMatch) { |
| 87 | + $wgOut->addWikiText ( "<hr />\n" ); |
| 88 | + $wgOut->addWikiText ( $this->resetPassword( $userID, $newpass ) ); |
| 89 | + } else { |
| 90 | + //Invalid user or passwords don't match - do nothing |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + function resetPassword( $userID, $newpass ) { |
| 95 | + $dbw =& wfGetDB( DB_MASTER ); |
| 96 | + |
| 97 | + $userTable = $dbw->tableName('user'); |
| 98 | + $sql = "update $userTable set user_password=MD5(CONCAT('$userID-',MD5('$newpass'))) WHERE user_id=$userID"; |
| 99 | + |
| 100 | + $res = $dbw->query($sql); |
| 101 | + |
| 102 | + if ( $res > 0 ) { |
| 103 | + return "Password has been reset for user_id: $userID"; |
| 104 | + } else { |
| 105 | + return "Unable to reset password for user_id: $userID"; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + function loadMessages() { |
| 110 | + static $messagesLoaded = false; |
| 111 | + global $wgMessageCache; |
| 112 | + if ( $messagesLoaded ) return true; |
| 113 | + $messagesLoaded = true; |
| 114 | + |
| 115 | + require( dirname( __FILE__ ) . '/PasswordReset.i18n.php' ); |
| 116 | + foreach ( $allMessages as $lang => $langMessages ) { |
| 117 | + $wgMessageCache->addMessages( $langMessages, $lang ); |
| 118 | + } |
| 119 | + |
| 120 | + return true; |
| 121 | + } |
| 122 | +} |
Property changes on: trunk/extensions/PasswordReset/PasswordReset_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 123 | + native |
Index: trunk/extensions/PasswordReset/PasswordReset.i18n.php |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +<?php |
| 3 | +$allMessages = array( |
| 4 | + 'en' => array( |
| 5 | + 'passwordreset' => 'Password Reset' |
| 6 | + ) |
| 7 | +); |
Property changes on: trunk/extensions/PasswordReset/PasswordReset.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: trunk/extensions/PasswordReset/PasswordReset.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | +# Not a valid entry point, skip unless MEDIAWIKI is defined |
| 4 | +if (!defined('MEDIAWIKI')) { |
| 5 | + echo "Password Reset extension"; |
| 6 | + exit(1); |
| 7 | +} |
| 8 | + |
| 9 | +$wgExtensionCredits['specialpage'][] = array( |
| 10 | + 'name'=>'Password Reset', |
| 11 | + 'url'=>'http://www.mediawiki.org/wiki/Extension:Password_Reset', |
| 12 | + 'author'=>'Tim Laqua, t.laqua at gmail dot com', |
| 13 | + 'description'=>"Resets Wiki user's passwords - requires 'userrights' privileges", |
| 14 | + 'version'=>'1.0' |
| 15 | +); |
| 16 | + |
| 17 | +$wgAutoloadClasses['PasswordReset'] = dirname(__FILE__) . '/PasswordReset_body.php'; |
| 18 | +$wgSpecialPages['PasswordReset'] = 'PasswordReset'; |
| 19 | + |
| 20 | +if ( version_compare( $wgVersion, '1.10.0', '<' ) ) { |
| 21 | + //Extension designed for 1.10.0+, but will work on some older versions |
| 22 | + //LoadAllMessages hook throws errors before 1.10.0 |
| 23 | +} else { |
| 24 | + $wgHooks['LoadAllMessages'][] = 'PasswordReset::loadMessages'; |
| 25 | +} |
Property changes on: trunk/extensions/PasswordReset/PasswordReset.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |
Index: trunk/extensions/UserMerge/UserMerge_body.php |
— | — | @@ -0,0 +1,169 @@ |
| 2 | +<?php |
| 3 | +class UserMerge extends SpecialPage |
| 4 | +{ |
| 5 | + function UserMerge() { |
| 6 | + SpecialPage::SpecialPage("UserMerge","userrights"); |
| 7 | + self::loadMessages(); |
| 8 | + } |
| 9 | + |
| 10 | + function execute( $par ) { |
| 11 | + global $wgRequest, $wgOut, $wgUser, $wgTitle; |
| 12 | + |
| 13 | + $this->setHeaders(); |
| 14 | + |
| 15 | + if ( !$wgUser->isAllowed( 'userrights' ) ) { |
| 16 | + $wgOut->permissionRequired( 'userrights' ); |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + if (strlen($wgRequest->getText('olduser').$wgRequest->getText('newuser'))>0 || $wgRequest->getText( 'deleteuser' )) { |
| 21 | + //POST data found |
| 22 | + $olduser = Title::newFromText( $wgRequest->getText( 'olduser' ) ); |
| 23 | + $olduser_text = is_object( $olduser ) ? $olduser->getText() : ''; |
| 24 | + |
| 25 | + $newuser = Title::newFromText( $wgRequest->getText( 'newuser' ) ); |
| 26 | + $newuser_text = is_object( $newuser ) ? $newuser->getText() : ''; |
| 27 | + |
| 28 | + if ($wgRequest->getText( 'deleteuser' )) { |
| 29 | + $deleteUserCheck = "CHECKED "; |
| 30 | + } |
| 31 | + |
| 32 | + if (strlen($olduser_text)>0) { |
| 33 | + $objOldUser = User::newFromName( $olduser_text ); |
| 34 | + $olduserID = $objOldUser->idForName(); |
| 35 | + |
| 36 | + if ( !is_object( $objOldUser ) || $olduserID == 0 ) { |
| 37 | + $validOldUser = false; |
| 38 | + $wgOut->addHTML( "<span style=\"color: red;\">Invalid Old Username</span><br>\n" ); |
| 39 | + } else { |
| 40 | + $validOldUser = true; |
| 41 | + |
| 42 | + if (strlen($newuser_text)>0) { |
| 43 | + |
| 44 | + $objNewUser = User::newFromName( $newuser_text ); |
| 45 | + $newuserID = $objNewUser->idForName(); |
| 46 | + |
| 47 | + if ( !is_object( $objNewUser ) || $newuserID == 0 ) { |
| 48 | + //invalid newuser entered |
| 49 | + $validNewUser = false; |
| 50 | + $wgOut->addHTML( "<span style=\"color: red;\">Invalid New User.</span><br>\n" ); |
| 51 | + } else { |
| 52 | + //newuser looks good |
| 53 | + $validNewUser = true; |
| 54 | + } |
| 55 | + } else { |
| 56 | + //empty newuser string |
| 57 | + $validNewUser = false; |
| 58 | + $newuser_text = User::whoIs(1); |
| 59 | + $wgOut->addHTML( "<span style=\"color: red;\">Empty New Username - Assuming merge to $newuser_text.\nClick <U>Merge User</u> to accept.</span><br>\n" ); |
| 60 | + } |
| 61 | + } |
| 62 | + } else { |
| 63 | + $validOldUser = false; |
| 64 | + $wgOut->addHTML( "<span style=\"color: red;\">Empty Old Username</span><br>\n" ); |
| 65 | + } |
| 66 | + } else { |
| 67 | + //NO POST data found |
| 68 | + } |
| 69 | + |
| 70 | + $action = $wgTitle->escapeLocalUrl(); |
| 71 | + $token = $wgUser->editToken(); |
| 72 | + |
| 73 | + $wgOut->addHTML( " |
| 74 | +<form id='usermergeform' method='post' action=\"$action\"> |
| 75 | +<table> |
| 76 | + <tr> |
| 77 | + <td align='right'>Old User(Merge From)</td> |
| 78 | + <td align='left'><input tabindex='1' type='text' size='20' name='olduser' id='olduser' value=\"$olduser_text\" onFocus=\"document.getElementById('olduser').select;\" /></td> |
| 79 | + </tr> |
| 80 | + <tr> |
| 81 | + <td align='right'>New User(Merge To)</td> |
| 82 | + <td align='left'><input tabindex='2' type='text' size='20' name='newuser' id='newuser' value=\"$newuser_text\" onFocus=\"document.getElementById('newuser').select;\" /></td> |
| 83 | + </tr> |
| 84 | + <tr> |
| 85 | + <td align='right'>Delete Old User?</td> |
| 86 | + <td align='left'><input tabindex='3' type='checkbox' name='deleteuser' id='deleteuser' $deleteUserCheck/></td> |
| 87 | + </tr> |
| 88 | + <tr> |
| 89 | + <td> </td> |
| 90 | + <td align='right'><input type='submit' name='submit' value=\"Merge User\" /></td> |
| 91 | + </tr> |
| 92 | +</table> |
| 93 | +<input type='hidden' name='token' value='$token' /> |
| 94 | +</form>"); |
| 95 | + |
| 96 | + if ($validNewUser && $validOldUser) { |
| 97 | + //go time, baby |
| 98 | + if (!$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { |
| 99 | + //bad editToken |
| 100 | + $wgOut->addHTML( "<span style=\"color: red;\">Invalid Edit Token.</span><br>\n" ); |
| 101 | + } else { |
| 102 | + //good editToken |
| 103 | + $this->mergeUser($newuser_text,$newuserID,$olduser_text,$olduserID); |
| 104 | + if ($wgRequest->getText( 'deleteuser' )) { |
| 105 | + $this->deleteUser($olduserID, $olduser_text); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + function deleteUser ($olduserID, $olduser_text) { |
| 112 | + global $wgOut; |
| 113 | + |
| 114 | + $dbw =& wfGetDB( DB_MASTER ); |
| 115 | + $dbw->delete( 'user_groups', array( 'ug_user' => $olduserID )); |
| 116 | + $dbw->delete( 'user', array( 'user_id' => $olduserID )); |
| 117 | + $wgOut->addHTML("$olduser_text($olduserID) has been deleted."); |
| 118 | + } |
| 119 | + |
| 120 | + function mergeUser ($newuser_text, $newuserID, $olduser_text, $olduserID) { |
| 121 | + global $wgOut; |
| 122 | + |
| 123 | + $textUpdateFields = array(array('archive','ar_user_text'), |
| 124 | + array('revision','rev_user_text'), |
| 125 | + array('filearchive','fa_user_text'), |
| 126 | + array('image','img_user_text'), |
| 127 | + array('oldimage','oi_user_text'), |
| 128 | + array('recentchanges','rc_user_text'), |
| 129 | + array('ipblocks','ipb_address')); |
| 130 | + |
| 131 | + $idUpdateFields = array(array('archive','ar_user'), |
| 132 | + array('revision','rev_user'), |
| 133 | + array('filearchive','fa_user'), |
| 134 | + array('image','img_user'), |
| 135 | + array('oldimage','oi_user'), |
| 136 | + array('recentchanges','rc_user'), |
| 137 | + array('logging','log_user')); |
| 138 | + |
| 139 | + $dbw =& wfGetDB( DB_MASTER ); |
| 140 | + |
| 141 | + foreach ($idUpdateFields as $idUpdateField) { |
| 142 | + $dbw->update($idUpdateField[0], array( $idUpdateField[1] => $newuserID ), array( $idUpdateField[1] => $olduserID )); |
| 143 | + $wgOut->addHTML("Updating $idUpdateField[0] table ($olduserID to $newuserID)<br>\n"); |
| 144 | + } |
| 145 | + |
| 146 | + foreach ($textUpdateFields as $textUpdateField) { |
| 147 | + $dbw->update($textUpdateField[0], array( $textUpdateField[1] => $newuser_text ), array( $textUpdateField[1] => $olduser_text )); |
| 148 | + $wgOut->addHTML("Updating $textUpdateField[0] table ($olduser_text to $newuser_text)<br>\n"); |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | + $dbw->delete( 'user_newtalk', array( 'user_ip' => $olduserID )); |
| 153 | + |
| 154 | + $wgOut->addHTML("<hr />\nMerge from $olduser_text($olduserID) to $newuser_text($newuserID) is complete.\n<br>"); |
| 155 | + } |
| 156 | + |
| 157 | + function loadMessages() { |
| 158 | + static $messagesLoaded = false; |
| 159 | + global $wgMessageCache; |
| 160 | + if ( $messagesLoaded ) return true; |
| 161 | + $messagesLoaded = true; |
| 162 | + |
| 163 | + require( dirname( __FILE__ ) . '/UserMerge.i18n.php' ); |
| 164 | + foreach ( $allMessages as $lang => $langMessages ) { |
| 165 | + $wgMessageCache->addMessages( $langMessages, $lang ); |
| 166 | + } |
| 167 | + |
| 168 | + return true; |
| 169 | + } |
| 170 | +} |
Property changes on: trunk/extensions/UserMerge/UserMerge_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 171 | + native |
Index: trunk/extensions/UserMerge/UserMerge.i18n.php |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +<?php |
| 3 | +$allMessages = array( |
| 4 | + 'en' => array( |
| 5 | + 'usermerge' => 'User Merge and Delete' |
| 6 | + ) |
| 7 | +); |
Property changes on: trunk/extensions/UserMerge/UserMerge.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: trunk/extensions/UserMerge/UserMerge.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | +# Not a valid entry point, skip unless MEDIAWIKI is defined |
| 4 | +if (!defined('MEDIAWIKI')) { |
| 5 | + echo "User Merge and Delete extension"; |
| 6 | + exit(1); |
| 7 | +} |
| 8 | + |
| 9 | +$wgExtensionCredits['specialpage'][] = array( |
| 10 | + 'name'=>'User Merge and Delete', |
| 11 | + 'url'=>'http://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete', |
| 12 | + 'author'=>'Tim Laqua, t.laqua at gmail dot com', |
| 13 | + 'description'=>"Merges references from one user to another user in the Wiki database - will also delete old users following merge. Requires 'userrights' privileges.", |
| 14 | + 'version'=>'1.0' |
| 15 | +); |
| 16 | + |
| 17 | +$wgAutoloadClasses['UserMerge'] = dirname(__FILE__) . '/UserMerge_body.php'; |
| 18 | +$wgSpecialPages['UserMerge'] = 'UserMerge'; |
| 19 | + |
| 20 | +if ( version_compare( $wgVersion, '1.10.0', '<' ) ) { |
| 21 | + //Extension designed for 1.10.0+, but will work on some older versions |
| 22 | + //LoadAllMessages hook throws errors before 1.10.0 |
| 23 | +} else { |
| 24 | + $wgHooks['LoadAllMessages'][] = 'UserMerge::loadMessages'; |
| 25 | +} |
Property changes on: trunk/extensions/UserMerge/UserMerge.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |