Updates for the modern age
[lhc/web/wiklou.git] / maintenance / addwiki.php
1 <?php
2 /**
3 * Add a new wiki
4 * Wikimedia specific!
5 *
6 * @file
7 * @ingroup Maintenance
8 */
9
10 $wgNoDBParam = true;
11
12 require_once( "commandLine.inc" );
13 require_once( "rebuildInterwiki.inc" );
14 require_once( "languages/Names.php" );
15 if ( count( $args ) != 3 ) {
16 wfDie( "Usage: php addwiki.php <language> <site> <dbname>\nThe site for Wikipedia is 'wikipedia'.\n" );
17 }
18
19 addWiki( $args[0], $args[1], $args[2] );
20
21 # -----------------------------------------------------------------
22
23 function addWiki( $lang, $site, $dbName )
24 {
25 global $IP, $wgLanguageNames, $wgDefaultExternalStore;
26
27 if ( !isset( $wgLanguageNames[$lang] ) ) {
28 print "Language $lang not found in \$wgLanguageNames\n";
29 return;
30 }
31 $name = $wgLanguageNames[$lang];
32
33 $dbw = wfGetDB( DB_MASTER );
34 $common = "/home/wikipedia/common";
35 $maintenance = "$IP/maintenance";
36
37 print "Creating database $dbName for $lang.$site ($name)\n";
38
39 # Set up the database
40 $dbw->query( "SET table_type=Innodb" );
41 $dbw->query( "CREATE DATABASE $dbName" );
42 $dbw->selectDB( $dbName );
43
44 print "Initialising tables\n";
45 dbsource( "$maintenance/tables.sql", $dbw );
46 dbsource( "$IP/extensions/OAI/update_table.sql", $dbw );
47 dbsource( "$IP/extensions/AntiSpoof/mysql/patch-antispoof.sql", $dbw );
48 dbsource( "$IP/extensions/CheckUser/cu_changes.sql", $dbw );
49 dbsource( "$IP/extensions/CheckUser/cu_log.sql", $dbw );
50 dbsource( "$IP/extensions/TitleKey/titlekey.sql", $dbw );
51 dbsource( "$IP/extensions/Oversight/hidden.sql", $dbw );
52
53 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
54
55 # Initialise external storage
56 if ( is_array( $wgDefaultExternalStore ) ) {
57 $stores = $wgDefaultExternalStore;
58 } elseif ( $stores ) {
59 $stores = array( $wgDefaultExternalStore );
60 } else {
61 $stores = array();
62 }
63 if ( count( $stores ) ) {
64 require_once( 'ExternalStoreDB.php' );
65 print "Initialising external storage $store...\n";
66 global $wgDBuser, $wgDBpassword, $wgExternalServers;
67 foreach ( $stores as $storeURL ) {
68 $m = array();
69 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
70 continue;
71 }
72
73 $cluster = $m[1];
74
75 # Hack
76 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
77 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
78
79 $store = new ExternalStoreDB;
80 $extdb =& $store->getMaster( $cluster );
81 $extdb->query( "SET table_type=InnoDB" );
82 $extdb->query( "CREATE DATABASE $dbName" );
83 $extdb->selectDB( $dbName );
84 dbsource( "$maintenance/storage/blobs.sql", $extdb );
85 $extdb->immediateCommit();
86 }
87 }
88
89 global $wgTitle, $wgArticle;
90 $wgTitle = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
91 print "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n";
92 $wgArticle = new Article( $wgTitle );
93 $ucsite = ucfirst( $site );
94
95 $wgArticle->insertNewArticle( <<<EOT
96 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
97
98 * 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.
99
100 * If you would like to help translating the interface to this language, please do not translate here, but go to [[betawiki:|Betawiki]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]].
101
102 * 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]].
103
104 == Sister projects ==
105 <span class="plainlinks">
106 [http://www.wikipedia.org Wikipedia] |
107 [http://www.wiktionary.org Wiktonary] |
108 [http://www.wikibooks.org Wikibooks] |
109 [http://www.wikinews.org Wikinews] |
110 [http://www.wikiquote.org Wikiquote] |
111 [http://www.wikisource.org Wikisource]
112 [http://www.wikiversity.org Wikiversity]
113 </span>
114
115 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
116
117 [[aa:]]
118 [[af:]]
119 [[als:]]
120 [[ar:]]
121 [[de:]]
122 [[en:]]
123 [[as:]]
124 [[ast:]]
125 [[ay:]]
126 [[az:]]
127 [[bcl:]]
128 [[be:]]
129 [[bg:]]
130 [[bn:]]
131 [[bo:]]
132 [[bs:]]
133 [[cs:]]
134 [[co:]]
135 [[cs:]]
136 [[cy:]]
137 [[da:]]
138 [[el:]]
139 [[eo:]]
140 [[es:]]
141 [[et:]]
142 [[eu:]]
143 [[fa:]]
144 [[fi:]]
145 [[fr:]]
146 [[fy:]]
147 [[ga:]]
148 [[gl:]]
149 [[gn:]]
150 [[gu:]]
151 [[he:]]
152 [[hi:]]
153 [[hr:]]
154 [[hsb:]]
155 [[hy:]]
156 [[ia:]]
157 [[id:]]
158 [[is:]]
159 [[it:]]
160 [[ja:]]
161 [[ka:]]
162 [[kk:]]
163 [[km:]]
164 [[kn:]]
165 [[ko:]]
166 [[ks:]]
167 [[ku:]]
168 [[ky:]]
169 [[la:]]
170 [[ln:]]
171 [[lo:]]
172 [[lt:]]
173 [[lv:]]
174 [[hu:]]
175 [[mi:]]
176 [[mk:]]
177 [[ml:]]
178 [[mn:]]
179 [[mr:]]
180 [[ms:]]
181 [[mt:]]
182 [[my:]]
183 [[na:]]
184 [[nah:]]
185 [[nds:]]
186 [[ne:]]
187 [[nl:]]
188 [[no:]]
189 [[oc:]]
190 [[om:]]
191 [[pa:]]
192 [[pl:]]
193 [[ps:]]
194 [[pt:]]
195 [[qu:]]
196 [[ro:]]
197 [[ru:]]
198 [[sa:]]
199 [[si:]]
200 [[sk:]]
201 [[sl:]]
202 [[sq:]]
203 [[sr:]]
204 [[sv:]]
205 [[sw:]]
206 [[ta:]]
207 [[te:]]
208 [[tg:]]
209 [[th:]]
210 [[tk:]]
211 [[tl:]]
212 [[tr:]]
213 [[tt:]]
214 [[ug:]]
215 [[uk:]]
216 [[ur:]]
217 [[uz:]]
218 [[vi:]]
219 [[vo:]]
220 [[xh:]]
221 [[yo:]]
222 [[za:]]
223 [[zh:]]
224 [[zu:]]
225
226 EOT
227 , '', false, false );
228
229 print "Adding to dblists\n";
230
231 # Add to dblist
232 $file = fopen( "$common/all.dblist", "a" );
233 fwrite( $file, "$dbName\n" );
234 fclose( $file );
235
236 # Update the sublists
237 shell_exec("cd $common && ./refresh-dblist");
238
239 #print "Constructing interwiki SQL\n";
240 # Rebuild interwiki tables
241 #passthru( '/home/wikipedia/conf/interwiki/update' );
242
243 # Create the upload dir
244 $uploadDir = "/mnt/upload3/$site/$lang";
245 if( file_exists( $uploadDir ) ) {
246 echo "$uploadDir already exists.\n";
247 } else {
248 echo "Creating $uploadDir...\n";
249 mkdir( $uploadDir, 0777 );
250 chmod( $uploadDir, 0777 );
251 }
252
253 print "Script ended. You still have to:
254 * Add any required settings in InitialiseSettings.php
255 * Run sync-common-all
256 * Run /home/wikipedia/conf/interwiki/update
257 ";
258 }
259