Add 'EnhancedChangesListModifyLineData' hook
authorStephane Bisson <sbisson@wikimedia.org>
Thu, 25 Jun 2015 19:13:23 +0000 (15:13 -0400)
committerKunal Mehta <legoktm@gmail.com>
Fri, 26 Jun 2015 19:51:55 +0000 (12:51 -0700)
Gives extensions a chance to modify the data used to
build each enhanced recent change 'inner' lines
(as opposed to the header lines).

Bug: T102021
Change-Id: Ia8a796fb9621db14d6574e66a4572e1fdf3bad03

RELEASE-NOTES-1.26
docs/hooks.txt
includes/changes/ChangesList.php
includes/changes/EnhancedChangesList.php

index 983601e..33ba6de 100644 (file)
@@ -34,6 +34,8 @@ production.
   if ImageMagick is used as image scaler ($wgUseImageMagick = true). Uploading
   of WebP images still disabled by default. Add $wgFileExtensions[] =
   'webp'; to LocalSettings.php to enable uploading of WebP images.
+* Added a new hook 'EnhancedChangesListModifyLineData', to
+  modify the data used to build lines in enhanced recentchanges and watchlist.
 
 ==== External libraries ====
 * Update es5-shim from v4.0.0 to v4.1.5.
@@ -116,7 +118,6 @@ changes to languages because of Bugzilla reports.
   way will issue a deprecation warning.
 * The jquery.mwExtension module was deprecated.
 
-
 == Compatibility ==
 
 MediaWiki 1.26 requires PHP 5.3.3 or later. There is experimental support for
@@ -182,4 +183,3 @@ going to run a public MediaWiki, so you can be notified of security fixes.
 == IRC help ==
 
 There's usually someone online in #mediawiki on irc.freenode.net.
-
index 8cfdee9..5480a25 100644 (file)
@@ -1304,6 +1304,13 @@ $changesList: EnhancedChangesList object
 &$links: The links that were generated by EnhancedChangesList
 $block: The RecentChanges objects in that block
 
+'EnhancedChangesListModifyLineData': to alter data used to build
+a recent change inner line in EnhancedChangesList.
+$changesList: EnhancedChangesList object
+&$data: An array with all the components that will be joined in order to create the line
+$block: An array of RecentChange objects in that block
+$rc: The RecentChange object for this line
+
 'ExemptFromAccountCreationThrottle': Exemption from the account creation
 throttle.
 $ip: The ip address of the user
index 932006d..8989b2a 100644 (file)
@@ -204,7 +204,8 @@ class ChangesList extends ContextSource {
                $code = $lang->getCode();
                static $fastCharDiff = array();
                if ( !isset( $fastCharDiff[$code] ) ) {
-                       $fastCharDiff[$code] = $config->get( 'MiserMode' ) || $context->msg( 'rc-change-size' )->plain() === '$1';
+                       $fastCharDiff[$code] = $config->get( 'MiserMode' )
+                               || $context->msg( 'rc-change-size' )->plain() === '$1';
                }
 
                $formattedSize = $lang->formatNum( $szdiff );
@@ -542,6 +543,17 @@ class ChangesList extends ContextSource {
                }
        }
 
+       /**
+        * @param RecentChange $rc
+        * @return string
+        * @since 1.26
+        */
+       public function getRollback( RecentChange $rc ) {
+               $s = '';
+               $this->insertRollback( $s, $rc );
+               return $s;
+       }
+
        /**
         * @param string $s
         * @param RecentChange $rc
@@ -560,6 +572,18 @@ class ChangesList extends ContextSource {
                $s .= ' ' . $tagSummary;
        }
 
+       /**
+        * @param RecentChange $rc
+        * @param array $classes
+        * @return string
+        * @since 1.26
+        */
+       public function getTags( RecentChange $rc, array &$classes ) {
+               $s = '';
+               $this->insertTags( $s, $rc, $classes );
+               return $s;
+       }
+
        public function insertExtra( &$s, &$rc, &$classes ) {
                // Empty, used for subclasses to add anything special.
        }
index 54cde0d..545ea26 100644 (file)
@@ -304,18 +304,18 @@ class EnhancedChangesList extends ChangesList {
                        # Classes to apply -- TODO implement
                        $classes = array();
                        $type = $rcObj->mAttribs['rc_type'];
+                       $data = array();
 
                        $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
                                ? ' class="mw-enhanced-watched"' : '';
+                       $separator = ' <span class="mw-changeslist-separator">. .</span> ';
 
-                       $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
-                       $r .= $this->recentChangesFlags( array(
+                       $data['recentChangesFlags'] = array(
                                'newpage' => $type == RC_NEW,
                                'minor' => $rcObj->mAttribs['rc_minor'],
                                'unpatrolled' => $rcObj->unpatrolled,
                                'bot' => $rcObj->mAttribs['rc_bot'],
-                       ) );
-                       $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
+                       );
 
                        $params = $queryParams;
 
@@ -340,40 +340,65 @@ class EnhancedChangesList extends ChangesList {
                                        $link = '<span class="history-deleted">' . $link . '</span> ';
                                }
                        }
-                       $r .= $link . '</span>';
+                       $data['timestampLink'] = $link;
 
+                       $currentAndLastLinks = '';
                        if ( !$type == RC_LOG || $type == RC_NEW ) {
-                               $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
+                               $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
                                        $rcObj->curlink .
                                                $this->message['pipe-separator'] .
                                                $rcObj->lastlink
                                )->escaped();
                        }
-                       $r .= ' <span class="mw-changeslist-separator">. .</span> ';
+                       $data['currentAndLastLinks'] = $currentAndLastLinks;
+                       $data['separatorAfterCurrentAndLastLinks'] = $separator;
 
                        # Character diff
                        if ( $RCShowChangedSize ) {
                                $cd = $this->formatCharacterDifference( $rcObj );
                                if ( $cd !== '' ) {
-                                       $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
+                                       $data['characterDiff'] = $cd;
+                                       $data['separatorAfterCharacterDiff'] = $separator;
                                }
                        }
 
                        if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
-                               $r .= $this->insertLogEntry( $rcObj );
+                               $data['logEntry'] = $this->insertLogEntry( $rcObj );
                        } else {
                                # User links
-                               $r .= $rcObj->userlink;
-                               $r .= $rcObj->usertalklink;
-                               $r .= $this->insertComment( $rcObj );
+                               $data['userLink'] = $rcObj->userlink;
+                               $data['userTalkLink'] = $rcObj->usertalklink;
+                               $data['comment'] = $this->insertComment( $rcObj );
                        }
 
                        # Rollback
-                       $this->insertRollback( $r, $rcObj );
+                       $data['rollback'] = $this->getRollback( $rcObj );
+
                        # Tags
-                       $this->insertTags( $r, $rcObj, $classes );
+                       $data['tags'] = $this->getTags( $rcObj, $classes );
+
+                       // give the hook a chance to modify the data
+                       Hooks::run( 'EnhancedChangesListModifyLineData',
+                               array( $this, &$data, $block, $rcObj ) );
+
+                       $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
+                       if ( isset( $data['recentChangesFlags'] ) ) {
+                               $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
+                               unset( $data['recentChangesFlags'] );
+                       }
+                       $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
+
+                       if ( isset( $data['timestampLink'] ) ) {
+                               $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
+                               unset( $data['timestampLink'] );
+                       }
+
+                       // everything else: makes it easier for extensions to add or remove data
+                       $line .= implode( '', $data );
+
+                       $line .= "</td></tr>\n";
 
-                       $r .= "</td></tr>\n";
+                       $r .= $line;
                }
                $r .= "</table>\n";