Awight has uploaded a new change for review.

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

Change subject: Use template to render EnhancedChangesList groups
......................................................................

Use template to render EnhancedChangesList groups

This first pass decouples from the view logic, which is hopefully a step
towards more general handling of the recentChangesFlags.

Change-Id: I3217b80168f89e7b91dbc33a7053865ad3408615
---
M includes/changes/ChangesList.php
M includes/changes/EnhancedChangesList.php
M includes/changes/OldChangesList.php
A includes/templates/EnhancedChangesListGroup.mustache
4 files changed, 94 insertions(+), 65 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/48/247248/1

diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php
index fdc9944..80e1f58 100644
--- a/includes/changes/ChangesList.php
+++ b/includes/changes/ChangesList.php
@@ -340,12 +340,13 @@
        }
 
        /**
-        * @param string $s HTML to update
         * @param RecentChange $rc
         * @param bool $unpatrolled
         * @param bool $watched
+        * @return string HTML
+        * @since 1.26
         */
-       public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
+       public function getArticleLink( &$rc, $unpatrolled, $watched ) {
                $params = array();
                if ( $rc->getTitle()->isRedirect() ) {
                        $params = array( 'redirect' => 'no' );
@@ -365,23 +366,23 @@
                # RTL/LTR marker
                $articlelink .= $this->getLanguage()->getDirMark();
 
+               # TODO: Deprecate the $s argument, it seems happily unused.
+               $s = '';
                Hooks::run( 'ChangesListInsertArticleLink',
                        array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, 
$watched ) );
 
-               $s .= " $articlelink";
+               return "{$s} {$articlelink}";
        }
 
        /**
+        * @param string $s
         * @param RecentChange $rc
         * @param bool $unpatrolled
         * @param bool $watched
-        * @return string
-        * @since 1.26
+        * @deprecated in 1.26. Use getArticleLink instead.
         */
-       public function getArticleLink( RecentChange $rc, $unpatrolled, 
$watched ) {
-               $s = '';
-               $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
-               return $s;
+       public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, 
$watched ) {
+               $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
        }
 
        /**
diff --git a/includes/changes/EnhancedChangesList.php 
b/includes/changes/EnhancedChangesList.php
index 5a4c8bc..c746252 100644
--- a/includes/changes/EnhancedChangesList.php
+++ b/includes/changes/EnhancedChangesList.php
@@ -160,19 +160,22 @@
        protected function recentChangesBlockGroup( $block ) {
 
                # Add the namespace and title of the block as part of the class
-               $classes = array( 'mw-collapsible', 'mw-collapsed', 
'mw-enhanced-rc' );
+               $tableClasses = array( 'mw-collapsible', 'mw-collapsed', 
'mw-enhanced-rc' );
                if ( $block[0]->mAttribs['rc_log_type'] ) {
                        # Log entry
-                       $classes[] = Sanitizer::escapeClass( 
'mw-changeslist-log-'
+                       $tableClasses[] = Sanitizer::escapeClass( 
'mw-changeslist-log-'
                                . $block[0]->mAttribs['rc_log_type'] );
                } else {
-                       $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
+                       $tableClasses[] = Sanitizer::escapeClass( 
'mw-changeslist-ns'
                                . $block[0]->mAttribs['rc_namespace'] . '-' . 
$block[0]->mAttribs['rc_title'] );
                }
-               $classes[] = $block[0]->watched && 
$block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
-                       ? 'mw-changeslist-line-watched' : 
'mw-changeslist-line-not-watched';
-               $r = Html::openElement( 'table', array( 'class' => $classes ) ) 
.
-                       Html::openElement( 'tr' );
+               if ( $block[0]->watched
+                       && $block[0]->mAttribs['rc_timestamp'] >= 
$block[0]->watched
+               ) {
+                       $tableClasses[] = 'mw-changeslist-line-watched';
+               } else {
+                       $tableClasses[] = 'mw-changeslist-line-not-watched';
+               }
 
                # Collate list of users
                $userlinks = array();
@@ -242,42 +245,24 @@
                        array_push( $users, $text );
                }
 
-               $users = ' <span class="changedby">'
-                       . $this->msg( 'brackets' )->rawParams(
-                               implode( $this->message['semicolon-separator'], 
$users )
-                       )->escaped() . '</span>';
-
-               $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow 
' .
-                       'mw-enhancedchanges-arrow 
mw-enhancedchanges-arrow-space"></span>';
-               $r .= "<td>$tl</td>";
-
-               # Main line
-               $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags(
-                       $collectedRcFlags
-               );
-
-               # Timestamp
-               $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
-
                # Article link
+               $articleLink = '';
                if ( $namehidden ) {
-                       $r .= ' <span class="history-deleted">' .
-                               $this->msg( 'rev-deleted-event' )->escaped() . 
'</span>';
+                       $templateParams['rev-deleted-event'] = $this->msg( 
'rev-deleted-event' )->escaped();
                } elseif ( $allLogs ) {
-                       $r .= $this->maybeWatchedLink( $block[0]->link, 
$block[0]->watched );
+                       $articleLink = $this->maybeWatchedLink( 
$block[0]->link, $block[0]->watched );
                } else {
-                       $this->insertArticleLink( $r, $block[0], 
$block[0]->unpatrolled, $block[0]->watched );
+                       $articleLink = $this->getArticleLink( $block[0], 
$block[0]->unpatrolled, $block[0]->watched );
                }
-
-               $r .= $this->getLanguage()->getDirMark();
 
                $queryParams['curid'] = $curId;
 
-               $r .= $this->getLogText( $block, $queryParams, $allLogs, 
$collectedRcFlags['newpage'], $namehidden );
-
-               $r .= ' <span class="mw-changeslist-separator">. .</span> ';
+               $logtext = $this->getLogText( $block, $queryParams, $allLogs,
+                       $collectedRcFlags['newpage'], $namehidden
+               );
 
                # Character difference (does not apply if only log items)
+               $chardiff = '';
                if ( $RCShowChangedSize && !$allLogs ) {
                        $last = 0;
                        $first = count( $block ) - 1;
@@ -290,27 +275,22 @@
                        }
                        # Get net change
                        $chardiff = $this->formatCharacterDifference( 
$block[$first], $block[$last] );
-
-                       if ( $chardiff == '' ) {
-                               $r .= ' ';
-                       } else {
-                               $r .= ' ' . $chardiff . ' <span 
class="mw-changeslist-separator">. .</span> ';
-                       }
                }
 
-               $r .= $users;
-               $r .= $this->numberofWatchingusers( 
$block[0]->numberofWatchingusers );
-               $r .= '</td></tr>';
-
                # Sub-entries
+               $lines = array();
                foreach ( $block as $rcObj ) {
                        # Classes to apply -- TODO implement
                        $classes = array();
                        $type = $rcObj->mAttribs['rc_type'];
                        $data = array();
+                       $lineParams = array();
 
-                       $trClass = $rcObj->watched && 
$rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
-                               ? ' class="mw-enhanced-watched"' : '';
+                       if ( $rcObj->watched
+                               && $rcObj->mAttribs['rc_timestamp'] >= 
$rcObj->watched
+                       ) {
+                               $lineParams['classes'] = array( 
'mw-enhanced-watched' );
+                       }
                        $separator = ' <span class="mw-changeslist-separator">. 
.</span> ';
 
                        $data['recentChangesFlags'] = array(
@@ -388,30 +368,48 @@
                                continue;
                        }
 
-                       $line = '<tr' . $trClass . '><td></td><td 
class="mw-enhanced-rc">';
                        if ( isset( $data['recentChangesFlags'] ) ) {
-                               $line .= $this->recentChangesFlags( 
$data['recentChangesFlags'] );
+                               $lineParams['recentChangesFlags'] = 
$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>';
+                               $lineParams['timestampLink'] = 
$data['timestampLink'];
                                unset( $data['timestampLink'] );
                        }
 
                        // everything else: makes it easier for extensions to 
add or remove data
-                       $line .= implode( '', $data );
+                       $lineParams['data'] = array_values( $data );
 
-                       $line .= "</td></tr>\n";
-
-                       $r .= $line;
+                       $lines[] = $lineParams;
                }
-               $r .= "</table>\n";
+
+               $numberofWatchingusers = $this->numberofWatchingusers( 
$block[0]->numberofWatchingusers );
+               $usersList = $this->msg( 'brackets' )->rawParams(
+                       implode( $this->message['semicolon-separator'], $users )
+               )->escaped();
+
+               $templateParams = array(
+                       'tableClasses' => $tableClasses,
+                       'collectedRcFlags' => $this->recentChangesFlags( 
$collectedRcFlags ),
+                       'timestamp' => $block[0]->timestamp,
+                       'namehidden' => $namehidden,
+                       'articleLink' => $articleLink,
+                       'languageDirMark' => $this->getLanguage()->getDirMark(),
+                       'numberofWatchingusers' => $numberofWatchingusers,
+                       'logtext' => $logtext,
+                       'chardiff' => $chardiff,
+                       'users' => $usersList,
+                       'lines' => $lines,
+               );
 
                $this->rcCacheIndex++;
 
-               return $r;
+               $templateParser = new TemplateParser();
+               return $templateParser->processTemplate(
+                       'EnhancedChangesListGroup',
+                       $templateParams
+               );
        }
 
        /**
diff --git a/includes/changes/OldChangesList.php 
b/includes/changes/OldChangesList.php
index 4ce564d..618145a 100644
--- a/includes/changes/OldChangesList.php
+++ b/includes/changes/OldChangesList.php
@@ -99,7 +99,7 @@
                                ),
                                ''
                        );
-                       $this->insertArticleLink( $html, $rc, $unpatrolled, 
$watched );
+                       $html .= $this->getArticleLink( $rc, $unpatrolled, 
$watched );
                }
                # Edit/log timestamp
                $this->insertTimestamp( $html, $rc );
diff --git a/includes/templates/EnhancedChangesListGroup.mustache 
b/includes/templates/EnhancedChangesListGroup.mustache
new file mode 100644
index 0000000..c72aabd
--- /dev/null
+++ b/includes/templates/EnhancedChangesListGroup.mustache
@@ -0,0 +1,30 @@
+<table class="{{# tableClasses }}{{ . }} {{/ tableClasses }}">
+       <tr>
+               <td>
+                       <span class="mw-collapsible-toggle mw-collapsible-arrow 
mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>
+               </td>
+               <td class="mw-enhanced-rc">{{{ collectedRcFlags }}}&#160;{{ 
timestamp }}&#160;</td>
+               <td>
+                       {{# namehidden }}<span class="history-deleted">{{ 
rev-deleted-event }}</span>{{/ namehidden }}
+                       {{{ articleLink }}}
+                       {{{ languageDirMark }}}
+                       {{{ logText }}}
+                       <span class="mw-changeslist-separator">. .</span>
+                       {{# chardiff }}{{{ chardiff }}}<span 
class="mw-changeslist-separator">. .</span>{{/ chardiff }}
+                       <span class="changedby">{{{ users }}}</span>
+                       {{ numberofWatchingusers }}
+               </td>
+       </tr>
+       {{# lines }}
+       <tr class="{{# classes }}{{ . }} {{/ classes }}">
+               <td></td>
+               <td class="mw-enhanced-rc">{{{ recentChangesFlags }}}&#160;</td>
+               <td class="mw-enhanced-rc-nested">
+                       {{# timestampLink }}
+                       <span class="mw-enhanced-rc-time">{{{ timestampLink 
}}}</span>
+                       {{/ timestampLink }}
+                       {{# data }}{{{ . }}}{{/ data }}
+               </td>
+       </tr>
+       {{/ lines }}
+</table>

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

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

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

Reply via email to