Merge "Linker::link() prints deprecated warning if $query is a string"
[lhc/web/wiklou.git] / includes / Linker.php
index 70dac96..9949aa8 100644 (file)
@@ -139,9 +139,9 @@ class Linker {
                if ( $t->isRedirect() ) {
                        # Page is a redirect
                        $colour = 'mw-redirect';
-               } elseif ( $threshold > 0 &&
-                          $t->exists() && $t->getLength() < $threshold &&
-                          $t->isContentPage() ) {
+               } elseif ( $threshold > 0 && $t->isContentPage() &&
+                       $t->exists() && $t->getLength() < $threshold
+               ) {
                        # Page is a stub
                        $colour = 'stub';
                }
@@ -412,6 +412,11 @@ class Linker {
         * despite $query not being used.
         *
         * @param $nt Title
+        * @param $html String [optional]
+        * @param $query String [optional]
+        * @param $trail String [optional]
+        * @param $prefix String [optional]
+        *
         *
         * @return string
         */
@@ -513,7 +518,8 @@ class Linker {
         * Given parameters derived from [[Image:Foo|options...]], generate the
         * HTML that that syntax inserts in the page.
         *
-        * @param $title Title object
+        * @param $parser Parser object
+        * @param $title Title object of the file (not the currently viewed page)
         * @param $file File object, or false if it doesn't exist
         * @param $frameParams Array: associative array of parameters external to the media handler.
         *     Boolean parameters are indicated by presence or absence, the value is arbitrary and
@@ -540,9 +546,10 @@ class Linker {
         * @param $time String: timestamp of the file, set as false for current
         * @param $query String: query params for desc url
         * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
+        * @since 1.20
         * @return String: HTML for an image, with links, wrappers, etc.
         */
-       public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+       public static function makeImageLink( /*Parser*/ $parser, Title $title, $file, $frameParams = array(),
                $handlerParams = array(), $time = false, $query = "", $widthOption = null )
        {
                $res = null;
@@ -615,16 +622,20 @@ class Linker {
                }
 
                if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
-                       global $wgContLang;
-                       # Create a thumbnail. Alignment depends on language
-                       # writing direction, # right aligned for left-to-right-
-                       # languages ("Western languages"), left-aligned
-                       # for right-to-left-languages ("Semitic languages")
+                       # Create a thumbnail. Alignment depends on the writing direction of
+                       # the page content language (right-aligned for LTR languages,
+                       # left-aligned for RTL languages)
                        #
-                       # If  thumbnail width has not been provided, it is set
+                       # If a thumbnail width has not been provided, it is set
                        # to the default user option as specified in Language*.php
                        if ( $fp['align'] == '' ) {
-                               $fp['align'] = $wgContLang->alignEnd();
+                               if( $parser instanceof Parser ) {
+                                       $fp['align'] = $parser->getTargetLanguage()->alignEnd();
+                               } else {
+                                       # backwards compatibility, remove with makeImageLink2()
+                                       global $wgContLang;
+                                       $fp['align'] = $wgContLang->alignEnd();
+                               }
                        }
                        return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
                }
@@ -663,6 +674,17 @@ class Linker {
                return str_replace( "\n", ' ', $prefix . $s . $postfix );
        }
 
+       /**
+        * See makeImageLink()
+        * When this function is removed, remove if( $parser instanceof Parser ) check there too
+        * @deprecated since 1.20
+        */
+       public static function makeImageLink2( Title $title, $file, $frameParams = array(),
+               $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
+               return self::makeImageLink( null, $title, $file, $frameParams,
+                       $handlerParams, $time, $query, $widthOption );
+       }
+
        /**
         * Get the link parameters for MediaTransformOutput::toHtml() from given
         * frame parameters supplied by the Parser.
@@ -983,7 +1005,7 @@ class Linker {
         * @param $userName String: user name in database.
         * @param $altUserName String: text to display instead of the user name (optional)
         * @return String: HTML fragment
-        * @since 1.19 Method exists for a long time. $displayText was added in 1.19.
+        * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
         */
        public static function userLink( $userId, $userName, $altUserName = false ) {
                if ( $userId == 0 ) {
@@ -1651,11 +1673,17 @@ class Linker {
         * other users.
         *
         * @param $rev Revision object
+        * @param $context IContextSource context to use or null for the main context.
         * @return string
         */
-       public static function generateRollback( $rev ) {
+       public static function generateRollback( $rev, IContextSource $context = null ) {
+               if ( $context === null ) {
+                       $context = RequestContext::getMain();
+               }
+
                return '<span class="mw-rollback-link">'
-                       . wfMessage( 'brackets' )->rawParams( self::buildRollbackLink( $rev ) )->plain()
+                       . $context->msg( 'brackets' )->rawParams(
+                               self::buildRollbackLink( $rev, $context ) )->plain()
                        . '</span>';
        }
 
@@ -1663,27 +1691,84 @@ class Linker {
         * Build a raw rollback link, useful for collections of "tool" links
         *
         * @param $rev Revision object
+        * @param $context IContextSource context to use or null for the main context.
         * @return String: HTML fragment
         */
-       public static function buildRollbackLink( $rev ) {
-               global $wgRequest, $wgUser;
+       public static function buildRollbackLink( $rev, IContextSource $context = null ) {
+               global $wgShowRollbackEditCount, $wgMiserMode;
+               
+               // To config which pages are effected by miser mode
+               $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
+
+               if ( $context === null ) {
+                       $context = RequestContext::getMain();
+               }
+
                $title = $rev->getTitle();
                $query = array(
                        'action' => 'rollback',
                        'from' => $rev->getUserText(),
-                       'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
+                       'token' => $context->getUser()->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
                );
-               if ( $wgRequest->getBool( 'bot' ) ) {
+               if ( $context->getRequest()->getBool( 'bot' ) ) {
                        $query['bot'] = '1';
                        $query['hidediff'] = '1'; // bug 15999
                }
-               return self::link(
-                       $title,
-                       wfMsgHtml( 'rollbacklink' ),
-                       array( 'title' => wfMsg( 'tooltip-rollback' ) ),
-                       $query,
-                       array( 'known', 'noclasses' )
-               );
+
+               $disableRollbackEditCount = false;
+               if( $wgMiserMode ) {
+                       foreach( $disableRollbackEditCountSpecialPage as $specialPage ) {
+                               if( $context->getTitle()->isSpecial( $specialPage ) ) {
+                                       $disableRollbackEditCount = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if( !$disableRollbackEditCount && is_int( $wgShowRollbackEditCount ) && $wgShowRollbackEditCount > 0 ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+
+                       // Up to the value of $wgShowRollbackEditCount revisions are counted
+                       $res = $dbr->select( 'revision',
+                               array( 'rev_id', 'rev_user_text' ),
+                               // $rev->getPage() returns null sometimes
+                               array( 'rev_page' => $rev->getTitle()->getArticleID() ),
+                               __METHOD__,
+                               array(  'USE INDEX' => 'page_timestamp',
+                                       'ORDER BY' => 'rev_timestamp DESC',
+                                       'LIMIT' => $wgShowRollbackEditCount + 1 )
+                       );
+
+                       $editCount = 0;
+                       while( $row = $dbr->fetchObject( $res ) ) {
+                               if( $rev->getUserText() != $row->rev_user_text ) {
+                                       break;
+                               }
+                               $editCount++;
+                       }
+
+                       if( $editCount > $wgShowRollbackEditCount ) {
+                               $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )->numParams( $wgShowRollbackEditCount )->parse();
+                       } else {
+                               $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
+                       }
+
+                       return self::link(
+                               $title,
+                               $editCount_output,
+                               array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
+                               $query,
+                               array( 'known', 'noclasses' )
+                       );
+               } else {
+                       return self::link(
+                               $title,
+                               $context->msg( 'rollbacklink' )->escaped(),
+                               array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
+                               $query,
+                               array( 'known', 'noclasses' )
+                       );
+               }
        }
 
        /**
@@ -1718,7 +1803,7 @@ class Linker {
                        }
                        $outText .= "</div><ul>\n";
 
-                       usort( $templates, array( 'Title', 'compare' ) );
+                       usort( $templates, 'Title::compare' );
                        foreach ( $templates as $titleObj ) {
                                $r = $titleObj->getRestrictions( 'edit' );
                                if ( in_array( 'sysop', $r ) ) {
@@ -1918,10 +2003,10 @@ class Linker {
         * Creates a (show/hide) link for deleting revisions/log entries
         *
         * @param $query Array: query parameters to be passed to link()
-        * @param $restricted Boolean: set to true to use a <strong> instead of a <span>
+        * @param $restricted Boolean: set to true to use a "<strong>" instead of a "<span>"
         * @param $delete Boolean: set to true to use (show/hide) rather than (show)
         *
-        * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
+        * @return String: HTML "<a>" link to Special:Revisiondelete, wrapped in a
         * span to allow for customization of appearance with CSS
         */
        public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {