Last modified: 2011-07-29 17:48:40 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 T25104, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 23104 - wgTemplates in JavaScript
wgTemplates in JavaScript
Status: NEW
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-09 08:38 UTC by Robin Krahl
Modified: 2011-07-29 17:48 UTC (History)
4 users (show)

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


Attachments

Description Robin Krahl 2010-04-09 08:38:44 UTC
It would be great to have a JavaScript variable containing the templates a page uses, similar to the new wgCategories variable. It should be an array with the data presented in the templatesUsed section below the edit box.
Comment 1 Trevor Parscal 2010-04-09 10:37:31 UTC
It would be better if we stopped using wg* variables. Ideally we would integrate more and more of this sort stuff into the mw object seen in the js2 stuff. mw.page.getCategories(); or mw.page.getTemplates(); for instance...

In the mean time, you could use a bit of jQuery like this (on the edit page only of course)

var wgTemplatesUsed = jQuery.map(
    $j( 'div.templatesUsed li a:first-child' ),
    function( n ) { return $j( n ).text(); }
);

- Trevor
Comment 2 The Evil IP address 2010-07-05 08:17:29 UTC
I agree that this would be quite good, either as wgTemplates or that stuff Trevor proposes here. However, there are already some options to get them.

The API lists them at
api.php?action=query&titles=Some_page_name&list=tl

or some stuff like that, just check out the documentation if it's wrong

If you only want to find out if one template is used, it may be easier to put an id or class within it. For example, at the German Wikipedia, the deletion template uses the id "Vorlage_Löschantragstext".

You could  then use

if (document.getElementById('Vorlage_Löschantragstext')) {
stuff to do if there's this template;
}
else {
something else;
}

However, the latter method of course has the disadvantage that people could just add the id without adding the template, so it's not as stable as the API result or a possible wgTemplates variable.
Comment 3 Roan Kattouw 2010-07-15 18:00:14 UTC
(In reply to comment #2)
> If you only want to find out if one template is used, it may be easier to put
> an id or class within it. For example, at the German Wikipedia, the deletion
> template uses the id "Vorlage_Löschantragstext".
> 
> You could  then use
> 
> if (document.getElementById('Vorlage_Löschantragstext')) {
> stuff to do if there's this template;
> }
> else {
> something else;
> }
> 
> However, the latter method of course has the disadvantage that people could
> just add the id without adding the template, so it's not as stable as the API
> result or a possible wgTemplates variable.
This is a very bad idea for a general solution, because 1) template names might be legitimate section names or conflict with other IDs and 2) not all template names are valid IDs

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


Navigation
Links