Matthias Mullie has submitted this change and it was merged.

Change subject: Hygiene: Pass FormatterRow for context if possible
......................................................................


Hygiene: Pass FormatterRow for context if possible

I ran into an issue in a followup patch writing tests for the
RevisionFormatter that it was reaching out into global state via the
Collection class to get the previous revision of the one it was formatting.

This patch allows a FormatterRow instance, which is often available, to
be passed into processParams as well so it can access the already loaded
previous revision rather than reaching out through global state.

Change-Id: I416da501eeb0d41506c0192c6df581d576fe5ffc
---
M includes/Formatter/RevisionFormatter.php
1 file changed, 13 insertions(+), 6 deletions(-)

Approvals:
  Matthias Mullie: Verified; Looks good to me, approved



diff --git a/includes/Formatter/RevisionFormatter.php 
b/includes/Formatter/RevisionFormatter.php
index 19962ce..c3b1801 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -164,7 +164,7 @@
                        'timestamp_readable' => $language->userTimeAndDate( 
$ts, $user ),
                        'changeType' => $row->revision->getChangeType(),
                        'dateFormats' => $this->getDateFormats( $row->revision, 
$ctx ),
-                       'properties' => $this->buildProperties( 
$row->workflow->getId(), $row->revision, $ctx ),
+                       'properties' => $this->buildProperties( 
$row->workflow->getId(), $row->revision, $ctx, $row ),
                        'isModerated' => $moderatedRevision->isModerated(),
                        // These are read urls
                        'links' => $this->buildLinks( $row ),
@@ -263,7 +263,8 @@
                                        'topic-of-post',
                                        $row->revision,
                                        $row->workflow->getId(),
-                                       $ctx
+                                       $ctx,
+                                       $row
                                );
                        }
                }
@@ -728,9 +729,10 @@
         * @param UUID $workflowId
         * @param AbstractRevision $revision
         * @param IContextSource $ctx
+        * @param FormatterRow|null $row
         * @return array
         */
-       public function buildProperties( UUID $workflowId, AbstractRevision 
$revision, IContextSource $ctx ) {
+       public function buildProperties( UUID $workflowId, AbstractRevision 
$revision, IContextSource $ctx, FormatterRow $row = null ) {
                if ( $this->includeProperties === false ) {
                        return array();
                }
@@ -748,7 +750,7 @@
 
                $res = array( '_key' => $actions->getValue( $changeType, 
'history', 'i18n-message' ) );
                foreach ( $params as $param ) {
-                       $res[$param] = $this->processParam( $param, $revision, 
$workflowId, $ctx );
+                       $res[$param] = $this->processParam( $param, $revision, 
$workflowId, $ctx, $row );
                }
 
                return $res;
@@ -761,11 +763,12 @@
         * @param AbstractRevision|array $revision The revision to format or an 
array of revisions
         * @param UUID $workflowId The UUID of the workflow $revision belongs 
tow
         * @param IContextSource $ctx
+        * @param FormatterRow|null $row
         * @return mixed A valid parameter for a core Message instance. These 
parameters will be used
         *  with Message::parse
         * @throws FlowException
         */
-       public function processParam( $param, /* AbstractRevision|array */ 
$revision, UUID $workflowId, IContextSource $ctx ) {
+       public function processParam( $param, /* AbstractRevision|array */ 
$revision, UUID $workflowId, IContextSource $ctx, FormatterRow $row = null ) {
                switch ( $param ) {
                case 'creator-text':
                        if ( $revision instanceof PostRevision ) {
@@ -804,7 +807,11 @@
                        if ( $revision->isFirstRevision() ) {
                                return '';
                        }
-                       $previousRevision = 
$revision->getCollection()->getPrevRevision( $revision );
+                       if ( $row === null ) {
+                               $previousRevision = 
$revision->getCollection()->getPrevRevision( $revision );
+                       } else {
+                               $previousRevision = $row->previousRevision;
+                       }
                        if ( !$previousRevision ) {
                                return '';
                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I416da501eeb0d41506c0192c6df581d576fe5ffc
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>

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

Reply via email to