* And unbreak, rebuildLanguage should really be fixed
[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( "
79 ==This subdomain is reserved for the creation of a $ucsite in '''[[:en:{$name}|{$name}]]''' language==
80
81 If you can write in this language and want to collaborate in the creation of this encyclopedia then '''you''' can make it.
82
83 Go ahead. Translate this page and start working on your encyclopedia.
84
85 For help, see '''[[m:Help:How to start a new Wikipedia|how to start a new Wikipedia]]'''.
86
87 ==Sister projects==
88 [http://meta.wikipedia.org Meta-Wikipedia] | [http://www.wiktionary.org Wikitonary] | [http://www.wikibooks.org Wikibooks] | [http://www.wikinews.org Wikinews] | [http://www.wikiquote.org Wikiquote] | [http://www.wikisource.org Wikisource]
89
90 See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedias.
91
92 [[aa:]]
93 [[af:]]
94 [[als:]]
95 [[ar:]]
96 [[de:]]
97 [[en:]]
98 [[as:]]
99 [[ast:]]
100 [[ay:]]
101 [[az:]]
102 [[be:]]
103 [[bg:]]
104 [[bn:]]
105 [[bo:]]
106 [[bs:]]
107 [[cs:]]
108 [[co:]]
109 [[cs:]]
110 [[cy:]]
111 [[da:]]
112 [[el:]]
113 [[eo:]]
114 [[es:]]
115 [[et:]]
116 [[eu:]]
117 [[fa:]]
118 [[fi:]]
119 [[fr:]]
120 [[fy:]]
121 [[ga:]]
122 [[gl:]]
123 [[gn:]]
124 [[gu:]]
125 [[he:]]
126 [[hi:]]
127 [[hr:]]
128 [[hy:]]
129 [[ia:]]
130 [[id:]]
131 [[is:]]
132 [[it:]]
133 [[ja:]]
134 [[ka:]]
135 [[kk:]]
136 [[km:]]
137 [[kn:]]
138 [[ko:]]
139 [[ks:]]
140 [[ku:]]
141 [[ky:]]
142 [[la:]]
143 [[ln:]]
144 [[lo:]]
145 [[lt:]]
146 [[lv:]]
147 [[hu:]]
148 [[mi:]]
149 [[mk:]]
150 [[ml:]]
151 [[mn:]]
152 [[mr:]]
153 [[ms:]]
154 [[mt:]]
155 [[my:]]
156 [[na:]]
157 [[nah:]]
158 [[nds:]]
159 [[ne:]]
160 [[nl:]]
161 [[no:]]
162 [[oc:]]
163 [[om:]]
164 [[pa:]]
165 [[pl:]]
166 [[ps:]]
167 [[pt:]]
168 [[qu:]]
169 [[ro:]]
170 [[ru:]]
171 [[sa:]]
172 [[si:]]
173 [[sk:]]
174 [[sl:]]
175 [[sq:]]
176 [[sr:]]
177 [[sv:]]
178 [[sw:]]
179 [[ta:]]
180 [[te:]]
181 [[tg:]]
182 [[th:]]
183 [[tk:]]
184 [[tl:]]
185 [[tr:]]
186 [[tt:]]
187 [[ug:]]
188 [[uk:]]
189 [[ur:]]
190 [[uz:]]
191 [[vi:]]
192 [[vo:]]
193 [[xh:]]
194 [[yo:]]
195 [[za:]]
196 [[zh:]]
197 [[zu:]]
198 ", '', false, false );
199
200 print "Adding to dblists\n";
201
202 # Add to dblist
203 $file = fopen( "$common/all.dblist", "a" );
204 fwrite( $file, "$dbName\n" );
205 fclose( $file );
206
207 # Update the sublists
208 system("cd $common && ./refresh-dblist");
209
210 print "Constructing interwiki SQL\n";
211 # Rebuild interwiki tables
212 $sql = getRebuildInterwikiSQL();
213 $tempname = tempnam( '/tmp', 'addwiki' );
214 $file = fopen( $tempname, 'w' );
215 if ( !$file ) {
216 wfDie( "Error, unable to open temporary file $tempname\n" );
217 }
218 fwrite( $file, $sql );
219 fclose( $file );
220 print "Sourcing interwiki SQL\n";
221 dbsource( $tempname, $dbw );
222 #unlink( $tempname );
223
224 # Create the upload dir
225 global $wgUploadDirectory;
226 if( file_exists( $wgUploadDirectory ) ) {
227 echo "$wgUploadDirectory already exists.\n";
228 } else {
229 echo "Creating $wgUploadDirectory...\n";
230 mkdir( $wgUploadDirectory, 0777 );
231 chmod( $wgUploadDirectory, 0777 );
232 }
233
234 print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";
235 }
236