In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit
[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 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
38
39 # Initialise external storage
40 if ( is_array( $wgDefaultExternalStore ) ) {
41 $stores = $wgDefaultExternalStore;
42 } elseif ( $stores ) {
43 $stores = array( $wgDefaultExternalStore );
44 } else {
45 $stores = array();
46 }
47 if ( count( $stores ) ) {
48 require_once( 'ExternalStoreDB.php' );
49 print "Initialising external storage $store...\n";
50 global $wgDBuser, $wgDBpassword, $wgExternalServers;
51 foreach ( $stores as $storeURL ) {
52 $m = array();
53 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
54 continue;
55 }
56
57 $cluster = $m[1];
58
59 # Hack
60 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
61 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
62
63 $store = new ExternalStoreDB;
64 $extdb =& $store->getMaster( $cluster );
65 $extdb->query( "SET table_type=InnoDB" );
66 $extdb->query( "CREATE DATABASE $dbName" );
67 $extdb->selectDB( $dbName );
68 dbsource( "$maintenance/storage/blobs.sql", $extdb );
69 $extdb->immediateCommit();
70 }
71 }
72
73 $wgTitle = Title::newMainPage();
74 $wgArticle = new Article( $wgTitle );
75 $ucsite = ucfirst( $site );
76
77 $wgArticle->insertNewArticle( "
78 ==This subdomain is reserved for the creation of a $ucsite in '''[[:en:{$name}|{$name}]]''' language==
79
80 If you can write in this language and want to collaborate in the creation of this encyclopedia then '''you''' can make it.
81
82 Go ahead. Translate this page and start working on your encyclopedia.
83
84 For help, see '''[[m:Help:How to start a new Wikipedia|how to start a new Wikipedia]]'''.
85
86 ==Sister projects==
87 [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]
88
89 See the [http://www.wikipedia.org Wikipedia portal] for other language Wikipedias.
90
91 [[aa:]]
92 [[af:]]
93 [[als:]]
94 [[ar:]]
95 [[de:]]
96 [[en:]]
97 [[as:]]
98 [[ast:]]
99 [[ay:]]
100 [[az:]]
101 [[be:]]
102 [[bg:]]
103 [[bn:]]
104 [[bo:]]
105 [[bs:]]
106 [[cs:]]
107 [[co:]]
108 [[cs:]]
109 [[cy:]]
110 [[da:]]
111 [[el:]]
112 [[eo:]]
113 [[es:]]
114 [[et:]]
115 [[eu:]]
116 [[fa:]]
117 [[fi:]]
118 [[fr:]]
119 [[fy:]]
120 [[ga:]]
121 [[gl:]]
122 [[gn:]]
123 [[gu:]]
124 [[he:]]
125 [[hi:]]
126 [[hr:]]
127 [[hy:]]
128 [[ia:]]
129 [[id:]]
130 [[is:]]
131 [[it:]]
132 [[ja:]]
133 [[ka:]]
134 [[kk:]]
135 [[km:]]
136 [[kn:]]
137 [[ko:]]
138 [[ks:]]
139 [[ku:]]
140 [[ky:]]
141 [[la:]]
142 [[ln:]]
143 [[lo:]]
144 [[lt:]]
145 [[lv:]]
146 [[hu:]]
147 [[mi:]]
148 [[mk:]]
149 [[ml:]]
150 [[mn:]]
151 [[mr:]]
152 [[ms:]]
153 [[mt:]]
154 [[my:]]
155 [[na:]]
156 [[nah:]]
157 [[nds:]]
158 [[ne:]]
159 [[nl:]]
160 [[no:]]
161 [[oc:]]
162 [[om:]]
163 [[pa:]]
164 [[pl:]]
165 [[ps:]]
166 [[pt:]]
167 [[qu:]]
168 [[ro:]]
169 [[ru:]]
170 [[sa:]]
171 [[si:]]
172 [[sk:]]
173 [[sl:]]
174 [[sq:]]
175 [[sr:]]
176 [[sv:]]
177 [[sw:]]
178 [[ta:]]
179 [[te:]]
180 [[tg:]]
181 [[th:]]
182 [[tk:]]
183 [[tl:]]
184 [[tr:]]
185 [[tt:]]
186 [[ug:]]
187 [[uk:]]
188 [[ur:]]
189 [[uz:]]
190 [[vi:]]
191 [[vo:]]
192 [[xh:]]
193 [[yo:]]
194 [[za:]]
195 [[zh:]]
196 [[zu:]]
197 ", '', false, false );
198
199 print "Adding to dblists\n";
200
201 # Add to dblist
202 $file = fopen( "$common/all.dblist", "a" );
203 fwrite( $file, "$dbName\n" );
204 fclose( $file );
205
206 # Update the sublists
207 system("cd $common && ./refresh-dblist");
208
209 print "Constructing interwiki SQL\n";
210 # Rebuild interwiki tables
211 $sql = getRebuildInterwikiSQL();
212 $tempname = tempnam( '/tmp', 'addwiki' );
213 $file = fopen( $tempname, 'w' );
214 if ( !$file ) {
215 wfDie( "Error, unable to open temporary file $tempname\n" );
216 }
217 fwrite( $file, $sql );
218 fclose( $file );
219 print "Sourcing interwiki SQL\n";
220 dbsource( $tempname, $dbw );
221 #unlink( $tempname );
222
223 # Create the upload dir
224 global $wgUploadDirectory;
225 if( file_exists( $wgUploadDirectory ) ) {
226 echo "$wgUploadDirectory already exists.\n";
227 } else {
228 echo "Creating $wgUploadDirectory...\n";
229 mkdir( $wgUploadDirectory, 0777 );
230 chmod( $wgUploadDirectory, 0777 );
231 }
232
233 print "Script ended. You now want to run sync-common-all to publish *dblist files (check them for duplicates first)\n";
234 }
235 ?>