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.

This commit is contained in:
Happy-melon 2011-02-16 19:54:02 +00:00
parent ef6041d750
commit eb9cf4b00c
6 changed files with 79 additions and 10 deletions

View 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

View 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',

View 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;
}

View 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

View file

@ -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();
}
}

View 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 */