r57436 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57435‎ | r57436 | r57437 >
Date:20:50, 6 October 2009
Author:tparscal
Status:ok
Tags:
Comment:
Refactored user-agent black-listing system, now allowing more sophisticated logic and more flexiblility for black-listing very specific versions of browsers.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -15,9 +15,38 @@
1616 $.wikiEditor = {
1717 'modules': {},
1818 'instances': [],
19 - 'supportedBrowsers': {
20 - 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
21 - 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
 19+ /**
 20+ * For each browser name, an array of conditions that must be met are supplied in [operaton, value] form where
 21+ * operation is a string containing a JavaScript compatible binary operator and value is either a number to be
 22+ * compared with $.browser.versionNumber or a string to be compared with $.browser.version
 23+ */
 24+ 'browsers': {
 25+ 'ltr': {
 26+ 'msie': [['>=', 7]],
 27+ 'firefox': [
 28+ ['>=', 2],
 29+ ['!=', '2.0'],
 30+ ['!=', '2.0.0.1'],
 31+ ['!=', '2.0.0.2'],
 32+ ['!=', '2.0.0.3'],
 33+ ['!=', '2.0.0.4']
 34+ ],
 35+ 'opera': [['>=', 9.6]],
 36+ 'safari': [['>=', 3.1]]
 37+ },
 38+ 'rtl': {
 39+ 'msie': [['>=', 8]],
 40+ 'firefox': [
 41+ ['>=', 2],
 42+ ['!=', '2.0'],
 43+ ['!=', '2.0.0.1'],
 44+ ['!=', '2.0.0.2'],
 45+ ['!=', '2.0.0.3'],
 46+ ['!=', '2.0.0.4']
 47+ ],
 48+ 'opera': [['>=', 9.6]],
 49+ 'safari': [['>=', 3.1]]
 50+ }
2251 },
2352 /**
2453 * Path to images - this is a bit messy, and it would need to change if
@@ -28,14 +57,28 @@
2958 };
3059
3160 $.wikiEditor.isSupportKnown = function() {
32 - return ( function( supportedBrowsers ) {
33 - return $.browser.name in supportedBrowsers;
34 - } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 61+ return $.browser.name in $.wikiEditor.browsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'];
3562 };
3663 $.wikiEditor.isSupported = function() {
37 - return ( function( supportedBrowsers ) {
38 - return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
39 - } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 64+ if ( !$.wikiEditor.isSupportKnown ) {
 65+ // Assume good faith :)
 66+ return true;
 67+ }
 68+ var browser = $.wikiEditor.browsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'][$.browser.name];
 69+ for ( condition in browser ) {
 70+ var op = browser[condition][0];
 71+ var val = browser[condition][1];
 72+ if ( typeof val == 'string' ) {
 73+ if ( !( eval( '$.browser.version' + op + '"' + val + '"' ) ) ) {
 74+ return false;
 75+ }
 76+ } else if ( typeof val == 'number' ) {
 77+ if ( !( eval( '$.browser.versionNumber' + op + val ) ) ) {
 78+ return false;
 79+ }
 80+ }
 81+ }
 82+ return true;
4083 };
4184 // Wraps gM from js2, but allows raw text to supercede
4285 $.wikiEditor.autoMsg = function( object, property ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1157,9 +1157,38 @@
11581158 $.wikiEditor = {
11591159 'modules': {},
11601160 'instances': [],
1161 - 'supportedBrowsers': {
1162 - 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
1163 - 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
 1161+ /**
 1162+ * For each browser name, an array of conditions that must be met are supplied in [operaton, value] form where
 1163+ * operation is a string containing a JavaScript compatible binary operator and value is either a number to be
 1164+ * compared with $.browser.versionNumber or a string to be compared with $.browser.version
 1165+ */
 1166+ 'browsers': {
 1167+ 'ltr': {
 1168+ 'msie': [['>=', 7]],
 1169+ 'firefox': [
 1170+ ['>=', 2],
 1171+ ['!=', '2.0'],
 1172+ ['!=', '2.0.0.1'],
 1173+ ['!=', '2.0.0.2'],
 1174+ ['!=', '2.0.0.3'],
 1175+ ['!=', '2.0.0.4']
 1176+ ],
 1177+ 'opera': [['>=', 9.6]],
 1178+ 'safari': [['>=', 3.1]]
 1179+ },
 1180+ 'rtl': {
 1181+ 'msie': [['>=', 8]],
 1182+ 'firefox': [
 1183+ ['>=', 2],
 1184+ ['!=', '2.0'],
 1185+ ['!=', '2.0.0.1'],
 1186+ ['!=', '2.0.0.2'],
 1187+ ['!=', '2.0.0.3'],
 1188+ ['!=', '2.0.0.4']
 1189+ ],
 1190+ 'opera': [['>=', 9.6]],
 1191+ 'safari': [['>=', 3.1]]
 1192+ }
11641193 },
11651194 /**
11661195 * Path to images - this is a bit messy, and it would need to change if
@@ -1170,14 +1199,28 @@
11711200 };
11721201
11731202 $.wikiEditor.isSupportKnown = function() {
1174 - return ( function( supportedBrowsers ) {
1175 - return $.browser.name in supportedBrowsers;
1176 - } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 1203+ return $.browser.name in $.wikiEditor.browsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'];
11771204 };
11781205 $.wikiEditor.isSupported = function() {
1179 - return ( function( supportedBrowsers ) {
1180 - return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
1181 - } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 1206+ if ( !$.wikiEditor.isSupportKnown ) {
 1207+ // Assume good faith :)
 1208+ return true;
 1209+ }
 1210+ var browser = $.wikiEditor.browsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'][$.browser.name];
 1211+ for ( condition in browser ) {
 1212+ var op = browser[condition][0];
 1213+ var val = browser[condition][1];
 1214+ if ( typeof val == 'string' ) {
 1215+ if ( !( eval( '$.browser.version' + op + '"' + val + '"' ) ) ) {
 1216+ return false;
 1217+ }
 1218+ } else if ( typeof val == 'number' ) {
 1219+ if ( !( eval( '$.browser.versionNumber' + op + val ) ) ) {
 1220+ return false;
 1221+ }
 1222+ }
 1223+ }
 1224+ return true;
11821225 };
11831226 // Wraps gM from js2, but allows raw text to supercede
11841227 $.wikiEditor.autoMsg = function( object, property ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -78,7 +78,9 @@
7979 return this.each(function(){if(this.selectionStart||this.selectionStart=='0'){var scroll=getCaretScrollPosition(this);if(force||scroll<$(this).scrollTop()||scroll>$(this).scrollTop()+$(this).height())
8080 $(this).scrollTop(scroll);}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();var pos=$(this).getCaretPosition();var oldScrollTop=this.scrollTop;range.moveToElementText(this);range.collapse();range.move('character',pos+1);range.select();if(this.scrollTop!=oldScrollTop)
8181 this.scrollTop+=range.offsetTop;else if(force){range.move('character',-1);range.select();}}
82 -$(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'supportedBrowsers':{'ltr':{'msie':7,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1},'rtl':{'msie':8,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1}},imgPath:wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/'};$.wikiEditor.isSupportKnown=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers;})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.isSupported=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers&&$.browser.versionNumber>=supportedBrowsers[$.browser.name];})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.autoMsg=function(object,property){if(typeof property=='object'){for(i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
 82+$(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'browsers':{'ltr':{'msie':[['>=',7]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',3.1]]},'rtl':{'msie':[['>=',8]],'firefox':[['>=',2],['!=','2.0'],['!=','2.0.0.1'],['!=','2.0.0.2'],['!=','2.0.0.3'],['!=','2.0.0.4']],'opera':[['>=',9.6]],'safari':[['>=',3.1]]}},imgPath:wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/'};$.wikiEditor.isSupportKnown=function(){return $.browser.name in $.wikiEditor.browsers[$('body.rtl').size()?'rtl':'ltr'];};$.wikiEditor.isSupported=function(){if(!$.wikiEditor.isSupportKnown){return true;}
 83+var browser=$.wikiEditor.browsers[$('body.rtl').size()?'rtl':'ltr'][$.browser.name];for(condition in browser){var op=browser[condition][0];var val=browser[condition][1];if(typeof val=='string'){if(!(eval('$.browser.version'+op+'"'+val+'"'))){return false;}}else if(typeof val=='number'){if(!(eval('$.browser.versionNumber'+op+val))){return false;}}}
 84+return true;};$.wikiEditor.autoMsg=function(object,property){if(typeof property=='object'){for(i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
8385 if(property in object){return object[property];}else if(property+'Msg'in object){return gM(object[property+'Msg']);}else{return'';}};$.wikiEditor.fixOperaBrokenness=function(s){if(typeof $.isOperaBroken=='undefined'&&$.wikiEditor.instances.length>0){var div=$('<div />').height(0).width(0).insertBefore($.wikiEditor.instances[0]);var textarea=$('<textarea />').height(0).appendTo(div).val("foo\r\nbar");var index=textarea.val().indexOf('bar');textarea.select();textarea.setSelection(index,index+3);textarea.encapsulateSelection('','BAR','',false,true);if(textarea.val().substr(-1)=='R')
8486 $.isOperaBroken=false;else
8587 $.isOperaBroken=true;div.remove();}

Follow-up revisions

RevisionCommit summaryAuthorDate
r57719wmf-deployment: Merge babaco fixes from trunk...catrope20:20, 14 October 2009

Status & tagging log