Merge "Handle missing namespace prefix in XML dumps more gracefully"
[lhc/web/wiklou.git] / includes / Title.php
index 5cf911f..3ed6b8b 100644 (file)
@@ -134,7 +134,7 @@ class Title implements LinkTarget {
 
        /**
         * @var int Namespace index when there is no namespace. Don't change the
-        *   following default, NS_MAIN is hardcoded in several places. See bug 696.
+        *   following default, NS_MAIN is hardcoded in several places. See T2696.
         *   Zero except in {{transclusion}} tags.
         */
        public $mDefaultNamespace = NS_MAIN;
@@ -307,7 +307,7 @@ class Title implements LinkTarget {
                        }
                }
 
-               // Convert things like é ā or 〗 into normalized (bug 14952) text
+               // Convert things like é ā or 〗 into normalized (T16952) text
                $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
 
                $t = new Title();
@@ -2417,7 +2417,7 @@ class Title implements LinkTarget {
         *
         * @param string $action The action to check
         * @param bool $short Short circuit on first error
-        * @return array List of errors
+        * @return array Array containing an error message key and any parameters
         */
        private function missingPermissionError( $action, $short ) {
                // We avoid expensive display logic for quickUserCan's and such
@@ -2425,19 +2425,7 @@ class Title implements LinkTarget {
                        return [ 'badaccess-group0' ];
                }
 
-               $groups = array_map( [ 'User', 'makeGroupLinkWiki' ],
-                       User::getGroupsWithPermission( $action ) );
-
-               if ( count( $groups ) ) {
-                       global $wgLang;
-                       return [
-                               'badaccess-groups',
-                               $wgLang->commaList( $groups ),
-                               count( $groups )
-                       ];
-               } else {
-                       return [ 'badaccess-group0' ];
-               }
+               return User::newFatalPermissionDeniedStatus( $action )->getErrorsArray()[0];
        }
 
        /**
@@ -2561,6 +2549,29 @@ class Title implements LinkTarget {
         *   protection, or false if there's none.
         */
        public function getTitleProtection() {
+               $protection = $this->getTitleProtectionInternal();
+               if ( $protection ) {
+                       if ( $protection['permission'] == 'sysop' ) {
+                               $protection['permission'] = 'editprotected'; // B/C
+                       }
+                       if ( $protection['permission'] == 'autoconfirmed' ) {
+                               $protection['permission'] = 'editsemiprotected'; // B/C
+                       }
+               }
+               return $protection;
+       }
+
+       /**
+        * Fetch title protection settings
+        *
+        * To work correctly, $this->loadRestrictions() needs to have access to the
+        * actual protections in the database without munging 'sysop' =>
+        * 'editprotected' and 'autoconfirmed' => 'editsemiprotected'. Other
+        * callers probably want $this->getTitleProtection() instead.
+        *
+        * @return array|bool
+        */
+       protected function getTitleProtectionInternal() {
                // Can't protect pages in special namespaces
                if ( $this->getNamespace() < 0 ) {
                        return false;
@@ -2588,12 +2599,6 @@ class Title implements LinkTarget {
                        // fetchRow returns false if there are no rows.
                        $row = $dbr->fetchRow( $res );
                        if ( $row ) {
-                               if ( $row['permission'] == 'sysop' ) {
-                                       $row['permission'] = 'editprotected'; // B/C
-                               }
-                               if ( $row['permission'] == 'autoconfirmed' ) {
-                                       $row['permission'] = 'editsemiprotected'; // B/C
-                               }
                                $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] );
                        }
                        $this->mTitleProtection = $row;
@@ -2991,7 +2996,7 @@ class Title implements LinkTarget {
 
                        $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
                } else {
-                       $title_protection = $this->getTitleProtection();
+                       $title_protection = $this->getTitleProtectionInternal();
 
                        if ( $title_protection ) {
                                $now = wfTimestampNow();
@@ -3753,14 +3758,14 @@ class Title implements LinkTarget {
                        }
                        $newPageName = preg_replace(
                                        '#^' . preg_quote( $this->getDBkey(), '#' ) . '#',
-                                       StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
+                                       StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
                                        $oldSubpage->getDBkey() );
                        if ( $oldSubpage->isTalkPage() ) {
                                $newNs = $nt->getTalkPage()->getNamespace();
                        } else {
                                $newNs = $nt->getSubjectPage()->getNamespace();
                        }
-                       # Bug 14385: we need makeTitleSafe because the new page names may
+                       # T16385: we need makeTitleSafe because the new page names may
                        # be longer than 255 characters.
                        $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
 
@@ -3877,7 +3882,7 @@ class Title implements LinkTarget {
         * categories' names.
         *
         * @return array Array of parents in the form:
-        *        $parent => $currentarticle
+        *     $parent => $currentarticle
         */
        public function getParentCategories() {
                global $wgContLang;