tableName calls moved inside fieldInfoMulti and removed call that existed only for...
[lhc/web/wiklou.git] / maintenance / addwiki.php
1 <?php
2 /**
3 * @defgroup Wikimedia Wikimedia
4 */
5
6 /**
7 * Add a new wiki
8 * Wikimedia specific!
9 *
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.
14 *
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.
19 *
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
24 *
25 * @file
26 * @ingroup Maintenance
27 * @ingroup Wikimedia
28 */
29
30 require_once( dirname(__FILE__) . '/Maintenance.php' );
31
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' );
39 }
40
41 protected function getDbType() {
42 return Maintenance::DB_ADMIN;
43 }
44
45 public function execute() {
46 global $IP, $wgLanguageNames, $wgDefaultExternalStore, $wgNoDBParam;
47
48 $wgNoDBParam = true;
49 $lang = $this->getArg(0);
50 $site = $this->getArg(1);
51 $dbName = $this->getArg(2);
52
53 if ( !isset( $wgLanguageNames[$lang] ) ) {
54 $this->error( "Language $lang not found in \$wgLanguageNames", true );
55 }
56 $name = $wgLanguageNames[$lang];
57
58 $dbw = wfGetDB( DB_MASTER );
59 $common = "/home/wikipedia/common";
60
61 $this->output( "Creating database $dbName for $lang.$site ($name)\n" );
62
63 # Set up the database
64 $dbw->query( "SET table_type=Innodb" );
65 $dbw->query( "CREATE DATABASE $dbName" );
66 $dbw->selectDB( $dbName );
67
68 $this->output( "Initialising tables\n" );
69 $dbw->sourceFile( $this->getDir() . '/tables.sql' );
70 $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" );
71 $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" );
72 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" );
73 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" );
74 $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" );
75 $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
76 $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
77 $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
78 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/PrefStats/PrefStats.sql" );
79 $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" );
80 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTrackingEvents.sql" );
81 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/ClickTracking/ClickTracking.sql" );
82 $dbw->sourceFile( "$IP/extensions/UsabilityInitiative/UserDailyContribs/UserDailyContribs.sql" );
83
84 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
85
86 # Initialise external storage
87 if ( is_array( $wgDefaultExternalStore ) ) {
88 $stores = $wgDefaultExternalStore;
89 } elseif ( $stores ) {
90 $stores = array( $wgDefaultExternalStore );
91 } else {
92 $stores = array();
93 }
94 if ( count( $stores ) ) {
95 global $wgDBuser, $wgDBpassword, $wgExternalServers;
96 foreach ( $stores as $storeURL ) {
97 $m = array();
98 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
99 continue;
100 }
101
102 $cluster = $m[1];
103 $this->output( "Initialising external storage $cluster...\n" );
104
105 # Hack
106 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
107 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
108
109 $store = new ExternalStoreDB;
110 $extdb = $store->getMaster( $cluster );
111 $extdb->query( "SET table_type=InnoDB" );
112 $extdb->query( "CREATE DATABASE $dbName" );
113 $extdb->selectDB( $dbName );
114
115 # Hack x2
116 $blobsTable = $store->getTable( $extdb );
117 $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql";
118 $blobsFile = popen( $sedCmd, 'r' );
119 $extdb->sourceStream( $blobsFile );
120 pclose( $blobsFile );
121 $extdb->commit();
122 }
123 }
124
125 global $wgTitle, $wgArticle;
126 $wgTitle = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
127 $this->output( "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n" );
128 $wgArticle = new Article( $wgTitle );
129 $ucsite = ucfirst( $site );
130
131 $wgArticle->insertNewArticle( $this->getFirstArticle( $ucsite, $name ), '', false, false );
132
133 $this->output( "Adding to dblists\n" );
134
135 # Add to dblist
136 $file = fopen( "$common/all.dblist", "a" );
137 fwrite( $file, "$dbName\n" );
138 fclose( $file );
139
140 # Update the sublists
141 shell_exec("cd $common && ./refresh-dblist");
142
143 #print "Constructing interwiki SQL\n";
144 # Rebuild interwiki tables
145 #passthru( '/home/wikipedia/conf/interwiki/update' );
146
147 $this->output( "Script ended. You still have to:
148 * Add any required settings in InitialiseSettings.php
149 * Run sync-common-all
150 * Run /home/wikipedia/conf/interwiki/update
151 " );
152 }
153
154 private function getFirstArticle( $ucsite, $name ) {
155 return <<<EOT
156 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
157
158 * 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
160 * 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
162 * 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
164 == Sister projects ==
165 <span class="plainlinks">
166 [http://www.wikipedia.org Wikipedia] |
167 [http://www.wiktionary.org Wiktonary] |
168 [http://www.wikibooks.org Wikibooks] |
169 [http://www.wikinews.org Wikinews] |
170 [http://www.wikiquote.org Wikiquote] |
171 [http://www.wikisource.org Wikisource]
172 [http://www.wikiversity.org Wikiversity]
173 </span>
174
175 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
176
177 [[aa:]]
178 [[ab:]]
179 [[ace:]]
180 [[af:]]
181 [[ak:]]
182 [[als:]]
183 [[am:]]
184 [[an:]]
185 [[ang:]]
186 [[ar:]]
187 [[arc:]]
188 [[arz:]]
189 [[as:]]
190 [[ast:]]
191 [[av:]]
192 [[ay:]]
193 [[az:]]
194 [[ba:]]
195 [[bar:]]
196 [[bat-smg:]]
197 [[bcl:]]
198 [[be:]]
199 [[be-x-old:]]
200 [[bg:]]
201 [[bh:]]
202 [[bi:]]
203 [[bm:]]
204 [[bn:]]
205 [[bo:]]
206 [[bpy:]]
207 [[br:]]
208 [[bs:]]
209 [[bug:]]
210 [[bxr:]]
211 [[ca:]]
212 [[cbk-zam:]]
213 [[cdo:]]
214 [[ce:]]
215 [[ceb:]]
216 [[ch:]]
217 [[cho:]]
218 [[chr:]]
219 [[chy:]]
220 [[ckb:]]
221 [[co:]]
222 [[cr:]]
223 [[crh:]]
224 [[cs:]]
225 [[csb:]]
226 [[cu:]]
227 [[cv:]]
228 [[cy:]]
229 [[da:]]
230 [[de:]]
231 [[diq:]]
232 [[dk:]]
233 [[dsb:]]
234 [[dv:]]
235 [[dz:]]
236 [[ee:]]
237 [[el:]]
238 [[eml:]]
239 [[en:]]
240 [[eo:]]
241 [[es:]]
242 [[et:]]
243 [[eu:]]
244 [[ext:]]
245 [[fa:]]
246 [[ff:]]
247 [[fi:]]
248 [[fiu-vro:]]
249 [[fj:]]
250 [[fo:]]
251 [[fr:]]
252 [[frp:]]
253 [[fur:]]
254 [[fy:]]
255 [[ga:]]
256 [[gan:]]
257 [[gd:]]
258 [[gl:]]
259 [[glk:]]
260 [[gn:]]
261 [[got:]]
262 [[gu:]]
263 [[gv:]]
264 [[ha:]]
265 [[hak:]]
266 [[haw:]]
267 [[he:]]
268 [[hi:]]
269 [[hif:]]
270 [[ho:]]
271 [[hr:]]
272 [[hsb:]]
273 [[ht:]]
274 [[hu:]]
275 [[hy:]]
276 [[hz:]]
277 [[ia:]]
278 [[id:]]
279 [[ie:]]
280 [[ig:]]
281 [[ii:]]
282 [[ik:]]
283 [[ilo:]]
284 [[io:]]
285 [[is:]]
286 [[it:]]
287 [[iu:]]
288 [[ja:]]
289 [[jbo:]]
290 [[jv:]]
291 [[ka:]]
292 [[kaa:]]
293 [[kab:]]
294 [[kg:]]
295 [[ki:]]
296 [[kj:]]
297 [[kk:]]
298 [[kl:]]
299 [[km:]]
300 [[kn:]]
301 [[ko:]]
302 [[kr:]]
303 [[ks:]]
304 [[ksh:]]
305 [[ku:]]
306 [[kv:]]
307 [[kw:]]
308 [[ky:]]
309 [[la:]]
310 [[lad:]]
311 [[lb:]]
312 [[lbe:]]
313 [[lg:]]
314 [[li:]]
315 [[lij:]]
316 [[lmo:]]
317 [[ln:]]
318 [[lo:]]
319 [[lt:]]
320 [[lv:]]
321 [[map-bms:]]
322 [[mdf:]]
323 [[mg:]]
324 [[mh:]]
325 [[mhr:]]
326 [[mi:]]
327 [[mk:]]
328 [[ml:]]
329 [[mn:]]
330 [[mo:]]
331 [[mr:]]
332 [[ms:]]
333 [[mt:]]
334 [[mus:]]
335 [[mwl:]]
336 [[my:]]
337 [[myv:]]
338 [[mzn:]]
339 [[na:]]
340 [[nan:]]
341 [[nap:]]
342 [[nds:]]
343 [[nds-nl:]]
344 [[ne:]]
345 [[new:]]
346 [[ng:]]
347 [[nl:]]
348 [[nn:]]
349 [[no:]]
350 [[nov:]]
351 [[nrm:]]
352 [[nv:]]
353 [[ny:]]
354 [[oc:]]
355 [[om:]]
356 [[or:]]
357 [[os:]]
358 [[pa:]]
359 [[pag:]]
360 [[pam:]]
361 [[pap:]]
362 [[pdc:]]
363 [[pi:]]
364 [[pih:]]
365 [[pl:]]
366 [[pms:]]
367 [[pnt:]]
368 [[pnb:]]
369 [[ps:]]
370 [[pt:]]
371 [[qu:]]
372 [[rm:]]
373 [[rmy:]]
374 [[rn:]]
375 [[ro:]]
376 [[roa-rup:]]
377 [[roa-tara:]]
378 [[ru:]]
379 [[rw:]]
380 [[sa:]]
381 [[sah:]]
382 [[sc:]]
383 [[scn:]]
384 [[sco:]]
385 [[sd:]]
386 [[se:]]
387 [[sg:]]
388 [[sh:]]
389 [[si:]]
390 [[simple:]]
391 [[sk:]]
392 [[sl:]]
393 [[sm:]]
394 [[sn:]]
395 [[so:]]
396 [[sq:]]
397 [[sr:]]
398 [[srn:]]
399 [[ss:]]
400 [[st:]]
401 [[stq:]]
402 [[su:]]
403 [[sv:]]
404 [[sw:]]
405 [[szl:]]
406 [[ta:]]
407 [[te:]]
408 [[tet:]]
409 [[tg:]]
410 [[th:]]
411 [[ti:]]
412 [[tk:]]
413 [[tl:]]
414 [[tn:]]
415 [[to:]]
416 [[tpi:]]
417 [[tr:]]
418 [[ts:]]
419 [[tt:]]
420 [[tum:]]
421 [[tw:]]
422 [[ty:]]
423 [[udm:]]
424 [[ug:]]
425 [[uk:]]
426 [[ur:]]
427 [[uz:]]
428 [[ve:]]
429 [[vec:]]
430 [[vi:]]
431 [[vls:]]
432 [[vo:]]
433 [[wa:]]
434 [[war:]]
435 [[wo:]]
436 [[wuu:]]
437 [[xal:]]
438 [[xh:]]
439 [[yi:]]
440 [[yo:]]
441 [[za:]]
442 [[zea:]]
443 [[zh:]]
444 [[zh-classical:]]
445 [[zh-min-nan:]]
446 [[zh-yue:]]
447 [[zu:]]
448
449 EOT;
450 }
451 }
452
453 $maintClass = "AddWiki";
454 require_once( DO_MAINTENANCE );