Followup r86622: add initial QUnit test cases for jquery.textSelection module.
[lhc/web/wiklou.git] / includes / LogPage.php
index ee18d67..5155d9a 100644 (file)
@@ -38,7 +38,18 @@ class LogPage {
        const SUPPRESSED_USER = 12;
        const SUPPRESSED_ACTION = 9;
        /* @access private */
-       var $type, $action, $comment, $params, $target, $doer;
+       var $type, $action, $comment, $params;
+
+       /**
+        * @var User
+        */
+       var $doer;
+
+       /**
+        * @var Title
+        */
+       var $target;
+
        /* @acess public */
        var $updateRecentChanges, $sendToUDP;
 
@@ -56,6 +67,9 @@ class LogPage {
                $this->sendToUDP = ( $udp == 'UDP' );
        }
 
+       /**
+        * @return bool|int|null
+        */
        protected function saveContent() {
                global $wgLogRestrictions;
 
@@ -193,26 +207,32 @@ class LogPage {
        {
                global $wgLang, $wgContLang, $wgLogActions;
 
+               if ( is_null( $skin ) ) {
+                       $langObj = $wgContLang;
+                       $langObjOrNull = null;
+               } else {
+                       $langObj = $wgLang;
+                       $langObjOrNull = $wgLang;
+               }
+
                $key = "$type/$action";
                # Defer patrol log to PatrolLog class
                if( $key == 'patrol/patrol' ) {
-                       return PatrolLog::makeActionText( $title, $params, $skin );
+                       return PatrolLog::makeActionText( $title, $params, $langObjOrNull );
                }
                if( isset( $wgLogActions[$key] ) ) {
                        if( is_null( $title ) ) {
-                               $rv = wfMsgHtml( $wgLogActions[$key] );
+                               $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'language' => $langObj ) );
                        } else {
-                               $titleLink = self::getTitleLink( $type, $skin, $title, $params );
-                               if( $key == 'rights/rights' ) {
+                               $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params );
+                               if( preg_match( '/^rights\/(rights|autopromote)/', $key ) ) {
+                                       $rightsnone = wfMsgExt( 'rightsnone', array( 'parsemag', 'language' => $langObj ) );
                                        if( $skin ) {
-                                               $rightsnone = wfMsg( 'rightsnone' );
                                                foreach ( $params as &$param ) {
                                                        $groupArray = array_map( 'trim', explode( ',', $param ) );
                                                        $groupArray = array_map( array( 'User', 'getGroupMember' ), $groupArray );
                                                        $param = $wgLang->listToText( $groupArray );
                                                }
-                                       } else {
-                                               $rightsnone = wfMsgForContent( 'rightsnone' );
                                        }
                                        if( !isset( $params[0] ) || trim( $params[0] ) == '' ) {
                                                $params[0] = $rightsnone;
@@ -222,11 +242,7 @@ class LogPage {
                                        }
                                }
                                if( count( $params ) == 0 ) {
-                                       if ( $skin ) {
-                                               $rv = wfMsgHtml( $wgLogActions[$key], $titleLink );
-                                       } else {
-                                               $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'content' ), $titleLink );
-                                       }
+                                       $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'language' => $langObj ), $titleLink );
                                } else {
                                        $details = '';
                                        array_unshift( $params, $titleLink );
@@ -239,33 +255,25 @@ class LogPage {
                                                        $params[1] = $wgContLang->translateBlockExpiry( $params[1] );
                                                }
                                                $params[2] = isset( $params[2] ) ?
-                                                       self::formatBlockFlags( $params[2], is_null( $skin ) ) : '';
+                                                       self::formatBlockFlags( $params[2], $langObj ) : '';
 
                                        // Page protections
                                        } elseif ( $type == 'protect' && count($params) == 3 ) {
                                                // Restrictions and expiries
                                                if( $skin ) {
-                                                       $details .= htmlspecialchars( " {$params[1]}" );
+                                                       $details .= $wgLang->getDirMark() . htmlspecialchars( " {$params[1]}" );
                                                } else {
                                                        $details .= " {$params[1]}";
                                                }
                                                // Cascading flag...
                                                if( $params[2] ) {
-                                                       if ( $skin ) {
-                                                               $details .= ' [' . wfMsg( 'protect-summary-cascade' ) . ']';
-                                                       } else {
-                                                               $details .= ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']';
-                                                       }
+                                                       $details .= ' [' . wfMsgExt( 'protect-summary-cascade', array( 'parsemag', 'language' => $langObj ) ) . ']';
                                                }
 
                                        // Page moves
                                        } elseif ( $type == 'move' && count( $params ) == 3 ) {
                                                if( $params[2] ) {
-                                                       if ( $skin ) {
-                                                               $details .= ' [' . wfMsg( 'move-redirect-suppressed' ) . ']';
-                                                       } else {
-                                                               $details .= ' [' . wfMsgForContent( 'move-redirect-suppressed' ) . ']';
-                                                       }
+                                                       $details .= ' [' . wfMsgExt( 'move-redirect-suppressed', array( 'parsemag', 'language' => $langObj ) ) . ']';
                                                }
 
                                        // Revision deletion
@@ -273,21 +281,17 @@ class LogPage {
                                                $count = substr_count( $params[2], ',' ) + 1; // revisions
                                                $ofield = intval( substr( $params[3], 7 ) ); // <ofield=x>
                                                $nfield = intval( substr( $params[4], 7 ) ); // <nfield=x>
-                                               $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, false, is_null( $skin ) );
+                                               $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, $langObj, false );
 
                                        // Log deletion
                                        } elseif ( preg_match( '/^(delete|suppress)\/event$/', $key ) && count( $params ) == 4 ) {
                                                $count = substr_count( $params[1], ',' ) + 1; // log items
                                                $ofield = intval( substr( $params[2], 7 ) ); // <ofield=x>
                                                $nfield = intval( substr( $params[3], 7 ) ); // <nfield=x>
-                                               $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, true, is_null( $skin ) );
+                                               $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, $langObj, true );
                                        }
 
-                                       if ( $skin ) {
-                                               $rv = wfMsgHtml( $wgLogActions[$key], $params ) . $details;
-                                       } else {
-                                               $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'content' ), $params ) . $details;
-                                       }
+                                       $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'language' => $langObj ), $params ) . $details;
                                }
                        }
                } else {
@@ -321,14 +325,14 @@ class LogPage {
        /**
         * TODO document
         * @param  $type String
-        * @param  $skin Skin
+        * @param  $lang Language or null
         * @param  $title Title
         * @param  $params Array
         * @return String
         */
-       protected static function getTitleLink( $type, $skin, $title, &$params ) {
-               global $wgLang, $wgContLang, $wgUserrightsInterwikiDelimiter;
-               if( !$skin ) {
+       protected static function getTitleLink( $type, $lang, $title, &$params ) {
+               global $wgContLang, $wgUserrightsInterwikiDelimiter;
+               if( !$lang ) {
                        return $title->getPrefixedText();
                }
                switch( $type ) {
@@ -384,7 +388,7 @@ class LogPage {
                                        Title::newFromText( $params[0] ),
                                        htmlspecialchars( $params[0] )
                                );
-                               $params[1] = $wgLang->timeanddate( $params[1] );
+                               $params[1] = $lang->timeanddate( $params[1] );
                                break;
                        default:
                                if( $title->getNamespace() == NS_SPECIAL ) {
@@ -493,19 +497,16 @@ class LogPage {
         * into a more readable (and translated) form
         *
         * @param $flags Flags to format
-        * @param $forContent Whether to localize the message depending of the user
-        *                    language
+        * @param $lang Language object to use
         * @return String
         */
-       public static function formatBlockFlags( $flags, $forContent = false ) {
-               global $wgLang;
-
+       public static function formatBlockFlags( $flags, $lang ) {
                $flags = explode( ',', trim( $flags ) );
                if( count( $flags ) > 0 ) {
                        for( $i = 0; $i < count( $flags ); $i++ ) {
-                               $flags[$i] = self::formatBlockFlag( $flags[$i], $forContent );
+                               $flags[$i] = self::formatBlockFlag( $flags[$i], $lang );
                        }
-                       return '(' . $wgLang->commaList( $flags ) . ')';
+                       return '(' . $lang->commaList( $flags ) . ')';
                } else {
                        return '';
                }
@@ -515,19 +516,15 @@ class LogPage {
         * Translate a block log flag if possible
         *
         * @param $flag int Flag to translate
-        * @param $forContent Whether to localize the message depending of the user
-        *                    language
+        * @param $lang Language object to use
         * @return String
         */
-       public static function formatBlockFlag( $flag, $forContent = false ) {
+       public static function formatBlockFlag( $flag, $lang ) {
                static $messages = array();
                if( !isset( $messages[$flag] ) ) {
                        $messages[$flag] = htmlspecialchars( $flag ); // Fallback
 
-                       $msg = wfMessage( 'block-log-flags-' . $flag );
-                       if ( $forContent ) {
-                               $msg->inContentLanguage();
-                       }
+                       $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang );
                        if ( $msg->exists() ) {
                                $messages[$flag] = $msg->escaped();
                        }