Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/66038


Change subject: Allow modification of flags on Recent Changes
......................................................................

Allow modification of flags on Recent Changes

Moved the message map in ChangesList::flag to a new setting named
$wgRecentChangesFlags and used it keys to iterate over the flags

Also make ChangesList::recentChangesFlags public to be used from
extensions, when they will build its own line

Changed one list of placeholders to use recentChangesFlags to have the
correct number of spaces there

Change-Id: If69de05c4edec4e84c3e059090b9cb89845e3269
---
M includes/ChangesList.php
M includes/DefaultSettings.php
2 files changed, 31 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/38/66038/1

diff --git a/includes/ChangesList.php b/includes/ChangesList.php
index 796b92a..d1a83cd 100644
--- a/includes/ChangesList.php
+++ b/includes/ChangesList.php
@@ -136,9 +136,10 @@
         * @param string $nothing to use for empty space
         * @return String
         */
-       protected function recentChangesFlags( $flags, $nothing = ' ' ) {
+       public function recentChangesFlags( $flags, $nothing = ' ' ) {
+               global $wgRecentChangesFlags;
                $f = '';
-               foreach ( array( 'newpage', 'minor', 'bot', 'unpatrolled' ) as 
$flag ) {
+               foreach ( array_keys( $wgRecentChangesFlags ) as $flag ) {
                        $f .= isset( $flags[$flag] ) && $flags[$flag]
                                ? self::flag( $flag )
                                : $nothing;
@@ -152,36 +153,30 @@
         * unpatrolled edit.  By default in English it will contain "N", "m", 
"b",
         * "!" respectively, plus it will have an appropriate title and class.
         *
-        * @param string $flag 'newpage', 'unpatrolled', 'minor', or 'bot'
+        * @param string $flag One key of $wgRecentChangesFlags
         * @return String: Raw HTML
         */
        public static function flag( $flag ) {
                static $messages = null;
                if ( is_null( $messages ) ) {
-                       $messages = array(
-                               'newpage' => array( 'newpageletter', 
'recentchanges-label-newpage' ),
-                               'minoredit' => array( 'minoreditletter', 
'recentchanges-label-minor' ),
-                               'botedit' => array( 'boteditletter', 
'recentchanges-label-bot' ),
-                               'unpatrolled' => array( 'unpatrolledletter', 
'recentchanges-label-unpatrolled' ),
-                       );
-                       foreach ( $messages as &$value ) {
-                               $value[0] = wfMessage( $value[0] )->escaped();
-                               $value[1] = wfMessage( $value[1] )->escaped();
+                       global $wgRecentChangesFlags;
+                       $messages = array();
+                       foreach ( $wgRecentChangesFlags as $key => $value ) {
+                               $messages[$key][0] = wfMessage( $value[0] 
)->escaped();
+                               $messages[$key][1] = wfMessage( $value[1] 
)->escaped();
                        }
                }
 
                # Inconsistent naming, bleh
                $map = array(
-                       'newpage' => 'newpage',
-                       'minor' => 'minoredit',
-                       'bot' => 'botedit',
-                       'unpatrolled' => 'unpatrolled',
-                       'minoredit' => 'minoredit',
-                       'botedit' => 'botedit',
+                       'minoredit' => 'minor',
+                       'botedit' => 'bot',
                );
-               $flag = $map[$flag];
+               if ( isset( $map[$flag] ) ) {
+                       $flag = $map[$flag];
+               }
 
-               return "<abbr class='$flag' title='" . $messages[$flag][1] . 
"'>" . $messages[$flag][0] . '</abbr>';
+               return "<abbr class='" . Sanitizer::escapeClass( $flag ) . "' 
title='" . $messages[$flag][1] . "'>" . $messages[$flag][0] . '</abbr>';
        }
 
        /**
@@ -1198,7 +1193,7 @@
                $r .= '<td class="mw-enhanced-rc"><span 
class="mw-enhancedchanges-arrow-space"></span>';
                # Flag and Timestamp
                if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
-                       $r .= '&#160;&#160;&#160;&#160;'; // 4 flags -> 4 spaces
+                       $r .= $this->recentChangesFlags( array() ); //no flags, 
but need the placeholders
                } else {
                        $r .= $this->recentChangesFlags( array(
                                'newpage' => $type == RC_NEW,
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 5edcce9..9ea1fe9 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5212,6 +5212,21 @@
  */
 $wgUnwatchedPageThreshold = false;
 
+/**
+ * Recent changes flag, shown in Recentchanges and watchlist
+ *
+ * Adding a new one:
+ *   $wgRecentChangesFlags['flag'] => array( 'letter-msg', 'tooltip-msg' );
+ *
+ * @since 1.22
+ */
+$wgRecentChangesFlags = array(
+       'newpage' => array( 'newpageletter', 'recentchanges-label-newpage' ),
+       'minor' => array( 'minoreditletter', 'recentchanges-label-minor' ),
+       'bot' => array( 'boteditletter', 'recentchanges-label-bot' ),
+       'unpatrolled' => array( 'unpatrolledletter', 
'recentchanges-label-unpatrolled' ),
+);
+
 /** @} */ # end RC/watchlist }
 
 /************************************************************************//**

-- 
To view, visit https://gerrit.wikimedia.org/r/66038
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If69de05c4edec4e84c3e059090b9cb89845e3269
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to