WARNING: HUGE COMMIT
[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>\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 $name = $wgLanguageNames[$lang];
28
29 $dbw = wfGetDB( DB_MASTER );
30 $common = "/home/wikipedia/common";
31 $maintenance = "$IP/maintenance";
32
33 print "Creating database $dbName for $lang.$site\n";
34
35 # Set up the database
36 $dbw->query( "SET table_type=Innodb" );
37 $dbw->query( "CREATE DATABASE $dbName" );
38 $dbw->selectDB( $dbName );
39
40 print "Initialising tables\n";
41 dbsource( "$maintenance/tables.sql", $dbw );
42 dbsource( "$IP/extensions/OAI/update_table.sql", $dbw );
43 dbsource( "$IP/extensions/AntiSpoof/mysql/patch-antispoof.sql", $dbw );
44 dbsource( "$IP/extensions/CheckUser/cu_changes.sql", $dbw );
45 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
46
47 # Initialise external storage
48 if ( is_array( $wgDefaultExternalStore ) ) {
49 $stores = $wgDefaultExternalStore;
50 } elseif ( $stores ) {
51 $stores = array( $wgDefaultExternalStore );
52 } else {
53 $stores = array();
54 }
55 if ( count( $stores ) ) {
56 require_once( 'ExternalStoreDB.php' );
57 print "Initialising external storage $store...\n";
58 global $wgDBuser, $wgDBpassword, $wgExternalServers;
59 foreach ( $stores as $storeURL ) {
60 $m = array();
61 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
62 continue;
63 }
64
65 $cluster = $m[1];
66
67 # Hack
68 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
69 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
70
71 $store = new ExternalStoreDB;
72 $extdb =& $store->getMaster( $cluster );
73 $extdb->query( "SET table_type=InnoDB" );
74 $extdb->query( "CREATE DATABASE $dbName" );
75 $extdb->selectDB( $dbName );
76 dbsource( "$maintenance/storage/blobs.sql", $extdb );
77 $extdb->immediateCommit();
78 }
79 }
80
81 global $wgTitle, $wgArticle;
82 $wgTitle = Title::newMainPage();
83 $wgArticle = new Article( $wgTitle );
84 $ucsite = ucfirst( $site );
85
86 $wgArticle->insertNewArticle( <<<EOT
87 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
88
89 * 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.
90
91 * 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]].
92
93 * 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]].
94
95 == Sister projects ==
96 <span class="plainlinks">
97 [http://www.wikipedia.org Wikipedia] |
98 [http://www.wiktionary.org Wiktonary] |
99 [http://www.wikibooks.org Wikibooks] |
100 [http://www.wikinews.org Wikinews] |
101 [http://www.wikiquote.org Wikiquote] |
102 [http://www.wikisource.org Wikisource]
103 [http://www.wikiversity.org Wikiversity]
104 </span>
105
106 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
107
108 [[aa:]]
109 [[af:]]
110 [[als:]]
111 [[ar:]]
112 [[de:]]
113 [[en:]]
114 [[as:]]
115 [[ast:]]
116 [[ay:]]
117 [[az:]]
118 [[bcl:]]
119 [[be:]]
120 [[bg:]]
121 [[bn:]]
122 [[bo:]]
123 [[bs:]]
124 [[cs:]]
125 [[co:]]
126 [[cs:]]
127 [[cy:]]
128 [[da:]]
129 [[el:]]
130 [[eo:]]
131 [[es:]]
132 [[et:]]
133 [[eu:]]
134 [[fa:]]
135 [[fi:]]
136 [[fr:]]
137 [[fy:]]
138 [[ga:]]
139 [[gl:]]
140 [[gn:]]
141 [[gu:]]
142 [[he:]]
143 [[hi:]]
144 [[hr:]]
145 [[hsb:]]
146 [[hy:]]
147 [[ia:]]
148 [[id:]]
149 [[is:]]
150 [[it:]]
151 [[ja:]]
152 [[ka:]]
153 [[kk:]]
154 [[km:]]
155 [[kn:]]
156 [[ko:]]
157 [[ks:]]
158 [[ku:]]
159 [[ky:]]
160 [[la:]]
161 [[ln:]]
162 [[lo:]]
163 [[lt:]]
164 [[lv:]]
165 [[hu:]]
166 [[mi:]]
167 [[mk:]]
168 [[ml:]]
169 [[mn:]]
170 [[mr:]]
171 [[ms:]]
172 [[mt:]]
173 [[my:]]
174 [[na:]]
175 [[nah:]]
176 [[nds:]]
177 [[ne:]]
178 [[nl:]]
179 [[no:]]
180 [[oc:]]
181 [[om:]]
182 [[pa:]]
183 [[pl:]]
184 [[ps:]]
185 [[pt:]]
186 [[qu:]]
187 [[ro:]]
188 [[ru:]]
189 [[sa:]]
190 [[si:]]
191 [[sk:]]
192 [[sl:]]
193 [[sq:]]
194 [[sr:]]
195 [[sv:]]
196 [[sw:]]
197 [[ta:]]
198 [[te:]]
199 [[tg:]]
200 [[th:]]
201 [[tk:]]
202 [[tl:]]
203 [[tr:]]
204 [[tt:]]
205 [[ug:]]
206 [[uk:]]
207 [[ur:]]
208 [[uz:]]
209 [[vi:]]
210 [[vo:]]
211 [[xh:]]
212 [[yo:]]
213 [[za:]]
214 [[zh:]]
215 [[zu:]]
216
217 EOT
218 , '', false, false );
219
220 print "Adding to dblists\n";
221
222 # Add to dblist
223 $file = fopen( "$common/all.dblist", "a" );
224 fwrite( $file, "$dbName\n" );
225 fclose( $file );
226
227 # Update the sublists
228 system("cd $common && ./refresh-dblist");
229
230 print "Constructing interwiki SQL\n";
231 # Rebuild interwiki tables
232 $sql = getRebuildInterwikiSQL();
233 $tempname = tempnam( '/tmp', 'addwiki' );
234 $file = fopen( $tempname, 'w' );
235 if ( !$file ) {
236 wfDie( "Error, unable to open temporary file $tempname\n" );
237 }
238 fwrite( $file, $sql );
239 fclose( $file );
240 print "Sourcing interwiki SQL\n";
241 dbsource( $tempname, $dbw );
242 #unlink( $tempname );
243
244 # Create the upload dir
245 global $wgUploadDirectory;
246 if( file_exists( $wgUploadDirectory ) ) {
247 echo "$wgUploadDirectory already exists.\n";
248 } else {
249 echo "Creating $wgUploadDirectory...\n";
250 mkdir( $wgUploadDirectory, 0777 );
251 chmod( $wgUploadDirectory, 0777 );
252 }
253
254 print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";
255 }
256