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