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 

Docs on the web
Documentation on Templates can be found here: Documentation on AWB: Feel free to add more.
 * meta.wikimedia.org Help:Templates
 * www.mediawiki.org Extension:StringFunctions
 * help.wikia.com Help:Extensions (those are installed here)
 * Wikipedia Wikipedia:AutoWikiBrowser

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 link to the Perl mediawiki framework and maybe a page that explains how to set it up? Perhaps rename "Docs on the Web" to "useful links" while you're at it? ;-) --mendel 07:28, 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)