Bureaucrats, checkuser, Interface administrators, interwiki, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), staff, Suppressors, Administrators
83,693
edits
Leucosticte (talk | contribs) No edit summary |
Hoof Hearted (talk | contribs) m (minor tweaks) |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
This bot looks for pages that have a url with .wikia.com in them, and changes the wiki engine to | This bot script looks for pages that have a url with <tt>.wikia.com</tt> in them, and changes the wiki engine to Wikia. It iterates over the list of pages contained in CategoryMembers.txt. See [[mw:Manual:Chris G's botclasses/AllCategoryMembersBot.php]] for details on generating that file. | ||
< | <pre> | ||
<?php | <?php | ||
/* | /* | ||
* ChangeWikiaEngine.php | * ChangeWikiaEngine.php | ||
* By Leucosticte, https://www. | * By Leucosticte, https://www.MediaWiki.org/wiki/User:Leucosticte | ||
* GPL 2.0 | * GPL 2.0 | ||
* | * | ||
* This bot looks for pages that have a url with .wikia.com in them, and changes the wiki engine to | * This bot looks for pages that have a url with .wikia.com in them, and changes the wiki engine to | ||
* | * Wikia. | ||
/* | /* | ||
/* Setup my classes. */ | /* Setup my classes. */ | ||
include( 'botclasses.php' ); | include( 'botclasses.php' ); | ||
$wiki = | $wiki = WikiIndex; | ||
$wiki->url = " | $wiki->url = "https://WikiIndex.org/api.php"; | ||
/* All the login stuff. */ | /* All the login stuff. */ | ||
| Line 32: | Line 32: | ||
// Read files | // Read files | ||
$lines = file( $pageTitlesFile, FILE_IGNORE_NEW_LINES ); | $lines = file( $pageTitlesFile, FILE_IGNORE_NEW_LINES ); | ||
$startHere = 'Belligerent Universe Wiki'; // Resume where we left off | |||
// Each line is a wiki page | // Each line is a wiki page | ||
$thereYet = false; | |||
foreach ( $lines as $line ) { | foreach ( $lines as $line ) { | ||
// Poll to get wiki page content | if ( !$startHere || $thereYet || $line == $startHere ) { | ||
$thereYet = true; | |||
// 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 ) ) { | if ( $equals = strpos ( $contents, '=', $begin ) ) { | ||
$closingBrace = strpos ( $contents, "}}", $equals ); | $closingBrace = strpos ( $contents, "}}", $equals ); | ||
| Line 65: | Line 52: | ||
} | } | ||
if ( $newline ) { | if ( $newline ) { | ||
$mediawiki = strpos ( $contents, 'MediaWiki', $equals ); | $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' ); | |||
} | |||
} | } | ||
} | } | ||
| Line 76: | Line 81: | ||
} | } | ||
} | } | ||
</ | </pre> | ||
edits