Major refactoring of site and user CSS, creating ResourceLoaderUserModule and ResourceLoaderUserPreferenceModule. Also moved as much of the global variables being generated in Skin::makeGlobalVaiablesScript into the ResourceLoaderStartupModule - which will make configuration changes effective site-wide in 5 minutes instead of whenever all pages are purged from cache - what remains embedded in the HTML is article and user specific - two things we don't know by the time we request the startup module. Also, fixed issue where debug=false was being interpreted to be equivilant to debug=true. Finally, finished integrating the introduction of $wgLoadScript, thus fixing overlooked issues in r72763.
This commit is contained in:
parent
af26088bd9
commit
a99f9ec28b
7 changed files with 279 additions and 295 deletions
|
|
@ -2283,19 +2283,33 @@ class OutputPage {
|
||||||
static function makeResourceLoaderLink( $skin, $modules, $only ) {
|
static function makeResourceLoaderLink( $skin, $modules, $only ) {
|
||||||
global $wgUser, $wgLang, $wgRequest, $wgLoadScript;
|
global $wgUser, $wgLang, $wgRequest, $wgLoadScript;
|
||||||
// TODO: Should this be a static function of ResourceLoader instead?
|
// TODO: Should this be a static function of ResourceLoader instead?
|
||||||
|
// TODO: Divide off modules starting with "user", and add the user parameter to them
|
||||||
$query = array(
|
$query = array(
|
||||||
'modules' => implode( '|', array_unique( (array) $modules ) ),
|
|
||||||
'lang' => $wgLang->getCode(),
|
'lang' => $wgLang->getCode(),
|
||||||
'debug' => $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false',
|
'debug' => $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false',
|
||||||
'skin' => $wgUser->getSkin()->getSkinName(),
|
'skin' => $wgUser->getSkin()->getSkinName(),
|
||||||
'only' => $only,
|
'only' => $only,
|
||||||
);
|
);
|
||||||
// Automatically select style/script elements
|
$moduleGroups = array( null => array(), 'user' => array() );
|
||||||
if ( $only === 'styles' ) {
|
foreach ( (array) $modules as $module ) {
|
||||||
return Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) );
|
$moduleGroups[strpos( $module, 'user' ) === 0 ? 'user' : null][] = $module;
|
||||||
} else {
|
|
||||||
return Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) );
|
|
||||||
}
|
}
|
||||||
|
$links = '';
|
||||||
|
foreach ( $moduleGroups as $group => $modules ) {
|
||||||
|
if ( count( $modules ) ) {
|
||||||
|
$query['modules'] = implode( '|', array_unique( (array) $modules ) );
|
||||||
|
if ( $group === 'user' ) {
|
||||||
|
$query['user'] = $wgUser->getName();
|
||||||
|
}
|
||||||
|
// Automatically select style/script elements
|
||||||
|
if ( $only === 'styles' ) {
|
||||||
|
$links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) );
|
||||||
|
} else {
|
||||||
|
$links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2313,8 +2327,8 @@ class OutputPage {
|
||||||
// Statup - this will immediately load jquery and mediawiki modules
|
// Statup - this will immediately load jquery and mediawiki modules
|
||||||
$scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts' );
|
$scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts' );
|
||||||
|
|
||||||
// Configuration -- this could be merged together with the load and go, but makeGlobalVariablesScript returns a
|
// Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a
|
||||||
// whole script tag -- grumble grumble
|
// whole script tag -- grumble grumble...
|
||||||
$scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
|
$scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
|
||||||
|
|
||||||
// Script and Messages "only"
|
// Script and Messages "only"
|
||||||
|
|
|
||||||
|
|
@ -31,23 +31,24 @@ class ResourceLoaderContext {
|
||||||
protected $language;
|
protected $language;
|
||||||
protected $direction;
|
protected $direction;
|
||||||
protected $skin;
|
protected $skin;
|
||||||
|
protected $user;
|
||||||
protected $debug;
|
protected $debug;
|
||||||
protected $only;
|
protected $only;
|
||||||
protected $hash;
|
protected $hash;
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
public function __construct( WebRequest $request, $server ) {
|
public function __construct( WebRequest $request ) {
|
||||||
global $wgLang, $wgDefaultSkin;
|
global $wgLang, $wgDefaultSkin;
|
||||||
|
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->server = $server;
|
|
||||||
// Interperet request
|
// Interperet request
|
||||||
$this->modules = explode( '|', $request->getVal( 'modules' ) );
|
$this->modules = explode( '|', $request->getVal( 'modules' ) );
|
||||||
$this->language = $request->getVal( 'lang' );
|
$this->language = $request->getVal( 'lang' );
|
||||||
$this->direction = $request->getVal( 'dir' );
|
$this->direction = $request->getVal( 'dir' );
|
||||||
$this->skin = $request->getVal( 'skin' );
|
$this->skin = $request->getVal( 'skin' );
|
||||||
$this->debug = $request->getVal( 'debug' ) === 'true' || $request->getBool( 'debug' );
|
$this->user = $request->getVal( 'user' );
|
||||||
|
$this->debug = $request->getBool( 'debug' ) && $request->getVal( 'debug' ) === 'true';
|
||||||
$this->only = $request->getVal( 'only' );
|
$this->only = $request->getVal( 'only' );
|
||||||
|
|
||||||
// Fallback on system defaults
|
// Fallback on system defaults
|
||||||
|
|
@ -68,10 +69,6 @@ class ResourceLoaderContext {
|
||||||
return $this->request;
|
return $this->request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getServer() {
|
|
||||||
return $this->server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getModules() {
|
public function getModules() {
|
||||||
return $this->modules;
|
return $this->modules;
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +85,10 @@ class ResourceLoaderContext {
|
||||||
return $this->skin;
|
return $this->skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUser() {
|
||||||
|
return $this->skin;
|
||||||
|
}
|
||||||
|
|
||||||
public function getDebug() {
|
public function getDebug() {
|
||||||
return $this->debug;
|
return $this->debug;
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +112,6 @@ class ResourceLoaderContext {
|
||||||
public function getHash() {
|
public function getHash() {
|
||||||
return isset( $this->hash ) ?
|
return isset( $this->hash ) ?
|
||||||
$this->hash : $this->hash =
|
$this->hash : $this->hash =
|
||||||
implode( '|', array( $this->language, $this->skin, $this->debug, $this->only ) );
|
implode( '|', array( $this->language, $this->skin, $this->user, $this->debug, $this->only ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,6 @@ abstract class ResourceLoaderModule {
|
||||||
return $context->getDirection() === 'rtl';
|
return $context->getDirection() === 'rtl';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Abstract Methods */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all JS for this module for a given language and skin.
|
* Get all JS for this module for a given language and skin.
|
||||||
* Includes all relevant JS except loader scripts.
|
* Includes all relevant JS except loader scripts.
|
||||||
|
|
@ -90,7 +88,10 @@ abstract class ResourceLoaderModule {
|
||||||
* @param $context ResourceLoaderContext object
|
* @param $context ResourceLoaderContext object
|
||||||
* @return String: JS
|
* @return String: JS
|
||||||
*/
|
*/
|
||||||
public abstract function getScript( ResourceLoaderContext $context );
|
public function getScript( ResourceLoaderContext $context ) {
|
||||||
|
// Stub, override expected
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all CSS for this module for a given skin.
|
* Get all CSS for this module for a given skin.
|
||||||
|
|
@ -98,7 +99,10 @@ abstract class ResourceLoaderModule {
|
||||||
* @param $context ResourceLoaderContext object
|
* @param $context ResourceLoaderContext object
|
||||||
* @return array: strings of CSS keyed by media type
|
* @return array: strings of CSS keyed by media type
|
||||||
*/
|
*/
|
||||||
public abstract function getStyles( ResourceLoaderContext $context );
|
public function getStyles( ResourceLoaderContext $context ) {
|
||||||
|
// Stub, override expected
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the messages needed for this module.
|
* Get the messages needed for this module.
|
||||||
|
|
@ -107,14 +111,20 @@ abstract class ResourceLoaderModule {
|
||||||
*
|
*
|
||||||
* @return array of message keys. Keys may occur more than once
|
* @return array of message keys. Keys may occur more than once
|
||||||
*/
|
*/
|
||||||
public abstract function getMessages();
|
public function getMessages() {
|
||||||
|
// Stub, override expected
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the loader JS for this module, if set.
|
* Get the loader JS for this module, if set.
|
||||||
*
|
*
|
||||||
* @return Mixed: loader JS (string) or false if no custom loader set
|
* @return Mixed: loader JS (string) or false if no custom loader set
|
||||||
*/
|
*/
|
||||||
public abstract function getLoaderScript();
|
public function getLoaderScript() {
|
||||||
|
// Stub, override expected
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of modules this module depends on.
|
* Get a list of modules this module depends on.
|
||||||
|
|
@ -131,8 +141,13 @@ abstract class ResourceLoaderModule {
|
||||||
* loader script, see getLoaderScript()
|
* loader script, see getLoaderScript()
|
||||||
* @return Array of module names (strings)
|
* @return Array of module names (strings)
|
||||||
*/
|
*/
|
||||||
public abstract function getDependencies();
|
public function getDependencies() {
|
||||||
|
// Stub, override expected
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Abstract Methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get this module's last modification timestamp for a given
|
* Get this module's last modification timestamp for a given
|
||||||
* combination of language, skin and debug mode flag. This is typically
|
* combination of language, skin and debug mode flag. This is typically
|
||||||
|
|
@ -682,58 +697,65 @@ abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
|
||||||
/* Protected Members */
|
/* Protected Members */
|
||||||
|
|
||||||
// In-object cache for modified time
|
// In-object cache for modified time
|
||||||
protected $modifiedTime = null;
|
protected $modifiedTime = array();
|
||||||
|
|
||||||
/* Abstract Protected Methods */
|
/* Abstract Protected Methods */
|
||||||
|
|
||||||
abstract protected function getPages( ResourceLoaderContext $context );
|
abstract protected function getPages( ResourceLoaderContext $context );
|
||||||
|
|
||||||
/* Protected Methods */
|
/* Methods */
|
||||||
|
|
||||||
protected function getStyleCode( array $styles ) {
|
public function getScript( ResourceLoaderContext $context ) {
|
||||||
foreach ( $styles as $media => $messages ) {
|
$scripts = '';
|
||||||
foreach ( $messages as $i => $message ) {
|
foreach ( $this->getPages( $context ) as $page => $options ) {
|
||||||
$style = wfMsgExt( $message, 'content' );
|
if ( $options['type'] === 'script' ) {
|
||||||
if ( !wfEmptyMsg( $message, $style ) ) {
|
$script = wfMsgExt( $page, 'content' );
|
||||||
$styles[$media][$i] = $style;
|
$scripts .= "/* MediaWiki:$page */\n" . ( !wfEmptyMsg( $page, $script ) ? $script : '' ) . "\n";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ( $styles as $media => $messages ) {
|
return $scripts;
|
||||||
$styles[$media] = implode( "\n", $messages );
|
}
|
||||||
|
|
||||||
|
public function getStyles( ResourceLoaderContext $context ) {
|
||||||
|
$styles = array();
|
||||||
|
foreach ( $this->getPages( $context ) as $page => $options ) {
|
||||||
|
if ( $options['type'] === 'style' ) {
|
||||||
|
$media = isset( $options['media'] ) ? $options['media'] : 'all';
|
||||||
|
$style = wfMsgExt( $page, 'content' );
|
||||||
|
if ( !isset( $styles[$media] ) ) {
|
||||||
|
$styles[$media] = '';
|
||||||
|
}
|
||||||
|
$styles[$media] .= "/* MediaWiki:$page */\n" . ( !wfEmptyMsg( $page, $style ) ? $style : '' ) . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $styles;
|
return $styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Methods */
|
|
||||||
|
|
||||||
public function getModifiedTime( ResourceLoaderContext $context ) {
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
||||||
if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
|
$hash = $context->getHash();
|
||||||
return $this->modifiedTime[$context->getHash()];
|
if ( isset( $this->modifiedTime[$hash] ) ) {
|
||||||
|
return $this->modifiedTime[$hash];
|
||||||
}
|
}
|
||||||
$pages = $this->getPages( $context );
|
$titles = array();
|
||||||
foreach ( $pages as $i => $page ) {
|
foreach ( $this->getPages( $context ) as $page => $options ) {
|
||||||
$pages[$i] = Title::makeTitle( NS_MEDIAWIKI, $page );
|
$titles[] = Title::makeTitle( NS_MEDIAWIKI, $page );
|
||||||
}
|
}
|
||||||
// Do batch existence check
|
// Do batch existence check
|
||||||
// TODO: This would work better if page_touched were loaded by this as well
|
// TODO: This would work better if page_touched were loaded by this as well
|
||||||
$lb = new LinkBatch( $pages );
|
$lb = new LinkBatch( $titles );
|
||||||
$lb->execute();
|
$lb->execute();
|
||||||
$this->modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
|
$modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
|
||||||
foreach ( $pages as $page ) {
|
foreach ( $titles as $title ) {
|
||||||
if ( $page->exists() ) {
|
if ( $title->exists() ) {
|
||||||
$this->modifiedTime = max( $this->modifiedTime, wfTimestamp( TS_UNIX, $page->getTouched() ) );
|
$modifiedTime = max( $modifiedTime, wfTimestamp( TS_UNIX, $title->getTouched() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->modifiedTime;
|
return $this->modifiedTime[$hash] = $modifiedTime;
|
||||||
}
|
}
|
||||||
public function getMessages() { return array(); }
|
|
||||||
public function getLoaderScript() { return ''; }
|
|
||||||
public function getDependencies() { return array(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom module for site customizations
|
* Module for site customizations
|
||||||
*/
|
*/
|
||||||
class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
|
class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
|
||||||
|
|
||||||
|
|
@ -742,49 +764,172 @@ class ResourceLoaderSiteModule extends ResourceLoaderWikiModule {
|
||||||
protected function getPages( ResourceLoaderContext $context ) {
|
protected function getPages( ResourceLoaderContext $context ) {
|
||||||
global $wgHandheldStyle;
|
global $wgHandheldStyle;
|
||||||
|
|
||||||
// HACK: We duplicate the message names from generateUserJs() and generateUserCss here and weird things (i.e.
|
|
||||||
// mtime moving backwards) can happen when a MediaWiki:Something.js page is deleted
|
|
||||||
$pages = array(
|
$pages = array(
|
||||||
'Common.js',
|
'Common.js' => array( 'type' => 'script' ),
|
||||||
'Common.css',
|
'Common.css' => array( 'type' => 'style' ),
|
||||||
ucfirst( $context->getSkin() ) . '.js',
|
ucfirst( $context->getSkin() ) . '.js' => array( 'type' => 'script' ),
|
||||||
ucfirst( $context->getSkin() ) . '.css',
|
ucfirst( $context->getSkin() ) . '.css' => array( 'type' => 'style' ),
|
||||||
'Print.css',
|
'Print.css' => array( 'type' => 'style', 'media' => 'print' ),
|
||||||
);
|
);
|
||||||
if ( $wgHandheldStyle ) {
|
if ( $wgHandheldStyle ) {
|
||||||
$pages[] = 'Handheld.css';
|
$pages['Handheld.css'] = array( 'type' => 'style', 'media' => 'handheld' );
|
||||||
}
|
}
|
||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for user customizations
|
||||||
|
*/
|
||||||
|
class ResourceLoaderUserModule extends ResourceLoaderWikiModule {
|
||||||
|
|
||||||
|
/* Protected Methods */
|
||||||
|
|
||||||
|
protected function getPages( ResourceLoaderContext $context ) {
|
||||||
|
global $wgAllowUserCss;
|
||||||
|
|
||||||
|
if ( $context->getUser() && $wgAllowUserCss ) {
|
||||||
|
$user = User::newFromName( $context->getUser() );
|
||||||
|
$userPage = $user->getUserPage()->getPrefixedText();
|
||||||
|
return array(
|
||||||
|
"$userPage/common.css" => array( 'type' => 'style' ),
|
||||||
|
"$userPage/" . $context->getSkin() . '.css' => array( 'type' => 'style' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module for user preference customizations
|
||||||
|
*/
|
||||||
|
class ResourceLoaderUserPreferencesModule extends ResourceLoaderModule {
|
||||||
|
|
||||||
|
/* Protected Members */
|
||||||
|
|
||||||
|
protected $modifiedTime = array();
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
public function getScript( ResourceLoaderContext $context ) {
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
||||||
return Skin::newFromKey( $context->getSkin() )->generateUserJs();
|
$hash = $context->getHash();
|
||||||
|
if ( isset( $this->modifiedTime[$hash] ) ) {
|
||||||
|
return $this->modifiedTime[$hash];
|
||||||
|
}
|
||||||
|
$user = User::newFromName( $context->getUser() );
|
||||||
|
return $this->modifiedTime[$hash] = $user->getTouched();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStyles( ResourceLoaderContext $context ) {
|
public function getStyles( ResourceLoaderContext $context ) {
|
||||||
global $wgHandheldStyle;
|
global $wgAllowUserCssPrefs;
|
||||||
$styles = array(
|
if ( $wgAllowUserCssPrefs ) {
|
||||||
'all' => array( 'Common.css', $context->getSkin() . '.css' ),
|
$user = User::newFromName( $context->getUser() );
|
||||||
'print' => array( 'Print.css' ),
|
$rules = array();
|
||||||
);
|
if ( ( $underline = $user->getOption( 'underline' ) ) < 2 ) {
|
||||||
if ( $wgHandheldStyle ) {
|
$rules[] = "a { text-decoration: " . ( $underline ? 'underline' : 'none' ) . "; }";
|
||||||
$sources['handheld'] = array( 'Handheld.css' );
|
}
|
||||||
|
if ( $user->getOption( 'highlightbroken' ) ) {
|
||||||
|
$rules[] = "a.new, #quickbar a.new { color: #CC2200; }\n";
|
||||||
|
} else {
|
||||||
|
$rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
|
||||||
|
$rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #CC2200; }";
|
||||||
|
$rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
|
||||||
|
}
|
||||||
|
if ( $user->getOption( 'justify' ) ) {
|
||||||
|
$rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
|
||||||
|
}
|
||||||
|
if ( !$user->getOption( 'showtoc' ) ) {
|
||||||
|
$rules[] = "#toc { display: none; }\n";
|
||||||
|
}
|
||||||
|
if ( !$user->getOption( 'editsection' ) ) {
|
||||||
|
$rules[] = ".editsection { display: none; }\n";
|
||||||
|
}
|
||||||
|
if ( ( $fontstyle = $user->getOption( 'editfont' ) ) !== 'default' ) {
|
||||||
|
$rules[] = "textarea { font-family: $fontstyle; }\n";
|
||||||
|
}
|
||||||
|
return array( 'all' => implode( "\n", $rules ) );
|
||||||
}
|
}
|
||||||
return $this->getStyleCode( $styles );
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFlip( $context ) {
|
||||||
|
global $wgContLang;
|
||||||
|
|
||||||
|
return $wgContLang->getDir() !== $context->getDirection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
||||||
/* Protected Members */
|
/* Protected Members */
|
||||||
|
|
||||||
protected $modifiedTime = null;
|
protected $modifiedTime = array();
|
||||||
|
|
||||||
|
/* Protected Methods */
|
||||||
|
|
||||||
|
protected function getConfig( $context ) {
|
||||||
|
global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer,
|
||||||
|
$wgContLang, $wgBreakFrames, $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgAjaxWatch, $wgVersion,
|
||||||
|
$wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, $wgSitename, $wgFileExtensions;
|
||||||
|
|
||||||
|
// Pre-process information
|
||||||
|
$separatorTransTable = $wgContLang->separatorTransformTable();
|
||||||
|
$separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
|
||||||
|
$compactSeparatorTransTable = array(
|
||||||
|
implode( "\t", array_keys( $separatorTransTable ) ),
|
||||||
|
implode( "\t", $separatorTransTable ),
|
||||||
|
);
|
||||||
|
$digitTransTable = $wgContLang->digitTransformTable();
|
||||||
|
$digitTransTable = $digitTransTable ? $digitTransTable : array();
|
||||||
|
$compactDigitTransTable = array(
|
||||||
|
implode( "\t", array_keys( $digitTransTable ) ),
|
||||||
|
implode( "\t", $digitTransTable ),
|
||||||
|
);
|
||||||
|
$mainPage = Title::newMainPage();
|
||||||
|
|
||||||
|
// Build list of variables
|
||||||
|
$vars = array(
|
||||||
|
'wgLoadScript' => $wgLoadScript,
|
||||||
|
'debug' => $context->getDebug(),
|
||||||
|
'skin' => $context->getSkin(),
|
||||||
|
'stylepath' => $wgStylePath,
|
||||||
|
'wgUrlProtocols' => wfUrlProtocols(),
|
||||||
|
'wgArticlePath' => $wgArticlePath,
|
||||||
|
'wgScriptPath' => $wgScriptPath,
|
||||||
|
'wgScriptExtension' => $wgScriptExtension,
|
||||||
|
'wgScript' => $wgScript,
|
||||||
|
'wgVariantArticlePath' => $wgVariantArticlePath,
|
||||||
|
'wgActionPaths' => $wgActionPaths,
|
||||||
|
'wgServer' => $wgServer,
|
||||||
|
'wgUserLanguage' => $context->getLanguage(),
|
||||||
|
'wgContentLanguage' => $wgContLang->getCode(),
|
||||||
|
'wgBreakFrames' => $wgBreakFrames,
|
||||||
|
'wgVersion' => $wgVersion,
|
||||||
|
'wgEnableAPI' => $wgEnableAPI,
|
||||||
|
'wgEnableWriteAPI' => $wgEnableWriteAPI,
|
||||||
|
'wgSeparatorTransformTable' => $compactSeparatorTransTable,
|
||||||
|
'wgDigitTransformTable' => $compactDigitTransTable,
|
||||||
|
'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null,
|
||||||
|
'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
|
||||||
|
'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
|
||||||
|
'wgSiteName' => $wgSitename,
|
||||||
|
'wgFileExtensions' => $wgFileExtensions,
|
||||||
|
);
|
||||||
|
if ( $wgContLang->hasVariants() ) {
|
||||||
|
$vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
|
||||||
|
}
|
||||||
|
if ( $wgUseAjax && $wgEnableMWSuggest ) {
|
||||||
|
$vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
|
||||||
|
$vars['wgDBname'] = $wgDBname;
|
||||||
|
$vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
public function getScript( ResourceLoaderContext $context ) {
|
public function getScript( ResourceLoaderContext $context ) {
|
||||||
global $IP;
|
global $IP, $wgStylePath, $wgLoadScript;
|
||||||
|
|
||||||
$scripts = file_get_contents( "$IP/resources/startup.js" );
|
$scripts = file_get_contents( "$IP/resources/startup.js" );
|
||||||
|
|
||||||
|
|
@ -792,9 +937,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
||||||
// Get all module registrations
|
// Get all module registrations
|
||||||
$registration = ResourceLoader::getModuleRegistrations( $context );
|
$registration = ResourceLoader::getModuleRegistrations( $context );
|
||||||
// Build configuration
|
// Build configuration
|
||||||
$config = FormatJson::encode(
|
$config = FormatJson::encode( $this->getConfig( $context ) );
|
||||||
array( 'server' => $context->getServer(), 'debug' => $context->getDebug() )
|
|
||||||
);
|
|
||||||
// Add a well-known start-up function
|
// Add a well-known start-up function
|
||||||
$scripts .= "window.startUp = function() { $registration mediaWiki.config.set( $config ); };";
|
$scripts .= "window.startUp = function() { $registration mediaWiki.config.set( $config ); };";
|
||||||
// Build load query for jquery and mediawiki modules
|
// Build load query for jquery and mediawiki modules
|
||||||
|
|
@ -814,7 +957,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Build HTML code for loading jquery and mediawiki modules
|
// Build HTML code for loading jquery and mediawiki modules
|
||||||
$loadScript = Html::linkedScript( $context->getServer() . "?$query" );
|
$loadScript = Html::linkedScript( "$wgLoadScript?$query" );
|
||||||
// Add code to add jquery and mediawiki loading code; only if the current client is compatible
|
// Add code to add jquery and mediawiki loading code; only if the current client is compatible
|
||||||
$scripts .= "if ( isCompatible() ) { document.write( '$loadScript' ); }";
|
$scripts .= "if ( isCompatible() ) { document.write( '$loadScript' ); }";
|
||||||
// Delete the compatible function - it's not needed anymore
|
// Delete the compatible function - it's not needed anymore
|
||||||
|
|
@ -827,14 +970,15 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
||||||
public function getModifiedTime( ResourceLoaderContext $context ) {
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
||||||
global $IP;
|
global $IP;
|
||||||
|
|
||||||
if ( !is_null( $this->modifiedTime ) ) {
|
$hash = $context->getHash();
|
||||||
return $this->modifiedTime;
|
if ( isset( $this->modifiedTime[$hash] ) ) {
|
||||||
|
return $this->modifiedTime[$hash];
|
||||||
}
|
}
|
||||||
|
$this->modifiedTime[$hash] = filemtime( "$IP/resources/startup.js" );
|
||||||
// HACK getHighestModifiedTime() calls this function, so protect against infinite recursion
|
// ATTENTION!: Because of the line above, this is not going to cause infinite recursion - think carefully
|
||||||
$this->modifiedTime = filemtime( "$IP/resources/startup.js" );
|
// before making changes to this code!
|
||||||
$this->modifiedTime = ResourceLoader::getHighestModifiedTime( $context );
|
$this->modifiedTime[$hash] = ResourceLoader::getHighestModifiedTime( $context );
|
||||||
return $this->modifiedTime;
|
return $this->modifiedTime[$hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClientMaxage() {
|
public function getClientMaxage() {
|
||||||
|
|
@ -845,14 +989,9 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
||||||
return 300; // 5 minutes
|
return 300; // 5 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStyles( ResourceLoaderContext $context ) { return array(); }
|
|
||||||
|
|
||||||
public function getFlip( $context ) {
|
public function getFlip( $context ) {
|
||||||
global $wgContLang;
|
global $wgContLang;
|
||||||
|
|
||||||
return $wgContLang->getDir() !== $context->getDirection();
|
return $wgContLang->getDir() !== $context->getDirection();
|
||||||
}
|
}
|
||||||
public function getMessages() { return array(); }
|
|
||||||
public function getLoaderScript() { return ''; }
|
|
||||||
public function getDependencies() { return array(); }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -357,10 +357,10 @@ class Skin extends Linker {
|
||||||
|
|
||||||
static function makeVariablesScript( $data ) {
|
static function makeVariablesScript( $data ) {
|
||||||
if ( $data ) {
|
if ( $data ) {
|
||||||
return Html::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' );
|
return Html::inlineScript( 'mediaWiki.config.set(' . FormatJson::encode( $data ) . ');' );
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -368,50 +368,16 @@ class Skin extends Linker {
|
||||||
* @param $skinName string Name of the skin
|
* @param $skinName string Name of the skin
|
||||||
* The odd calling convention is for backwards compatibility
|
* The odd calling convention is for backwards compatibility
|
||||||
* @todo FIXME: Make this not depend on $wgTitle!
|
* @todo FIXME: Make this not depend on $wgTitle!
|
||||||
|
*
|
||||||
|
* Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state.
|
||||||
|
* You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
|
||||||
*/
|
*/
|
||||||
static function makeGlobalVariablesScript( $skinName ) {
|
static function makeGlobalVariablesScript( $skinName ) {
|
||||||
if ( is_array( $skinName ) ) {
|
global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes;
|
||||||
# Weird back-compat stuff.
|
|
||||||
$skinName = $skinName['skinname'];
|
|
||||||
}
|
|
||||||
|
|
||||||
global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
|
|
||||||
global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
|
|
||||||
global $wgOut, $wgArticle;
|
|
||||||
global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
|
|
||||||
global $wgUseAjax, $wgAjaxWatch;
|
|
||||||
global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
|
|
||||||
global $wgRestrictionTypes;
|
|
||||||
global $wgDBname, $wgEnableMWSuggest;
|
|
||||||
global $wgSitename;
|
|
||||||
|
|
||||||
$ns = $wgTitle->getNamespace();
|
$ns = $wgTitle->getNamespace();
|
||||||
$nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
|
$nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
|
||||||
$separatorTransTable = $wgContLang->separatorTransformTable();
|
|
||||||
$separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
|
|
||||||
$compactSeparatorTransTable = array(
|
|
||||||
implode( "\t", array_keys( $separatorTransTable ) ),
|
|
||||||
implode( "\t", $separatorTransTable ),
|
|
||||||
);
|
|
||||||
$digitTransTable = $wgContLang->digitTransformTable();
|
|
||||||
$digitTransTable = $digitTransTable ? $digitTransTable : array();
|
|
||||||
$compactDigitTransTable = array(
|
|
||||||
implode( "\t", array_keys( $digitTransTable ) ),
|
|
||||||
implode( "\t", $digitTransTable ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$mainPage = Title::newMainPage();
|
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'skin' => $skinName,
|
|
||||||
'stylepath' => $wgStylePath,
|
|
||||||
'wgUrlProtocols' => wfUrlProtocols(),
|
|
||||||
'wgArticlePath' => $wgArticlePath,
|
|
||||||
'wgScriptPath' => $wgScriptPath,
|
|
||||||
'wgScriptExtension' => $wgScriptExtension,
|
|
||||||
'wgScript' => $wgScript,
|
|
||||||
'wgVariantArticlePath' => $wgVariantArticlePath,
|
|
||||||
'wgActionPaths' => (object)$wgActionPaths,
|
|
||||||
'wgServer' => $wgServer,
|
|
||||||
'wgCanonicalNamespace' => $nsname,
|
'wgCanonicalNamespace' => $nsname,
|
||||||
'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
|
'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
|
||||||
SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
|
SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
|
||||||
|
|
@ -423,56 +389,16 @@ class Skin extends Linker {
|
||||||
'wgIsArticle' => $wgOut->isArticle(),
|
'wgIsArticle' => $wgOut->isArticle(),
|
||||||
'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
|
'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
|
||||||
'wgUserGroups' => $wgUser->getEffectiveGroups(),
|
'wgUserGroups' => $wgUser->getEffectiveGroups(),
|
||||||
'wgUserLanguage' => $wgLang->getCode(),
|
|
||||||
'wgContentLanguage' => $wgContLang->getCode(),
|
|
||||||
'wgBreakFrames' => $wgBreakFrames,
|
|
||||||
'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
|
'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
|
||||||
'wgVersion' => $wgVersion,
|
|
||||||
'wgEnableAPI' => $wgEnableAPI,
|
|
||||||
'wgEnableWriteAPI' => $wgEnableWriteAPI,
|
|
||||||
'wgSeparatorTransformTable' => $compactSeparatorTransTable,
|
|
||||||
'wgDigitTransformTable' => $compactDigitTransTable,
|
|
||||||
'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null,
|
|
||||||
'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
|
|
||||||
'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
|
|
||||||
'wgSiteName' => $wgSitename,
|
|
||||||
'wgCategories' => $wgOut->getCategories(),
|
'wgCategories' => $wgOut->getCategories(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $wgContLang->hasVariants() ) {
|
|
||||||
$vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if on upload page output the extension list & js_upload
|
|
||||||
if ( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
|
|
||||||
global $wgFileExtensions;
|
|
||||||
$vars['wgFileExtensions'] = $wgFileExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
|
|
||||||
$vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
|
|
||||||
$vars['wgDBname'] = $wgDBname;
|
|
||||||
$vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
|
|
||||||
$vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $wgRestrictionTypes as $type ) {
|
foreach ( $wgRestrictionTypes as $type ) {
|
||||||
$vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
|
$vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
|
|
||||||
$msgs = (object)array();
|
|
||||||
|
|
||||||
foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
|
|
||||||
'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
|
|
||||||
$msgs-> { $msgName . 'Msg' } = wfMsg( $msgName );
|
|
||||||
}
|
|
||||||
$vars['wgAjaxWatch'] = $msgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow extensions to add their custom variables to the global JS variables
|
// Allow extensions to add their custom variables to the global JS variables
|
||||||
wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
|
wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
|
||||||
|
|
||||||
return self::makeVariablesScript( $vars );
|
return self::makeVariablesScript( $vars );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -521,51 +447,20 @@ class Skin extends Linker {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generateUserJs( $skinName = null ) {
|
public function generateUserJs( $skinName = null ) {
|
||||||
global $wgStylePath;
|
|
||||||
|
// Stub - see ResourceLoaderSiteModule, CologneBlue, Simple and Standard skins override this
|
||||||
wfProfileIn( __METHOD__ );
|
|
||||||
|
return '';
|
||||||
if ( !$skinName ) {
|
|
||||||
$skinName = $this->getSkinName();
|
|
||||||
}
|
|
||||||
|
|
||||||
$s = "/* generated javascript */\n";
|
|
||||||
$s .= "var skin = '" . Xml::escapeJsString( $skinName ) . "';\n";
|
|
||||||
$s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
|
|
||||||
$s .= "\n\n/* MediaWiki:Common.js */\n";
|
|
||||||
|
|
||||||
$commonJs = wfMsgExt( 'common.js', 'content' );
|
|
||||||
|
|
||||||
if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
|
|
||||||
$s .= $commonJs;
|
|
||||||
}
|
|
||||||
|
|
||||||
$s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
|
|
||||||
|
|
||||||
// avoid inclusion of non defined user JavaScript (with custom skins only)
|
|
||||||
// by checking for default message content
|
|
||||||
$msgKey = ucfirst( $skinName ) . '.js';
|
|
||||||
$userJS = wfMsgExt( $msgKey, 'content' );
|
|
||||||
|
|
||||||
if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
|
|
||||||
$s .= $userJS;
|
|
||||||
}
|
|
||||||
|
|
||||||
wfProfileOut( __METHOD__ );
|
|
||||||
return $s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate user stylesheet for action=raw&gen=css
|
* Generate user stylesheet for action=raw&gen=css
|
||||||
*/
|
*/
|
||||||
public function generateUserStylesheet() {
|
public function generateUserStylesheet() {
|
||||||
wfProfileIn( __METHOD__ );
|
|
||||||
|
// Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
|
||||||
$s = "/* generated user stylesheet */\n" .
|
|
||||||
$this->reallyGenerateUserStylesheet();
|
return '';
|
||||||
|
|
||||||
wfProfileOut( __METHOD__ );
|
|
||||||
return $s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -573,53 +468,10 @@ class Skin extends Linker {
|
||||||
* Anything in here won't be generated if $wgAllowUserCssPrefs is false.
|
* Anything in here won't be generated if $wgAllowUserCssPrefs is false.
|
||||||
*/
|
*/
|
||||||
protected function reallyGenerateUserStylesheet() {
|
protected function reallyGenerateUserStylesheet() {
|
||||||
global $wgUser;
|
|
||||||
|
// Stub - see ResourceLoaderUserModule, CologneBlue, Simple and Standard skins override this
|
||||||
$s = '';
|
|
||||||
|
return '';
|
||||||
if ( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
|
|
||||||
$underline = $undopt ? 'underline' : 'none';
|
|
||||||
$s .= "a { text-decoration: $underline; }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $wgUser->getOption( 'highlightbroken' ) ) {
|
|
||||||
$s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
|
|
||||||
} else {
|
|
||||||
$s .= <<<CSS
|
|
||||||
a.new, #quickbar a.new,
|
|
||||||
a.stub, #quickbar a.stub {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
a.new:after, #quickbar a.new:after {
|
|
||||||
content: "?";
|
|
||||||
color: #CC2200;
|
|
||||||
}
|
|
||||||
a.stub:after, #quickbar a.stub:after {
|
|
||||||
content: "!";
|
|
||||||
color: #772233;
|
|
||||||
}
|
|
||||||
CSS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $wgUser->getOption( 'justify' ) ) {
|
|
||||||
$s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$wgUser->getOption( 'showtoc' ) ) {
|
|
||||||
$s .= "#toc { display: none; }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$wgUser->getOption( 'editsection' ) ) {
|
|
||||||
$s .= ".editsection { display: none; }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$fontstyle = $wgUser->getOption( 'editfont' );
|
|
||||||
|
|
||||||
if ( $fontstyle !== 'default' ) {
|
|
||||||
$s .= "textarea { font-family: $fontstyle; }\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -627,7 +479,7 @@ CSS;
|
||||||
*/
|
*/
|
||||||
function setupUserCss( OutputPage $out ) {
|
function setupUserCss( OutputPage $out ) {
|
||||||
global $wgRequest, $wgUser;
|
global $wgRequest, $wgUser;
|
||||||
global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage;
|
global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
|
||||||
|
|
||||||
wfProfileIn( __METHOD__ );
|
wfProfileIn( __METHOD__ );
|
||||||
|
|
||||||
|
|
@ -643,51 +495,26 @@ CSS;
|
||||||
$out->addStyle( $url );
|
$out->addStyle( $url );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we use the site's dynamic CSS, throw that in, too
|
|
||||||
// Per-site custom styles
|
// Per-site custom styles
|
||||||
if ( $wgUseSiteCss ) {
|
if ( $wgUseSiteCss ) {
|
||||||
$out->addModuleStyles( 'site' );
|
$out->addModuleStyles( 'site' );
|
||||||
}
|
}
|
||||||
|
|
||||||
global $wgAllowUserCssPrefs;
|
// Per-user custom styles
|
||||||
|
if ( $wgAllowUserCss ) {
|
||||||
if ( $wgAllowUserCssPrefs ) {
|
if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getVal( 'action' ) ) ) {
|
||||||
if ( $wgUser->isLoggedIn() ) {
|
|
||||||
// Ensure that logged-in users' generated CSS isn't clobbered
|
|
||||||
// by anons' publicly cacheable generated CSS.
|
|
||||||
$siteargs['smaxage'] = '0';
|
|
||||||
$siteargs['ts'] = $wgUser->mTouched;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Per-user styles based on preferences
|
|
||||||
$siteargs['gen'] = 'css';
|
|
||||||
|
|
||||||
if ( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
|
|
||||||
$siteargs['useskin'] = $us;
|
|
||||||
}
|
|
||||||
|
|
||||||
$out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Per-user custom style pages
|
|
||||||
if ( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
|
|
||||||
$action = $wgRequest->getVal( 'action' );
|
|
||||||
|
|
||||||
# If we're previewing the CSS page, use it
|
|
||||||
if ( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
|
|
||||||
// @FIXME: properly escape the cdata!
|
// @FIXME: properly escape the cdata!
|
||||||
$out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
|
$out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
|
||||||
} else {
|
} else {
|
||||||
$names = array( 'common', $this->getSkinName() );
|
$out->addModuleStyles( 'user' );
|
||||||
foreach ( $names as $name ) {
|
|
||||||
$out->addStyle( self::makeUrl(
|
|
||||||
$this->userpage . '/' . $name . '.css',
|
|
||||||
'action=raw&ctype=text/css' )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Per-user preference styles
|
||||||
|
if ( $wgAllowUserCssPrefs ) {
|
||||||
|
$out->addModuleStyles( 'user.preferences' );
|
||||||
|
}
|
||||||
|
|
||||||
wfProfileOut( __METHOD__ );
|
wfProfileOut( __METHOD__ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
load.php
2
load.php
|
|
@ -45,7 +45,7 @@ if ( $wgRequest->isPathInfoBad() ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to resource loading request
|
// Respond to resource loading request
|
||||||
ResourceLoader::respond( new ResourceLoaderContext( $wgRequest, $wgServer . $wgScriptPath . '/load.php' ) );
|
ResourceLoader::respond( new ResourceLoaderContext( $wgRequest ) );
|
||||||
|
|
||||||
wfProfileOut( 'load.php' );
|
wfProfileOut( 'load.php' );
|
||||||
wfLogProfilingData();
|
wfLogProfilingData();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ ResourceLoader::register( array(
|
||||||
|
|
||||||
'site' => new ResourceLoaderSiteModule,
|
'site' => new ResourceLoaderSiteModule,
|
||||||
'startup' => new ResourceLoaderStartUpModule,
|
'startup' => new ResourceLoaderStartUpModule,
|
||||||
|
'user' => new ResourceLoaderUserModule,
|
||||||
|
'user.preferences' => new ResourceLoaderUserPreferencesModule,
|
||||||
|
|
||||||
/* Skins */
|
/* Skins */
|
||||||
|
|
||||||
|
|
@ -356,6 +358,7 @@ ResourceLoader::register( array(
|
||||||
'mediawiki.legacy.mwsuggest' => new ResourceLoaderFileModule( array(
|
'mediawiki.legacy.mwsuggest' => new ResourceLoaderFileModule( array(
|
||||||
'scripts' => 'skins/common/mwsuggest.js',
|
'scripts' => 'skins/common/mwsuggest.js',
|
||||||
'dependencies' => 'mediawiki.legacy.wikibits',
|
'dependencies' => 'mediawiki.legacy.wikibits',
|
||||||
|
'messages' => array( 'search-mwsuggest-enabled', 'search-mwsuggest-disabled' ),
|
||||||
) ),
|
) ),
|
||||||
'mediawiki.legacy.password' => new ResourceLoaderFileModule( array(
|
'mediawiki.legacy.password' => new ResourceLoaderFileModule( array(
|
||||||
'scripts' => 'skins/common/password.js',
|
'scripts' => 'skins/common/password.js',
|
||||||
|
|
|
||||||
|
|
@ -469,7 +469,7 @@ window.mediaWiki = new ( function( $ ) {
|
||||||
var html = '';
|
var html = '';
|
||||||
for ( var r = 0; r < requests.length; r++ ) {
|
for ( var r = 0; r < requests.length; r++ ) {
|
||||||
// Build out the HTML
|
// Build out the HTML
|
||||||
var src = mediaWiki.config.get( 'server' ) + '?' + $.param( requests[r] );
|
var src = mediaWiki.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] );
|
||||||
html += '<script type="text/javascript" src="' + src + '"></script>';
|
html += '<script type="text/javascript" src="' + src + '"></script>';
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue