Merge "'lang' attrib in #mw-content-text should be set to variant code."
[lhc/web/wiklou.git] / includes / Title.php
index 642f8dd..f9c7bdf 100644 (file)
@@ -347,7 +347,7 @@ class Title {
         * @return Title the new object
         */
        public static function newMainPage() {
-               $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+               $title = Title::newFromText( wfMessage( 'mainpage' )->inContentLanguage()->text() );
                // Don't give fatal errors if the message is broken
                if ( !$title ) {
                        $title = Title::newFromText( 'Main Page' );
@@ -1270,9 +1270,11 @@ class Title {
         * See getLocalURL for the arguments.
         *
         * @see self::getLocalURL
+        * @see wfExpandUrl
+        * @param $proto Protocol type to use in URL
         * @return String the URL
         */
-       public function getFullURL( $query = '', $query2 = false ) {
+       public function getFullURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
                $query = self::fixUrlQueryArgs( $query, $query2 );
 
                # Hand off all the decisions on urls to getLocalURL
@@ -1281,7 +1283,7 @@ class Title {
                # Expand the url to make it a full url. Note that getLocalURL has the
                # potential to output full urls for a variety of reasons, so we use
                # wfExpandUrl instead of simply prepending $wgServer
-               $url = wfExpandUrl( $url, PROTO_RELATIVE );
+               $url = wfExpandUrl( $url, $proto );
 
                # Finally, add the fragment.
                $url .= $this->getFragmentForURL();
@@ -1592,7 +1594,7 @@ class Title {
         *   queries by skipping checks for cascading protections and user blocks.
         * @param $ignoreErrors Array of Strings Set this to a list of message keys
         *   whose corresponding errors may be ignored.
-        * @return Array of arguments to wfMsg to explain permissions problems.
+        * @return Array of arguments to wfMessage to explain permissions problems.
         */
        public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
                $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
@@ -1749,7 +1751,7 @@ class Title {
                # Check $wgNamespaceProtection for restricted namespaces
                if ( $this->isNamespaceProtected( $user ) ) {
                        $ns = $this->mNamespace == NS_MAIN ?
-                               wfMsg( 'nstab-main' ) : $this->getNsText();
+                               wfMessage( 'nstab-main' )->text() : $this->getNsText();
                        $errors[] = $this->mNamespace == NS_MEDIAWIKI ?
                                array( 'protectedinterface' ) : array( 'namespaceprotected',  $ns );
                }
@@ -1948,7 +1950,7 @@ class Title {
                        $id = $user->blockedBy();
                        $reason = $user->blockedFor();
                        if ( $reason == '' ) {
-                               $reason = wfMsg( 'blockednoreason' );
+                               $reason = wfMessage( 'blockednoreason' )->text();
                        }
                        $ip = $user->getRequest()->getIP();
 
@@ -2106,7 +2108,7 @@ class Title {
         * @param $user User to check
         * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
         * @param $short Bool Set this to true to stop after the first permission error.
-        * @return Array of arrays of the arguments to wfMsg to explain permissions problems.
+        * @return Array of arrays of the arguments to wfMessage to explain permissions problems.
         */
        protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) {
                wfProfileIn( __METHOD__ );
@@ -3544,9 +3546,13 @@ class Title {
                        );
                        # Update the protection log
                        $log = new LogPage( 'protect' );
-                       $comment = wfMsgForContent( 'prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
+                       $comment = wfMessage(
+                               'prot_1movedto2',
+                               $this->getPrefixedText(),
+                               $nt->getPrefixedText()
+                       )->inContentLanguage()->text();
                        if ( $reason ) {
-                               $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+                               $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                        }
                        // @todo FIXME: $params?
                        $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) );
@@ -3604,7 +3610,7 @@ class Title {
                $formatter->setContext( RequestContext::newExtraneousContext( $this ) );
                $comment = $formatter->getPlainActionText();
                if ( $reason ) {
-                       $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+                       $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                }
                # Truncate for whole multibyte characters.
                $comment = $wgContLang->truncate( $comment, 255 );
@@ -3818,7 +3824,7 @@ class Title {
                        return false;
                }
                # Get the article text
-               $rev = Revision::newFromTitle( $nt );
+               $rev = Revision::newFromTitle( $nt, false, Revision::READ_LATEST );
                if( !is_object( $rev ) ){
                        return false;
                }
@@ -4111,11 +4117,11 @@ class Title {
                if ( in_array( 'include_old', $options ) ) {
                        $old_cmp = '>=';
                }
-               if ( in_array( 'include_new', $options ) ) {\r
-                       $new_cmp = '<=';\r
-               }\r
-               if ( in_array( 'include_both', $options ) ) {\r
-                       $old_cmp = '>=';\r
+               if ( in_array( 'include_new', $options ) ) {
+                       $new_cmp = '<=';
+               }
+               if ( in_array( 'include_both', $options ) ) {
+                       $old_cmp = '>=';
                        $new_cmp = '<=';
                }
                // No DB query needed if $old and $new are the same or successive revisions:
@@ -4126,7 +4132,7 @@ class Title {
                                return ( $old_cmp === '>' && $new_cmp === '<' ) ? 0 : 1;
                        }
                        return ( $old->getRawUserText() === $new->getRawUserText() ) ? 1 : 2;
-               }\r
+               }
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
                        array(
@@ -4524,9 +4530,9 @@ class Title {
        }
 
        /**
-        * Get the language in which the content of this page is written.
-        * Defaults to $wgContLang, but in certain cases it can be e.g.
-        * $wgLang (such as special pages, which are in the user language).
+        * Get the language in which the content of this page is written in
+        * wikitext. Defaults to $wgContLang, but in certain cases it can be
+        * e.g. $wgLang (such as special pages, which are in the user language).
         *
         * @since 1.18
         * @return Language
@@ -4551,4 +4557,29 @@ class Title {
                wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) );
                return wfGetLangObj( $pageLang );
        }
+
+       /**
+        * Get the language in which the content of this page is written when
+        * viewed by user. Defaults to $wgContLang, but in certain cases it can be
+        * e.g. $wgLang (such as special pages, which are in the user language).
+        *
+        * @since 1.20
+        * @return Language
+        */
+       public function getPageViewLanguage() {
+               $pageLang = $this->getPageLanguage();
+               // If this is nothing special (so the content is converted when viewed)
+               if ( !$this->isSpecialPage()
+                       && !$this->isCssOrJsPage() && !$this->isCssJsSubpage()
+                       && $this->getNamespace() !== NS_MEDIAWIKI
+               ) {
+                       // If the user chooses a variant, the content is actually
+                       // in a language whose code is the variant code.
+                       $variant = $pageLang->getPreferredVariant();
+                       if ( $pageLang->getCode() !== $variant ) {
+                               $pageLang = Language::factory( $variant );
+                       }
+               }
+               return $pageLang;
+       }
 }