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