Fixes for r82645:
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 23 Feb 2011 23:42:04 +0000 (23:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 23 Feb 2011 23:42:04 +0000 (23:42 +0000)
* Fixed several obvious bugs in the $wgCiteCacheReferences helper functions, missed due to inadequate testing.
* Don't save complete Title objects to memcached, they contain cached data with a short lifetime.
* Fixed a doc comment.

includes/parser/LinkHolderArray.php
includes/parser/Parser.php

index 1a76fa8..04b61d2 100644 (file)
@@ -27,15 +27,48 @@ class LinkHolderArray {
                }
        }
 
-       /**
+       /**
         * Don't serialize the parent object, it is big, and not needed when it is
         * a parameter to mergeForeign(), which is the only application of 
         * serializing at present.
+        *
+        * Compact the titles, only serialize the text form.
         */
        function __sleep() {
+               foreach ( $this->internals as $ns => &$nsLinks ) {
+                       foreach ( $nsLinks as $key => &$entry ) {
+                               unset( $entry['title'] );
+                       }
+               }
+               unset( $nsLinks );
+               unset( $entry );
+
+               foreach ( $this->interwikis as $key => &$entry ) {
+                       unset( $entry['title'] );
+               }
+               unset( $entry );
+
                return array( 'internals', 'interwikis', 'size' );
        }
 
+       /**
+        * Recreate the Title objects
+        */
+       function __wakeup() {
+               foreach ( $this->internals as $ns => &$nsLinks ) {
+                       foreach ( $nsLinks as $key => &$entry ) {
+                               $entry['title'] = Title::newFromText( $entry['pdbk'] );
+                       }
+               }
+               unset( $nsLinks );
+               unset( $entry );
+
+               foreach ( $this->interwikis as $key => &$entry ) {
+                       $entry['title'] = Title::newFromText( $entry['pdbk'] );
+               }
+               unset( $entry );
+       }
+
        /**
         * Merge another LinkHolderArray into this one
         * @param $other LinkHolderArray
@@ -76,22 +109,22 @@ class LinkHolderArray {
                                $maxId = $newKey > $maxId ? $newKey : $maxId;
                        }
                }
-               $texts = preg_replace_callback( '(<!--LINK \d+:)(\d+)(-->)', 
+               $texts = preg_replace_callback( '/(<!--LINK \d+:)(\d+)(-->)/', 
                        array( $this, 'mergeForeignCallback' ), $texts );
 
                # Renumber interwiki links
-               foreach ( $links['interwiki'] as $key => $entry ) {
+               foreach ( $other->interwikis as $key => $entry ) {
                        $newKey = $idOffset + $key;
                        $this->interwikis[$newKey] = $entry;
                        $maxId = $newKey > $maxId ? $newKey : $maxId;
-
                }
-               $texts = preg_replace_callback( '(<!--IWLINK )(\d+)(-->)', 
+               $texts = preg_replace_callback( '/(<!--IWLINK )(\d+)(-->)/', 
                        array( $this, 'mergeForeignCallback' ), $texts );
 
-               # Set the parent link ID to be the highest used ID
-               $this->parent->setLinkID( $maxId );
+               # Set the parent link ID to be beyond the highest used ID
+               $this->parent->setLinkID( $maxId + 1 );
                $this->tempIdOffset = null;
+               return $texts;
        }
 
        protected function mergeForeignCallback( $m ) {
index 9e75c32..880dcc9 100644 (file)
@@ -481,10 +481,9 @@ class Parser {
        /**
         * Get a random string
         *
-        * @private
         * @static
         */
-       static private function getRandomString() {
+       static public function getRandomString() {
                return dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) );
        }
 
@@ -5265,7 +5264,7 @@ class Parser {
         *
         * Returns an array which can be serialized and stored persistently. This 
         * array can later be loaded into another parser instance with 
-        * unserializeHalfParsed(). The text can then be safely incorporated into 
+        * unserializeHalfParsedText(). The text can then be safely incorporated into 
         * the return value of a parser hook.
         */
        function serializeHalfParsedText( $text ) {