- // Gets the subject namespace if this title
- $namespace = MWNamespace::getSubject( $this->getNamespace() );
- // Checks if canonical namespace name exists for namespace
- if ( MWNamespace::exists( $this->getNamespace() ) ) {
- // Uses canonical namespace name
- $namespaceKey = MWNamespace::getCanonicalName( $namespace );
- } else {
- // Uses text of namespace
+ // Gets the subject namespace of this title
+ $subjectNS = MWNamespace::getSubject( $this->getNamespace() );
+ // Prefer canonical namespace name for HTML IDs
+ $namespaceKey = MWNamespace::getCanonicalName( $subjectNS );
+ if ( $namespaceKey === false ) {
+ // Fallback to localised text