Merge "Exclude non-standard global $checkBlacklist in CodeSniffer checks"
[lhc/web/wiklou.git] / includes / cache / LinkCache.php
index 01ceeed..6ac7e7a 100644 (file)
@@ -37,16 +37,41 @@ class LinkCache {
        private $mForUpdate = false;
 
        /**
-        * 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;
        }
 
        /**
@@ -78,7 +103,7 @@ class LinkCache {
         * @return mixed
         */
        public function getGoodLinkFieldObj( $title, $field ) {
-               $dbkey = $title->getPrefixedDbKey();
+               $dbkey = $title->getPrefixedDBkey();
                if ( array_key_exists( $dbkey, $this->mGoodLinkFields ) ) {
                        return $this->mGoodLinkFields[$dbkey][$field];
                } else {
@@ -105,7 +130,7 @@ class LinkCache {
         * @param $model Integer: latest revision's content model ID
         */
        public function addGoodLinkObj( $id, $title, $len = -1, $redir = null, $revision = false, $model = false ) {
-               $dbkey = $title->getPrefixedDbKey();
+               $dbkey = $title->getPrefixedDBkey();
                $this->mGoodLinks[$dbkey] = intval( $id );
                $this->mGoodLinkFields[$dbkey] = array(
                        'length' => intval( $len ),
@@ -122,7 +147,7 @@ class LinkCache {
         *  page_latest and page_content_model
         */
        public function addGoodLinkObjFromRow( $title, $row ) {
-               $dbkey = $title->getPrefixedDbKey();
+               $dbkey = $title->getPrefixedDBkey();
                $this->mGoodLinks[$dbkey] = intval( $row->page_id );
                $this->mGoodLinkFields[$dbkey] = array(
                        'length' => intval( $row->page_len ),
@@ -136,7 +161,7 @@ class LinkCache {
         * @param $title Title
         */
        public function addBadLinkObj( $title ) {
-               $dbkey = $title->getPrefixedDbKey();
+               $dbkey = $title->getPrefixedDBkey();
                if ( !$this->isBadLink( $dbkey ) ) {
                        $this->mBadLinks[$dbkey] = 1;
                }
@@ -150,14 +175,19 @@ class LinkCache {
         * @param $title Title
         */
        public function clearLink( $title ) {
-               $dbkey = $title->getPrefixedDbKey();
+               $dbkey = $title->getPrefixedDBkey();
                unset( $this->mBadLinks[$dbkey] );
                unset( $this->mGoodLinks[$dbkey] );
                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 +197,7 @@ class LinkCache {
         */
        public function addLink( $title ) {
                $nt = Title::newFromDBkey( $title );
-               if( $nt ) {
+               if ( $nt ) {
                        return $this->addLinkObj( $nt );
                } else {
                        return 0;
@@ -215,7 +245,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() ),