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