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