Committing various live hacks from Wikimedia servers
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Oct 2005 20:52:30 +0000 (20:52 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Oct 2005 20:52:30 +0000 (20:52 +0000)
26 files changed:
RELEASE-NOTES
includes/Block.php
includes/Database.php
includes/DefaultSettings.php
includes/EditPage.php
includes/Image.php
includes/LinkCache.php
includes/LoadBalancer.php
includes/MessageCache.php
includes/Profiling.php
includes/Skin.php
includes/SkinTemplate.php
includes/User.php
includes/memcached-client.php
index.php
maintenance/FiveUpgrade.inc
maintenance/cleanupCaps.php
maintenance/clear_interwiki_cache.php
maintenance/commandLine.inc
maintenance/deleteImageMemcached.php
maintenance/dumpHTML.inc
maintenance/eval.php
maintenance/ourusers.php
maintenance/rebuildInterwiki.inc
maintenance/rebuildInterwiki.php
skins/htmldump/main.css

index 2efccbd..e22fa66 100644 (file)
@@ -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 ===
index 4151f25..a64dcc3 100644 (file)
@@ -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()
index 8fc4b27..6689b96 100644 (file)
@@ -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 );
                }
index 2abb778..cdaea23 100644 (file)
@@ -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.
index ec2d749..8e22eb0 100644 (file)
@@ -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 = '';
index ffd647c..426d50d 100644 (file)
@@ -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;
                }
index 7d19214..dd87fce 100644 (file)
@@ -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();
index 33cbe09..326a83f 100644 (file)
@@ -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']);
index be44654..1987fe9 100755 (executable)
@@ -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...
index 605b101..57c43fa 100755 (executable)
@@ -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();
index eb8a7e2..4902c46 100644 (file)
@@ -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)) {
index 11fd225..4e1e3c7 100644 (file)
@@ -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();
index 7d30637..a346456 100644 (file)
@@ -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();
        }
 
        /**
index 7d08964..bc7ce1c 100644 (file)
@@ -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;
    }
 
    /**
index 026f31f..c8e0cd5 100644 (file)
--- 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 );
 
 }
index 42e5efb..420885c 100644 (file)
@@ -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();
        }
        
index 7d59c8b..ad3d5ab 100644 (file)
@@ -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();
 
 ?>
index ca26d73..9786972 100644 (file)
@@ -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
+?>
index fc5147c..daf1c76 100644 (file)
@@ -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" );
index 2de04ce..a1c5be2 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// php deleteImageMemcached.php --until "2003-09-04 04:40:00" --wait 500
+// php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0 --report 10
 $optionsWithArgs = array( 'until', 'sleep', 'report' );
 
 require_once 'commandLine.inc';
@@ -16,6 +16,8 @@ class DeleteImageCache {
        function main() {
                global $wgMemc, $wgDBname;
                $fname = 'DeleteImageCache::main';
+
+               ini_set( 'display_errors', false );
                
                $dbr =& wfGetDB( DB_SLAVE );
                
index e2e5601..decd278 100644 (file)
@@ -285,7 +285,7 @@ class DumpHTML {
                global $wgUploadPath, $wgLogo, $wgMaxCredits, $wgSharedUploadPath;
                global $wgHideInterlanguageLinks, $wgUploadDirectory, $wgThumbnailScriptPath;
                global $wgSharedThumbnailScriptPath, $wgEnableParserCache, $wgHooks, $wgServer;
-               global $wgRightsUrl, $wgRightsText;
+               global $wgRightsUrl, $wgRightsText, $wgCopyrightIcon;
 
                static $oldLogo = NULL;
                
@@ -330,6 +330,12 @@ class DumpHTML {
                        $wgLogo = $wgScriptPath . $wgLogo;
                }
 
+               # Another ugly hack
+               $wgCopyrightIcon = str_replace( 'src="/images', 
+                       'src="' . htmlspecialchars( $wgScriptPath ) . '/images', $wgCopyrightIcon );
+
+
+
                $wgStylePath = "$wgScriptPath/skins";
                $wgUploadPath = "$wgScriptPath/{$this->imageRel}";
                $wgSharedUploadPath = "$wgUploadPath/shared";
index 732e619..21d7ee5 100755 (executable)
 
 $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 ) ) {
index 37b1abb..f138c37 100644 (file)
@@ -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',
index 3404627..23ad414 100644 (file)
@@ -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 ) {
index 3f786d0..42888eb 100644 (file)
@@ -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 );
index 2994c22..d1b4a92 100644 (file)
@@ -4,4 +4,6 @@
        display: block;
 }
 head:first-child + body #footer li { white-space: normal; }
+.usermessage { display: none; }
+.editsection { display: none; }