/** * Returns true if the title is inside the specified namespace. * * Please make use of this instead of comparing to getNamespace() * This function is much more resistant to changes we may make * to namespaces than code that makes direct comparisons. * @param int $ns The namespace * @return bool * @since 1.19 */ public function inNamespace($ns) { return MWNamespace::equals($this->getNamespace(), $ns); }
/** * Test MWNamespace::equals * Note if we add a namespace registration system with keys like 'MAIN' * we should add tests here for equivilance on things like 'MAIN' == 0 * and 'MAIN' == NS_MAIN. */ public function testEquals() { $this->assertTrue(MWNamespace::equals(NS_MAIN, NS_MAIN)); $this->assertTrue(MWNamespace::equals(NS_MAIN, 0)); // In case we make NS_MAIN 'MAIN' $this->assertTrue(MWNamespace::equals(NS_USER, NS_USER)); $this->assertTrue(MWNamespace::equals(NS_USER, 2)); $this->assertTrue(MWNamespace::equals(NS_USER_TALK, NS_USER_TALK)); $this->assertTrue(MWNamespace::equals(NS_SPECIAL, NS_SPECIAL)); $this->assertFalse(MWNamespace::equals(NS_MAIN, NS_TALK)); $this->assertFalse(MWNamespace::equals(NS_USER, NS_USER_TALK)); $this->assertFalse(MWNamespace::equals(NS_PROJECT, NS_TEMPLATE)); }