Re-introduce "Templatize Special:Contributions lines"
authoramir <Ladsgroup@gmail.com>
Mon, 6 Jun 2016 21:10:43 +0000 (21:10 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 8 Jun 2016 20:50:44 +0000 (20:50 +0000)
The original change was 1bce6db10e99840cfbd10fa074c93d8d96d88412
It got reverted in I8f63e002e34a9d13e2597a27e3dd918a687d1e7c
Fixed issues raised

Bug: T122537
Change-Id: I047038d6164bd6e32909d25bb37002b43bfd3a92

includes/specials/pagers/ContribsPager.php
includes/templates/SpecialContributionsLine.mustache [new file with mode: 0644]

index d90c37b..201e4e8 100644 (file)
@@ -447,16 +447,13 @@ class ContribsPager extends ReverseChronologicalPager {
                                $userlink = '';
                        }
 
+                       $flags = [];
                        if ( $rev->getParentId() === 0 ) {
-                               $nflag = ChangesList::flag( 'newpage' );
-                       } else {
-                               $nflag = '';
+                               $flags[] = ChangesList::flag( 'newpage' );
                        }
 
                        if ( $rev->isMinor() ) {
-                               $mflag = ChangesList::flag( 'minor' );
-                       } else {
-                               $mflag = '';
+                               $flags[] = ChangesList::flag( 'minor' );
                        }
 
                        $del = Linker::getRevDeleteLink( $user, $rev, $page );
@@ -467,15 +464,6 @@ class ContribsPager extends ReverseChronologicalPager {
                        $diffHistLinks = $this->msg( 'parentheses' )
                                ->rawParams( $difftext . $this->messages['pipe-separator'] . $histlink )
                                ->escaped();
-                       $ret = "{$del}{$d} {$diffHistLinks}{$chardiff}{$nflag}{$mflag} ";
-                       $ret .= "{$link}{$userlink} {$comment} {$topmarktext}";
-
-                       # Denote if username is redacted for this edit
-                       if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
-                               $ret .= " <strong>" .
-                                       $this->msg( 'rev-deleted-user-contribs' )->escaped() .
-                                       "</strong>";
-                       }
 
                        # Tags, if any.
                        list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
@@ -484,20 +472,47 @@ class ContribsPager extends ReverseChronologicalPager {
                                $this->getContext()
                        );
                        $classes = array_merge( $classes, $newClasses );
-                       $ret .= " $tagSummary";
+
+                       $templateParams = [
+                               'del' => $del,
+                               'timestamp' => $d,
+                               'diffHistLinks' => $diffHistLinks,
+                               'charDifference' => $chardiff,
+                               'flags' => $flags,
+                               'articleLink' => $link,
+                               'userlink' => $userlink,
+                               'logText' => $comment,
+                               'topmarktext' => $topmarktext,
+                               'tagSummary' => $tagSummary,
+                       ];
+
+                       # Denote if username is redacted for this edit
+                       if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
+                               $templateParams['rev-deleted-user-contribs'] =
+                                       $this->msg( 'rev-deleted-user-contribs' )->escaped();
+                       }
+
+                       $templateParser = new TemplateParser();
+                       $ret = $templateParser->processTemplate(
+                               'SpecialContributionsLine',
+                               $templateParams
+                       );
                }
 
                // Let extensions add data
                Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes ] );
 
+               // TODO: Handle exceptions in the catch block above.  Do any extensions rely on
+               // receiving empty rows?
+
                if ( $classes === [] && $ret === '' ) {
                        wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
-                       $ret = "<!-- Could not format Special:Contribution row. -->\n";
-               } else {
-                       $ret = Html::rawElement( 'li', [ 'class' => $classes ], $ret ) . "\n";
+                       return "<!-- Could not format Special:Contribution row. -->\n";
                }
 
-               return $ret;
+               // FIXME: The signature of the ContributionsLineEnding hook makes it
+               // very awkward to move this LI wrapper into the template.
+               return Html::rawElement( 'li', [ 'class' => $classes ], $ret ) . "\n";
        }
 
        /**
diff --git a/includes/templates/SpecialContributionsLine.mustache b/includes/templates/SpecialContributionsLine.mustache
new file mode 100644 (file)
index 0000000..7a33401
--- /dev/null
@@ -0,0 +1,6 @@
+{{{ del }}}{{{ timestamp }}}
+{{{ diffHistLinks }}}{{{ charDifference }}}{{# flags }}{{{ . }}}{{/ flags }}
+{{{ articleLink }}}{{{ userlink }}}
+{{{ logText }}}
+{{{ topmarktext }}}{{# rev-deleted-user-contribs }} <strong>{{{ . }}}</strong>{{/ rev-deleted-user-contribs }}
+{{{ tagSummary }}}