helpers to get subjects/talk namespaces
Introduce two new methods to easily get array of namespaces indices which are subjects or talks: MWNamespace::getSubjectNamespaces() MWNamespace::getTalkNamespaces() Change-Id: I975db344afd97713521713a708368d37cd633c50
This commit is contained in:
parent
c2979968b8
commit
e06ad28e7a
2 changed files with 57 additions and 0 deletions
|
|
@ -339,6 +339,33 @@ class MWNamespace {
|
|||
return $wgContentNamespaces;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all namespace indices which are considered subject, aka not a talk
|
||||
* or special namespace. See also MWNamespace::isSubject
|
||||
*
|
||||
* @return array of namespace indices
|
||||
*/
|
||||
public static function getSubjectNamespaces() {
|
||||
return array_filter(
|
||||
MWNamespace::getValidNamespaces(),
|
||||
'MWNamespace::isSubject'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all namespace indices which are considered talks, aka not a subject
|
||||
* or special namespace. See also MWNamespace::isTalk
|
||||
*
|
||||
* @return array of namespace indices
|
||||
*/
|
||||
public static function getTalkNamespaces() {
|
||||
return array_filter(
|
||||
MWNamespace::getValidNamespaces(),
|
||||
'MWNamespace::isTalk'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the namespace first-letter capitalized?
|
||||
*
|
||||
|
|
|
|||
|
|
@ -437,6 +437,36 @@ class MWNamespaceTest extends MediaWikiTestCase {
|
|||
$wgContentNamespaces = $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetSubjectNamespaces() {
|
||||
$subjectsNS = MWNamespace::getSubjectNamespaces();
|
||||
$this->assertContains( NS_MAIN, $subjectsNS,
|
||||
"Talk namespaces should have NS_MAIN" );
|
||||
$this->assertNotContains( NS_TALK, $subjectsNS,
|
||||
"Talk namespaces should have NS_TALK" );
|
||||
|
||||
$this->assertNotContains( NS_MEDIA, $subjectsNS,
|
||||
"Talk namespaces should not have NS_MEDIA" );
|
||||
$this->assertNotContains( NS_SPECIAL, $subjectsNS,
|
||||
"Talk namespaces should not have NS_SPECIAL" );
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetTalkNamespaces() {
|
||||
$talkNS = MWNamespace::getTalkNamespaces();
|
||||
$this->assertContains( NS_TALK, $talkNS,
|
||||
"Subject namespaces should have NS_TALK" );
|
||||
$this->assertNotContains( NS_MAIN, $talkNS,
|
||||
"Subject namespaces should not have NS_MAIN" );
|
||||
|
||||
$this->assertNotContains( NS_MEDIA, $talkNS,
|
||||
"Subject namespaces should not have NS_MEDIA" );
|
||||
$this->assertNotContains( NS_SPECIAL, $talkNS,
|
||||
"Subject namespaces should not have NS_SPECIAL" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some namespaces are always capitalized per code definition
|
||||
* in MWNamespace::$alwaysCapitalizedNamespaces
|
||||
|
|
|
|||
Loading…
Reference in a new issue