From be3710c3124a2a744bdae5618094018c3ebaafcf Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 23 Feb 2011 23:42:04 +0000 Subject: [PATCH] Fixes for r82645: * 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 | 47 ++++++++++++++++++++++++----- includes/parser/Parser.php | 5 ++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 1a76fa867c..04b61d278c 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -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( '()', + $texts = preg_replace_callback( '/()/', 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( '()', + $texts = preg_replace_callback( '/()/', 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 ) { diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9e75c32796..880dcc925a 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 ) { -- 2.20.1