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