Kill non namespaced ScopedCallback
[lhc/web/wiklou.git] / includes / Title.php
index 58e6885..9711749 100644 (file)
@@ -207,8 +207,8 @@ class Title implements LinkTarget {
         * Create a new Title from a prefixed DB key
         *
         * @param string $key The database key, which has underscores
-        *      instead of spaces, possibly including namespace and
-        *      interwiki prefixes
+        *      instead of spaces, possibly including namespace and
+        *      interwiki prefixes
         * @return Title|null Title, or null on an error
         */
        public static function newFromDBkey( $key ) {
@@ -784,11 +784,8 @@ class Title implements LinkTarget {
         * @return int Result of string comparison, or namespace comparison
         */
        public static function compare( LinkTarget $a, LinkTarget $b ) {
-               if ( $a->getNamespace() == $b->getNamespace() ) {
-                       return strcmp( $a->getText(), $b->getText() );
-               } else {
-                       return $a->getNamespace() - $b->getNamespace();
-               }
+               return $a->getNamespace() <=> $b->getNamespace()
+                       ?: strcmp( $a->getText(), $b->getText() );
        }
 
        /**
@@ -1027,12 +1024,11 @@ class Title implements LinkTarget {
         */
        public function getNsText() {
                if ( $this->isExternal() ) {
-                       // This probably shouldn't even happen,
-                       // but for interwiki transclusion it sometimes does.
-                       // Use the canonical namespaces if possible to try to
-                       // resolve a foreign namespace.
-                       if ( MWNamespace::exists( $this->mNamespace ) ) {
-                               return MWNamespace::getCanonicalName( $this->mNamespace );
+                       // This probably shouldn't even happen, except for interwiki transclusion.
+                       // If possible, use the canonical name for the foreign namespace.
+                       $nsText = MWNamespace::getCanonicalName( $this->mNamespace );
+                       if ( $nsText !== false ) {
+                               return $nsText;
                        }
                }
 
@@ -3090,9 +3086,7 @@ class Title implements LinkTarget {
                if ( !$this->mRestrictionsLoaded ) {
                        $this->loadRestrictions();
                }
-               return isset( $this->mRestrictions[$action] )
-                               ? $this->mRestrictions[$action]
-                               : [];
+               return $this->mRestrictions[$action] ?? [];
        }
 
        /**
@@ -3120,7 +3114,7 @@ class Title implements LinkTarget {
                if ( !$this->mRestrictionsLoaded ) {
                        $this->loadRestrictions();
                }
-               return isset( $this->mRestrictionsExpiry[$action] ) ? $this->mRestrictionsExpiry[$action] : false;
+               return $this->mRestrictionsExpiry[$action] ?? false;
        }
 
        /**
@@ -4695,9 +4689,12 @@ class Title implements LinkTarget {
                }
 
                $dbw = wfGetDB( DB_MASTER );
-               $dbw->onTransactionPreCommitOrIdle( function () {
-                       ResourceLoaderWikiModule::invalidateModuleCache( $this, null, null, wfWikiID() );
-               } );
+               $dbw->onTransactionPreCommitOrIdle(
+                       function () {
+                               ResourceLoaderWikiModule::invalidateModuleCache( $this, null, null, wfWikiID() );
+                       },
+                       __METHOD__
+               );
 
                $conds = $this->pageCond();
                DeferredUpdates::addUpdate(
@@ -4795,14 +4792,12 @@ class Title implements LinkTarget {
         */
        public function getNamespaceKey( $prepend = 'nstab-' ) {
                global $wgContLang;
-               // 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
                        $namespaceKey = $this->getSubjectNsText();
                }
                // Makes namespace key lowercase