* The mw.user.stickyRandomId() method, deprecated in 1.32, was removed.
Use mw.user.getPageviewToken() instead.
* Removed deprecated class property WikiRevision::$importer.
+* ResourceLoaderFileModule::readStyleFiles() now requires its $context
+ parameter.
=== Deprecations in 1.33 ===
* The configuration option $wgUseESI has been deprecated, and is expected
use ParserFactory;
use PasswordFactory;
use ProxyLookup;
+use ResourceLoader;
use SearchEngine;
use SearchEngineConfig;
use SearchEngineFactory;
return $this->getService( 'ReadOnlyMode' );
}
+ /**
+ * @since 1.33
+ * @return ResourceLoader
+ */
+ public function getResourceLoader() {
+ return $this->getService( 'ResourceLoader' );
+ }
+
/**
* @since 1.31
* @return RevisionFactory
*/
use MediaWiki\Linker\LinkTarget;
-use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
use Wikimedia\Rdbms\IResultWrapper;
*/
public function getResourceLoader() {
if ( is_null( $this->mResourceLoader ) ) {
- $this->mResourceLoader = new ResourceLoader(
- $this->getConfig(),
- LoggerFactory::getInstance( 'resourceloader' )
- );
+ // Lazy-initialise as needed
+ $this->mResourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
}
return $this->mResourceLoader;
}
);
},
+ 'ResourceLoader' => function ( MediaWikiServices $services ) : ResourceLoader {
+ return new ResourceLoader(
+ $services->getMainConfig(),
+ LoggerFactory::getInstance( 'resourceloader' )
+ );
+ },
+
'RevisionFactory' => function ( MediaWikiServices $services ) : RevisionFactory {
return $services->getRevisionStore();
},
* @author Timo Tijhof
*/
+use MediaWiki\MediaWikiServices;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
// Lazy-initialise this property because most callers don't need it.
if ( $this->resourceloader === null ) {
$this->logger->warning( __CLASS__ . ' created without a ResourceLoader instance' );
- $this->resourceloader = new ResourceLoader();
+ $this->resourceloader = MediaWikiServices::getInstance()->getResourceLoader();
}
return $this->resourceloader;
}
* @ingroup Deployment
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Output class modelled on OutputPage.
*
'mediawiki.skinning.interface',
];
- $resourceLoader = new ResourceLoader();
+ $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
// Force loading Vector skin if available as a fallback skin
$this->logger = $logger ?: new NullLogger();
if ( !$config ) {
+ // TODO: Deprecate and remove.
$this->logger->debug( __METHOD__ . ' was called without providing a Config instance' );
$config = MediaWikiServices::getInstance()->getMainConfig();
}
/**
* Return a dummy ResourceLoaderContext object suitable for passing into
* things that don't "really" need a context.
+ *
+ * Use cases:
+ * - Creating html5shiv script tag in OutputPage.
+ * - Unit tests (deprecated, create empty instance directly or use RLTestCase).
+ *
* @return ResourceLoaderContext
*/
public static function newDummyContext() {
+ // This currently creates a non-empty instance of ResourceLoader (all modules registered),
+ // but that's probably not needed. So once that moves into ServiceWiring, this'll
+ // become more like the EmptyResourceLoader class we have in PHPUnit tests, which
+ // is what this should've had originally. If this turns out to be untrue, change to:
+ // `MediaWikiServices::getInstance()->getResourceLoader()` instead.
return new self( new ResourceLoader(
MediaWikiServices::getInstance()->getMainConfig(),
LoggerFactory::getInstance( 'resourceloader' )
/**
* Get the contents of a list of CSS files.
*
- * This is considered a private method. Exposed for internal use by WebInstallerOutput.
- *
- * @private
+ * @internal This is considered a private method. Exposed for internal use by WebInstallerOutput.
* @param array $styles Map of media type to file paths to read, remap, and concatenate
* @param bool $flip
- * @param ResourceLoaderContext|null $context
+ * @param ResourceLoaderContext $context
* @return array List of concatenated and remapped CSS data from $styles,
* keyed by media type
* @throws MWException
- * @since 1.27 Calling this method without a ResourceLoaderContext instance
- * is deprecated.
*/
- public function readStyleFiles( array $styles, $flip, $context = null ) {
- if ( $context === null ) {
- wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' );
- $context = ResourceLoaderContext::newDummyContext();
- }
-
- if ( empty( $styles ) ) {
+ public function readStyleFiles( array $styles, $flip, $context ) {
+ if ( !$styles ) {
return [];
}
foreach ( $styles as $media => $files ) {
* @author Trevor Parscal
*/
-use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
// This endpoint is supposed to be independent of request cookies and other
// writes when getting database connections for ResourceLoader. (T192611)
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->disableChronologyProtection();
-// Set up ResourceLoader
-$resourceLoader = new ResourceLoader(
- ConfigFactory::getDefaultInstance()->makeConfig( 'main' ),
- LoggerFactory::getInstance( 'resourceloader' )
-);
+$resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
$context = new ResourceLoaderContext( $resourceLoader, $wgRequest );
// Respond to ResourceLoader request
$this->output( "Cleaning up module_deps table...\n" );
$dbw = $this->getDB( DB_MASTER );
- $rl = new ResourceLoader( MediaWikiServices::getInstance()->getMainConfig() );
+ $rl = MediaWikiServices::getInstance()->getResourceLoader();
$moduleNames = $rl->getModuleNames();
$res = $dbw->select( 'module_deps',
[ 'md_module', 'md_skin' ],
* @return {boolean} Namespace is a signature namespace
*/
Title.wantSignaturesNamespace = function ( namespaceId ) {
- return this.isTalkNamespace( namespaceId ) ||
+ return Title.isTalkNamespace( namespaceId ) ||
mw.config.get( 'wgExtraSignatureNamespaces' ).indexOf( namespaceId ) !== -1;
};
<?php
+
+use MediaWiki\MediaWikiServices;
+use Wikimedia\TestingAccessWrapper;
+
/**
* Sanity checks for making sure registered resources are sane.
*
- * @file
* @author Antoine Musso
* @author Niklas Laxström
* @author Santhosh Thottingal
$org_wgEnableJavaScriptTest = $wgEnableJavaScriptTest;
$wgEnableJavaScriptTest = true;
- // Initialize ResourceLoader
- $rl = new ResourceLoader();
+ // Get main ResourceLoader
+ $rl = MediaWikiServices::getInstance()->getResourceLoader();
$modules = [];
/**
* Get all resource files from modules that are an instance of
* ResourceLoaderFileModule (or one of its subclasses).
- *
- * Since the raw data is stored in protected properties, we have to
- * overrride this through ReflectionObject methods.
*/
public static function provideResourceFiles() {
$data = self::getAllModules();
continue;
}
- $reflectedModule = new ReflectionObject( $module );
+ $moduleProxy = TestingAccessWrapper::newFromObject( $module );
$files = [];
foreach ( $filePathProps['lists'] as $propName ) {
- $property = $reflectedModule->getProperty( $propName );
- $property->setAccessible( true );
- $list = $property->getValue( $module );
+ $list = $moduleProxy->$propName;
foreach ( $list as $key => $value ) {
// 'scripts' are numeral arrays.
// 'styles' can be numeral or associative.
}
foreach ( $filePathProps['nested-lists'] as $propName ) {
- $property = $reflectedModule->getProperty( $propName );
- $property->setAccessible( true );
- $lists = $property->getValue( $module );
+ $lists = $moduleProxy->$propName;
foreach ( $lists as $list ) {
foreach ( $list as $key => $value ) {
// We need the same filter as for 'lists',
}
}
- // Get method for resolving the paths to full paths
- $method = $reflectedModule->getMethod( 'getLocalPath' );
- $method->setAccessible( true );
-
// Populate cases
foreach ( $files as $file ) {
$cases[] = [
- $method->invoke( $module, $file ),
+ $moduleProxy->getLocalPath( $file ),
$moduleName,
( $file instanceof ResourceLoaderFilePath ? $file->getPath() : $file ),
];
}
// To populate missingLocalFileRefs. Not sure how sane this is inside this test...
- $module->readStyleFiles(
+ $moduleProxy->readStyleFiles(
$module->getStyleFiles( $data['context'] ),
$module->getFlip( $data['context'] ),
$data['context']
);
- $property = $reflectedModule->getProperty( 'missingLocalFileRefs' );
- $property->setAccessible( true );
- $missingLocalFileRefs = $property->getValue( $module );
+ $missingLocalFileRefs = $moduleProxy->missingLocalFileRefs;
foreach ( $missingLocalFileRefs as $file ) {
$cases[] = [
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @author Sam Smith <samsmith@wikimedia.org>
*/
public function __construct() {
parent::__construct();
- $resourceLoader = new ResourceLoader();
+ $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
foreach ( $resourceLoader->getModuleNames() as $name ) {
$module = $resourceLoader->getModule( $name );
} );
QUnit.test( 'wantSignaturesNamespace', function ( assert ) {
- var namespaces = mw.config.values.wgExtraSignatureNamespaces;
-
- mw.config.values.wgExtraSignatureNamespaces = [];
+ mw.config.set( 'wgExtraSignatureNamespaces', [] );
assert.strictEqual( mw.Title.wantSignaturesNamespace( 0 ), false, 'Main namespace has no signatures' );
assert.strictEqual( mw.Title.wantSignaturesNamespace( 1 ), true, 'Talk namespace has signatures' );
assert.strictEqual( mw.Title.wantSignaturesNamespace( 2 ), false, 'NS2 has no signatures' );
assert.strictEqual( mw.Title.wantSignaturesNamespace( 3 ), true, 'NS3 has signatures' );
- mw.config.values.wgExtraSignatureNamespaces = [ 0 ];
+ mw.config.set( 'wgExtraSignatureNamespaces', [ 0 ] );
assert.strictEqual( mw.Title.wantSignaturesNamespace( 0 ), true, 'Main namespace has signatures when explicitly defined' );
-
- // Restore
- mw.config.values.wgExtraSignatureNamespaces = namespaces;
} );
QUnit.test( 'Throw error on invalid title', function ( assert ) {