MediaWiki talk:Common.js/Archive 17: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
m Replaced deprecated <source> tags with <syntaxhighlight> (via WP:JWB)
Line 120:
I'd like to disable the anontips banner ("Wikipedia is sustained by people like you. Please donate today.", etc.) before the start of the next fundraiser. This year's fundraiser banners will be particularly large and noticeable; there's really no need to clutter the reader's screen with multiple donate messages. In addition, the non-donate messages are stale and the break will hopefully give us some time to write fresh content. Any objections? --[[User:MZMcBride|MZMcBride]] ([[User talk:MZMcBride|talk]]) 00:37, 27 October 2009 (UTC)
 
: Forgot that we have [[MediaWiki:Monobook.css]] too. Probably good if change some of the more stagnant elements in the site. Looking at the code I came up with the following improvement to shave bytes by using wikilinking. <sourcesyntaxhighlight lang=javascript>div.innerHTML = message[whichMessage].replace(/\[\[([^[\]{|}]+)\]\]/g, "[[$1|$1]]").replace(/\[\[([^[\]{|}]+)\|(.+?)\]\]('??\w*)/g, '<a href="'+wgArticlePath+'" title="$1">$2$3</a>');</sourcesyntaxhighlight> It has the add benefit that the links work better on the secure server. Also, for accessibility we should be attaching this div to the end of the page so it isn't the first text read aloud by screen readers. — [[User:Dispenser|Dispenser]] 03:41, 27 October 2009 (UTC)
::Now we just a javascript implementation of the parser and we'll be set! — [[User:RockMFR|RockMFR]] 23:20, 27 October 2009 (UTC)
 
Line 129:
So we'll add "needs a code rewrite" to the list of reasons I've now [http://en.wikipedia.org/w/index.php?title=MediaWiki:Monobook.js&diff=prev&oldid=322588403 removed] the banner. Copied below for posterity and for improvements. --[[User:MZMcBride|MZMcBride]] ([[User talk:MZMcBride|talk]]) 19:26, 28 October 2009 (UTC)
{{collapse top}}
<sourcesyntaxhighlight lang="javascript">
/** Anon tips and donation banner **************************
*
Line 170:
}
}));
</syntaxhighlight>
</source>
{{collapse bottom}}
 
Line 178:
 
I think we could simplify this code from the function ''toggleNavigationBar''
<sourcesyntaxhighlight lang="javascript">
if ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
Line 185:
NavChild.style.display = 'none';
}
</syntaxhighlight>
</source>
to
<sourcesyntaxhighlight lang="javascript">
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent') ) {
NavChild.style.display = 'none';
}
</syntaxhighlight>
</source>
 
and this one
<sourcesyntaxhighlight lang="javascript">
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
Line 201:
NavChild.style.display = 'block';
}
</syntaxhighlight>
</source>
to
<sourcesyntaxhighlight lang="javascript">
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
</syntaxhighlight>
</source>
 
What do you think? [[User:Heldergeovane|Helder]] ([[User talk:Heldergeovane|talk]]) 18:47, 29 October 2009 (UTC)
:No objections. Though realistically, it won't make much of a difference in both speed and size of the script. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 19:49, 29 October 2009 (UTC)
::Or maybe all this part
<sourcesyntaxhighlight lang="javascript">
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
Line 237:
NavToggle.firstChild.data = NavigationBarHide;
}
</syntaxhighlight>
</source>
::could be changed to
<sourcesyntaxhighlight lang="javascript">
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavPic') || hasClass(NavChild, 'NavContent')) {
Line 245:
}
}
</syntaxhighlight>
</source>
::It seems a lot simpler, isn't? ;-) [[User:Heldergeovane|Helder]] ([[User talk:Heldergeovane|talk]]) 18:20, 30 October 2009 (UTC)
:::Add the forgotten <code>NavToggle.firstChild.data = ...</code> and then your code is very similar to what I had for a year in [[:ru:MediaWiki:Common.js]] (collapseDiv() function), so naturally I support this simplification. However, the en.wp style of JS programming seems to be "the more lines of code, the merrier". — [[user:Alex Smotrov|AlexSm]] 19:31, 30 October 2009 (UTC)
Line 255:
 
:I think it would be much better to catch these links at the destination page, i.e. [[Special:MySkin.js]] and [[Special:MySkin.css]]. This way it would take almost zero processing time on all other pages, only 2 lines in Common.js and the rest will be in a separate script:
<sourcesyntaxhighlight lang="javascript">
if (wgCanonicalNamespace=='Special' && /myskin\.(js|css)/i.test(wgTitle))
importScript('MediaWiki:Common.js/myskin.js')
</syntaxhighlight>
</source>
:P.S. Could you please elaborate on the "upcoming change to vector"? — [[user:Alex Smotrov|AlexSm]] 19:14, 16 October 2009 (UTC)
:: Drawback is that they stay redlinked. And the upcoming change is I guess that it will be made the default skin at some point. [[User talk:Amalthea|<span style="font-variant:small-caps;color:#832">Amalthea</span>]] 19:21, 16 October 2009 (UTC)
Line 389:
 
Many users are not familiar with using SVG images available on Wikipedia/Commons in office applications, etc. This is particularly true, if the base size is small ([[:File:1LT BNC.svg|example]]). Therefore, I suggest adding links to rendered PNG images in different sizes to the image page. This has already been implemented on de-WP and on Commons (see [[Commons:MediaWiki talk:Common.js#SVG files: links to rendered PNG images|talk page]]). --[[User:Leyo|Leyo]] 18:14, 12 November 2009 (UTC)
<sourcesyntaxhighlight lang="javascript">
// SVG images: adds links to rendered PNG images in different resolutions
addOnloadHook(function() {
Line 421:
}
});
</syntaxhighlight>
</source>
:This is the code in question. I think this would be a nice addition. I'm wondering if we should have a /file.js page for this however. What do you guys think ? Also, the usage of "nextSibling" should probably be avoided. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 18:39, 24 November 2009 (UTC)
 
Line 434:
 
Code prepared in [[MediaWiki:Common.js/file.js]]. To be loaded from Common.js with:
<sourcesyntaxhighlight lang=javascript>
if( wgNamespaceNumber == 6 )
importScript('MediaWiki:Common.js/file.js');
</syntaxhighlight>
</source>
Most suggestions by David incorporated. I was wondering. Isn't "resolutions" a misnomer ? Perhaps we should just say "in different sizes" —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 14:07, 25 November 2009 (UTC)
 
Line 447:
Hmm, JavaScript can do ''loops'', if you get what I mean... — [[user:Alex Smotrov|AlexSm]] 20:43, 25 November 2009 (UTC)
 
<sourcesyntaxhighlight lang=javascript>
// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
Line 477:
};
addOnloadHook( SVGThumbs );
</syntaxhighlight>
</source>
Code untested. I think you use wgIsArticle instead of wgAction == "view" since things like purge renders a fully viewed page. You should be using wgServer + wgScriptPath, not all SVGs are at commons. We probably should be picking common screen resolutions like 1024x768, 1280x960, 1920x1080, 2048x1536. — [[User:Dispenser|Dispenser]] 21:06, 25 November 2009 (UTC)
:I fixed the paths immediately, I think that was kinda important. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 21:14, 25 November 2009 (UTC)
Line 502:
=== 3rd version ===
OK, my 3rd version of the code. Now just patches the URL of the original thumb (since for SVG we always have png thumbs). Also, per popular request, a loop. This code is not yet live. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 00:29, 27 November 2009 (UTC)
<sourcesyntaxhighlight lang="javascript">
// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
Line 533:
};
addOnloadHook( SVGThumbs )
</syntaxhighlight>
</source>
 
 
Line 541:
 
:That code works, but might I suggest this alteration:
<sourcesyntaxhighlight lang="javascript">
var thumbu = file.getElementsByTagName('img')[0].src;
if (!thumbu) return;
Line 547:
function svgAltSize(w, title) {
var path = thumbu.replace(/\/\d+(px-[^\/]+$)/, "/" + w + "$1");
</syntaxhighlight>
</source>
:Otherwise it relies on the img's specified width on the page matching the width in the URL. It probably will, but there might be other strange influences at work that browsers get wrong: zooming, not having fully loaded the image yet (race condition?), etc. The other part of that regexp is to prevent matching on the wrong part of the URL if the file name includes something that looks like the size. E.g., <nowiki>http://upload.wikimedia.org/wikipedia/en/thumb/3/35/200px-stupid-file-name.svg/200px-200px-stupid-file-name.svg.png</nowiki>. Also the wgTitle logic could be shortened to the more elegant <samp>wgTitle.match(/\.svg$/i)</samp> if you wish. • [[User talk:Anakin101|Anakin]] 03:13, 27 November 2009 (UTC)
::Deployed with suggestions. —[[User:TheDJ|Th<span style="color: green">e</span>DJ]] ([[User talk:TheDJ|talk]] • [[Special:Contributions/TheDJ|contribs]]) 23:13, 27 November 2009 (UTC)
Line 581:
Per [[Wikipedia:Village pump (technical)#Turn on spellcheck in summary field|a discussion]] at the Village pump, we (I and Dispenser) would like to turn on spellchecking in the edit summary field. At the moment this works for Firefox 2 and 3. At least for me it doesn't work in Opera, but it is likely more browsers will sooner or later support this. I would like to add the code below to [[MediaWiki:Common.js/edit.js]]:
 
<sourcesyntaxhighlight lang="javascript">
// Turn on spellchecking in the edit summary field, for Firefox.
// Temporary until [[bugzilla:21604]] is deployed
Line 589:
wpSummary.spellcheck = true;
} );
</syntaxhighlight>
</source>
 
The code has been checked (and fixed) by TheDJ.
Line 628:
:But as I thought, we can't check variables set by users, unless inside addOnloadHook(). We need to load [[MediaWiki:Sysop.css]] before page rendering, so that means we can't check <code>!window.disableSysopJS</code> for it. But as far as I know the reason for that variable is that Sysop.js interferes with some user scripts, but the Sysop.css should not be a problem for those users. And as far as I can see from searching for "disableSysopJS" only three admins use that setting. The most noticeable difference for those three admins will be that from now on they will see pink background in the edit window when editing protected pages, just like all other admins see. If they don't like that, then they can instead do like some of us and add one line of CSS to their /monobook.css to change that pink background to something else.
:Since the code for loading the sysop and accountcreator files is so similar, I want to merge it, like this:
<sourcesyntaxhighlight lang="javascript">
/** For sysops and accountcreators *****************************************
*
Line 649:
}
}
</syntaxhighlight>
</source>
:This also makes it easy and efficient if we want to add loading of special CSS or javascript for other user groups.
:--[[User:Davidgothberg|David Göthberg]] ([[User talk:Davidgothberg|talk]]) 12:03, 6 January 2010 (UTC)
Line 657:
 
:The editnotice system now also needs to unhide a link when a user edits his own user or user talk page. That is, no one else than the user himself (and admins) should see it. See discussion at [[Wikipedia talk:Editnotice#User page links]]. To do that I intend to add this code to [[MediaWiki:Common.js/edit.js]]:
<sourcesyntaxhighlight lang="javascript">
// Loads [[MediaWiki:Ownuserspace.css]] when the
// user is on his own user or user talk basepage.
Line 663:
importStylesheet("MediaWiki:Ownuserspace.css");
}
</syntaxhighlight>
</source>
:The above code only loads [[MediaWiki:Ownuserspace.css]] when on the user's rootpage or root talk page, not on the user's subpages. Currently we don't need it to load on the subpages, so no reason to make the code more complicated. Later we might load it for the entire userspace, so I named the CSS file "userspace" instead of "userpage". And currently we only need it when editing the page, so loading it from /edit.js is more efficient than loading it from Common.js.
:--[[User:Davidgothberg|David Göthberg]] ([[User talk:Davidgothberg|talk]]) 22:41, 12 January 2010 (UTC)
Line 684:
And I will change the code in [[MediaWiki:Common.js]] that loads [[meta:MediaWiki:Wikiminiatlas.js]] to this:
 
<sourcesyntaxhighlight lang="javascript">
addOnloadHook( function() {
var wmaload = document.getElementById("wikiminiatlas-load");
Line 696:
importScriptURI(metaBase+"/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400")
} );
</syntaxhighlight>
</source>
 
I will notify the people who work with coordinates and Dschwen who seems to be the main coder of the WikiMiniAtlas system.
Line 735:
 
{{hidden begin|title=WMA loader lite}}
<sourcesyntaxhighlight lang="javascript">
// WikiMiniAtlas loader lite
var wikiminiatlas = {
Line 879:
}
addOnloadHook(wikiminiatlas.loader);
//</sourcesyntaxhighlight>
{{hidden end}}
I was hoping to get the size a lot smaller, but I guess this will have to do. It is currently at approx. 150 lines/6 KB compared to the original 503 lines/16 KB.