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

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, raw, raw with templates processed
 * http://trac.wikia-code.com/ if you ever want to browse wikia source...

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

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.

List of Categories for AWB
How to make a list of a category page that can be loaded into AWB

Awk version

 * Getting/using awk
 * get awk or gawk and install
 * make a work directory that is easy to find (e.g. C:\awk) and copy awk.exe there
 * open a command prompt, type CD \awk (if that is your work directory)
 * You can now run awk using

BEGIN{RS="<a href=\"/wiki/";FS="\""} { print $1; } --mendel 06:47, 11 June 2008 (UTC)
 * How to get the category list
 * save the category page with your browser (HTML only) to the work directory as category.htm
 * Usng notepad, save the following script as getlinks.awk:
 * run
 * open category.txt in notepad and clean the beginning and end
 * Make List from file in AWB
 * Tip: Save your settings before you import the list, saving the settings with the list loaded may corrupt them, making AWB not save

Perl version
Requires the Perlwikipedia module. Creates list in one step without needing to save an intermediate html file. Arguments to command-line are:, and insert your username where indicated in the script. This will generate a text file named .txt. Choose "Make from Text file" in AWB and select that file.


 * 1) !/usr/bin/perl

use strict; use Perlwikipedia;

my $user = ' '; ### REPLACE WITH YOUR USERNAME ### my $pass = $ARGV[0]; my $editor = Perlwikipedia->new($user); $editor->set_wiki('guildwars.wikia.com',''); my $status = $editor->login($user, $pass); if ($status) { die "Login failed: $editor->{errstr}\n"; }
 * 1) Create a Perlwikipedia object, login

my $cat = $ARGV[1];
 * 1) Read the category name from command line

my @all_pages = $editor->get_pages_in_category("Category:$cat");
 * 1) Get all pages in the category

open(OFP, ">$cat.txt") or die "can't open output file: $!\n"; foreach my $article (@all_pages) { print OFP "$article\n"; } close(OFP); &mdash;Dr Ishmael 21:38, 14 June 2008 (UTC)
 * The awk script may be more efficient for large categories.
 * If you are using Windows and have neither gawk nor Perl installed, gawk would be quicker to set up.
 * Is there a story behind those two bullet points? Because if there isn't, I'd have to extend the awk advice to note that Perl is probably the more useful language to learn. --mendel 07:00, 15 June 2008 (UTC)
 * Story? No, not that I know of...  I was just trying to be non-competetive and think of good reasons why the awk version might be preferred over Perl, as counterpoints to the fact that the Perl version does everything in a single step.  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 07:09, 15 June 2008 (UTC)
 * I believe the best way to be noncompetitive is to just juxtapose the two versions and leave the comparison to the reader; it is pretty obvious that whoever has the language/tool in question installed is going to use what he/she finds familiar.
 * Start a new section: "advantages of awk"? Refine my script so it matches the Template URLs better? Does your first bullet indicate that $editor->get_pages_in_category("Category:$cat"); may take awhile on big categories? Could you add the link to the Perl mediawiki framework and maybe Perl itself to "Docs on the Web" and rename that to "useful links" while you're at it? ;-) --mendel 07:28, 15 June 2008 (UTC)
 * Since it has to load the Category pages from the web every time it runs, it depends on how responsive the server is, but that's almost always slower than reading from a file. Still, for the awk method you have to load those pages manually, anyway, so I guess there's not much difference there.  &mdash;Dr Ishmael [[Image:Diablo_the_chicken.gif]] 16:48, 15 June 2008 (UTC)

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 ifexist 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)

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)