Add LinkTarget::inNamespace() helper function
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 11 May 2016 21:01:48 +0000 (14:01 -0700)
committerAddshore <addshorewiki@gmail.com>
Thu, 12 May 2016 08:28:26 +0000 (08:28 +0000)
And implementation for TitleValue, plus tests

Change-Id: I42c301e28938dcd55580e20b7c1ddefcbf5a2bef

includes/linker/LinkTarget.php
includes/title/TitleValue.php
tests/phpunit/includes/title/TitleValueTest.php

index 7b59751..da48e00 100644 (file)
@@ -33,6 +33,14 @@ interface LinkTarget {
         */
        public function getNamespace();
 
+       /**
+        * Convenience function to test if it is in the namespace
+        *
+        * @param int $ns
+        * @return bool
+        */
+       public function inNamespace( $ns );
+
        /**
         * Get the link fragment (i.e. the bit after the #) in text form.
         *
index 63c075f..597bf2f 100644 (file)
@@ -94,6 +94,15 @@ class TitleValue implements LinkTarget {
                return $this->namespace;
        }
 
+       /**
+        * @since 1.27
+        * @param int $ns
+        * @return bool
+        */
+       public function inNamespace( $ns ) {
+               return $this->namespace == $ns;
+       }
+
        /**
         * @return string
         */
index 7922553..4dbda74 100644 (file)
@@ -42,6 +42,7 @@ class TitleValueTest extends MediaWikiTestCase {
                $title = new TitleValue( $ns, $text, $fragment, $interwiki );
 
                $this->assertEquals( $ns, $title->getNamespace() );
+               $this->assertTrue( $title->inNamespace( $ns ) );
                $this->assertEquals( $text, $title->getText() );
                $this->assertEquals( $fragment, $title->getFragment() );
                $this->assertEquals( $hasFragment, $title->hasFragment() );