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()->addModules('ext.centralauth');
     $this->getOutput()->addModuleStyles('ext.centralauth.noflash');
     $this->addMergeMethodDescriptions();
     $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;
     }
     $this->mGlobalUser = $globalUser = new CentralAuthUser($this->mUserName);
     if (!$globalUser->exists() || $globalUser->isOversighted() && !$this->mCanOversight) {
         $this->showError('centralauth-admin-nonexistent', $this->mUserName);
         $this->showUsernameForm();
         return;
     }
     $continue = true;
     if ($this->mCanEdit && $this->mPosted) {
         $continue = $this->doSubmit();
     }
     $this->mAttachedLocalAccounts = $this->mGlobalUser->queryAttached();
     $this->mUnattachedLocalAccounts = $this->mGlobalUser->queryUnattached();
     $this->showUsernameForm();
     if ($continue) {
         $this->showInfo();
         if ($this->mCanLock) {
             $this->showStatusForm();
         }
         if ($this->mCanUnmerge) {
             $this->showActionForm('delete');
         }
         if ($this->mCanEdit) {
             $this->showLogExtract();
         }
         $this->showWikiLists();
     }
 }
Esempio n. 2
0
 /**
  * Switches a user's preferences off
  * @param $user User object to set preferences for
  * @param $global bool Whether to apply this change on all wikis in $wgPrefSwitchWikis
  */
 public static function switchOff($user, $global = false)
 {
     self::switchOffUser($user);
     if ($global) {
         $globalUser = new CentralAuthUser($user->getName());
         if (!$globalUser->exists()) {
             return;
         }
         $accounts = $globalUser->queryAttached();
         foreach ($accounts as $account) {
             $remoteUser = UserRightsProxy::newFromName($account['wiki'], $globalUser->getName(), true);
             if ($remoteUser) {
                 self::switchOffUser($remoteUser);
             }
         }
     }
 }
Esempio n. 3
0
	/**
	 * Checks how many central wikis the user is blocked on
	 * @param $user User
	 * @return Integer the number of wikis the user is blocked on.
	 */
	function getCentralBlockCount( $user ) {
		if ( ! class_exists( 'CentralAuthUser' ) ) {
			return 0;
		}
		
		$centralUser = new CentralAuthUser( $user->getName() );
		
		$attached = $centralUser->queryAttached();
		$blockCount = 0;
		
		foreach( $attached as $wiki => $data ) {
			if ( $data['blocked'] ) {
				$blockCount++;
			}
		}
		
		return $blockCount;
	}
 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');
         }
     }
 }