MediaWiki talk:Common.js

Latest comment: 3 years ago by Inductiveload in topic Gadgetizing PageNumbers.js
This interface message is documented at mw:Manual:Interface/Common.js.

Missing object edit

We have a problem here, an object can't be found by IE 6's script debugger. Can we get this sorted out?

function dotabs()
{
   //first tab
   var a = document.getElementById("ca-nstab-main");
--> var s = a.innerHTML;

Looks like a is not defined for some reason. - Ta bu shi da yu 05:59, 29 March 2006 (UTC)Reply

I don't get that problem; I assume it's been fixed since then. If not, you'll probably get more responses if you add a note on the community discussion page linking to your question here. —{admin} Pathoschild 01:38, 23 January 2007 (UTC)

Directory edit

Where can I find COMMON.JS? what is the path directory? I can't find it... thanks Alain, 22, January 2007

Hello Alain. Common.js is dynamically generated from MediaWiki:Common.js, and isn't saved in the files. You can see it for yourself by visiting en.wikisource.org/w/index.php?title=-&action=raw&smaxage=0&gen=js. It's called in the XHTML code on this line:
<script type="text/javascript" src="/w/index.php?title=-&action=raw&smaxage=0&gen=js"><!-- site js --></script>
. —{admin} Pathoschild 01:38, 23 January 2007 (UTC)

dotabs() error edit

The innerHTML hack in dotabs() messes up pages with non-english interface really bad. Please use proper DOM manipulation instead. --Tgr 17:13, 12 April 2007 (UTC)Reply

I'll recode it soon. —{admin} Pathoschild 05:33:54, 13 April 2007 (UTC)

wgArticlePath edit

I just tried to fix some bugs on the secure wiki (logging on to which is now encouraged) by replacing links beginning with /wiki with code similar to wgArticlePath.replace(/\$1/,"blah") (along with changing png images to their svg counterparts) and failed somehow (images don't show any more at all). Can somehow with better knowledge of the workings of our site JavaScript look into this? Thank you.--GrafZahl (talk) 11:13, 27 July 2007 (UTC)Reply

Script error edit

I can't pinpoint the exact cause, but most pages on Wikisource produce this error in IE6:

Line: 322
Char: 3
Error: Object doesn't support this property or method.

Edokter 19:19, 17 October 2007 (UTC)Reply

A better DisplayFooter() function edit

I think I found a way to get this function to work in IE too. Here's how:

function DisplayFooter() {
	if(document.getElementById && wgNamespaceNumber==0) {
		nofooter = document.getElementById('nofooter');
		hp = document.getElementById('headerprevious');
		hn = document.getElementById('headernext');
		cnt = document.getElementById('bodyContent');  // IE does not accept variable names
		ctl = document.getElementById('catlinks');     // if the name is already defined
		ftr = document.createElement('table');         // somewhere in HTML! --Lozman--
                //header_template = document.getElementById('headertemplate');		
 
                if( (!((cnt) && (ftr))) || (!(hp || hn)) ||
		(nofooter))
		return;
 
		ftr.className='headertemplate';                // IE does not have setAttribute! --Lozman--
		ftr.id='footertemplate'; 
		ftr.style.marginTop='1em'; 
		ftr.style.clear='all'; 
 
		/* Begin footer HTML code */
		tr = document.createElement('tr');
		td = document.createElement('td');
 		td.align='left';                               // IE does not have setAttribute! --Lozman--
		td.style.width='33%';
		td.className='header_backlink';

 
                if (hp) {
		  fp = hp.cloneNode(true);
		  fp.id='footerprevious';                      // IE does not have setAttribute! --Lozman--
		  td.appendChild(fp);
		}
		tr.appendChild(td);
 
		td = document.createElement('td');
		td.align='center';                             // IE does not have setAttribute! --Lozman--
		td.style.width='34%';
		td.className='header_title';
		a = document.createElement('a');
		a.href='#top';                                 // IE does not have setAttribute! --Lozman--
		text = document.createTextNode('Return to the top of the page.');
		a.appendChild(text);
		td.appendChild(a);
		tr.appendChild(td);
 
		td = document.createElement('td');
		td.align='right';                              // IE does not have setAttribute! --Lozman--
		td.style.width='33%';
		td.className='header_forelink';
 
                if (hn) {
		  fn = hn.cloneNode(true);
		  fn.id='footernext';                          // IE does not have setAttribute! --Lozman--
		  td.appendChild(fn);
		}
 
		tr.appendChild(td);
 
		ftr.appendChild(tr);
 
		/* End footer HTML code */
 
		if(ctl) // place footer before category box
		cnt.insertBefore(ftr, ctl);
		else
		cnt.appendChild(ftr);
		// This forces IE to refresh page content, otherwise it won't --Lozman--
		try {
		  bodyContent.outerHTML = cnt.outerHTML;
		} catch(e) {
		}
	}
}

Works in IE, Firefox, Opera and Safari (tested in ru.wikisource). — Lozman (talk) 19:42, 8 September 2008 (UTC)Reply

Thank you. I don't have IE and I didn't even know it doesn't work with it. Can some admin with IE try out the new code here on this Wikisource? Thanks!--GrafZahl (talk) 08:02, 10 September 2008 (UTC)Reply

MediaWiki:Common.js edit

where do i find MediaWiki:Common.js on my mediawiki. for example local setting or do i have to start a page called MediaWiki:Common.js but where? Thanks --86.136.108.50 15:15, 18 February 2009 (UTC)Reply

You need to create a page called "MediaWiki:Common.js"; go to that page name, and click edit. mw:Manual:Interface/JavaScript has a little bit more information, and that is the website where you should seek further technical support. John Vandenberg (chat) 22:54, 18 February 2009 (UTC)Reply

Tabber edit

What is the tabber code actually being used for on WikiSource? There has been talk of some day implementing an easy way to create additional tabs in MediaWiki, but it would be good to know the various use cases before anything gets developed. Kaldari (talk) 05:02, 4 September 2010 (UTC)Reply

Primarily Template:Welcome, hence widely used. Not sure of other use. — billinghurst sDrewth 07:50, 4 September 2010 (UTC)Reply
So we're loading 20K of Javascript on every page load just so Template:Welcome doesn't have to use any CSS? Seems like overkill to me. Kaldari (talk) 06:08, 5 September 2010 (UTC)Reply

Implemented commons script for secure servers edit

There has been navigation issues for those logged in via the secure login facility with relation to some links, especially crosswiki and interwiki links. Pathoschild amended those issues that came with the extension DoubleWiki yesterday, and today I have added the fix from Commons that rewrites the links. If there problems then we should revert my change to import that script. — billinghurst sDrewth 00:23, 11 January 2011 (UTC)Reply

I'm having problems with false-positive result for https WS, resulting in broken links of the format en.wikisource.org/wikisource/en/wiki/blah everywhere. Happens on both chrome and IE. Prosody (talk) 00:47, 11 January 2011 (UTC)Reply
That was probably badly worded. I'm not using secure.wikimedia.org, but getting links as if I am. Prosody (talk) 00:49, 11 January 2011 (UTC)Reply
Per commons:MediaWiki:Common.js, I think you just need to enclose the importScriptURI in 'if( wgServer == 'https://secure.wikimedia.org' )' Prosody (talk) 01:03, 11 January 2011 (UTC)Reply
Don't know if its related or just me but attempting to patrol edits from the (prev) link(s) on the Recent Changes page brings up 404-server-type errors. The provided alternative link does eventually take you to where you wanted to go apparently. -- George Orwell III (talk) 01:36, 11 January 2011 (UTC)Reply
This just stopped - back to as before -- George Orwell III (talk) 01:53, 11 January 2011 (UTC)Reply
Been better gIFt wrapped this time, and using enWP as per John's preference. Apologies. — billinghurst sDrewth 02:20, 11 January 2011 (UTC)Reply

Adding withJS support & temporal media fragments edit

I added withJS support to match commons and en.wikipeida this is helpful for people to try out gadgets. Per bug 26663 and Theornamentalist and I wanted to try supporting temporal media fragments for wikisource articles about video assets. You can see the work in progress here. If desirable we can more broadly enable the feature. Mdale (talk) 19:03, 14 January 2011 (UTC)Reply


Wikisource layouts edit

A variety of layouts for transcluded works are available for logged-in readers. [Left hand margin, toggle through Layout 1/2/3] There is scope for the development of more layouts, and this is the space to propose test layouts, and to have the discussion about layouts that are proposed. At this point in time it requires the intervention of an administrator to put the test layout into play, through every user can turn on the test layer through the gadget Billinghurst (talk) 03:44, 11 March 2011 (UTC)Reply

To have a test layout introduced, please identify below

  1. A name and the descriptive elements for your test code
  2. Where the administrator can get the code that you have tested

(this list of criteria/elements will certainly mature)

Test layouts edit

Commented out usejs edit

After a quick chat with the author of usejs, it was indicated that we believe that the script is archaic, unused and no longer supported, hence there is no longer a need for it to be included in the file. I have commented out the file, and see if this is an issue for users. — billinghurst sDrewth 06:47, 11 April 2011 (UTC)Reply

protocol relative url edit

Following the implementation of relative urls (see announcement at https://blog.wikimedia.org/2011/10/03/native-https-support-enabled-for-all-wikimedia-foundation-wikis/) I have modified the urls to be relative, which should allow a smooth transition. If not, then please revert and get back to me and I will seek an expert's opinion. — billinghurst sDrewth 12:57, 4 October 2011 (UTC)Reply

Could you get that last one at the bottom? Prosody (talk) 06:52, 15 October 2011 (UTC)Reply
  Done - hope that is correct; please let me know if it is not. -- George Orwell III (talk) 07:19, 15 October 2011 (UTC)Reply
For the record, the oldws link was broken before this edit. I think it broke during the 1.18 upgrade. Prosody (talk) 07:33, 15 October 2011 (UTC)Reply
???? If it was/is not working, is there any reason to keep the line at all? -- George Orwell III (talk) 08:00, 15 October 2011 (UTC)Reply
Good point. I was banking on the script being fixed soonish, but that may not be the case. As is, even if we remove that include we still have a bunch of broken interlanguage links to Arab wikisource everywhere, and it wouldn't be worthwhile to go about removing them unless we decided that we were just going to give up on on old ws links through that js for good. Prosody (talk) 01:14, 17 October 2011 (UTC)Reply
Nevermind, it works. I was under the impression that Chrome only reported insecure js but it apparently refuses to run it also. Prosody (talk) 01:20, 17 October 2011 (UTC)Reply

Reverted previous edit edit

Not sure what was happening why, however, I was getting a title, and no displayed text. Text was there (show sourced), but not displaying. A little problematic with refresh cache to know exactly it occurred. — billinghurst sDrewth 06:43, 3 November 2013 (UTC)Reply

Give search results even when page doesn't exist edit

 
Screenshot of the Earth test search, with this script adding links to Wikidata, Reasonator, Commons, and Wikipedia.

Hello, I propose to enable the tool created by Magnus Manske (creator of MediaWiki) to provide results from other languages and Commons (via Wikidata) when a page doesn't exist here: links are added to Special:Search and noarticletext. This helps to encourage translation and to make readers use your wiki more, because they can be sure to find something even if it's not local (rather than searching directly on the biggest wiki). The Italian and Polish Wikipedias, among others already enabled it by default.
Examples: [1] [2] [3]. More information: Magnus blog.
How to: just add the following line at the end of Common.js.

// Results from Wikidata
// [[File:Wdsearch_script_screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}
--[[m:User:Nemo_bis|Nemo]] ~~~~~ ([[w:en:MediaWiki talk:Wdsearch.js|comments, translations and last instructions]])
</div>
<!-- EdwardsBot 0661 -->

Proposed layouts, there is a gadget for this edit

There is an existing gadget that can be turned on and off for testing proposed layouts "Sandbox for new layouts". This saves having to edit common.js, and having it listed on the layout rotations, and the issues of caches, etc. — billinghurst sDrewth 05:56, 10 January 2014 (UTC)Reply

Yeah but not everybody will see the proposed layout that way, so what is the point? Its passed the testing phase as far as I'm concerned - all I want to get to now is any possible objections/browser issues. I didn't even announce it yet basically for the same reason you're looking to lock in a specific Layout (it no workie). Eliyak would be the person to tap btw. -- George Orwell III (talk) 04:58, 10 January 2014 (UTC)Reply
If it is in the rotation, then is it still proposed? If it is in call it 4, and tell people. Or if want people to test we can get them to gadget on. We are doing more and more live and in full view presentation of tests, and that is a change in which I am not fully supporting. We used to test and comment out of full view, and get comment prior to implementation, and that doesn't seem to be the approach now taken. — billinghurst sDrewth 05:56, 10 January 2014 (UTC)Reply

Updates edit

Hi George Orwell III!

Could you make these updates to the site JS? This will reduce the number of warnings like

Use of "addOnloadHook" is deprecated. Use jQuery instead

in the console. Helder.wiki 14:48, 13 March 2014 (UTC)

  Done - Helder.wiki. Keep them coming! I'm [eventually] here everyday :) George Orwell III (talk) 18:27, 13 March 2014 (UTC)Reply
George Orwell III, thanks! BTW: it seems you changed the code manually based in the diff I linked above, but I usually provide a full copy of the new code in the sandbox, so you can just copy it from there to replace the current one. Helder.wiki 18:39, 13 March 2014 (UTC)
Lesson learned Helder.wiki. I couldn't manage 4 simple changes without screwin' one up. will do from now on. -- George Orwell III (talk) 18:54, 13 March 2014 (UTC)Reply
No problem. I also make this some times... Some of the errors are easy to catch by pasting the code on http://www.jshint.com/ to validate it before saving (and possibly setting a few options in the "configure" menu, to avoid warnings about thinks we don't care for now - or if there are many, just count the number of errors before and after a change to at least do not increase it  ). Helder.wiki 18:57, 13 March 2014 (UTC)

Gadgetizing PageNumbers.js edit

{{editprotected}}

In my ongoing quest to convert MediaWiki:PageNumbers.js into a Gadget—so that it can be turned off in order to test updates, alternatives, modifications, layouts, etc.—I have, I think, come up with a reasonable temporary way to disable it when needed.

The idea is to have the code that loads PageNumbers.js and the code for the fixup functions conditional on a test for the presence of a particular HTML id attribute that is highly unlikely to occur by accident (#ws-suppress-pagenumbers-script). This is of course ugly and hacky, but should have no major drawbacks as a temporary solution. Once a Gadgetized version of the script is available that can be enabled and disabled in user preferences in the normal way (or if the attempt is abandoned), this hack can be removed along with the existing PageNumbers.js-related code in Common.js.

@Billinghurst: (or someone else with global-interface-admin rights) I can't actually test this, but the code is very simple so it should be low risk; and it's easy to roll back if needed. Can you apply the above linked diff to MediaWiki:Common.js? --Xover (talk) 11:32, 16 September 2019 (UTC)Reply

@Xover: but you can turn off already (well, hide) the page numbers in the sidebar at this time ... "page links displayed". Are you wanting to obliterate them completely? — billinghurst sDrewth 12:28, 17 October 2019 (UTC)Reply
@Billinghurst: I want to disable the code completely, because it modifies the DOM (on all pages in all namespaces) and makes it impossible to experiment with an alternate version of the PageNumbers.js script. And since the current version is buggy and limited in ways that cannot easily be fixed by just reading the code and requesting a simple edit (like the above), there is a need to be able to have a private copy in my userspace for debugging and experimentation, from which I can generate a diff that can be applied to the global version. Or put another way, I need to be able to have my own copy that I can modify without the global version interfering.
The above requested edit is the first step: it makes the Pagenumbers-related code disable itself on pages with a very specific HTML tag, so that I can create a test page where the global version is not active at all. The next step will be to make a copy of PageNumbers.js that I can modify until it can function as a Gadget that can be turned on and off at will in user preferences. At which point we can remove all the special code in Common.js (both my extra IF statements, and the original code that those if statements wrap). And at that point, anybody that wants to fix bugs or add new functionality to the script have an easy way to experiment without affecting anybody else until they have something worthwhile to propose as a modification to the global Gadget.
Once we're at that point I intend to work on fixing the bugs that prevent us from working around browser bugs tickled by proofreadpage (empty inline elements), and possibly clean up the dynamic layouts system such that it becomes feasible for someone other than GOIII to add or modify layouts (they'd typically be a .css file in Mediawiki:-space, or possibly even a personal stylesheet in User:-space). I don't have specific plans beyond that, but I know we occasionally run into issues with slightly odd page numbering schemes that may become more readily addressable at that point. --Xover (talk) 12:49, 17 October 2019 (UTC)Reply
@Xover: Done, in the way you suggest. If it turns out that's not flexible enough, we could add something like the MW Options API to allow to toggle easily without editing a page, but we'll see if that's needed. Inductiveloadtalk/contribs 09:38, 25 August 2020 (UTC)Reply