Wikipedia talk:WikiProject User scripts

From Wikipedia, the free encyclopedia

To-do list for Wikipedia:WikiProject User scripts:
  • Create a "bare bones" monobook script that is standardized, easy to read, well commented, and based on functions.
  • Create a list of functions that will interact well with the standard.
  • Test for incompatible user scripts and note this in the scripts list



Contents

[edit] Recommendation

Which monobook would recommend for a firefox user? --Nemissimo 09:52, 18 September 2007 (UTC)

It's not like there are only a few combinations of scripts you're allowed; you can have as many or few of the scripts here that you like. My recommendation is that you look through our scripts list and install all the scripts that you think you will find useful. (Which ones are useful for you will depend on your editing pattern.) --ais523 16:28, 18 September 2007 (UTC)

<:: If you want a whole bunch of scripts at once, try installing User:Pyrospirit/scriptpackage.js. It contains 20 various scripts all in one page, with editing, tagging, interface, meta-data and anti-vandalism scripts. The individual scripts it uses can be found in this WikiProject. However, if you want more customized scripts, just look around and find which ones look useful. I'd personally recommend wikEd and Twinkle. Pyrospirit (talk · contribs) 19:47, 14 October 2007 (UTC)

Yep. 69.143.226.129 (talk) 09:57, 4 March 2008 (UTC)

[edit] Scripts misread by MediaWiki

I've noticed quite a few cases of scripts not taking into account MediaWiki's interpretation of the script. See Special:Whatlinkshere/" + target + " for what I mean. Since I'm not an admin, I can't do anything about those, but someone should really fix these things with <nowiki> tags or changing "[[" to "[" + "[" and such. Pyrospirit (talk · contribs) 19:59, 14 October 2007 (UTC)

Yes, Whatlinkshere and categories "count" .js and .css pages as well. Yes, if the script was unintentonally added to a category it should be fixed. But I don't see a big problem with Whatlinkshere cases ∴ Alex Smotrov 23:37, 14 October 2007 (UTC)
Perhaps MediaWiki needs to be changed in such a way that only comments can get interpreted like that. Shinobu 16:21, 4 November 2007 (UTC)

[edit] New version of hidePane.js

Good news for those of us who have limited screen real estate, or who simply like to use it more efficiently. I've updated User:Gerbrant/hidePane.js - instead of the ugly (although functional) gutter on the left hand side it now shows a series of pull down menu's at the top. This is also useful if you are primarly a Wikipedia reader, since all the space used by the left pane that contains the navigation, interaction, etc. portlets will be available for the actual article content. Of course the downside is that actions that normally take one click, now require you to open the appropriate menu. Perhaps in the future I'll add a way to active the most commonly used menu items in one click. Compatible with Safari (although wrapping doesn't work, but that's not my fault), IE and Firefox. If you have any feedback, please let me know. Shinobu 04:51, 4 November 2007 (UTC)

[edit] Regarding the to-do list...

  • Create a "bare bones" monobook script that is standardized, easy to read, well commented, and based on functions.
    What does this mean? A bare bones monobook script would be an empty script without anything, functions or ortherwise, in it, no? In the end, what scripts you want to use depends on your taste and needs.
  • Create a list of functions that will interact well with the standard.
    What standard? Monobook? I expect almost all scripts will work well on monobook, since almost everyone is using that.
    Last time I checked this was a while ago, so I'm not sure if this is still true, but in some other skins a script written for Monobook couldn't find HTML elements because they were for example called differently. It is often easier to simply customise monobook, then you're also certain all your scripts keep working, and you don't have to update your js and css.
  • Test for incompatible user scripts and note this in the scripts list.
    That would be useful, but it would also entail a lot of work. Since it isn't like user scripts are extremely popular, the payoff will be small. Perhaps it's better to kindly ask people trying scripts to note any incompatibilities they encouter, but even then I don't really see the benefit. Most of the time someone encountering an error in a script will contact the writer of the script to have it fixed. Shinobu 18:44, 4 November 2007 (UTC)

[edit] Updated edit top script

Gerbrant.edit.top has been updated; I hope I didn't break anything. I fixed a bug, tried to make it more robust and also gave it a minor facelift. Shinobu 13:26, 12 November 2007 (UTC)

Still, I don't really need [edit] link on pages that I cannot edit. Why don't you admit that checking for existing [edit] link is a better idea? :) ∴ AlexSm 18:24, 12 November 2007 (UTC)

Admit? It isn't like I ever denied it. :-) But your script doesn't seem to show an [edit] link for pages containing only the introduction. An [edit] link on such pages may be superfluous for most users, but it's still inconsistent. To solve this, you would need no have some extra checks in the case no existing [edit] link is found, not unlike mine. I do think your solution is more elegant, but for my needs my version works better, even if it is ugly. Shinobu 07:19, 13 November 2007 (UTC)

[edit] AfDsorting script help?

I'm working on a script to add a sort link to the top of the edit page for Articles for Deletion. When editing such an article, the sort button asks for a category code and a reason for sorting (sorting as whatever), then produces the appropriate template and code, adds the reason to the edit summary, and submits the edit. I've based it on Digitalme's AIV Helper, paring down the function to just one button.

However, three problems exist. First, I can't get it to automatically take the single-letter code for the category (per CAT:AFD and generate an automatic edit summary. Second, the sorting template (REMOVE WHEN CLOSING THIS AFD) is generally placed on the second line, under the heading for the debate. I can't get the script to place the template anywhere other than the end of the page. This means that the existing template must be deleted by hand. Third, I don't know how to have the script remove any existing sorting templates (such as nominator unsure, for example). The script in its current form may be found here. Thanks in advance for any advice you can provide. ZZ Claims ~ Evidence 20:16, 15 November 2007 (UTC)

If this request goes elsewhere, please let me know. Thanks! ZZ Claims ~ Evidence 20:17, 15 November 2007 (UTC)

In order to add things to the right point in t.value, you have to come up with a rule to decide where to add the tag. In this case, I'd suggest adding the tag after the second occurrence of ===, which I'd do like this:
if(t.value.split("===").length>=3)
{
  var a=t.value.split("===");
  a[2]="\nTEXT TO ADD HERE"+a[2];
  t.value=a.join("===");
}
There are several ways to do this in JavaScript, though; the split/join is the method that I normally use, but other people use different methods.
As for removing a previous tag, this method comes directly from the source code of User:Bot523, modified to fit into code which uses the same variable names as Digitalme's code:
t.value=t.value.split("{{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD|").join("{{ns:0|");
({{ns:0}} is a magic word that always expands to the null string.) Come to think of it, {{subst:ns:0}} would possibly work even better, so as to remove the template altogether on page save. There are also methods which parse the page's wikimarkup to remove the template.
As for changing the edit summary, with the variable names that Digitalme's code uses, that's just f.wpSummary.value, which you can set to whatever you like to change the edit summary. Hope that helps! --ais523 13:26, 16 November 2007 (UTC)
Please doublecheck me, but based on your input, I think I have it working properly. I still can't get the edit summary to reflect the code input, so I simplified it to a generic "sorting per CAT:AFD" note. Thanks for your assistance! I've put together instructions and notes on the script here, and the completed (hopefully) code is here. Again, Thanks! ZZ Claims ~ Evidence 16:01, 16 November 2007 (UTC)
In its current form, it adds a line between the heading and the debate itself. I can accept this, even though I'm sure it's easily fixable and I'm missing something. ZZ Claims ~ Evidence 18:04, 16 November 2007 (UTC)
What seems to be happening is that both the newline before and the newline after the {{REMOVE THIS TEMPLATE... line are being preserved. Try writing \n just before the opening {{ inside each of your split-strings; that will cause the initial newline to also be deleted, getting rid of the extra space. --ais523 14:30, 19 November 2007 (UTC)
I figured it out - I needed to add both an /n for the new line and a /r for the carriage return. It's fixed and working well. I've also added a second script that removes the sort template entirely. I've been using that one to remove the sort template from closed debates, to take them out of the categories used for the open debates. Thanks again for the help! The scripts may be found here. UltraExactZZ Claims ~ Evidence 21:15, 28 December 2007 (UTC)

[edit] Adding user scripts to Special:Preferences

One of the problems that WP:US faces at the moment is that it isn't as widely known as maybe it ought to be, and that the method of installing scripts isn't intuitive and involves editing a personal scripts page, even if the user in question doesn't have an interest in developing scripts but only wanted to use them. Advances like {{subst:js}} are only so effective in this regard; but now, it seems that a better option is available. There is an extension mw:Extension:Gadgets that adds user scripts stored in MediaWiki: space as options in Special:Preferences; that way, we can have several users (probably mostly WP:US members, although there would be no reason to restrict the people who could check) check various scripts to see if they were safe to add as user preferences, and then an admin could edit MediaWiki space accordingly to add the script as a preference that users could easily access, install and uninstall, a sort of WP:US/S that's officially sanctioned by the software. Normally, this sort of project is the sort of thing that just gathers a bit of support on WP:VPR and then dies because nobody wants to implement it; however, the code has already been written, and reviewed by developers, and it is currently live on the German Wikipedia (if you have an account on dewiki, go to de:Special:Preferences and click on the rightmost tab to see the new code in action). This makes it seem much more likely that if their is community consensus, that extension will be installed. At the moment, I'm just posting this suggestion here, to see if people interested in user scripts think that this is a good idea; if the conversation here seems encouraging, I'll link it from VPR and we can have a proper attempt to gain consensus here to make a request to devs to enable this feature. Does anyone else think this is a good (or bad) idea? I'm trying to gauge consensus, so even a 'me too' is useful here if you agree. --ais523 14:39, 19 November 2007 (UTC)

Strong support from me. Slightly better link: [../../../../../de/articles/p/r/e/Special%7EPreferences_a6b2.html de:Special:Preferences?uselang=en]. Relevant bugs: mediazilla:11956 (done for de.wp) and mediazilla:12020 (done for fr.wp). The only thing I don't like is that Gadget code is included after user code, which is kind of limits the flexibility for CSS gadgets ∴ AlexSm 16:54, 19 November 2007 (UTC)
I suppose that it might sometimes be possible to override that using !important, but I agree that it isn't ideal. It's still a big improvement over the edit-your-monobook method, though. --ais523 10:46, 20 November 2007 (UTC)
I'll copy this to VPR in an attempt to get enough consensus for the devs, then. --ais523 12:09, 21 November 2007 (UTC)

[edit] Stub types script

Hi, I have a script installed (I'm pretty sure it was written by ais523) that easily allows me to add in a stub type simply by typing in the name of it. Anyway, what I would like to add to it (maybe I would only use it, or maybe it would be helpful to others) is a dropdown box with some stub types so that I don't have to keep typing the same ones in over and over. I can add in the types myself, I would just like to know how to add in the dropdown box. Thanks   jj137 (Talk) 17:44, 23 November 2007 (UTC)

Yes, I noticed you post this on WP:US/R. It's not very easy to do, though; the dialog box that appears can't be modified at all in code, so it would have to be done a different way. Should be possible, though. --ais523 17:46, 23 November 2007 (UTC)
OK. (I forgot I posted it there, I guess I was thinking I forgot to hit Save.) I have a somewhat basic understanding of this, so I'll work around with it and see what I can do.   jj137 (Talk) 18:05, 23 November 2007 (UTC)

[edit] Gadgets extension now live

It's now possible to add scripts to Special:Preferences (navigation popups is already there). I've started a new page at Wikipedia:WikiProject User scripts/Gadgets to try to decide which scripts should or should not be added (I know most about my own scripts, so they currently have some of the most detailed comments). Anyone who sees this, feel free to help reject/accept/test the scripts on the list! --ais523 09:20, 4 December 2007 (UTC)

[edit] Turn off scripts?

Is there an area an admin can edit other than monobook.js that prevents a user from using a particular script? I'm curious as I have suddenly and mysteriously lost all Twinkle functions without any kind of warning or reasoning (ie: no admin has told me and no changes have been made to the way my Firefox is setup that would prevent only 1 out of the several scripts I use from working). So, at the risk of offending admins, I want to know if this is possible and the admin that may have done this didn't tell me? -- ALLSTARecho 13:53, 20 December 2007 (UTC)

Try going to your monobook and refreshing the page or purging.   jj137 20:43, 20 December 2007 (UTC)
I've done that already but thanks. -- ALLSTARecho 21:59, 20 December 2007 (UTC)
On some browsers, Twinkle is affected by a race condition in runOnloadHook() - see WT:TW for more information and a workaround. —Random832 18:40, 1 February 2008 (UTC)

[edit] Bot

Hi. I have created around 14,000 articles on wikipedia, higher than anybody, and am currently adding Frebnch communes at bot speed around 6 a minute and have requested that my new articles are automatically filtered but noone seems to be concerned. I have addressed this to several people but no one has taken it seriously when I said I was concerned about clogging up new pages even when I am adding general content. I refused adminship long ago but surely I am respected enough to be regarded as admin level in editing. I always add valuable content and most of my articles are referenced except such stubs. Isn't it time somebody made a decision to help new page patrollers by helping them. I;ve contributed tens times more than many adminstrators on wikipedia (107,000 edits) who automatically have their page unmarked -shouldn't mine be the same on a permanent basis? I consistenly add new content to wikipedia which is generally referenced and useful content. Deforestation in Brazil is what I am capable of. It would help patollers a lot. Any idea if you can help me receive permanent clearance? ♦ Sir Blofeld ♦ Talk? 23:00, 29 January 2008 (UTC)

I'm not sure I get your point, Sir. Are you requesting that your edits be filtered/unfiltered? Are you running a bot or are you manually editing at "6 a minute"? Note, that this project is about client-side JavaScript, perhaps you should post your request at the bots page. Btw, having admin rights has little to do with the quality or quantity of your edits. Cheers, --Cameltrader (talk) 12:12, 30 January 2008 (UTC)
You can request bot rights for an account (i.e. edits do not show on Recent Changes) for a specific task at WP:BRFA, whether you actually use a bot to do it or not. You should explain why the bot flag will be helpful, and create an alternate account to do the specific edits (because bot-flagged accounts should only be used for the purpose the flag was granted). By the way, administrator edits do show on Recent Changes, generally speaking; administrators can bot-flag rollbacks and the edits they roll back (this is rarely used, its main purpose is to prevent a Recent Changes flood attack) but no other sort of edit. --ais523 13:55, 1 February 2008 (UTC)

[edit] structured gadget pages

Halló! I created stuctured gadget pages via sections at s:yi: w:yi: wikt:yi:. During the first trials I used spaces in the sections. Then I could see that w:en: is using « - » while w:fr: does not. The clue is to define « MediaWiki:Gadget-section-foo-bar » . Maybe such examples should be illustrated.
btw: the structured gadget page at http://test.wikipedia.org/wiki/Special:Preferences is broken. Any clue why? Best regards
‫·‏לערי ריינהארט‏·‏T‏·‏m‏:‏Th‏·‏T‏·‏email me‏·‏‬ 09:25, 12 February 2008 (UTC)

I am not sure what you mean, but maybe Wikipedia:Gadget can help you. Сасусlе 02:04, 14 February 2008 (UTC)

[edit] Need help cleaning out my monobook.js

Would someone be willing to help me clean up monobook.js. I can't figure out what is what anymore. I don't know javascript, and I really didn't add things there neatly. I would like to use some of the tools made by others, but before I do, my monobook.js really needs to be cleaned up. Please? - LA @ 00:48, 25 February 2008 (UTC)

The scripts that you're importing can be simplified to this:
importScript('User:Interiot/Tool2/code.js');
importScript('User:Splarka/dabfinder.js');
importScript('User:Pilaf/instaview.js');
You have two scripts that aren't being imported, though (the null edit and template replace script). Cleaning those up will be harder. --ais523 14:44, 21 April 2008 (UTC)

[edit] watchlistSorter

I have just created a new watchlistSorter because the existing one no longer works. I think this could become an gadget candidate and I would like to hear your opinion to improve the script. See the script's page under User:Cacycle/watchlistSorter and the code under User:Cacycle/watchlistSorter.js. Сасусlе 05:45, 25 February 2008 (UTC)

[edit] Disappearing AfD tab?

Hi, could someone advise on my monobook page? It has been working fine with the extra tabs from Twinkle up until I got my extra admin buttons. Now there doesn't seem to be enough room at the top of the page and on many page views, the AfD tab is missing. It does appear on some pages (when not all the other tabs are present) and also on some other monitors I use; but on my home monitor (a small one set to 1024 x 768 pixels) the AfD tab is almost always missing. I'm a total beginner when it comes to all this business, so advice in words of one syllable, please! Kim Dent-Brown (Talk) 20:57, 27 February 2008 (UTC)

[edit] Smart quotes script

Attention all pedants, I made a script. smartQuotes.js replaces typewriter (ASCII) quotation marks with proper (Unicode) quotation marks ("smart quotes", see quotation mark glyphs) on any page you view. For example:

The Smashing Pumpkins’ Billy Corgan described Surfer Rosa as “the one that made me go, ‘holy shit’. It was so fresh. It rocked without being lame.”

The Smashing Pumpkins’ Billy Corgan described Surfer Rosa as “the one that made me go, ‘holy shit’. It was so fresh. It rocked without being lame.”

This script will not affect the editing window, so you won't need to worry about tainting your edits with odd glyphs. I know this is irrelevant to pretty much everyone (there is no difference whatsoever at small sizes if you're using Arial), but for the oddballs like me (who use serif fonts and aren't getting laid) it's available. If you're ever printing out a Wikipedia article for academic usage or something, you might consider applying this script for that extra professional touch.

I've only tested this in Firefox 2.0. It may or may not work in any other browsers.—Werson (talk) 03:48, 27 March 2008 (UTC)

[edit] "Replaced by addPortletLink" help

Hello. Recently, whenever I go to a page, I am greeted by a JavaScript alert which says: "Replaced by addPortletLink". Could someone help me with this problem? Thanks! archanamiya · talk 21:10, 4 April 2008 (UTC)

See Wikipedia:Village pump (technical)#Strange error - "Replaced by addPortletLink()" --TheDJ (talkcontribs) 21:51, 4 April 2008 (UTC)

[edit] Link checker in JSON

I've extend the my checklinks script to output its results in JSON and created a reference JavaScript implementation. It also output the headers it retrieves, which could be useful for some scripts. — Dispenser 00:51, 20 April 2008 (UTC)

[edit] red link removal

I found that red link removal is cumbersome when dealing with more than three bad links in a very big section would someone make a script for me that would delete a bad link by hovering the mouse over the link.Hintss (talk)

[edit] Suggestion to avoid script incompatibility

I discovered a while back that scripts on Wikipedia have the rather annoying property that function names and global variables are shared between any scripts that run on the same page. This can often cause incompatibilities between scripts, such as where one script defines a global variable and another script uses a global variable of the same name as a user-defined setting; in such a case, the second script would use—and possibly change—the first script's value for the global variable, likely crashing one or both scripts. I ran into a version of this issue when one of my scripts stopped working after I installed another script, the reason being that they both had a function named loadXMLDoc.

What I suggest is that user scripts under this project include a global wrapper function around the script's functions and variables to avoid situations like this. Doing so would make the script's contents local to that one script and thus protected from unintentional access by another script.

To give an example, if there was a script named foo.js, it might look like this:

if ( typeof ( FooScriptVariable ) === 'undefined' ) {
    var FooScriptVariable = 'default value';
}
function FooScript () {
    var foo = FooScriptVariable;
    function bar (baz) {
        // some code here
    }
    function spam () {
        // more code
    }
    addOnloadHook(spam);
}
FooScript();

The nice thing about this construction is that only FooScriptVariable and FooScript are in the global scope, but variable names inside the FooScript function can be as common or short as you want to make them; it eliminates the need to ensure that there are no naming conflicts. For a more detailed example of a script structured like this, see recent versions of User:Pyrospirit/metadata.js, which I just rewrote using this method.

So, does this seem like a good idea for more frequent use, or is there something that I've missed or doesn't work the way I think it does? This might be a good way of making Wikipedia script structure more standardized as well. Pyrospirit (talk · contribs) 02:07, 5 June 2008 (UTC)

You could save one global object by using an anonymous function:
(function(){
    var foo = FooScriptVariable;
    function bar (baz) {
        // some code here
    }
    function spam () {
        // more code
    }
    addOnloadHook(spam);
})();
Or you could enclose everything in an object, and again take only one global:
var FooScript = {
    foo : 'default value',
 
    bar : function (baz) {
        // some code here
    },
 
    spam : function () {
        // more code
    }
};
if ( typeof ( FooScriptVariable ) != 'undefined' ) {
    FooScript.foo = 'default value';
    // Alternatively, if you can move the setting of "FooScriptVariable" to after
    // the include of this script, you could just set FooScript.foo directly.
}
if(doneOnloadHook) FooScript.spam();
else addOnloadHook(FooScript.spam);
Anomie 00:32, 6 June 2008 (UTC)
That's an interesting idea. However, I'm not sure it would be necessary to minimize globals that much; the idea is just to avoid spamming up the global namespace and to allow variables inside a script to have simple, common names such as color or text. Your suggestion does look like it would work as an alternative, though. Pyrospirit (talk · contribs) 00:40, 6 June 2008 (UTC)