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()));
     }
 }
 function showStatusForm()
 {
     // Allows locking, hiding, locking and hiding.
     $form = '';
     $form .= Xml::fieldset(wfMsg('centralauth-admin-status'));
     $form .= Html::hidden('wpMethod', 'set-status');
     $form .= Html::hidden('wpEditToken', $this->getUser()->getEditToken());
     $form .= wfMsgExt('centralauth-admin-status-intro', 'parse');
     // Radio buttons
     $radioLocked = Xml::radioLabel(wfMsgExt('centralauth-admin-status-locked-no', array('parseinline')), 'wpStatusLocked', '0', 'mw-centralauth-status-locked-no', !$this->mGlobalUser->isLocked()) . '<br />' . Xml::radioLabel(wfMsgExt('centralauth-admin-status-locked-yes', array('parseinline')), 'wpStatusLocked', '1', 'mw-centralauth-status-locked-yes', $this->mGlobalUser->isLocked());
     $radioHidden = Xml::radioLabel(wfMsgExt('centralauth-admin-status-hidden-no', array('parseinline')), 'wpStatusHidden', CentralAuthUser::HIDDEN_NONE, 'mw-centralauth-status-hidden-no', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_NONE) . '<br />' . Xml::radioLabel(wfMsgExt('centralauth-admin-status-hidden-list', array('parseinline')), 'wpStatusHidden', CentralAuthUser::HIDDEN_LISTS, 'mw-centralauth-status-hidden-list', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_LISTS) . '<br />';
     if ($this->mCanOversight) {
         $radioHidden .= Xml::radioLabel(wfMsgExt('centralauth-admin-status-hidden-oversight', array('parseinline')), 'wpStatusHidden', CentralAuthUser::HIDDEN_OVERSIGHT, 'mw-centralauth-status-hidden-oversight', $this->mGlobalUser->getHiddenLevel() == CentralAuthUser::HIDDEN_OVERSIGHT);
     }
     // Reason
     $reasonList = Xml::listDropDown('wpReasonList', wfMsgForContent('centralauth-admin-status-reasons'), wfMsgForContent('ipbreasonotherlist'));
     $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 .= '</fieldset>';
     $form = Xml::tags('form', array('method' => 'POST', 'action' => $this->getTitle()->getFullURL(array('target' => $this->mUserName))), $form);
     $this->getOutput()->addHTML($form);
 }
 /**
  * @param CentralAuthUser $globalUser
  * @return string
  */
 private function getUserTableRow(CentralAuthUser $globalUser)
 {
     $rowHtml = '';
     // @TODO: Don't use methods from the special page directly,
     // rather move them somewhere sane
     $sca = new SpecialCentralAuth();
     $sca->setContext($this->getContext());
     $guName = $globalUser->getName();
     $guLink = Linker::link(SpecialPage::getTitleFor('CentralAuth', $guName), htmlspecialchars($guName));
     $guHidden = $sca->formatHiddenLevel($globalUser->getHiddenLevel());
     $accountAge = time() - wfTimestamp(TS_UNIX, $globalUser->getRegistration());
     $guRegister = $sca->prettyTimespan($accountAge);
     $guLocked = $this->msg('centralauth-admin-status-locked-no')->escaped();
     if ($globalUser->isLocked()) {
         $guLocked = $this->msg('centralauth-admin-status-locked-yes')->escaped();
     }
     $guEditCount = htmlspecialchars($this->getLanguage()->formatNum($globalUser->getGlobalEditCount()));
     $guAttachedLocalAccounts = htmlspecialchars($this->getLanguage()->formatNum(count($globalUser->listAttached())));
     $rowHtml .= Html::rawElement('td', array(), Html::input('wpActionTarget[' . $guName . ']', $guName, 'checkbox', array('checked' => 'checked')));
     $rowHtml .= Html::rawElement('td', array(), $guLink);
     $rowHtml .= Html::element('td', array('data-sort-value' => $accountAge), $guRegister);
     $rowHtml .= Html::element('td', array(), $guLocked);
     $rowHtml .= Html::element('td', array(), $guHidden);
     $rowHtml .= Html::element('td', array(), $guEditCount);
     $rowHtml .= Html::element('td', array(), $guAttachedLocalAccounts);
     return $rowHtml;
 }
 /**
  * Get the username from CentralAuth for a list of CentralAuth user id's. Sets the name
  * to false if the userid doesn't exist, or the username is hidden.
  * @param string $wgMWOAuthCentralWiki
  * @param array &$namesById array of userIds=>names to associate
  * @param bool|User $audience show hidden names based on this user, or false for public
  * @param string $wgMWOAuthSharedUserSource the authoritative extension
  */
 public static function onOAuthGetUserNamesFromCentralIds($wgMWOAuthCentralWiki, &$namesById, $audience, $wgMWOAuthSharedUserSource)
 {
     if ($wgMWOAuthSharedUserSource !== 'CentralAuth') {
         // We aren't supposed to handle this
         return true;
     }
     $dbr = CentralAuthUser::getCentralSlaveDB();
     foreach ($namesById as $userid => $name) {
         $name = $dbr->selectField('globaluser', 'gu_name', array('gu_id' => $userid), __METHOD__);
         $namesById[$userid] = $name;
         $centralUser = new CentralAuthUser($name);
         if ($centralUser->getHiddenLevel() !== CentralAuthUser::HIDDEN_NONE && !($audience instanceof User && $audience->isAllowed('centralauth-oversight'))) {
             $namesById[$userid] = '';
         }
     }
     return true;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $prop = array_flip((array) $params['prop']);
     if (is_null($params['user'])) {
         $params['user'] = $this->getUser()->getName();
     }
     $user = new CentralAuthUser($params['user']);
     // Add basic info
     $result = $this->getResult();
     $data = array();
     $userExists = $user->exists();
     if ($userExists && ($user->getHiddenLevel() === CentralAuthUser::HIDDEN_NONE || $this->getUser()->isAllowed('centralauth-oversight'))) {
         // The global user exists and it's not hidden or the current user is allowed to see it
         $data['home'] = $user->getHomeWiki();
         $data['id'] = $user->getId();
         $data['registration'] = wfTimestamp(TS_ISO_8601, $user->getRegistration());
         $data['name'] = $user->getName();
         if ($user->isLocked()) {
             $data['locked'] = '';
         }
         if ($user->isHidden()) {
             $data['hidden'] = '';
         }
     } else {
         // The user doesn't exist or we pretend it doesn't if it's hidden
         $data['missing'] = '';
     }
     $result->addValue('query', $this->getModuleName(), $data);
     // Add requested info
     if ($userExists && isset($prop['groups'])) {
         $groups = $user->getGlobalGroups();
         $result->setIndexedTagName($groups, 'g');
         $result->addValue(array('query', $this->getModuleName()), 'groups', $groups);
     }
     if ($userExists && isset($prop['rights'])) {
         $rights = $user->getGlobalRights();
         $result->setIndexedTagName($rights, 'r');
         $result->addValue(array('query', $this->getModuleName()), 'rights', $rights);
     }
     $attachedAccounts = null;
     if ($userExists && (isset($prop['merged']) || isset($prop['editcount']))) {
         $attachedAccounts = $user->queryAttached();
     }
     if ($userExists && isset($prop['merged'])) {
         foreach ($attachedAccounts as $account) {
             $dbname = $account['wiki'];
             $wiki = WikiMap::getWiki($dbname);
             $a = array('wiki' => $dbname, 'url' => $wiki->getCanonicalServer(), 'timestamp' => wfTimestamp(TS_ISO_8601, $account['attachedTimestamp']), 'method' => $account['attachedMethod'], 'editcount' => $account['editCount']);
             if ($account['blocked']) {
                 $a['blocked'] = array('expiry' => $this->getLanguage()->formatExpiry($account['block-expiry'], TS_ISO_8601), 'reason' => $account['block-reason']);
             }
             $result->addValue(array('query', $this->getModuleName(), 'merged'), null, $a);
         }
         if (defined('ApiResult::META_CONTENT')) {
             $result->addIndexedTagName(array('query', $this->getModuleName(), 'merged'), 'account');
         } else {
             $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'merged'), 'account');
         }
     }
     if ($userExists && isset($prop['editcount'])) {
         $editcount = 0;
         foreach ($attachedAccounts as $account) {
             $editcount += $account['editCount'];
         }
         $result->addValue('query', $this->getModuleName(), array('editcount' => $editcount));
     }
     if (isset($prop['unattached'])) {
         $accounts = $user->queryUnattached();
         foreach ($accounts as $account) {
             $a = array('wiki' => $account['wiki'], 'editcount' => $account['editCount']);
             if ($account['blocked']) {
                 $a['blocked'] = array('expiry' => $this->getLanguage()->formatExpiry($account['block-expiry'], TS_ISO_8601), 'reason' => $account['block-reason']);
             }
             $result->addValue(array('query', $this->getModuleName(), 'unattached'), null, $a);
         }
         if (defined('ApiResult::META_CONTENT')) {
             $result->addIndexedTagName(array('query', $this->getModuleName(), 'unattached'), 'account');
         } else {
             $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'unattached'), 'account');
         }
     }
 }
 /**
  * @covers CentralAuthUser::isHidden
  * @covers CentralAuthUser::isOversighted
  * @covers CentralAuthUser::getHiddenLevel
  */
 public function testHidden()
 {
     $caUser = new CentralAuthUser('GlobalSuppressedUser');
     $this->assertSame(true, $caUser->exists());
     $this->assertSame(true, $caUser->isHidden());
     $this->assertSame(true, $caUser->isOversighted());
     $this->assertEquals(CentralAuthUser::HIDDEN_OVERSIGHT, $caUser->getHiddenLevel());
 }