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