* @file
*/
+use MediaWiki\Logger\LoggerFactory;
+
/**
* This class should be covered by a general architecture document which does
* not exist as of January 2011. This is one of the Core classes and should
/** @var array */
protected $mModuleStyles = array();
- /** @var array */
- protected $mModuleMessages = array();
-
/** @var ResourceLoader */
protected $mResourceLoader;
* @return array Array of module names
*/
public function getModuleStyles( $filter = false, $position = null ) {
+ // T97420
+ $resourceLoader = $this->getResourceLoader();
+
+ foreach ( $this->mModuleStyles as $val ) {
+ $module = $resourceLoader->getModule( $val );
+
+ if ( $module instanceof ResourceLoaderModule && $module->isPositionDefault() ) {
+ $warning = __METHOD__ . ': style module should define its position explicitly: ' . $val . ' ' . get_class( $module );
+ wfDebugLog( 'resourceloader', $warning );
+ wfLogWarning( $warning );
+ }
+ }
+
return $this->getModules( $filter, $position, 'mModuleStyles' );
}
/**
* Get the list of module messages to include on this page
*
+ * @deprecated since 1.26 Obsolete
* @param bool $filter
* @param string|null $position
- *
* @return array Array of module names
*/
public function getModuleMessages( $filter = false, $position = null ) {
- return $this->getModules( $filter, $position, 'mModuleMessages' );
+ wfDeprecated( __METHOD__, '1.26' );
+ return array();
}
/**
- * Add only messages of one or more modules recognized by the resource loader.
- * Module messages added through this function will be loaded by the resource
- * loader when the page loads.
+ * Load messages of one or more ResourceLoader modules.
*
+ * @deprecated since 1.26 Use addModules() instead
* @param string|array $modules Module name (string) or array of module names
*/
public function addModuleMessages( $modules ) {
- $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
+ wfDeprecated( __METHOD__, '1.26' );
}
/**
}
# Not modified
- # Give a 304 response code and disable body output
+ # Give a 304 Not Modified response code and disable body output
wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", 'log' );
ini_set( 'zlib.output_compression', 0 );
- $this->getRequest()->response()->header( "HTTP/1.1 304 Not Modified" );
+ $this->getRequest()->response()->statusHeader( 304 );
$this->sendCacheControl();
$this->disable();
/**
* Adds help link with an icon via page indicators.
- * @param string $to
- * @param bool $overrideBaseUrl
+ * Link target can be overridden by a local message containing a wikilink:
+ * the message key is: lowercase action or special page name + '-helppage'.
+ * @param string $to Target MediaWiki.org page title or encoded URL.
+ * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
* @since 1.25
*/
public function addHelpLink( $to, $overrideBaseUrl = false ) {
$toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
$helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
}
+
$link = Html::rawElement(
'a',
array(
$this->addModules( $parserOutput->getModules() );
$this->addModuleScripts( $parserOutput->getModuleScripts() );
$this->addModuleStyles( $parserOutput->getModuleStyles() );
- $this->addModuleMessages( $parserOutput->getModuleMessages() );
$this->addJsConfigVars( $parserOutput->getJsConfigVars() );
$this->mPreventClickjacking = $this->mPreventClickjacking
|| $parserOutput->preventClickjacking();
$this->addModules( $parserOutput->getModules() );
$this->addModuleScripts( $parserOutput->getModuleScripts() );
$this->addModuleStyles( $parserOutput->getModuleStyles() );
- $this->addModuleMessages( $parserOutput->getModuleMessages() );
$this->addJsConfigVars( $parserOutput->getJsConfigVars() );
}
if ( Hooks::run( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) {
if ( $code == '301' || $code == '303' ) {
if ( !$config->get( 'DebugRedirects' ) ) {
- $message = HttpStatus::getMessage( $code );
- $response->header( "HTTP/1.1 $code $message" );
+ $response->statusHeader( $code );
}
$this->mLastModified = wfTimestamp( TS_RFC2822 );
}
return;
} elseif ( $this->mStatusCode ) {
- $message = HttpStatus::getMessage( $this->mStatusCode );
- if ( $message ) {
- $response->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $message );
- }
+ $response->statusHeader( $this->mStatusCode );
}
# Buffer output; final headers may depend on later processing
*/
public function getResourceLoader() {
if ( is_null( $this->mResourceLoader ) ) {
- $this->mResourceLoader = new ResourceLoader( $this->getConfig() );
+ $this->mResourceLoader = new ResourceLoader(
+ $this->getConfig(),
+ LoggerFactory::getInstance( 'resourceloader' )
+ );
}
return $this->mResourceLoader;
}
// and we shouldn't be putting timestamps in Squid-cached HTML
$version = null;
if ( $group === 'user' ) {
- // Get the maximum timestamp
- $timestamp = 1;
- foreach ( $grpModules as $module ) {
- $timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
- }
- // Add a version parameter so cache will break when things change
- $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, $timestamp );
+ $query['version'] = $resourceLoader->getCombinedVersion( $context, array_keys( $grpModules ) );
}
$query['modules'] = ResourceLoader::makePackedModulesString( array_keys( $grpModules ) );
// Load embeddable private modules before any loader links
// This needs to be TYPE_COMBINED so these modules are properly wrapped
// in mw.loader.implement() calls and deferred until mw.user is available
- $embedScripts = array( 'user.options', 'user.tokens' );
+ $embedScripts = array( 'user.options' );
$links[] = $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
+ // Separate user.tokens as otherwise caching will be allowed (T84960)
+ $links[] = $this->makeResourceLoaderLink( 'user.tokens', ResourceLoaderModule::TYPE_COMBINED );
// Scripts and messages "only" requests marked for top inclusion
- // Messages should go first
- $links[] = $this->makeResourceLoaderLink(
- $this->getModuleMessages( true, 'top' ),
- ResourceLoaderModule::TYPE_MESSAGES
- );
$links[] = $this->makeResourceLoaderLink(
$this->getModuleScripts( true, 'top' ),
ResourceLoaderModule::TYPE_SCRIPTS
* @return string
*/
function getScriptsForBottomQueue( $inHead ) {
- // Scripts and messages "only" requests marked for bottom inclusion
+ // Scripts "only" requests marked for bottom inclusion
// If we're in the <head>, use load() calls rather than <script src="..."> tags
- // Messages should go first
$links = array();
- $links[] = $this->makeResourceLoaderLink( $this->getModuleMessages( true, 'bottom' ),
- ResourceLoaderModule::TYPE_MESSAGES, /* $useESI = */ false, /* $extraQuery = */ array(),
- /* $loadCall = */ $inHead
- );
+
$links[] = $this->makeResourceLoaderLink( $this->getModuleScripts( true, 'bottom' ),
ResourceLoaderModule::TYPE_SCRIPTS, /* $useESI = */ false, /* $extraQuery = */ array(),
/* $loadCall = */ $inHead
);
+ $links[] = $this->makeResourceLoaderLink( $this->getModuleStyles( true, 'bottom' ),
+ ResourceLoaderModule::TYPE_STYLES, /* $useESI = */ false, /* $extraQuery = */ array(),
+ /* $loadCall = */ $inHead
+ );
+
// Modules requests - let the client calculate dependencies and batch requests as it likes
// Only load modules that have marked themselves for loading at the bottom
$modules = $this->getModules( true, 'bottom' );
* @return string
*/
function getBottomScripts() {
+ // In case the skin wants to add bottom CSS
+ $this->getSkin()->setupSkinUserCss( $this );
+
// Optimise jQuery ready event cross-browser.
// This also enforces $.isReady to be true at </body> which fixes the
// mw.loader bug in Firefox with using document.write between </body>
$otherTags = ''; // Tags to append after the normal <link> tags
$resourceLoader = $this->getResourceLoader();
- $moduleStyles = $this->getModuleStyles();
+ $moduleStyles = $this->getModuleStyles( true, 'top' );
// Per-site custom styles
$moduleStyles[] = 'site';
public function enableOOUI() {
OOUI\Theme::setSingleton( new OOUI\MediaWikiTheme() );
OOUI\Element::setDefaultDir( $this->getLanguage()->getDir() );
- $this->addModuleStyles( 'oojs-ui.styles' );
+ $this->addModuleStyles( array(
+ 'oojs-ui.styles',
+ 'oojs-ui.styles.icons',
+ 'oojs-ui.styles.indicators',
+ 'oojs-ui.styles.textures',
+ ) );
}
}