Jack Phoenix has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374811 )
Change subject: Add a class to <body> on NS_USER pages depending on whether the
user has chosen the social profile or wikitext user page as their default User:
page
......................................................................
Add a class to <body> on NS_USER pages depending on whether the user has chosen
the social profile or wikitext user page as their default User: page
If the user has chosen the wikitext user page, the "mw-wiki-user-page"
class is appended to the <body> element; for users who have chosen the
social profile page instead, the class is "mw-social-profile-page".
This class is only applied on root user pages, e.g. [[User:Foo]], not on
subpages (e.g. [[User:Foo/Sandbox]], etc.) and obviously only for existing
users and only when users are allowed to choose their user page type
($wgUserPageChoice = true;, which happens to be the default).
Bug: T167506
Change-Id: I6f37f093e68c1949d0169ba4b4cd2ee9a9813a81
---
M UserProfile/UserProfile.php
M UserProfile/UserProfileHooks.php
2 files changed, 35 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialProfile
refs/changes/11/374811/1
diff --git a/UserProfile/UserProfile.php b/UserProfile/UserProfile.php
index 181f86c..1420d1e 100644
--- a/UserProfile/UserProfile.php
+++ b/UserProfile/UserProfile.php
@@ -116,7 +116,7 @@
$wgLogActions['avatar/avatar'] = 'avatarlogentry';
$wgHooks['ArticleFromTitle'][] = 'UserProfileHooks::onArticleFromTitle';
-
+$wgHooks['OutputPageBodyAttributes'][] =
'UserProfileHooks::onOutputPageBodyAttributes';
$wgHooks['DifferenceEngineShowDiff'][] =
'UserProfileHooks::onDifferenceEngineShowDiff';
$wgHooks['DifferenceEngineShowDiffPage'][] =
'UserProfileHooks::onDifferenceEngineShowDiffPage';
$wgHooks['DifferenceEngineOldHeader'][] =
'UserProfileHooks::onDifferenceEngineOldHeader';
diff --git a/UserProfile/UserProfileHooks.php b/UserProfile/UserProfileHooks.php
index aea74e2..2d02eb4 100644
--- a/UserProfile/UserProfileHooks.php
+++ b/UserProfile/UserProfileHooks.php
@@ -2,6 +2,40 @@
class UserProfileHooks {
/**
+ * Add a class to the <body> element on user pages to indicate which
type
+ * of user page -- social profile or traditional wiki user page -- has
been
+ * chosen by the user in question to make CSS styling easier.
+ *
+ * @see https://phabricator.wikimedia.org/T167506
+ * @param OutputPage $out
+ * @param Skin $skin
+ * @param array $bodyAttrs Pre-existing attributes of the <body> tag
+ * @return bool
+ */
+ public static function onOutputPageBodyAttributes( $out, $skin,
&$bodyAttrs ) {
+ global $wgUserPageChoice;
+
+ $title = $out->getTitle();
+ // Only NS_USER is "ambiguous", NS_USER_PROFILE and
NS_USER_WIKI are not
+ // Also we don't care about subpages here since only the main
user page
+ // can be something else than wikitext
+ if ( $title->inNamespace( NS_USER ) && !$title->isSubpage() &&
$wgUserPageChoice ) {
+ $profile = new UserProfile( $title->getText() );
+ $profile_data = $profile->getProfile();
+
+ if ( isset( $profile_data['user_id'] ) &&
$profile_data['user_id'] ) {
+ if ( $profile_data['user_page_type'] == 0 ) {
+ $bodyAttrs['class'] .= '
mw-wiki-user-page';
+ } else {
+ $bodyAttrs['class'] .= '
mw-social-profile-page';
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Called by ArticleFromTitle hook
* Calls UserProfilePage instead of standard article
*
--
To view, visit https://gerrit.wikimedia.org/r/374811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6f37f093e68c1949d0169ba4b4cd2ee9a9813a81
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialProfile
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits