Last modified: 2006-08-06 20:48:19 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T8156, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 6156 - Expose username and current title as JavaScript variables
Expose username and current title as JavaScript variables
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-06-01 01:31 UTC by Andrew Dunbar
Modified: 2006-08-06 20:48 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Andrew Dunbar 2006-06-01 01:31:22 UTC
It can be trickier than expected for a JavaScript extension to find seeminbly
obvious values:

*The user's name
*The name of the current page

These could easily be made available in an HTML FORM with INPUTs of type HIDDEN
and no SUBMIT. Each INPUT would have a CSS ID.

If a FORM is deemed a bad idea, SPANs with their CSS display set to invisible
would also work.

There are surely other values that js hackers have gone to extremes to extract
from the document structure, which have to be changed often as the document
structure is developed.

User preference settings would also be valuable for JavaScript extensions but
that may be beyong the scope of this feature request.
Comment 1 Darkoneko 2006-06-01 13:26:28 UTC
I think they are not that hard to recover :

the user name is in : id="pt-userpage" > A > text node
the page name is in : id="ca-nstab-main" > A > HREF parameter

for example, for the page name, you can use something like : 

function retrievePageName() {
  var temp = document.getElementById("ca-nstab-main")
  temp = temp.getElementsByTagName("A") //return an array with only one case
  temp = temp[0].getAttribute("HREF") //now we have a string "/wiki/articleName"
  return temp.substring(7, temp.length) //return the string after cutting "/wiki/"
}

note that I didn't test this function, just wrote it "on the fly", and also I
have the bad habit to re-use variables anytime I can which can be ake code a bit
confusing to read)
Comment 2 Andrew Dunbar 2006-06-04 20:44:25 UTC
A response to Darkoneko's comments:

> the user name is in : id="pt-userpage" > A > text node

This one does seem simple. I use this:

document.getElementById('pt-userpage').getElementsByTagName('a').item(0).firstChild.nodeValue;

> the page name is in : id="ca-nstab-main" > A > HREF parameter

This one is not so simple. Not every page has "ca-nstab-main". I use this:

document.getElementById('p-cactions').getElementsByTagName('ul').item(0).getElementsByTagName('li').item(0).firstChild.href;

Specifically, we need something which works on all skins, whether viewing,
diffing, editing, previewing, etc.

We might also have to think about what, if anything, it should return on special
pages.
Comment 3 Andrew Dunbar 2006-08-05 13:37:08 UTC
I just noticed this new javascript section today:

<script type= "text/javascript">
var skin = "monobook";
var stylepath = "/skins-1.5";

var wgArticlePath = "/wiki/$1";
var wgScriptPath = "/w";
var wgServer = "http://en.wiktionary.org";
                        
var wgCanonicalNamespace = "";
var wgPageName = "south-south-east";
var wgTitle = "south-south-east";
var wgArticleId = 201743;
                        
var wgUserName = "Hippietrail";
var wgUserLanguage = "en";
var wgContentLanguage = "en";
</script>

It provides more than I asked for in a very nice way.
Comment 4 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-08-06 20:48:19 UTC
Fixed in r15871.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links