Jump to content

MediaWiki talk:Common.js

Page contents not supported in other languages.
Add topic
From Wikipedia!
Latest comment: 17 years ago by Splarka in topic Dynamic import for testing, proposed

13232 discussion

[edit]
archived to history (aka deleted)

Dynamic import for testing, proposed

[edit]

Edit this source box, no need to create more (history is always available)

/* Dynamic import module 

- needs some instructions
*/
addOnloadHook(function() {
  var obj, scripts = []
  if (document.URL.indexOf('testjs=') > 0){
     if (obj=queryString('testjs='))
       scripts = obj.split('|')
  }else if (obj=document.getElementById('testjs')){
    scripts = obj.className.split(' ')
  }
  for (var i=0; i<scripts.length; i++) importScript('MediaWiki:Common.js/' + scripts[i] + '.js')
})
 
function queryString(p) {
  var matches = document.location.href.match(RegExp('[&?]' + p + '=([^&]*)'))
  if (matches)
    try { 
      return decodeURI(matches[1])
    } catch (e) { }
  return null
}

Discussion

[edit]

Should the URI parameters always overwrite the local divs? should they work in tandem? It might be useful to overwrite local scripts with ?loadjstest= Splarka (talk) 22:52, 11 June 2008 (UTC)Reply

"Always overwrite" makes sense to me. —AlexSm 03:58, 12 June 2008 (UTC)Reply

Although the original idea was mine, now I have doubts if we really need this and if it's really worth making the site a little less secure: for the code changes we'd have to watch the whole MediaWiki namespace, not just Common.js and Monobook.js. —AlexSm 19:50, 27 June 2008 (UTC)Reply

On the other hand, Commons admins already implemented a very similar thing (see commons:MediaWiki:Common.js: withJS parameter), so I guess it's okay for testwiki as well :) —AlexSm 16:27, 30 June 2008 (UTC)Reply
It sure would be nice if en.wp had this much discussion before changes to common.js/css. Go ahead and add it (here that is). ^_^ Splarka (talk) 07:03, 1 July 2008 (UTC)Reply

Okay, do you mind if I change the code to the following? indexOf is to minimize execution time on 99% of pages, testjs is for simplicity, extra semicolons removed. P.S. Wasn't that supposed to be decodeURIComponent()? —AlexSm 16:29, 1 July 2008 (UTC)Reply

(moved up)

Well, as long as it works. The other queryString() function has had rigorous testing for years though and I've never seen any problems with it. (And re decodeURIComponent(), maybe? I just copied it from somewhere back before I knew javascript, I've never really dissected it, I just use it). Splarka (talk) 07:09, 2 July 2008 (UTC)Reply