Merge "Surround edit notices with appropriate classes"
[lhc/web/wiklou.git] / includes / Title.php
index cfdba5d..bb4d04e 100644 (file)
@@ -614,28 +614,13 @@ class Title {
         * Note that this doesn't pick up many things that could be wrong with titles, but that
         * replacing this regex with something valid will make many titles valid.
         *
-        * @todo move this into MediaWikiTitleCodec
+        * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead
         *
         * @return string Regex string
         */
        static function getTitleInvalidRegex() {
-               static $rxTc = false;
-               if ( !$rxTc ) {
-                       # Matching titles will be held as illegal.
-                       $rxTc = '/' .
-                               # Any character not allowed is forbidden...
-                               '[^' . self::legalChars() . ']' .
-                               # URL percent encoding sequences interfere with the ability
-                               # to round-trip titles -- you can't link to them consistently.
-                               '|%[0-9A-Fa-f]{2}' .
-                               # XML/HTML character references produce similar issues.
-                               '|&[A-Za-z0-9\x80-\xff]+;' .
-                               '|&#[0-9]+;' .
-                               '|&#x[0-9A-Fa-f]+;' .
-                               '/S';
-               }
-
-               return $rxTc;
+               wfDeprecated( __METHOD__, '1.25' );
+               return MediaWikiTitleCodec::getTitleInvalidRegex();
        }
 
        /**
@@ -1334,6 +1319,25 @@ class Title {
                return Title::makeTitle( $subjectNS, $this->getDBkey() );
        }
 
+       /**
+        * Get the other title for this page, if this is a subject page
+        * get the talk page, if it is a subject page get the talk page
+        *
+        * @since 1.25
+        * @throws MWException
+        * @return Title
+        */
+       public function getOtherPage() {
+               if ( $this->isSpecialPage() ) {
+                       throw new MWException( 'Special pages cannot have other pages' );
+               }
+               if ( $this->isTalkPage() ) {
+                       return $this->getSubjectPage();
+               } else {
+                       return $this->getTalkPage();
+               }
+       }
+
        /**
         * Get the default namespace index, for when there is no namespace
         *
@@ -1778,7 +1782,6 @@ class Title {
         * @return string The URL
         */
        public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
-               wfProfileIn( __METHOD__ );
                if ( $this->isExternal() || $proto !== PROTO_RELATIVE ) {
                        $ret = $this->getFullURL( $query, $query2, $proto );
                } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
@@ -1786,7 +1789,6 @@ class Title {
                } else {
                        $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -2440,7 +2442,6 @@ class Title {
        protected function getUserPermissionsErrorsInternal( $action, $user,
                $doExpensiveQueries = true, $short = false
        ) {
-               wfProfileIn( __METHOD__ );
 
                # Read has special handling
                if ( $action == 'read' ) {
@@ -2481,7 +2482,6 @@ class Title {
                        $errors = $this->$method( $action, $user, $errors, $doExpensiveQueries, $short );
                }
 
-               wfProfileOut( __METHOD__ );
                return $errors;
        }
 
@@ -2717,8 +2717,6 @@ class Title {
                        return array( $this->mHasCascadingRestrictions, $pagerestrictions );
                }
 
-               wfProfileIn( __METHOD__ );
-
                $dbr = wfGetDB( DB_SLAVE );
 
                if ( $this->getNamespace() == NS_FILE ) {
@@ -2793,7 +2791,6 @@ class Title {
                        $this->mHasCascadingRestrictions = $sources;
                }
 
-               wfProfileOut( __METHOD__ );
                return array( $sources, $pagerestrictions );
        }
 
@@ -2812,8 +2809,10 @@ class Title {
         * Accessor/initialisation for mRestrictions
         *
         * @param string $action Action that permission needs to be checked for
-        * @return array Restriction levels needed to take the action. All levels
-        *     are required.
+        * @return array Restriction levels needed to take the action. All levels are
+        *     required. Note that restriction levels are normally user rights, but 'sysop'
+        *     and 'autoconfirmed' are also allowed for backwards compatibility. These should
+        *     be mapped to 'editprotected' and 'editsemiprotected' respectively.
         */
        public function getRestrictions( $action ) {
                if ( !$this->mRestrictionsLoaded ) {
@@ -4040,7 +4039,7 @@ class Title {
                if ( $this->mIsBigDeletion === null ) {
                        $dbr = wfGetDB( DB_SLAVE );
 
-                       $innerQuery = $dbr->selectSQLText(
+                       $revCount = $dbr->selectRowCount(
                                'revision',
                                '1',
                                array( 'rev_page' => $this->getArticleID() ),
@@ -4048,13 +4047,6 @@ class Title {
                                array( 'LIMIT' => $wgDeleteRevisionsLimit + 1 )
                        );
 
-                       $revCount = $dbr->query(
-                               'SELECT COUNT(*) FROM (' . $innerQuery . ') AS innerQuery',
-                               __METHOD__
-                       );
-                       $revCount = $revCount->fetchRow();
-                       $revCount = $revCount['COUNT(*)'];
-
                        $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit;
                }
 
@@ -4624,16 +4616,13 @@ class Title {
         */
        public function getPageLanguage() {
                global $wgLang, $wgLanguageCode;
-               wfProfileIn( __METHOD__ );
                if ( $this->isSpecialPage() ) {
                        // special pages are in the user language
-                       wfProfileOut( __METHOD__ );
                        return $wgLang;
                }
 
                // Checking if DB language is set
                if ( $this->mDbPageLanguage ) {
-                       wfProfileOut( __METHOD__ );
                        return wfGetLangObj( $this->mDbPageLanguage );
                }
 
@@ -4651,7 +4640,6 @@ class Title {
                        $langObj = wfGetLangObj( $this->mPageLanguage[0] );
                }
 
-               wfProfileOut( __METHOD__ );
                return $langObj;
        }
 
@@ -4702,7 +4690,9 @@ class Title {
                $editnotice_ns = 'editnotice-' . $this->getNamespace();
                $editnotice_ns_message = wfMessage( $editnotice_ns );
                if ( $editnotice_ns_message->exists() ) {
-                       $notices[$editnotice_ns] = $editnotice_ns_message->parseAsBlock();
+                       $notices[$editnotice_ns] = '<div class="mw-editnotice mw-editnotice-namespace ' .
+                               Sanitizer::escapeClass( "mw-$editnotice_ns" ) . '">' .
+                               $editnotice_ns_message->parseAsBlock() . '</div>';
                }
                if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
                        $parts = explode( '/', $this->getDBkey() );
@@ -4711,7 +4701,9 @@ class Title {
                                $editnotice_base .= '-' . array_shift( $parts );
                                $editnotice_base_msg = wfMessage( $editnotice_base );
                                if ( $editnotice_base_msg->exists() ) {
-                                       $notices[$editnotice_base] = $editnotice_base_msg->parseAsBlock();
+                                       $notices[$editnotice_base] = '<div class="mw-editnotice mw-editnotice-base ' .
+                                               Sanitizer::escapeClass( "mw-$editnotice_base" ) . '">' .
+                                               $editnotice_base_msg->parseAsBlock() . '</div>';
                                }
                        }
                } else {
@@ -4719,7 +4711,9 @@ class Title {
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() );
                        $editnoticeMsg = wfMessage( $editnoticeText );
                        if ( $editnoticeMsg->exists() ) {
-                               $notices[$editnoticeText] = $editnoticeMsg->parseAsBlock();
+                               $notices[$editnoticeText] = '<div class="mw-editnotice mw-editnotice-page ' .
+                                       Sanitizer::escapeClass( "mw-$editnoticeText" ) . '">' .
+                                       $editnoticeMsg->parseAsBlock() . '</div>';
                        }
                }