r51661 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51660‎ | r51661 | r51662 >
Date:20:23, 9 June 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Moved message code which emulates loadGM and gM functions to a central place.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Resources/messages.js (added) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -20,6 +20,7 @@
2121 '/extensions/UsabilityInitiative/Resources/jquery.js',
2222 '/extensions/UsabilityInitiative/Resources/jquery.textSelection.js',
2323 '/extensions/UsabilityInitiative/Resources/jquery.cookie.js',
 24+ '/extensions/UsabilityInitiative/Resources/messages.js',
2425 );
2526 foreach ( $scripts as $script ) {
2627 // Add javascript resources to document
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -1,46 +1,6 @@
22 /* JavaScript for EditToolbar extension */
33
44 /**
5 - * This is designed to be directly compatible with (and is essentially taken
6 - * directly from) the mv_embed code for bringing internationalized messages into
7 - * the JavaScript space. As such, if we get to the point of merging that stuff
8 - * into the main branch this code will be uneeded and probably cause issues.
9 - */
10 -// Creates global message object if not already in existence
11 -if ( !gMsg ) var gMsg = {};
12 -/**
13 - * Caches a list of messages for later retieval
14 - * @param {Object} msgSet Hash of key:value pairs of messages to cache
15 - */
16 -function loadGM( msgSet ){
17 - for ( var i in msgSet ){
18 - gMsg[ i ] = msgSet[i];
19 - }
20 -}
21 -/**
22 - * Retieves a message from the global message cache, performing on-the-fly
23 - * replacements using MediaWiki message syntax ($1, $2, etc.)
24 - * @param {String} key Name of message as it is in MediaWiki
25 - * @param {Array} args Array of replacment arguments
26 - */
27 -function gM( key, args ) {
28 - var ms = '';
29 - if ( key in gMsg ) {
30 - ms = gMsg[ key ];
31 - if ( typeof args == 'object' || typeof args == 'array' ) {
32 - for ( var v in args ){
33 - var rep = '\$'+ ( parseInt(v) + 1 );
34 - ms = ms.replace( rep, args[v]);
35 - }
36 - } else if ( typeof args =='string' || typeof args =='number' ) {
37 - ms = ms.replace( /\$1/, args );
38 - }
39 - return ms;
40 - } else {
41 - return '[' + key + ']';
42 - }
43 -}
44 -/**
455 * This is the toolbar plugin, which can be used like
466 * $( 'div#edittoolbar' ).toolbar( '#wpTextbox1', tools );
477 * Where tools is an array of objects which describe each tool (see below for
Index: trunk/extensions/UsabilityInitiative/Resources/messages.js
@@ -0,0 +1,42 @@
 2+/* JavaScript for UsabilityInitiative extensions */
 3+
 4+/**
 5+ * This is designed to be directly compatible with (and is essentially taken
 6+ * directly from) the mv_embed code for bringing internationalized messages into
 7+ * the JavaScript space. As such, if we get to the point of merging that stuff
 8+ * into the main branch this code will be uneeded and probably cause issues.
 9+ */
 10+// Creates global message object if not already in existence
 11+if ( !gMsg ) var gMsg = {};
 12+/**
 13+ * Caches a list of messages for later retrieval
 14+ * @param {Object} msgSet Hash of key:value pairs of messages to cache
 15+ */
 16+function loadGM( msgSet ){
 17+ for ( var i in msgSet ){
 18+ gMsg[ i ] = msgSet[i];
 19+ }
 20+}
 21+/**
 22+ * Retieves a message from the global message cache, performing on-the-fly
 23+ * replacements using MediaWiki message syntax ($1, $2, etc.)
 24+ * @param {String} key Name of message as it is in MediaWiki
 25+ * @param {Array} args Array of replacement arguments
 26+ */
 27+function gM( key, args ) {
 28+ var ms = '';
 29+ if ( key in gMsg ) {
 30+ ms = gMsg[ key ];
 31+ if ( typeof args == 'object' || typeof args == 'array' ) {
 32+ for ( var v in args ){
 33+ var rep = '\$'+ ( parseInt(v) + 1 );
 34+ ms = ms.replace( rep, args[v]);
 35+ }
 36+ } else if ( typeof args =='string' || typeof args =='number' ) {
 37+ ms = ms.replace( /\$1/, args );
 38+ }
 39+ return ms;
 40+ } else {
 41+ return '[' + key + ']';
 42+ }
 43+}
Index: trunk/extensions/UsabilityInitiative/EditWarning/EditWarning.js
@@ -1,46 +1,5 @@
2 -/* JavaScript for EditToolbar extension */
 2+/* JavaScript for EditWarning extension */
33
4 -/**
5 - * This is designed to be directly compatible with (and is essentially taken
6 - * directly from) the mv_embed code for bringing internationalized messages into
7 - * the JavaScript space. As such, if we get to the point of merging that stuff
8 - * into the main branch this code will be uneeded and probably cause issues.
9 - */
10 -// Creates global message object if not already in existence
11 -if ( !gMsg ) var gMsg = {};
12 -/**
13 - * Caches a list of messages for later retrieval
14 - * @param {Object} msgSet Hash of key:value pairs of messages to cache
15 - */
16 -function loadGM( msgSet ){
17 - for ( var i in msgSet ){
18 - gMsg[ i ] = msgSet[i];
19 - }
20 -}
21 -/**
22 - * Retieves a message from the global message cache, performing on-the-fly
23 - * replacements using MediaWiki message syntax ($1, $2, etc.)
24 - * @param {String} key Name of message as it is in MediaWiki
25 - * @param {Array} args Array of replacement arguments
26 - */
27 -function gM( key, args ) {
28 - var ms = '';
29 - if ( key in gMsg ) {
30 - ms = gMsg[ key ];
31 - if ( typeof args == 'object' || typeof args == 'array' ) {
32 - for ( var v in args ){
33 - var rep = '\$'+ ( parseInt(v) + 1 );
34 - ms = ms.replace( rep, args[v]);
35 - }
36 - } else if ( typeof args =='string' || typeof args =='number' ) {
37 - ms = ms.replace( /\$1/, args );
38 - }
39 - return ms;
40 - } else {
41 - return '[' + key + ']';
42 - }
43 -}
44 -
454 function editWarningSetWarning() {
465 $(window).bind('beforeunload', function(event) {
476 if(!confirm(gM('editwarning-warning')))

Status & tagging log