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