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
26 * @ingroup Maintenance
30 require_once( dirname( __FILE__
) . '/Maintenance.php' );
32 class AddWiki
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->mDescription
= "Add a new wiki to the family. Wikimedia specific!";
36 $this->addArg( 'language', 'Language code of new site' );
37 $this->addArg( 'site', 'Type of site' );
38 $this->addArg( 'dbname', 'Name of database to create' );
41 public function getDbType() {
42 return Maintenance
::DB_ADMIN
;
45 public function execute() {
46 global $IP, $wgDefaultExternalStore, $wgNoDBParam;
49 $lang = $this->getArg( 0 );
50 $site = $this->getArg( 1 );
51 $dbName = $this->getArg( 2 );
52 $languageNames = Language
::getLanguageNames();
54 if ( !isset( $languageNames[$lang] ) ) {
55 $this->error( "Language $lang not found in \$wgLanguageNames", true );
57 $name = $languageNames[$lang];
59 $dbw = wfGetDB( DB_MASTER
);
60 $common = "/home/wikipedia/common";
62 $this->output( "Creating database $dbName for $lang.$site ($name)\n" );
65 $dbw->query( "SET table_type=Innodb" );
66 $dbw->query( "CREATE DATABASE $dbName" );
67 $dbw->selectDB( $dbName );
69 $this->output( "Initialising tables\n" );
70 $dbw->sourceFile( $this->getDir() . '/tables.sql' );
71 $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" );
72 $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" );
73 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" );
74 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" );
75 $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" );
76 $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
77 $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
78 $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
79 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.sql" );
80 $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" );
81 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTrackingEvents.sql" );
82 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTracking.sql" );
83 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql" );
84 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/Optin/OptIn.sql" );
86 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
88 # Initialise external storage
89 if ( is_array( $wgDefaultExternalStore ) ) {
90 $stores = $wgDefaultExternalStore;
91 } elseif ( $stores ) {
92 $stores = array( $wgDefaultExternalStore );
96 if ( count( $stores ) ) {
97 global $wgDBuser, $wgDBpassword, $wgExternalServers;
98 foreach ( $stores as $storeURL ) {
100 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
105 $this->output( "Initialising external storage $cluster...\n" );
108 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
109 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
111 $store = new ExternalStoreDB
;
112 $extdb = $store->getMaster( $cluster );
113 $extdb->query( "SET table_type=InnoDB" );
114 $extdb->query( "CREATE DATABASE $dbName" );
115 $extdb->selectDB( $dbName );
118 $blobsTable = $store->getTable( $extdb );
119 $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql";
120 $blobsFile = popen( $sedCmd, 'r' );
121 $extdb->sourceStream( $blobsFile );
122 pclose( $blobsFile );
127 global $wgTitle, $wgArticle;
128 $wgTitle = Title
::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
129 $this->output( "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n" );
130 $wgArticle = new Article( $wgTitle );
131 $ucsite = ucfirst( $site );
133 $wgArticle->insertNewArticle( $this->getFirstArticle( $ucsite, $name ), '', false, false );
135 $this->output( "Adding to dblists\n" );
138 $file = fopen( "$common/all.dblist", "a" );
139 fwrite( $file, "$dbName\n" );
142 # Update the sublists
143 shell_exec( "cd $common && ./refresh-dblist" );
145 # print "Constructing interwiki SQL\n";
146 # Rebuild interwiki tables
147 # passthru( '/home/wikipedia/conf/interwiki/update' );
149 $this->output( "Script ended. You still have to:
150 * Add any required settings in InitialiseSettings.php
151 * Run sync-common-all
152 * Run /home/wikipedia/conf/interwiki/update
156 private function getFirstArticle( $ucsite, $name ) {
158 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
160 * 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.
162 * 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]].
164 * 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]].
166 == Sister projects ==
167 <span class="plainlinks">
168 [http://www.wikipedia.org Wikipedia] |
169 [http://www.wiktionary.org Wiktonary] |
170 [http://www.wikibooks.org Wikibooks] |
171 [http://www.wikinews.org Wikinews] |
172 [http://www.wikiquote.org Wikiquote] |
173 [http://www.wikisource.org Wikisource]
174 [http://www.wikiversity.org Wikiversity]
177 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
455 $maintClass = "AddWiki";
456 require_once( DO_MAINTENANCE
);