Clean up array() syntax in docs, part IV
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderModule.php
index 121a6c9..de89fc7 100644 (file)
@@ -35,6 +35,12 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
        const TYPE_STYLES = 'styles';
        const TYPE_COMBINED = 'combined';
 
+       # Desired load type
+       // Module only has styles (loaded via <style> or <link rel=stylesheet>)
+       const LOAD_STYLES = 'styles';
+       // Module may have other resources (loaded via mw.loader from a script)
+       const LOAD_GENERAL = 'general';
+
        # sitewide core module like a skin file or jQuery component
        const ORIGIN_CORE_SITEWIDE = 1;
 
@@ -76,6 +82,11 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         */
        protected $config;
 
+       /**
+        * @var array|bool
+        */
+       protected $deprecated = false;
+
        /**
         * @var LoggerInterface
         */
@@ -124,6 +135,28 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                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.
@@ -231,8 +264,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         *
         * @param ResourceLoaderContext $context
         * @return array List of CSS strings or array of CSS strings keyed by media type.
-        *  like array( 'screen' => '.foo { width: 0 }' );
-        *  or array( 'screen' => array( '.foo { width: 0 }' ) );
+        *  like [ 'screen' => '.foo { width: 0 }' ];
+        *  or [ 'screen' => [ '.foo { width: 0 }' ] ];
         */
        public function getStyles( ResourceLoaderContext $context ) {
                // Stub, override expected
@@ -246,7 +279,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
         * load the files directly. See also getScriptURLsForDebug()
         *
         * @param ResourceLoaderContext $context
-        * @return array Array( mediaType => array( URL1, URL2, ... ), ... )
+        * @return array [ mediaType => [ URL1, URL2, ... ], ... ]
         */
        public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
                $resourceLoader = $context->getResourceLoader();
@@ -343,6 +376,16 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                return $this->targets;
        }
 
+       /**
+        * Get the module's load type.
+        *
+        * @since 1.28
+        * @return string ResourceLoaderModule LOAD_* constant
+        */
+       public function getType() {
+               return self::LOAD_GENERAL;
+       }
+
        /**
         * Get the skip function.
         *
@@ -443,7 +486,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                                        ]
                                );
 
-                               $dbw->onTransactionIdle( function () use ( &$scopeLock ) {
+                               $dbw->onTransactionResolution( function () use ( &$scopeLock ) {
                                        ScopedCallback::consume( $scopeLock ); // release after commit
                                } );
                        }
@@ -594,7 +637,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                // Styles
                if ( $context->shouldIncludeStyles() ) {
                        $styles = [];
-                       // Don't create empty stylesheets like array( '' => '' ) for modules
+                       // Don't create empty stylesheets like [ '' => '' ] for modules
                        // that don't *have* any stylesheets (bug 38024).
                        $stylePairs = $this->getStyles( $context );
                        if ( count( $stylePairs ) ) {