From 559cc276e71be0e3a2594e6153d4ffef2c09d144 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Tue, 22 Jan 2013 14:44:22 -0800 Subject: [PATCH] Expose additional user attributes as JS vars This change adds user ID, registration time, and edit count to the default set of JavaScript configuration variables. These values are all included in $mCacheVars and so require no additional database lookups. Change-Id: Id0adb795567d4ba932104938f2793cdb4084883c --- includes/OutputPage.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index f71942163d..525fc24b7a 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3002,6 +3002,8 @@ $templates implode( "\t", $digitTransTable ), ); + $user = $this->getUser(); + $vars = array( 'wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => $canonicalName, @@ -3012,8 +3014,8 @@ $templates 'wgArticleId' => $pageID, 'wgIsArticle' => $this->isArticle(), 'wgAction' => Action::getActionName( $this->getContext() ), - 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(), - 'wgUserGroups' => $this->getUser()->getEffectiveGroups(), + 'wgUserName' => $user->isAnon() ? null : $user->getName(), + 'wgUserGroups' => $user->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', 'wgPageContentLanguage' => $lang->getCode(), @@ -3024,6 +3026,11 @@ $templates 'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(), 'wgRelevantPageName' => $relevantTitle->getPrefixedDBKey(), ); + if ( $user->isLoggedIn() ) { + $vars['wgUserId'] = $user->getId(); + $vars['wgUserEditCount'] = $user->getEditCount(); + $vars['wgUserRegistration'] = $user->getRegistration(); + } if ( $wgContLang->hasVariants() ) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); } -- 2.20.1