From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/cache/LinkCache.php | 68 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 9 deletions(-) (limited to 'includes/cache/LinkCache.php') diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 0e41e265..54de1989 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -35,18 +35,44 @@ class LinkCache { private $mGoodLinkFields = array(); private $mBadLinks = array(); private $mForUpdate = false; + private $useDatabase = true; /** - * Get an instance of this class + * @var LinkCache + */ + protected static $instance; + + /** + * Get an instance of this class. * * @return LinkCache */ static function &singleton() { - static $instance; - if ( !isset( $instance ) ) { - $instance = new LinkCache; + if ( self::$instance ) { + return self::$instance; } - return $instance; + self::$instance = new LinkCache; + return self::$instance; + } + + /** + * Destroy the singleton instance, a new one will be created next time + * singleton() is called. + * @since 1.22 + */ + static function destroySingleton() { + self::$instance = null; + } + + /** + * Set the singleton instance to a given object. + * Since we do not have an interface for LinkCache, you have to be sure the + * given object implements all the LinkCache public methods. + * @param LinkCache $instance + * @since 1.22 + */ + static function setSingleton( LinkCache $instance ) { + self::$instance = $instance; } /** @@ -156,8 +182,13 @@ class LinkCache { unset( $this->mGoodLinkFields[$dbkey] ); } - public function getGoodLinks() { return $this->mGoodLinks; } - public function getBadLinks() { return array_keys( $this->mBadLinks ); } + public function getGoodLinks() { + return $this->mGoodLinks; + } + + public function getBadLinks() { + return array_keys( $this->mBadLinks ); + } /** * Add a title to the link cache, return the page_id or zero if non-existent @@ -167,13 +198,26 @@ class LinkCache { */ public function addLink( $title ) { $nt = Title::newFromDBkey( $title ); - if( $nt ) { + if ( $nt ) { return $this->addLinkObj( $nt ); } else { return 0; } } + /** + * Enable or disable database use. + * @since 1.22 + * @param $value Boolean + * @return Boolean + */ + public function useDatabase( $value = null ) { + if ( $value !== null ) { + $this->useDatabase = (bool)$value; + } + return $this->useDatabase; + } + /** * Add a title to the link cache, return the page_id or zero if non-existent * @@ -201,6 +245,10 @@ class LinkCache { return 0; } + if( !$this->useDatabase ) { + return 0; + } + # Some fields heavily used for linking... if ( $this->mForUpdate ) { $db = wfGetDB( DB_MASTER ); @@ -215,7 +263,9 @@ class LinkCache { } $f = array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ); - if ( $wgContentHandlerUseDB ) $f[] = 'page_content_model'; + if ( $wgContentHandlerUseDB ) { + $f[] = 'page_content_model'; + } $s = $db->selectRow( 'page', $f, array( 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ), -- cgit v1.2.3-54-g00ecf