public function doRun() { if (!class_exists('RenameuserSQL')) { throw new Exception('Extension:Renameuser is not installed'); } $from = $this->params['from']; $to = $this->params['to']; $this->updateStatus('inprogress'); if (isset($this->params['force']) && $this->params['force']) { // If we're dealing with an invalid username, load the data ourselves to avoid // any normalization at all done by User or Title. $row = wfGetDB(DB_MASTER)->selectRow('user', User::selectFields(), array('user_name' => $from), __METHOD__); $oldUser = User::newFromRow($row); } else { $oldUser = User::newFromName($from); } $rename = new RenameuserSQL($from, $to, $oldUser->getId(), $this->getRenameUser(), array('checkIfUserExists' => false, 'debugPrefix' => 'GlobalRename', 'reason' => $this->params['reason'])); if (!$rename->rename()) { // This should never happen! // If it does happen, the user will be locked out of their account // until a sysadmin intervenes... throw new Exception('RenameuserSQL::rename returned false.'); } if ($this->params['movepages']) { $this->movePages($oldUser); } if ($this->params['promotetoglobal']) { $this->promoteToGlobal(); } $this->done(); }
/** * Show the special page * * @param mixed $par Parameter passed to the page */ public function execute($par) { global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang; global $wgVersion, $wgMaxNameChars, $wgCapitalLinks; $this->setHeaders(); if (!$wgUser->isAllowed('renameuser')) { $wgOut->permissionRequired('renameuser'); return; } if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } $showBlockLog = $wgRequest->getBool('submit-showBlockLog'); $oldusername = Title::newFromText($wgRequest->getText('oldusername'), NS_USER); $newusername = Title::newFromText($wgContLang->ucfirst($wgRequest->getText('newusername')), NS_USER); // Force uppercase of newusername otherweise wikis with wgCapitalLinks=false can create lc usernames $oun = is_object($oldusername) ? $oldusername->getText() : ''; $nun = is_object($newusername) ? $newusername->getText() : ''; $token = $wgUser->editToken(); $reason = $wgRequest->getText('reason'); $is_checked = true; if ($wgRequest->wasPosted() && !$wgRequest->getCheck('movepages')) { $is_checked = false; } $wgOut->addHTML("\n\t\t\t<!-- Current contributions limit is " . RENAMEUSER_CONTRIBLIMIT . " -->" . Xml::openElement('form', array('method' => 'post', 'action' => $wgTitle->getLocalUrl(), 'id' => 'renameuser')) . Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('renameuser')) . Xml::openElement('table', array('id' => 'mw-renameuser-table')) . "<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameuserold'), 'oldusername') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('oldusername', 20, $oun, array('type' => 'text', 'tabindex' => '1')) . ' ' . Xml::submitButton(wfMsg('blocklogpage'), array('name' => 'submit-showBlockLog', 'id' => 'submit-showBlockLog', 'tabindex' => '2')) . ' ' . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameusernew'), 'newusername') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('newusername', 20, $nun, array('type' => 'text', 'tabindex' => '3')) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameuserreason'), 'reason') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('reason', 40, $reason, array('type' => 'text', 'tabindex' => '4', 'maxlength' => 255)) . "</td>\n\t\t\t</tr>"); if ($wgUser->isAllowed('move') && version_compare($wgVersion, '1.9alpha', '>=')) { $wgOut->addHTML("\n\t\t\t\t<tr>\n\t\t\t\t\t<td> \n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::checkLabel(wfMsg('renameusermove'), 'movepages', 'movepages', $is_checked, array('tabindex' => '5')) . "</td>\n\t\t\t\t</tr>"); } $wgOut->addHTML("\n\t\t\t<tr>\n\t\t\t\t<td> \n\t\t\t\t</td>\n\t\t\t\t<td class='mw-submit'>" . Xml::submitButton(wfMsg('renameusersubmit'), array('name' => 'submit', 'tabindex' => '6', 'id' => 'submit')) . "</td>\n\t\t\t</tr>" . Xml::closeElement('table') . Xml::closeElement('fieldset') . Xml::hidden('token', $token) . Xml::closeElement('form') . "\n"); // Show block log if requested if ($showBlockLog && is_object($oldusername)) { $this->showLogExtract($oldusername, 'block', $wgOut); return; } if ($wgRequest->getText('token') === '') { # They probably haven't even submitted the form, so don't go further. return; } elseif (!$wgRequest->wasPosted() || !$wgUser->matchEditToken($wgRequest->getVal('token'))) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameuser-error-request') . "</div>"); return; } elseif (!is_object($oldusername)) { // FIXME: This is bogus. Invalid titles need to be rename-able! (bug 12654) $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrorinvalid', $wgRequest->getText('oldusername')) . "</div>"); return; } elseif (!is_object($newusername)) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrorinvalid', $wgRequest->getText('newusername')) . "</div>"); return; } elseif ($oldusername->getText() == $newusername->getText()) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameuser-error-same-user') . "</div>"); return; } // Suppress username validation of old username $olduser = User::newFromName($oldusername->getText(), false); $newuser = User::newFromName($newusername->getText()); // It won't be an object if for instance "|" is supplied as a value if (!is_object($olduser)) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrorinvalid', $oldusername->getText()) . "</div>"); return; } if (!is_object($newuser) || !User::isCreatableName($newuser->getName())) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrorinvalid', $newusername->getText()) . "</div>"); return; } // Check for the existence of lowercase oldusername in database. // Until r19631 it was possible to rename a user to a name with first character as lowercase if ($wgRequest->getText('oldusername') !== $wgContLang->ucfirst($wgRequest->getText('oldusername'))) { // oldusername was entered as lowercase -> check for existence in table 'user' $dbr_lc = wfGetDB(DB_SLAVE); $s = trim($wgRequest->getText('oldusername')); $uid = $dbr_lc->selectField('user', 'user_id', array('BINARY user_name' => $s), __METHOD__); if ($uid === false) { $uid = 0; # if ( !$wgCapitalLinks ) { # $uid = 0; // We are on a lowercase wiki but lowercase username does not exists # } else { # $uid = $olduser->idForName(); // We are on a standard uppercase wiki, use normal # } } else { // username with lowercase exists // Title::newFromText was nice, but forces uppercase // for older rename accidents on lowercase wikis we need the lowercase username as entered in the form $oldusername->mTextform = $wgRequest->getText('oldusername'); $oldusername->mUrlform = $wgRequest->getText('oldusername'); $oldusername->mDbkeyform = $wgRequest->getText('oldusername'); } } else { // oldusername was entered as upperase -> standard procedure $uid = $olduser->idForName(); } if ($uid == 0) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrordoesnotexist', $wgRequest->getText('oldusername')) . "</div>"); return; } if ($newuser->idForName() != 0) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrorexists', $newusername->getText()) . "</div>"); return; } // Always get the edits count, it will be used for the log message $contribs = User::edits($uid); // Check edit count if (!$wgUser->isAllowed('siteadmin')) { if (RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT) { $wgOut->addWikiText("<div class=\"errorbox\">" . wfMsg('renameusererrortoomany', $oldusername->getText(), $wgLang->formatNum($contribs), $wgLang->formatNum(RENAMEUSER_CONTRIBLIMIT)) . "</div>"); return; } } // Give other affected extensions a chance to validate or abort if (!wfRunHooks('RenameUserAbort', array($uid, $oldusername->getText(), $newusername->getText()))) { return; } $rename = new RenameuserSQL($oldusername->getText(), $newusername->getText(), $uid); $rename->rename(); $log = new LogPage('renameuser'); $log->addEntry('renameuser', $oldusername, wfMsgExt('renameuser-log', array('parsemag', 'content'), $wgContLang->formatNum($contribs), $reason), $newusername->getText()); $wgOut->addWikiText("<div class=\"successbox\">" . wfMsg('renameusersuccess', $oldusername->getText(), $newusername->getText()) . "</div><br style=\"clear:both\" />"); if ($wgRequest->getCheck('movepages') && $wgUser->isAllowed('move') && version_compare($wgVersion, '1.9alpha', '>=')) { $dbr =& wfGetDB(DB_SLAVE); $oldkey = $oldusername->getDBkey(); $pages = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')', '(page_title LIKE ' . $dbr->addQuotes($dbr->escapeLike($oldusername->getDBkey()) . '/%') . ' OR page_title = ' . $dbr->addQuotes($oldusername->getDBkey()) . ')'), __METHOD__); $output = ''; $skin =& $wgUser->getSkin(); while ($row = $dbr->fetchObject($pages)) { $oldPage = Title::makeTitleSafe($row->page_namespace, $row->page_title); $newPage = Title::makeTitleSafe($row->page_namespace, preg_replace('!^[^/]+!', $newusername->getDBkey(), $row->page_title)); if ($newPage->exists() && !$oldPage->isValidMoveTarget($newPage)) { $link = $skin->makeKnownLinkObj($newPage); $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml('renameuser-page-exists', $link) . '</li>'; } else { $success = $oldPage->moveTo($newPage, false, wfMsgForContent('renameuser-move-log', $oldusername->getText(), $newusername->getText())); if ($success === true) { $oldLink = $skin->makeKnownLinkObj($oldPage, '', 'redirect=no'); $newLink = $skin->makeKnownLinkObj($newPage); $output .= '<li class="mw-renameuser-pm">' . wfMsgHtml('renameuser-page-moved', $oldLink, $newLink) . '</li>'; } else { $oldLink = $skin->makeKnownLinkObj($oldPage); $newLink = $skin->makeLinkObj($newPage); $output .= '<li class="mw-renameuser-pu">' . wfMsgHtml('renameuser-page-unmoved', $oldLink, $newLink) . '</li>'; } } } if ($output) { $wgOut->addHtml('<ul>' . $output . '</ul>'); } } }
/** * Show the special page * * @param mixed $par Parameter passed to the page */ public function execute($par) { global $wgOut, $wgUser, $wgRequest, $wgContLang; global $wgCapitalLinks; $this->setHeaders(); $wgOut->addWikiMsg('renameuser-summary'); if (!$wgUser->isAllowed('renameuser')) { $wgOut->permissionRequired('renameuser'); return; } if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } if ($wgUser->isBlocked()) { $wgOut->blockedPage(); } $showBlockLog = $wgRequest->getBool('submit-showBlockLog'); $oldnamePar = trim(str_replace('_', ' ', $wgRequest->getText('oldusername', $par))); $oldusername = Title::makeTitle(NS_USER, $oldnamePar); // Force uppercase of newusername, otherwise wikis with wgCapitalLinks=false can create lc usernames $newusername = Title::makeTitleSafe(NS_USER, $wgContLang->ucfirst($wgRequest->getText('newusername'))); $oun = is_object($oldusername) ? $oldusername->getText() : ''; $nun = is_object($newusername) ? $newusername->getText() : ''; $token = $wgUser->editToken(); $reason = $wgRequest->getText('reason'); $move_checked = $wgRequest->getBool('movepages', !$wgRequest->wasPosted()); $suppress_checked = $wgRequest->getCheck('suppressredirect'); $warnings = array(); if ($oun && $nun && !$wgRequest->getCheck('confirmaction')) { wfRunHooks('RenameUserWarning', array($oun, $nun, &$warnings)); } $wgOut->addHTML(Xml::openElement('form', array('method' => 'post', 'action' => $this->getTitle()->getLocalUrl(), 'id' => 'renameuser')) . Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('renameuser')) . Xml::openElement('table', array('id' => 'mw-renameuser-table')) . "<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameuserold'), 'oldusername') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('oldusername', 20, $oun, array('type' => 'text', 'tabindex' => '1')) . ' ' . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameusernew'), 'newusername') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('newusername', 20, $nun, array('type' => 'text', 'tabindex' => '2')) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class='mw-label'>" . Xml::label(wfMsg('renameuserreason'), 'reason') . "</td>\n\t\t\t\t<td class='mw-input'>" . Xml::input('reason', 40, $reason, array('type' => 'text', 'tabindex' => '3', 'maxlength' => 255)) . "</td>\n\t\t\t</tr>"); if ($wgUser->isAllowed('move')) { $wgOut->addHTML("\n\t\t\t\t<tr>\n\t\t\t\t\t<td> \n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::checkLabel(wfMsg('renameusermove'), 'movepages', 'movepages', $move_checked, array('tabindex' => '4')) . "</td>\n\t\t\t\t</tr>"); if ($wgUser->isAllowed('suppressredirect')) { $wgOut->addHTML("\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td> \n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td class='mw-input'>" . Xml::checkLabel(wfMsg('renameusersuppress'), 'suppressredirect', 'suppressredirect', $suppress_checked, array('tabindex' => '5')) . "</td>\n\t\t\t\t\t</tr>"); } } if ($warnings) { $warningsHtml = array(); foreach ($warnings as $warning) { $warningsHtml[] = is_array($warning) ? call_user_func_array('wfMsgWikiHtml', $warning) : wfMsgHtml($warning); } $wgOut->addHTML("\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='mw-label'>" . wfMsgWikiHtml('renameuserwarnings') . "\n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>" . '<ul style="color: red; font-weight: bold"><li>' . implode('</li><li>', $warningsHtml) . '</li></ul>' . "</td>\n\t\t\t\t</tr>"); $wgOut->addHTML("\n\t\t\t\t<tr>\n\t\t\t\t\t<td> \n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::checkLabel(wfMsg('renameuserconfirm'), 'confirmaction', 'confirmaction', false, array('tabindex' => '6')) . "</td>\n\t\t\t\t</tr>"); } $wgOut->addHTML("\n\t\t\t<tr>\n\t\t\t\t<td> \n\t\t\t\t</td>\n\t\t\t\t<td class='mw-submit'>" . Xml::submitButton(wfMsg('renameusersubmit'), array('name' => 'submit', 'tabindex' => '7', 'id' => 'submit')) . ' ' . Xml::submitButton(wfMsg('blocklogpage'), array('name' => 'submit-showBlockLog', 'id' => 'submit-showBlockLog', 'tabindex' => '8')) . "</td>\n\t\t\t</tr>" . Xml::closeElement('table') . Xml::closeElement('fieldset') . Html::hidden('token', $token) . Xml::closeElement('form') . "\n"); // Show block log if requested if ($showBlockLog && is_object($oldusername)) { $this->showLogExtract($oldusername, 'block', $wgOut); return; } if ($wgRequest->getText('token') === '') { # They probably haven't even submitted the form, so don't go further. return; } elseif ($warnings) { # Let user read warnings return; } elseif (!$wgRequest->wasPosted() || !$wgUser->matchEditToken($wgRequest->getVal('token'))) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", 'renameuser-error-request'); return; } elseif (!is_object($oldusername)) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrorinvalid', $wgRequest->getText('oldusername'))); return; } elseif (!is_object($newusername)) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrorinvalid', $wgRequest->getText('newusername'))); return; } elseif ($oldusername->getText() == $newusername->getText()) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", 'renameuser-error-same-user'); return; } // Suppress username validation of old username $olduser = User::newFromName($oldusername->getText(), false); $newuser = User::newFromName($newusername->getText(), 'creatable'); // It won't be an object if for instance "|" is supplied as a value if (!is_object($olduser)) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrorinvalid', $oldusername->getText())); return; } if (!is_object($newuser) || !User::isCreatableName($newuser->getName())) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrorinvalid', $newusername->getText())); return; } // Check for the existence of lowercase oldusername in database. // Until r19631 it was possible to rename a user to a name with first character as lowercase if ($oldusername->getText() !== $wgContLang->ucfirst($oldusername->getText())) { // oldusername was entered as lowercase -> check for existence in table 'user' $dbr = wfGetDB(DB_SLAVE); $uid = $dbr->selectField('user', 'user_id', array('user_name' => $oldusername->getText()), __METHOD__); if ($uid === false) { if (!$wgCapitalLinks) { $uid = 0; // We are on a lowercase wiki but lowercase username does not exists } else { // We are on a standard uppercase wiki, use normal $uid = $olduser->idForName(); $oldusername = Title::makeTitleSafe(NS_USER, $olduser->getName()); } } } else { // oldusername was entered as upperase -> standard procedure $uid = $olduser->idForName(); } if ($uid == 0) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrordoesnotexist', $oldusername->getText())); return; } if ($newuser->idForName() != 0) { $wgOut->wrapWikiMsg("<div class=\"errorbox\">\$1</div>", array('renameusererrorexists', $newusername->getText())); return; } // Always get the edits count, it will be used for the log message $contribs = User::edits($uid); // Give other affected extensions a chance to validate or abort if (!wfRunHooks('RenameUserAbort', array($uid, $oldusername->getText(), $newusername->getText()))) { return; } // Do the heavy lifting... $rename = new RenameuserSQL($oldusername->getText(), $newusername->getText(), $uid); if (!$rename->rename()) { return; } // If this user is renaming his/herself, make sure that Title::moveTo() // doesn't make a bunch of null move edits under the old name! if ($wgUser->getId() == $uid) { $wgUser->setName($newusername->getText()); } // Log this rename $log = new LogPage('renameuser'); $log->addEntry('renameuser', $oldusername, wfMsgExt('renameuser-log', array('parsemag', 'content'), $wgContLang->formatNum($contribs), $reason), $newusername->getText()); // Move any user pages if ($wgRequest->getCheck('movepages') && $wgUser->isAllowed('move')) { $dbr = wfGetDB(DB_SLAVE); $pages = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')', '(page_title ' . $dbr->buildLike($oldusername->getDBkey() . '/', $dbr->anyString()) . ' OR page_title = ' . $dbr->addQuotes($oldusername->getDBkey()) . ')'), __METHOD__); $suppressRedirect = false; if ($wgRequest->getCheck('suppressredirect') && $wgUser->isAllowed('suppressredirect')) { $suppressRedirect = true; } $output = ''; foreach ($pages as $row) { $oldPage = Title::makeTitleSafe($row->page_namespace, $row->page_title); $newPage = Title::makeTitleSafe($row->page_namespace, preg_replace('!^[^/]+!', $newusername->getDBkey(), $row->page_title)); # Do not autodelete or anything, title must not exist if ($newPage->exists() && !$oldPage->isValidMoveTarget($newPage)) { $link = Linker::linkKnown($newPage); $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pe'), wfMessage('renameuser-page-exists')->rawParams($link)->escaped()); } else { $success = $oldPage->moveTo($newPage, false, wfMessage('renameuser-move-log', $oldusername->getText(), $newusername->getText())->inContentLanguage()->text(), !$suppressRedirect); if ($success === true) { # oldPage is not known in case of redirect suppression $oldLink = Linker::link($oldPage, null, array(), array('redirect' => 'no')); # newPage is always known because the move was successful $newLink = Linker::linkKnown($newPage); $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pm'), wfMessage('renameuser-page-moved')->rawParams($oldLink, $newLink)->escaped()); } else { $oldLink = Linker::linkKnown($oldPage); $newLink = Linker::link($newPage); $output .= Html::rawElement('li', array('class' => 'mw-renameuser-pu'), wfMessage('renameuser-page-unmoved')->rawParams($oldLink, $newLink)->escaped()); } } } if ($output) { $wgOut->addHTML(Html::rawElement('ul', array(), $output)); } } // Output success message stuff :) $wgOut->wrapWikiMsg("<div class=\"successbox\">\$1</div><br style=\"clear:both\" />", array('renameusersuccess', $oldusername->getText(), $newusername->getText())); }
function synchUsername($username) { global $wgLDAPUniqueBlockLogin, $wgLDAPUniqueRenameUser; global $wgLDAPUniqueAttribute; $this->printDebug("Entering synchUsername", NONSENSITIVE); $this->userInfo = $this->getUserInfo(); if (is_null($this->userInfo)) { $this->printDebug("Failed to get preferences", NONSENSITIVE); } // Are we blocking login/renaming users on unique external ID mismatches? // *** WARNING *** // This needs to be fixed before use! This probably does not work correctly // with all options. It is probably a good idea to refactor the username stuff // in general (as it is currently somewhat of a kludge). Also, MediaWiki does // not currently have support for this. // *** WARNING *** if (isset($wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']]) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']] || isset($wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) { $this->printDebug("Checking for username change in LDAP.", SENSITIVE); //Get the user's unique attribute from LDAP if (isset($wgLDAPUniqueAttribute[$_SESSION['wsDomain']])) { $ldapuniqueattr = $wgLDAPUniqueAttribute[$_SESSION['wsDomain']]; $this->externalid = $this->info[0][$ldapuniqueattr][0]; } else { return false; } $this->printDebug("Retrieved external id: {$this->externalid}", SENSITIVE); $retrievedusername = User::whoIsExternalID("{$this->externalid}"); $this->printDebug("Username (in MediaWiki database) of fetched external id: {$retrievedusername}", SENSITIVE); // See if the username returned from the database matches the username given if ($retrievedusername != '' && $username != $retrievedusername) { if (isset($wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']]) && $wgLDAPUniqueBlockLogin[$_SESSION['wsDomain']]) { $this->printDebug("Usernames do not match, blocking login.", SENSITIVE); return false; } else { if (isset($wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) && $wgLDAPUniqueRenameUser[$_SESSION['wsDomain']]) { $this->printDebug("Usernames do not match, renaming user in database.", SENSITIVE); global $wgVersion; if (version_compare($wgVersion, '1.7.0', '<')) { $this->printDebug("Renaming users is only supported in MediaWiki 1.7+, please upgrade.", SENSITIVE); $this->markAuthFailed(); return false; } $olduser = User::newFromName($retrievedusername); $uid = $olduser->idForName(); // Ensure we don't require the same class twice if (!class_exists('RenameuserSQL')) { require 'Renameuser/SpecialRenameuser_body.php'; } // Make a new rename user object with: from, to, uid of from $rename = new RenameuserSQL($retrievedusername, $username, $uid); $rename->rename(); // For the time being we can't just allow the user to log in // as MediaWiki will try to create the user account after we // do a rename. If we don't return false, the user will get // a database error return false; } } } $this->printDebug("Usernames matched or the user doesn't exist in the database yet.", SENSITIVE); } return true; }
function execute() { global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang; global $wgVersion, $wgMaxNameChars; $fname = 'Renameuser::execute'; $this->setHeaders(); if (!$wgUser->isAllowed('renameuser')) { $wgOut->permissionRequired('renameuser'); return; } if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } if (version_compare($wgVersion, '1.7.0', '<')) { $wgOut->versionRequired('1.7.0'); return; } $oldusername = Title::newFromText($wgRequest->getText('oldusername')); $newusername = Title::newFromText($wgRequest->getText('newusername')); // WERELATE: added isVandal $isVandal = $wgRequest->getVal('isvandal'); $action = $wgTitle->escapeLocalUrl(); $renameuserold = wfMsgHtml('renameuserold'); $renameusernew = wfMsgHtml('renameusernew'); $movepages = wfMsgHtml('renameusermove'); $oun = is_object($oldusername) ? $oldusername->getText() : ''; $nun = is_object($newusername) ? $newusername->getText() : ''; $submit = wfMsgHtml('renameusersubmit'); $token = $wgUser->editToken(); $wgOut->addHTML("\n<!-- Current contributions limit is " . RENAMEUSER_CONTRIBLIMIT . " -->\n<form id='renameuser' method='post' action=\"{$action}\">\n<table>\n\t<tr>\n\t\t<td align='right'>{$renameuserold} </td>\n\t\t<td align='left'><input tabindex='1' type='text' size='20' name='oldusername' value=\"{$oun}\" /></td>\n\t</tr>\n\t<tr>\n\t\t<td align='right'>{$renameusernew} </td>\n\t\t<td align='left'><input tabindex='2' type='text' size='20' name='newusername' value=\"{$nun}\"/></td>\n\t</tr>"); // WERELATE: added isVandal $checkedVandal = $isVandal ? ' checked' : ''; $wgOut->addHTML("\n <tr>\n <td align='right'>Delete watchlist, reset password and email</td>\n <td align='left'><input tabindex='3' type='checkbox' name='isvandal' value=\"yes\"{$checkedVandal}/></td>\n </tr>"); if ($wgUser->isAllowed('move') && version_compare($wgVersion, '1.9alpha', '>=')) { $wgOut->addHTML("\n\t<tr>\n\t\t<td> </td>\n\t\t<td>\n\t\t\t<input tabindex='3' type='checkbox' name='movepages' id='movepages' checked='checked' />\n\t\t\t<label for='movepages'>{$movepages}</label>\n\t\t</td>\n\t</tr>"); } $wgOut->addHTML("\n\t<tr>\n\t\t<td> </td>\n\t\t<td><input type='submit' name='submit' value=\"{$submit}\" /></td>\n\t</tr>\n</table>\n<input type='hidden' name='token' value='{$token}' />\n</form>"); // Sanity checks if (!$wgRequest->wasPosted() || !$wgUser->matchEditToken($wgRequest->getVal('token'))) { return; } if (!is_object($oldusername) || !is_object($newusername) || $oldusername->getText() == $newusername->getText()) { return; } $wgOut->addHTML('<hr />'); // Suppress username validation of old username $olduser = User::newFromName($oldusername->getText(), false); $newuser = User::newFromName($newusername->getText()); // It won't be an object if for instance "|" is supplied as a value if (!is_object($olduser)) { $wgOut->addWikiText(wfMsg('renameusererrorinvalid', $oldusername->getText())); return; } if (!is_object($newuser)) { $wgOut->addWikiText(wfMsg('renameusererrorinvalid', $newusername->getText())); return; } $uid = $olduser->idForName(); if ($uid == 0) { $wgOut->addWikiText(wfMsg('renameusererrordoesnotexist', $oldusername->getText())); return; } // WERELATE: check case-insensitive match // if ($newuser->idForName() != 0) { $dbr =& wfGetDB(DB_SLAVE); $userName = $dbr->selectField('user', 'user_name', array('LOWER(user_name)' => mb_strtolower($newusername->getText()))); if ($userName !== false && $userName != $oldusername->getText()) { $wgOut->addWikiText(wfMsg('renameusererrorexists', $userName)); return; } // Check edit count if (!$wgUser->isAllowed('siteadmin')) { $contribs = User::edits($uid); if (RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT) { $wgOut->addWikiText(wfMsg('renameusererrortoomany', $oldusername->getText(), $wgLang->formatNum($contribs), $wgLang->formatNum(RENAMEUSER_CONTRIBLIMIT))); return; } } // WERELATE: added isVandal $rename = new RenameuserSQL($oldusername->getText(), $newusername->getText(), $uid, $isVandal); $rename->rename(); // WERELATE: don't show in RC $log = new LogPage('renameuser', false); $log->addEntry('renameuser', $oldusername, wfMsgForContent('renameuserlog', $oldusername->getText(), $newusername->getText(), $wgContLang->formatNum($contribs))); $wgOut->addWikiText(wfMsg('renameusersuccess', $oldusername->getText(), $newusername->getText())); if ($wgRequest->getCheck('movepages') && $wgUser->isAllowed('move') && version_compare($wgVersion, '1.9alpha', '>=')) { $dbr =& wfGetDB(DB_SLAVE); $pages = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')', '(page_title LIKE "' . $dbr->escapeLike($oldusername->getDbKey() . '/') . '%" OR page_title = "' . $oldusername->getDbKey() . '")'), __METHOD__); $output = ''; $skin =& $wgUser->getSkin(); while ($row = $dbr->fetchObject($pages)) { $oldPage = Title::makeTitleSafe($row->page_namespace, $row->page_title); $newPage = Title::makeTitleSafe($row->page_namespace, preg_replace('!^[^/]+!', $newusername->getDbKey(), $row->page_title)); if ($newPage->exists() && !$oldPage->isValidMoveTarget($newPage)) { $link = $skin->makeKnownLinkObj($oldPage); $output .= '<li>' . wfMsgHtml('renameuser-page-exists', $link) . '</li>'; } else { $success = $oldPage->moveTo($newPage, false, wfMsg('renameuser-move-log', $oldusername->getText(), $newusername->getText())); if ($success === true) { $oldLink = $skin->makeKnownLinkObj($oldPage); $newLink = $skin->makeKnownLinkObj($newPage); $output .= '<li>' . wfMsgHtml('renameuser-page-moved', $oldLink, $newLink) . '</li>'; } else { $oldLink = $skin->makeKnownLinkObj($oldPage); $newLink = $skin->makeLinkObj($newPage); $output .= '<li>' . wfMsgHtml('renameuser-page-unmoved', $oldLink, $newLink) . '</li>'; } } } if ($output) { $wgOut->addHtml('<ul>' . $output . '</ul>'); } } }