/** * Show the special page * * @param $section Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgUser, $wgOut, $wgRequest, $wgUserProfileScripts, $wgScriptPath, $wgUpdateProfileInRecentChanges, $wgSupressPageTitle; $wgSupressPageTitle = true; $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'edit-profiles-title' ) ) ); // This feature is only available for logged-in users. if ( !$wgUser->isLoggedIn() ) { $wgOut->setPageTitle( wfMsg( 'user-profile-update-notloggedin-title' ) ); $wgOut->addWikiMsg( 'user-profile-update-notloggedin-text' ); return; } // No need to allow blocked users to access this page, they could abuse it, y'know. if ( $wgUser->isBlocked() ) { $wgOut->blockedPage( false ); return false; } // Database operations require write mode if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } // Are we even allowed to do this? if ( !$wgUser->isAllowed( 'editothersprofiles' ) ) { $wgOut->permissionRequired( 'editothersprofiles' ); return; } // Add CSS & JS $wgOut->addExtensionStyle( $wgUserProfileScripts . '/UserProfile.css' ); if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { $wgOut->addModuleScripts( 'ext.userProfile.updateProfile' ); } else { $wgOut->addScriptFile( $wgUserProfileScripts . '/UpdateProfile.js' ); } // Get the user's name from the wpUser URL parameter $userFromRequest = $wgRequest->getText( 'wpUser' ); // If the wpUser parameter isn't set but a parameter was passed to the // special page, use the given parameter instead if ( !$userFromRequest && $par ) { $userFromRequest = $par; } // Still not set? Just give up and show the "search for a user" form... if ( !$userFromRequest ) { $wgOut->addHTML( $this->createUserInputForm() ); return; } $target = User::newFromName( $userFromRequest ); if ( !$target || $target->getID() == 0 ) { $wgOut->addHTML( wfMsg( 'nosuchusershort', htmlspecialchars( $userFromRequest ) ) ); $wgOut->addHTML( $this->createUserInputForm() ); return; } if ( $wgRequest->wasPosted() ) { $this->saveProfileBasic( $target ); $this->saveSettings_basic( $target ); $this->saveProfilePersonal( $target ); $this->saveProfileCustom( $target ); UserProfile::clearCache( $target->getID() ); $log = new LogPage( 'profile' ); if ( !$wgUpdateProfileInRecentChanges ) { $log->updateRecentChanges = false; } $log->addEntry( 'profile', $target->getUserPage(), wfMsgForContent( 'user-profile-edit-profile', array( '[[User:'******']]' ) ) ); $wgOut->addHTML( '<span class="profile-on">' . wfMsg( 'user-profile-edit-profile-update-saved' ) . '</span><br /><br />' ); // create the user page if it doesn't exist yet $title = Title::makeTitle( NS_USER, $target->getName() ); $article = new Article( $title ); if ( !$article->exists() ) { $article->doEdit( '', 'create user page', EDIT_SUPPRESS_RC ); } } $wgOut->addHTML( $this->displayBasicForm( $target ) ); $wgOut->addHTML( $this->displayPersonalForm( $target ) ); $wgOut->addHTML( $this->displayCustomForm( $target ) ); }
/** * Show the special page * * @param $section Mixed: parameter passed to the page or null */ public function execute($section) { global $wgUser, $wgOut, $wgRequest, $wgUserProfileScripts, $wgUpdateProfileInRecentChanges, $wgSupressPageTitle; $wgSupressPageTitle = true; $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('edit-profile-title'))); // This feature is only available for logged-in users. if (!$wgUser->isLoggedIn()) { $wgOut->setPageTitle(wfMsgForContent('user-profile-update-notloggedin-title')); $wgOut->addHTML(wfMsgForContent('user-profile-update-notloggedin-text', SpecialPage::getTitleFor('Userlogin')->escapeFullURL(), SpecialPage::getTitleFor('Userlogin', 'signup')->escapeFullURL())); return; } // No need to allow blocked users to access this page, they could abuse it, y'know. if ($wgUser->isBlocked()) { $wgOut->blockedPage(false); return false; } // Database operations require write mode if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } // Add CSS & JS $wgOut->addExtensionStyle($wgUserProfileScripts . '/UserProfile.css'); $wgOut->addScriptFile($wgUserProfileScripts . '/UpdateProfile.js'); if ($wgRequest->wasPosted()) { if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $this->saveProfileBasic(); $this->saveSettings_basic(); break; case 'personal': $this->saveProfilePersonal(); break; case 'custom': $this->saveProfileCustom(); break; case 'preferences': $this->saveSettings_pref(); break; } UserProfile::clearCache($wgUser->getID()); $log = new LogPage(wfMsgForContent('user-profile-update-profile')); if (!$wgUpdateProfileInRecentChanges) { $log->updateRecentChanges = false; } $log->addEntry(wfMsgForContent('user-profile-update-profile'), $wgUser->getUserPage(), wfMsgForContent('user-profile-update-log-section') . " '{$section}'"); $wgOut->addHTML('<span class="profile-on">' . wfMsg('user-profile-update-saved') . '</span><br /><br />'); // create user page if not exists $title = Title::makeTitle(NS_USER, $wgUser->getName()); $article = new Article($title); if (!$article->exists()) { $article->doEdit('', 'create user page', EDIT_SUPPRESS_RC); } } if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $wgOut->addHTML($this->displayBasicForm()); break; case 'personal': $wgOut->addHTML($this->displayPersonalForm()); break; case 'custom': $wgOut->addHTML($this->displayCustomForm()); break; case 'preferences': $wgOut->addHTML($this->displayPreferencesForm()); break; } }
/** * Show the special page * * @param $section Mixed: parameter passed to the page or null */ public function execute($section) { global $wgUpdateProfileInRecentChanges, $wgUserProfileThresholds, $wgSupressPageTitle, $wgAutoConfirmCount; $out = $this->getOutput(); $request = $this->getRequest(); $user = $this->getUser(); $wgSupressPageTitle = true; // Set the page title, robot policies, etc. $this->setHeaders(); $out->setHTMLTitle($this->msg('pagetitle', $this->msg('edit-profile-title')->plain())->parse()); // This feature is only available for logged-in users. if (!$user->isLoggedIn()) { $out->setPageTitle($this->msg('user-profile-update-notloggedin-title')->plain()); $out->addWikiMsg('user-profile-update-notloggedin-text'); return; } // No need to allow blocked users to access this page, they could abuse it, y'know. if ($user->isBlocked()) { $out->blockedPage(false); return false; } // Database operations require write mode if (wfReadOnly()) { $out->readOnlyPage(); return; } /** * Create thresholds based on user stats */ if (is_array($wgUserProfileThresholds) && count($wgUserProfileThresholds) > 0) { $can_create = true; $stats = new UserStats($user->getId(), $user->getName()); $stats_data = $stats->getUserStats(); $thresholdReasons = array(); foreach ($wgUserProfileThresholds as $field => $threshold) { // If the threshold is greater than the user's amount of whatever // statistic we're looking at, then it means that they can't use // this special page. // Why, oh why did I want to be so f*****g smart with these // field names?! This str_replace() voodoo all over the place is // outright painful. $correctField = str_replace('-', '_', $field); if ($stats_data[$correctField] < $threshold) { $can_create = false; $thresholdReasons[$threshold] = $field; } } $hasEqualEditThreshold = isset($wgUserProfileThresholds['edit']) && $wgUserProfileThresholds['edit'] == $wgAutoConfirmCount ? true : false; $can_create = $user->isAllowed('createpage') && $hasEqualEditThreshold ? true : $can_create; // Boo, go away! if ($can_create == false) { global $wgSupressPageTitle; $wgSupressPageTitle = false; $out->setPageTitle($this->msg('user-profile-create-threshold-title')->text()); $thresholdMessages = array(); foreach ($thresholdReasons as $requiredAmount => $reason) { // Replace underscores with hyphens for consistency in i18n // message names. $reason = str_replace('_', '-', $reason); /** * For grep: * user-profile-create-threshold-edits * user-profile-create-threshold-votes * user-profile-create-threshold-comments * user-profile-create-threshold-comment-score-plus * user-profile-create-threshold-comment-score-minus * user-profile-create-threshold-recruits * user-profile-create-threshold-friend-count * user-profile-create-threshold-foe-count * user-profile-create-threshold-weekly-wins * user-profile-create-threshold-monthly-wins * user-profile-create-threshold-poll-votes * user-profile-create-threshold-picture-game-votes * user-profile-create-threshold-quiz-created * user-profile-create-threshold-quiz-answered * user-profile-create-threshold-quiz-correct * user-profile-create-threshold-quiz-points */ $thresholdMessages[] = $this->msg('user-profile-create-threshold-' . $reason)->numParams($requiredAmount)->parse(); } $out->addHTML($this->msg('user-profile-create-threshold-reason', $this->getLanguage()->commaList($thresholdMessages))->parse()); return ''; } } // Add CSS & JS $out->addModuleStyles('ext.socialprofile.userprofile.css'); $out->addModules('ext.userProfile.updateProfile'); if ($request->wasPosted()) { if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $this->saveProfileBasic($user); $this->saveSettings_basic($user); break; case 'personal': $this->saveProfilePersonal($user); break; case 'custom': $this->saveProfileCustom($user); break; case 'preferences': $this->saveSettings_pref(); break; } UserProfile::clearCache($user->getID()); $log = new LogPage('profile'); if (!$wgUpdateProfileInRecentChanges) { $log->updateRecentChanges = false; } $log->addEntry('profile', $user->getUserPage(), $this->msg('user-profile-update-log-section')->inContentLanguage()->text() . " '{$section}'"); $out->addHTML('<span class="profile-on">' . $this->msg('user-profile-update-saved')->plain() . '</span><br /><br />'); // create the user page if it doesn't exist yet $title = Title::makeTitle(NS_USER, $user->getName()); $article = new Article($title); if (!$article->exists()) { $article->doEdit('', 'create user page', EDIT_SUPPRESS_RC); } } if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $out->addHTML($this->displayBasicForm($user)); break; case 'personal': $out->addHTML($this->displayPersonalForm($user)); break; case 'custom': $out->addHTML($this->displayCustomForm($user)); break; case 'preferences': $out->addHTML($this->displayPreferencesForm()); break; } }