public function resetUserProfile() { wfProfileIn(__METHOD__); if (!$this->checkRequest()) { wfProfileOut(__METHOD__); return; } $user = $this->request->getVal('user'); if (empty($user)) { $this->response->setVal('success', false); $this->response->setVal('errorMsg', wfMessage('coppatool-invalid-user')->plain()); wfProfileOut(__METHOD__); return; } $userObj = User::newFromName($user); if (!$userObj instanceof User || $userObj->getId() === 0) { $this->response->setVal('success', false); $this->response->setVal('errorMsg', wfMessage('coppatool-invalid-user')->plain()); wfProfileOut(__METHOD__); return; } $userIdentityBox = new UserIdentityBox($userObj); $userIdentityBox->resetUserProfile(); $this->response->setVal('success', true); wfProfileOut(__METHOD__); }
/** * Don't send 404 status for user pages with filled in masthead (bugid:44602) * @brief hook handler * * @param Article $article * * @return Boolean */ public static function onBeforeDisplayNoArticleText($article) { global $UPPNamespaces; $wg = F::app()->wg; $title = $article->getTitle(); if ($title instanceof Title && in_array($title->getNamespace(), $UPPNamespaces)) { $user = UserProfilePageHelper::getUserFromTitle($title); if ($user instanceof User && $user->getId() > 0) { $userIdentityBox = new UserIdentityBox($user); $userData = $userIdentityBox->getFullData(); if (is_array($userData) && array_key_exists('showZeroStates', $userData)) { if (!$userData['showZeroStates']) { $wg->Out->setStatusCode(200); } } } } return true; }
/** * Before resetting the options, save the masthead info so we can restore it in onSpecialPreferencesAfterResetUserOptions * * @param $storage - storage in which we can save some options, it will be passed in onSpecialPreferencesAfterResetUserOptions hook call * @param User $user */ public static function onSpecialPreferencesBeforeResetUserOptions($preferences, &$user, &$storage) { // user identity box/masthead $userIdentityObject = new UserIdentityBox($user); $mastheadOptions = $userIdentityObject->getFullData(); $masthead = new Masthead($user); if (!empty($masthead->mUser->mOptionOverrides['avatar'])) { $mastheadOptions['avatar'] = $masthead->mUser->mOptionOverrides['avatar']; } $storage[self::MASTHEAD_OPTIONS_STORAGE_ARRAY_KEY_NAME] = $mastheadOptions; // customize toolbar/myToolbar $oasisToolbarService = new SharedToolbarService(); $toolbarNameInUserOptions = $oasisToolbarService->getToolbarOptionName(); $toolbarCurrentList = $user->getGlobalPreference($oasisToolbarService->getToolbarOptionName()); $storage[self::MY_TOOLBAR_OPTIONS_STORAGE_ARRAY_KEY_NAME] = array($toolbarNameInUserOptions => $toolbarCurrentList); return true; }
/** * @brief Gets fav wikis information and passes it as JSON * * @author Andrzej 'nAndy' Łukaszewski */ public function onRefreshFavWikis() { $userId = intval($this->getVal('userId')); $user = User::newFromId($userId); $userIdentityBox = new UserIdentityBox($user); $result = array('success' => true, 'wikis' => $userIdentityBox->getTopWikis(true)); $this->setVal('result', $result); }
/** * @dataProvider checkIfDisplayZeroStatesDataProvider * * @author Andrzej 'nAndy' Łukaszewski */ public function testCheckIfDisplayZeroStates($data, $expectedResult) { $userIdentityBox = new UserIdentityBox(F::app(), $this->getMock('User'), self::TOP_WIKI_LIMIT); $this->assertEquals($expectedResult, $userIdentityBox->checkIfDisplayZeroStates($data)); }
/** * @dataProvider checkIfDisplayZeroStatesDataProvider * * @author Andrzej 'nAndy' Łukaszewski */ public function testCheckIfDisplayZeroStates($data, $expectedResult) { $userIdentityBox = new UserIdentityBox($this->getMock('User')); $this->assertEquals($expectedResult, $userIdentityBox->checkIfDisplayZeroStates($data)); }
/** * Before resetting the options, save the masthead info so we can restore it in onSpecialPreferencesAfterResetUserOptions * * @param $storage - storage in which we can save some options, it will be passed in onSpecialPreferencesAfterResetUserOptions hook call * @param User $user */ public function onSpecialPreferencesBeforeResetUserOptions($preferences, &$user, &$storage) { //user identity box/masthead $userIdentityObject = new UserIdentityBox(F::app(), $user, 0); $mastheadOptions = $userIdentityObject->getFullData(); $masthead = F::build('Masthead', array($user)); if (!empty($masthead->mUser->mOptionOverrides['avatar'])) { $mastheadOptions['avatar'] = $masthead->mUser->mOptionOverrides['avatar']; } $storage[self::MASTHEAD_OPTIONS_STORAGE_ARRAY_KEY_NAME] = $mastheadOptions; //customize toolbar/myToolbar $skinName = RequestContext::getMain()->getSkin()->getSkinName(); $oasisToolbarService = new OasisToolbarService($skinName); $toolbarNameInUserOptions = $oasisToolbarService->getToolbarOptionName(); $toolbarCurrentList = $user->getOption($oasisToolbarService->getToolbarOptionName()); $storage[self::MY_TOOLBAR_OPTIONS_STORAGE_ARRAY_KEY_NAME] = array($toolbarNameInUserOptions => $toolbarCurrentList); return true; }