From 9bae2198c950040f9f9139893a23a1012d54d8d6 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 29 Jul 2012 18:57:11 +0200 Subject: [PATCH] (bug 18834) Add an edit count to rollback link Add an edit count to rollback link to show how many edits will be rollbacked. When the count is over 10 the text "more than 10 edits" will be outputed. Change-Id: I5c4050e0a9197d4c505e85685a9780c97138d427 --- includes/DefaultSettings.php | 8 +++++ includes/Linker.php | 53 ++++++++++++++++++++++++++---- languages/messages/MessagesEn.php | 2 ++ languages/messages/MessagesQqq.php | 3 ++ maintenance/language/messages.inc | 2 ++ 5 files changed, 61 insertions(+), 7 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index abf25dc376..54f41757fa 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2685,6 +2685,14 @@ $wgBetterDirectionality = true; */ $wgSend404Code = true; + +/** + * The $wgShowRollbackEditCount variable is used to show how many edits will be + * rollback. The numeric value of the varible are the limit up to are counted. + * If the value is false or 0, the edits are not counted. + */ +$wgShowRollbackEditCount = 10; + /** @} */ # End of output format settings } /*************************************************************************//** diff --git a/includes/Linker.php b/includes/Linker.php index 083845dc04..ae334c6b00 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1673,6 +1673,8 @@ class Linker { * @return String: HTML fragment */ public static function buildRollbackLink( $rev, IContextSource $context = null ) { + global $wgShowRollbackEditCount; + if ( $context === null ) { $context = RequestContext::getMain(); } @@ -1687,13 +1689,50 @@ class Linker { $query['bot'] = '1'; $query['hidediff'] = '1'; // bug 15999 } - return self::link( - $title, - $context->msg( 'rollbacklink' )->escaped(), - array( 'title' => $context->msg( 'tooltip-rollback' )->text() ), - $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' ) + ); + } } /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 461db78053..5f799741d2 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2927,6 +2927,8 @@ proceed with caution.', 'rollback' => 'Roll back edits', 'rollback_short' => 'Rollback', 'rollbacklink' => 'rollback', +'rollbacklinkcount' => 'rollback $1 {{PLURAL:$1|edit|edits}}', +'rollbacklinkcount-morethan' => 'rollback more than $1 {{PLURAL:$1|edit|edits}}', 'rollbackfailed' => 'Rollback failed', 'cantrollback' => 'Cannot revert edit; last contributor is only author of this page.', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index b36bef86dc..f2c7e0bd4c 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -2693,6 +2693,9 @@ $1 is the approximate number of revisions that the page has, the message 'rollback_short' => '{{Identical|Rollback}}', 'rollbacklink' => '{{Identical|Rollback}} This message has a tooltip {{msg-mw|tooltip-rollback}}', +'rollbacklinkcount' => '* $1: the number of edit that will be rollbacked +If $1 is over the value of $wgShowRollbackEditCount (default: 10) [[MediaWiki:Rollbacklinkcount-morethan/en|rollbacklinkcount-morethan]] is used', +'rollbacklinkcount-morethan' => 'Similar to [[MediaWiki:Rollbacklinkcount/en|rollbacklinkcount]] but with prefix more than', 'rollbackfailed' => '{{Identical|Rollback}}', 'cantrollback' => '{{Identical|Revert}} {{Identical|Rollback}}', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 126faaaaa2..000517fa90 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1962,6 +1962,8 @@ $wgMessageStructure = array( 'rollback', 'rollback_short', 'rollbacklink', + 'rollbacklinkcount', + 'rollbacklinkcount-morethan', 'rollbackfailed', 'cantrollback', 'alreadyrolled', -- 2.20.1