Latest features and bug fixes imported from stable
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 12 Nov 2003 10:21:28 +0000 (10:21 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 12 Nov 2003 10:21:28 +0000 (10:21 +0000)
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/LinkCache.php
includes/MemcachedSessions.php [new file with mode: 0644]
includes/Setup.php
includes/SpecialAllpages.php
includes/SpecialEmailuser.php
includes/SpecialUndelete.php

index 69ad5e4..0c7f1d9 100644 (file)
@@ -42,9 +42,12 @@ $wgDBmysql4                  = false; # Set to true to use enhanced fulltext search
 # memcached settings
 # See docs/memcached.doc
 #
-$wgUseMemCached     = false; # Will be set to false in Setup.php, if the server isn't working
+$wgMemCachedDebug   = false; # Will be set to false in Setup.php, if the server isn't working
+$wgUseMemCached     = false;
 $wgMemCachedServers = array( "127.0.0.1:11000" );
 $wgMemCachedDebug   = false;
+$wgSessionsInMemcached = false;
+$wgLinkCacheMemcached = false; # Not fully tested
 
 # Language settings
 #
@@ -105,6 +108,11 @@ $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
 
 $wgCookieExpiration = 2592000;
 
+# Set to set an explicit domain on the login cookies
+# eg, "justthis.domain.org" or ".any.subdomain.net"
+$wgCookieDomain = "";
+$wgCookiePath = "/";
+
 $wgAllowExternalImages = true;
 $wgMiserMode = false; # Disable database-intensive features
 $wgUseTeX = false;
@@ -120,7 +128,7 @@ $wgDebugFunctionEntry = 0; # Output debug message on every wfProfileIn/wfProfile
 $wgDisableCounters = false;
 $wgDisableTextSearch = false;
 $wgDisableSearchUpdate = 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.
-$wgDisableUploads = false;
+$wgDisableUploads = true; # Uploads have to be specially set up to be secure
 $wgDisableAnonTalk = false;
 
 # We can serve pages compressed in order to save bandwidth,
index 801bde2..261f5ee 100644 (file)
@@ -466,6 +466,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc )
 
        $now = wfTimestampNow();
        $won = wfInvertTimestamp( $now );
+       $size = IntVal( $size );
        
        if ( $wgUseCopyrightUpload )
          {
@@ -481,7 +482,7 @@ function wfRecordUpload( $name, $oldver, $size, $desc )
        if ( 0 == wfNumRows( $res ) ) {
                $sql = "INSERT INTO image (img_name,img_size,img_timestamp," .
                  "img_description,img_user,img_user_text) VALUES ('" .
-                 wfStrencode( $name ) . "',{$size},'{$now}','" .
+                 wfStrencode( $name ) . "',$size,'{$now}','" .
                  wfStrencode( $desc ) . "', '" . $wgUser->getID() .
                  "', '" . wfStrencode( $wgUser->getName() ) . "')";
                wfQuery( $sql, DB_WRITE, $fname );
@@ -671,4 +672,25 @@ function wfLoadAllMessages()
        wfFreeResult( $res );
        return $messages;
 }
+
+function wfQuotedPrintable( $string, $charset = "" ) 
+{
+       # Probably incomplete; see RFC 2045
+       if( empty( $charset ) ) {
+               global $wgInputEncoding;
+               $charset = $wgInputEncoding;
+       }
+       $charset = strtoupper( $charset );
+       $charset = str_replace( "ISO-8859", "ISO8859", $charset ); // ?
+
+       $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
+       $replace = $illegal . '\t ?_';
+       if( !preg_match( "/[$illegal]/", $string ) ) return $string;
+       $out = "=?$charset?Q?";
+       $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
+       $out .= "?=";
+       return $out;
+}
+
+
 ?>
index 212b214..9b0f077 100644 (file)
@@ -75,9 +75,11 @@ class LinkCache {
                $this->clearLink( $title );
        }
        
-       function clearLink( $title ) {
-               global $wgMemc;
-               $wgMemc->delete( $this->getKey( $title ) );
+       function clearLink( $title ) 
+       {
+               global $wgMemc, $wgLinkCacheMemcached;
+               if( $wgLinkCacheMemcached )
+                       $wgMemc->delete( $this->getKey( $title ) );
        }
 
        function suspend() { $this->mActive = false; }
@@ -114,8 +116,11 @@ class LinkCache {
                        wfProfileOut( $fname );
                        return 0; 
                }
+               
+               $id = FALSE;
+               if( $wgLinkCacheMemcached )
+                       $id = $wgMemc->get( $key = $this->getKey( $title ) );
 
-               $id = $wgMemc->get( $key = $this->getKey( $title ) );
                if( $id === FALSE ) {
                        $sql = "SELECT cur_id FROM cur WHERE cur_namespace=" .
                          "{$ns} AND cur_title='" . wfStrencode( $t ) . "'";
@@ -127,7 +132,8 @@ class LinkCache {
                                $s = wfFetchObject( $res );
                                $id = $s->cur_id;
                        }
-                       $wgMemc->add( $key, $id, time()+3600 );
+                       if( $wgLinkCacheMemcached )
+                               $wgMemc->add( $key, $id, time()+3600 );
                }
                if ( 0 == $id ) { $this->addBadLink( $title ); }
                else { $this->addGoodLink( $id, $title ); }
diff --git a/includes/MemcachedSessions.php b/includes/MemcachedSessions.php
new file mode 100644 (file)
index 0000000..4b72e58
--- /dev/null
@@ -0,0 +1,54 @@
+<?
+
+/*
+       This file gets included if $wgSessionsInMemcache is set in the config.
+       It redirects session handling functions to store their data in memcached
+       instead of the local filesystem. Depending on circumstances, it may also
+       be necessary to change the cookie settings to work across hostnames.
+       
+       See: http://www.php.net/manual/en/function.session-set-save-handler.php
+*/
+
+
+function memsess_key( $id ) {
+       global $wgDBname;
+       return "$wgDBname:session:$id";
+}
+
+function memsess_open( $save_path, $session_name ) {
+       # NOP, $wgMemc should be set up already
+       return true;
+}
+
+function memsess_close() {
+       # NOP
+       return true;
+}
+
+function memsess_read( $id ) {
+       global $wgMemc;
+       $data = $wgMemc->get( memsess_key( $id ) );
+       if( $data === FALSE ) return "";
+       return $data;
+}
+
+function memsess_write( $id, $data ) {
+       global $wgMemc;
+       $wgMemc->set( memsess_key( $id ), $data, 3600 );
+       return true;
+}
+
+function memsess_destroy( $id ) {
+       global $wgMemc;
+       $wgMemc->delete( memsess_key( $id ) );
+       return true;
+}
+
+function memsess_gc( $maxlifetime ) {
+       # NOP: Memcached performs garbage collection.
+       return true;
+}
+
+session_set_save_handler( "memsess_open", "memsess_close", "memsess_read", "memsess_write", "memsess_destroy", "memsess_gc" );
+
+?>
index 038e117..826f15a 100644 (file)
@@ -77,6 +77,19 @@ if( ! class_exists( $wgLangClass ) ) {
 }
 $wgLang = new $wgLangClass();
 
+if( !$wgCommandLineMode ) {
+       if( $wgSessionsInMemcached ) {
+               include_once( "$IP/MemcachedSessions.php" );
+       }
+       session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain );
+       session_cache_limiter( "private, must-revalidate" );
+       session_start();
+       session_register( "wsUserID" );
+       session_register( "wsUserName" );
+       session_register( "wsUserPassword" );
+       session_register( "wsUploadFiles" );
+}
+
 $wgUser = User::loadFromSession();
 $wgDeferredUpdateList = array();
 $wgLinkCache = new LinkCache();
index 2e01937..621a237 100644 (file)
@@ -108,14 +108,18 @@ ORDER BY cur_title
 LIMIT {$indexMaxperpage}";
        $res = wfQuery( $sql, DB_READ, "indexShowChunk" );
 
-       # FIXME: Dynamic column widths, backlink to main list,
-       # side links to next and previous
+# FIXME: Dynamic column widths, backlink to main list,
+# side links to next and previous
        $n = 0;
-       $out = "<table border=\"0\">\n";
+       $out = "<table border=\"0\">\n<tr>";
        while( $s = wfFetchObject( $res ) ) {
-               $out .= "<td width=\"33%\">" .
-                       $sk->makeKnownLink( $s->cur_title ) .
-                       "</td>";
+               $t = Title::makeTitle( 0, $s->cur_title );
+               if( $t ) {
+                       $link = $sk->makeKnownLinkObj( $t );
+               } else {
+                       $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
+               }
+               $out .= "<td width=\"33%\">$link</td>";
                $n = ++$n % 3;
                if( $n == 0 ) {
                        $out .= "</tr>\n<tr>";
@@ -125,7 +129,7 @@ LIMIT {$indexMaxperpage}";
                $out .= "</tr>\n";
        }
        $out .= "</table>";
-       #return $out;
+#return $out;
        $wgOut->addHtml( $out );
 }
 
index 8ae02b2..ababac2 100644 (file)
@@ -105,17 +105,20 @@ class EmailUserForm {
        {
                global $wgOut, $wgUser, $wgLang, $wgOutputEncoding;
                global $wpSubject, $wpText, $target;
+           
+               $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
+           $to = wfQuotedPrintable( $this->mAddress );
 
-               $from = $wgUser->getName() . " <" . $wgUser->getEmail() . ">";
                $headers =
                        "MIME-Version: 1.0\r\n" .
                        "Content-type: text/plain; charset={$wgOutputEncoding}\r\n" .
                        "Content-transfer-encoding: 8bit\r\n" .
                        "From: {$from}\r\n" .
                        "Reply-To: {$from}\r\n" .
-                       "To: {$this->mAddress}\r\n" .
-                       "X-Mailer: Pediawiki interuser e-mailer";
-               mail( $this->mAddress, $wpSubject, $wpText, $headers );
+                       "To: {$to}\r\n" .
+                       "X-Mailer: MediaWiki interuser e-mailer";
+               mail( $this->mAddress, wfQuotedPrintable( $wpSubject ), $wpText, $headers );
+
 
                $success = wfLocalUrl( $wgLang->specialPage( "Emailuser" ),
                  "target={$target}&action=success" );
index 116ec67..ba5fce1 100644 (file)
@@ -169,9 +169,11 @@ function wfSpecialUndelete( $par )
                wfQuery( $sql, DB_WRITE, $fname );
 
                
-        # Touch the log?
-        
-        $wgOut->addWikiText(str_replace("$1", $target, wfMsg("undeletedtext")));
+               # Touch the log?
+               $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
+               $log->addEntry( wfMsg( "undeletedarticle", $target ), "" );
+
+               $wgout->addwikitext(str_replace("$1", $target, wfmsg("undeletedtext")));
                return 0;
        }
 ?>