5 require_once( "commandLine.inc" );
6 require_once( "rebuildInterwiki.inc" );
7 require_once( "languages/Names.php" );
8 if ( count( $args ) != 3 ) {
9 wfDie( "Usage: php addwiki.php <language> <site> <dbname>\n" );
12 addWiki( $args[0], $args[1], $args[2] );
14 # -----------------------------------------------------------------
16 function addWiki( $lang, $site, $dbName )
18 global $IP, $wgLanguageNames, $wgDefaultExternalStore;
20 $name = $wgLanguageNames[$lang];
22 $dbw = wfGetDB( DB_WRITE
);
23 $common = "/home/wikipedia/common";
24 $maintenance = "$IP/maintenance";
26 print "Creating database $dbName for $lang.$site\n";
29 $dbw->query( "SET table_type=Innodb" );
30 $dbw->query( "CREATE DATABASE $dbName" );
31 $dbw->selectDB( $dbName );
33 print "Initialising tables\n";
34 dbsource( "$maintenance/tables.sql", $dbw );
35 dbsource( "$IP/extensions/OAI/update_table.sql", $dbw );
36 dbsource( "$IP/extensions/AntiSpoof/mysql/patch-antispoof.sql", $dbw );
37 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
39 # Initialise external storage
40 if ( is_array( $wgDefaultExternalStore ) ) {
41 $stores = $wgDefaultExternalStore;
42 } elseif ( $stores ) {
43 $stores = array( $wgDefaultExternalStore );
47 if ( count( $stores ) ) {
48 require_once( 'ExternalStoreDB.php' );
49 print "Initialising external storage $store...\n";
50 global $wgDBuser, $wgDBpassword, $wgExternalServers;
51 foreach ( $stores as $storeURL ) {
53 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
60 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
61 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
63 $store = new ExternalStoreDB
;
64 $extdb =& $store->getMaster( $cluster );
65 $extdb->query( "SET table_type=InnoDB" );
66 $extdb->query( "CREATE DATABASE $dbName" );
67 $extdb->selectDB( $dbName );
68 dbsource( "$maintenance/storage/blobs.sql", $extdb );
69 $extdb->immediateCommit();
73 $wgTitle = Title
::newMainPage();
74 $wgArticle = new Article( $wgTitle );
75 $ucsite = ucfirst( $site );
77 $wgArticle->insertNewArticle( "
78 ==This subdomain is reserved for the creation of a $ucsite in '''[[:en:{$name}|{$name}]]''' language==
80 If you can write in this language and want to collaborate in the creation of this encyclopedia then '''you''' can make it.
82 Go ahead. Translate this page and start working on your encyclopedia.
84 For help, see '''[[m:Help:How to start a new Wikipedia|how to start a new Wikipedia]]'''.
87 [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]
89 See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedias.
197 ", '', false, false );
199 print "Adding to dblists\n";
202 $file = fopen( "$common/all.dblist", "a" );
203 fwrite( $file, "$dbName\n" );
206 # Update the sublists
207 system("cd $common && ./refresh-dblist");
209 print "Constructing interwiki SQL\n";
210 # Rebuild interwiki tables
211 $sql = getRebuildInterwikiSQL();
212 $tempname = tempnam( '/tmp', 'addwiki' );
213 $file = fopen( $tempname, 'w' );
215 wfDie( "Error, unable to open temporary file $tempname\n" );
217 fwrite( $file, $sql );
219 print "Sourcing interwiki SQL\n";
220 dbsource( $tempname, $dbw );
221 #unlink( $tempname );
223 # Create the upload dir
224 global $wgUploadDirectory;
225 if( file_exists( $wgUploadDirectory ) ) {
226 echo "$wgUploadDirectory already exists.\n";
228 echo "Creating $wgUploadDirectory...\n";
229 mkdir( $wgUploadDirectory, 0777 );
230 chmod( $wgUploadDirectory, 0777 );
233 print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";