MediaWiki talk:Monobook.js
Please adhere to the Commons:JavaScript styleguide. |
Non-existing user page bug
[edit]The newly-added tabs don't appear when you view a user page that doesn't exist. The reason is that MediaWiki doesn't send a "delete" tab, so the get_sysop_status() function returns false. I don't know how to fix this bug in general. I've solved the problem for myself by adding
- function get_sysop_status() { return true; }
to the top of User:Dbenbenn/monobook.js. User:dbenbenn 08:31, 16 February 2006 (UTC)
- This bug is now fixed. See [1]. Arnomane 12:54, 17 February 2006 (UTC)
- I don't think that fixes the problem. (I tried commenting out the relevant line of my monobook.js, and now the tabs don't appear when I view nonexisting user pages.) The change looks for a "t-blockip" element. Do you have a "block" tab when viewing user pages? I don't. Maybe it has something to do with the interface language? I'm using English. User:dbenbenn 13:33, 17 February 2006 (UTC)
- Hm this is strange. I use German as preference but now I have changed the language to English and if I'm looking at the HTML code of the page User:Arnomane I can still find this line
<li id="t-blockip"><a href="/wiki/Special:Blockip/Arnomane">Block user</a></li>
- The block tab is at my interface in the left "tools" box. Luckily the fix by me does not make it worse if it fails IMHO and thus it still works in the other cases. Arnomane 14:05, 17 February 2006 (UTC)
- Oh, look at that, a "block user" link! My mistake. Note that the link doesn't appear for User:Arnomane/subpage or for User:Arnomanedoesnotexist. That's why I didn't see it before. User:dbenbenn 15:16, 17 February 2006 (UTC)
- Yes. In case of non existant sup pages or eg nonexistant discussion pages of existing user sub pages it does not work and also not in case of users that do not exist in the system... And I now guess that the bug with Konqueror maybe did never exist but I simply did not get the right page because of the /de subpage. Very wired everything. ;-) Arnomane 16:45, 17 February 2006 (UTC)
- Oh, look at that, a "block user" link! My mistake. Note that the link doesn't appear for User:Arnomane/subpage or for User:Arnomanedoesnotexist. That's why I didn't see it before. User:dbenbenn 15:16, 17 February 2006 (UTC)
- I don't think that fixes the problem. (I tried commenting out the relevant line of my monobook.js, and now the tabs don't appear when I view nonexisting user pages.) The change looks for a "t-blockip" element. Do you have a "block" tab when viewing user pages? I don't. Maybe it has something to do with the interface language? I'm using English. User:dbenbenn 13:33, 17 February 2006 (UTC)
From MediaWiki:Monobook.js
[edit]Please add the folowing code, thanks. This code is for show/hide structure used in en --Cool CatTalk|@ 20:36, 26 February 2006 (UTC)
function addLoadEvent(func)
{
if (window.addEventListener) window.addEventListener("load", func, false); else if (window.attachEvent) window.attachEvent("onload", func);
}
// ============================================================ // BEGIN Dynamic Navigation Bars (experimantal) // set up the words in your language var NavigationBarHide = '[ Hide ]'; var NavigationBarShow = '[ Show ]'; // set up max count of Navigation Bars on page, // if there are more, all will be hidden // NavigationBarShowDefault = 0; // all bars will be hidden // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden var NavigationBarShowDefault = 1; // shows and hides content and picture (if available) of navigation bars // Parameters: // indexNavigationBar: the index of navigation bar to be toggled function toggleNavigationBar(indexNavigationBar) { var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); if (!NavFrame || !NavToggle) { return false; } // if shown now if (NavToggle.firstChild.data == NavigationBarHide) { for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if (NavChild.className == 'NavPic') { NavChild.style.display = 'none'; } if (NavChild.className == 'NavContent') { NavChild.style.display = 'none'; } } NavToggle.firstChild.data = NavigationBarShow; // if hidden now } else if (NavToggle.firstChild.data == NavigationBarShow) { for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if (NavChild.className == 'NavPic') { NavChild.style.display = 'block'; } if (NavChild.className == 'NavContent') { NavChild.style.display = 'block'; } } NavToggle.firstChild.data = NavigationBarHide; } } // adds show/hide-button to navigation bars function createNavigationBarToggleButton() { var indexNavigationBar = 0; // iterate over all < div >-elements for( var i=0; NavFrame = document.getElementsByTagName("div")[i]; i++ ) { // if found a navigation bar if (NavFrame.className == "NavFrame") { indexNavigationBar++; var NavToggle = document.createElement("a"); NavToggle.className = 'NavToggle'; NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); var NavToggleText = document.createTextNode(NavigationBarHide); NavToggle.appendChild(NavToggleText); // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) for( var j=0; j < NavFrame.childNodes.length; j++ ) { if (NavFrame.childNodes[j].className == "NavHead") { NavFrame.childNodes[j].appendChild(NavToggle); } } NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); } } // if more Navigation Bars found than Default: hide all if (NavigationBarShowDefault < indexNavigationBar) { for( var i=1; i<=indexNavigationBar; i++ ) { toggleNavigationBar(i); } } } addLoadEvent(createNavigationBarToggleButton); // END Dynamic Navigation Bars // ============================================================
You realise that wikibits.js defines an addOnloadHook()
already (as documented here)? Also, can we have some screenshots of what this is going to do? Alphax (talk) 22:21, 2 March 2006 (UTC)
Well currently we luckily do not need this script as we have no navigation bars in Commons. And I deeply hope that Commons will remain a navigation bar free zone forever as these bars are simply pointless and duplication of categories. Apart that navigation bars do not make sense at all at gallery pages. We simply don't have town articles or such that someone could link in a wired way with navigation bars. ;-) Arnomane 03:34, 5 March 2006 (UTC)
- This is really awesome. I think we should implement it. It allows you to give sections a 'show'/'hide' link that you can toggle. Could be really handy, for example, on COM:FPC... (I've installed this on my files and am testing it out now) pfctdayelise (translate?) 09:29, 31 March 2006 (UTC)
- From what I understand, this would be an excellent idea for use in multilingual templates such as Template:Image source. Currently, clicking the language links requires a page load and doesn't correctly display the name of the image in question. —Simetrical (talk • contribs) 04:22, 14 May 2006 (UTC)
move of script into central place
[edit]I moved the script for the extra tabs in a central place (easier maintainance) and embeded it into this monobook.js. The variables can get customized for each language in its Monobook.js. The new functions added by Dbenbenn will be reintegrated later. Arnomane 20:16, 4 March 2006 (UTC)
I have now merged all changes into the new script. However the sysop status funtion has still a small bug. It will reject admin status at special pages if you do not overwrite the function in your local monobook.js. This is due to the fact that we need there again other flags determining admin status, but they exist and I will fix it but not now... Arnomane 03:29, 5 March 2006 (UTC)
- By the way, that central place is MediaWiki:Extra-tabs.js. Good idea. User:dbenbenn 14:09, 5 March 2006 (UTC)
strange function
[edit]What does this [2] function do? It doesn't get called in any script that gets called by default. Arnomane 09:58, 15 September 2006 (UTC)
- I moved it here from MediaWiki:Quick-delete.js. I answer more deeply on you discussion. Platonides 11:37, 16 September 2006 (UTC)
Link FA
[edit]/** Interwiki links to featured articles *************************************** * * Description: Highlights interwiki links to featured articles (or * equivalents) by changing the bullet before the interwiki link * into a star. * Maintainers: User:R. Koot */ function LinkFA() { for(var i=0; a = document.getElementsByTagName("span")[i]; i++) { if(a.className == "FA") { for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { if(b.className == "interwiki-" + a.id) { b.className += " FA"; b.title = "This article has gained featured status"; } } } } } addOnloadHook( LinkFA );
Yuval Y • Chat • 02:14, 1 December 2006 (UTC)
- Do we need this? Commons doesn't have interwikies like other wikipedias have. On a wikipedia it is useful to mark the best article on the wikis, if you happen to understand it. On commons i don't see the utility... Platonides 18:31, 1 December 2006 (UTC)
- Commons doesn't have interwikis, what are you talking about?? I am not sure having the FA star is that useful, but we certainly do have interwiki links! pfctdayelise (说什么?) 07:04, 3 December 2006 (UTC)
- Commons doesn't have interwikies on the way other wikipedias have. Platonides 22:25, 4 December 2006 (UTC)
concerning the thumbwarn
[edit]What about adding a fat red outline to the thumb with a red warning text below? --Dschwen 06:01, 24 April 2007 (UTC)
JS-i18n
[edit]The i18n stuff will not work in monobook.js. loading a subpage 'monobook.js/'+wgUserLanguage is a nice idea, but such script includes are only queued by the includePage()! The scripts are not loaded immediately. It might help to move the i18n stuff to common.js, it could still be skin-specific if we use a script path including the skin variable, like: 'monobook.js/'+skin+'/'+wgUserLanguage. I'll test if that works... --Dschwen 10:51, 10 July 2007 (UTC)
- Ok, that won't work. Common.js and Monobook.js are delivered to the client as one chunk.. --Dschwen 11:06, 10 July 2007 (UTC)
- Taken to the mailinglist... --Dschwen 11:23, 10 July 2007 (UTC)
Since the scripts are already loaded by the time you have to insert new html elements (all the functions called with addOnloadHook), I don't see a problem here. P.S. Please provide a link to that mailinglist archives, if it exists ∴ Alex Smotrov 15:49, 10 July 2007 (UTC)
- Right, but some i18n strings are already needed before the onload Hooks are executed. But now that I think about it, I might be able to work around that problem. Let me explain my problem: if you look at MediaWiki:Common.js you'll notice the JSConfig object. It provides a framework to register, edit, store, and query configuration items. When registering a config item a description text has to be passed. I'd like to make this translatable. The config item registration happens before the onload hooks, it even happens before the includePage commands for the extension (I want to be able to only load extensions when they are activated with a config item).
- But the solution would be the following: do not pass a description text when registering the config item, but pass an i18n-identifier. The descriptions are only needed on the Preferences page and then only after the page loading has finished. I could add an onload Hook which updates the description texts from the then already initialized i18n object.
- We could then move all remaining translations from Common.js and Monobook.js to i18n objects (or variables) on subpages and include them like before.
- The archives are here [3], but why don't you subscribe to the list, I'm sure you can provide valuable input there! --Dschwen 16:20, 10 July 2007 (UTC)
- OK there is this page User:Steinninn/extra-tabs which has info for Icelandic (is). What should be done with it? pfctdayelise (说什么?) 11:23, 7 August 2007 (UTC)
- For the time being I copied it to MediaWiki:Monobook.js/is, this should enable icelandic extratabs globally. --Dschwen 11:48, 7 August 2007 (UTC)
.5B bug
[edit]Are the two lines
// A workaround for bug 2831, http://bugzilla.wikimedia.org/show_bug.cgi?id=2831 // This comes from Wiktionary, // http://en.wiktionary.org/w/index.php?title=MediaWiki:Monobook.js&diff=prev&oldid=1144333 if (/\.5B/.test(window.location.href)) window.location = window.location.href.replace(/.5B/g, "").replace(/.5D/g, "");
still needed? They unconditionally strip any ".5B" (that's the encoding for "[") and ".5D" ("]") from the href and then cause a reload. That breaks pages that do contain these character sequences. Witness .5B, or (a real case) Image:Shinhwa07.5B.jpg. (Has since been deleted by replacing the first "." by "%2E" in the URL...)
If this Bug 2831 is indeed not fixed yet in the MediaWiki software, can we change this "workaround" (I'd call it a poorly thought-through and untested hack) to at least only replace ".5B" and ".5D" if they occur after a "#" following the last "/" in the href? That may still mess wrongly with some section links, but not in such a gross way. Lupo 13:44, 5 September 2007 (UTC)
- Or even better, change that to an onload function that sets window.location.hash correctly. That should jump to the correct section without forcing a reload. Lupo 14:30, 5 September 2007 (UTC)
- Something like
function bug2831Workaround () { if (/\.5[BD]/.test (window.location.hash)) window.location.hash = window.location.hash.replace(/\.5[BD]/g, ""); }
- If we could do that only if the hash refers to an unknown anchor, it would be even better. And if we could somehow figure out which ".5[BD]"s refer to replaced "[" and "]" and which ones are genuinely part of the section heading, that'd be perfect. Lupo 14:36, 5 September 2007 (UTC)
- I added your proposal. Platonides 18:41, 5 September 2007 (UTC)
- For a more complete solution (but still not totally complete; there are some cases that just cannot be caught reasonably), see en:User:Lupo/monobook.js at the bottom. Tested with page en:User:Lupo/tmp1. Don't know if that's worth the trouble; ultimately, the bug should be fixed. (Note that it also affects section links in the watchlist and user contributions.) Lupo 10:52, 6 September 2007 (UTC)
JavaScript NavFrame does not work
[edit]- Does anyone know why the JavaScript NavFrame "show" button does not appear here on the commons? It works just fine in wikipedia and both pages have the exact same wording, but it does not work how it is suppose to here. It apparently broke between June 21 and July 11 Any help would be appreciated. Thanks. --Digon3 talk 15:19, 5 September 2007 (UTC)
- After many fiddling i got it working. Platonides 20:31, 5 September 2007 (UTC)
- Thank-you so much! However, is there any way the "show" button could be the word show/hide, as it is on wikipedia, instead of a small triangle? --Digon3 talk 20:37, 5 September 2007 (UTC)
- Having a symbol instead of words is better for Commons: can be understood by people speaking any language. pfctdayelise (说什么?) 12:25, 6 September 2007 (UTC)
- Ah, ok. Then is there any way the symbol can be made a little bigger and aligned right? See my userpage for what I mean by the alignment. --Digon3 talk 13:49, 6 September 2007 (UTC)
- Having a symbol instead of words is better for Commons: can be understood by people speaking any language. pfctdayelise (说什么?) 12:25, 6 September 2007 (UTC)
Shouldn't that one be migrated to MediaWiki:Common.js?? I don't see anything skin-specific in that file... Lupo 22:34, 24 March 2008 (UTC)
- Yes, I think that's a good idea. However we should wait another year or two. Rocket000 (talk) 10:13, 9 September 2009 (UTC)
- :-) I forgot that I had asked about this that long ago... Lupo 10:21, 9 September 2009 (UTC)
- hahaha... =) Helder 15:18, 9 September 2009 (UTC)
- :-) I forgot that I had asked about this that long ago... Lupo 10:21, 9 September 2009 (UTC)
russian translation for i18n_resize
[edit]{{Editprotected}} Please add russian translation for i18n_resize:
'ru': 'Подстраивать ширину галерей и категорий (количество изображений в ряду) по размеру экрана'
- Maybe move this code into gadgets area? --Kaganer (talk) 16:19, 13 January 2010 (UTC)
--Kaganer (talk) 16:19, 13 January 2010 (UTC)
Extra toolbar options
[edit]{{Editprotected}} I get warnings about "Use of "mwCustomEditButtons" is deprecated. Use mw.toolbar instead.". I think that is because of code in this script trying to add a redirect button to the edit toolbar. I don't see any redirect button in the toolbar, so the code can probably be removed if nobody wants to update it. /Ö 13:33, 25 June 2014 (UTC)
Done I can not see also (for example on here), removed. −ebraminiotalk 10:20, 4 July 2014 (UTC)
Legacy JavaScript
[edit]Hello! This script has been detected as using deprecated parameters that need to be replaced with the updated version. Examples include addOnloadHook()
needs to be replaced with $()
; all wgGlobalVariables need to be properly gotten with mw.config.get( 'wgGlobalVariable' )
; and addPortletLink
needs to be called with mw.util.addPortletLink
. Please see MW:ResourceLoader/Legacy JavaScript for details. Thank you. — {{U|Technical 13}} (e • t • c) 21:55, 18 January 2015 (UTC)
- There is nothing deprecated here.
importScript
most likely has been un-deprecated. -- Rillke(q?) 23:52, 23 July 2015 (UTC)