"type": "string",
"description": "Group with which this module should be loaded"
},
+ "deprecated": {
+ "type": ["object", "boolean"],
+ "description": "Whether the module is deprecated and usage is discouraged. Either a boolean or an object with key message can be used to customise deprecation message."
+ },
"position": {
"type": "string",
"description": "Position on the page to load this module at",
"type": "string",
"description": "Group which this module should be loaded together with"
},
+ "deprecated": {
+ "type": ["object", "boolean"],
+ "description": "Whether the module is deprecated and usage is discouraged. Either a boolean or an object with key message can be used to customise deprecation message."
+ },
"position": {
"type": "string",
"description": "Position on the page to load this module at",
$this->{$member}[$key] = (array)$value;
}
break;
+ case 'deprecated':
+ $this->deprecated = $option;
+ break;
// Lists of strings
case 'dependencies':
case 'messages':
*/
public function getScript( ResourceLoaderContext $context ) {
$files = $this->getScriptFiles( $context );
- return $this->readScriptFiles( $files );
+ return $this->getDeprecationInformation() . $this->readScriptFiles( $files );
}
/**
*/
protected $config;
+ /**
+ * @var array|bool
+ */
+ protected $deprecated = false;
+
/**
* @var LoggerInterface
*/
return $wgContLang->getDir() !== $context->getDirection();
}
+ /**
+ * Get JS representing deprecation information for the current module if available
+ *
+ * @return string JavaScript code
+ */
+ protected function getDeprecationInformation() {
+ $deprecationInfo = $this->deprecated;
+ if ( $deprecationInfo ) {
+ $name = $this->getName();
+ $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
+ if ( !is_bool( $deprecationInfo ) && isset( $deprecationInfo['message'] ) ) {
+ $warning .= "\n" . $deprecationInfo['message'];
+ }
+ return Xml::encodeJsCall(
+ 'mw.log.warn',
+ [ $warning ]
+ );
+ } else {
+ return '';
+ }
+ }
+
/**
* Get all JS for this module for a given language and skin.
* Includes all relevant JS except loader scripts.
return [
'noTemplateModule' => [],
+ 'deprecatedModule' => $base + [
+ 'deprecated' => true,
+ ],
+ 'deprecatedTomorrow' => $base + [
+ 'deprecated' => [
+ 'message' => 'Will be removed tomorrow.'
+ ],
+ ],
+
'htmlTemplateModule' => $base + [
'templates' => [
'templates/template.html',
$this->assertEquals( $rl->getDependencies(), $expected );
}
+ public static function providerDeprecatedModules() {
+ return [
+ [
+ 'deprecatedModule',
+ 'mw.log.warn("This page is using the deprecated ResourceLoader module \"deprecatedModule\".");',
+ ],
+ [
+ 'deprecatedTomorrow',
+ 'mw.log.warn(' .
+ '"This page is using the deprecated ResourceLoader module \"deprecatedTomorrow\".\\n' .
+ "Will be removed tomorrow." .
+ '");'
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider providerDeprecatedModules
+ * @covers ResourceLoaderFileModule::getScripts
+ */
+ public function testDeprecatedModules( $name, $expected ) {
+ $modules = self::getModules();
+ $rl = new ResourceLoaderFileModule( $modules[$name] );
+ $rl->setName( $name );
+ $ctx = $this->getResourceLoaderContext( 'en', 'ltr' );
+ $this->assertEquals( $rl->getScript( $ctx ), $expected );
+ }
+
/**
* @covers ResourceLoaderFileModule::getAllStyleFiles
* @covers ResourceLoaderFileModule::getAllSkinStyleFiles