r88553 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88552‎ | r88553 | r88554 >
Date:22:52, 21 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Adding user.tokens module and loading by default. (ResourceLoaderUserTokensModule Class)
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserTokensModule.php (added) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.user.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/Resources.php
@@ -8,8 +8,9 @@
99 'noscript' => array( 'class' => 'ResourceLoaderNoscriptModule' ),
1010 'startup' => array( 'class' => 'ResourceLoaderStartUpModule' ),
1111 'user' => array( 'class' => 'ResourceLoaderUserModule' ),
 12+ 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
1213 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ),
13 - 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
 14+ 'user.tokens' => array( 'class' => 'ResourceLoaderUserTokensModule' ),
1415
1516 /* Skins */
1617
Index: trunk/phase3/resources/mediawiki/mediawiki.user.js
@@ -17,6 +17,8 @@
1818
1919 this.options = new mw.Map();
2020
 21+ this.tokens = new mw.Map();
 22+
2123 /* Public Methods */
2224
2325 /**
Index: trunk/phase3/includes/AutoLoader.php
@@ -620,6 +620,7 @@
621621 'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
622622 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php',
623623 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
 624+ 'ResourceLoaderUserTokensModule' => 'includes/resourceloader/ResourceLoaderUserTokensModule.php',
624625 'ResourceLoaderWikiModule' => 'includes/resourceloader/ResourceLoaderWikiModule.php',
625626
626627 # includes/revisiondelete
Index: trunk/phase3/includes/OutputPage.php
@@ -2615,7 +2615,7 @@
26162616 // Legacy Scripts
26172617 $scripts .= "\n" . $this->mScripts;
26182618
2619 - $userScripts = array( 'user.options' );
 2619+ $userScripts = array( 'user.options', 'user.tokens' );
26202620
26212621 // Add site JS if enabled
26222622 if ( $wgUseSiteJs ) {
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserTokensModule.php
@@ -0,0 +1,62 @@
 2+<?php
 3+/**
 4+ * This program is free software; you can redistribute it and/or modify
 5+ * it under the terms of the GNU General Public License as published by
 6+ * the Free Software Foundation; either version 2 of the License, or
 7+ * (at your option) any later version.
 8+ *
 9+ * This program is distributed in the hope that it will be useful,
 10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 12+ * GNU General Public License for more details.
 13+ *
 14+ * You should have received a copy of the GNU General Public License along
 15+ * with this program; if not, write to the Free Software Foundation, Inc.,
 16+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 17+ * http://www.gnu.org/copyleft/gpl.html
 18+ *
 19+ * @file
 20+ * @author Krinkle
 21+ */
 22+
 23+/**
 24+ * Module for user tokens
 25+ */
 26+class ResourceLoaderUserTokensModule extends ResourceLoaderModule {
 27+
 28+ /* Protected Members */
 29+
 30+ protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
 31+
 32+ /* Methods */
 33+
 34+ /**
 35+ * Fetch the tokens for the current user.
 36+ *
 37+ * @param $context ResourceLoaderContext: Context object
 38+ * @return Array: List of tokens keyed by token type
 39+ */
 40+ protected function contextUserTokens( ResourceLoaderContext $context ) {
 41+ global $wgUser;
 42+
 43+ return array(
 44+ 'editToken' => $wgUser->edittoken(),
 45+ );
 46+ }
 47+
 48+ /**
 49+ * @param $context ResourceLoaderContext
 50+ * @return string
 51+ */
 52+ public function getScript( ResourceLoaderContext $context ) {
 53+ return Xml::encodeJsCall( 'mw.user.tokens.set',
 54+ array( $this->contextUserTokens( $context ) ) );
 55+ }
 56+
 57+ /**
 58+ * @return string
 59+ */
 60+ public function getGroup() {
 61+ return 'private';
 62+ }
 63+}
Property changes on: trunk/phase3/includes/resourceloader/ResourceLoaderUserTokensModule.php
___________________________________________________________________
Added: svn:eol-style
164 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r88554Passing token paremeter in mw.action.watch.ajax since this is required as of ...krinkle23:14, 21 May 2011
r88565Using the new mw.user.tokens (Introduced in r88553).krinkle08:47, 22 May 2011
r88627Release notes for r88625, r88553, r88511 (bringing back 'Other changes' like ...krinkle00:01, 23 May 2011

Comments

#Comment by Krinkle (talk | contribs)   22:53, 21 May 2011

bug 29067, by the way.

#Comment by Duplicatebug (talk | contribs)   17:36, 24 May 2011

It is good to generate an edittoken on each page view?

#Comment by Platonides (talk | contribs)   17:51, 24 May 2011

So each time a user views a page the edit token is streamed to him in the bottom of the page? It doesn't seem a good idea.

I think it should be lazy loaded. The first time a token is used, there is an AJAX post to the api that requests it and caches them in sessionStorage. If you also preload it on edit pages, there's no penalty involved.

Status & tagging log