r82577 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82576‎ | r82577 | r82578 >
Date:22:17, 21 February 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
improve namespace related methods

MWNamespace::getTalk() could give erroneus results when using it on specials
namespaces (NS_MEDIA, NS_SPECIAL). It now use MWNamespace::isMethodValidFor()
which will throw an exception if a special namespace was given.

MWNamespace::getSubject() is now returning identity for specials namespaces.

New MWNamespace::getAssociated() used to find out the subject page of a talk
page and vice versa. Special namespaces will results in an exception.


TESTS:

Added tests for almost complete code coverage. Functions relying on global
$wgCanonicalNamespaces are still incomplete though.
MWNamespace::isMovable() needs more assertions.

Tests results (ignoring incomplete tests output):

$ php phpunit.php --filter MWNamespace
PHPUnit 3.5.10 by Sebastian Bergmann.

.........IIIII..........

Time: 1 second, Memory: 31.75Mb

OK, but incomplete or skipped tests!
Tests: 24, Assertions: 99, Incomplete: 5.
Modified paths:
  • /trunk/phase3/includes/Namespace.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php
@@ -0,0 +1,441 @@
 2+<?php
 3+/**
 4+ * @author Ashar Voultoiz
 5+ * @copyright Copyright © 2011, Ashar Voultoiz
 6+ * @file
 7+ */
 8+
 9+require_once '/var/www/mediawiki-trunk/includes/Namespace.php';
 10+
 11+/**
 12+ * Test class for MWNamespace.
 13+ * Generated by PHPUnit on 2011-02-20 at 21:01:55.
 14+ *
 15+ */
 16+class MWNamespaceTest extends PHPUnit_Framework_TestCase {
 17+ /**
 18+ * @var MWNamespace
 19+ */
 20+ protected $object;
 21+
 22+ /**
 23+ * Sets up the fixture, for example, opens a network connection.
 24+ * This method is called before a test is executed.
 25+ */
 26+ protected function setUp() {
 27+ $this->object = new MWNamespace;
 28+ }
 29+
 30+ /**
 31+ * Tears down the fixture, for example, closes a network connection.
 32+ * This method is called after a test is executed.
 33+ */
 34+ protected function tearDown() {
 35+ }
 36+
 37+
 38+#### START OF TESTS #########################################################
 39+
 40+ /**
 41+ * @todo Write more texts, handle $wgAllowImageMoving setting
 42+ */
 43+ public function testIsMovable() {
 44+ $this->assertFalse( MWNamespace::isMovable( NS_CATEGORY ) );
 45+ # FIXME : write more tests!!
 46+ }
 47+
 48+ /**
 49+ * Please make sure to change testIsTalk() if you change the assertions below
 50+ */
 51+ public function testIsMain() {
 52+ // Special namespaces
 53+ $this->assertTrue( MWNamespace::isMain( NS_MEDIA ) );
 54+ $this->assertTrue( MWNamespace::isMain( NS_SPECIAL ) );
 55+
 56+ // Subject pages
 57+ $this->assertTrue( MWNamespace::isMain( NS_MAIN ) );
 58+ $this->assertTrue( MWNamespace::isMain( NS_USER ) );
 59+ $this->assertTrue( MWNamespace::isMain( 100 ) ); # user defined
 60+
 61+ // Talk pages
 62+ $this->assertFalse( MWNamespace::isMain( NS_TALK ) );
 63+ $this->assertFalse( MWNamespace::isMain( NS_USER_TALK ) );
 64+ $this->assertFalse( MWNamespace::isMain( 101 ) ); # user defined
 65+ }
 66+
 67+ /**
 68+ * Reverse of testIsMain().
 69+ * Please update testIsMain() if you change assertions below
 70+ */
 71+ public function testIsTalk() {
 72+ // Special namespaces
 73+ $this->assertFalse( MWNamespace::isTalk( NS_MEDIA ) );
 74+ $this->assertFalse( MWNamespace::isTalk( NS_SPECIAL ) );
 75+
 76+ // Subject pages
 77+ $this->assertFalse( MWNamespace::isTalk( NS_MAIN ) );
 78+ $this->assertFalse( MWNamespace::isTalk( NS_USER ) );
 79+ $this->assertFalse( MWNamespace::isTalk( 100 ) ); # user defined
 80+
 81+ // Talk pages
 82+ $this->assertTrue( MWNamespace::isTalk( NS_TALK ) );
 83+ $this->assertTrue( MWNamespace::isTalk( NS_USER_TALK ) );
 84+ $this->assertTrue( MWNamespace::isTalk( 101 ) ); # user defined
 85+ }
 86+
 87+ /**
 88+ * Regular getTalk() calls
 89+ * Namespaces without a talk page (NS_MEDIA, NS_SPECIAL) are tested in
 90+ * the function testGetTalkExceptions()
 91+ */
 92+ public function testGetTalk() {
 93+ $this->assertEquals( MWNamespace::getTalk( NS_MAIN), NS_TALK );
 94+ }
 95+
 96+ /**
 97+ * Exceptions with getTalk()
 98+ * NS_MEDIA and NS_SPECIAL do not have talk pages. MediaWiki raise an exception for them.
 99+ * @expectedException MWException
 100+ */
 101+ public function testGetTalkExceptions() {
 102+ $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
 103+ $this->assertNull( MWNamespace::getAssociated( NS_SPECIAL ) );
 104+ }
 105+
 106+ /**
 107+ * Regular getAssociated() calls
 108+ * Namespaces without an associated page (NS_MEDIA, NS_SPECIAL) are tested in
 109+ * the function testGetAssociatedExceptions()
 110+ */
 111+ public function testGetAssociated() {
 112+ $this->assertEquals( MWNamespace::getAssociated( NS_MAIN ), NS_TALK );
 113+ $this->assertEquals( MWNamespace::getAssociated( NS_TALK ), NS_MAIN );
 114+
 115+ }
 116+
 117+ ### Exceptions with getAssociated()
 118+ ### NS_MEDIA and NS_SPECIAL do not have talk pages. MediaWiki raises
 119+ ### an exception for them.
 120+ /**
 121+ * @expectedException MWException
 122+ */
 123+ public function testGetAssociatedExceptionsForNsMedia() {
 124+ $this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
 125+ }
 126+ /**
 127+ * @expectedException MWException
 128+ */
 129+ public function testGetAssociatedExceptionsForNsSpecial() {
 130+ $this->assertNull( MWNamespace::getAssociated( NS_SPECIAL ) );
 131+ }
 132+
 133+ /**
 134+ */
 135+ public function testGetSubject() {
 136+ // Special namespaces are their own subjects
 137+ $this->assertEquals( MWNamespace::getSubject( NS_MEDIA ), NS_MEDIA );
 138+ $this->assertEquals( MWNamespace::getSubject( NS_SPECIAL ), NS_SPECIAL );
 139+
 140+ $this->assertEquals( MWNamespace::getSubject( NS_TALK ), NS_MAIN );
 141+ $this->assertEquals( MWNamespace::getSubject( NS_USER_TALK ), NS_USER );
 142+ }
 143+
 144+ /**
 145+ * @todo Implement testExists().
 146+ */
 147+ public function testExists() {
 148+ // Remove the following lines when you implement this test.
 149+ $this->markTestIncomplete(
 150+ 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
 151+ );
 152+ }
 153+
 154+ /**
 155+ * @todo Implement testGetCanonicalNamespaces().
 156+ */
 157+ public function testGetCanonicalNamespaces() {
 158+ // Remove the following lines when you implement this test.
 159+ $this->markTestIncomplete(
 160+ 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
 161+ );
 162+ }
 163+
 164+ /**
 165+ * @todo Implement testGetCanonicalName().
 166+ */
 167+ public function testGetCanonicalName() {
 168+ // Remove the following lines when you implement this test.
 169+ $this->markTestIncomplete(
 170+ 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
 171+ );
 172+ }
 173+
 174+ /**
 175+ * @todo Implement testGetCanonicalIndex().
 176+ */
 177+ public function testGetCanonicalIndex() {
 178+ // Remove the following lines when you implement this test.
 179+ $this->markTestIncomplete(
 180+ 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
 181+ );
 182+ }
 183+
 184+ /**
 185+ * @todo Implement testGetValidNamespaces().
 186+ */
 187+ public function testGetValidNamespaces() {
 188+ // Remove the following lines when you implement this test.
 189+ $this->markTestIncomplete(
 190+ 'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
 191+ );
 192+ }
 193+
 194+ /**
 195+ */
 196+ public function testCanTalk() {
 197+ $this->assertFalse( MWNamespace::canTalk( NS_MEDIA ) );
 198+ $this->assertFalse( MWNamespace::canTalk( NS_SPECIAL ) );
 199+
 200+ $this->assertTrue( MWNamespace::canTalk( NS_MAIN ) );
 201+ $this->assertTrue( MWNamespace::canTalk( NS_TALK ) );
 202+ $this->assertTrue( MWNamespace::canTalk( NS_USER ) );
 203+ $this->assertTrue( MWNamespace::canTalk( NS_USER_TALK ) );
 204+
 205+ // User defined namespaces
 206+ $this->assertTrue( MWNamespace::canTalk( 100 ) );
 207+ $this->assertTrue( MWNamespace::canTalk( 101 ) );
 208+ }
 209+
 210+ /**
 211+ */
 212+ public function testIsContent() {
 213+ // NS_MAIN is a content namespace per DefaultSettings.php
 214+ // and per function definition.
 215+ $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 216+
 217+ // Other namespaces which are not expected to be content
 218+ $this->assertFalse( MWNamespace::isContent( NS_MEDIA ) );
 219+ $this->assertFalse( MWNamespace::isContent( NS_SPECIAL ) );
 220+ $this->assertFalse( MWNamespace::isContent( NS_TALK ) );
 221+ $this->assertFalse( MWNamespace::isContent( NS_USER ) );
 222+ $this->assertFalse( MWNamespace::isContent( NS_CATEGORY ) );
 223+ // User defined namespace:
 224+ $this->assertFalse( MWNamespace::isContent( 100 ) );
 225+ }
 226+
 227+ /**
 228+ * Similar to testIsContent() but alters the $wgContentNamespaces
 229+ * global variable.
 230+ */
 231+ public function testIsContentWithAdditionsInWgContentNamespaces() {
 232+ // NS_MAIN is a content namespace per DefaultSettings.php
 233+ // and per function definition.
 234+ $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 235+
 236+ // Tests that user defined namespace #252 is not content:
 237+ $this->assertFalse( MWNamespace::isContent( 252 ) );
 238+
 239+ # FIXME: is global saving really required for PHPUnit?
 240+ // Bless namespace # 252 as a content namespace
 241+ global $wgContentNamespaces;
 242+ $savedGlobal = $wgContentNamespaces;
 243+ $wgContentNamespaces[] = 252;
 244+ $this->assertTrue( MWNamespace::isContent( 252 ) );
 245+
 246+ // Makes sure NS_MAIN was not impacted
 247+ $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 248+
 249+ // Restore global
 250+ $wgContentNamespaces = $savedGlobal;
 251+
 252+ // Verify namespaces after global restauration
 253+ $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 254+ $this->assertFalse( MWNamespace::isContent( 252 ) );
 255+ }
 256+
 257+ public function testIsWatchable() {
 258+ // Specials namespaces are not watchable
 259+ $this->assertFalse( MWNamespace::isWatchable( NS_MEDIA ) );
 260+ $this->assertFalse( MWNamespace::isWatchable( NS_SPECIAL ) );
 261+
 262+ // Core defined namespaces are watchables
 263+ $this->assertTrue( MWNamespace::isWatchable( NS_MAIN ) );
 264+ $this->assertTrue( MWNamespace::isWatchable( NS_TALK ) );
 265+
 266+ // Additional, user defined namespaces are watchables
 267+ $this->assertTrue( MWNamespace::isWatchable( 100 ) );
 268+ $this->assertTrue( MWNamespace::isWatchable( 101 ) );
 269+ }
 270+
 271+ public function testHasSubpages() {
 272+ // Special namespaces:
 273+ $this->assertFalse( MWNamespace::hasSubpages( NS_MEDIA ) );
 274+ $this->assertFalse( MWNamespace::hasSubpages( NS_SPECIAL ) );
 275+
 276+ // namespaces without subpages
 277+ $this->assertFalse( MWNamespace::hasSubpages( NS_MAIN ) );
 278+
 279+ // Some namespaces with subpages
 280+ $this->assertTrue( MWNamespace::hasSubpages( NS_TALK ) );
 281+ $this->assertTrue( MWNamespace::hasSubpages( NS_USER ) );
 282+ $this->assertTrue( MWNamespace::hasSubpages( NS_USER_TALK ) );
 283+ }
 284+
 285+ /**
 286+ */
 287+ public function testGetContentNamespaces() {
 288+ $this->assertEquals(
 289+ MWNamespace::getcontentNamespaces(),
 290+ array( NS_MAIN),
 291+ '$wgContentNamespaces is an array with only NS_MAIN by default'
 292+ );
 293+
 294+ global $wgContentNamespaces;
 295+
 296+ # test !is_array( $wgcontentNamespaces )
 297+ $wgContentNamespaces = '';
 298+ $this->assertEquals( MWNamespace::getcontentNamespaces(), NS_MAIN );
 299+ $wgContentNamespaces = false;
 300+ $this->assertEquals( MWNamespace::getcontentNamespaces(), NS_MAIN );
 301+ $wgContentNamespaces = null;
 302+ $this->assertEquals( MWNamespace::getcontentNamespaces(), NS_MAIN );
 303+ $wgContentNamespaces = 5;
 304+ $this->assertEquals( MWNamespace::getcontentNamespaces(), NS_MAIN );
 305+
 306+ # test $wgContentNamespaces === array()
 307+ $wgContentNamespaces = array();
 308+ $this->assertEquals( MWNamespace::getcontentNamespaces(), NS_MAIN );
 309+
 310+ # test !in_array( NS_MAIN, $wgContentNamespaces )
 311+ $wgContentNamespaces = array( NS_USER, NS_CATEGORY );
 312+ $this->assertEquals(
 313+ MWNamespace::getcontentNamespaces(),
 314+ array( NS_MAIN, NS_USER, NS_CATEGORY ),
 315+ 'NS_MAIN is forced in wgContentNamespaces even if unwanted'
 316+ );
 317+
 318+ # test other cases, return $wgcontentNamespaces as is
 319+ $wgContentNamespaces = array( NS_MAIN );
 320+ $this->assertEquals(
 321+ MWNamespace::getcontentNamespaces(),
 322+ array( NS_MAIN )
 323+ );
 324+
 325+ $wgContentNamespaces = array( NS_MAIN, NS_USER, NS_CATEGORY );
 326+ $this->assertEquals(
 327+ MWNamespace::getcontentNamespaces(),
 328+ array( NS_MAIN, NS_USER, NS_CATEGORY )
 329+ );
 330+
 331+ }
 332+
 333+ /**
 334+ * Some namespaces are always capitalized per code definition
 335+ * in MWNamespace::$alwaysCapitalizedNamespaces
 336+ */
 337+ public function testIsCapitalizedHardcodedAssertions() {
 338+ // NS_MEDIA and NS_FILE are treated the same
 339+ $this->assertEquals(
 340+ MWNamespace::isCapitalized( NS_MEDIA ),
 341+ MWNamespace::isCapitalized( NS_FILE ),
 342+ 'NS_MEDIA and NS_FILE have same capitalization rendering'
 343+ );
 344+
 345+ // Boths are capitalized by default
 346+ $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIA ) );
 347+ $this->assertTrue( MWNamespace::isCapitalized( NS_FILE ) );
 348+
 349+ // Always capitalized namespaces
 350+ // @see MWNamespace::$alwaysCapitalizedNamespaces
 351+ $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) );
 352+ $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) );
 353+ $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) );
 354+ }
 355+
 356+ /**
 357+ * Follows up for testIsCapitalizedHardcodedAssertions() but alter the
 358+ * global $wgCapitalLink setting to have extended coverage.
 359+ *
 360+ * MWNamespace::isCapitalized() rely on two global settings:
 361+ * $wgCapitalLinkOverrides = array(); by default
 362+ * $wgCapitalLinks = true; by default
 363+ * This function test $wgCapitalLinks
 364+ *
 365+ * Global setting correctness is tested against the NS_PROJECT and
 366+ * NS_PROJECT_TALK namespaces since they are not hardcoded nor specials
 367+ */
 368+ public function testIsCapitalizedWithWgCapitalLinks() {
 369+ global $wgCapitalLinks;
 370+ // Save the global to easily reset to MediaWiki default settings
 371+ $savedGlobal = $wgCapitalLinks;
 372+
 373+ $wgCapitalLinks = true;
 374+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 375+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT_TALK ) );
 376+
 377+ $wgCapitalLinks = false;
 378+ // hardcoded namespaces (see above function) are still capitalized:
 379+ $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) );
 380+ $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) );
 381+ $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) );
 382+ // setting is correctly applied
 383+ $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT ) );
 384+ $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT_TALK ) );
 385+
 386+ // reset global state:
 387+ $wgCapitalLinks = $savedGlobal;
 388+ }
 389+
 390+ /**
 391+ * Counter part for MWNamespace::testIsCapitalizedWithWgCapitalLinks() now
 392+ * testing the $wgCapitalLinkOverrides global.
 393+ *
 394+ * @todo split groups of assertions in autonomous testing functions
 395+ */
 396+ public function testIsCapitalizedWithWgCapitalLinkOverrides() {
 397+ global $wgCapitalLinkOverrides;
 398+ // Save the global to easily reset to MediaWiki default settings
 399+ $savedGlobal = $wgCapitalLinkOverrides;
 400+
 401+ // Test default settings
 402+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 403+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT_TALK ) );
 404+ // hardcoded namespaces (see above function) are capitalized:
 405+ $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) );
 406+ $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) );
 407+ $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) );
 408+
 409+ // Hardcoded namespaces remains capitalized
 410+ $wgCapitalLinkOverrides[NS_SPECIAL] = false;
 411+ $wgCapitalLinkOverrides[NS_USER] = false;
 412+ $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false;
 413+ $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) );
 414+ $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) );
 415+ $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) );
 416+
 417+ $wgCapitalLinkOverrides = $savedGlobal;
 418+ $wgCapitalLinkOverrides[NS_PROJECT] = false;
 419+ $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT ) );
 420+ $wgCapitalLinkOverrides[NS_PROJECT] = true ;
 421+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 422+ unset( $wgCapitalLinkOverrides[NS_PROJECT] );
 423+ $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 424+
 425+ // reset global state:
 426+ $wgCapitalLinkOverrides = $savedGlobal;
 427+ }
 428+
 429+ public function testHasGenderDistinction() {
 430+ // Namespaces with gender distinctions
 431+ $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER ) );
 432+ $this->assertTrue( MWNamespace::hasGenderDistinction( NS_USER_TALK ) );
 433+
 434+ // Other ones, "genderless"
 435+ $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MEDIA ) );
 436+ $this->assertFalse( MWNamespace::hasGenderDistinction( NS_SPECIAL ) );
 437+ $this->assertFalse( MWNamespace::hasGenderDistinction( NS_MAIN ) );
 438+ $this->assertFalse( MWNamespace::hasGenderDistinction( NS_TALK ) );
 439+
 440+ }
 441+}
 442+?>
Property changes on: trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php
___________________________________________________________________
Added: svn:eol-style
1443 + native
Index: trunk/phase3/includes/Namespace.php
@@ -54,6 +54,22 @@
5555 private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL, NS_USER, NS_MEDIAWIKI );
5656
5757 /**
 58+ * Trow an exception when trying to get the subject or talk page
 59+ * for a given namespace where it does not make sens.
 60+ * Special namespaces are defined in includes/define.php and have
 61+ * a value below 0 (ex: NS_SPECIAL = -1 , NS_MEDIA = -2)
 62+ *
 63+ * @param $ns Int: namespace index
 64+ */
 65+ private static function isMethodValidFor( $index, $method ) {
 66+ if( $index < NS_MAIN ) {
 67+ throw new MWException( "$method does not make any sens for given namespace $index" );
 68+ return false;
 69+ }
 70+ return true;
 71+ }
 72+
 73+ /**
5874 * Can pages in the given namespace be moved?
5975 *
6076 * @param $index Int: namespace index
@@ -92,6 +108,7 @@
93109 * @return int
94110 */
95111 public static function getTalk( $index ) {
 112+ self::isMethodValidFor( $index, __METHOD__ );
96113 return self::isTalk( $index )
97114 ? $index
98115 : $index + 1;
@@ -99,17 +116,43 @@
100117
101118 /**
102119 * Get the subject namespace index for a given namespace
 120+ * Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
103121 *
104122 * @param $index Int: Namespace index
105123 * @return int
106124 */
107125 public static function getSubject( $index ) {
 126+ # Handle special namespaces
 127+ if( $index < NS_MAIN ) {
 128+ return $index;
 129+ }
 130+
108131 return self::isTalk( $index )
109132 ? $index - 1
110133 : $index;
111134 }
112135
113136 /**
 137+ * Get the associated namespace.
 138+ * For talk namespaces, returns the subject (non-talk) namespace
 139+ * For subject (non-talk) namespaces, returns the talk namespace
 140+ *
 141+ * @param $index Int: namespace index
 142+ * @return int or null if no associated namespace could be found
 143+ */
 144+ public static function getAssociated( $index ) {
 145+ self::isMethodValidFor( $index, __METHOD__ );
 146+
 147+ if( self::isMain( $index ) ) {
 148+ return self::getTalk( $index );
 149+ } elseif( self::isTalk( $index ) ) {
 150+ return self::getSubject( $index );
 151+ } else {
 152+ return null;
 153+ }
 154+ }
 155+
 156+ /**
114157 * Returns whether the specified namespace exists
115158 */
116159 public static function exists( $index ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r82580remove hardcoded local pathhashar22:56, 21 February 2011
r82692Minor typos...hashar19:56, 23 February 2011
r83643Followup r82577: Only generate talk page links on content pages...tbleher07:45, 10 March 2011
r92234NS_MAIN can locally have subpages enabled...hashar09:45, 15 July 2011
r95422Followup r82577...reedy19:32, 24 August 2011
r95426Fix testGetTalkExceptions from r82577reedy19:52, 24 August 2011
r95439Fixup the rest of r82577reedy20:14, 24 August 2011

Comments

#Comment by Hashar (talk | contribs)   22:58, 21 February 2011

followed up by r82580 which fix hardcoded path

#Comment by Nikerabbit (talk | contribs)   07:46, 22 February 2011

Few minor typos:

+* NS_MEDIA and NS_SPECIAL do not have talk pages. MediaWiki raise an exception for them.
+throw new MWException( "$method does not make any sens for given namespace $index" );
+* for a given namespace where it does not make sens.
#Comment by Hashar (talk | contribs)   19:56, 23 February 2011

Typos fixed in 82692 Thanks to both of you.

#Comment by Platonides (talk | contribs)   09:58, 22 February 2011

What's the usecase for MWNamespace::getAssociated() ? Where would it be useful?

And as Nikerabbit mentioned, you have a couple of typos: Trow -> Throw, Sens -> sense (twice)

#Comment by Hashar (talk | contribs)   07:34, 23 February 2011

The new getAssociated method is needed by a feature I am working on actually.

#Comment by Platonides (talk | contribs)   00:08, 25 February 2011

Fair enough.

#Comment by Nikerabbit (talk | contribs)   09:13, 6 March 2011

Trying to access /wiki/Media:Wiki.png:


#0 /www/w/includes/Namespace.php(110): MWNamespace::isMethodValidFor(-2, 'MWNamespace::ge...')
#1 /www/w/includes/Title.php(2783): MWNamespace::getTalk(-2)
#2 /www/w/includes/Skin.php(246): Title->getTalkPage()
#3 /www/w/includes/Skin.php(226): Skin->preloadExistence()
#4 /www/w/skins/Vector.php(31): Skin->initPage(Object(OutputPage))
#5 /www/w/includes/SkinTemplate.php(155): SkinVector->initPage(Object(OutputPage))
#6 /www/w/includes/OutputPage.php(1857): SkinTemplate->outputPage(Object(OutputPage))
#7 /www/w/includes/Wiki.php(399): OutputPage->output()
#8 /www/w/index.php(105): MediaWiki->finalCleanup(Object(OutputPage))
#9 {main}
#Comment by Hashar (talk | contribs)   12:45, 6 March 2011

This is exactly why I made it throw an extension: bad handling in MediaWiki :p

In this case, we have never properly handled the [[Media:file.ext]] web requests. The Wiki::articleFromTitle() function has a FIXME:

 if( NS_MEDIA == $title->getNamespace() ) {
      // FIXME: where should this go?
      $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
  }

We should probably hack Wiki::handleSpecialCases() and redirect the user to the File: page.

#Comment by Hashar (talk | contribs)   21:58, 6 March 2011

I have played a bit with NS_MEDIA but haven't found a proper way to handle a clean redirection to NS_FILE equivalent. If you have any idea I am all for it!

#Comment by Tbleher (talk | contribs)   18:07, 6 March 2011

This change also breaks the DumpHTML extension:

Special:Categories...MWNamespace::getTalk does not make any sense for given namespace -1
Backtrace:
#0 /srv/www/mediawiki/code/includes/Namespace.php(110): MWNamespace::isMethodValidFor(-1, 'MWNamespace::ge...')
#1 /srv/www/mediawiki/code/includes/Title.php(2783): MWNamespace::getTalk(-1)
#2 /srv/www/mediawiki/extensions/DumpHTML/SkinOffline.php(61): Title->getTalkPage()
#3 /srv/www/mediawiki/code/includes/SkinTemplate.php(500): SkinOffline->buildContentActionUrls(Array)
#4 /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.inc(817): SkinTemplate->outputPage(Object(OutputPage))
#5 /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.inc(481): DumpHTML->getArticleHTML(Object(Title))
#6 /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.inc(221): DumpHTML->doArticle(Object(Title))
#7 /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.inc(151): DumpHTML->doSpecials()
#8 /srv/www/mediawiki/extensions/DumpHTML/dumpHTML.php(151): DumpHTML->doEverything()
#9 {main}
#Comment by Hashar (talk | contribs)   22:06, 6 March 2011

In SkinOffline the buildContentActionUrls() seems to add a talk page to any namespace. Could be skipped when the page is a special one, for example:

       if( $this->mTitle->isTalkPage() ) {  // only add the talk action if the namespace has a talk page
       $content_actions['talk'] = $this->tabAction(
           $this->mTitle->getTalkPage(),
           'talk',
           $this->mTitle->isTalkPage(),
           ,
           true);
       }
#Comment by Platonides (talk | contribs)   22:43, 6 March 2011

I think you want $this->mTitle->canTalk(), not $this->mTitle->isTalkPage()

#Comment by Tbleher (talk | contribs)   07:48, 10 March 2011

Thanks for the suggestions. I tested this and committed the change in r83643.

#Comment by Bawolff (talk | contribs)   23:45, 23 June 2011

Note, testHasSubpages fails for me (Since I have subpages enabled in main namespace on my test wiki). I don't know if unittests are supposed to care if users have non-default stuff in LocalSettings.php, so I don't know if that's an issue or not.

#Comment by Hashar (talk | contribs)   09:46, 15 July 2011

I have added a workaround to testHasSubpages in r92234. Test will simply be skipped if you have that setting.

#Comment by Hashar (talk | contribs)   13:39, 15 August 2011

resetting to new. Looks fine in both 1.18 and trunk

#Comment by Catrope (talk | contribs)   12:38, 20 August 2011
+		$this->object = new MWNamespace;

This is useless (MWNamespace only has static methods) and unused.

+		$this->assertEquals( MWNamespace::getTalk( NS_MAIN), NS_TALK );

It's assertEquals( $expected, $actual ) , so you've got the order wrong. This appears to apply to all calls in this test from a quick glance.

+	public function testGetTalkExceptions() {
+		$this->assertNull( MWNamespace::getAssociated( NS_MEDIA ) );
+		$this->assertNull( MWNamespace::getAssociated( NS_SPECIAL ) );
+	}

This doesn't work the way you think it does. Because an exception stops the execution of the function, this doesn't test that both calls throw an exception, just that one of them does. Because the NS_MEDIA call throws an exception, the NS_SPECIAL call is never executed, so we'd never notice if that were to stop throwing an exception. Conversely, if NS_MEDIA were to stop throwing an exception but NS_SPECIAL still threw one, we'd never notice either. You would need to either split this up into two tests or use a data provider, I guess. You did do this properly in testGetAssociatedExceptionsForNsMedia().

+	public function testIsContent() {

Since the set of content namespaces is configurable, this test breaks on setups with funky configs. If you add e.g. $wgContentNamespaces[] = NS_USER; to your config, this test will fail. To test this properly you will have to exercise full control over $wgContentNamespaces for every assertion.

+	public function testHasSubpages() {

Same thing; this was fixed properly though.

#Comment by Reedy (talk | contribs)   19:55, 24 August 2011

The first 3 items have been dealt with. The last 2 still need dealing with...

Status & tagging log