resourceloader: Move FILTER_NOMIN annotation to the beginning of output
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 30 Jan 2018 11:12:46 +0000 (12:12 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 30 Jan 2018 19:12:34 +0000 (19:12 +0000)
This allows ResourceLoader::filter() to handle this case slightly
faster, since it searches for this annotation from the beginning.
In practice this is a negligible performance optimization, but let's
set a good example for the future.

Also tweak the comments and whitespace:
* Move comment about the FILTER_NOMIN from doc comment to code comment,
  it's an implementation detail and not meant for public documentation
* Remove duplicated documentation from the parent class
* Change whitespace to be identical in both cases

Change-Id: I624914ff28d903027ba58710708ccc3c66af9e24

includes/resourceloader/ResourceLoaderUserOptionsModule.php
includes/resourceloader/ResourceLoaderUserTokensModule.php

index 458c44d..ffa55c0 100644 (file)
@@ -51,10 +51,12 @@ class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
         * @return string JavaScript code
         */
        public function getScript( ResourceLoaderContext $context ) {
-               return Xml::encodeJsCall( 'mw.user.options.set',
+               // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
+               return ResourceLoader::FILTER_NOMIN . Xml::encodeJsCall(
+                       'mw.user.options.set',
                        [ $context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS ) ],
                        ResourceLoader::inDebugMode()
-               ) . ResourceLoader::FILTER_NOMIN;
+               );
        }
 
        /**
index e933f1f..ae4fb67 100644 (file)
@@ -48,19 +48,16 @@ class ResourceLoaderUserTokensModule extends ResourceLoaderModule {
        }
 
        /**
-        * Generate the JavaScript content of this module.
-        *
-        * Add FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
-        *
         * @param ResourceLoaderContext $context
         * @return string JavaScript code
         */
        public function getScript( ResourceLoaderContext $context ) {
-               return Xml::encodeJsCall(
+               // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
+               return ResourceLoader::FILTER_NOMIN . Xml::encodeJsCall(
                        'mw.user.tokens.set',
                        [ $this->contextUserTokens( $context ) ],
                        ResourceLoader::inDebugMode()
-               ) . ResourceLoader::FILTER_NOMIN;
+               );
        }
 
        /**