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 14:36, 16 June 2007 (Automated archival of 4 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]

Audio pop-ups

We have an {{audio}} template for inline audio clips:

'''Bordeaux''' ({{Audio|Fr-Bordeaux.ogg|pronunciation}}) is a [[Seaport|port]] city in...

gives this:

Bordeaux (Audio file "Fr-Bordeaux.ogg" not found) is a port city in...
What the new version looks like in Firefox

A lot of people think the extra links are cluttery, but they're necessary for newcomers. I proposed that the links be removed with javascript and put in a pop-up instead. I don't know enough about javascript to write more than a mock-up, though. Could someone else finish this and deploy it site-wide?

When we finally get inline java players, the player could be inside the pop-up, too? — Omegatron 18:24, 28 April 2007 (UTC)[reply]

Yes, I agree with this new JavaScript. Count me in. --Steinninn 10:19, 6 May 2007 (UTC)[reply]
That's an interesting script, but it seems like it would be more appropriate as a user script than as a site-wide thing. What more do you think needs to be changed for it to be usable? I'd assume it needs some more cross-browser testing to deal with weird layout/margin issues. Also, I'd suggest requesting that some extra spans with their own distinct classes be added to {{audio}} to simplify some of the more fragile parts of the code relating to extracting and moving the "help" and "info" links (i.e. spans that contain only the help and info links respectively). Mike Dillon 02:42, 8 May 2007 (UTC)[reply]
I think it's more appropriate as a site-wide thing. There are numerous complaints about the help and info links cluttering up articles, but there's really no way around them. We need to link to the help so that people can open ogg files, and we need to link to the description for copyright reasons and to find out more details about the audio sample.
The things that still need work: cross-browser, not extending past the edge of the browser window, not obstructing the original link, the timing with which it opens and closes and whether you're hovering over it, etc. etc. Just needs to be tweaked to work really nicely.
Agreed about the spans. I used class audiolink and audiolinkinfo, but they might be better in another place, etc. If the audio template is ever changed, it would break the javascript. The javascript should test to see whether the audio template has been changed, and if it has, do nothing, so that it degrades gracefully. — Omegatron 16:17, 12 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]

PROPOSAL: Adding New Java Script Code to Wikipedia

How can I request that new Java Script code be added to Wikipedia by an Administrator? The code would allow for entries in a Table/Chart to be autonumbered ... much like entries in a simple List can be autonumbered with the # symbol. Please advise. Thanks. (JosephASpadaro 03:57, 12 May 2007 (UTC))[reply]

Just propose it below on this page :-) —METS501 (talk) 13:58, 12 May 2007 (UTC)[reply]
While Joseph was discussing this with me, I wrote the code he wanted at User:Mike Dillon/Scripts/autonumber.js. It basically detects tables with class="autonumber" and adds a new cell to each row to create a column of automatic numbers. It's currently a little Monobook-specific in that it relies on the presence of "bodyContent" and I think we'd need to see a consensus for adding the feature somewhere before adding it site-wide. I've deployed similar code on another wiki and it works in Firefox and Internet Explorer. One thing that is weird about it is that you can't currently make an autonumbered table where the synthetic column is sortable because of a timing issue with the sortable code and onload hooks.
For what it's worth, I don't see this addition being worthwhile for Wikipedia, but I posted the code since I had already written it. Mike Dillon 15:01, 12 May 2007 (UTC)[reply]