summaryrefslogtreecommitdiff
path: root/includes/cache/LinkCache.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/cache/LinkCache.php')
-rw-r--r--includes/cache/LinkCache.php68
1 files changed, 59 insertions, 9 deletions
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,7 +198,7 @@ class LinkCache {
*/
public function addLink( $title ) {
$nt = Title::newFromDBkey( $title );
- if( $nt ) {
+ if ( $nt ) {
return $this->addLinkObj( $nt );
} else {
return 0;
@@ -175,6 +206,19 @@ class LinkCache {
}
/**
+ * 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
*
* @param $nt Title object to add
@@ -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() ),