Forum:Coding

__NEWSECTIONLINK__

Welcome to the Coding forum
This forum is dedicated to discussing matters of template and bot coding. These matters are now distributed across various talk pages, and it is hard to later find these gems of information. So how should we use this forum?
 * put it on the watchlist (duh)
 * post questions
 * post answers
 * post links to questions and answers elsewhere, new or old
 * post announcements and links to these
 * post requests for help with (debugging) templates or bots
 * anything else related to templates and bots

Watchlist
This forum won't fly if people aren't watching it. Please sign here (using three tildes, ) to indicate you do.
 * --mendel
 * &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]]
 * &mdash;[[Image:MaySig.png]] Warw/Wick
 * -- [[Image:merty_sign.gif]]-- ( talk )
 * -- Shadowphoenix 
 * Orite - I'm ment to sign Random Time
 * See RT's comment  &not; Wizårdbõÿ777  ( talk ) 09:00, 23 July 2008 (UTC)
 * I like new .css and .js hacks [[Image:Entropy Sig.jpg]] (T/C) 05:20, 3 August 2008 (UTC)
 * Silent fist of fury

Useful links

 * Forum:Coding/Javascript - handy Javascript functions to use in your personal .js file
 * CSS classes
 * Templates (may need some work)

MediaWiki features

 * meta.wikimedia.org Help:Templates
 * www.mediawiki.org Extension:StringFunctions
 * help.wikia.com Help:Extensions (those are installed here)
 * Parameters to index.php let you display the page in various ways: render, print, view with ads, view with Monobook skin, raw, raw with templates processed. action=purge can solve problems with caching.
 * http://trac.wikia-code.com/ if you ever want to browse wikia source...
 * Database dumps, especially the current pages, come in handy for searching the wiki offline.

AutoWikiBrowser

 * Wikipedia Wikipedia:AutoWikiBrowser

Perlwikipedia
You need a C (?) compiler and the utility make to get Perliwikipedia to run. These come free with MinGW or cygwin (see below).
 * Perlwikipedia module, a MediaWiki framework for Perl
 * Perl central
 * Active Perl, free Perl distribution for Windows

pywikipedia
User:Dantman has a fork of it, and some adapations linked on the userpage.

GNU tools for Windows
The GNU tools are a suite of powerful tools used by programmers around the world for decades. They have originally been written for a Unix-like operating system, but most of them have been "translated" to windows, usually from the same sources.
 * MinGW, a collection of tools for compiling C/C++ programs, including `make`, `gcc`, etc.
 * CygWin, a huge collection of GNU tools (the closest you can come to running GNU/Linux on Windows); includes Perl.
 * GnuWin32, a collection of useful tools that can be used separately. GnuWin32 doesn't include the gcc compiler, so you need to find a port of that elsewhere (e.g. in MingW).
 * gawk, a port of `awk`, is the tool mendel likes to use for quick automated text processing tasks.

Feel free to add more useful links.

Interwiki Transclusion
See User:KyleH. Since when is that possible? --mendel 01:39, 12 June 2008 (UTC)
 * Been a while, obviously. See Shared_templates. --mendel 12:36, 12 June 2008 (UTC)

Skill Bar and other stuff
--◄mendel► 14:35, 25 June 2008 (UTC)
 * 1) There is a workaround for #ifexist. Let's say article "redlink" doesn't exist. Then  is   to Template:redlink . Of course this costs a lot when "redlink" does in fact exist. However, it ought to work well on images as they typically have short articles if any. So.
 * 2) In finding that out, it helped that one can add action=raw&templates=expand&ctype=text/css to an URL to see the un-htmlized version of a page after template expansion. Are Mediawiki URL additions and options (liek action=raw and ctype) documented anywhere?
 * 3) Why did PanSola make Template:Skill_bar/doc when there is, in fact, no documentation on that page? Can anyone propose a simple way to find those templates that have no docs? including those that have a /doc with nothing on it? not even a stub tag or something? Hmm, probably comes down to parsing pages_current again.
 * 4) Is  used for user skills at all, or is it only supposed to be used for existing skills?   is not likely to work for any parameter outside mainspace, and in fact there is no article that starts with Image:User: . So the technique to get the correct image that I used in  could be ported to, and that would avoid the #ifexist entirely.
 * 5) We could then have skill bars for monsters and totally, like, not use.


 * Two errors in the code example you posted (that you are probably aware of anyway): first, you have to have a colon after #ifeq (#ifeq:); second, the first word of the image name will be titlecased by MediaWiki, so the second part of the comparison needs to reflect that ( :Image:Someimage.jpg  ).  So:.
 * mediawikiwiki:Manual:Parameters_to_index.php
 * Maybe he was planning on documenting it later, and "later" never came? I don't know how to easily find undocumented templates.
 * I'm pretty sure Skill bar is only used for existing skills, and removing the #ifexist: from Skill bar box would completely empty Category:Pages with too many expensive parser function calls.
 * I'd be for that, although we'd still need a separate template because monsters rarely need a full 8-skill bar, while the userpages that use it do expect a full 8-skill bar (a lot of them have "Optional"s in the middle of the bar). This "Monster skill bar" would only need a simple modification: each line that calls a Skill bar box would be wrapped with an #if:, like  .  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 04:23, 27 June 2008 (UTC)


 * 1. Hah! That's how you know I didn't copy and paste that code snippet!
 * 4. Let's just remove the #ifexist then!
 * 5. We could call that Template:Skillbar (and it wouldn't have  in it) (Yay for 7 closing braces!).It might be necessary to put a single  around all the #ifexist so that a stack of nonexistant boxes at the end doesn't add too many spaces to the last table cell. You can then express Template:Skill bar as   if it ever becomes necessary.
 * Actually, see User:M.mendel/Templates/Skillbar, User:M.mendel/Templates/Skillbar2 and User:M.mendel/Templates/Skill bar box.
 * I could write short articles on "Optional" (possibly redirect to "optional skill" and write that) and "generic resurrect". The cheapest fix to the missing monster skill icons is to do image redirects for them, going from Monster skill.
 * To fix the way Skillbar2 looks now, there are two options: a) undelete Template:Optional and write Template:empty and Template:Generic resurrect, or revert my Skill bar box to what it was before and use the image redirects for the monster skills. --◄mendel► 10:32, 27 June 2008 (UTC)

Color
There is a template called. It is deprecated. Instead we have now W-color, R-color etc. LordBiro once advocated doing that with CSS (and apparently that still works) - I would advocate that for pretty much the same reason. It causes no extra server headaches, and needs just a browser that can cope.

For template colors it seems to make sense to me to use templates without parameters, i.e., or even. The first version sorts better, the last reads better. These templates would just return the color code, i.e. they'd be extremely short and contain no parser function at all. We have 11 colors, in light, dark, possibly "border" and "background", and the new pale. The professions exist abbreviated and written out. (Whoever thought up these abbreviations ought to be stoned, why can't I just substring the first 2 letters? Argh!)

I am bringing this up because I want to experiment with a set of "pale" background colors, and I need to make templates for them. Unless we change site CSS. (Well, I guess I could experiment with personal CSS and change site CSS later...) And of course I need to use the long versions for input... :-( --◄mendel► 01:22, 30 June 2008 (UTC)

Skill box damage output Template
Ok, I need your advice here. I'm currently trying to clean up the Area of effect skills quick reference page. In this page the Template:Skill box damage output is used. However, the 'damage' column isn't needed here and all mentioned skill (-templates) don't have 'damage' filled in, so it will result in a list full of tags. My take on this is that there will be 3 options: What would you think ? What is common here, in such situations ? -- -- ( talk ) 11:59, 3 July 2008 (UTC)
 * 1) Drop use of this template, write your own table
 * 2) Copy existing template to new template, take damage column out (and maybe alter notes column too)
 * 3) Adjust existing template and insert clever trick to 'hide' damage column if needed


 * As a quick fix, I made the tags disappear when there is no damage. Is there anything that should be listed for these skills instead? --◄mendel► 12:43, 3 July 2008 (UTC)
 * Hey thanks Mendel, thats quick ! As far as I can see, I cannot think of anything that should be listed instead. Now we have an empty 'damage' column and 'note'. Ah well, at least its a start..ty :) -- [[Image:merty_sign.gif]]-- ( talk ) 09:37, 7 July 2008 (UTC)

Dialogue CSS
I would like to propose some CSS for Mediawiki:Common.css to easier format cutscene and other dialogues. div.dialogue p { text-indent:-4em; margin-left:4em; font-weight:bold; } div.dialogue p i { font-weight:normal; } See User_talk:Quizzical for the intended effect.

Quotation marks could be added with these two lines (if there's no bug) : div.dialogue p i:before { content:"\201C" } div.dialogue p i:after { content:"\201D" } --◄mendel► 21:37, 7 July 2008 (UTC)


 * I tested these lines on my global.css and they work (the quotes, too). --◄mendel► 13:22, 8 July 2008 (UTC)

Why does this work?
Q: Hey, I'm sort of teaching myself the different coding languages (got hung up on javascripting, bleh), and I was wondering why the code for the div class dialogue works. The code is, as follows: div.dialogue p { text-indent:-4em; margin-left:4em; font-weight:bold; } div.dialogue p i { font-weight:normal; } The answer I got to was that because of the javascript that already exists, each page is written in a way that the javascript sees the apostrophe and decides to write a paragraph style, either "p", "p i", or some other third "p" type for normal text. As I said before, I don't know how to code so I can't check the javascript file and see if I'm right or not. If you could enlighten me, it'd be greatly appreciated but, by all means, don't feel obligated. &mdash; Powersurge360  18:47, 13 August 2008 (UTC)

A: This has absolutely nothing to do with Javascript; it should work just as well when you turn Javascript off. (Well, on NN4.7 turning JS off also disabled CSS, but that was years ago in a galaxy far, far away). The CSS comes into effect after the wiki has converted the wikicode to HTML. The wiki converts regular text to paragraphs ( this is a paragraph  ) and apostrophes to italics tags ( this is italic text ). You can see this if you view the page source with your browser (provided you can find the text, you might want to use action=render to get rid of the wiki skin code ; see above on how to use that).

Now stylesheets (CSS) work by selecting a type of tag and specifying how content in that tag should be formatted. You can either put the format in the style="" attribute in the tag itself; or you can put it at the top of the HTML file; or you can import it at the top of the page file from another file. If you put p { color: red; } at the top of your HTML page or in a .css (like w:Special:MyPage/global.css), all text (all paragraphs) in the HTML that includes this style will be red. Headings won't be affected, because they aren't inside tags, they use, etc.

We need to select more specific paragraphs, though. div.dialogue p { text-indent:-4em; margin-left:4em; font-weight:bold; } means we select all tags that are directly inside a tag; and not just any tag, but it has to have class=dialogue. This means any paragraph text inside the is indented and bold.

Now one final adjustment is necessary: the text in italics should not be bold. Therefore, we use div.dialogue p i { font-weight:normal; } to select text that is inside  tags inside tags inside a with class=dialogue, and only that text is made to be not bold, but normal.

All this is being done by your CSS-compatible browser without any Javascript at all. --◄mendel► 19:18, 13 August 2008 (UTC)
 * Ok, so I didn't do too badly, I understood most of why it worked, but didn't quite get how the wikicode became HTML mark-up (assuming it was javascript as opposed to whatever it actually is). Thanks for moving/explaining it. &mdash; Powersurge360  19:21, 13 August 2008 (UTC)
 * Javascript can put additional HTML text on a page after the wiki has sent it to your browser (the nav boxes that show/hide work that way), but that's not the case here. --◄mendel► 19:28, 13 August 2008 (UTC)

Naming Convention for Templates
Do we have one? "BeastInfo", "QuestItem", "Skill box", "Effext box", "Shield begin info", "Quest-stub", "Unique-item-stub", "Location info", "CollectableCategory", "ElonianMissionProgression", "MonumentsNavBox". Guess we don't. --◄mendel► 05:35, 8 July 2008 (UTC)

Category list for AWB
As long as making a category list from within AWB doesn't work, you can use Special:Export to create a category list. Enter the category name into the top box, click "Add", copy the contents of the big edit box to a text file, and let AWb make a list from that.

For deprecated methods of generating a category list by scripting, see here in the page history.


 * AWB is now able to create lists from categories. Not sure if it was the new release of AWB 4.4.0.0 or Wikia's upgrade to MediaWiki 1.13, but at least it works.  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 02:06, 20 September 2008 (UTC)

Mini Database Dump
The Database dumps are quite big - editing a 250MB with a text editor is a daunting task. You can make a miniature database dump that contains just one page with Special:Export. Just enter the page name into the big box and click "Export". ("Save as file" doesn't work for me, though.) The XML file you get has exactly the same structure as our big database dumps. ◄mendel►

...makes four. Right? Well, it should. Apparently our version of MediaWiki doesn't have support to do exponentials. Is there perhaps some alternative workaround I could use in the meantime? Calculating a power manually is quite messy...

If a^(b(x)): ...and I'm trying to make a damage calculation template, so after that the user would then need to multiply by the Raw Damage. That is too much work for the user, I think.
 * 1) I evaluate b(x) (=c)
 * 2) Truncate the value (=d)
 * 3) Multiply a by itself d times
 * 4) Take the remainder after truncation by subtracting d from c (=e)
 * 5) Output to the user that they must manually multiply a by itself e times to finish the calculation

Maybe I should just go bug Kyle instead. (T/C) 06:56, 8 September 2008 (UTC)


 * Ok, I've done some digging. Meta documents powers (and logarithms and whatnot) since May 10th, albeit not on the m:Help:ParserFunctions page. They seem to be running ParserFunctions (Version 1.1.1), same as we. Ofcourse they're running MW 1.14a, and it seems that the calculations are somewhat dependent on the server OS as well. I'd wait until we get MW1.13 and file it as bug report then. ;-) (But since the database has just been locked, who knows? we may already have that.) 2^7= --◄mendel► 11:32, 8 September 2008 (UTC)


 * So close to achieving the ultimate dream of GuildWiki coders... :\ Other than this obstacle, I think User:Entropy/dcal should be ready for deployment soon. I wonder why it seemed so difficult before, it's really quite a simple thing to do if you put the data-gathering as the user's duty. To make it really really cool I would need to put in a whole listing of every damage source at the same, and a way to query its raw damage at a specified rank...etc. Lots of possible automation that I could add but it would make the template grow exponentially. (Pune.)
 * Random idea...I wonder if we could use an outside site to do the math? I know there is some template somewhere which puts out calls to an outside site for...timezone differences or something. [[Image:Entropy Sig.jpg]] (T/C) 14:42, 8 September 2008 (UTC)
 * Yeah, Template:TZ. <- Check it out. Then we would do http://WEBSITE_THAT_DOES_MATH_BASED_ON_URL_IMPUT.com?math=2^ or such.
 * Actually, if someone had their own website, it would probably be a lot easier to make a template that calls out everything to there and then the website returns the data to the template for display. I am sure it would be easier to code this without the restrictions of MediaWiki. Less drain on system resources also. [[Image:Entropy Sig.jpg]] (T/C) 14:50, 8 September 2008 (UTC)
 * The way that would work is to make it site Javascript and link to it from the sidebar. I envision someone clicking on a "damage calculator" sidebar link, then a small window pops up that lets you do the calculations.
 * Good default values are "12" for attributes, "60" for armor, and "20" for a level. That makes casters do 60 damage with no mods, (hope that's right - I am too lazy to check), so that'd be a good damage default for average weapons as well. --◄mendel► 17:06, 8 September 2008 (UTC)
 * Well I don't know how to write .JS unfortunately. I could do it in Visual :P Those are good default values, I was tired. [[Image:Entropy Sig.jpg]] (T/C) 23:49, 8 September 2008 (UTC)
 * Yay, it works now! Entropy gogogo! --◄mendel► 15:09, 10 September 2008 (UTC)
 * Cheers \o/\o/\o/ Once I'm done you can help me make it into a sidebar link or Monaco widget through .JS ! [[Image:Entropy Sig.jpg]] (T/C) 21:23, 10 September 2008 (UTC)
 * Damage template is done now. Moving to mainspace at Template:Damage. If someone can convert it into a cool .JS thing that would be awesome...maybe we can have our own damage calculator page. [[Image:Entropy Sig.jpg]] (T/C) 23:02, 10 September 2008 (UTC)

PAGESIZE not working
(Reset indent) The thing that does not yet work is, which works everywhere but our wiki (I tried central wikia and wowwiki), and the cause may be that I had created a template of that name - it's been deleted today, so I hope the server script run that gives us the wantedpages etc. fixes that. If not, somebody's got to totally wipe the page from the database. --◄mendel► 21:26, 10 September 2008 (UTC)
 * I don't see how that is totally relevant but ok. sizeof is a fun and useful function, but what would you do with it on Wikis? [[Image:Entropy Sig.jpg]] (T/C) 21:34, 10 September 2008 (UTC)


 * Well, sizeof does soemthing totally different in C, but anyhow.... what I want to do is tally up the size of Warwick's talkpage archives, and maybe automate that so we can compute some editcount/talkpage ratio for other users as well. More of a pastime, really. --◄mendel► 23:08, 10 September 2008 (UTC)
 * Right, so the talkpage is X Kb, you use sizeof to find the size in bytes of each talkpage, which is part of the Warwick's archives array. foreach(archive in warwick_archives){ sizeof(archive) } ... Anyway can't you just take the contents of the archive, stick it to MSWord, and use Word Count? I understand that you want to do it automated, but...meh. I think it's strange how there isn't already a MediaWiki function for this, since obviously the software has the capability to count page size. Else it couldn't give those messages at 32kb about archiving. [[Image:Entropy Sig.jpg]] (T/C) 23:24, 10 September 2008 (UTC)
 * Entropy, the MediaWiki Parserfunction that does this is called PAGESIZE, it is new with version 1.13, and it works on all Wikia wikis I've tested except ours. Do you want to copy & paste 49 pages, some quite huge, into a MSWORD document? I tried two approaches doing Wikitemplates, but ran into the processing limits imposed by the server because WarWick's archives are just too darn huge - and from those attempts stems the template that blocks the MediaWiki PAGESIZE from working, if my guess is right. Once it works, the oldest revision of User:Warwick/Archive size‎ just needs to have an #expr added that sums it all up. --◄mendel► 23:39, 10 September 2008 (UTC)
 * "I think it's strange how there isn't already a MediaWiki function for this" before MediaWiki 1.13. I understand that you may be frustrated but why take it out on the ignorant? :\ [[Image:Entropy Sig.jpg]] (T/C) 23:41, 10 September 2008 (UTC)
 * I've reported the issue, seems today I find a lot of wikis with the problem when yesterday there wasn't one. --◄mendel► 10:33, 11 September 2008 (UTC)

JS for redirect=no
I'd find a piece of JS useful that adds "?redirect=no" to all URLs on a page that don't have a question mark in them, and mayve "&redirect=no" to the URLs that do. It could be called via an extra tab. This would enable me to go to skill icon page from a skill page without triggering the redirect and attendant page load first. --◄mendel► 10:35, 13 September 2008 (UTC)
 * Minorly related question, but what is the difference between a "?function" and a "&function" call? I am also wondering if it would be more practical to instead make a piece of .JS that simply disables all redirects for you while it is on (so that you don't need to append URLs). [[Image:Entropy Sig.jpg]] (T/C) 18:41, 13 September 2008 (UTC)
 * In a URL, the "?" signifies the beginning of parameters that are not part of the actual URL. The "&" is used between parameters if you have more than one.  What Mendel's saying here is that for links that don't have parameters yet, the function would need to add "?redirect=no", and for those that do have parameters (that already have a "?" in the URL string), it needs to append this parameter to the existing set of parameters, as "&redirect=no" (so the full parameter list would be something like "?action=edit&redirect=no").  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 18:57, 13 September 2008 (UTC)
 * Thank you, doctor. Remains for me to clarify that the redirects are done by the server without knowledge of the browser, so you cannot actually use JavaScript to control the server directly. What you can control is the page URL for the next page, because that is sent by the browser software and can be rewritten by the Javascript before it is sent (i.e. before you click on that link). What I take you to mean is to make it a toggle, so you would not have to click it for each page, but you'd turn them off once, and they'd stay off until you turned them on again. Clever! --◄mendel► 21:35, 13 September 2008 (UTC)

the following was copied from Entropy's user talk


 * The magic word (no need for template) is part of the new MediaWiki parser engine - it was released alongside the old engine in 1.12.  Wikia hasn't forced anyone to switch to the new engine yet, although individual wikis can request it if they want it, but they are going to roll it out to everyone in the near future.  There's a page Special:ParserDiffTest where you can compare the way a page is rendered with the old and new engines (the biggest difference I've seen is that the new engine adds a "class='mw-redirect'" attribute to all links that link to redirect pages, could be useful if we ever wanted to trim our use of internal redirects).  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 22:52, 24 September 2008 (UTC)
 * Hey, could that be used for Forum:Coding?? Also, we have 1.13 now iirc, and I was talking about the magic word/template thing which gives a page's size in bytes, not return the URL or whatever. [[Image:Entropy Sig.jpg]] (T/C) 22:59, 24 September 2008 (UTC)
 * Right, Wikia is now on 1.13, I was saying that the new engine was first released in 1.12. And I meant , dunno why I typed "NAME". >.>
 * only refers to the name of the current page, so it wouldn't be of any use in creating "?redirect=no" links from a page. &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 23:05, 24 September 2008 (UTC)
 * I was talking of the class='mw-redirect' . [[Image:Entropy Sig.jpg]] (T/C) 23:08, 24 September 2008 (UTC)
 * Ohhhhh... I see. Yes, that would work.  There's a JS function   whereby you could get all links that had   and rewrite them to include  .  Brilliant!  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 23:25, 24 September 2008 (UTC)

Solution found? (T/C) 03:49, 25 September 2008 (UTC)

Sort keys for pages in categories
Sometimes you want a page to placed somewhere else in a category (a common case is when the pages have a common prefix and all get sorted under the same initial - you'd want them to sort by the part of the name that really matters). The way to do it is to add the sort key after the category, like so:  would sort this page in Category:Forums, it would be listed as "Forum:Coding" but display under C (not F), sorted after "Cobbling" and before "Cooking".

Articles that use several categories, or that get autosorted by templates, can use another way to set their sort key:  sets a default category sort key for the whole current page; it acts as if   was appended to every category anywhere on the page, including those put there by templates. --◄mendel► 21:48, 18 September 2008 (UTC)

Ugly hacks
Category:Ugly hacks is for code that does the job, but less than elegant - it may be hard to read, perform badly, or I may remain uncertain that it works correctly under all conditions. Putting a page in that category remains invisible on the page itself once we upgrade to the new parser. I strive to use a &lt;!-- comment --&gt; on the page to indicate the ugliness so that others can have a go at beautifying. --◄mendel► 05:50, 23 September 2008 (UTC)

rearranging the RC box
fieldset.rcoptions { border-style: none; margin: 0; padding: 0; } fieldset.rcoptions form table tr+tr { position:absolute; top:235px; left:330px; } See User_talk:JonTheMon/monobook.css. --◄mendel► 17:28, 29 October 2008 (UTC)

Recentchanges for WhatLinksHere ?
Try Special:RecentChangesLinked/Category:GuildWiki or (wtf?) or Special:RecentChangesLinked/User:M.mendel. --◄mendel► 18:05, 29 October 2008 (UTC)

mass edits outside RC
This procedure needs admin powers for the "import" step.
 * 1) Special:Export the articles that are to be edited
 * 2) strip Wikia's copyright message from them
 * 3) edit the articles
 * 4) make the date current
 * 5) change the summary
 * 6) change the author to yourself
 * 7) I am unsure what happens to the revision numbers
 * 8) Special:Import the bunch

I haven't tested it yet, though, so proceed at your own risk. --◄mendel► 23:19, 7 November 2008 (UTC)


 * Dubious. Why not use a bot? [[Image:Entropy Sig.jpg]] (T/C) 01:26, 8 November 2008 (UTC)