Merge "Support deleting all rows"
[lhc/web/wiklou.git] / includes / Linker.php
index 9fcac65..ae334c6 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';
                }
@@ -407,6 +407,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
         */
@@ -978,7 +983,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 ) {
@@ -1646,11 +1651,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>';
        }
 
@@ -1658,27 +1669,70 @@ 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;
+
+               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' )
-               );
+
+               if( 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' ),
+                               array( 'rev_page' => $rev->getPage() ),
+                               __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' )
+                       );
+               }
        }
 
        /**
@@ -1713,7 +1767,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 ) ) {
@@ -1913,10 +1967,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 ) {