/**
* TODO: Document
- * @param $modules Array/string with the module name
+ * @param $modules Array/string with the module name(s)
* @param $only String ResourceLoaderModule TYPE_ class constant
* @param $useESI boolean
+ * @param $extraQuery Array with extra query parameters to add to each request. array( param => value )
* @return string html <script> and <style> tags
*/
- protected function makeResourceLoaderLink( $modules, $only, $useESI = false ) {
+ protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array() ) {
global $wgLoadScript, $wgResourceLoaderUseESI,
$wgResourceLoaderInlinePrivateModules;
$baseQuery = array(
'lang' => $this->getContext()->getLang()->getCode(),
'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
'skin' => $this->getSkin()->getSkinName(),
- );
+ ) + $extraQuery;
if ( $only !== ResourceLoaderModule::TYPE_COMBINED ) {
$baseQuery['only'] = $only;
}
if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview() ) {
# XXX: additional security check/prompt?
+ // We're on a preview of a JS subpage
+ // Exclude this page from the user module in case it's in there (bug 26283)
+ $scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS, false,
+ array( 'excludepage' => $this->getTitle()->getPrefixedText() )
+ );
+ // Load the previewed JS
$scripts .= Html::inlineScript( "\n" . $this->getRequest()->getText( 'wpTextbox1' ) . "\n" ) . "\n";
} else {
- # @todo FIXME: This means that User:Me/Common.js doesn't load when previewing
- # User:Me/Vector.js, and vice versa (bug 26283)
-
+ // Include the user module normally
// We can't do $userScripts[] = 'user'; because the user module would end up
// being wrapped in a closure, so load it raw like 'site'
$scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS );
// Add ResourceLoader styles
// Split the styles into four groups
$styles = array( 'other' => array(), 'user' => array(), 'site' => array(), 'private' => array(), 'noscript' => array() );
+ $otherTags = ''; // Tags to append after the normal <link> tags
$resourceLoader = $this->getResourceLoader();
$moduleStyles = $this->getModuleStyles();
// Per-user custom styles
if ( $wgAllowUserCss ) {
if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview() ) {
- // @todo FIXME: Properly escape the cdata!
- $this->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
+ // We're on a preview of a CSS subpage
+ // Exclude this page from the user module in case it's in there (bug 26283)
+ $otherTags .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_STYLES, false,
+ array( 'excludepage' => $this->getTitle()->getPrefixedText() )
+ );
+ // Load the previewed CSS
+ $otherTags .= Html::inlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );;
} else {
+ // Load the user styles normally
$moduleStyles[] = 'user';
}
}
ResourceLoaderModule::TYPE_STYLES
);
}
+
+ // Add stuff in $otherTags (previewed user CSS if applicable)
+ $ret .= $otherTags;
return $ret;
}
protected function getPages( ResourceLoaderContext $context ) {
if ( $context->getUser() ) {
$username = $context->getUser();
- return array(
+ $pages = array(
"User:$username/common.js" => array( 'type' => 'script' ),
"User:$username/" . $context->getSkin() . '.js' =>
array( 'type' => 'script' ),
"User:$username/" . $context->getSkin() . '.css' =>
array( 'type' => 'style' ),
);
+
+ // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
+ // we need to exclude that page from this module. In that case, the excludepage
+ // parameter will be set to the name of the page we need to exclude.
+ $excludepage = $context->getRequest()->getVal( 'excludepage' );
+ if ( isset( $pages[$excludepage] ) ) {
+ unset( $pages[$excludepage] );
+ }
+ return $pages;
}
return array();
}