Merge "Don't link to title on "htmlform-title-not-exists""
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderUserTokensModule.php
index 668467c..d37aa55 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Resource loader module for user tokens.
+ * ResourceLoader module for user tokens.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,27 +37,34 @@ class ResourceLoaderUserTokensModule extends ResourceLoaderModule {
        /**
         * Fetch the tokens for the current user.
         *
+        * @param ResourceLoaderContext $context
         * @return array List of tokens keyed by token type
         */
-       protected function contextUserTokens() {
-               global $wgUser;
+       protected function contextUserTokens( ResourceLoaderContext $context ) {
+               $user = $context->getUserObj();
 
                return array(
-                       'editToken' => $wgUser->getEditToken(),
-                       'patrolToken' => $wgUser->getEditToken( 'patrol' ),
-                       'watchToken' => $wgUser->getEditToken( 'watch' ),
+                       'editToken' => $user->getEditToken(),
+                       'patrolToken' => $user->getEditToken( 'patrol' ),
+                       'watchToken' => $user->getEditToken( 'watch' ),
                );
        }
 
        /**
+        * Generate the JavaScript content of this module.
+        *
+        * Add '@nomin' annotation to prevent the module's contents from getting
+        * cached (T84960).
+        *
         * @param ResourceLoaderContext $context
         * @return string
         */
        public function getScript( ResourceLoaderContext $context ) {
-               return Xml::encodeJsCall( 'mw.user.tokens.set',
-                       array( $this->contextUserTokens() ),
+               return Xml::encodeJsCall(
+                       'mw.user.tokens.set',
+                       array( $this->contextUserTokens( $context ) ),
                        ResourceLoader::inDebugMode()
-               );
+               ) . ResourceLoader::FILTER_NOMIN;
        }
 
        /**