From 219094eb01468fcc7356522dee03b570928ca4cd Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 22 Oct 2005 20:52:30 +0000 Subject: [PATCH] Committing various live hacks from Wikimedia servers --- RELEASE-NOTES | 1 + includes/Block.php | 8 ++- includes/Database.php | 6 +- includes/DefaultSettings.php | 1 + includes/EditPage.php | 12 ++++ includes/Image.php | 5 +- includes/LinkCache.php | 5 ++ includes/LoadBalancer.php | 6 +- includes/MessageCache.php | 6 ++ includes/Profiling.php | 19 ++++++- includes/Skin.php | 12 ++++ includes/SkinTemplate.php | 16 +++++- includes/User.php | 6 +- includes/memcached-client.php | 21 ++++++- index.php | 2 +- maintenance/FiveUpgrade.inc | 3 +- maintenance/cleanupCaps.php | 14 +++-- maintenance/clear_interwiki_cache.php | 11 +++- maintenance/commandLine.inc | 10 +++- maintenance/deleteImageMemcached.php | 4 +- maintenance/dumpHTML.inc | 8 ++- maintenance/eval.php | 22 +++++++ maintenance/ourusers.php | 82 ++++++++++++++++++--------- maintenance/rebuildInterwiki.inc | 56 ++++++++++++------ maintenance/rebuildInterwiki.php | 2 +- skins/htmldump/main.css | 2 + 26 files changed, 270 insertions(+), 70 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2efccbd3fd..e22fa66cf1 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -163,6 +163,7 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 3722) Update of Arabic language (ar) Namespace changes * Wrap message page insertions in a transaction to speed up installation * Avoid notice warning on edit with no User-Agent header +* Various fixes === Caveats === diff --git a/includes/Block.php b/includes/Block.php index 4151f25c20..a64dcc37b4 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -275,14 +275,18 @@ class Block function deleteIfExpired() { + $fname = 'Block::deleteIfExpired'; + wfProfileIn( $fname ); if ( $this->isExpired() ) { wfDebug( "Block::deleteIfExpired() -- deleting\n" ); $this->delete(); - return true; + $retVal = true; } else { wfDebug( "Block::deleteIfExpired() -- not expired\n" ); - return false; + $retVal = false; } + wfProfileOut( $fname ); + return $retVal; } function isExpired() diff --git a/includes/Database.php b/includes/Database.php index 8fc4b27aac..6689b968e5 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -334,7 +334,11 @@ class Database { if ( $wgProfiling ) { # generalizeSQL will probably cut down the query to reasonable # logging size most of the time. The substr is really just a sanity check. - $profName = 'query: ' . $fname . ' ' . substr( Database::generalizeSQL( $sql ), 0, 255 ); + + # Who's been wasting my precious column space? -- TS + #$profName = 'query: ' . $fname . ' ' . substr( Database::generalizeSQL( $sql ), 0, 255 ); + $profName = 'query: ' . substr( Database::generalizeSQL( $sql ), 0, 255 ); + wfProfileIn( 'Database::query' ); wfProfileIn( $profName ); } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2abb7788ec..cdaea231ab 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -968,6 +968,7 @@ $wgDebugSquid = false; $wgDisableCounters = false; $wgDisableTextSearch = false; +$wgDisableSearchContext = false; /** * If you've disabled search semi-permanently, this also disables updates to the * table. If you ever re-enable, be sure to rebuild the search table. diff --git a/includes/EditPage.php b/includes/EditPage.php index ec2d7495b5..8e22eb036e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -156,6 +156,7 @@ class EditPage { $fname = 'EditPage::edit'; wfProfileIn( $fname ); + wfDebug( "$fname: enter\n" ); // this is not an article $wgOut->setArticleFlag(false); @@ -170,29 +171,35 @@ class EditPage { } if ( ! $this->mTitle->userCanEdit() ) { + wfDebug( "$fname: user can't edit\n" ); $wgOut->readOnlyPage( $this->mArticle->getContent( true ), true ); wfProfileOut( $fname ); return; } + wfDebug( "$fname: Checking blocks\n" ); if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) { # When previewing, don't check blocked state - will get caught at save time. # Also, check when starting edition is done against slave to improve performance. + wfDebug( "$fname: user is blocked\n" ); $this->blockedIPpage(); wfProfileOut( $fname ); return; } if ( !$wgUser->isAllowed('edit') ) { if ( $wgUser->isAnon() ) { + wfDebug( "$fname: user must log in\n" ); $this->userNotLoggedInPage(); wfProfileOut( $fname ); return; } else { + wfDebug( "$fname: read-only page\n" ); $wgOut->readOnlyPage( $this->mArticle->getContent( true ), true ); wfProfileOut( $fname ); return; } } if ( wfReadOnly() ) { + wfDebug( "$fname: read-only mode is engaged\n" ); if( $this->save || $this->preview ) { $this->formtype = 'preview'; } else if ( $this->diff ) { @@ -313,6 +320,8 @@ class EditPage { $this->starttime = $request->getVal( 'wpStarttime' ); if( is_null( $this->edittime ) ) { # If the form is incomplete, force to preview. + wfDebug( "$fname: Form data appears to be incomplete\n" ); + wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" ); $this->preview = true; } else { if( $this->tokenOk( $request ) ) { @@ -320,11 +329,13 @@ class EditPage { # if the user hits enter in the comment box. # The unmarked state will be assumed to be a save, # if the form seems otherwise complete. + wfDebug( "$fname: Passed token check.\n" ); $this->preview = $request->getCheck( 'wpPreview' ); $this->diff = $request->getCheck( 'wpDiff' ); } else { # Page might be a hack attempt posted from # an external site. Preview instead of saving. + wfDebug( "$fname: Failed token check; forcing preview\n" ); $this->preview = true; } } @@ -343,6 +354,7 @@ class EditPage { $this->watchthis = $request->getCheck( 'wpWatchthis' ); } else { # Not a posted form? Start with nothing. + wfDebug( "$fname: Not a posted form.\n" ); $this->textbox1 = ''; $this->textbox2 = ''; $this->mMetaData = ''; diff --git a/includes/Image.php b/includes/Image.php index ffd647c764..426d50d593 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -944,7 +944,10 @@ class Image # Don't thumbnail an image so big that it will fill hard drives and send servers into swap # JPEG has the handy property of allowing thumbnailing without full decompression, so we make # an exception for it. - if ( $this->getMimeType() !== "image/jpeg" && $this->width * $this->height > $wgMaxImageArea ) { + if ( $this->getMediaType() == MEDIATYPE_BITMAP && + $this->getMimeType() !== 'image/jpeg' && + $this->width * $this->height > $wgMaxImageArea ) + { wfProfileOut( $fname ); return null; } diff --git a/includes/LinkCache.php b/includes/LinkCache.php index 7d192140fd..dd87fcead2 100644 --- a/includes/LinkCache.php +++ b/includes/LinkCache.php @@ -135,6 +135,11 @@ class LinkCache { if ( 0 != $id ) { return $id; } $fname = 'LinkCache::addLinkObj'; + global $wgProfiler; + if ( isset( $wgProfiler ) ) { + $fname .= ' (' . $wgProfiler->getCurrentSection() . ')'; + } + wfProfileIn( $fname ); $ns = $nt->getNamespace(); diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 33cbe09118..326a83fbcf 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -579,11 +579,13 @@ class LoadBalancer { * Results are cached for a short time in memcached */ function getLagTimes() { + global $wgDBname; + $expiry = 5; $requestRate = 10; global $wgMemc; - $times = $wgMemc->get( 'lag_times' ); + $times = $wgMemc->get( "$wgDBname:lag_times" ); if ( $times ) { # Randomly recache with probability rising over $expiry $elapsed = time() - $times['timestamp']; @@ -605,7 +607,7 @@ class LoadBalancer { # Add a timestamp key so we know when it was cached $times['timestamp'] = time(); - $wgMemc->set( 'lag_times', $times, $expiry ); + $wgMemc->set( "$wgDBname:lag_times", $times, $expiry ); # But don't give the timestamp to the caller unset($times['timestamp']); diff --git a/includes/MessageCache.php b/includes/MessageCache.php index be4465495b..1987fe93cc 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -272,6 +272,9 @@ class MessageCache wfSuppressWarnings(); $message = $lang->getMessage( $key ); wfRestoreWarnings(); + if ( is_null( $message ) ) { + $message = false; + } } # Try the English array @@ -279,6 +282,9 @@ class MessageCache wfSuppressWarnings(); $message = Language::getMessage( $key ); wfRestoreWarnings(); + if ( is_null( $message ) ) { + $message = false; + } } # Is this a custom message? Try the default language in the db... diff --git a/includes/Profiling.php b/includes/Profiling.php index 605b10160d..57c43facf9 100755 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -279,7 +279,7 @@ class Profiler { $calls = $this->mCalls[$fname]; $percent = $total ? 100. * $elapsed / $total : 0; $memory = $this->mMemory[$fname]; - $prof .= sprintf($format, $fname, $calls, (float) ($elapsed * 1000), (float) ($elapsed * 1000) / $calls, $percent, $memory, ($this->mMin[$fname] * 1000.0), ($this->mMax[$fname] * 1000.0), $this->mOverhead[$fname]); + $prof .= sprintf($format, substr($fname, 0, $nameWidth), $calls, (float) ($elapsed * 1000), (float) ($elapsed * 1000) / $calls, $percent, $memory, ($this->mMin[$fname] * 1000.0), ($this->mMax[$fname] * 1000.0), $this->mOverhead[$fname]); global $wgProfileToDatabase; if ($wgProfileToDatabase) { @@ -313,18 +313,23 @@ class Profiler { * @static */ function logToDB($name, $timeSum, $eventCount) { + # Warning: $wguname is a live patch, it should be moved to Setup.php + global $wguname; + $fname = 'Profiler::logToDB'; $dbw = & wfGetDB(DB_MASTER); $profiling = $dbw->tableName('profiling'); $name = substr($name, 0, 255); $encname = $dbw->strencode($name); - $sql = "UPDATE $profiling "."SET pf_count=pf_count+{$eventCount}, "."pf_time=pf_time + {$timeSum} "."WHERE pf_name='{$encname}'"; + $sql = "UPDATE $profiling "."SET pf_count=pf_count+{$eventCount}, "."pf_time=pf_time + {$timeSum} ". + "WHERE pf_name='{$encname}' AND pf_server='{$wguname['nodename']}'"; $dbw->query($sql); $rc = $dbw->affectedRows(); if ($rc == 0) { - $dbw->insert('profiling', array ('pf_name' => $name, 'pf_count' => $eventCount, 'pf_time' => $timeSum), $fname, array ('IGNORE')); + $dbw->insert('profiling', array ('pf_name' => $name, 'pf_count' => $eventCount, + 'pf_time' => $timeSum, 'pf_server' => $wguname['nodename'] ), $fname, array ('IGNORE')); } // When we upgrade to mysql 4.1, the insert+update // can be merged into just a insert with this construct added: @@ -333,6 +338,14 @@ class Profiler { // "pf_time=pf_time + VALUES(pf_time)"; } + /** + * Get the function name of the current profiling section + */ + function getCurrentSection() { + $elt =& end($this->mWorkStack); + return $elt[0]; + } + } $wgProfiler = new Profiler(); diff --git a/includes/Skin.php b/includes/Skin.php index eb8a7e2d85..4902c460b6 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1295,6 +1295,18 @@ END; ); } + /** + * Make URL details where the article exists (or at least it's convenient to think so) + */ + function makeKnownUrlDetails( $name, $urlaction='' ) { + $title = Title::newFromText( $name ); + $this->checkTitle($title, $name); + return array( + 'href' => $title->getLocalURL( $urlaction ), + 'exists' => true + ); + } + # make sure we have some title to operate on /*static*/ function checkTitle ( &$title, &$name ) { if(!is_object($title)) { diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 11fd225bc9..4e1e3c7385 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -178,7 +178,14 @@ class SkinTemplate extends Skin { $this->username = $wgUser->getName(); $userPage = $wgUser->getUserPage(); $this->userpage = $userPage->getPrefixedText(); - $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage); + + if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) { + $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage); + } else { + # This won't be used in the standard skins, but we define it to preserve the interface + # To save time, we check for existence + $this->userpageUrlDetails = $this->makeKnownUrlDetails($this->userpage); + } $this->usercss = $this->userjs = $this->userjsprev = false; $this->setupUserCss(); @@ -509,6 +516,13 @@ class SkinTemplate extends Skin { return $personal_urls; } + /** + * Returns true if the IP should be shown in the header + */ + function showIPinHeader() { + global $wgShowIPinHeader; + return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ); + } function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) { $classes = array(); diff --git a/includes/User.php b/includes/User.php index 7d30637d64..a3464564ee 100644 --- a/includes/User.php +++ b/includes/User.php @@ -428,6 +428,10 @@ class User { } } } + + # Extensions + wfRunHooks( 'GetBlockedStatus', array( &$this ) ); + wfProfileOut( $fname ); } @@ -1510,7 +1514,7 @@ class User { } function isAllowedToCreateAccount() { - return $this->isAllowed( 'createaccount' ); + return $this->isAllowed( 'createaccount' ) && !$this->isBlocked(); } /** diff --git a/includes/memcached-client.php b/includes/memcached-client.php index 7d08964592..bc7ce1cfbe 100644 --- a/includes/memcached-client.php +++ b/includes/memcached-client.php @@ -1003,19 +1003,36 @@ class memcached * * @return bool false on failure, true on success */ + /* function _safe_fwrite($f, $buf, $len = false) { stream_set_blocking($f, 0); if ($len === false) { + wfDebug("Writing " . strlen( $buf ) . " bytes\n"); $bytesWritten = fwrite($f, $buf); } else { + wfDebug("Writing $len bytes\n"); $bytesWritten = fwrite($f, $buf, $len); } - $n = stream_select($r=NULL, $w = array($f), $e = NULL, - $this->_timeout_seconds, $this->_timeout_microseconds); + $n = stream_select($r=NULL, $w = array($f), $e = NULL, 10, 0); + # $this->_timeout_seconds, $this->_timeout_microseconds); + wfDebug("stream_select returned $n\n"); stream_set_blocking($f, 1); return $n == 1; + return $bytesWritten; + }*/ + + /** + * Original behaviour + */ + function _safe_fwrite($f, $buf, $len = false) { + if ($len === false) { + $bytesWritten = fwrite($f, $buf); + } else { + $bytesWritten = fwrite($f, $buf, $len); + } + return $bytesWritten; } /** diff --git a/index.php b/index.php index 026f31fe89..c8e0cd5bf4 100644 --- a/index.php +++ b/index.php @@ -82,7 +82,7 @@ if ( '' == $title && 'delete' != $action ) { /* check variant links so that interwiki links don't have to worry about the possible different language variants */ - if( !is_null($wgTitle) && $wgTitle->getArticleID() == 0 ) + if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 ) $wgContLang->findVariantLink( $title, $wgTitle ); } diff --git a/maintenance/FiveUpgrade.inc b/maintenance/FiveUpgrade.inc index 42e5efbfd7..420885c310 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/FiveUpgrade.inc @@ -159,7 +159,8 @@ class FiveUpgrade { * @access private */ function log( $message ) { - echo wfTimestamp( TS_DB ) . ': ' . $message . "\n"; + global $wgDBname; + echo $wgDBname . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n"; flush(); } diff --git a/maintenance/cleanupCaps.php b/maintenance/cleanupCaps.php index 7d59c8b055..ad3d5ab3f6 100644 --- a/maintenance/cleanupCaps.php +++ b/maintenance/cleanupCaps.php @@ -35,11 +35,12 @@ require_once( 'commandLine.inc' ); require_once( 'FiveUpgrade.inc' ); class CapsCleanup extends FiveUpgrade { - function CapsCleanup( $dryrun = false ) { + function CapsCleanup( $dryrun = false, $namespace=0 ) { parent::FiveUpgrade(); $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait $this->dryrun = $dryrun; + $this->namespace = intval( $namespace ); } function cleanup() { @@ -49,7 +50,7 @@ class CapsCleanup extends FiveUpgrade { return false; } - $this->runTable( 'page', 'WHERE page_namespace=0', + $this->runTable( 'page', 'WHERE page_namespace=' . $this->namespace, array( &$this, 'processPage' ) ); } @@ -134,10 +135,10 @@ class CapsCleanup extends FiveUpgrade { if( $ok === true ) { $this->progress( 1 ); - if( $row->page_namespace == NS_MAIN ) { - $talk = Title::makeTitle( NS_TALK, $row->page_title ); + if( $row->page_namespace == $this->namespace ) { + $talk = $target->getTalkPage(); $xrow = $row; - $row->page_namespace = NS_TALK; + $row->page_namespace = $talk->getNamespace(); if( $talk->exists() ) { return $this->processPage( $row ); } @@ -150,7 +151,8 @@ class CapsCleanup extends FiveUpgrade { } $wgUser->setName( 'Conversion script' ); -$caps = new CapsCleanup( isset( $options['dry-run'] ) ); +$ns = isset( $options['namespace'] ) ? $options['namespace'] : 0; +$caps = new CapsCleanup( isset( $options['dry-run'] ), $ns ); $caps->cleanup(); ?> diff --git a/maintenance/clear_interwiki_cache.php b/maintenance/clear_interwiki_cache.php index ca26d73dec..97869728de 100644 --- a/maintenance/clear_interwiki_cache.php +++ b/maintenance/clear_interwiki_cache.php @@ -9,11 +9,18 @@ /** */ require_once('commandLine.inc'); +$dbr =& wfGetDB( DB_SLAVE ); +$res = $dbr->select( 'interwiki', array( 'iw_prefix' ), false ); +$prefixes = array(); +while ( $row = $dbr->fetchObject( $res ) ) { + $prefixes[] = $row->iw_prefix; +} + foreach ( $wgLocalDatabases as $db ) { print "$db "; - foreach ( $wgLanguageNamesEn as $prefix => $name ) { + foreach ( $prefixes as $prefix ) { $wgMemc->delete("$db:interwiki:$prefix"); } } print "\n"; -?> \ No newline at end of file +?> diff --git a/maintenance/commandLine.inc b/maintenance/commandLine.inc index fc5147c685..daf1c7649e 100644 --- a/maintenance/commandLine.inc +++ b/maintenance/commandLine.inc @@ -126,7 +126,10 @@ if ( file_exists( '/home/wikipedia/common/langlist' ) ) { require_once( "$IP/includes/Defines.php" ); require_once( "$IP/CommonSettings.php" ); - if ( !$wgUseNormalUser ) { + if ( $wgUseRootUser ) { + $wgDBuser = $wgDBadminuser = "root"; + $wgDBpassword = $wgDBadminpassword = trim(`mysql_root_pass`); + } elseif ( !$wgUseNormalUser ) { $wgDBuser = $wgDBadminuser = "wikiadmin"; $wgDBpassword = $wgDBadminpassword = trim(`wikiadmin_pass`); } @@ -165,6 +168,11 @@ if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) && $wgDBservers ) { } } +if ( defined( 'MW_CMDLINE_CALLBACK' ) ) { + $fn = MW_CMDLINE_CALLBACK; + $fn(); +} + ini_set( 'memory_limit', -1 ); require_once( "Setup.php" ); diff --git a/maintenance/deleteImageMemcached.php b/maintenance/deleteImageMemcached.php index 2de04ce0e8..a1c5be24a6 100644 --- a/maintenance/deleteImageMemcached.php +++ b/maintenance/deleteImageMemcached.php @@ -1,5 +1,5 @@ imageRel}"; $wgSharedUploadPath = "$wgUploadPath/shared"; diff --git a/maintenance/eval.php b/maintenance/eval.php index 732e619db8..21d7ee5bbc 100755 --- a/maintenance/eval.php +++ b/maintenance/eval.php @@ -18,10 +18,32 @@ $wgForceLoadBalancing = (getenv('MW_BALANCE') ? true : false); $wgUseNormalUser = (getenv('MW_WIKIUSER') ? true : false); +if (getenv('MW_PROFILING')) { + define('MW_CMDLINE_CALLBACK', 'wfSetProfiling'); +} +function wfSetProfiling() { $GLOBALS['wgProfiling'] = true; } + +$optionsWithArgs = array( 'd' ); /** */ require_once( "commandLine.inc" ); +if ( isset( $options['d'] ) ) { + $d = $options['d']; + if ( $d > 0 ) { + $wgDebugLogFile = '/dev/stdout'; + } + if ( $d > 1 ) { + foreach ( $wgLoadBalancer->mServers as $i => $server ) { + $wgLoadBalancer->mServers[$i]['flags'] |= DBO_DEBUG; + } + } + if ( $d > 2 ) { + $wgDebugFunctionEntry = true; + } +} + + while ( ( $line = readconsole( '> ' ) ) !== false ) { $val = eval( $line . ";" ); if( is_null( $val ) ) { diff --git a/maintenance/ourusers.php b/maintenance/ourusers.php index 37b1abba95..f138c374c8 100644 --- a/maintenance/ourusers.php +++ b/maintenance/ourusers.php @@ -10,33 +10,61 @@ $wikiuser_pass = `wikiuser_pass`; $wikiadmin_pass = `wikiadmin_pass`; $wikisql_pass = `wikisql_pass`; -$hosts = array( - 'localhost', - '207.142.131.194', - '207.142.131.195', - '207.142.131.196', - '207.142.131.197', - '207.142.131.198', - '207.142.131.199', - '207.142.131.226', - '207.142.131.227', - '207.142.131.228', - '207.142.131.229', - '207.142.131.230', - '207.142.131.231', - '207.142.131.232', - '207.142.131.233', - '207.142.131.234', - '207.142.131.237', - '207.142.131.238', - '207.142.131.239', - '207.142.131.243', - '207.142.131.244', - '207.142.131.249', - '207.142.131.250', - '207.142.131.216', - '10.0.%', -); +if ( @$argv[1] == 'yaseo' ) { + $hosts = array( + 'localhost', + '211.115.107.158', + '211.115.107.159', + '211.115.107.160', + '211.115.107.138', + '211.115.107.139', + '211.115.107.140', + '211.115.107.141', + '211.115.107.142', + '211.115.107.143', + '211.115.107.144', + '211.115.107.145', + '211.115.107.146', + '211.115.107.147', + '211.115.107.148', + '211.115.107.149', + '211.115.107.150', + '211.115.107.152', + '211.115.107.153', + '211.115.107.154', + '211.115.107.155', + '211.115.107.156', + '211.115.107.157', + ); +} else { + $hosts = array( + 'localhost', + '207.142.131.194', + '207.142.131.195', + '207.142.131.196', + '207.142.131.197', + '207.142.131.198', + '207.142.131.199', + '207.142.131.226', + '207.142.131.227', + '207.142.131.228', + '207.142.131.229', + '207.142.131.230', + '207.142.131.231', + '207.142.131.232', + '207.142.131.233', + '207.142.131.234', + '207.142.131.237', + '207.142.131.238', + '207.142.131.239', + '207.142.131.243', + '207.142.131.244', + '207.142.131.249', + '207.142.131.250', + '207.142.131.216', + '10.0.%', + ); +} $databases = array( '%wikibooks', diff --git a/maintenance/rebuildInterwiki.inc b/maintenance/rebuildInterwiki.inc index 34046274c2..23ad4148c8 100644 --- a/maintenance/rebuildInterwiki.inc +++ b/maintenance/rebuildInterwiki.inc @@ -30,19 +30,26 @@ class Site { } function getRebuildInterwikiSQL() { - global $langlist, $languageAliases, $wgDBname; + global $langlist, $languageAliases, $prefixRewrites, $wgDBname; - # Initialise lists of wikis + # 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' ), ); + + # List of language prefixes likely to be found in multi-language sites $langlist = array_map( "trim", file( "/home/wikipedia/common/langlist" ) ); + + # List of all database names $dblist = array_map( "trim", file( "/home/wikipedia/common/all.dblist" ) ); + # Special-case hostnames $specials = array( 'sourceswiki' => 'sources.wikipedia.org', 'quotewiki' => 'wikiquote.org', @@ -52,12 +59,17 @@ function getRebuildInterwikiSQL() { 'commonswiki' => 'commons.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 $languageAliases = array( 'zh-cn' => 'zh', 'zh-tw' => 'zh', @@ -65,6 +77,12 @@ function getRebuildInterwikiSQL() { 'nb' => 'no', ); + # Special case prefix rewrites, for the benefit of Swedish which uses s:t + # as an abbreviation for saint + $prefixRewrites = array( + 'svwiki' => array( 's' => 'src' ), + ); + # Construct a list of reserved prefixes $reserved = array(); foreach ( $langlist as $lang ) { @@ -81,7 +99,7 @@ function getRebuildInterwikiSQL() { $intermap = wfGetHTTP( 'http://meta.wikimedia.org/w/index.php?title=Interwiki_map&action=raw' ); $lines = array_map( 'trim', explode( "\n", trim( $intermap ) ) ); - if ( !$lines ) { + if ( !$lines || count( $lines ) < 2 ) { die( "m:Interwiki_map not found" ); } @@ -120,20 +138,20 @@ function getRebuildInterwikiSQL() { # Intermap links foreach ( $iwArray as $iwEntry ) { - $sql .= makeLink( $iwEntry, $first ); + $sql .= makeLink( $iwEntry, $first, $db ); } # Links to multilanguage sites foreach ( $sites as $targetSite ) { - $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first ); + $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db ); } # Interlanguage links to wikipedia - $sql .= makeLanguageLinks( $sites['wiki'], $first ); + $sql .= makeLanguageLinks( $sites['wiki'], $first, $db ); # Extra links foreach ( $extraLinks as $link ) { - $sql .= makeLink( $link, $first ); + $sql .= makeLink( $link, $first, $db ); } $sql .= ";\n"; @@ -166,7 +184,7 @@ function getRebuildInterwikiSQL() { if ( ( $suffix == 'wiki' && $iwEntry['iw_prefix'] != 'wikipedia' ) || ( $suffix != 'wiki' && $suffix != $iwEntry['iw_prefix'] ) ) { - $sql .= makeLink( $iwEntry, $first ); + $sql .= makeLink( $iwEntry, $first, $db ); } } @@ -174,22 +192,22 @@ function getRebuildInterwikiSQL() { foreach ( $sites as $targetSite ) { # Suppress link to self if ( $targetSite->suffix != $site->suffix ) { - $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first ); + $sql .= makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first, $db ); } } # Interlanguage links - $sql .= makeLanguageLinks( $site, $first ); + $sql .= makeLanguageLinks( $site, $first, $db ); # w link within wikipedias # Other sites already have it as a lateral link if ( $site->suffix == "wiki" ) { - $sql .= makeLink( array("w", "http://en.wikipedia.org/wiki/$1", 1), $first ); + $sql .= makeLink( array("w", "http://en.wikipedia.org/wiki/$1", 1), $first, $db ); } # Extra links foreach ( $extraLinks as $link ){ - $sql .= makeLink( $link, $first ); + $sql .= makeLink( $link, $first, $db ); } $sql .= ";\n\n"; } @@ -200,25 +218,31 @@ function getRebuildInterwikiSQL() { # ------------------------------------------------------------------------------------------ # Returns part of an INSERT statement, corresponding to all interlanguage links to a particular site -function makeLanguageLinks( &$site, &$first ) { +function makeLanguageLinks( &$site, &$first, $source ) { global $langlist, $languageAliases; $sql = ""; # Actual languages with their own databases foreach ( $langlist as $targetLang ) { - $sql .= makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first ); + $sql .= makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first, $source ); } # Language aliases foreach ( $languageAliases as $alias => $lang ) { - $sql .= makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first ); + $sql .= makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first, $source ); } return $sql; } # Make SQL for a single link from an array -function makeLink( $entry, &$first ) { +function makeLink( $entry, &$first, $source ) { + global $prefixRewrites; + + if ( isset( $prefixRewrites[$source] ) && isset( $prefixRewrites[$source][$entry[0]] ) ) { + $entry[0] = $prefixRewrites[$source][$entry[0]]; + } + $sql = ""; # Add comma if ( $first ) { diff --git a/maintenance/rebuildInterwiki.php b/maintenance/rebuildInterwiki.php index 3f786d074a..42888eba04 100644 --- a/maintenance/rebuildInterwiki.php +++ b/maintenance/rebuildInterwiki.php @@ -13,13 +13,13 @@ $oldCwd = getcwd(); $optionsWithArgs = array( "o" ); include_once( "commandLine.inc" ); include_once( "rebuildInterwiki.inc" ); +chdir( $oldCwd ); $sql = getRebuildInterwikiSQL(); # Output if ( isset( $options['o'] ) ) { # To file specified with -o - chdir( $oldCwd ); $file = fopen( $options['o'], "w" ); fwrite( $file, $sql ); fclose( $file ); diff --git a/skins/htmldump/main.css b/skins/htmldump/main.css index 2994c2273e..d1b4a92b11 100644 --- a/skins/htmldump/main.css +++ b/skins/htmldump/main.css @@ -4,4 +4,6 @@ display: block; } head:first-child + body #footer li { white-space: normal; } +.usermessage { display: none; } +.editsection { display: none; } -- 2.20.1