mDescription = "Add a new wiki to the family. Wikimedia specific!"; $this->addArg( 'language', 'Language code of new site, e.g. en' ); $this->addArg( 'site', 'Type of site, e.g. wikipedia' ); $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' ); $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' ); $wgNoDBParam = true; } public function getDbType() { return Maintenance::DB_ADMIN; } public function execute() { global $IP, $wgDefaultExternalStore, $wmfVersionNumber; if ( !$wmfVersionNumber ) { // set in CommonSettings.php $this->error( '$wmfVersionNumber is not set, please use MWScript.php wrapper.', true ); } $lang = $this->getArg( 0 ); $site = $this->getArg( 1 ); $dbName = $this->getArg( 2 ); $domain = $this->getArg( 3 ); $languageNames = Language::getLanguageNames(); if ( !isset( $languageNames[$lang] ) ) { $this->error( "Language $lang not found in Names.php", true ); } $name = $languageNames[$lang]; $dbw = wfGetDB( DB_MASTER ); $common = "/home/wikipedia/common"; $this->output( "Creating database $dbName for $lang.$site ($name)\n" ); # Set up the database $dbw->query( "SET table_type=Innodb" ); $dbw->query( "CREATE DATABASE $dbName" ); $dbw->selectDB( $dbName ); $this->output( "Initialising tables\n" ); $dbw->sourceFile( $this->getDir() . '/tables.sql' ); $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" ); $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" ); $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" ); $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" ); $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" ); $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" ); $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" ); $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" ); $dbw->sourceFile( "$IP/extensions/PrefStats/patches/PrefStats.sql" ); $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" ); $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTrackingEvents.sql" ); $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTracking.sql" ); $dbw->sourceFile( "$IP/extensions/UserDailyContribs/patches/UserDailyContribs.sql" ); $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" ); # Initialise external storage if ( is_array( $wgDefaultExternalStore ) ) { $stores = $wgDefaultExternalStore; } elseif ( $wgDefaultExternalStore ) { $stores = array( $wgDefaultExternalStore ); } else { $stores = array(); } if ( count( $stores ) ) { global $wgDBuser, $wgDBpassword, $wgExternalServers; foreach ( $stores as $storeURL ) { $m = array(); if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { continue; } $cluster = $m[1]; $this->output( "Initialising external storage $cluster...\n" ); # 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 ); # Hack x2 $blobsTable = $store->getTable( $extdb ); $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql"; $blobsFile = popen( $sedCmd, 'r' ); $extdb->sourceStream( $blobsFile ); pclose( $blobsFile ); $extdb->commit(); } } $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() ); $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" ); $article = new Article( $title ); $ucsite = ucfirst( $site ); $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY ); $this->output( "Adding to dblists\n" ); # Add to dblist $file = fopen( "$common/all.dblist", "a" ); fwrite( $file, "$dbName\n" ); fclose( $file ); # Update the sublists shell_exec( "cd $common && ./refresh-dblist" ); # Add to wikiversions.dat $file = fopen( "$common/wikiversions.dat", "a" ); fwrite( $file, "$dbName php-$wmfVersionNumber\n" ); fclose( $file ); # Rebuild wikiversions.cdb shell_exec( "cd $common/multiversion && ./refreshWikiversionsCDB" ); # print "Constructing interwiki SQL\n"; # Rebuild interwiki tables # passthru( '/home/wikipedia/conf/interwiki/update' ); $time = wfTimestamp( TS_RFC2822 ); // These arguments need to be escaped twice: once for echo and once for at $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) ); $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) ); $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) ); $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) ); $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) ); $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) ); shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" ); $this->output( "Script ended. You still have to: * Add any required settings in InitialiseSettings.php * Run sync-common-all * Run /home/wikipedia/conf/interwiki/update " ); } private function getFirstArticle( $ucsite, $name ) { return << [http://www.wikipedia.org Wikipedia] | [http://www.wiktionary.org Wiktonary] | [http://www.wikibooks.org Wikibooks] | [http://www.wikinews.org Wikinews] | [http://www.wikiquote.org Wikiquote] | [http://www.wikisource.org Wikisource] [http://www.wikiversity.org Wikiversity] See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects. EOT; } } $maintClass = "AddWiki"; require_once( RUN_MAINTENANCE_IF_MAIN );