* Adding a trailing ?>
[lhc/web/wiklou.git] / maintenance / addwiki.php
index 060ff6c..253033a 100644 (file)
@@ -6,7 +6,7 @@ require_once( "commandLine.inc" );
 require_once( "rebuildInterwiki.inc" );
 require_once( "languages/Names.php" );
 if ( count( $args ) != 3 ) {
-       die( "Usage: php addwiki.php <language> <site> <dbname>\n" );
+       wfDie( "Usage: php addwiki.php <language> <site> <dbname>\n" );
 }
 
 addWiki( $args[0], $args[1], $args[2] );
@@ -15,7 +15,7 @@ addWiki( $args[0], $args[1], $args[2] );
 
 function addWiki( $lang, $site, $dbName )
 {
-       global $IP, $wgLanguageNames;
+       global $IP, $wgLanguageNames, $wgDefaultExternalStore;
 
        $name = $wgLanguageNames[$lang];
 
@@ -24,6 +24,7 @@ function addWiki( $lang, $site, $dbName )
        $maintenance = "$IP/maintenance";
 
        print "Creating database $dbName for $lang.$site\n";
+       
        # Set up the database
        $dbw->query( "SET table_type=Innodb" );
        $dbw->query( "CREATE DATABASE $dbName" );
@@ -34,6 +35,26 @@ function addWiki( $lang, $site, $dbName )
        dbsource( "$IP/extensions/OAI/update_table.sql", $dbw );
        $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
 
+       # Initialise external storage
+       if ( $wgDefaultExternalStore && preg_match( '!^DB://(.*)$!', $wgDefaultExternalStore, $m ) ) {
+               print "Initialising external storage...\n";
+               require_once( 'ExternalStoreDB.php' );
+               global $wgDBuser, $wgDBpassword, $wgExternalServers;
+               $cluster = $m[1];
+               
+               # Hack
+               $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
+               $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
+               
+               $store = new ExternalStoreDB;
+               $extdb =& $store->getMaster( $cluster );
+               $extdb->query( "SET table_type=InnoDB" );
+               $extdb->query( "CREATE DATABASE $dbName" );
+               $extdb->selectDB( $dbName );
+               dbsource( "$maintenance/storage/blobs.sql", $extdb );
+               $extdb->immediateCommit();
+       }
+
        $wgTitle = Title::newMainPage();
        $wgArticle = new Article( $wgTitle );
        $ucsite = ucfirst( $site );
@@ -176,7 +197,7 @@ See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedia
        $tempname = tempnam( '/tmp', 'addwiki' );
        $file = fopen( $tempname, 'w' );
        if ( !$file ) {
-               die( "Error, unable to open temporary file $tempname\n" );
+               wfDie( "Error, unable to open temporary file $tempname\n" );
        }
        fwrite( $file, $sql );
        fclose( $file );
@@ -186,3 +207,4 @@ See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedia
 
        print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";
 }
+?>