User:LeucosticteBot/ChangeWikiaEngine.php
Jump to navigation
Jump to search
This bot looks for pages that have a url with .wikia.com in them, and changes the wiki engine to wikia.
<?php
/*
* ChangeWikiaEngine.php
* By Leucosticte, https://www.mediawiki.org/wiki/User:Leucosticte
* GPL 2.0
*
* This bot looks for pages that have a url with .wikia.com in them, and changes the wiki engine to
* wikia.
/*
/* Setup my classes. */
include( 'botclasses.php' );
$wiki = new wikipedia;
$wiki->url = "http://wikiindex.org/api.php";
/* All the login stuff. */
$user = 'LeucosticteBot';
$pass = 'REMOVED';
$wiki->login( $user, $pass );
// Configuration
$pageTitlesFile = 'CategoryMembers.txt';
// Test file existence
if ( !file_exists ( $pageTitlesFile ) ) {
die ( "File $pageTitlesFile not found" );
}
// Read files
$lines = file( $pageTitlesFile, FILE_IGNORE_NEW_LINES );
// Each line is a wiki page
foreach ( $lines as $line ) {
// Poll to get wiki page content
$contents = $wiki->getpage ( $line );
// A template line with data will start with a |, e.g. |URL = wikiindex.org
if ( $begin = strpos ( $contents, '|URL' ) ) {
if ( $equals = strpos ( $contents, '=', $begin ) ) {
$closingBrace = strpos ( $contents, "}}", $equals );
// End this string at the newline or the }} (closing the template), whichever
// comes first
$newline = strpos ( $contents, "\n", $equals );
if ( $closingBrace && $closingBrace < $newline ) {
$newline = $closingBrace;
}
if ( $newline ) {
$url = trim( substr ( $contents, $equals + 1,
$newline - $equals - 1 ) );
}
}
}
// If the URL contains .wikia.com, then replace the engine, if necessary
if ( strpos ( $url, '.wikia.com' ) ) {
if ( $begin = strpos ( $contents, '|engine' ) ) {
if ( $equals = strpos ( $contents, '=', $begin ) ) {
$closingBrace = strpos ( $contents, "}}", $equals );
// End this string at the newline or the }} (closing the template), whichever
// comes first
$newline = strpos ( $contents, "\n", $equals );
if ( $closingBrace && $closingBrace < $newline ) {
$newline = $closingBrace;
}
if ( $newline ) {
$mediawiki = strpos ( $contents, 'MediaWiki', $equals );
if ( $mediawiki && $mediawiki < $newline ) {
$contents = substr_replace ( $contents, 'Wikia', $mediawiki, 9 );
echo $contents;
$wiki->edit( $line, $contents, 'Robot: Changing engine. MediaWiki -> Wikia' );
}
}
}
}
}
}