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