r82285 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82284‎ | r82285 | r82286 >
Date:19:54, 16 February 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Create a user.groups module in ResourceLoader, which bundles a CSS and JS page for each usergroup the user is a member of (MediaWiki:Sysop.js, MediaWiki:Autoconfirmed.css, etc). Groups '*' and 'user' are not included.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserGroupsModule.php (added) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2555,28 +2555,29 @@
25562556 // Legacy Scripts
25572557 $scripts .= "\n" . $this->mScripts;
25582558
 2559+ $userScripts = array( 'user.options' );
 2560+
25592561 // Add site JS if enabled
25602562 if ( $wgUseSiteJs ) {
25612563 $scripts .= $this->makeResourceLoaderLink( $sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS );
 2564+ if( $wgUser->isLoggedIn() ){
 2565+ $userScripts[] = 'user.groups';
 2566+ }
25622567 }
25632568
2564 - // Add user JS if enabled - trying to load user.options as a bundle if possible
2565 - $userOptionsAdded = false;
 2569+ // Add user JS if enabled
25662570 if ( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
25672571 $action = $wgRequest->getVal( 'action', 'view' );
25682572 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
25692573 # XXX: additional security check/prompt?
25702574 $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n";
25712575 } else {
2572 - $scripts .= $this->makeResourceLoaderLink(
2573 - $sk, array( 'user', 'user.options' ), ResourceLoaderModule::TYPE_SCRIPTS
2574 - );
2575 - $userOptionsAdded = true;
 2576+ # FIXME: this means that User:Me/Common.js doesn't load when previewing
 2577+ # User:Me/Vector.js, and vice versa (bug26283)
 2578+ $userScripts[] = 'user';
25762579 }
25772580 }
2578 - if ( !$userOptionsAdded ) {
2579 - $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', ResourceLoaderModule::TYPE_SCRIPTS );
2580 - }
 2581+ $scripts .= $this->makeResourceLoaderLink( $sk, $userScripts, ResourceLoaderModule::TYPE_SCRIPTS );
25812582
25822583 return $scripts;
25832584 }
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserGroupsModule.php
@@ -0,0 +1,61 @@
 2+<?php
 3+/**
 4+ * This program is free software; you can redistribute it and/or modify
 5+ * it under the terms of the GNU General Public License as published by
 6+ * the Free Software Foundation; either version 2 of the License, or
 7+ * (at your option) any later version.
 8+ *
 9+ * This program is distributed in the hope that it will be useful,
 10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 12+ * GNU General Public License for more details.
 13+ *
 14+ * You should have received a copy of the GNU General Public License along
 15+ * with this program; if not, write to the Free Software Foundation, Inc.,
 16+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 17+ * http://www.gnu.org/copyleft/gpl.html
 18+ *
 19+ * @file
 20+ * @author Trevor Parscal
 21+ * @author Roan Kattouw
 22+ */
 23+
 24+/**
 25+ * Module for user customizations
 26+ */
 27+class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
 28+
 29+ /* Protected Methods */
 30+ protected $origin = self::ORIGIN_USER_SITEWIDE;
 31+
 32+ protected function getPages( ResourceLoaderContext $context ) {
 33+ if ( $context->getUser() ) {
 34+ $user = User::newFromName( $context->getUser() );
 35+ if( $user instanceof User ){
 36+ $pages = array();
 37+ foreach( $user->getEffectiveGroups() as $group ){
 38+ if( in_array( $group, array( '*', 'user' ) ) ){
 39+ continue;
 40+ }
 41+ $g = ucfirst( $group );
 42+ $pages["MediaWiki:$g.js"] = array( 'type' => 'script' );
 43+ $pages["MediaWiki:$g.css"] = array( 'type' => 'style' );
 44+ }
 45+ return $pages;
 46+ }
 47+ }
 48+ return array();
 49+ }
 50+
 51+ /* Methods */
 52+
 53+ public function getGroup() {
 54+ return 'user';
 55+ }
 56+
 57+ public function getFlip( $context ) {
 58+ global $wgContLang;
 59+
 60+ return $wgContLang->getDir() !== $context->getDirection();
 61+ }
 62+}
Property changes on: trunk/phase3/includes/resourceloader/ResourceLoaderUserGroupsModule.php
___________________________________________________________________
Added: svn:eol-style
163 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -211,6 +211,7 @@
212212 'ResourceLoaderFileModule' => 'includes/resourceloader/ResourceLoaderFileModule.php',
213213 'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php',
214214 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php',
 215+ 'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
215216 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
216217 'ResourceLoaderStartUpModule' => 'includes/resourceloader/ResourceLoaderStartUpModule.php',
217218 'ReverseChronologicalPager' => 'includes/Pager.php',
Index: trunk/phase3/includes/Skin.php
@@ -546,7 +546,7 @@
547547 * @private
548548 */
549549 function setupUserCss( OutputPage $out ) {
550 - global $wgRequest;
 550+ global $wgRequest, $wgUser;
551551 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
552552
553553 wfProfileIn( __METHOD__ );
@@ -560,6 +560,9 @@
561561 // Per-site custom styles
562562 if ( $wgUseSiteCss ) {
563563 $out->addModuleStyles( 'site' );
 564+ if( $wgUser->isLoggedIn() ){
 565+ $out->addModuleStyles( 'user.groups' );
 566+ }
564567 }
565568
566569 // Per-user custom styles
Index: trunk/phase3/RELEASE-NOTES
@@ -72,6 +72,8 @@
7373 (maintenance/fixDoubleRedirects.php)
7474 * (bug 23315) New body classes to allow easier styling of special pages
7575 * (bug 27159) Make email confirmation code expiration time configurable
 76+* CSS/JS for each user group is imported from MediaWiki:Sysop.js,
 77+ MediaWiki:Autoconfirmed.css, etc.
7678
7779 === Bug fixes in 1.18 ===
7880 * (bug 23119) WikiError class and subclasses are now marked as deprecated
Index: trunk/phase3/resources/Resources.php
@@ -8,6 +8,7 @@
99 'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
1010 'user' => array( 'class' => 'ResourceLoaderUserModule' ),
1111 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ),
 12+ 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
1213
1314 /* Skins */
1415

Follow-up revisions

RevisionCommit summaryAuthorDate
r82335Per r82285: Add new messages for the default user groups. This way they can b...raymond15:39, 17 February 2011
r86508Follow-up r82285: prefix group css and js pages with "Group-", and fix licens...happy-melon17:29, 20 April 2011
r100239Follow-up r82285: we should not apply case conversion to these names, because...happy-melon17:09, 19 October 2011

Comments

#Comment by Hashar (talk | contribs)   09:15, 23 February 2011

This is a good idea! thanks happy melon :-)

#Comment by P858snake (talk | contribs)   10:36, 23 February 2011

What about if someone was say to create a user group called for example Print, that would conflict with Mediawiki:Print.css, We could perhaps prefix the page names with something like [[Mediawiki:Group-<group>]].

#Comment by Reedy (talk | contribs)   10:42, 23 February 2011

Prefixing sounds like a good idea.

This can be said for most possible words, where conflict may be possible (granted, less likely, but possible)


Also, you've added a new code file, and then just listed Roan and Trevor as the author :)

#Comment by Happy-melon (talk | contribs)   10:54, 23 February 2011

I'm really, really bad at copying license headers and getting other random stuff as well; it generally doesn't get very rigorous review... :D I think I copied the class description from Skin.php to an extension once...

#Comment by Krinkle (talk | contribs)   19:42, 7 March 2011

Just for the record:

  • The load of user.groups is added to the same call as user.

Does not take an extra http-request (nice!)

  • Takes advantage of the same split (styles on top – without js-dependancy; scripts at the bottom – close to document ready).
#Comment by Aaron Schulz (talk | contribs)   00:07, 20 April 2011
  • Needs prefixing
  • License on ResourceLoaderUserGroupsModule.php looks wrong

Status & tagging log