/**
  * Get the CentralAuthUser from a line of text
  *
  * @param $username string
  * @return CentralAuthUser|string User object, or a string containing the error
  */
 private function getGlobalUser($username)
 {
     $username = trim($username);
     if ($username === '') {
         return false;
     }
     $username = $this->getLanguage()->ucfirst($username);
     $globalUser = new CentralAuthUser($username);
     if (!$globalUser->exists() || !$this->mCanOversight && ($globalUser->isOversighted() || $globalUser->isHidden())) {
         return $this->msg('centralauth-admin-nonexistent', $username)->parse();
     }
     return $globalUser;
 }
 /**
  * This is also used in SpecialGlobalRenameQueue
  *
  * @param string $oldname User's old (current) name
  * @param array $conflicts Conflicting usernames
  * @return array Usernames that are safe for display
  */
 public function processAntiSpoofConflicts($oldname, array $conflicts)
 {
     $display = array();
     foreach ($conflicts as $name) {
         if ($name === $oldname) {
             // Not a conflict since the old usage will go away
             continue;
         }
         $ca = new CentralAuthUser($name);
         if ($ca->isHidden()) {
             $display[] = $this->msg('centralauth-rename-conflict-hidden')->text();
         } else {
             $display[] = $name;
         }
     }
     return $display;
 }
 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) {
         $data['home'] = $user->getHomeWiki();
         $data['id'] = $user->getId();
         $data['registration'] = wfTimestamp(TS_ISO_8601, $user->getRegistration());
         if ($user->isLocked()) {
             $data['locked'] = '';
         }
         if ($user->isHidden()) {
             $data['hidden'] = '';
         }
     } else {
         $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);
     }
     if ($userExists && isset($prop['merged'])) {
         $accounts = $user->queryAttached();
         foreach ($accounts as $account) {
             $dbname = $account['wiki'];
             $a = array('wiki' => $dbname, 'url' => $this->getUrl($dbname), '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);
         }
         $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'merged'), 'account');
     }
     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);
         }
         $result->setIndexedTagName_internal(array('query', $this->getModuleName(), 'unattached'), 'account');
     }
 }
 public function execute($subpage)
 {
     global $wgContLang;
     $this->setHeaders();
     $this->mCanUnmerge = $this->getUser()->isAllowed('centralauth-unmerge');
     $this->mCanLock = $this->getUser()->isAllowed('centralauth-lock');
     $this->mCanOversight = $this->getUser()->isAllowed('centralauth-oversight');
     $this->mCanEdit = $this->mCanUnmerge || $this->mCanLock || $this->mCanOversight;
     $this->getOutput()->setPageTitle($this->msg($this->mCanEdit ? 'centralauth' : 'centralauth-ro'));
     $this->getOutput()->addModules('ext.centralauth');
     $this->getOutput()->addModules('ext.centralauth.globaluserautocomplete');
     $this->getOutput()->addModuleStyles('ext.centralauth.noflash');
     $this->getOutput()->addJsConfigVars('wgMergeMethodDescriptions', $this->getMergeMethodDescriptions());
     $this->mUserName = trim(str_replace('_', ' ', $this->getRequest()->getText('target', $subpage)));
     $this->mUserName = $wgContLang->ucfirst($this->mUserName);
     $this->mPosted = $this->getRequest()->wasPosted();
     $this->mMethod = $this->getRequest()->getVal('wpMethod');
     $this->mWikis = (array) $this->getRequest()->getArray('wpWikis');
     // Possible demo states
     // success, all accounts merged
     // successful login, some accounts merged, others left
     // successful login, others left
     // not account owner, others left
     // is owner / is not owner
     // did / did not merge some accounts
     // do / don't have more accounts to merge
     if ($this->mUserName === '') {
         # First time through
         $this->getOutput()->addWikiMsg('centralauth-admin-intro');
         $this->showUsernameForm();
         return;
     }
     // per bug 47991
     $this->getOutput()->setHTMLTitle($this->msg('pagetitle', $this->msg($this->mCanEdit ? 'centralauth-admin-title' : 'centralauth-admin-title-ro', $this->mUserName)->plain()));
     $this->mGlobalUser = $globalUser = new CentralAuthUser($this->mUserName);
     if (($globalUser->isOversighted() || $globalUser->isHidden()) && !$this->mCanOversight) {
         // Claim that there's nothing if the global account is hidden and the user is not
         // allowed to see it.
         $this->showNonexistentError();
         return;
     }
     $continue = true;
     if ($this->mCanEdit && $this->mPosted) {
         $continue = $this->doSubmit();
     }
     // Show just a user friendly message when a rename is in progress
     try {
         $this->mAttachedLocalAccounts = $globalUser->queryAttached();
     } catch (Exception $e) {
         if ($globalUser->renameInProgress()) {
             $this->showRenameInProgressError();
             return;
         }
         // Rethrow
         throw $e;
     }
     $this->mUnattachedLocalAccounts = $globalUser->queryUnattached();
     if (!$globalUser->exists() && !count($this->mUnattachedLocalAccounts)) {
         // Nothing to see here
         $this->showNonexistentError();
         return;
     }
     $this->showUsernameForm();
     if ($continue && $globalUser->exists()) {
         $this->showInfo();
         if ($this->mCanLock) {
             $this->showStatusForm();
         }
         if ($this->mCanUnmerge) {
             $this->showActionForm('delete');
         }
         $this->showLogExtract();
         $this->showWikiLists();
     } elseif ($continue && !$globalUser->exists()) {
         // No global account, but we can still list the local ones
         $this->showError('centralauth-admin-nonexistent', $this->mUserName);
         $this->showWikiLists();
     }
 }
 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::adminLock
  * @covers CentralAuthUser::adminUnlock
  * @covers CentralAuthUser::adminSetHidden
  */
 public function testAdminLockAndHide()
 {
     $caUser = new CentralAuthUser('GlobalUser');
     $this->assertSame(true, $caUser->exists());
     #sanity
     $this->assertSame(false, $caUser->isHidden());
     #sanity
     $this->assertSame(false, $caUser->isLocked());
     #sanity
     $caUser->adminLock();
     $caUser->adminSetHidden(CentralAuthUser::HIDDEN_LISTS);
     // Check the DB
     $this->assertSelect('globaluser', array('gu_name', 'gu_locked', 'gu_hidden'), array('gu_name' => 'GlobalUser'), array(array('GlobalUser', '1', CentralAuthUser::HIDDEN_LISTS)));
     $caUser = new CentralAuthUser('GlobalUser');
     $this->assertSame(true, $caUser->exists());
     $this->assertSame(true, $caUser->isLocked());
     $this->assertSame(true, $caUser->isHidden());
     $caUser->adminUnlock();
     $caUser->adminSetHidden(CentralAuthUser::HIDDEN_NONE);
     $caUser = new CentralAuthUser('GlobalUser');
     $this->assertSame(true, $caUser->exists());
     $this->assertSame(false, $caUser->isHidden());
     $this->assertSame(false, $caUser->isLocked());
 }