/** * @covers CentralAuthUser::exists * @covers CentralAuthUser::getId * @covers CentralAuthUser::getName * @covers CentralAuthUser::getHomeWiki * @covers CentralAuthUser::isAttached * @covers CentralAuthUser::getRegistration * @covers CentralAuthUser::getStateHash */ public function testBasicAttrs() { $caUser = new CentralAuthUser('GlobalUser'); $this->assertSame(true, $caUser->exists()); $this->assertEquals(1001, $caUser->getId()); $this->assertEquals('GlobalUser', $caUser->getName()); $this->assertEquals(wfWikiID(), $caUser->getHomeWiki()); $this->assertSame(true, $caUser->isAttached()); $this->assertSame(false, $caUser->isLocked()); $this->assertEquals('20130627183537', $caUser->getRegistration()); $this->assertEquals(CentralAuthUser::HIDDEN_NONE, $caUser->getHiddenLevel()); $this->assertEquals('2234d7949459185926a50073d174b673', $caUser->getStateHash()); }
public function execute() { $globalUser = new CentralAuthUser($this->getParameter('user')); if (!$this->getUser()->isAllowed('centralauth-lock')) { $this->dieUsageMsg(array('badaccess-groups')); } elseif (!$globalUser->exists()) { $this->dieUsageMsg(array('nosuchuser', $globalUser->getName())); } elseif ($globalUser->isOversighted() && !$this->getUser()->isAllowed('centralauth-oversight')) { $this->dieUsageMsg(array('nosuchuser', $globalUser->getName())); } elseif (!$this->getRequest()->getCheck('locked') && $this->getParameter('hidden') === null) { $this->dieUsage("At least one of the parameters locked, hidden is required", "missingparam"); } $setLocked = $this->getParameter('locked'); if (!$setLocked) { // Don't lock or unlock $setLocked = null; } else { $setLocked = $setLocked === 'lock'; } $setHidden = $this->getParameter('hidden'); $reason = $this->getParameter('reason'); $stateCheck = $this->getParameter('statecheck'); if ($stateCheck && $stateCheck !== $globalUser->getStateHash(true)) { $this->dieUsage('Edit conflict detected, Aborting.', 'editconflict'); } $status = $globalUser->adminLockHide($setLocked, $setHidden, $reason, $this->getContext()); // Logging etc if ($status->isGood()) { $this->getResult()->addValue(null, $this->getModuleName(), array('user' => $globalUser->getName(), 'locked' => $globalUser->isLocked(), 'hidden' => $globalUser->getHiddenLevel(), 'reason' => $reason)); } else { if (is_callable(array($this, 'getErrorFormatter'))) { $error = $this->getErrorFormatter()->arrayFromStatus($status); } else { $error = $this->getResult()->convertStatusToArray($status); } $this->getResult()->addValue('error', null, $error); $this->getResult()->addValue(null, $this->getModuleName(), array('user' => $globalUser->getName(), 'locked' => $globalUser->isLocked(), 'hidden' => $globalUser->getHiddenLevel())); } }
private function showStatusForm() { // Allows locking, hiding, locking and hiding. $form = ''; $form .= Xml::fieldset($this->msg('centralauth-admin-status')->text()); $form .= Html::hidden('wpMethod', 'set-status'); $form .= Html::hidden('wpEditToken', $this->getUser()->getEditToken()); $form .= Html::hidden('wpUserState', $this->mGlobalUser->getStateHash(false)); $form .= $this->msg('centralauth-admin-status-intro')->parseAsBlock(); // Radio buttons $radioLocked = Xml::radioLabel($this->msg('centralauth-admin-status-locked-no')->parse(), 'wpStatusLocked', '0', 'mw-centralauth-status-locked-no', !$this->mGlobalUser->isLocked()) . '<br />' . Xml::radioLabel($this->msg('centralauth-admin-status-locked-yes')->parse(), 'wpStatusLocked', '1', 'mw-centralauth-status-locked-yes', $this->mGlobalUser->isLocked()); $radioHidden = Xml::radioLabel($this->msg('centralauth-admin-status-hidden-no')->parse(), 'wpStatusHidden', CentralAuthUser::HIDDEN_NONE, 'mw-centralauth-status-hidden-no', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_NONE); if ($this->mCanOversight) { $radioHidden .= '<br />' . Xml::radioLabel($this->msg('centralauth-admin-status-hidden-list')->parse(), 'wpStatusHidden', CentralAuthUser::HIDDEN_LISTS, 'mw-centralauth-status-hidden-list', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_LISTS) . '<br />' . Xml::radioLabel($this->msg('centralauth-admin-status-hidden-oversight')->parse(), 'wpStatusHidden', CentralAuthUser::HIDDEN_OVERSIGHT, 'mw-centralauth-status-hidden-oversight', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_OVERSIGHT); } // Reason $reasonList = Xml::listDropDown('wpReasonList', $this->msg('centralauth-admin-status-reasons')->inContentLanguage()->text(), $this->msg('centralauth-admin-reason-other-select')->inContentLanguage()->text()); $reasonField = Xml::input('wpReason', 45, false); $form .= Xml::buildForm(array('centralauth-admin-status-locked' => $radioLocked, 'centralauth-admin-status-hidden' => $radioHidden, 'centralauth-admin-reason' => $reasonList, 'centralauth-admin-reason-other' => $reasonField), 'centralauth-admin-status-submit'); $form .= Xml::closeElement('fieldset'); $form = Xml::tags('form', array('method' => 'POST', 'action' => $this->getPageTitle()->getFullURL(array('target' => $this->mUserName))), $form); $this->getOutput()->addHTML($form); }