Index: trunk/phase3/maintenance/renamewiki.php |
— | — | @@ -1,89 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Why yes, this *is* another special-purpose Wikimedia maintenance script! |
5 | | - * Should be fixed up and generalized. |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - * |
22 | | - * @file |
23 | | - * @ingroup Maintenance |
24 | | - * @ingroup Wikimedia |
25 | | - */ |
26 | | - |
27 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
28 | | - |
29 | | -class RenameWiki extends Maintenance { |
30 | | - public function __construct() { |
31 | | - parent::__construct(); |
32 | | - $this->mDescription = "Rename external storage dbs and leave a new one"; |
33 | | - $this->addArg( 'olddb', 'Old DB name' ); |
34 | | - $this->addArg( 'newdb', 'New DB name' ); |
35 | | - } |
36 | | - |
37 | | - public function getDbType() { |
38 | | - return Maintenance::DB_ADMIN; |
39 | | - } |
40 | | - |
41 | | - public function execute() { |
42 | | - global $wgDefaultExternalStore; |
43 | | - |
44 | | - # Setup |
45 | | - $from = $this->getArg( 0 ); |
46 | | - $to = $this->getArg( 1 ); |
47 | | - $this->output( "Renaming blob tables in ES from $from to $to...\n" ); |
48 | | - $this->output( "Sleeping 5 seconds...\n" ); |
49 | | - sleep( 5 ); |
50 | | - |
51 | | - # Initialise external storage |
52 | | - if ( is_array( $wgDefaultExternalStore ) ) { |
53 | | - $stores = $wgDefaultExternalStore; |
54 | | - } elseif ( $wgDefaultExternalStore ) { |
55 | | - $stores = array( $wgDefaultExternalStore ); |
56 | | - } else { |
57 | | - $stores = array(); |
58 | | - } |
59 | | - |
60 | | - if ( count( $stores ) ) { |
61 | | - $this->output( "Initialising external storage...\n" ); |
62 | | - global $wgDBuser, $wgDBpassword, $wgExternalServers; |
63 | | - foreach ( $stores as $storeURL ) { |
64 | | - $m = array(); |
65 | | - if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { |
66 | | - continue; |
67 | | - } |
68 | | - |
69 | | - $cluster = $m[1]; |
70 | | - |
71 | | - # Hack |
72 | | - $wgExternalServers[$cluster][0]['user'] = $wgDBuser; |
73 | | - $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; |
74 | | - |
75 | | - $store = new ExternalStoreDB; |
76 | | - $extdb =& $store->getMaster( $cluster ); |
77 | | - $extdb->query( "SET table_type=InnoDB" ); |
78 | | - $extdb->query( "CREATE DATABASE {$to}" ); |
79 | | - $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" ); |
80 | | - $extdb->selectDB( $from ); |
81 | | - $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' ); |
82 | | - $extdb->commit(); |
83 | | - } |
84 | | - } |
85 | | - $this->output( "done.\n" ); |
86 | | - } |
87 | | -} |
88 | | - |
89 | | -$maintClass = "RenameWiki"; |
90 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/phase3/maintenance/addwiki.php |
— | — | @@ -1,207 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @defgroup Wikimedia Wikimedia |
5 | | - */ |
6 | | - |
7 | | -/** |
8 | | - * Add a new wiki |
9 | | - * Wikimedia specific! |
10 | | - * |
11 | | - * This program is free software; you can redistribute it and/or modify |
12 | | - * it under the terms of the GNU General Public License as published by |
13 | | - * the Free Software Foundation; either version 2 of the License, or |
14 | | - * (at your option) any later version. |
15 | | - * |
16 | | - * This program is distributed in the hope that it will be useful, |
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | | - * GNU General Public License for more details. |
20 | | - * |
21 | | - * You should have received a copy of the GNU General Public License along |
22 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
23 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 | | - * http://www.gnu.org/copyleft/gpl.html |
25 | | - * |
26 | | - * @file |
27 | | - * @ingroup Maintenance |
28 | | - * @ingroup Wikimedia |
29 | | - */ |
30 | | - |
31 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
32 | | - |
33 | | -class AddWiki extends Maintenance { |
34 | | - public function __construct() { |
35 | | - global $wgNoDBParam; |
36 | | - |
37 | | - parent::__construct(); |
38 | | - $this->mDescription = "Add a new wiki to the family. Wikimedia specific!"; |
39 | | - $this->addArg( 'language', 'Language code of new site, e.g. en' ); |
40 | | - $this->addArg( 'site', 'Type of site, e.g. wikipedia' ); |
41 | | - $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' ); |
42 | | - $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' ); |
43 | | - |
44 | | - $wgNoDBParam = true; |
45 | | - } |
46 | | - |
47 | | - public function getDbType() { |
48 | | - return Maintenance::DB_ADMIN; |
49 | | - } |
50 | | - |
51 | | - public function execute() { |
52 | | - global $IP, $wgDefaultExternalStore, $wmfVersionNumber; |
53 | | - if ( !$wmfVersionNumber ) { // set in CommonSettings.php |
54 | | - $this->error( '$wmfVersionNumber is not set, please use MWScript.php wrapper.', true ); |
55 | | - } |
56 | | - |
57 | | - $lang = $this->getArg( 0 ); |
58 | | - $site = $this->getArg( 1 ); |
59 | | - $dbName = $this->getArg( 2 ); |
60 | | - $domain = $this->getArg( 3 ); |
61 | | - $languageNames = Language::getLanguageNames(); |
62 | | - |
63 | | - if ( !isset( $languageNames[$lang] ) ) { |
64 | | - $this->error( "Language $lang not found in Names.php", true ); |
65 | | - } |
66 | | - $name = $languageNames[$lang]; |
67 | | - |
68 | | - $dbw = wfGetDB( DB_MASTER ); |
69 | | - $common = "/home/wikipedia/common"; |
70 | | - |
71 | | - $this->output( "Creating database $dbName for $lang.$site ($name)\n" ); |
72 | | - |
73 | | - # Set up the database |
74 | | - $dbw->query( "SET table_type=Innodb" ); |
75 | | - $dbw->query( "CREATE DATABASE $dbName" ); |
76 | | - $dbw->selectDB( $dbName ); |
77 | | - |
78 | | - $this->output( "Initialising tables\n" ); |
79 | | - $dbw->sourceFile( $this->getDir() . '/tables.sql' ); |
80 | | - $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" ); |
81 | | - $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" ); |
82 | | - $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" ); |
83 | | - $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" ); |
84 | | - $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" ); |
85 | | - $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" ); |
86 | | - $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" ); |
87 | | - $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" ); |
88 | | - $dbw->sourceFile( "$IP/extensions/PrefStats/patches/PrefStats.sql" ); |
89 | | - $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" ); |
90 | | - $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTrackingEvents.sql" ); |
91 | | - $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTracking.sql" ); |
92 | | - $dbw->sourceFile( "$IP/extensions/UserDailyContribs/patches/UserDailyContribs.sql" ); |
93 | | - |
94 | | - $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" ); |
95 | | - |
96 | | - # Initialise external storage |
97 | | - if ( is_array( $wgDefaultExternalStore ) ) { |
98 | | - $stores = $wgDefaultExternalStore; |
99 | | - } elseif ( $wgDefaultExternalStore ) { |
100 | | - $stores = array( $wgDefaultExternalStore ); |
101 | | - } else { |
102 | | - $stores = array(); |
103 | | - } |
104 | | - if ( count( $stores ) ) { |
105 | | - global $wgDBuser, $wgDBpassword, $wgExternalServers; |
106 | | - foreach ( $stores as $storeURL ) { |
107 | | - $m = array(); |
108 | | - if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { |
109 | | - continue; |
110 | | - } |
111 | | - |
112 | | - $cluster = $m[1]; |
113 | | - $this->output( "Initialising external storage $cluster...\n" ); |
114 | | - |
115 | | - # Hack |
116 | | - $wgExternalServers[$cluster][0]['user'] = $wgDBuser; |
117 | | - $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; |
118 | | - |
119 | | - $store = new ExternalStoreDB; |
120 | | - $extdb = $store->getMaster( $cluster ); |
121 | | - $extdb->query( "SET table_type=InnoDB" ); |
122 | | - $extdb->query( "CREATE DATABASE $dbName" ); |
123 | | - $extdb->selectDB( $dbName ); |
124 | | - |
125 | | - # Hack x2 |
126 | | - $blobsTable = $store->getTable( $extdb ); |
127 | | - $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql"; |
128 | | - $blobsFile = popen( $sedCmd, 'r' ); |
129 | | - $extdb->sourceStream( $blobsFile ); |
130 | | - pclose( $blobsFile ); |
131 | | - $extdb->commit(); |
132 | | - } |
133 | | - } |
134 | | - |
135 | | - $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() ); |
136 | | - $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" ); |
137 | | - $article = new Article( $title ); |
138 | | - $ucsite = ucfirst( $site ); |
139 | | - |
140 | | - $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY ); |
141 | | - |
142 | | - $this->output( "Adding to dblists\n" ); |
143 | | - |
144 | | - # Add to dblist |
145 | | - $file = fopen( "$common/all.dblist", "a" ); |
146 | | - fwrite( $file, "$dbName\n" ); |
147 | | - fclose( $file ); |
148 | | - |
149 | | - # Update the sublists |
150 | | - shell_exec( "cd $common && ./refresh-dblist" ); |
151 | | - |
152 | | - # Add to wikiversions.dat |
153 | | - $file = fopen( "$common/wikiversions.dat", "a" ); |
154 | | - fwrite( $file, "$dbName php-$wmfVersionNumber\n" ); |
155 | | - fclose( $file ); |
156 | | - # Rebuild wikiversions.cdb |
157 | | - shell_exec( "cd $common/multiversion && ./refreshWikiversionsCDB" ); |
158 | | - |
159 | | - # print "Constructing interwiki SQL\n"; |
160 | | - # Rebuild interwiki tables |
161 | | - # passthru( '/home/wikipedia/conf/interwiki/update' ); |
162 | | - |
163 | | - $time = wfTimestamp( TS_RFC2822 ); |
164 | | - // These arguments need to be escaped twice: once for echo and once for at |
165 | | - $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) ); |
166 | | - $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) ); |
167 | | - $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) ); |
168 | | - $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) ); |
169 | | - $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) ); |
170 | | - $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) ); |
171 | | - shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" ); |
172 | | - |
173 | | - $this->output( "Script ended. You still have to: |
174 | | - * Add any required settings in InitialiseSettings.php |
175 | | - * Run sync-common-all |
176 | | - * Run /home/wikipedia/conf/interwiki/update |
177 | | - " ); |
178 | | - } |
179 | | - |
180 | | - private function getFirstArticle( $ucsite, $name ) { |
181 | | - return <<<EOT |
182 | | -==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language== |
183 | | - |
184 | | -* Please '''do not start editing''' this new site. This site has a test project on the [[incubator:|Wikimedia Incubator]] (or on the [[betawikiversity:|Beta Wikiversity]] or on the [[oldwikisource:|Old Wikisource]]) and it will be imported to here. |
185 | | - |
186 | | -* If you would like to help translating the interface to this language, please do not translate here, but go to [[translatewiki:|translatewiki.net]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]]. |
187 | | - |
188 | | -* 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]]. |
189 | | - |
190 | | -== Sister projects == |
191 | | -<span class="plainlinks"> |
192 | | -[http://www.wikipedia.org Wikipedia] | |
193 | | -[http://www.wiktionary.org Wiktionary] | |
194 | | -[http://www.wikibooks.org Wikibooks] | |
195 | | -[http://www.wikinews.org Wikinews] | |
196 | | -[http://www.wikiquote.org Wikiquote] | |
197 | | -[http://www.wikisource.org Wikisource] | |
198 | | -[http://www.wikiversity.org Wikiversity] |
199 | | -</span> |
200 | | - |
201 | | -See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects. |
202 | | - |
203 | | -EOT; |
204 | | - } |
205 | | -} |
206 | | - |
207 | | -$maintClass = "AddWiki"; |
208 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/phase3/maintenance/dumpInterwiki.php |
— | — | @@ -1,265 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Build constant slightly compact database of interwiki prefixes |
5 | | - * Wikimedia specific! |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - * |
22 | | - * @file |
23 | | - * @todo document |
24 | | - * @ingroup Maintenance |
25 | | - * @ingroup Wikimedia |
26 | | - */ |
27 | | - |
28 | | -require_once( dirname( __FILE__ ) . '/Site.php' ); |
29 | | - |
30 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
31 | | - |
32 | | -class DumpInterwiki extends Maintenance { |
33 | | - |
34 | | - public function __construct() { |
35 | | - parent::__construct(); |
36 | | - $this->mDescription = "Build constant slightly compact database of interwiki prefixes."; |
37 | | - $this->addOption( 'langlist', 'File with one language code per line', false, true ); |
38 | | - $this->addOption( 'dblist', 'File with one db per line', false, true ); |
39 | | - $this->addOption( 'specialdbs', "File with one 'special' db per line", false, true ); |
40 | | - $this->addOption( 'o', 'Cdb output file', false, true ); |
41 | | - $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false ); |
42 | | - } |
43 | | - |
44 | | - function execute() { |
45 | | - # List of language prefixes likely to be found in multi-language sites |
46 | | - $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); |
47 | | - |
48 | | - # List of all database names |
49 | | - $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); |
50 | | - |
51 | | - # Special-case databases |
52 | | - $this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); |
53 | | - |
54 | | - if ( $this->hasOption( 'o' ) ) { |
55 | | - $this->dbFile = CdbWriter::open( $this->getOption( 'o' ) ) ; |
56 | | - } else { |
57 | | - $this->dbFile = false; |
58 | | - } |
59 | | - |
60 | | - if ( $this->hasOption( 'protocolrelative' ) ) { |
61 | | - $this->urlprotocol = ''; |
62 | | - } else { |
63 | | - $this->urlprotocol = 'http:'; |
64 | | - } |
65 | | - |
66 | | - $this->getRebuildInterwikiDump(); |
67 | | - } |
68 | | - |
69 | | - function getRebuildInterwikiDump() { |
70 | | - global $wgContLang; |
71 | | - |
72 | | - # Multi-language sites |
73 | | - # db suffix => db suffix, iw prefix, hostname |
74 | | - $sites = array( |
75 | | - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), |
76 | | - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), |
77 | | - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), |
78 | | - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), |
79 | | - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), |
80 | | - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), |
81 | | - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), |
82 | | - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), |
83 | | - ); |
84 | | - |
85 | | - # Extra interwiki links that can't be in the intermap for some reason |
86 | | - $extraLinks = array( |
87 | | - array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), |
88 | | - array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), |
89 | | - array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ), |
90 | | - ); |
91 | | - |
92 | | - # Language aliases, usually configured as redirects to the real wiki in apache |
93 | | - # Interlanguage links are made directly to the real wiki |
94 | | - # Something horrible happens if you forget to list an alias here, I can't |
95 | | - # remember what |
96 | | - $this->languageAliases = array( |
97 | | - 'zh-cn' => 'zh', |
98 | | - 'zh-tw' => 'zh', |
99 | | - 'dk' => 'da', |
100 | | - 'nb' => 'no', |
101 | | - ); |
102 | | - |
103 | | - # Special case prefix rewrites, for the benefit of Swedish which uses s:t |
104 | | - # as an abbreviation for saint |
105 | | - $this->prefixRewrites = array( |
106 | | - 'svwiki' => array( 's' => 'src' ), |
107 | | - ); |
108 | | - |
109 | | - # Construct a list of reserved prefixes |
110 | | - $reserved = array(); |
111 | | - foreach ( $this->langlist as $lang ) { |
112 | | - $reserved[$lang] = 1; |
113 | | - } |
114 | | - foreach ( $this->languageAliases as $alias => $lang ) { |
115 | | - $reserved[$alias] = 1; |
116 | | - } |
117 | | - foreach ( $sites as $site ) { |
118 | | - $reserved[$site->lateral] = 1; |
119 | | - } |
120 | | - |
121 | | - # Extract the intermap from meta |
122 | | - $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); |
123 | | - $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); |
124 | | - |
125 | | - if ( !$lines || count( $lines ) < 2 ) { |
126 | | - $this->error( "m:Interwiki_map not found", true ); |
127 | | - } |
128 | | - |
129 | | - # Global interwiki map |
130 | | - foreach ( $lines as $line ) { |
131 | | - if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) { |
132 | | - $prefix = $wgContLang->lc( $matches[1] ); |
133 | | - $prefix = str_replace( ' ', '_', $prefix ); |
134 | | - |
135 | | - $url = $matches[2]; |
136 | | - if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { |
137 | | - if ( $this->hasOption( 'protocolrelative' ) ) { |
138 | | - if ( substr( $url, 0, 5 ) == 'http:' ) { |
139 | | - $url = substr( $url, 5 ); |
140 | | - } else if ( substr( $url, 0, 6 ) == 'https:' ) { |
141 | | - $url = substr( $url, 6 ); |
142 | | - } |
143 | | - } |
144 | | - $local = 1; |
145 | | - } else { |
146 | | - $local = 0; |
147 | | - } |
148 | | - |
149 | | - if ( empty( $reserved[$prefix] ) ) { |
150 | | - $imap = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); |
151 | | - $this->makeLink ( $imap, "__global" ); |
152 | | - } |
153 | | - } |
154 | | - } |
155 | | - |
156 | | - # Exclude Wikipedia for Wikipedia |
157 | | - $this->makeLink ( array ( 'iw_prefix' => 'wikipedia', 'is_url' => null ), "_wiki" ); |
158 | | - |
159 | | - # Multilanguage sites |
160 | | - foreach ( $sites as $site ) { |
161 | | - $this->makeLanguageLinks ( $site, "_" . $site->suffix ); |
162 | | - } |
163 | | - |
164 | | - foreach ( $this->dblist as $db ) { |
165 | | - if ( isset( $this->specials[$db] ) ) { |
166 | | - # Special wiki |
167 | | - # Has interwiki links and interlanguage links to wikipedia |
168 | | - |
169 | | - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki" ), "__sites" ); |
170 | | - # Links to multilanguage sites |
171 | | - foreach ( $sites as $targetSite ) { |
172 | | - $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, |
173 | | - 'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ), |
174 | | - 'iw_local' => 1 ), $db ); |
175 | | - } |
176 | | - } else { |
177 | | - # Find out which site this DB belongs to |
178 | | - $site = false; |
179 | | - foreach ( $sites as $candidateSite ) { |
180 | | - $suffix = $candidateSite->suffix; |
181 | | - if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { |
182 | | - $site = $candidateSite; |
183 | | - break; |
184 | | - } |
185 | | - } |
186 | | - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix ), "__sites" ); |
187 | | - if ( !$site ) { |
188 | | - $this->error( "Invalid database $db\n" ); |
189 | | - continue; |
190 | | - } |
191 | | - $lang = $matches[1]; |
192 | | - |
193 | | - # Lateral links |
194 | | - foreach ( $sites as $targetSite ) { |
195 | | - if ( $targetSite->suffix != $site->suffix ) { |
196 | | - $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, |
197 | | - 'iw_url' => $targetSite->getURL( $lang, $this->urlprotocol ), |
198 | | - 'iw_local' => 1 ), $db ); |
199 | | - } |
200 | | - } |
201 | | - |
202 | | - if ( $site->suffix == "wiki" ) { |
203 | | - $this->makeLink( array( 'iw_prefix' => 'w', |
204 | | - 'iw_url' => $this->urlprotocol . "//en.wikipedia.org/wiki/$1", |
205 | | - 'iw_local' => 1 ), $db ); |
206 | | - } |
207 | | - |
208 | | - } |
209 | | - } |
210 | | - foreach ( $extraLinks as $link ) { |
211 | | - $this->makeLink( $link, "__global" ); |
212 | | - } |
213 | | - |
214 | | - # List prefixes for each source |
215 | | - foreach ( $this->prefixLists as $source => $hash ) { |
216 | | - $list = array_keys( $hash ); |
217 | | - sort( $list ); |
218 | | - if ( $this->dbFile ) { |
219 | | - $this->dbFile->set( "__list:{$source}", implode( ' ', $list ) ); |
220 | | - } else { |
221 | | - print "__list:{$source} " . implode( ' ', $list ) . "\n"; |
222 | | - } |
223 | | - } |
224 | | - } |
225 | | - |
226 | | - # ------------------------------------------------------------------------------------------ |
227 | | - |
228 | | - # Executes part of an INSERT statement, corresponding to all interlanguage links to a particular site |
229 | | - function makeLanguageLinks( &$site, $source ) { |
230 | | - # Actual languages with their own databases |
231 | | - foreach ( $this->langlist as $targetLang ) { |
232 | | - $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source ); |
233 | | - } |
234 | | - |
235 | | - # Language aliases |
236 | | - foreach ( $this->languageAliases as $alias => $lang ) { |
237 | | - $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source ); |
238 | | - } |
239 | | - } |
240 | | - |
241 | | - function makeLink( $entry, $source ) { |
242 | | - if ( isset( $this->prefixRewrites[$source] ) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) |
243 | | - $entry[0] = $this->prefixRewrites[$source][$entry[0]]; |
244 | | - |
245 | | - if ( !array_key_exists( "iw_prefix", $entry ) ) { |
246 | | - $entry = array( "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] ); |
247 | | - } |
248 | | - if ( array_key_exists( $source, $this->prefixRewrites ) && |
249 | | - array_key_exists( $entry['iw_prefix'], $this->prefixRewrites[$source] ) ) { |
250 | | - $entry['iw_prefix'] = $this->prefixRewrites[$source][$entry['iw_prefix']]; |
251 | | - } |
252 | | - |
253 | | - if ( $this->dbFile ) { |
254 | | - $this->dbFile->set( "{$source}:{$entry['iw_prefix']}", trim( "{$entry['iw_local']} {$entry['iw_url']}" ) ); |
255 | | - } else { |
256 | | - $this->output( "{$source}:{$entry['iw_prefix']} {$entry['iw_url']} {$entry['iw_local']}\n" ); |
257 | | - } |
258 | | - |
259 | | - # Add to list of prefixes |
260 | | - $this->prefixLists[$source][$entry['iw_prefix']] = 1; |
261 | | - } |
262 | | -} |
263 | | - |
264 | | -$maintClass = "DumpInterwiki"; |
265 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
266 | | - |
Index: trunk/phase3/maintenance/ourusers.php |
— | — | @@ -1,70 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Wikimedia specific |
5 | | - * |
6 | | - * This script generates SQL used to update MySQL users on a hardcoded |
7 | | - * list of hosts. It takes care of setting the wikiuser for every |
8 | | - * database as well as setting up wikiadmin. |
9 | | - * |
10 | | - * This program is free software; you can redistribute it and/or modify |
11 | | - * it under the terms of the GNU General Public License as published by |
12 | | - * the Free Software Foundation; either version 2 of the License, or |
13 | | - * (at your option) any later version. |
14 | | - * |
15 | | - * This program is distributed in the hope that it will be useful, |
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | - * GNU General Public License for more details. |
19 | | - * |
20 | | - * You should have received a copy of the GNU General Public License along |
21 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
22 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 | | - * http://www.gnu.org/copyleft/gpl.html |
24 | | - * |
25 | | - * @todo document |
26 | | - * @file |
27 | | - * @ingroup Maintenance |
28 | | - * @ingroup Wikimedia |
29 | | - */ |
30 | | - |
31 | | -/** */ |
32 | | -$wikiuser_pass = `wikiuser_pass`; |
33 | | -$wikiadmin_pass = `wikiadmin_pass`; |
34 | | -$nagios_pass = `nagios_sql_pass`; |
35 | | - |
36 | | -$hosts = array( |
37 | | - 'localhost', |
38 | | - '10.0.%', |
39 | | - '66.230.200.%', |
40 | | - '208.80.152.%', |
41 | | -); |
42 | | - |
43 | | -$databases = array( |
44 | | - '%wik%', |
45 | | - 'centralauth', |
46 | | -); |
47 | | - |
48 | | -print "/*!40100 set old_passwords=1 */;\n"; |
49 | | -print "/*!40100 set global old_passwords=1 */;\n"; |
50 | | - |
51 | | -foreach ( $hosts as $host ) { |
52 | | - print "--\n-- $host\n--\n"; |
53 | | - print "\n-- wikiuser\n\n"; |
54 | | - print "GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
55 | | - print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
56 | | - foreach ( $databases as $db ) { |
57 | | - print "GRANT SELECT, INSERT, UPDATE, DELETE ON `$db`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
58 | | - } |
59 | | - |
60 | | - print "\n-- wikiadmin\n\n"; |
61 | | - print "GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'wikiadmin'@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
62 | | - print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
63 | | - foreach ( $databases as $db ) { |
64 | | - print "GRANT ALL PRIVILEGES ON `$db`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
65 | | - } |
66 | | - print "\n-- nagios\n\n"; |
67 | | - print "GRANT REPLICATION CLIENT ON *.* TO 'nagios'@'$host' IDENTIFIED BY '$nagios_pass';\n"; |
68 | | - |
69 | | - print "\n"; |
70 | | -} |
71 | | - |
Index: trunk/phase3/maintenance/rebuildInterwiki.php |
— | — | @@ -1,275 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Rebuild interwiki table using the file on meta and the language list |
5 | | - * Wikimedia specific! |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - * |
22 | | - * @file |
23 | | - * @todo document |
24 | | - * @ingroup Maintenance |
25 | | - * @ingroup Wikimedia |
26 | | - */ |
27 | | - |
28 | | -require_once( dirname( __FILE__ ) . '/Site.php' ); |
29 | | - |
30 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
31 | | - |
32 | | -class RebuildInterwiki extends Maintenance { |
33 | | - public function __construct() { |
34 | | - parent::__construct(); |
35 | | - $this->mDescription = "Rebuild the interwiki table using the file on meta and the language list."; |
36 | | - $this->addOption( 'langlist', 'File with one language code per line', false, true ); |
37 | | - $this->addOption( 'dblist', 'File with one db per line', false, true ); |
38 | | - $this->addOption( 'd', 'Output folder', false, true ); |
39 | | - } |
40 | | - |
41 | | - function execute() { |
42 | | - # List of language prefixes likely to be found in multi-language sites |
43 | | - $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); |
44 | | - |
45 | | - # List of all database names |
46 | | - $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); |
47 | | - |
48 | | - # Special-case databases |
49 | | - //$this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); |
50 | | - |
51 | | - $this->makeInterwikiSQL( $this->getOption( 'd', '/home/wikipedia/conf/interwiki/sql' ) ); |
52 | | - } |
53 | | - |
54 | | - function makeInterwikiSQL( $destDir ) { |
55 | | - $this->output( "Making new interwiki SQL files in $destDir\n" ); |
56 | | - |
57 | | - # Multi-language sites |
58 | | - # db suffix => db suffix, iw prefix, hostname |
59 | | - $sites = array( |
60 | | - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), |
61 | | - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), |
62 | | - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), |
63 | | - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), |
64 | | - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), |
65 | | - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), |
66 | | - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), |
67 | | - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), |
68 | | - ); |
69 | | - |
70 | | - # Special-case hostnames |
71 | | - $this->specials = array( |
72 | | - 'sourceswiki' => 'sources.wikipedia.org', |
73 | | - 'quotewiki' => 'wikiquote.org', |
74 | | - 'textbookwiki' => 'wikibooks.org', |
75 | | - 'sep11wiki' => 'sep11.wikipedia.org', |
76 | | - 'metawiki' => 'meta.wikimedia.org', |
77 | | - 'commonswiki' => 'commons.wikimedia.org', |
78 | | - 'specieswiki' => 'species.wikimedia.org', |
79 | | - ); |
80 | | - |
81 | | - # Extra interwiki links that can't be in the intermap for some reason |
82 | | - $extraLinks = array( |
83 | | - array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ), |
84 | | - array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ), |
85 | | - array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ), |
86 | | - ); |
87 | | - |
88 | | - # Language aliases, usually configured as redirects to the real wiki in apache |
89 | | - # Interlanguage links are made directly to the real wiki |
90 | | - # Something horrible happens if you forget to list an alias here, I can't |
91 | | - # remember what |
92 | | - $this->languageAliases = array( |
93 | | - 'zh-cn' => 'zh', |
94 | | - 'zh-tw' => 'zh', |
95 | | - 'dk' => 'da', |
96 | | - 'nb' => 'no', |
97 | | - ); |
98 | | - |
99 | | - # Special case prefix rewrites, for the benefit of Swedish which uses s:t |
100 | | - # as an abbreviation for saint |
101 | | - $this->prefixRewrites = array( |
102 | | - 'svwiki' => array( 's' => 'src' ), |
103 | | - ); |
104 | | - |
105 | | - # Construct a list of reserved prefixes |
106 | | - $reserved = array(); |
107 | | - foreach ( $this->langlist as $lang ) { |
108 | | - $reserved[$lang] = 1; |
109 | | - } |
110 | | - foreach ( $this->languageAliases as $alias => $lang ) { |
111 | | - $reserved[$alias] = 1; |
112 | | - } |
113 | | - foreach ( $sites as $site ) { |
114 | | - $reserved[$site->lateral] = 1; |
115 | | - } |
116 | | - |
117 | | - # Extract the intermap from meta |
118 | | - $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); |
119 | | - $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); |
120 | | - |
121 | | - if ( !$lines || count( $lines ) < 2 ) { |
122 | | - $this->error( "m:Interwiki_map not found", true ); |
123 | | - } |
124 | | - |
125 | | - $iwArray = array(); |
126 | | - |
127 | | - foreach ( $lines as $line ) { |
128 | | - $matches = array(); |
129 | | - if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(https?:\/\/.*?)\s*$/', $line, $matches ) ) { |
130 | | - $prefix = strtolower( $matches[1] ); |
131 | | - $url = $matches[2]; |
132 | | - if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { |
133 | | - $local = 1; |
134 | | - } else { |
135 | | - $local = 0; |
136 | | - } |
137 | | - |
138 | | - if ( empty( $reserved[$prefix] ) ) { |
139 | | - $iwArray[$prefix] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); |
140 | | - } |
141 | | - } |
142 | | - } |
143 | | - |
144 | | - foreach ( $this->dblist as $db ) { |
145 | | - $sql = "-- Generated by rebuildInterwiki.php"; |
146 | | - if ( isset( $this->specials[$db] ) ) { |
147 | | - # Special wiki |
148 | | - # Has interwiki links and interlanguage links to wikipedia |
149 | | - |
150 | | - $host = $this->specials[$db]; |
151 | | - $sql .= "\n--$host\n\n"; |
152 | | - $sql .= "USE $db;\n" . |
153 | | - "TRUNCATE TABLE interwiki;\n" . |
154 | | - "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n"; |
155 | | - $first = true; |
156 | | - |
157 | | - # Intermap links |
158 | | - foreach ( $iwArray as $iwEntry ) { |
159 | | - $sql .= $this->makeLink( $iwEntry, $first, $db ); |
160 | | - } |
161 | | - |
162 | | - # Links to multilanguage sites |
163 | | - foreach ( $sites as $targetSite ) { |
164 | | - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db ); |
165 | | - } |
166 | | - |
167 | | - # Interlanguage links to wikipedia |
168 | | - $sql .= $this->makeLanguageLinks( $sites['wiki'], $first, $db ); |
169 | | - |
170 | | - # Extra links |
171 | | - foreach ( $extraLinks as $link ) { |
172 | | - $sql .= $this->makeLink( $link, $first, $db ); |
173 | | - } |
174 | | - |
175 | | - $sql .= ";\n"; |
176 | | - } else { |
177 | | - # Find out which site this DB belongs to |
178 | | - $site = false; |
179 | | - foreach ( $sites as $candidateSite ) { |
180 | | - $suffix = $candidateSite->suffix; |
181 | | - if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { |
182 | | - $site = $candidateSite; |
183 | | - break; |
184 | | - } |
185 | | - } |
186 | | - if ( !$site ) { |
187 | | - print "Invalid database $db\n"; |
188 | | - continue; |
189 | | - } |
190 | | - $lang = $matches[1]; |
191 | | - $host = "$lang." . $site->url; |
192 | | - $sql .= "\n--$host\n\n"; |
193 | | - |
194 | | - $sql .= "USE $db;\n" . |
195 | | - "TRUNCATE TABLE interwiki;\n" . |
196 | | - "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n"; |
197 | | - $first = true; |
198 | | - |
199 | | - # Intermap links |
200 | | - foreach ( $iwArray as $iwEntry ) { |
201 | | - # Suppress links with the same name as the site |
202 | | - if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || |
203 | | - ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) |
204 | | - { |
205 | | - $sql .= $this->makeLink( $iwEntry, $first, $db ); |
206 | | - } |
207 | | - } |
208 | | - |
209 | | - # Lateral links |
210 | | - foreach ( $sites as $targetSite ) { |
211 | | - # Suppress link to self |
212 | | - if ( $targetSite->suffix != $site->suffix ) { |
213 | | - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first, $db ); |
214 | | - } |
215 | | - } |
216 | | - |
217 | | - # Interlanguage links |
218 | | - $sql .= $this->makeLanguageLinks( $site, $first, $db ); |
219 | | - |
220 | | - # w link within wikipedias |
221 | | - # Other sites already have it as a lateral link |
222 | | - if ( $site->suffix == "wiki" ) { |
223 | | - $sql .= $this->makeLink( array( "w", "http://en.wikipedia.org/wiki/$1", 1 ), $first, $db ); |
224 | | - } |
225 | | - |
226 | | - # Extra links |
227 | | - foreach ( $extraLinks as $link ) { |
228 | | - $sql .= $this->makeLink( $link, $first, $db ); |
229 | | - } |
230 | | - $sql .= ";\n"; |
231 | | - } |
232 | | - file_put_contents( "$destDir/$db.sql", $sql ); |
233 | | - } |
234 | | - } |
235 | | - |
236 | | - # ------------------------------------------------------------------------------------------ |
237 | | - |
238 | | - # Returns part of an INSERT statement, corresponding to all interlanguage links to a particular site |
239 | | - function makeLanguageLinks( &$site, &$first, $source ) { |
240 | | - $sql = ""; |
241 | | - |
242 | | - # Actual languages with their own databases |
243 | | - foreach ( $this->langlist as $targetLang ) { |
244 | | - $sql .= $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first, $source ); |
245 | | - } |
246 | | - |
247 | | - # Language aliases |
248 | | - foreach ( $this->languageAliases as $alias => $lang ) { |
249 | | - $sql .= $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first, $source ); |
250 | | - } |
251 | | - return $sql; |
252 | | - } |
253 | | - |
254 | | - # Make SQL for a single link from an array |
255 | | - function makeLink( $entry, &$first, $source ) { |
256 | | - |
257 | | - if ( isset( $this->prefixRewrites[$source] ) && isset($entry[0]) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) { |
258 | | - $entry[0] = $this->prefixRewrites[$source][$entry[0]]; |
259 | | - } |
260 | | - |
261 | | - $sql = ""; |
262 | | - # Add comma |
263 | | - if ( $first ) { |
264 | | - $first = false; |
265 | | - } else { |
266 | | - $sql .= ",\n"; |
267 | | - } |
268 | | - $dbr = wfGetDB( DB_SLAVE ); |
269 | | - $sql .= "(" . $dbr->makeList( $entry ) . ")"; |
270 | | - return $sql; |
271 | | - } |
272 | | -} |
273 | | - |
274 | | -$maintClass = "RebuildInterwiki"; |
275 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
276 | | - |
Index: trunk/phase3/maintenance/Site.php |
— | — | @@ -1,19 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @todo document |
5 | | - * @ingroup Maintenance |
6 | | - */ |
7 | | -class Site { |
8 | | - var $suffix, $lateral, $url; |
9 | | - |
10 | | - function __construct( $s, $l, $u ) { |
11 | | - $this->suffix = $s; |
12 | | - $this->lateral = $l; |
13 | | - $this->url = $u; |
14 | | - } |
15 | | - |
16 | | - function getURL( $lang, $urlprotocol ) { |
17 | | - $xlang = str_replace( '_', '-', $lang ); |
18 | | - return "$urlprotocol//$xlang.{$this->url}/wiki/\$1"; |
19 | | - } |
20 | | -} |
Index: trunk/extensions/WikimediaMaintenance/ourusers.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Wikimedia specific |
| 5 | + * |
| 6 | + * This script generates SQL used to update MySQL users on a hardcoded |
| 7 | + * list of hosts. It takes care of setting the wikiuser for every |
| 8 | + * database as well as setting up wikiadmin. |
| 9 | + * |
| 10 | + * This program is free software; you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation; either version 2 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU General Public License along |
| 21 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 23 | + * http://www.gnu.org/copyleft/gpl.html |
| 24 | + * |
| 25 | + * @todo document |
| 26 | + * @file |
| 27 | + * @ingroup Maintenance |
| 28 | + * @ingroup Wikimedia |
| 29 | + */ |
| 30 | + |
| 31 | +/** */ |
| 32 | +$wikiuser_pass = `wikiuser_pass`; |
| 33 | +$wikiadmin_pass = `wikiadmin_pass`; |
| 34 | +$nagios_pass = `nagios_sql_pass`; |
| 35 | + |
| 36 | +$hosts = array( |
| 37 | + 'localhost', |
| 38 | + '10.0.%', |
| 39 | + '66.230.200.%', |
| 40 | + '208.80.152.%', |
| 41 | +); |
| 42 | + |
| 43 | +$databases = array( |
| 44 | + '%wik%', |
| 45 | + 'centralauth', |
| 46 | +); |
| 47 | + |
| 48 | +print "/*!40100 set old_passwords=1 */;\n"; |
| 49 | +print "/*!40100 set global old_passwords=1 */;\n"; |
| 50 | + |
| 51 | +foreach ( $hosts as $host ) { |
| 52 | + print "--\n-- $host\n--\n"; |
| 53 | + print "\n-- wikiuser\n\n"; |
| 54 | + print "GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
| 55 | + print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
| 56 | + foreach ( $databases as $db ) { |
| 57 | + print "GRANT SELECT, INSERT, UPDATE, DELETE ON `$db`.* TO 'wikiuser'@'$host' IDENTIFIED BY '$wikiuser_pass';\n"; |
| 58 | + } |
| 59 | + |
| 60 | + print "\n-- wikiadmin\n\n"; |
| 61 | + print "GRANT PROCESS, REPLICATION CLIENT ON *.* TO 'wikiadmin'@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
| 62 | + print "GRANT ALL PRIVILEGES ON `boardvote%`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
| 63 | + foreach ( $databases as $db ) { |
| 64 | + print "GRANT ALL PRIVILEGES ON `$db`.* TO wikiadmin@'$host' IDENTIFIED BY '$wikiadmin_pass';\n"; |
| 65 | + } |
| 66 | + print "\n-- nagios\n\n"; |
| 67 | + print "GRANT REPLICATION CLIENT ON *.* TO 'nagios'@'$host' IDENTIFIED BY '$nagios_pass';\n"; |
| 68 | + |
| 69 | + print "\n"; |
| 70 | +} |
| 71 | + |
Property changes on: trunk/extensions/WikimediaMaintenance/ourusers.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 72 | + native |
Added: svn:keywords |
2 | 73 | + Author Date Id Revision |
Index: trunk/extensions/WikimediaMaintenance/dumpInterwiki.php |
— | — | @@ -0,0 +1,269 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Build constant slightly compact database of interwiki prefixes |
| 5 | + * Wikimedia specific! |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + * |
| 22 | + * @file |
| 23 | + * @todo document |
| 24 | + * @ingroup Maintenance |
| 25 | + * @ingroup Wikimedia |
| 26 | + */ |
| 27 | + |
| 28 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 29 | +if ( $IP === false ) { |
| 30 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 31 | +} |
| 32 | +require( "$IP/maintenance/Maintenance.php" ); |
| 33 | + |
| 34 | +require_once( dirname( __FILE__ ) . '/Site.php' ); |
| 35 | + |
| 36 | +class DumpInterwiki extends Maintenance { |
| 37 | + |
| 38 | + public function __construct() { |
| 39 | + parent::__construct(); |
| 40 | + $this->mDescription = "Build constant slightly compact database of interwiki prefixes."; |
| 41 | + $this->addOption( 'langlist', 'File with one language code per line', false, true ); |
| 42 | + $this->addOption( 'dblist', 'File with one db per line', false, true ); |
| 43 | + $this->addOption( 'specialdbs', "File with one 'special' db per line", false, true ); |
| 44 | + $this->addOption( 'o', 'Cdb output file', false, true ); |
| 45 | + $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false ); |
| 46 | + } |
| 47 | + |
| 48 | + function execute() { |
| 49 | + # List of language prefixes likely to be found in multi-language sites |
| 50 | + $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); |
| 51 | + |
| 52 | + # List of all database names |
| 53 | + $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); |
| 54 | + |
| 55 | + # Special-case databases |
| 56 | + $this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); |
| 57 | + |
| 58 | + if ( $this->hasOption( 'o' ) ) { |
| 59 | + $this->dbFile = CdbWriter::open( $this->getOption( 'o' ) ) ; |
| 60 | + } else { |
| 61 | + $this->dbFile = false; |
| 62 | + } |
| 63 | + |
| 64 | + if ( $this->hasOption( 'protocolrelative' ) ) { |
| 65 | + $this->urlprotocol = ''; |
| 66 | + } else { |
| 67 | + $this->urlprotocol = 'http:'; |
| 68 | + } |
| 69 | + |
| 70 | + $this->getRebuildInterwikiDump(); |
| 71 | + } |
| 72 | + |
| 73 | + function getRebuildInterwikiDump() { |
| 74 | + global $wgContLang; |
| 75 | + |
| 76 | + # Multi-language sites |
| 77 | + # db suffix => db suffix, iw prefix, hostname |
| 78 | + $sites = array( |
| 79 | + 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), |
| 80 | + 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), |
| 81 | + 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), |
| 82 | + 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), |
| 83 | + 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), |
| 84 | + 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), |
| 85 | + 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), |
| 86 | + 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), |
| 87 | + ); |
| 88 | + |
| 89 | + # Extra interwiki links that can't be in the intermap for some reason |
| 90 | + $extraLinks = array( |
| 91 | + array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), |
| 92 | + array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), |
| 93 | + array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ), |
| 94 | + ); |
| 95 | + |
| 96 | + # Language aliases, usually configured as redirects to the real wiki in apache |
| 97 | + # Interlanguage links are made directly to the real wiki |
| 98 | + # Something horrible happens if you forget to list an alias here, I can't |
| 99 | + # remember what |
| 100 | + $this->languageAliases = array( |
| 101 | + 'zh-cn' => 'zh', |
| 102 | + 'zh-tw' => 'zh', |
| 103 | + 'dk' => 'da', |
| 104 | + 'nb' => 'no', |
| 105 | + ); |
| 106 | + |
| 107 | + # Special case prefix rewrites, for the benefit of Swedish which uses s:t |
| 108 | + # as an abbreviation for saint |
| 109 | + $this->prefixRewrites = array( |
| 110 | + 'svwiki' => array( 's' => 'src' ), |
| 111 | + ); |
| 112 | + |
| 113 | + # Construct a list of reserved prefixes |
| 114 | + $reserved = array(); |
| 115 | + foreach ( $this->langlist as $lang ) { |
| 116 | + $reserved[$lang] = 1; |
| 117 | + } |
| 118 | + foreach ( $this->languageAliases as $alias => $lang ) { |
| 119 | + $reserved[$alias] = 1; |
| 120 | + } |
| 121 | + foreach ( $sites as $site ) { |
| 122 | + $reserved[$site->lateral] = 1; |
| 123 | + } |
| 124 | + |
| 125 | + # Extract the intermap from meta |
| 126 | + $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); |
| 127 | + $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); |
| 128 | + |
| 129 | + if ( !$lines || count( $lines ) < 2 ) { |
| 130 | + $this->error( "m:Interwiki_map not found", true ); |
| 131 | + } |
| 132 | + |
| 133 | + # Global interwiki map |
| 134 | + foreach ( $lines as $line ) { |
| 135 | + if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) { |
| 136 | + $prefix = $wgContLang->lc( $matches[1] ); |
| 137 | + $prefix = str_replace( ' ', '_', $prefix ); |
| 138 | + |
| 139 | + $url = $matches[2]; |
| 140 | + if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { |
| 141 | + if ( $this->hasOption( 'protocolrelative' ) ) { |
| 142 | + if ( substr( $url, 0, 5 ) == 'http:' ) { |
| 143 | + $url = substr( $url, 5 ); |
| 144 | + } else if ( substr( $url, 0, 6 ) == 'https:' ) { |
| 145 | + $url = substr( $url, 6 ); |
| 146 | + } |
| 147 | + } |
| 148 | + $local = 1; |
| 149 | + } else { |
| 150 | + $local = 0; |
| 151 | + } |
| 152 | + |
| 153 | + if ( empty( $reserved[$prefix] ) ) { |
| 154 | + $imap = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); |
| 155 | + $this->makeLink ( $imap, "__global" ); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + # Exclude Wikipedia for Wikipedia |
| 161 | + $this->makeLink ( array ( 'iw_prefix' => 'wikipedia', 'is_url' => null ), "_wiki" ); |
| 162 | + |
| 163 | + # Multilanguage sites |
| 164 | + foreach ( $sites as $site ) { |
| 165 | + $this->makeLanguageLinks ( $site, "_" . $site->suffix ); |
| 166 | + } |
| 167 | + |
| 168 | + foreach ( $this->dblist as $db ) { |
| 169 | + if ( isset( $this->specials[$db] ) ) { |
| 170 | + # Special wiki |
| 171 | + # Has interwiki links and interlanguage links to wikipedia |
| 172 | + |
| 173 | + $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki" ), "__sites" ); |
| 174 | + # Links to multilanguage sites |
| 175 | + foreach ( $sites as $targetSite ) { |
| 176 | + $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, |
| 177 | + 'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ), |
| 178 | + 'iw_local' => 1 ), $db ); |
| 179 | + } |
| 180 | + } else { |
| 181 | + # Find out which site this DB belongs to |
| 182 | + $site = false; |
| 183 | + foreach ( $sites as $candidateSite ) { |
| 184 | + $suffix = $candidateSite->suffix; |
| 185 | + if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { |
| 186 | + $site = $candidateSite; |
| 187 | + break; |
| 188 | + } |
| 189 | + } |
| 190 | + $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix ), "__sites" ); |
| 191 | + if ( !$site ) { |
| 192 | + $this->error( "Invalid database $db\n" ); |
| 193 | + continue; |
| 194 | + } |
| 195 | + $lang = $matches[1]; |
| 196 | + |
| 197 | + # Lateral links |
| 198 | + foreach ( $sites as $targetSite ) { |
| 199 | + if ( $targetSite->suffix != $site->suffix ) { |
| 200 | + $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, |
| 201 | + 'iw_url' => $targetSite->getURL( $lang, $this->urlprotocol ), |
| 202 | + 'iw_local' => 1 ), $db ); |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + if ( $site->suffix == "wiki" ) { |
| 207 | + $this->makeLink( array( 'iw_prefix' => 'w', |
| 208 | + 'iw_url' => $this->urlprotocol . "//en.wikipedia.org/wiki/$1", |
| 209 | + 'iw_local' => 1 ), $db ); |
| 210 | + } |
| 211 | + |
| 212 | + } |
| 213 | + } |
| 214 | + foreach ( $extraLinks as $link ) { |
| 215 | + $this->makeLink( $link, "__global" ); |
| 216 | + } |
| 217 | + |
| 218 | + # List prefixes for each source |
| 219 | + foreach ( $this->prefixLists as $source => $hash ) { |
| 220 | + $list = array_keys( $hash ); |
| 221 | + sort( $list ); |
| 222 | + if ( $this->dbFile ) { |
| 223 | + $this->dbFile->set( "__list:{$source}", implode( ' ', $list ) ); |
| 224 | + } else { |
| 225 | + print "__list:{$source} " . implode( ' ', $list ) . "\n"; |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + # ------------------------------------------------------------------------------------------ |
| 231 | + |
| 232 | + # Executes part of an INSERT statement, corresponding to all interlanguage links to a particular site |
| 233 | + function makeLanguageLinks( &$site, $source ) { |
| 234 | + # Actual languages with their own databases |
| 235 | + foreach ( $this->langlist as $targetLang ) { |
| 236 | + $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source ); |
| 237 | + } |
| 238 | + |
| 239 | + # Language aliases |
| 240 | + foreach ( $this->languageAliases as $alias => $lang ) { |
| 241 | + $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source ); |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + function makeLink( $entry, $source ) { |
| 246 | + if ( isset( $this->prefixRewrites[$source] ) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) |
| 247 | + $entry[0] = $this->prefixRewrites[$source][$entry[0]]; |
| 248 | + |
| 249 | + if ( !array_key_exists( "iw_prefix", $entry ) ) { |
| 250 | + $entry = array( "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] ); |
| 251 | + } |
| 252 | + if ( array_key_exists( $source, $this->prefixRewrites ) && |
| 253 | + array_key_exists( $entry['iw_prefix'], $this->prefixRewrites[$source] ) ) { |
| 254 | + $entry['iw_prefix'] = $this->prefixRewrites[$source][$entry['iw_prefix']]; |
| 255 | + } |
| 256 | + |
| 257 | + if ( $this->dbFile ) { |
| 258 | + $this->dbFile->set( "{$source}:{$entry['iw_prefix']}", trim( "{$entry['iw_local']} {$entry['iw_url']}" ) ); |
| 259 | + } else { |
| 260 | + $this->output( "{$source}:{$entry['iw_prefix']} {$entry['iw_url']} {$entry['iw_local']}\n" ); |
| 261 | + } |
| 262 | + |
| 263 | + # Add to list of prefixes |
| 264 | + $this->prefixLists[$source][$entry['iw_prefix']] = 1; |
| 265 | + } |
| 266 | +} |
| 267 | + |
| 268 | +$maintClass = "DumpInterwiki"; |
| 269 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 270 | + |
Property changes on: trunk/extensions/WikimediaMaintenance/dumpInterwiki.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 271 | + native |
Added: svn:keywords |
2 | 272 | + Author Date Id Revision |
Index: trunk/extensions/WikimediaMaintenance/renameWiki.php |
— | — | @@ -0,0 +1,89 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Why yes, this *is* another special-purpose Wikimedia maintenance script! |
| 5 | + * Should be fixed up and generalized. |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + * |
| 22 | + * @file |
| 23 | + * @ingroup Maintenance |
| 24 | + * @ingroup Wikimedia |
| 25 | + */ |
| 26 | + |
| 27 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 28 | + |
| 29 | +class RenameWiki extends Maintenance { |
| 30 | + public function __construct() { |
| 31 | + parent::__construct(); |
| 32 | + $this->mDescription = "Rename external storage dbs and leave a new one"; |
| 33 | + $this->addArg( 'olddb', 'Old DB name' ); |
| 34 | + $this->addArg( 'newdb', 'New DB name' ); |
| 35 | + } |
| 36 | + |
| 37 | + public function getDbType() { |
| 38 | + return Maintenance::DB_ADMIN; |
| 39 | + } |
| 40 | + |
| 41 | + public function execute() { |
| 42 | + global $wgDefaultExternalStore; |
| 43 | + |
| 44 | + # Setup |
| 45 | + $from = $this->getArg( 0 ); |
| 46 | + $to = $this->getArg( 1 ); |
| 47 | + $this->output( "Renaming blob tables in ES from $from to $to...\n" ); |
| 48 | + $this->output( "Sleeping 5 seconds...\n" ); |
| 49 | + sleep( 5 ); |
| 50 | + |
| 51 | + # Initialise external storage |
| 52 | + if ( is_array( $wgDefaultExternalStore ) ) { |
| 53 | + $stores = $wgDefaultExternalStore; |
| 54 | + } elseif ( $wgDefaultExternalStore ) { |
| 55 | + $stores = array( $wgDefaultExternalStore ); |
| 56 | + } else { |
| 57 | + $stores = array(); |
| 58 | + } |
| 59 | + |
| 60 | + if ( count( $stores ) ) { |
| 61 | + $this->output( "Initialising external storage...\n" ); |
| 62 | + global $wgDBuser, $wgDBpassword, $wgExternalServers; |
| 63 | + foreach ( $stores as $storeURL ) { |
| 64 | + $m = array(); |
| 65 | + if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { |
| 66 | + continue; |
| 67 | + } |
| 68 | + |
| 69 | + $cluster = $m[1]; |
| 70 | + |
| 71 | + # Hack |
| 72 | + $wgExternalServers[$cluster][0]['user'] = $wgDBuser; |
| 73 | + $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; |
| 74 | + |
| 75 | + $store = new ExternalStoreDB; |
| 76 | + $extdb =& $store->getMaster( $cluster ); |
| 77 | + $extdb->query( "SET table_type=InnoDB" ); |
| 78 | + $extdb->query( "CREATE DATABASE {$to}" ); |
| 79 | + $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" ); |
| 80 | + $extdb->selectDB( $from ); |
| 81 | + $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' ); |
| 82 | + $extdb->commit(); |
| 83 | + } |
| 84 | + } |
| 85 | + $this->output( "done.\n" ); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +$maintClass = "RenameWiki"; |
| 90 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/extensions/WikimediaMaintenance/renameWiki.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 91 | + native |
Index: trunk/extensions/WikimediaMaintenance/addwiki.php |
— | — | @@ -0,0 +1,207 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @defgroup Wikimedia Wikimedia |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * Add a new wiki |
| 9 | + * Wikimedia specific! |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + * |
| 26 | + * @file |
| 27 | + * @ingroup Maintenance |
| 28 | + * @ingroup Wikimedia |
| 29 | + */ |
| 30 | + |
| 31 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 32 | + |
| 33 | +class AddWiki extends Maintenance { |
| 34 | + public function __construct() { |
| 35 | + global $wgNoDBParam; |
| 36 | + |
| 37 | + parent::__construct(); |
| 38 | + $this->mDescription = "Add a new wiki to the family. Wikimedia specific!"; |
| 39 | + $this->addArg( 'language', 'Language code of new site, e.g. en' ); |
| 40 | + $this->addArg( 'site', 'Type of site, e.g. wikipedia' ); |
| 41 | + $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' ); |
| 42 | + $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' ); |
| 43 | + |
| 44 | + $wgNoDBParam = true; |
| 45 | + } |
| 46 | + |
| 47 | + public function getDbType() { |
| 48 | + return Maintenance::DB_ADMIN; |
| 49 | + } |
| 50 | + |
| 51 | + public function execute() { |
| 52 | + global $IP, $wgDefaultExternalStore, $wmfVersionNumber; |
| 53 | + if ( !$wmfVersionNumber ) { // set in CommonSettings.php |
| 54 | + $this->error( '$wmfVersionNumber is not set, please use MWScript.php wrapper.', true ); |
| 55 | + } |
| 56 | + |
| 57 | + $lang = $this->getArg( 0 ); |
| 58 | + $site = $this->getArg( 1 ); |
| 59 | + $dbName = $this->getArg( 2 ); |
| 60 | + $domain = $this->getArg( 3 ); |
| 61 | + $languageNames = Language::getLanguageNames(); |
| 62 | + |
| 63 | + if ( !isset( $languageNames[$lang] ) ) { |
| 64 | + $this->error( "Language $lang not found in Names.php", true ); |
| 65 | + } |
| 66 | + $name = $languageNames[$lang]; |
| 67 | + |
| 68 | + $dbw = wfGetDB( DB_MASTER ); |
| 69 | + $common = "/home/wikipedia/common"; |
| 70 | + |
| 71 | + $this->output( "Creating database $dbName for $lang.$site ($name)\n" ); |
| 72 | + |
| 73 | + # Set up the database |
| 74 | + $dbw->query( "SET table_type=Innodb" ); |
| 75 | + $dbw->query( "CREATE DATABASE $dbName" ); |
| 76 | + $dbw->selectDB( $dbName ); |
| 77 | + |
| 78 | + $this->output( "Initialising tables\n" ); |
| 79 | + $dbw->sourceFile( $this->getDir() . '/tables.sql' ); |
| 80 | + $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" ); |
| 81 | + $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" ); |
| 82 | + $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" ); |
| 83 | + $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" ); |
| 84 | + $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" ); |
| 85 | + $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" ); |
| 86 | + $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" ); |
| 87 | + $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" ); |
| 88 | + $dbw->sourceFile( "$IP/extensions/PrefStats/patches/PrefStats.sql" ); |
| 89 | + $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" ); |
| 90 | + $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTrackingEvents.sql" ); |
| 91 | + $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTracking.sql" ); |
| 92 | + $dbw->sourceFile( "$IP/extensions/UserDailyContribs/patches/UserDailyContribs.sql" ); |
| 93 | + |
| 94 | + $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" ); |
| 95 | + |
| 96 | + # Initialise external storage |
| 97 | + if ( is_array( $wgDefaultExternalStore ) ) { |
| 98 | + $stores = $wgDefaultExternalStore; |
| 99 | + } elseif ( $wgDefaultExternalStore ) { |
| 100 | + $stores = array( $wgDefaultExternalStore ); |
| 101 | + } else { |
| 102 | + $stores = array(); |
| 103 | + } |
| 104 | + if ( count( $stores ) ) { |
| 105 | + global $wgDBuser, $wgDBpassword, $wgExternalServers; |
| 106 | + foreach ( $stores as $storeURL ) { |
| 107 | + $m = array(); |
| 108 | + if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { |
| 109 | + continue; |
| 110 | + } |
| 111 | + |
| 112 | + $cluster = $m[1]; |
| 113 | + $this->output( "Initialising external storage $cluster...\n" ); |
| 114 | + |
| 115 | + # Hack |
| 116 | + $wgExternalServers[$cluster][0]['user'] = $wgDBuser; |
| 117 | + $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; |
| 118 | + |
| 119 | + $store = new ExternalStoreDB; |
| 120 | + $extdb = $store->getMaster( $cluster ); |
| 121 | + $extdb->query( "SET table_type=InnoDB" ); |
| 122 | + $extdb->query( "CREATE DATABASE $dbName" ); |
| 123 | + $extdb->selectDB( $dbName ); |
| 124 | + |
| 125 | + # Hack x2 |
| 126 | + $blobsTable = $store->getTable( $extdb ); |
| 127 | + $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql"; |
| 128 | + $blobsFile = popen( $sedCmd, 'r' ); |
| 129 | + $extdb->sourceStream( $blobsFile ); |
| 130 | + pclose( $blobsFile ); |
| 131 | + $extdb->commit(); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() ); |
| 136 | + $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" ); |
| 137 | + $article = new Article( $title ); |
| 138 | + $ucsite = ucfirst( $site ); |
| 139 | + |
| 140 | + $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY ); |
| 141 | + |
| 142 | + $this->output( "Adding to dblists\n" ); |
| 143 | + |
| 144 | + # Add to dblist |
| 145 | + $file = fopen( "$common/all.dblist", "a" ); |
| 146 | + fwrite( $file, "$dbName\n" ); |
| 147 | + fclose( $file ); |
| 148 | + |
| 149 | + # Update the sublists |
| 150 | + shell_exec( "cd $common && ./refresh-dblist" ); |
| 151 | + |
| 152 | + # Add to wikiversions.dat |
| 153 | + $file = fopen( "$common/wikiversions.dat", "a" ); |
| 154 | + fwrite( $file, "$dbName php-$wmfVersionNumber\n" ); |
| 155 | + fclose( $file ); |
| 156 | + # Rebuild wikiversions.cdb |
| 157 | + shell_exec( "cd $common/multiversion && ./refreshWikiversionsCDB" ); |
| 158 | + |
| 159 | + # print "Constructing interwiki SQL\n"; |
| 160 | + # Rebuild interwiki tables |
| 161 | + # passthru( '/home/wikipedia/conf/interwiki/update' ); |
| 162 | + |
| 163 | + $time = wfTimestamp( TS_RFC2822 ); |
| 164 | + // These arguments need to be escaped twice: once for echo and once for at |
| 165 | + $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) ); |
| 166 | + $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) ); |
| 167 | + $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) ); |
| 168 | + $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) ); |
| 169 | + $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) ); |
| 170 | + $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) ); |
| 171 | + shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" ); |
| 172 | + |
| 173 | + $this->output( "Script ended. You still have to: |
| 174 | + * Add any required settings in InitialiseSettings.php |
| 175 | + * Run sync-common-all |
| 176 | + * Run /home/wikipedia/conf/interwiki/update |
| 177 | + " ); |
| 178 | + } |
| 179 | + |
| 180 | + private function getFirstArticle( $ucsite, $name ) { |
| 181 | + return <<<EOT |
| 182 | +==This subdomain is reserved for the creation of a [[wikimedia:Our projects|$ucsite]] in '''[[w:en:{$name}|{$name}]]''' language== |
| 183 | + |
| 184 | +* Please '''do not start editing''' this new site. This site has a test project on the [[incubator:|Wikimedia Incubator]] (or on the [[betawikiversity:|Beta Wikiversity]] or on the [[oldwikisource:|Old Wikisource]]) and it will be imported to here. |
| 185 | + |
| 186 | +* If you would like to help translating the interface to this language, please do not translate here, but go to [[translatewiki:|translatewiki.net]], a special wiki for translating the interface. That way everyone can use it on every wiki using the [[mw:|same software]]. |
| 187 | + |
| 188 | +* 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]]. |
| 189 | + |
| 190 | +== Sister projects == |
| 191 | +<span class="plainlinks"> |
| 192 | +[http://www.wikipedia.org Wikipedia] | |
| 193 | +[http://www.wiktionary.org Wiktionary] | |
| 194 | +[http://www.wikibooks.org Wikibooks] | |
| 195 | +[http://www.wikinews.org Wikinews] | |
| 196 | +[http://www.wikiquote.org Wikiquote] | |
| 197 | +[http://www.wikisource.org Wikisource] | |
| 198 | +[http://www.wikiversity.org Wikiversity] |
| 199 | +</span> |
| 200 | + |
| 201 | +See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects. |
| 202 | + |
| 203 | +EOT; |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +$maintClass = "AddWiki"; |
| 208 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/extensions/WikimediaMaintenance/addwiki.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 209 | + native |
Added: svn:keywords |
2 | 210 | + Author Date Id Revision |
Index: trunk/extensions/WikimediaMaintenance/rebuildInterwiki.php |
— | — | @@ -0,0 +1,279 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Rebuild interwiki table using the file on meta and the language list |
| 5 | + * Wikimedia specific! |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + * |
| 22 | + * @file |
| 23 | + * @todo document |
| 24 | + * @ingroup Maintenance |
| 25 | + * @ingroup Wikimedia |
| 26 | + */ |
| 27 | + |
| 28 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 29 | +if ( $IP === false ) { |
| 30 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 31 | +} |
| 32 | +require( "$IP/maintenance/Maintenance.php" ); |
| 33 | + |
| 34 | +require_once( dirname( __FILE__ ) . '/Site.php' ); |
| 35 | + |
| 36 | +class RebuildInterwiki extends Maintenance { |
| 37 | + public function __construct() { |
| 38 | + parent::__construct(); |
| 39 | + $this->mDescription = "Rebuild the interwiki table using the file on meta and the language list."; |
| 40 | + $this->addOption( 'langlist', 'File with one language code per line', false, true ); |
| 41 | + $this->addOption( 'dblist', 'File with one db per line', false, true ); |
| 42 | + $this->addOption( 'd', 'Output folder', false, true ); |
| 43 | + } |
| 44 | + |
| 45 | + function execute() { |
| 46 | + # List of language prefixes likely to be found in multi-language sites |
| 47 | + $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); |
| 48 | + |
| 49 | + # List of all database names |
| 50 | + $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); |
| 51 | + |
| 52 | + # Special-case databases |
| 53 | + //$this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); |
| 54 | + |
| 55 | + $this->makeInterwikiSQL( $this->getOption( 'd', '/home/wikipedia/conf/interwiki/sql' ) ); |
| 56 | + } |
| 57 | + |
| 58 | + function makeInterwikiSQL( $destDir ) { |
| 59 | + $this->output( "Making new interwiki SQL files in $destDir\n" ); |
| 60 | + |
| 61 | + # Multi-language sites |
| 62 | + # db suffix => db suffix, iw prefix, hostname |
| 63 | + $sites = array( |
| 64 | + 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), |
| 65 | + 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), |
| 66 | + 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), |
| 67 | + 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), |
| 68 | + 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), |
| 69 | + 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), |
| 70 | + 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), |
| 71 | + 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), |
| 72 | + ); |
| 73 | + |
| 74 | + # Special-case hostnames |
| 75 | + $this->specials = array( |
| 76 | + 'sourceswiki' => 'sources.wikipedia.org', |
| 77 | + 'quotewiki' => 'wikiquote.org', |
| 78 | + 'textbookwiki' => 'wikibooks.org', |
| 79 | + 'sep11wiki' => 'sep11.wikipedia.org', |
| 80 | + 'metawiki' => 'meta.wikimedia.org', |
| 81 | + 'commonswiki' => 'commons.wikimedia.org', |
| 82 | + 'specieswiki' => 'species.wikimedia.org', |
| 83 | + ); |
| 84 | + |
| 85 | + # Extra interwiki links that can't be in the intermap for some reason |
| 86 | + $extraLinks = array( |
| 87 | + array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ), |
| 88 | + array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ), |
| 89 | + array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ), |
| 90 | + ); |
| 91 | + |
| 92 | + # Language aliases, usually configured as redirects to the real wiki in apache |
| 93 | + # Interlanguage links are made directly to the real wiki |
| 94 | + # Something horrible happens if you forget to list an alias here, I can't |
| 95 | + # remember what |
| 96 | + $this->languageAliases = array( |
| 97 | + 'zh-cn' => 'zh', |
| 98 | + 'zh-tw' => 'zh', |
| 99 | + 'dk' => 'da', |
| 100 | + 'nb' => 'no', |
| 101 | + ); |
| 102 | + |
| 103 | + # Special case prefix rewrites, for the benefit of Swedish which uses s:t |
| 104 | + # as an abbreviation for saint |
| 105 | + $this->prefixRewrites = array( |
| 106 | + 'svwiki' => array( 's' => 'src' ), |
| 107 | + ); |
| 108 | + |
| 109 | + # Construct a list of reserved prefixes |
| 110 | + $reserved = array(); |
| 111 | + foreach ( $this->langlist as $lang ) { |
| 112 | + $reserved[$lang] = 1; |
| 113 | + } |
| 114 | + foreach ( $this->languageAliases as $alias => $lang ) { |
| 115 | + $reserved[$alias] = 1; |
| 116 | + } |
| 117 | + foreach ( $sites as $site ) { |
| 118 | + $reserved[$site->lateral] = 1; |
| 119 | + } |
| 120 | + |
| 121 | + # Extract the intermap from meta |
| 122 | + $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); |
| 123 | + $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); |
| 124 | + |
| 125 | + if ( !$lines || count( $lines ) < 2 ) { |
| 126 | + $this->error( "m:Interwiki_map not found", true ); |
| 127 | + } |
| 128 | + |
| 129 | + $iwArray = array(); |
| 130 | + |
| 131 | + foreach ( $lines as $line ) { |
| 132 | + $matches = array(); |
| 133 | + if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(https?:\/\/.*?)\s*$/', $line, $matches ) ) { |
| 134 | + $prefix = strtolower( $matches[1] ); |
| 135 | + $url = $matches[2]; |
| 136 | + if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { |
| 137 | + $local = 1; |
| 138 | + } else { |
| 139 | + $local = 0; |
| 140 | + } |
| 141 | + |
| 142 | + if ( empty( $reserved[$prefix] ) ) { |
| 143 | + $iwArray[$prefix] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + foreach ( $this->dblist as $db ) { |
| 149 | + $sql = "-- Generated by rebuildInterwiki.php"; |
| 150 | + if ( isset( $this->specials[$db] ) ) { |
| 151 | + # Special wiki |
| 152 | + # Has interwiki links and interlanguage links to wikipedia |
| 153 | + |
| 154 | + $host = $this->specials[$db]; |
| 155 | + $sql .= "\n--$host\n\n"; |
| 156 | + $sql .= "USE $db;\n" . |
| 157 | + "TRUNCATE TABLE interwiki;\n" . |
| 158 | + "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n"; |
| 159 | + $first = true; |
| 160 | + |
| 161 | + # Intermap links |
| 162 | + foreach ( $iwArray as $iwEntry ) { |
| 163 | + $sql .= $this->makeLink( $iwEntry, $first, $db ); |
| 164 | + } |
| 165 | + |
| 166 | + # Links to multilanguage sites |
| 167 | + foreach ( $sites as $targetSite ) { |
| 168 | + $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db ); |
| 169 | + } |
| 170 | + |
| 171 | + # Interlanguage links to wikipedia |
| 172 | + $sql .= $this->makeLanguageLinks( $sites['wiki'], $first, $db ); |
| 173 | + |
| 174 | + # Extra links |
| 175 | + foreach ( $extraLinks as $link ) { |
| 176 | + $sql .= $this->makeLink( $link, $first, $db ); |
| 177 | + } |
| 178 | + |
| 179 | + $sql .= ";\n"; |
| 180 | + } else { |
| 181 | + # Find out which site this DB belongs to |
| 182 | + $site = false; |
| 183 | + foreach ( $sites as $candidateSite ) { |
| 184 | + $suffix = $candidateSite->suffix; |
| 185 | + if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { |
| 186 | + $site = $candidateSite; |
| 187 | + break; |
| 188 | + } |
| 189 | + } |
| 190 | + if ( !$site ) { |
| 191 | + print "Invalid database $db\n"; |
| 192 | + continue; |
| 193 | + } |
| 194 | + $lang = $matches[1]; |
| 195 | + $host = "$lang." . $site->url; |
| 196 | + $sql .= "\n--$host\n\n"; |
| 197 | + |
| 198 | + $sql .= "USE $db;\n" . |
| 199 | + "TRUNCATE TABLE interwiki;\n" . |
| 200 | + "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n"; |
| 201 | + $first = true; |
| 202 | + |
| 203 | + # Intermap links |
| 204 | + foreach ( $iwArray as $iwEntry ) { |
| 205 | + # Suppress links with the same name as the site |
| 206 | + if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || |
| 207 | + ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) |
| 208 | + { |
| 209 | + $sql .= $this->makeLink( $iwEntry, $first, $db ); |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + # Lateral links |
| 214 | + foreach ( $sites as $targetSite ) { |
| 215 | + # Suppress link to self |
| 216 | + if ( $targetSite->suffix != $site->suffix ) { |
| 217 | + $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first, $db ); |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + # Interlanguage links |
| 222 | + $sql .= $this->makeLanguageLinks( $site, $first, $db ); |
| 223 | + |
| 224 | + # w link within wikipedias |
| 225 | + # Other sites already have it as a lateral link |
| 226 | + if ( $site->suffix == "wiki" ) { |
| 227 | + $sql .= $this->makeLink( array( "w", "http://en.wikipedia.org/wiki/$1", 1 ), $first, $db ); |
| 228 | + } |
| 229 | + |
| 230 | + # Extra links |
| 231 | + foreach ( $extraLinks as $link ) { |
| 232 | + $sql .= $this->makeLink( $link, $first, $db ); |
| 233 | + } |
| 234 | + $sql .= ";\n"; |
| 235 | + } |
| 236 | + file_put_contents( "$destDir/$db.sql", $sql ); |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + # ------------------------------------------------------------------------------------------ |
| 241 | + |
| 242 | + # Returns part of an INSERT statement, corresponding to all interlanguage links to a particular site |
| 243 | + function makeLanguageLinks( &$site, &$first, $source ) { |
| 244 | + $sql = ""; |
| 245 | + |
| 246 | + # Actual languages with their own databases |
| 247 | + foreach ( $this->langlist as $targetLang ) { |
| 248 | + $sql .= $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first, $source ); |
| 249 | + } |
| 250 | + |
| 251 | + # Language aliases |
| 252 | + foreach ( $this->languageAliases as $alias => $lang ) { |
| 253 | + $sql .= $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first, $source ); |
| 254 | + } |
| 255 | + return $sql; |
| 256 | + } |
| 257 | + |
| 258 | + # Make SQL for a single link from an array |
| 259 | + function makeLink( $entry, &$first, $source ) { |
| 260 | + |
| 261 | + if ( isset( $this->prefixRewrites[$source] ) && isset($entry[0]) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) { |
| 262 | + $entry[0] = $this->prefixRewrites[$source][$entry[0]]; |
| 263 | + } |
| 264 | + |
| 265 | + $sql = ""; |
| 266 | + # Add comma |
| 267 | + if ( $first ) { |
| 268 | + $first = false; |
| 269 | + } else { |
| 270 | + $sql .= ",\n"; |
| 271 | + } |
| 272 | + $dbr = wfGetDB( DB_SLAVE ); |
| 273 | + $sql .= "(" . $dbr->makeList( $entry ) . ")"; |
| 274 | + return $sql; |
| 275 | + } |
| 276 | +} |
| 277 | + |
| 278 | +$maintClass = "RebuildInterwiki"; |
| 279 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 280 | + |
Property changes on: trunk/extensions/WikimediaMaintenance/rebuildInterwiki.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 281 | + native |
Added: svn:keywords |
2 | 282 | + Author Date Id Revision |
Index: trunk/extensions/WikimediaMaintenance/Site.php |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @todo document |
| 5 | + * @ingroup Maintenance |
| 6 | + */ |
| 7 | +class Site { |
| 8 | + var $suffix, $lateral, $url; |
| 9 | + |
| 10 | + function __construct( $s, $l, $u ) { |
| 11 | + $this->suffix = $s; |
| 12 | + $this->lateral = $l; |
| 13 | + $this->url = $u; |
| 14 | + } |
| 15 | + |
| 16 | + function getURL( $lang, $urlprotocol ) { |
| 17 | + $xlang = str_replace( '_', '-', $lang ); |
| 18 | + return "$urlprotocol//$xlang.{$this->url}/wiki/\$1"; |
| 19 | + } |
| 20 | +} |
Property changes on: trunk/extensions/WikimediaMaintenance/Site.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 21 | + native |
Added: svn:keywords |
2 | 22 | + Author Date Id Revision |