User:LeucosticteBot/ChangeWikiaEngine.php: Difference between revisions

m
minor tweaks
No edit summary
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 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.
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.


<source lang="php">
<pre>
<?php
<?php
/*
/*
  * ChangeWikiaEngine.php
  * ChangeWikiaEngine.php
  * By Leucosticte, https://www.mediawiki.org/wiki/User:Leucosticte
  * 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.
  * Wikia.
/*
/*


/* Setup my classes. */
/* Setup my classes. */
include( 'botclasses.php' );
include( 'botclasses.php' );
$wiki      = new wikipedia;
$wiki      = WikiIndex;
$wiki->url = "http://wikiindex.org/api.php";
$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 ) {
    $contents = $wiki->getpage ( $line );
        $thereYet = true;
    // A template line with data will start with a |, e.g. |URL = wikiindex.org
        // Poll to get wiki page content
    if ( $begin = strpos ( $contents, '|URL' ) ) {
        $contents = $wiki->getpage ( $line );
        if ( $equals = strpos ( $contents, '=', $begin ) ) {
        // A template line with data will start with a |, e.g. |URL = WikiIndex.org
            $closingBrace = strpos ( $contents, "}}", $equals );
        if ( $begin = strpos ( $contents, '|URL' ) ) {
            // 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 ) ) {
             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,
                    if ( $mediawiki && $mediawiki < $newline ) {
                        $newline - $equals - 1 ) );
                        $contents = substr_replace ( $contents, 'Wikia', $mediawiki, 9 );
                }
                        echo $contents;
            }
                        $wiki->edit( $line, $contents, 'Robot: Changing engine. MediaWiki -> Wikia' );
        }
        // 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:
     }
     }
}
}
</source>
</pre>