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