Jump to content

MediaWiki talk:Common.js/Archive 6

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Shadowbot3 (talk | contribs) at 01:15, 13 June 2007 (Automated archival of 2 sections from MediaWiki talk:Common.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Hello, i'd like to change our current star icon at es:Plantilla:Destacado (it's a big bronze star) for the small yellow star used for the same porpouse at the French and English wikipedia. Could someone help me? I Post this at the template's discussion, and an librarian told me to come here. Thank you!--Fernandopascullo 19:30, 2 May 2007 (UTC)[reply]

Well, the section how does it work pretty much explains how {{Link FA}} works here. You have it slightly differently in es:MediaWiki:Monobook.js: your function LinkFA() directly specifies image. You could just change it to /media/wikipedia/en/d/d4/Monobook-bullet-star.png (). Or even better, do it the way it works here. Alex Smotrov 20:25, 2 May 2007 (UTC)[reply]

Enhancements to importScript

I'm interested in seeing the following enhancements made to importScript():

  1. Ability to specify base server name
  2. Ability to specify specific script revision with oldid

I've seen something like the first one in place at ru:MediaWiki:Common.js. I haven't seen the second one, but I think it would be useful to let users stick with a known-good version of a script. For example, I currently have copies of User:Lupin/popups.js and User:Zocky/PicturePopups.js in my own userspace because I've been burnt by upgrades to scripts and prefer to stick with a known version and not be forcibly upgraded. If I could easily pull in a script using oldid, I wouldn't have this problem.

Here are my proposed versions of importScript() and importStylesheet():

function importScript( page, options ) {
    if( importedScripts[page] ) {
        return;
    }
    if (!options) options = {};
    importedScripts[page] = true;
    var server = '';
    if (options.server) {
        server = "http://" + options.server;
    }
    var url = server + wgScriptPath
            + '/index.php?title='
            + encodeURIComponent( page.replace( ' ', '_' ) )
            + '&action=raw&ctype=text/javascript';
    if (options.oldid) {
        url += "&oldid=" + encodeURIComponent(options.oldid);
    }
    var scriptElem = document.createElement( 'script' );
    scriptElem.setAttribute( 'src' , url );
    scriptElem.setAttribute( 'type' , 'text/javascript' );
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}

function importStylesheet( page, options ) {
    if (!options) options = {};
    var server = '';
    if (options.server) {
        server = "http://" + options.server;
    }
    var url = server + wgScriptPath
              + '/index.php?title='
              + encodeURIComponent( page.replace( ' ', '_' ) )
              + '&action=raw&ctype=text/css';
    if (options.oldid) {
        url += "&oldid=" + encodeURIComponent(options.oldid);
    }
    var sheet = '@import "' + url + '";';
    var styleElem = document.createElement( 'style' );
    styleElem.setAttribute( 'type' , 'text/css' );
    styleElem.appendChild( document.createTextNode( sheet ) );
    document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}

The Russian version takes a single "lang" parameter instead of a hash of options, but I figured that using "server" would be more accomodating to hosting scripts on Meta or Commons, since they are under wikimedia.org, not wikipedia.org. Plus, I needed it to take a hash to support both "server" and "oldid". It would be pretty easy to support both "server" and "lang", but I didn't really see the point. The code would look something like this:

    if (options.server) {
        server = "http://" + options.server;
    } else if (options.lang) {
        server = wgServer.replace("\\b" + wgContentLanguage + "\\b", options.lang);
        // server = "http://" + options.lang + ".wikipedia.org";
    }

What do people think of doing this? I think that it would improve the ability to reuse scripts across multiple Wikimedia projects, especially if combined with an internationalization library like the one I'm playing around with here. Mike Dillon 00:36, 7 May 2007 (UTC)[reply]

It might be worth adding support for the "smaxage" parameter here as well. Mike Dillon 15:34, 9 May 2007 (UTC)[reply]

JavaScript version of MediaWiki:Edittools

Please contribute to the discussion of a JavaScript version of MediaWiki:Edittools at MediaWiki talk:Edittools#Request. If there is agreement to move in this direction, the code will have to be moved to MediaWiki:Edittools.js or some such and imported from MediaWiki:Common.js. Mike Dillon 05:35, 9 May 2007 (UTC)[reply]