Create a user.groups module in ResourceLoader, which bundles a CSS and JS page for...
authorHappy-melon <happy-melon@users.mediawiki.org>
Wed, 16 Feb 2011 19:54:02 +0000 (19:54 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Wed, 16 Feb 2011 19:54:02 +0000 (19:54 +0000)
RELEASE-NOTES
includes/AutoLoader.php
includes/OutputPage.php
includes/Skin.php
includes/resourceloader/ResourceLoaderUserGroupsModule.php [new file with mode: 0644]
resources/Resources.php

index 1e5d474..a33bffa 100644 (file)
@@ -72,6 +72,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   (maintenance/fixDoubleRedirects.php)
 * (bug 23315) New body classes to allow easier styling of special pages
 * (bug 27159) Make email confirmation code expiration time configurable
+* CSS/JS for each user group is imported from MediaWiki:Sysop.js, 
+  MediaWiki:Autoconfirmed.css, etc.
 
 === Bug fixes in 1.18 ===
 * (bug 23119) WikiError class and subclasses are now marked as deprecated
index 198f279..9a42099 100644 (file)
@@ -211,6 +211,7 @@ $wgAutoloadLocalClasses = array(
        'ResourceLoaderFileModule' => 'includes/resourceloader/ResourceLoaderFileModule.php',
        'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php',
        'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php',
+       'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
        'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
        'ResourceLoaderStartUpModule' => 'includes/resourceloader/ResourceLoaderStartUpModule.php',
        'ReverseChronologicalPager' => 'includes/Pager.php',
index ca2acbf..f03e0e9 100644 (file)
@@ -2555,28 +2555,29 @@ class OutputPage {
                // Legacy Scripts
                $scripts .= "\n" . $this->mScripts;
 
+               $userScripts = array( 'user.options' );
+
                // Add site JS if enabled
                if ( $wgUseSiteJs ) {
                        $scripts .= $this->makeResourceLoaderLink( $sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS );
+                       if( $wgUser->isLoggedIn() ){
+                               $userScripts[] = 'user.groups';
+                       }
                }
 
-               // Add user JS if enabled - trying to load user.options as a bundle if possible
-               $userOptionsAdded = false;
+               // Add user JS if enabled
                if ( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $action = $wgRequest->getVal( 'action', 'view' );
                        if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
                                # XXX: additional security check/prompt?
                                $scripts .= Html::inlineScript( "\n" . $wgRequest->getText( 'wpTextbox1' ) . "\n" ) . "\n";
                        } else {
-                               $scripts .= $this->makeResourceLoaderLink(
-                                       $sk, array( 'user', 'user.options' ), ResourceLoaderModule::TYPE_SCRIPTS
-                               );
-                               $userOptionsAdded = true;
+                               # FIXME: this means that User:Me/Common.js doesn't load when previewing
+                               # User:Me/Vector.js, and vice versa (bug26283)
+                               $userScripts[] = 'user';
                        }
                }
-               if ( !$userOptionsAdded ) {
-                       $scripts .= $this->makeResourceLoaderLink( $sk, 'user.options', ResourceLoaderModule::TYPE_SCRIPTS );
-               }
+               $scripts .= $this->makeResourceLoaderLink( $sk, $userScripts, ResourceLoaderModule::TYPE_SCRIPTS );
 
                return $scripts;
        }
index 489bda8..57e535f 100644 (file)
@@ -546,7 +546,7 @@ abstract class Skin extends Linker {
         * @private
         */
        function setupUserCss( OutputPage $out ) {
-               global $wgRequest;
+               global $wgRequest, $wgUser;
                global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
 
                wfProfileIn( __METHOD__ );
@@ -560,6 +560,9 @@ abstract class Skin extends Linker {
                // Per-site custom styles
                if ( $wgUseSiteCss ) {
                        $out->addModuleStyles( 'site' );
+                       if( $wgUser->isLoggedIn() ){
+                               $out->addModuleStyles( 'user.groups' );
+                       }
                }
 
                // Per-user custom styles
diff --git a/includes/resourceloader/ResourceLoaderUserGroupsModule.php b/includes/resourceloader/ResourceLoaderUserGroupsModule.php
new file mode 100644 (file)
index 0000000..c81a999
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Trevor Parscal
+ * @author Roan Kattouw
+ */
+
+/**
+ * Module for user customizations
+ */
+class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule {
+
+       /* Protected Methods */
+       protected $origin = self::ORIGIN_USER_SITEWIDE;
+
+       protected function getPages( ResourceLoaderContext $context ) {
+               if ( $context->getUser() ) {
+                       $user = User::newFromName( $context->getUser() );
+                       if( $user instanceof User ){
+                               $pages = array();
+                               foreach( $user->getEffectiveGroups() as $group ){
+                                       if( in_array( $group, array( '*', 'user' ) ) ){
+                                               continue;
+                                       }
+                                       $g = ucfirst( $group );
+                                       $pages["MediaWiki:$g.js"] = array( 'type' => 'script' );
+                                       $pages["MediaWiki:$g.css"] = array( 'type' => 'style' );
+                               }
+                               return $pages;
+                       }
+               }
+               return array();
+       }
+       
+       /* Methods */
+       
+       public function getGroup() {
+               return 'user';
+       }
+       
+       public function getFlip( $context ) {
+               global $wgContLang;
+
+               return $wgContLang->getDir() !== $context->getDirection();
+       }
+}
index 553c8ae..085462c 100644 (file)
@@ -8,6 +8,7 @@ return array(
        'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
        'user' => array( 'class' => 'ResourceLoaderUserModule' ),
        'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ),
+       'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
 
        /* Skins */