/**
  * Perform validation on the user submitted data
  * and check that we can perform the rename
  * @param array $data
  *
  * @return Status
  */
 function validate(array $data)
 {
     if (!class_exists('RenameuserSQL')) {
         return Status::newFatal('centralauth-rename-notinstalled');
     }
     $oldUser = User::newFromName($data['oldname']);
     if (!$oldUser) {
         return Status::newFatal('centralauth-rename-doesnotexist');
     }
     if ($oldUser->getName() === $this->getUser()->getName()) {
         return Status::newFatal('centralauth-rename-cannotself');
     }
     $newUser = User::newFromName($data['newname']);
     if (!$newUser) {
         return Status::newFatal('centralauth-rename-badusername');
     }
     if (!$this->overrideAntiSpoof && class_exists('CentralAuthSpoofUser')) {
         $spoofUser = new CentralAuthSpoofUser($newUser->getName());
         $conflicts = $this->processAntiSpoofConflicts($oldUser->getName(), $spoofUser->getConflicts());
         if ($conflicts) {
             return Status::newFatal('centralauth-rename-antispoofconflicts2', $this->getLanguage()->commaList($conflicts));
         }
     }
     $validator = new GlobalRenameUserValidator();
     $status = $validator->validate($oldUser, $newUser);
     return $status;
 }
 /**
  * On rename, remove the old entry and add the new
  * (After a sucessful user rename)
  *
  * @param $uid
  * @param $oldName string
  * @param $newName string
  * @return bool
  */
 public static function asAddRenameUserHook($uid, $oldName, $newName)
 {
     $spoof = new CentralAuthSpoofUser($newName);
     $spoof->update($oldName);
     return true;
 }
 /**
  * Display form for approving/denying request or process form submission.
  *
  * @param GlobalRenameRequest $req Pending request
  */
 protected function doShowProcessForm(GlobalRenameRequest $req)
 {
     $this->commonPreamble('globalrenamequeue-request-title', array($req->getName()));
     $form = HTMLForm::factory('vform', array('rid' => array('default' => $req->getId(), 'name' => 'rid', 'type' => 'hidden'), 'comments' => array('default' => $this->getRequest()->getVal('comments'), 'id' => 'mw-renamequeue-comments', 'label-message' => 'globalrenamequeue-request-comments-label', 'name' => 'comments', 'type' => 'textarea', 'rows' => 5), 'reason' => array('id' => 'mw-renamequeue-reason', 'label-message' => 'globalrenamequeue-request-reason-label', 'name' => 'reason', 'type' => 'text'), 'movepages' => array('id' => 'mw-renamequeue-movepages', 'name' => 'movepages', 'label-message' => 'globalrenamequeue-request-movepages', 'type' => 'check', 'default' => 1), 'suppressredirects' => array('id' => 'mw-renamequeue-suppressredirects', 'name' => 'suppressredirects', 'label-message' => 'globalrenamequeue-request-suppressredirects', 'type' => 'check')), $this->getContext(), 'globalrenamequeue');
     $form->suppressDefaultSubmit();
     $form->addButton('approve', $this->msg('globalrenamequeue-request-approve-text')->text(), 'mw-renamequeue-approve', array('class' => 'mw-ui-constructive mw-ui-flush-right'));
     $form->addButton('deny', $this->msg('globalrenamequeue-request-deny-text')->text(), 'mw-renamequeue-deny', array('class' => 'mw-ui-destructive mw-ui-flush-right'));
     $form->addButton('cancel', $this->msg('globalrenamequeue-request-cancel-text')->text(), 'mw-renamequeue-cancel', array('class' => 'mw-ui-quiet mw-ui-flush-left'));
     $form->setId('mw-globalrenamequeue-request');
     if ($req->userIsGlobal()) {
         $globalUser = new CentralAuthUser($req->getName());
         $homeWiki = $globalUser->getHomeWiki();
         $infoMsgKey = 'globalrenamequeue-request-userinfo-global';
     } else {
         $homeWiki = $req->getWiki();
         $infoMsgKey = 'globalrenamequeue-request-userinfo-local';
     }
     $headerMsg = $this->msg('globalrenamequeue-request-header', WikiMap::getForeignURL($homeWiki, "User:{$req->getName()}"), $req->getName(), $req->getNewName());
     $form->addHeaderText('<span class="plainlinks">' . $headerMsg->parseAsBlock() . '</span>');
     $homeWikiWiki = WikiMap::getWiki($homeWiki);
     $infoMsg = $this->msg($infoMsgKey, $req->getName(), $homeWikiWiki ? $homeWikiWiki->getDisplayName() : $homeWiki, $req->getNewName());
     $form->addHeaderText($infoMsg->parseAsBlock());
     if (class_exists('CentralAuthSpoofUser')) {
         $spoofUser = new CentralAuthSpoofUser($req->getNewName());
         // @todo move this code somewhere else
         $specialGblRename = new SpecialGlobalRenameUser();
         $specialGblRename->setContext($this->getContext());
         $conflicts = $specialGblRename->processAntiSpoofConflicts($req->getName(), $spoofUser->getConflicts());
         if ($conflicts) {
             $form->addHeaderText($this->msg('globalrenamequeue-request-antispoof-conflicts', $this->getLanguage()->commaList($conflicts))->numParams(count($conflicts))->parse());
         }
     }
     // Show a log entry of previous renames under the requesting user's username
     $caTitle = Title::makeTitleSafe(NS_SPECIAL, 'CentralAuth/' . $req->getName());
     $extract = '';
     $extractCount = LogEventsList::showLogExtract($extract, 'gblrename', $caTitle, '', array('showIfEmpty' => false));
     if ($extractCount) {
         $form->addHeaderText(Xml::fieldset($this->msg('globalrenamequeue-request-previous-renames')->numParams($extractCount)->text(), $extract));
     }
     $reason = $req->getReason() ?: $this->msg('globalrenamequeue-request-reason-sul')->parseAsBlock();
     $form->addHeaderText($this->msg('globalrenamequeue-request-reason', $reason)->parseAsBlock());
     $form->setSubmitCallback(array($this, 'onProcessSubmit'));
     $out = $this->getOutput();
     $out->addModuleStyles(array('mediawiki.ui', 'mediawiki.ui.button', 'mediawiki.ui.input', 'ext.centralauth.globalrenamequeue.styles'));
     $out->addModules('ext.centralauth.globalrenamequeue');
     $status = $form->show();
     if ($status instanceof Status && $status->isOk()) {
         $this->getOutput()->redirect($this->getPageTitle(self::PAGE_PROCESS_REQUEST . "/{$req->getId()}/{$status->value}")->getFullURL());
     }
 }
コード例 #4
0
 /**
  * @param $items array
  */
 protected function batchRecord($items)
 {
     CentralAuthSpoofUser::batchRecord($items);
 }
コード例 #5
0
 /**
  * Remove the current username from the central AntiSpoof system
  * if that feature is enabled
  */
 public function removeAntiSpoof()
 {
     if (class_exists('CentralAuthSpoofUser')) {
         $spoof = new CentralAuthSpoofUser($this->mName);
         $spoof->remove();
     }
 }
コード例 #6
0
 /**
  * Rename a global user (this assumes that the data has been verified before
  * and that $newUser is being a creatable user)!
  *
  * @param $options array
  * @return Status
  */
 public function rename(array $options)
 {
     $wikis = $this->oldCAUser->listAttached();
     $status = $this->setRenameStatuses($wikis);
     if (!$status->isOK()) {
         return $status;
     }
     $this->databaseUpdates->update($this->oldUser->getName(), $this->newUser->getName());
     // Update CA's AntiSpoof if enabled
     if (class_exists('CentralAuthSpoofUser')) {
         $spoof = new CentralAuthSpoofUser($this->newUser->getName());
         $spoof->update($this->oldUser->getName());
     }
     // From this point on all code using CentralAuthUser
     // needs to use the new username, except for
     // the renameInProgress function. Probably.
     // Clear some caches...
     $this->oldCAUser->quickInvalidateCache();
     $this->newCAUser->quickInvalidateCache();
     $this->injectLocalRenameUserJobs($wikis, $options);
     $this->logger->log($this->oldUser->getName(), $this->newUser->getName(), $options['reason']);
     return Status::newGood();
 }
コード例 #7
0
 /**
  * @param $items array
  */
 protected function batchRecord($items)
 {
     CentralAuthSpoofUser::batchRecord($this->getDB(), $items);
 }