3 * @defgroup Wikimedia Wikimedia
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @ingroup Maintenance
29 require_once( dirname(__FILE__
) . '/Maintenance.php' );
31 class AddWiki
extends Maintenance
{
32 public function __construct() {
33 parent
::__construct();
34 $this->mDescription
= "Add a new wiki to the family. Wikimedia specific!";
35 $this->addArg( 'language', 'Language code of new site' );
36 $this->addArg( 'site', 'Type of site' );
37 $this->addArg( 'dbname', 'Name of database to create' );
40 protected function getDbType() {
41 return Maintenance
::DB_ADMIN
;
44 public function execute() {
45 global $IP, $wgLanguageNames, $wgDefaultExternalStore, $wgNoDBParam;
48 $lang = $this->getArg(0);
49 $site = $this->getArg(1);
50 $dbName = $this->getArg(2);
52 if ( !isset( $wgLanguageNames[$lang] ) ) {
53 $this->error( "Language $lang not found in \$wgLanguageNames", true );
55 $name = $wgLanguageNames[$lang];
57 $dbw = wfGetDB( DB_MASTER
);
58 $common = "/home/wikipedia/common";
60 $this->output( "Creating database $dbName for $lang.$site ($name)\n" );
63 $dbw->query( "SET table_type=Innodb" );
64 $dbw->query( "CREATE DATABASE $dbName" );
65 $dbw->selectDB( $dbName );
67 $this->output( "Initialising tables\n" );
68 $dbw->sourceFile( $this->getDir() . '/tables.sql' );
69 $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" );
70 $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" );
71 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" );
72 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" );
73 $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" );
74 $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
75 $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
76 $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
77 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.sql" );
78 $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" );
79 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTrackingEvents.sql" );
80 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTracking.sql" );
81 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql" );
83 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
85 # Initialise external storage
86 if ( is_array( $wgDefaultExternalStore ) ) {
87 $stores = $wgDefaultExternalStore;
88 } elseif ( $stores ) {
89 $stores = array( $wgDefaultExternalStore );
93 if ( count( $stores ) ) {
94 global $wgDBuser, $wgDBpassword, $wgExternalServers;
95 foreach ( $stores as $storeURL ) {
97 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
102 $this->output( "Initialising external storage $cluster...\n" );
105 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
106 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
108 $store = new ExternalStoreDB
;
109 $extdb = $store->getMaster( $cluster );
110 $extdb->query( "SET table_type=InnoDB" );
111 $extdb->query( "CREATE DATABASE $dbName" );
112 $extdb->selectDB( $dbName );
115 $blobsTable = $store->getTable( $extdb );
116 $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql";
117 $blobsFile = popen( $sedCmd, 'r' );
118 $extdb->sourceStream( $blobsFile );
119 pclose( $blobsFile );
120 $extdb->immediateCommit();
124 global $wgTitle, $wgArticle;
125 $wgTitle = Title
::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
126 $this->output( "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n" );
127 $wgArticle = new Article( $wgTitle );
128 $ucsite = ucfirst( $site );
130 $wgArticle->insertNewArticle( $this->getFirstArticle( $ucsite, $name ), '', false, false );
132 $this->output( "Adding to dblists\n" );
135 $file = fopen( "$common/all.dblist", "a" );
136 fwrite( $file, "$dbName\n" );
139 # Update the sublists
140 shell_exec("cd $common && ./refresh-dblist");
142 #print "Constructing interwiki SQL\n";
143 # Rebuild interwiki tables
144 #passthru( '/home/wikipedia/conf/interwiki/update' );
146 $this->output( "Script ended. You still have to:
147 * Add any required settings in InitialiseSettings.php
148 * Run sync-common-all
149 * Run /home/wikipedia/conf/interwiki/update
153 private function getFirstArticle( $ucsite, $name ) {
155 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
157 * Please '''do not start editing''' this new site. This site has a test project on the [[incubator:|Wikimedia Incubator]] (or on the [[betawikiversity:|BetaWikiversity]] or on the [[oldwikisource:|Old Wikisource]]) and it will be imported to here.
159 * If you would like to help translating the interface to this language, please do not translate here, but go to [[translatewiki:|translatewiki]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]].
161 * For information about how to edit and for other general help, see [[m:Help:Contents|Help on Wikimedia's Meta-Wiki]] or [[mw:Help:Contents|Help on MediaWiki.org]].
163 == Sister projects ==
164 <span class="plainlinks">
165 [http://www.wikipedia.org Wikipedia] |
166 [http://www.wiktionary.org Wiktonary] |
167 [http://www.wikibooks.org Wikibooks] |
168 [http://www.wikinews.org Wikinews] |
169 [http://www.wikiquote.org Wikiquote] |
170 [http://www.wikisource.org Wikisource]
171 [http://www.wikiversity.org Wikiversity]
174 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
452 $maintClass = "AddWiki";
453 require_once( DO_MAINTENANCE
);