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