From: Sam Reed Date: Wed, 7 Sep 2011 20:40:42 +0000 (+0000) Subject: Move addWiki, dumpInterwiki, ourusers, rebuildInterwiki, renameWiki and Site to Wikim... X-Git-Tag: 1.31.0-rc.0~27817 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=5432cda08159f7b02e51dfe832a63f00f639b75b;p=lhc%2Fweb%2Fwiklou.git Move addWiki, dumpInterwiki, ourusers, rebuildInterwiki, renameWiki and Site to WikimediaMaintenance "extension" --- diff --git a/maintenance/Site.php b/maintenance/Site.php deleted file mode 100644 index 87d637b45e..0000000000 --- a/maintenance/Site.php +++ /dev/null @@ -1,19 +0,0 @@ -suffix = $s; - $this->lateral = $l; - $this->url = $u; - } - - function getURL( $lang, $urlprotocol ) { - $xlang = str_replace( '_', '-', $lang ); - return "$urlprotocol//$xlang.{$this->url}/wiki/\$1"; - } -} diff --git a/maintenance/addwiki.php b/maintenance/addwiki.php deleted file mode 100644 index d75cce5867..0000000000 --- a/maintenance/addwiki.php +++ /dev/null @@ -1,207 +0,0 @@ -mDescription = "Add a new wiki to the family. Wikimedia specific!"; - $this->addArg( 'language', 'Language code of new site, e.g. en' ); - $this->addArg( 'site', 'Type of site, e.g. wikipedia' ); - $this->addArg( 'dbname', 'Name of database to create, e.g. enwiki' ); - $this->addArg( 'domain', 'Domain name of the wiki, e.g. en.wikipedia.org' ); - - $wgNoDBParam = true; - } - - public function getDbType() { - return Maintenance::DB_ADMIN; - } - - public function execute() { - global $IP, $wgDefaultExternalStore, $wmfVersionNumber; - if ( !$wmfVersionNumber ) { // set in CommonSettings.php - $this->error( '$wmfVersionNumber is not set, please use MWScript.php wrapper.', true ); - } - - $lang = $this->getArg( 0 ); - $site = $this->getArg( 1 ); - $dbName = $this->getArg( 2 ); - $domain = $this->getArg( 3 ); - $languageNames = Language::getLanguageNames(); - - if ( !isset( $languageNames[$lang] ) ) { - $this->error( "Language $lang not found in Names.php", true ); - } - $name = $languageNames[$lang]; - - $dbw = wfGetDB( DB_MASTER ); - $common = "/home/wikipedia/common"; - - $this->output( "Creating database $dbName for $lang.$site ($name)\n" ); - - # Set up the database - $dbw->query( "SET table_type=Innodb" ); - $dbw->query( "CREATE DATABASE $dbName" ); - $dbw->selectDB( $dbName ); - - $this->output( "Initialising tables\n" ); - $dbw->sourceFile( $this->getDir() . '/tables.sql' ); - $dbw->sourceFile( "$IP/extensions/OAI/update_table.sql" ); - $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" ); - $dbw->sourceFile( "$IP/extensions/CheckUser/cu_changes.sql" ); - $dbw->sourceFile( "$IP/extensions/CheckUser/cu_log.sql" ); - $dbw->sourceFile( "$IP/extensions/TitleKey/titlekey.sql" ); - $dbw->sourceFile( "$IP/extensions/Oversight/hidden.sql" ); - $dbw->sourceFile( "$IP/extensions/GlobalBlocking/localdb_patches/setup-global_block_whitelist.sql" ); - $dbw->sourceFile( "$IP/extensions/AbuseFilter/abusefilter.tables.sql" ); - $dbw->sourceFile( "$IP/extensions/PrefStats/patches/PrefStats.sql" ); - $dbw->sourceFile( "$IP/extensions/ProofreadPage/ProofreadPage.sql" ); - $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTrackingEvents.sql" ); - $dbw->sourceFile( "$IP/extensions/ClickTracking/patches/ClickTracking.sql" ); - $dbw->sourceFile( "$IP/extensions/UserDailyContribs/patches/UserDailyContribs.sql" ); - - $dbw->query( "INSERT INTO site_stats(ss_row_id) VALUES (1)" ); - - # Initialise external storage - if ( is_array( $wgDefaultExternalStore ) ) { - $stores = $wgDefaultExternalStore; - } elseif ( $wgDefaultExternalStore ) { - $stores = array( $wgDefaultExternalStore ); - } else { - $stores = array(); - } - if ( count( $stores ) ) { - global $wgDBuser, $wgDBpassword, $wgExternalServers; - foreach ( $stores as $storeURL ) { - $m = array(); - if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { - continue; - } - - $cluster = $m[1]; - $this->output( "Initialising external storage $cluster...\n" ); - - # Hack - $wgExternalServers[$cluster][0]['user'] = $wgDBuser; - $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; - - $store = new ExternalStoreDB; - $extdb = $store->getMaster( $cluster ); - $extdb->query( "SET table_type=InnoDB" ); - $extdb->query( "CREATE DATABASE $dbName" ); - $extdb->selectDB( $dbName ); - - # Hack x2 - $blobsTable = $store->getTable( $extdb ); - $sedCmd = "sed s/blobs\\\\\\>/$blobsTable/ " . $this->getDir() . "/storage/blobs.sql"; - $blobsFile = popen( $sedCmd, 'r' ); - $extdb->sourceStream( $blobsFile ); - pclose( $blobsFile ); - $extdb->commit(); - } - } - - $title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() ); - $this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" ); - $article = new Article( $title ); - $ucsite = ucfirst( $site ); - - $article->doEdit( $this->getFirstArticle( $ucsite, $name ), '', EDIT_NEW | EDIT_AUTOSUMMARY ); - - $this->output( "Adding to dblists\n" ); - - # Add to dblist - $file = fopen( "$common/all.dblist", "a" ); - fwrite( $file, "$dbName\n" ); - fclose( $file ); - - # Update the sublists - shell_exec( "cd $common && ./refresh-dblist" ); - - # Add to wikiversions.dat - $file = fopen( "$common/wikiversions.dat", "a" ); - fwrite( $file, "$dbName php-$wmfVersionNumber\n" ); - fclose( $file ); - # Rebuild wikiversions.cdb - shell_exec( "cd $common/multiversion && ./refreshWikiversionsCDB" ); - - # print "Constructing interwiki SQL\n"; - # Rebuild interwiki tables - # passthru( '/home/wikipedia/conf/interwiki/update' ); - - $time = wfTimestamp( TS_RFC2822 ); - // These arguments need to be escaped twice: once for echo and once for at - $escDbName = wfEscapeShellArg( wfEscapeShellArg( $dbName ) ); - $escTime = wfEscapeShellArg( wfEscapeShellArg( $time ) ); - $escUcsite = wfEscapeShellArg( wfEscapeShellArg( $ucsite ) ); - $escName = wfEscapeShellArg( wfEscapeShellArg( $name ) ); - $escLang = wfEscapeShellArg( wfEscapeShellArg( $lang ) ); - $escDomain = wfEscapeShellArg( wfEscapeShellArg( $domain ) ); - shell_exec( "echo notifyNewProjects $escDbName $escTime $escUcsite $escName $escLang $escDomain | at now + 15 minutes" ); - - $this->output( "Script ended. You still have to: - * Add any required settings in InitialiseSettings.php - * Run sync-common-all - * Run /home/wikipedia/conf/interwiki/update - " ); - } - - private function getFirstArticle( $ucsite, $name ) { - return << -[http://www.wikipedia.org Wikipedia] | -[http://www.wiktionary.org Wiktionary] | -[http://www.wikibooks.org Wikibooks] | -[http://www.wikinews.org Wikinews] | -[http://www.wikiquote.org Wikiquote] | -[http://www.wikisource.org Wikisource] | -[http://www.wikiversity.org Wikiversity] - - -See Wikimedia's [[m:|Meta-Wiki]] for the coordination of these projects. - -EOT; - } -} - -$maintClass = "AddWiki"; -require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/maintenance/dumpInterwiki.php b/maintenance/dumpInterwiki.php deleted file mode 100644 index e1170bd7ea..0000000000 --- a/maintenance/dumpInterwiki.php +++ /dev/null @@ -1,265 +0,0 @@ -mDescription = "Build constant slightly compact database of interwiki prefixes."; - $this->addOption( 'langlist', 'File with one language code per line', false, true ); - $this->addOption( 'dblist', 'File with one db per line', false, true ); - $this->addOption( 'specialdbs', "File with one 'special' db per line", false, true ); - $this->addOption( 'o', 'Cdb output file', false, true ); - $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false ); - } - - function execute() { - # List of language prefixes likely to be found in multi-language sites - $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); - - # List of all database names - $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); - - # Special-case databases - $this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); - - if ( $this->hasOption( 'o' ) ) { - $this->dbFile = CdbWriter::open( $this->getOption( 'o' ) ) ; - } else { - $this->dbFile = false; - } - - if ( $this->hasOption( 'protocolrelative' ) ) { - $this->urlprotocol = ''; - } else { - $this->urlprotocol = 'http:'; - } - - $this->getRebuildInterwikiDump(); - } - - function getRebuildInterwikiDump() { - global $wgContLang; - - # Multi-language sites - # db suffix => db suffix, iw prefix, hostname - $sites = array( - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), - ); - - # Extra interwiki links that can't be in the intermap for some reason - $extraLinks = array( - array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), - array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ), - array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ), - ); - - # Language aliases, usually configured as redirects to the real wiki in apache - # Interlanguage links are made directly to the real wiki - # Something horrible happens if you forget to list an alias here, I can't - # remember what - $this->languageAliases = array( - 'zh-cn' => 'zh', - 'zh-tw' => 'zh', - 'dk' => 'da', - 'nb' => 'no', - ); - - # Special case prefix rewrites, for the benefit of Swedish which uses s:t - # as an abbreviation for saint - $this->prefixRewrites = array( - 'svwiki' => array( 's' => 'src' ), - ); - - # Construct a list of reserved prefixes - $reserved = array(); - foreach ( $this->langlist as $lang ) { - $reserved[$lang] = 1; - } - foreach ( $this->languageAliases as $alias => $lang ) { - $reserved[$alias] = 1; - } - foreach ( $sites as $site ) { - $reserved[$site->lateral] = 1; - } - - # Extract the intermap from meta - $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); - $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); - - if ( !$lines || count( $lines ) < 2 ) { - $this->error( "m:Interwiki_map not found", true ); - } - - # Global interwiki map - foreach ( $lines as $line ) { - if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(.*?)\s*$/', $line, $matches ) ) { - $prefix = $wgContLang->lc( $matches[1] ); - $prefix = str_replace( ' ', '_', $prefix ); - - $url = $matches[2]; - if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { - if ( $this->hasOption( 'protocolrelative' ) ) { - if ( substr( $url, 0, 5 ) == 'http:' ) { - $url = substr( $url, 5 ); - } else if ( substr( $url, 0, 6 ) == 'https:' ) { - $url = substr( $url, 6 ); - } - } - $local = 1; - } else { - $local = 0; - } - - if ( empty( $reserved[$prefix] ) ) { - $imap = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); - $this->makeLink ( $imap, "__global" ); - } - } - } - - # Exclude Wikipedia for Wikipedia - $this->makeLink ( array ( 'iw_prefix' => 'wikipedia', 'is_url' => null ), "_wiki" ); - - # Multilanguage sites - foreach ( $sites as $site ) { - $this->makeLanguageLinks ( $site, "_" . $site->suffix ); - } - - foreach ( $this->dblist as $db ) { - if ( isset( $this->specials[$db] ) ) { - # Special wiki - # Has interwiki links and interlanguage links to wikipedia - - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki" ), "__sites" ); - # Links to multilanguage sites - foreach ( $sites as $targetSite ) { - $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, - 'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ), - 'iw_local' => 1 ), $db ); - } - } else { - # Find out which site this DB belongs to - $site = false; - foreach ( $sites as $candidateSite ) { - $suffix = $candidateSite->suffix; - if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { - $site = $candidateSite; - break; - } - } - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix ), "__sites" ); - if ( !$site ) { - $this->error( "Invalid database $db\n" ); - continue; - } - $lang = $matches[1]; - - # Lateral links - foreach ( $sites as $targetSite ) { - if ( $targetSite->suffix != $site->suffix ) { - $this->makeLink( array( 'iw_prefix' => $targetSite->lateral, - 'iw_url' => $targetSite->getURL( $lang, $this->urlprotocol ), - 'iw_local' => 1 ), $db ); - } - } - - if ( $site->suffix == "wiki" ) { - $this->makeLink( array( 'iw_prefix' => 'w', - 'iw_url' => $this->urlprotocol . "//en.wikipedia.org/wiki/$1", - 'iw_local' => 1 ), $db ); - } - - } - } - foreach ( $extraLinks as $link ) { - $this->makeLink( $link, "__global" ); - } - - # List prefixes for each source - foreach ( $this->prefixLists as $source => $hash ) { - $list = array_keys( $hash ); - sort( $list ); - if ( $this->dbFile ) { - $this->dbFile->set( "__list:{$source}", implode( ' ', $list ) ); - } else { - print "__list:{$source} " . implode( ' ', $list ) . "\n"; - } - } - } - - # ------------------------------------------------------------------------------------------ - - # Executes part of an INSERT statement, corresponding to all interlanguage links to a particular site - function makeLanguageLinks( &$site, $source ) { - # Actual languages with their own databases - foreach ( $this->langlist as $targetLang ) { - $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source ); - } - - # Language aliases - foreach ( $this->languageAliases as $alias => $lang ) { - $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source ); - } - } - - function makeLink( $entry, $source ) { - if ( isset( $this->prefixRewrites[$source] ) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) - $entry[0] = $this->prefixRewrites[$source][$entry[0]]; - - if ( !array_key_exists( "iw_prefix", $entry ) ) { - $entry = array( "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] ); - } - if ( array_key_exists( $source, $this->prefixRewrites ) && - array_key_exists( $entry['iw_prefix'], $this->prefixRewrites[$source] ) ) { - $entry['iw_prefix'] = $this->prefixRewrites[$source][$entry['iw_prefix']]; - } - - if ( $this->dbFile ) { - $this->dbFile->set( "{$source}:{$entry['iw_prefix']}", trim( "{$entry['iw_local']} {$entry['iw_url']}" ) ); - } else { - $this->output( "{$source}:{$entry['iw_prefix']} {$entry['iw_url']} {$entry['iw_local']}\n" ); - } - - # Add to list of prefixes - $this->prefixLists[$source][$entry['iw_prefix']] = 1; - } -} - -$maintClass = "DumpInterwiki"; -require_once( RUN_MAINTENANCE_IF_MAIN ); - diff --git a/maintenance/ourusers.php b/maintenance/ourusers.php deleted file mode 100644 index c8578e24e9..0000000000 --- a/maintenance/ourusers.php +++ /dev/null @@ -1,70 +0,0 @@ -mDescription = "Rebuild the interwiki table using the file on meta and the language list."; - $this->addOption( 'langlist', 'File with one language code per line', false, true ); - $this->addOption( 'dblist', 'File with one db per line', false, true ); - $this->addOption( 'd', 'Output folder', false, true ); - } - - function execute() { - # List of language prefixes likely to be found in multi-language sites - $this->langlist = array_map( "trim", file( $this->getOption( 'langlist', "/home/wikipedia/common/langlist" ) ) ); - - # List of all database names - $this->dblist = array_map( "trim", file( $this->getOption( 'dblist', "/home/wikipedia/common/all.dblist" ) ) ); - - # Special-case databases - //$this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) ); - - $this->makeInterwikiSQL( $this->getOption( 'd', '/home/wikipedia/conf/interwiki/sql' ) ); - } - - function makeInterwikiSQL( $destDir ) { - $this->output( "Making new interwiki SQL files in $destDir\n" ); - - # Multi-language sites - # db suffix => db suffix, iw prefix, hostname - $sites = array( - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ), - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ), - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ), - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ), - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ), - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ), - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ), - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ), - ); - - # Special-case hostnames - $this->specials = array( - 'sourceswiki' => 'sources.wikipedia.org', - 'quotewiki' => 'wikiquote.org', - 'textbookwiki' => 'wikibooks.org', - 'sep11wiki' => 'sep11.wikipedia.org', - 'metawiki' => 'meta.wikimedia.org', - 'commonswiki' => 'commons.wikimedia.org', - 'specieswiki' => 'species.wikimedia.org', - ); - - # Extra interwiki links that can't be in the intermap for some reason - $extraLinks = array( - array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ), - array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ), - array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ), - ); - - # Language aliases, usually configured as redirects to the real wiki in apache - # Interlanguage links are made directly to the real wiki - # Something horrible happens if you forget to list an alias here, I can't - # remember what - $this->languageAliases = array( - 'zh-cn' => 'zh', - 'zh-tw' => 'zh', - 'dk' => 'da', - 'nb' => 'no', - ); - - # Special case prefix rewrites, for the benefit of Swedish which uses s:t - # as an abbreviation for saint - $this->prefixRewrites = array( - 'svwiki' => array( 's' => 'src' ), - ); - - # Construct a list of reserved prefixes - $reserved = array(); - foreach ( $this->langlist as $lang ) { - $reserved[$lang] = 1; - } - foreach ( $this->languageAliases as $alias => $lang ) { - $reserved[$alias] = 1; - } - foreach ( $sites as $site ) { - $reserved[$site->lateral] = 1; - } - - # Extract the intermap from meta - $intermap = Http::get( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw', 30 ); - $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); - - if ( !$lines || count( $lines ) < 2 ) { - $this->error( "m:Interwiki_map not found", true ); - } - - $iwArray = array(); - - foreach ( $lines as $line ) { - $matches = array(); - if ( preg_match( '/^\|\s*(.*?)\s*\|\|\s*(https?:\/\/.*?)\s*$/', $line, $matches ) ) { - $prefix = strtolower( $matches[1] ); - $url = $matches[2]; - if ( preg_match( '/(wikipedia|wiktionary|wikisource|wikiquote|wikibooks|wikimedia)\.org/', $url ) ) { - $local = 1; - } else { - $local = 0; - } - - if ( empty( $reserved[$prefix] ) ) { - $iwArray[$prefix] = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); - } - } - } - - foreach ( $this->dblist as $db ) { - $sql = "-- Generated by rebuildInterwiki.php"; - if ( isset( $this->specials[$db] ) ) { - # Special wiki - # Has interwiki links and interlanguage links to wikipedia - - $host = $this->specials[$db]; - $sql .= "\n--$host\n\n"; - $sql .= "USE $db;\n" . - "TRUNCATE TABLE interwiki;\n" . - "INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES \n"; - $first = true; - - # Intermap links - foreach ( $iwArray as $iwEntry ) { - $sql .= $this->makeLink( $iwEntry, $first, $db ); - } - - # Links to multilanguage sites - foreach ( $sites as $targetSite ) { - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db ); - } - - # Interlanguage links to wikipedia - $sql .= $this->makeLanguageLinks( $sites['wiki'], $first, $db ); - - # Extra links - foreach ( $extraLinks as $link ) { - $sql .= $this->makeLink( $link, $first, $db ); - } - - $sql .= ";\n"; - } else { - # Find out which site this DB belongs to - $site = false; - foreach ( $sites as $candidateSite ) { - $suffix = $candidateSite->suffix; - if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { - $site = $candidateSite; - break; - } - } - if ( !$site ) { - print "Invalid database $db\n"; - continue; - } - $lang = $matches[1]; - $host = "$lang." . $site->url; - $sql .= "\n--$host\n\n"; - - $sql .= "USE $db;\n" . - "TRUNCATE TABLE interwiki;\n" . - "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES\n"; - $first = true; - - # Intermap links - foreach ( $iwArray as $iwEntry ) { - # Suppress links with the same name as the site - if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || - ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) - { - $sql .= $this->makeLink( $iwEntry, $first, $db ); - } - } - - # Lateral links - foreach ( $sites as $targetSite ) { - # Suppress link to self - if ( $targetSite->suffix != $site->suffix ) { - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first, $db ); - } - } - - # Interlanguage links - $sql .= $this->makeLanguageLinks( $site, $first, $db ); - - # w link within wikipedias - # Other sites already have it as a lateral link - if ( $site->suffix == "wiki" ) { - $sql .= $this->makeLink( array( "w", "http://en.wikipedia.org/wiki/$1", 1 ), $first, $db ); - } - - # Extra links - foreach ( $extraLinks as $link ) { - $sql .= $this->makeLink( $link, $first, $db ); - } - $sql .= ";\n"; - } - file_put_contents( "$destDir/$db.sql", $sql ); - } - } - - # ------------------------------------------------------------------------------------------ - - # Returns part of an INSERT statement, corresponding to all interlanguage links to a particular site - function makeLanguageLinks( &$site, &$first, $source ) { - $sql = ""; - - # Actual languages with their own databases - foreach ( $this->langlist as $targetLang ) { - $sql .= $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first, $source ); - } - - # Language aliases - foreach ( $this->languageAliases as $alias => $lang ) { - $sql .= $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first, $source ); - } - return $sql; - } - - # Make SQL for a single link from an array - function makeLink( $entry, &$first, $source ) { - - if ( isset( $this->prefixRewrites[$source] ) && isset($entry[0]) && isset( $this->prefixRewrites[$source][$entry[0]] ) ) { - $entry[0] = $this->prefixRewrites[$source][$entry[0]]; - } - - $sql = ""; - # Add comma - if ( $first ) { - $first = false; - } else { - $sql .= ",\n"; - } - $dbr = wfGetDB( DB_SLAVE ); - $sql .= "(" . $dbr->makeList( $entry ) . ")"; - return $sql; - } -} - -$maintClass = "RebuildInterwiki"; -require_once( RUN_MAINTENANCE_IF_MAIN ); - diff --git a/maintenance/renamewiki.php b/maintenance/renamewiki.php deleted file mode 100644 index 4146525e0b..0000000000 --- a/maintenance/renamewiki.php +++ /dev/null @@ -1,89 +0,0 @@ -mDescription = "Rename external storage dbs and leave a new one"; - $this->addArg( 'olddb', 'Old DB name' ); - $this->addArg( 'newdb', 'New DB name' ); - } - - public function getDbType() { - return Maintenance::DB_ADMIN; - } - - public function execute() { - global $wgDefaultExternalStore; - - # Setup - $from = $this->getArg( 0 ); - $to = $this->getArg( 1 ); - $this->output( "Renaming blob tables in ES from $from to $to...\n" ); - $this->output( "Sleeping 5 seconds...\n" ); - sleep( 5 ); - - # Initialise external storage - if ( is_array( $wgDefaultExternalStore ) ) { - $stores = $wgDefaultExternalStore; - } elseif ( $wgDefaultExternalStore ) { - $stores = array( $wgDefaultExternalStore ); - } else { - $stores = array(); - } - - if ( count( $stores ) ) { - $this->output( "Initialising external storage...\n" ); - global $wgDBuser, $wgDBpassword, $wgExternalServers; - foreach ( $stores as $storeURL ) { - $m = array(); - if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { - continue; - } - - $cluster = $m[1]; - - # Hack - $wgExternalServers[$cluster][0]['user'] = $wgDBuser; - $wgExternalServers[$cluster][0]['password'] = $wgDBpassword; - - $store = new ExternalStoreDB; - $extdb =& $store->getMaster( $cluster ); - $extdb->query( "SET table_type=InnoDB" ); - $extdb->query( "CREATE DATABASE {$to}" ); - $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" ); - $extdb->selectDB( $from ); - $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' ); - $extdb->commit(); - } - } - $this->output( "done.\n" ); - } -} - -$maintClass = "RenameWiki"; -require_once( RUN_MAINTENANCE_IF_MAIN );