Index: trunk/phase3/includes/LinkCache.php |
— | — | @@ -6,7 +6,10 @@ |
7 | 7 | define ('LINKCACHE_BAD', 1); |
8 | 8 | define ('LINKCACHE_IMAGE', 2); |
9 | 9 | |
10 | | -class LinkCache { |
| 10 | +class LinkCache { |
| 11 | + // Increment $mClassVer whenever old serialized versions of this class |
| 12 | + // becomes incompatible with the new version. |
| 13 | + /* private */ var $mClassVer = 1; |
11 | 14 | |
12 | 15 | /* private */ var $mGoodLinks, $mBadLinks, $mActive; |
13 | 16 | /* private */ var $mImageLinks; |
— | — | @@ -140,7 +143,7 @@ |
141 | 144 | |
142 | 145 | function preFill( &$fromtitle ) |
143 | 146 | { |
144 | | - global $wgEnablePersistentLC; |
| 147 | + global $wgEnablePersistentLC, $wgCompressedPersistentLC; |
145 | 148 | |
146 | 149 | $fname = "LinkCache::preFill"; |
147 | 150 | wfProfileIn( $fname ); |
— | — | @@ -148,12 +151,8 @@ |
149 | 152 | $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() ); |
150 | 153 | |
151 | 154 | if ( $wgEnablePersistentLC ) { |
152 | | - $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'", |
153 | | - DB_READ); |
154 | | - $row = wfFetchObject( $res ); |
155 | | - if( $row != FALSE){ |
156 | | - $cacheobj = gzuncompress( $row->lcc_cacheobj ); |
157 | | - $cc = unserialize( $cacheobj ); |
| 155 | + $cc =& $this->getFromLinkscc( $dbkeyfrom ); |
| 156 | + if( $cc != FALSE ){ |
158 | 157 | $this->mOldGoodLinks = $this->mGoodLinks = $cc->mGoodLinks; |
159 | 158 | $this->mOldBadLinks = $this->mBadLinks = $cc->mBadLinks; |
160 | 159 | $this->mPreFilled = true; |
— | — | @@ -192,8 +191,12 @@ |
193 | 192 | |
194 | 193 | if ( $wgEnablePersistentLC ) { |
195 | 194 | // put fetched link data into cache |
196 | | - $serCachegz = wfStrencode( gzcompress( serialize( $this ), 3) ); |
197 | | - wfQuery("REPLACE INTO linkscc VALUES({$id}, '{$dbkeyfrom}', '{$serCachegz}')", |
| 195 | + if( $wgCompressedPersistentLC and function_exists( "gzcompress" ) ) { |
| 196 | + $ser = wfStrencode( gzcompress( serialize( $this ), 3 )); |
| 197 | + } else { |
| 198 | + $ser = wfStrencode( serialize( $this ) ); |
| 199 | + } |
| 200 | + wfQuery("REPLACE INTO linkscc VALUES({$id}, '{$dbkeyfrom}', '{$ser}')", |
198 | 201 | DB_WRITE); |
199 | 202 | wfDebug( "LinkCache::preFill - saved to linkscc\n" ); |
200 | 203 | } |
— | — | @@ -270,6 +273,28 @@ |
271 | 274 | $this->mBadLinks = array(); |
272 | 275 | $this->mImageLinks = array(); |
273 | 276 | } |
274 | | - |
| 277 | + |
| 278 | + |
| 279 | + function &getFromLinkscc( $dbkeyfrom ){ |
| 280 | + $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'", |
| 281 | + DB_READ); |
| 282 | + $row = wfFetchObject( $res ); |
| 283 | + if( $row == FALSE) |
| 284 | + return false; |
| 285 | + |
| 286 | + $cacheobj = false; |
| 287 | + if( function_exists( "gzuncompress" ) ) |
| 288 | + $cacheobj = @gzuncompress( $row->lcc_cacheobj ); |
| 289 | + |
| 290 | + if($cacheobj == FALSE){ |
| 291 | + $cacheobj = $row->lcc_cacheobj; |
| 292 | + } |
| 293 | + $cc = @unserialize( $cacheobj ); |
| 294 | + if( isset( $cc->mClassVer ) and ($cc->mClassVer == $this->mClassVer ) ){ |
| 295 | + return $cc; |
| 296 | + } else { |
| 297 | + return FALSE; |
| 298 | + } |
| 299 | + } |
275 | 300 | } |
276 | 301 | ?> |