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() {
36 parent
::__construct();
37 $this->mDescription
= "Add a new wiki to the family. Wikimedia specific!";
38 $this->addArg( 'language', 'Language code of new site, e.g. en' );
39 $this->addArg( 'site', 'Type of site, e.g. wikipedia' );
40 $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' );
41 $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' );
46 public function getDbType() {
47 return Maintenance
::DB_ADMIN
;
50 public function execute() {
51 global $IP, $wgDefaultExternalStore;
53 $lang = $this->getArg( 0 );
54 $site = $this->getArg( 1 );
55 $dbName = $this->getArg( 2 );
56 $domain = $this->getArg( 3 );
57 $languageNames = Language
::getLanguageNames();
59 if ( !isset( $languageNames[$lang] ) ) {
60 $this->error( "Language $lang not found in \$wgLanguageNames", true );
62 $name = $languageNames[$lang];
64 $dbw = wfGetDB( DB_MASTER
);
65 $common = "/home/wikipedia/common";
67 $this->output( "Creating database $dbName for $lang.$site ($name)\n" );
70 $dbw->query( "SET table_type=Innodb" );
71 $dbw->query( "CREATE DATABASE $dbName" );
72 $dbw->selectDB( $dbName );
74 $this->output( "Initialising tables\n" );
75 $dbw->sourceFile( $this->getDir() . '/tables.sql' );
76 $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" );
77 $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" );
78 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" );
79 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" );
80 $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" );
81 $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
82 $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
83 $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
84 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.sql" );
85 $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" );
86 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTrackingEvents.sql" );
87 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTracking.sql" );
88 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql" );
89 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/OptIn/OptIn.sql" );
91 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
93 # Initialise external storage
94 if ( is_array( $wgDefaultExternalStore ) ) {
95 $stores = $wgDefaultExternalStore;
96 } elseif ( $stores ) {
97 $stores = array( $wgDefaultExternalStore );
101 if ( count( $stores ) ) {
102 global $wgDBuser, $wgDBpassword, $wgExternalServers;
103 foreach ( $stores as $storeURL ) {
105 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
110 $this->output( "Initialising external storage $cluster...\n" );
113 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
114 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
116 $store = new ExternalStoreDB
;
117 $extdb = $store->getMaster( $cluster );
118 $extdb->query( "SET table_type=InnoDB" );
119 $extdb->query( "CREATE DATABASE $dbName" );
120 $extdb->selectDB( $dbName );
123 $blobsTable = $store->getTable( $extdb );
124 $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql";
125 $blobsFile = popen( $sedCmd, 'r' );
126 $extdb->sourceStream( $blobsFile );
127 pclose( $blobsFile );
132 $title = Title
::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() );
133 $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" );
134 $article = new Article( $title );
135 $ucsite = ucfirst( $site );
137 $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY
);
139 $this->output( "Adding to dblists\n" );
142 $file = fopen( "$common/all.dblist", "a" );
143 fwrite( $file, "$dbName\n" );
146 # Update the sublists
147 shell_exec( "cd $common && ./refresh-dblist" );
149 # print "Constructing interwiki SQL\n";
150 # Rebuild interwiki tables
151 # passthru( '/home/wikipedia/conf/interwiki/update' );
153 $time = wfTimestamp( TS_RFC2822
);
154 // These arguments need to be escaped twice: once for echo and once for at
155 $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) );
156 $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) );
157 $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) );
158 $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) );
159 $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) );
160 $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) );
161 shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" );
163 $this->output( "Script ended. You still have to:
164 * Add any required settings in InitialiseSettings.php
165 * Run sync-common-all
166 * Run /home/wikipedia/conf/interwiki/update
170 private function getFirstArticle( $ucsite, $name ) {
172 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
174 * 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.
176 * 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]].
178 * 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]].
180 == Sister projects ==
181 <span class="plainlinks">
182 [http://www.wikipedia.org Wikipedia] |
183 [http://www.wiktionary.org Wiktonary] |
184 [http://www.wikibooks.org Wikibooks] |
185 [http://www.wikinews.org Wikinews] |
186 [http://www.wikiquote.org Wikiquote] |
187 [http://www.wikisource.org Wikisource]
188 [http://www.wikiversity.org Wikiversity]
191 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
469 $maintClass = "AddWiki";
470 require_once( RUN_MAINTENANCE_IF_MAIN
);