GuildWiki

GuildWiki has been locked down: anonymous editing and account creation are disabled. Current registered users are unaffected. Leave any comments on the Community Portal.

READ MORE

GuildWiki
m (New page: ==Description== This script moves all articles in one category to another category. *Language: [http://www.perl.org Perl] **Uses the module [http://code.google.com/p/perlwikipedia/ Perlwi...)
 
m (AWB has built-in functions for image/cat replacement)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Description==
 
==Description==
This script moves all articles in one category to another category.
+
This task is for the quick updating of links to an article, image, or category that has been moved to a new name.
   
  +
*Tool: [[wikipedia:WP:AWB|AWB]]
*Language: [http://www.perl.org Perl]
 
**Uses the module [http://code.google.com/p/perlwikipedia/ Perlwikipedia] for most wiki interface tasks.
 
*Throttle: 360 edits/hour (10 seconds between edits)
 
   
  +
In order to prevent false positives where a longer article name contains a shorter one (e.g. [[:Category:Mursaat]] is contained in [[:Category:Mursaat Bosses]]), each of the replacement operations given below will actually consist of three find/replace rules, one for each of the possible characters that can follow an article name in a wikilink.
==Process==
 
For moving articles from "Category:Monk Bosses" to "Category:Monk bosses":
 
#Gets list of articles from {{DeletedLink|:Category:Monk Bosses}}.
 
#For each article, performs the following edit:
 
#*<code>[[Category:Monk Bosses &rarr; [[Category:Monk bosses</code>
 
   
  +
:<code>[[old]</code> &rarr; <code>[[new]</code>
==Code==
 
  +
:<code>[[old|</code> &rarr; <code>[[new|</code>
<pre>
 
  +
:<code>[[old#</code> &rarr; <code>[[new#</code>
#!/usr/bin/perl
 
use strict;
 
   
  +
==Articles==
use Perlwikipedia;
 
  +
AWB will make a list from "What links here" to the old article name. On each page in this list, AWB will perform the following replacement:
   
  +
<code>[[Old Article Name</code> &rarr; <code>[[New article name</code>
# Read the category names from the command line
 
my $oldcat = $ARGV[1];
 
my $newcat = $ARGV[2];
 
   
  +
==Categories==
# Log file
 
  +
===Articles in category===
open (OFP, ">$0.log") or die "can't open log file: $!\n";
 
  +
Since AWB is currently unable to make a list from categories on Wikia wikis, the list of articles assigned to the old category will have to be manually saved to a local file (methods for doing so can be found [[Forum:Coding#List of Categories for AWB|here]]). Using the category task "Replaced category:", AWB will perform the following replacement:
print OFP "\n", "="x20, "\n";
 
{
 
my ($sec, $min, $hour, $day, $mon, $year) = (localtime)[0,1,2,3,4,5];
 
printf OFP "$0 starting at %2d:%02d:%02d %4d-%02d-%02d\n", $hour, $min, $sec, $year+1900, $mon+1, $day;
 
print OFP "Replacing Category:$oldname with Category:$newname\n";
 
}
 
   
  +
<code>Old Cat Name</code> &rarr; <code>New cat name</code>
# Create a Perlwikipedia object
 
my $user = 'Bot ishmael'; my $pass = $ARGV[0];
 
my $editor = Perlwikipedia->new($user);
 
   
  +
===Links to category===
# Turn debugging on, to see what the bot is doing
 
  +
AWB will make a list from "What links here" to the old category name. On each page in this list, AWB will perform the following replacement:
$editor->{debug} = 1;
 
   
 
<code>[[:Category:Old Cat Name</code> &rarr; <code>[[:Category:New cat name</code>
# Login to guildwiki
 
$editor->set_wiki('guildwars.wikia.com','');
 
my $status = $editor->login($user, $pass);
 
if ($status) { die "Login failed: $editor->{errstr}\n"; }
 
   
  +
==Images==
# Editing options
 
  +
===Image file links===
my $is_minor = 1;
 
  +
AWB will make a list from "Image file links" to the old image name. Using the image task "Replace image:", AWB will perform the following replacement:
my $edit_summary="Category rename: Category:$oldname -> [[Category:$newname]])";
 
   
  +
<code>Old Image Name</code> &rarr; <code>New image name</code>
# Get all pages in the old category
 
my @all_pages = $editor->get_pages_in_category("Category:$oldname");
 
   
  +
===Image page links===
foreach my $article (@all_pages) {
 
  +
AWB will make a list from "What links here" to the old image name. On each page in this list, AWB will perform the following replacement:
 
# Get the text of the article
 
my $text = $editor->get_text($article->{title});
 
 
# Replace the old category with the new one
 
$text =~ s/\[\]Category:$oldname(\|.*?|)\]\]/\[\]Category:$newname$1\]\]/gi;
 
# For cats with spaces in the name, look for underscore version too
 
if ($oldname =~ / /) {
 
$oldname =~ s/ /_/g;
 
$text =~ s/\[\[Category:$oldname(\|.*?|)\]\]/\[\[Category:$newname$1\]\]/gi;
 
}
 
 
# Save the article
 
$editor->edit($article, $text, $edit_summary, $is_minor);
 
   
  +
<code>[[:Image:Old Image Name</code> &rarr; <code>[[:Image:New image name</code>
# Record the edit
 
my ($sec, $min, $hour, $day, $mon, $year) = (localtime)[0,1,2,3,4,5];
 
printf OFP "%2d:%02d:%02d %4d-%02d-%02d\t%s\n", $hour, $min, $sec, $year+1900, $mon+1, $day, $article->{title};
 
 
# Wait 10 seconds before making another edit
 
sleep 10;
 
}
 
   
  +
==Templates==
{
 
  +
===Template transclusions===
my ($sec, $min, $hour, $day, $mon, $year) = (localtime)[0,1,2,3,4,5];
 
  +
AWB will make a list from "What transcludes page" to the old template name. On each page in this list, AWB will perform the following replacements:
printf OFP "\n$0 finishing at %2d:%02d:%02d %4d-%02d-%02d\n", $hour, $min, $sec, $year+1900, $mon+1, $day;
 
  +
}
 
  +
<code>{{Template:Old Template Name</code> &rarr; <code>{{Template:New template name</code>
close (OFP);
 
  +
</pre>
 
  +
<code>{{Old Template Name</code> &rarr; <code>{{New template name</code>
  +
  +
===Template page links===
  +
AWB will make a list from "What links here" to the old template name. On each page in this list, AWB will perform the following replacement:
  +
  +
<code>[[Template:Old Template Name</code> &rarr; <code>[[Template:New template name</code>
  +
  +
==Requests==
  +
Any requests for link updating can be posted on the talk page. Provide a link to both the old and the new page names.

Latest revision as of 13:33, 4 July 2008

Description[]

This task is for the quick updating of links to an article, image, or category that has been moved to a new name.

In order to prevent false positives where a longer article name contains a shorter one (e.g. Category:Mursaat is contained in Category:Mursaat Bosses), each of the replacement operations given below will actually consist of three find/replace rules, one for each of the possible characters that can follow an article name in a wikilink.

[[old][[new]
[[old|[[new|
[[old#[[new#

Articles[]

AWB will make a list from "What links here" to the old article name. On each page in this list, AWB will perform the following replacement:

[[Old Article Name[[New article name

Categories[]

Articles in category[]

Since AWB is currently unable to make a list from categories on Wikia wikis, the list of articles assigned to the old category will have to be manually saved to a local file (methods for doing so can be found here). Using the category task "Replaced category:", AWB will perform the following replacement:

Old Cat NameNew cat name

Links to category[]

AWB will make a list from "What links here" to the old category name. On each page in this list, AWB will perform the following replacement:

[[:Category:Old Cat Name[[:Category:New cat name

Images[]

Image file links[]

AWB will make a list from "Image file links" to the old image name. Using the image task "Replace image:", AWB will perform the following replacement:

Old Image NameNew image name

Image page links[]

AWB will make a list from "What links here" to the old image name. On each page in this list, AWB will perform the following replacement:

[[:Image:Old Image Name[[:Image:New image name

Templates[]

Template transclusions[]

AWB will make a list from "What transcludes page" to the old template name. On each page in this list, AWB will perform the following replacements:

{{Template:Old Template Name{{Template:New template name

{{Old Template Name{{New template name

Template page links[]

AWB will make a list from "What links here" to the old template name. On each page in this list, AWB will perform the following replacement:

[[Template:Old Template Name[[Template:New template name

Requests[]

Any requests for link updating can be posted on the talk page. Provide a link to both the old and the new page names.