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