Wikipedia talk:WikiProject User scripts/Archive 5
![]() | This is an archive of past discussions. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
DOMParser problems
Continuing this discussion. When HTML 5 was enabled for 24 hours last week, all scripts using DOMParser to parse results returned by invoking index.php failed, to the best of my knowledge. HTML 5 is about to be re-enabled, which will kill everyone again. A massive rewrite of Twinkle is in progress. . AlexSm seems to have said that it's not really a problem. I don't understand this statement, so I'm posting here. All of my research shows that DOMParser is fundamentally incompatible with HTML 5. Furthermore, the Wikipedia developers have been telling everyone to use api.php exclusively for many years and their tolerance for non-compliance appears to be down to zero. Also, see my related post on JavaScript deprecations. —UncleDouggie (talk) 08:56, 1 March 2011 (UTC)
- This is the message that I had problems with. The thing is, using index.php ≠ using Dom Parser. Fetching the whole HTML page and then using Dom Parser was a problem, not using index.php per se. Thus switching to HTML5 will not automatically break all the scripts that make requests to index.php (WikEd comes to mind here). Some parameters (action=raw / action=render) can make index.php output specific data which doesn't even have the DOCTYPE. Having said that, I agree that it is much better to use API whenever possible and even the raw/render index.php parameters can now be replaced with API. — AlexSm 16:52, 1 March 2011 (UTC)
- As for XML statement, it was answered by Ale jrb. — AlexSm 16:52, 1 March 2011 (UTC)
- OK, but the vast majority of scripts that use index.php are retrieving and attempting to parse HTML. We need to make clear to users that this is all about to break, not give them false hope that their index.php code will somehow survive. I have referenced HTML in the majority of my comments, either directly, or in a preceding comment in the same section. —UncleDouggie (talk) 01:26, 2 March 2011 (UTC)
Replacing importScript()
importScript() has been deprecated in MediaWiki 1.17 and the developers have instructed us to transition to mw.loader.load(). I have tried this out for the Twinkle rewrite and it's been a disaster. I had to finally revert back to importScript(). I just want to save others the trouble of going down this painful road. Hopefully a lot of changes will be made before importScript() is removed. There are several related bug reports. My biggest issues are:
- It's impossible to debug scripts using Firefox/Firebug, even when setting debug=true to stop minification. Firebug isn't happy when scripts are appended to the body after the page is loaded as is done by mw.loader.load(). Opera can debug them, but it's very hard to select a particular script name and strange errors show up on the console.
- importScript() filters multiple requests for the same script, which are very common on en.wikipedia with all our various utility scripts. mw.loader.load() doesn't perform such filtering.
- mw.loader.load() will only minify registered modules and your top-level skin.js file. It won't minify user scripts. importScript() doesn't minify either, but the promise of minification was a big reason to consider switching to mw.loader.load().
- Loading a script that is in the browser cache takes twice as long with mw.loader.load() as it does with importScript(). It might be that the technique used by mw.loader.load() is somehow causing the cache to be bypassed.
- The god-awful syntax:
importScript('User:Foo/bar.js');
gets replaced bymw.loader.load(mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=User:Foo/bar.js&action=raw&ctype=text/javascript');
- While I could actually live with this in Twinkle if the other things worked, requiring this for all uses of importScript() on the project shows an utter disregard for usability.
- The almost non-existent documentation. I had to figure all this out by myself, including debugging into the MediaWiki scripts. The documentation only covers use of registered modules. User scripts seem to have been an afterthought.
If you've been dreaming of using mw.loader.using() to solve dependency issues between user scripts, sorry. mw.loader.using() can only be used for dependencies on registered modules such as jquery.ui.dialog. I've now solved all the dependency problems in the new Twinkle, but I had to write my own loader to do it. —UncleDouggie (talk) 11:17, 3 April 2011 (UTC)
Request
Hi. A question from a newby. Is it possible to have a function to be executed by a button? E.g. convert selected text to Lowercase? I tried to look around but I could not find anything. If so, can you give a short example of code? Mpaa (talk) 23:00, 5 May 2011 (UTC)
- Hi. Short answer is "yes". You'll need code to add the button to the loaded page then add an event listener to the button then code to run when the button is pressed causing the event to trigger. Since I have no idea how much a newby you are I suggest looking at other scripts that do basically the same thing. I have one written in pure JavaScript (not jQuery or shorthand of any kind) that follows this process. See User:Fred Gandt/getUnpatrolledOfAlexNewArtBotResultsPages.js. It is only one example and some might argue that it's not a good one but it's better than nthing
fredgandt 03:34, 20 November 2011 (UTC)
FileRedirect
Hello, I'm from Polish Wikipedia. I've made a very short script that redirects user from en.wiki File's page to its commons page, when it's hosted there. If it's hosted locally it doesn't redirect. To use it You should copy that (yes, with the first line, please – I'd be glad if I could know how many ppl uses that script:>).
//if viewing page of a File then redirect to commons; script from [[User:Vinne2/FileRedirect.js]]
importScript('User:Vinne2/FileRedirect.js')
Can You tell me where should I add information about that script? The structure of pages about script, tools and gadgets here is different from the one on pl.wiki, so I'm lost here. Vinne2 (talk) 15:24, 16 October 2011 (UTC)
Can anyone help...
I posted the following message to the Help Desk a day or two ago and I didn't get an answer. I was hoping maybe somebody here could help. Also, it would be preferable if you could respond on my talk page. Thanks.
- Hello, I've been starting to experiment with my skin .js pages and trying to modify other scripts for my own use (in my own userspace of course). During this process I keep on finding variables like wgScriptPath, #wpSummary, wgCanonicalNamespace, etc. While I've been able to figure out the basic meaning of those above, there are many others variables I can't find out about. These variables aren't defined anywhere in the script so my first guess was that they were MediaWiki global variables, or something like that. Can somebody please explain to me where I can find a listing and explanation of all these frequently occurring variables. Any help is very much appreciated, M Magister Scientatalk (20 November 2011)
- Ah yes that's probably more appropriate than the one below. This section is the right section. The note below about the namespace numbers still applies, though. I guess that page is fairly new (as in, less than five years or so), since I'm only familiar with the one below, which I probably last had to refer to a few years ago. I wish I had this new link to use as a reference back then, that's for sure. Also, this question that you posted at WP:HD is better suited for WP:VPT, so be sure to bookmark that or something for future reference when you need technical help. Gary King (talk · scripts) 03:24, 20 November 2011 (UTC)
- (edit conflict) This is probably the most appropriate page to explain this stuff. I know that it doesn't explicitly lay out what each variable means, but it shouldn't be too difficult to determine that. The example given there provides the information for that very page. Namespaces are unique to each wiki; the ones for Wikipedia are found here. If you have questions on specific variables, just ask here. Gary King (talk · scripts) 03:22, 20 November 2011 (UTC)
- Thanks both of you for all the information. Highly appreciated, M Magister Scientatalk (20 November 2011)
Scripts listing cleanup project
![](http://upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/20px-Yes_check.svg.png)
Wikipedia:WikiProject User scripts/Scripts is in dire need of cleanup. I've started Wikipedia:WikiProject User scripts/Scripts cleanup in order to hopefully get that rolling. If you know of scripts that are currently working, please list them in their appropriate sections on that page. If/when the list seems reasonably complete, we can deprecate the old page and move this one in (though keeping and linking to the old one as a more exhaustive list of all existing scripts). Please share any thoughts on this. Thanks. Equazcion (talk) 00:12, 25 Mar 2012 (UTC)
- Also if anyone has ideas for a better categorization format, feel free to suggest. Equazcion (talk) 01:08, 25 Mar 2012 (UTC)
redirects, modify its appearance
- hello. is there a script that can search a page for outgoing links to redirects and then modify its appearance, e.g. adding a name of the final target as a visible text after each redirect link? Tks Ling.Nut3 (talk) 08:33, 6 April 2012 (UTC)
- Not that I know of. However, you can change the appearance for redirects quite easily by adding to Special:MyPage/skin.css something like the following:
a.mw-redirect { color: green; }
- This should change the color of redirects to green. You could also add a border around the links instead, or a background color, etc. using CSS as well. ("border: green;", "background-color: green;") Gary King (talk · scripts) 19:15, 6 April 2012 (UTC)
- Thanks for your help! yeah, i already have the color-changing code (found elsewhere). I need the ability to display (on the page) the target of a redirect. In order to verify a large amount of data, I want to create a page that deliberatly has several hundred redirects. Then I want to run some sort of script or tool or add some sort of hard-coded link or something against that page that gives me the target of the redirect in plain text. In the end I want a table or something similar, listing 3 things: a label that I add, a redirect that I add, the actual target of the redirect given by script or tool or whatever.. If that doesn't make sense, I'm doing languages:
- I start with this:
- Alngith language | ISO 639:aid
- ... and some script or tool or link gives me this:
- Alngith language | ISO 639:aid | Alngith dialect
- I know there's no reason to fix valid redirects, but I suspect a small amount of the info I have is wildly invalid. I have already found Old Prussian in Indonesia, etc. So I would like to check everything I have in one fell swoop. Tks.Ling.Nut3 (talk) 01:52, 7 April 2012 (UTC)
- Are you just looking to convert ISO language codes to what the language name? It's not a script, but you could make use of Template:ConvertAbbrev. An example is
{{ConvertAbbrev|Languages|en}}
, which yields "{{ConvertAbbrev|Languages|en}}". It only works for ISO 639-1 and ISO 639-2, though, so it wouldn't work for your example above, which is only defined in 639-3.--Dudemanfellabra (talk) 02:56, 7 April 2012 (UTC)- Ah, thanks, that's helpful. I think I see what I can do. Tks! Ling.Nut3 (talk) 12:20, 7 April 2012 (UTC)
- Are you just looking to convert ISO language codes to what the language name? It's not a script, but you could make use of Template:ConvertAbbrev. An example is
Disabling of preference for wikieditor
A patch has been merged into mediawiki which removes the preference for enabling/disabling the WikiEditor and enables it for all by default. A discussion regarding this is ongoing at Wikipedia:Village_pump_(technical)#Disabling_of_preference_for_wikieditor. All users are requested to comment.--Siddhartha Ghai (talk) 08:21, 7 April 2012 (UTC)
New sources script
I'm pleased to announce that an improved user script targeted at fixing source names will go live on 1 December 2012.
I would also like to request beta-testers for the script, noting that it does not seem to even load on IE8. Any comments, suggestions and features requests will be most welcome. -- Ohconfucius ping / poke 03:59, 13 November 2012 (UTC)
Internet Explorer 8
A discussion in the Village pump you might be interested in: Wikipedia:Village pump (technical)#Internet Explorer 8.
New standards
I have been playing with user scripts and gadgets for few weeks, and notice some problems.
- Only a few of them are fully internationalized;
- If I see an interesting script and want to enable it on all wikis (Commons, Wiktionary, Wikipedia etc.) and all language versions, I have to manually edit every 'common.js' to do that;
- It's hard to search for user scripts, maybe I created some that already existed.
Thus, I propose some improvements:
- The scripts should be placed in the proper list or category;
- The scripts should be internationalized in a standard way, also with contributions by other users;
- The scripts should be designed to work unchanged within all wikis;
- The scripts should be uploaded only in a specific section (I suggest on Commons);
- Users should be able to enable any script globally and with one click, in the Preferences tab.
Please note that:
- The Preferences tab already hosts some gadgets, but should host (maybe separately) also 'unsigned' user scripts from all users
- There is already a standard way to internationalize the scripts, but to me it isn't well clear.
I don't know technical details, please answer. excuse for my bad English --Ricordisamoa (talk) 18:46, 17 January 2013 (UTC)
- update No replies here... I launched Wikimedia Scripts. --Ricordisamoa 20:32, 11 February 2013 (UTC)
Anyone out there using morebits.js?
If there is anyone out there whose scripts depend on morebits.js, I'd love to hear from you just so I know who (if anyone at all) has written scripts that need morebits.js in any way. Specifically, you might like to check out a notification of a minor breaking change to the library. — This, that, and the other (talk) 09:12, 6 February 2013 (UTC)