Redo addArgs() as addArg() so we can actually do useful things with arguments like...
[lhc/web/wiklou.git] / maintenance / addwiki.php
1 <?php
2 /**
3 * Add a new wiki
4 * Wikimedia specific!
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @defgroup Wikimedia Wikimedia
22 * @ingroup Maintenance
23 * @ingroup Wikimedia
24 */
25
26 require_once( dirname(__FILE__) . '/Maintenance.php' );
27
28 class AddWiki extends Maintenance {
29 public function __construct() {
30 parent::__construct();
31 $this->mDescription = "Add a new wiki to the family. Wikimedia specific!";
32 $this->addArg( 'language', 'Language code of new site' );
33 $this->addArg( 'site', 'Type of site' );
34 $this->addArg( 'dbname', 'Name of database to create' );
35 }
36
37 protected function getDbType() {
38 return Maintenance::DB_ADMIN;
39 }
40
41 public function execute() {
42 global $IP, $wgLanguageNames, $wgDefaultExternalStore, $wgNoDBParam;
43
44 $wgNoDBParam = true;
45 $lang = $this->getArg(0);
46 $site = $this->getArg(1);
47 $dbName = $this->getArg(2);
48
49 if ( !isset( $wgLanguageNames[$lang] ) ) {
50 $this->error( "Language $lang not found in \$wgLanguageNames", true );
51 }
52 $name = $wgLanguageNames[$lang];
53
54 $dbw = wfGetDB( DB_MASTER );
55 $common = "/home/wikipedia/common";
56
57 $this->output( "Creating database $dbName for $lang.$site ($name)\n" );
58
59 # Set up the database
60 $dbw->query( "SET table_type=Innodb" );
61 $dbw->query( "CREATE DATABASE $dbName" );
62 $dbw->selectDB( $dbName );
63
64 $this->output( "Initialising tables\n" );
65 $dbw->sourceFile( $this->getDir() . '/tables.sql' );
66 $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" );
67 $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" );
68 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" );
69 $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" );
70 $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" );
71 $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" );
72 $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" );
73 $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" );
74
75 $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" );
76
77 # Initialise external storage
78 if ( is_array( $wgDefaultExternalStore ) ) {
79 $stores = $wgDefaultExternalStore;
80 } elseif ( $stores ) {
81 $stores = array( $wgDefaultExternalStore );
82 } else {
83 $stores = array();
84 }
85 if ( count( $stores ) ) {
86 global $wgDBuser, $wgDBpassword, $wgExternalServers;
87 foreach ( $stores as $storeURL ) {
88 $m = array();
89 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
90 continue;
91 }
92
93 $cluster = $m[1];
94 $this->output( "Initialising external storage $cluster...\n" );
95
96 # Hack
97 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
98 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
99
100 $store = new ExternalStoreDB;
101 $extdb = $store->getMaster( $cluster );
102 $extdb->query( "SET table_type=InnoDB" );
103 $extdb->query( "CREATE DATABASE $dbName" );
104 $extdb->selectDB( $dbName );
105
106 # Hack x2
107 $blobsTable = $store->getTable( $extdb );
108 $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql";
109 $blobsFile = popen( $sedCmd, 'r' );
110 $extdb->sourceStream( $blobsFile );
111 pclose( $blobsFile );
112 $extdb->immediateCommit();
113 }
114 }
115
116 global $wgTitle, $wgArticle;
117 $wgTitle = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
118 $this->output( "Writing main page to " . $wgTitle->getPrefixedDBkey() . "\n" );
119 $wgArticle = new Article( $wgTitle );
120 $ucsite = ucfirst( $site );
121
122 $wgArticle->insertNewArticle( $this->getFirstArticle( $ucsite, $name ), '', false, false );
123
124 $this->output( "Adding to dblists\n" );
125
126 # Add to dblist
127 $file = fopen( "$common/all.dblist", "a" );
128 fwrite( $file, "$dbName\n" );
129 fclose( $file );
130
131 # Update the sublists
132 shell_exec("cd $common && ./refresh-dblist");
133
134 #print "Constructing interwiki SQL\n";
135 # Rebuild interwiki tables
136 #passthru( '/home/wikipedia/conf/interwiki/update' );
137
138 $this->output( "Script ended. You still have to:
139 * Add any required settings in InitialiseSettings.php
140 * Run sync-common-all
141 * Run /home/wikipedia/conf/interwiki/update
142 " );
143 }
144
145 private function getFirstArticle( $ucsite, $name ) {
146 return <<<EOT
147 ==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language==
148
149 * 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.
150
151 * 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]].
152
153 * 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]].
154
155 == Sister projects ==
156 <span class="plainlinks">
157 [http://www.wikipedia.org Wikipedia] |
158 [http://www.wiktionary.org Wiktonary] |
159 [http://www.wikibooks.org Wikibooks] |
160 [http://www.wikinews.org Wikinews] |
161 [http://www.wikiquote.org Wikiquote] |
162 [http://www.wikisource.org Wikisource]
163 [http://www.wikiversity.org Wikiversity]
164 </span>
165
166 See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects.
167
168 [[aa:]]
169 [[af:]]
170 [[als:]]
171 [[ar:]]
172 [[de:]]
173 [[en:]]
174 [[as:]]
175 [[ast:]]
176 [[ay:]]
177 [[az:]]
178 [[bcl:]]
179 [[be:]]
180 [[bg:]]
181 [[bn:]]
182 [[bo:]]
183 [[bs:]]
184 [[cs:]]
185 [[co:]]
186 [[cs:]]
187 [[cy:]]
188 [[da:]]
189 [[el:]]
190 [[eo:]]
191 [[es:]]
192 [[et:]]
193 [[eu:]]
194 [[fa:]]
195 [[fi:]]
196 [[fr:]]
197 [[fy:]]
198 [[ga:]]
199 [[gl:]]
200 [[gn:]]
201 [[gu:]]
202 [[he:]]
203 [[hi:]]
204 [[hr:]]
205 [[hsb:]]
206 [[hy:]]
207 [[ia:]]
208 [[id:]]
209 [[is:]]
210 [[it:]]
211 [[ja:]]
212 [[ka:]]
213 [[kk:]]
214 [[km:]]
215 [[kn:]]
216 [[ko:]]
217 [[ks:]]
218 [[ku:]]
219 [[ky:]]
220 [[la:]]
221 [[ln:]]
222 [[lo:]]
223 [[lt:]]
224 [[lv:]]
225 [[hu:]]
226 [[mi:]]
227 [[mk:]]
228 [[ml:]]
229 [[mn:]]
230 [[mr:]]
231 [[ms:]]
232 [[mt:]]
233 [[my:]]
234 [[na:]]
235 [[nah:]]
236 [[nds:]]
237 [[ne:]]
238 [[nl:]]
239 [[no:]]
240 [[oc:]]
241 [[om:]]
242 [[pa:]]
243 [[pl:]]
244 [[ps:]]
245 [[pt:]]
246 [[qu:]]
247 [[ro:]]
248 [[ru:]]
249 [[sa:]]
250 [[si:]]
251 [[sk:]]
252 [[sl:]]
253 [[sq:]]
254 [[sr:]]
255 [[sv:]]
256 [[sw:]]
257 [[ta:]]
258 [[te:]]
259 [[tg:]]
260 [[th:]]
261 [[tk:]]
262 [[tl:]]
263 [[tr:]]
264 [[tt:]]
265 [[ug:]]
266 [[uk:]]
267 [[ur:]]
268 [[uz:]]
269 [[vi:]]
270 [[vo:]]
271 [[xh:]]
272 [[yo:]]
273 [[za:]]
274 [[zh:]]
275 [[zu:]]
276
277 EOT;
278 }
279 }
280
281 $maintClass = "AddWiki";
282 require_once( DO_MAINTENANCE );