* Adding a trailing ?>
[lhc/web/wiklou.git] / maintenance / addwiki.php
index 0a1f0cd..253033a 100644 (file)
@@ -1,21 +1,21 @@
 <?php
 
-$wgNoDBParam = true;   
-       
+$wgNoDBParam = true;
+
 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] ); 
+addWiki( $args[0], $args[1], $args[2] );
 
 # -----------------------------------------------------------------
 
 function addWiki( $lang, $site, $dbName )
 {
-       global $IP, $wgLanguageNames;
+       global $IP, $wgLanguageNames, $wgDefaultExternalStore;
 
        $name = $wgLanguageNames[$lang];
 
@@ -24,16 +24,37 @@ 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" );
        $dbw->selectDB( $dbName );
-       
+
        print "Initialising tables\n";
        dbsource( "$maintenance/tables.sql", $dbw );
        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 );
@@ -50,7 +71,7 @@ For help, see '''[[m:Help:How to start a new Wikipedia|how to start a new Wikipe
 ==Sister projects==
 [http://meta.wikipedia.org Meta-Wikipedia] | [http://www.wiktionary.org Wikitonary] | [http://www.wikibooks.org Wikibooks] | [http://www.wikinews.org Wikinews] | [http://www.wikiquote.org Wikiquote] | [http://www.wikisource.org Wikisource]
 
-See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedias. 
+See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedias.
 
 [[aa:]]
 [[af:]]
@@ -159,14 +180,14 @@ See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedia
 [[zh:]]
 [[zu:]]
 ", '', false, false );
-       
+
        print "Adding to dblists\n";
 
        # Add to dblist
        $file = fopen( "$common/all.dblist", "a" );
        fwrite( $file, "$dbName\n" );
        fclose( $file );
-       
+
        # Update the sublists
        system("cd $common && ./refresh-dblist");
 
@@ -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";
 }
+?>