jenkins-bot has submitted this change and it was merged.

Change subject: Move output functionality from AbstractRevision to Templating
......................................................................


Move output functionality from AbstractRevision to Templating

AbstractRevision::getUserText() & ::getContent() had some functionality that did
not seem like it belonged there. I feel like AbstractRevision should return the
exact data & Templating (responsible for output) should deal with how it should
be displayed, depending on the moderation status.

Since there were multiple getUserText (getUserTextRaw) and getContent
(getConvertedContent, unused getHiddenContent) methods to fetch different
variations of usertext/content, I think it makes sense to keep the "pure data"
in AbstractRevision & the "how do we output it for a certain user and moderation
level" in Templating.

I've removed the now pointless AbstractRevision::getConvertedContent,
::getHiddenContent & ::getUserTextRaw, in favor or just getContent &
getUserText, which will always return raw data.

Added/re-instated Templating::getContent() & ::getUserText(), which should be
used when outputting that data.

Got rid of AbstractRevision::$perms[*]['content'] & ['usertext'] in
AbstractRevision; didn't belong there. Strings are now simply
flow-$state-usertext * flow-$state-content, as defined in Templating.

Note: I have, for now, ignored Notifications & RecentChanges. Both of these are
saved somewhere else right away, so won't be moderated at that time yet.
We should think about this some day.

Change-Id: Ie42a5b1c6efd618a5bd2fa1e7ac43316c239cb50
---
M Flow.i18n.php
M Flow.php
M FlowActions.php
M Hooks.php
M container.php
M includes/Block/Header.php
M includes/Block/Topic.php
M includes/Data/RecentChanges.php
M includes/Model/AbstractRevision.php
M includes/Notifications/Controller.php
M includes/RecentChanges/Formatter.php
M includes/Templating.php
M includes/View/History/HistoryRenderer.php
M templates/edit-header.html.php
M templates/edit-post.html.php
M templates/edit-title.html.php
M templates/header.html.php
M templates/post-history.html.php
M templates/post.html.php
M templates/topic-history.html.php
M templates/topic.html.php
21 files changed, 222 insertions(+), 159 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Flow.i18n.php b/Flow.i18n.php
index 130c89c..89d2a92 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -24,12 +24,12 @@
 
        'flow-post-moderated-toggle-show' => '[Show]',
        'flow-post-moderated-toggle-hide' => '[Hide]',
-       'flow-post-hidden' => '[post hidden]',
-       'flow-post-hidden-by' => '{{GENDER:$1|Hidden}} by $1 $2',
-       'flow-post-deleted' => '[post deleted]',
-       'flow-post-deleted-by' => '{{GENDER:$1|Deleted}} by $1 $2',
-       'flow-post-censored' => '[post suppressed]',
-       'flow-post-censored-by' => '{{GENDER:$1|Suppressed}} by $1 $2',
+       'flow-hide-content' => '{{GENDER:$1|Hidden}} by $1 $2',
+       'flow-hide-usertext' => '$1',
+       'flow-delete-content' => '{{GENDER:$1|Deleted}} by $1 $2',
+       'flow-delete-usertext' => '$1',
+       'flow-censor-content' => '{{GENDER:$1|Suppressed}} by $1 $2',
+       'flow-censor-usertext' => "''Username suppressed''",
        'flow-post-actions' => 'Actions',
        'flow-topic-actions' => 'Actions',
        'flow-cancel' => 'Cancel',
@@ -227,10 +227,11 @@
        'flow-header-empty' => 'Used as a placeholder text for headers which 
have no content.',
        'flow-post-moderated-toggle-show' => 'Text for link used to display a 
moderated post',
        'flow-post-moderated-toggle-hide' => 'Text for link used to hide a 
moderated post',
-       'flow-post-hidden' => 'Used as username/content if the post was hidden.
+       'flow-hide-usertext' => 'Used as username if the post was hidden.
 
-Translate this as "post which was hidden".',
-       'flow-post-hidden-by' => 'Parameters:
+Parameters:
+* $1 - Username of the post creator. Can be used for GENDER',
+       'flow-hide-content' => 'Parameters:
 * $1 - username that hid the post, can be used for GENDER
 * $2 - timestamp, relative to post creation date, of when the post was hidden. 
Any one of the following:
 ** timestamp (time and date); localized
@@ -238,10 +239,11 @@
 ** {{msg-mw|Sunday-at}}, {{msg-mw|Monday-at}}, {{msg-mw|Tuesday-at}}, ...
 ** {{msg-mw|Yesterday-at}}, {{msg-mw|Today-at}}
 {{Related|Flow-post-by}}',
-       'flow-post-deleted' => 'Used as username/content if the post was 
deleted.
+       'flow-delete-usertext' => 'Used as username if the post was deleted.
 
-Translate this as "post which was deleted".',
-       'flow-post-deleted-by' => 'Parameters:
+Parameters:
+* $1 - Username of the post creator. Can be used for GENDER',
+       'flow-delete-content' => 'Parameters:
 * $1 - username that deleted the post, can be used for GENDER
 * $2 - timestamp, relative to post creation date, of when the post was 
deleted. Any one of the following:
 ** timestamp (time and date); localized
@@ -249,10 +251,11 @@
 ** {{msg-mw|Sunday-at}}, {{msg-mw|Monday-at}}, {{msg-mw|Tuesday-at}}, ...
 ** {{msg-mw|Yesterday-at}}, {{msg-mw|Today-at}}
 {{Related|Flow-post-by}}',
-       'flow-post-censored' => 'Used as username/content if the post was 
suppressed.
+       'flow-censor-usertext' => 'Used as username if the post was suppressed.
 
-Translate this as "post which was suppressed".',
-       'flow-post-censored-by' => 'Parameters:
+Parameters:
+* $1 - Username of the post creator. Can be used for GENDER',
+       'flow-censor-content' => 'Parameters:
 * $1 - username that suppressed the post, can be used for GENDER
 * $2 - timestamp, relative to post creation date, of when the post was 
suppressed. Any one of the following:
 ** timestamp (time and date); localized
diff --git a/Flow.php b/Flow.php
index 243c0b4..5d4d745 100755
--- a/Flow.php
+++ b/Flow.php
@@ -157,6 +157,7 @@
 $wgHooks['SkinTemplateNavigation::Universal'][] = 
'FlowHooks::onSkinTemplateNavigation';
 $wgHooks['Article::MissingArticleConditions'][] = 
'FlowHooks::onMissingArticleConditions';
 $wgHooks['SpecialWatchlistGetNonRevisionTypes'][] = 
'FlowHooks::onSpecialWatchlistGetNonRevisionTypes';
+$wgHooks['UserGetReservedNames'][] = 'FlowHooks::onUserGetReservedNames';
 
 // Extension initialization
 $wgExtensionFunctions[] = 'FlowHooks::initFlowExtension';
diff --git a/FlowActions.php b/FlowActions.php
index 32d0d39..d69d18e 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -4,8 +4,8 @@
 use Flow\Model\Header;
 use Flow\PostActionPermissions;
 use Flow\Log\Logger;
-use Flow\UrlGenerator;
 use Flow\Block\Block;
+use Flow\Templating;
 
 /**
  * Flow actions: key => value map with key being the action name.
@@ -39,8 +39,8 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-create-header',
                        'i18n-params' => array(
-                               function ( Header $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( Header $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
                        ),
                        'class' => 'flow-history-create-header',
@@ -61,8 +61,8 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-edit-header',
                        'i18n-params' => array(
-                               function ( Header $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( Header $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
                        ),
                        'class' => 'flow-history-edit-header',
@@ -79,20 +79,20 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-edit-title',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $urlGenerator->generateUrl( 
$revision->getPostId() );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return 
$templating->getUrlGenerator()->generateUrl( $revision->getPostId() );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getContent( $user, 
'wikitext' );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getContent( 
$revision, 'wikitext', $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $previousId = 
$revision->getPrevRevisionId();
                                        if ( $previousId ) {
                                                $previousRevision = 
$block->getStorage()->get( get_class( $revision ), $previousId );
-                                               return 
$previousRevision->getContent( $user, 'wikitext' );
+                                               return $templating->getContent( 
$previousRevision, 'wikitext', $user );
                                        }
 
                                        return '';
@@ -110,14 +110,14 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-new-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $urlGenerator->generateUrl( 
$revision->getPostId() );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return 
$templating->getUrlGenerator()->generateUrl( $revision->getPostId() );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getContent( $user, 
'wikitext' );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getContent( 
$revision, 'wikitext', $user );
                                },
                        ),
                        'class' => 'flow-history-new-post',
@@ -137,12 +137,12 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-edit-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-edit-post',
@@ -162,15 +162,15 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-hid-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-hid-post',
@@ -188,15 +188,15 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-deleted-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-deleted-post',
@@ -215,15 +215,15 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-censored-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-censored-post',
@@ -248,15 +248,15 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-restored-post',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-restored-post',
@@ -298,19 +298,19 @@
                'history' => array(
                        'i18n-message' => 'flow-rev-message-reply',
                        'i18n-params' => array(
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
-                                       return $revision->getUserText( $user );
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
+                                       return $templating->getUserText( 
$revision, $user );
                                },
-                               function ( PostRevision $revision, UrlGenerator 
$urlGenerator, User $user, Block $block ) {
+                               function ( PostRevision $revision, Templating 
$templating, User $user, Block $block ) {
                                        $data = array( $block->getName() . 
'[postId]' => $revision->getPostId()->getHex() );
-                                       return $urlGenerator->generateUrl( 
$block->getWorkflowId(), 'view', $data );
+                                       return 
$templating->getUrlGenerator()->generateUrl( $block->getWorkflowId(), 'view', 
$data );
                                },
                        ),
                        'class' => 'flow-history-reply',
                        'bundle' => array(
                                'i18n-message' => 
'flow-rev-message-reply-bundle',
                                'i18n-params' => array(
-                                       function ( array $revisions, 
UrlGenerator $urlGenerator, User $user, Block $block ) {
+                                       function ( array $revisions, Templating 
$templating, User $user, Block $block ) {
                                                return array( 'num' => count( 
$revisions ) );
                                        }
                                ),
diff --git a/Hooks.php b/Hooks.php
index b3f7793..246c30e 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -263,4 +263,21 @@
                $types[] = Flow\Data\RecentChanges::SRC_FLOW;
                return true;
        }
+
+       /**
+        * Make sure no user can register a flow-*-usertext username, to avoid
+        * confusion with a real user when we print e.g. "Censored" instead of a
+        * username.
+        *
+        * @param array $names
+        * @return bool
+        */
+       public static function onUserGetReservedNames( &$names ) {
+               $permissions = array_keys( AbstractRevision::$perms );
+               foreach ( $permissions as $permission ) {
+                       $names[] = "msg:flow-$permission-usertext";
+               }
+
+               return true;
+       }
 }
diff --git a/container.php b/container.php
index 582a00b..e6fa29b 100644
--- a/container.php
+++ b/container.php
@@ -379,7 +379,7 @@
                $c['storage'],
                $c['factory.loader.workflow'],
                $c['flow_actions'],
-               $c['url_generator'],
+               $c['templating'],
                $wgLang
        );
 } );
diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index a90fd6c..7cfc570 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -76,9 +76,14 @@
                case 'edit-header':
                        $this->storage->put( $this->header );
 
+                       $header = $this->header;
+                       $user = $this->user;
+
                        return array(
                                'new-revision-id' => 
$this->header->getRevisionId(),
-                               'rendered' => $this->header->getContent( 
$this->user, 'html' ),
+                               'render-function' => function( $templating ) 
use ( $header, $user ) {
+                                       return $templating->getContent( 
$header, 'html', $user );
+                               },
                        );
                        break;
 
@@ -128,7 +133,7 @@
                }
 
                if ( $this->header !== null ) {
-                       $output['*'] = $this->header->getContent( $this->user, 
$contentFormat );
+                       $output['*'] = $templating->getContent( $this->header, 
$contentFormat, $this->user );
                        $output['format'] = $contentFormat;
                        $output['header-id'] = 
$this->header->getRevisionId()->getHex();
                } else {
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index f3c1c06..77cfbb0 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -130,8 +130,8 @@
                        $this->setNotification(
                                'flow-topic-renamed',
                                array(
-                                       'old-subject' => 
$topicTitle->getContent( null, 'wikitext' ),
-                                       'new-subject' => 
$this->newRevision->getContent( null, 'wikitext' ),
+                                       'old-subject' => 
$topicTitle->getContent( 'wikitext' ),
+                                       'new-subject' => 
$this->newRevision->getContent( 'wikitext' ),
                                )
                        );
                }
@@ -162,7 +162,7 @@
                                        array(
                                                'reply-to' => $post,
                                                'content' => 
$this->submitted['content'],
-                                               'topic-title' => 
$this->getTitleText(),
+                                               'topic-title' => 
$this->loadTopicTitle()->getContent( 'wikitext' ),
                                        )
                                );
                        }
@@ -257,7 +257,7 @@
                        'flow-post-edited',
                        array(
                                'content' => $this->submitted['content'],
-                               'topic-title' => $this->getTitleText(),
+                               'topic-title' => 
$this->loadTopicTitle()->getContent( 'wikitext' ),
                        )
                );
        }
@@ -281,14 +281,15 @@
                        $this->storage->put( $this->workflow );
                        $self = $this;
                        $newRevision = $this->newRevision;
+                       $user = $this->user;
                        $rootPost = $this->loadRootPost();
 
                        $newRevision->setChildren( array() );
 
                        // FIXME special case
                        if ( $this->action == 'edit-title' ) {
-                               $renderFunction = function( $templating ) use ( 
$newRevision ) {
-                                       return $newRevision->getContent( null, 
'wikitext' );
+                               $renderFunction = function( $templating ) use ( 
$newRevision, $user ) {
+                                       return $templating->getContent( 
$newRevision, 'wikitext', $user );
                                };
                        } else {
                                $renderFunction = function( $templating ) use ( 
$self, $newRevision, $rootPost ) {
@@ -473,7 +474,7 @@
                }
                $output = array(
                        '_element' => 'post',
-                       'title' => $rootPost->getContent( null, 'wikitext' ),
+                       'title' => $templating->getContent( $rootPost, 
'wikitext', $this->user ),
                        'topic-id' => $topic->getId()->getHex(),
                );
 
@@ -527,7 +528,7 @@
                        $output['post-moderated'] = 'post-moderated';
                } else {
                        $output['content'] = array(
-                               '*' => $post->getContent( null, $contentFormat 
),
+                               '*' => $templating->getContent( $post, 
$contentFormat, $this->user ),
                                'format' => $contentFormat
                        );
                        $output['user'] = $post->getCreatorName();
@@ -550,13 +551,13 @@
 
                $postId = $post->getPostId()->getHex();
                if ( isset( $options['history'][$postId] ) ) {
-                       $output['revisions'] = $this->getAPIHistory( $postId, 
$options['history'][$postId] );
+                       $output['revisions'] = $this->getAPIHistory( 
$templating, $postId, $options['history'][$postId] );
                }
 
                return $output;
        }
 
-       protected function getAPIHistory( /*string*/ $postId, array $history ) {
+       protected function getAPIHistory( Templating $templating, /*string*/ 
$postId, array $history ) {
                $output = array();
 
                $output['_element'] = 'revision';
@@ -566,7 +567,7 @@
                        if ( $this->permissions->isAllowed( $revision, 'view' ) 
) {
                                $output[] = array(
                                        'revision-id' => 
$revision->getRevisionId()->getHex(),
-                                       'revision-author' => 
$revision->getUserText(),
+                                       'revision-author' => 
$templating->getUserText( $revision ),
                                        'revision-change-type' => 
$revision->getChangeType(),
                                );
                        }
@@ -643,10 +644,6 @@
                        }
                }
                return $this->topicTitle;
-       }
-
-       public function getTitleText() {
-               return $this->loadTopicTitle()->getContent( null, 'wikitext' );
        }
 
        protected function loadTopicHistory() {
diff --git a/includes/Data/RecentChanges.php b/includes/Data/RecentChanges.php
index a7dd610..9cfac0e 100644
--- a/includes/Data/RecentChanges.php
+++ b/includes/Data/RecentChanges.php
@@ -154,7 +154,7 @@
 
        protected function getTopicTitle( PostRevision $rev ) {
                if ( $rev->isTopicTitle() ) {
-                       return $rev->getContent( null, 'wikitext' );
+                       return $rev->getContent( 'wikitext' );
                }
                $topicTitleId = $this->tree->findRoot( $rev->getPostId() );
                if ( $topicTitleId === null ) {
@@ -169,7 +169,7 @@
                        return null;
                }
 
-               $content = reset( $found )->getContent( null, 'wikitext' );
+               $content = reset( $found )->getContent( 'wikitext' );
                if ( is_object( $content ) ) {
                        // moderated
                        return null;
diff --git a/includes/Model/AbstractRevision.php 
b/includes/Model/AbstractRevision.php
index 512d642..1006e76 100644
--- a/includes/Model/AbstractRevision.php
+++ b/includes/Model/AbstractRevision.php
@@ -16,14 +16,10 @@
         * Metadata relatied to moderation states from least restrictive
         * to most restrictive.
         **/
-       static protected $perms = array(
+       static public $perms = array(
                self::MODERATED_NONE => array(
                        // The permission needed from User::isAllowed to see 
and create new revisions
                        'perm' => null,
-                       // i18n key to replace content with when state is 
active(unused with perm === null )
-                       'content' => null,
-                       // This is the bit of text rendered instead of the post 
creator
-                       'usertext' => null,
                        // Whether or not to create a new revision when setting 
this state
                        'new-revision' => true,
                        // i18n key for history and recentchanges
@@ -32,11 +28,6 @@
                self::MODERATED_HIDDEN => array(
                        // The permission needed from User::isAllowed to see 
and create new revisions
                        'perm' => 'flow-hide',
-                       // i18n key to replace content with when state is active
-                       // NOTE: special case self::getHiddenContent still 
retrieves content in this case only
-                       'content' => 'flow-post-hidden-by',
-                       // This is the bit of text rendered instead of the post 
creator
-                       'usertext' => 'flow-rev-message-hid-post', // @todo: 
message has changed
                        // Whether or not to create a new revision when setting 
this state
                        'new-revision' => true,
                        // i18n key for history and recentchanges
@@ -45,10 +36,6 @@
                self::MODERATED_DELETED => array(
                        // The permission needed from User::isAllowed to see 
and create new revisions
                        'perm' => 'flow-delete',
-                       // i18n key to replace content with when state is active
-                       'content' => 'flow-post-deleted-by',
-                       // This is the bit of text rendered instead of the post 
creator
-                       'usertext' => 'flow-rev-message-deleted-post', // 
@todo: message has changed
                        // Whether or not to create a new revision when setting 
this state
                        'new-revision' => false,
                        // i18n key for history and recentchanges
@@ -57,10 +44,6 @@
                self::MODERATED_CENSORED => array(
                        // The permission needed from User::isAllowed to see 
and create new revisions
                        'perm' => 'flow-censor',
-                       // i18n key to replace content with when state is active
-                       'content' => 'flow-post-censored-by',
-                       // This is the bit of text rendered instead of the post 
creator
-                       'usertext' => 'flow-rev-message-censored-post', // 
@todo: message has changed
                        // Whether or not to create a new revision when setting 
this state
                        'new-revision' => false,
                        // i18n key for history and recentchanges
@@ -278,28 +261,6 @@
                return $this->moderationState === self::MODERATED_HIDDEN;
        }
 
-       public function getHiddenContent( $format ) {
-               if ( $this->hasHiddenContent() ) {
-                       return $this->getConvertedContent( $format );
-               }
-               return '';
-       }
-
-       public function getContent( $user = null, $format = 'html' ) {
-               if ( $this->isAllowed( $user ) ) {
-                       return $this->getConvertedContent( $format );
-               } else {
-                       $moderatedAt = new MWTimestamp( 
$this->moderationTimestamp );
-
-                       // Messages: flow-post-hidden-by, flow-post-deleted-by, 
flow-post-censored-by
-                       return wfMessage(
-                               self::$perms[$this->moderationState]['content'],
-                               $this->moderatedByUserText,
-                               $moderatedAt->getHumanTimestamp()
-                       );
-               }
-       }
-
        public function getContentRaw() {
                if ( $this->decompressedContent === null ) {
                        $this->decompressedContent = 
\Revision::decompressRevisionText( $this->content, $this->flags );
@@ -308,7 +269,15 @@
                return $this->decompressedContent;
        }
 
-       public function getConvertedContent( $format = 'html' ) {
+       /**
+        * DO NOT USE THIS METHOD to output the content; use
+        * Templating::getContent, which will do additional (permissions-based)
+        * checks to make sure it outputs something the user can see.
+        *
+        * @param string[optional] $format Format to output content in 
(html|wikitext)
+        * @return string
+        */
+       public function getContent( $format = 'html' ) {
                if ( !isset( $this->convertedContent[$format] ) ) {
                        // check how content is stored & convert to requested 
format
                        $sourceFormat = in_array( 'html', $this->flags ) ? 
'html' : 'wikitext';
@@ -322,17 +291,14 @@
                return $this->userId;
        }
 
-       public function getUserText( $user = null ) {
-               // The text of *this* revision is only stripped when fully 
moderated
-               if ( $this->isCensored() ) {
-                       // Messages: flow-post-hidden, flow-post-deleted, 
flow-post-censored
-                       return wfMessage( 
self::$perms[$this->moderationState]['usertext'] );
-               } else {
-                       return $this->getUserTextRaw();
-               }
-       }
-
-       public function getUserTextRaw() {
+       /**
+        * DO NOT USE THIS METHOD to output the username; use
+        * Templating::getUserText, which will do additional (permissions-based)
+        * checks to make sure it outputs something the user can see.
+        *
+        * @return string
+        */
+       public function getUserText() {
                return $this->userText;
        }
 
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index 6891779..6309258 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -149,7 +149,7 @@
                                'board-workflow' => $boardWorkflow->getId(),
                                'topic-workflow' => $topicWorkflow->getId(),
                                'post-id' => $firstPost ? 
$firstPost->getRevisionId() : null,
-                               'topic-title' => $topicPost->getContentRaw(),
+                               'topic-title' => $topicPost->getContent(),
                                'content' => $firstPost ? 
$firstPost->getContent() : null,
                        )
                ) );
@@ -159,7 +159,7 @@
                                'title' => $boardWorkflow->getArticleTitle(),
                                'user' => $user,
                                'post' => $firstPost,
-                               'topic-title' => $topicPost->getContentRaw(),
+                               'topic-title' => $topicPost->getContent(),
                                'topic-workflow' => $topicWorkflow,
                        ) )
                );
@@ -214,7 +214,7 @@
                // At the moment, it is not possible to get a list of mentioned 
users from HTML
                //  unless that HTML comes from Parsoid. But VisualEditor (what 
is currently used
                //  to convert wikitext to HTML) does not currently use Parsoid.
-               $wikitext = $post->getContent( null, 'wikitext' );
+               $wikitext = $post->getContent( 'wikitext' );
                $mentions = $this->getMentionedUsersFromWikitext( $wikitext );
                $notifyUsers = $this->filterMentionedUsers( $mentions, $post, 
$title );
 
diff --git a/includes/RecentChanges/Formatter.php 
b/includes/RecentChanges/Formatter.php
index 037bc7c..9b8b657 100644
--- a/includes/RecentChanges/Formatter.php
+++ b/includes/RecentChanges/Formatter.php
@@ -6,8 +6,9 @@
 use Flow\Data\ManagerGroup;
 use Flow\FlowActions;
 use Flow\Model\UUID;
-use Flow\UrlGenerator;
 use ChangesList;
+use Flow\Templating;
+use Flow\UrlGenerator;
 use Flow\WorkflowLoaderFactory;
 use Language;
 use Linker;
@@ -33,7 +34,12 @@
        protected $actions;
 
        /**
-        * @var UrlGenerator
+        * @var Templating
+        */
+       protected $templating;
+
+       /**
+        * @var UrlGenerator;
         */
        protected $urlGenerator;
 
@@ -42,12 +48,21 @@
         */
        protected $lang;
 
-       public function __construct( ManagerGroup $storage, 
WorkflowLoaderFactory $workflowLoaderFactory, FlowActions $actions, 
UrlGenerator $urlGenerator, Language $lang ) {
+       /**
+        * @param ManagerGroup $storage
+        * @param WorkflowLoaderFactory $workflowLoaderFactory
+        * @param FlowActions $actions
+        * @param Templating $templating
+        * @param Language $lang
+        */
+       public function __construct( ManagerGroup $storage, 
WorkflowLoaderFactory $workflowLoaderFactory, FlowActions $actions, Templating 
$templating, Language $lang ) {
                $this->actions = $actions;
                $this->storage = $storage;
                $this->workflowLoaderFactory = $workflowLoaderFactory;
-               $this->urlGenerator = $urlGenerator;
+               $this->templating = $templating;
                $this->lang = $lang;
+
+               $this->urlGenerator = $this->templating->getUrlGenerator();
        }
 
        public function format( ChangesList $cl, RecentChange $rc ) {
@@ -250,7 +265,7 @@
                $params = $this->actions->getValue( $changeData['action'], 
'history', 'i18n-params' );
                return $this->buildMessage( $msg, (array) $params, array(
                        $revision,
-                       $this->urlGenerator,
+                       $this->templating,
                        $cl->getUser(),
                        $block
                ) )->parse();
diff --git a/includes/Templating.php b/includes/Templating.php
index 387504e..c5c96bc 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -4,6 +4,7 @@
 
 use Flow\Block\Block;
 use Flow\Block\TopicBlock;
+use Flow\Model\AbstractRevision;
 use Flow\Model\PostRevision;
 use Flow\Model\UUID;
 use Flow\Model\Workflow;
@@ -212,4 +213,62 @@
                        $secondMostRecentPoster
                )->parse();
        }
+
+       /**
+        * Formats a revision's usertext for displaying. Usually, the revision's
+        * usertext can just be displayed. In the event of moderation, however, 
that
+        * info should not be exposed.
+        *
+        * If a specific i18n message is available for a certain moderation 
level,
+        * that message will be returned (well, unless the user actually has the
+        * required permissions to view the full username). Otherwise, in normal
+        * cases, the full username will be returned.
+        *
+        * @param AbstractRevision $revision Revision to display usertext for
+        * @param User[optional] $permissionsUser User to display usertext to
+        * @return string
+        */
+       public function getUserText( AbstractRevision $revision, User 
$permissionsUser = null ) {
+               $state = $revision->getModerationState();
+               $username = $revision->getUserText();
+
+               // Messages: flow-hide-usertext, flow-delete-usertext, 
flow-censor-usertext
+               $message = wfMessage( "flow-$state-usertext", $username );
+
+               if ( !$revision->isAllowed( $permissionsUser ) && 
$message->exists() ) {
+                       return $message->text();
+               } else {
+                       return $username;
+               }
+       }
+
+       /**
+        * Formats a revision's content for displaying. Usually, the revisions's
+        * content can just be displayed. In the event of moderation, however, 
that
+        * info should not be exposed.
+        *
+        * If a specific i18n message is available for a certain moderation 
level,
+        * that message will be returned (well, unless the user actually has the
+        * required permissions to view the full content). Otherwise, in normal
+        * cases, the full content will be returned.
+        *
+        * @param AbstractRevision $revision Revision to display content for
+        * @param string[optional] $format Format to output content in 
(html|wikitext)
+        * @param User[optional] $permissionsUser User to display content to
+        * @return string
+        */
+       public function getContent( AbstractRevision $revision, $format = 
'html', User $permissionsUser = null ) {
+               $state = $revision->getModerationState();
+               $user = $revision->getModeratedByUserText();
+               $moderatedAt = new MWTimestamp( 
$revision->getModerationTimestamp() );
+
+               // Messages: flow-hide-content, flow-delete-content, 
flow-censor-content
+               $message = wfMessage( "flow-$state-content", $user, 
$moderatedAt->getHumanTimestamp() );
+
+               if ( !$revision->isAllowed( $permissionsUser ) && 
$message->exists() ) {
+                       return $message->text();
+               } else {
+                       return $revision->getContent( $format );
+               }
+       }
 }
diff --git a/includes/View/History/HistoryRenderer.php 
b/includes/View/History/HistoryRenderer.php
index c1b11c4..7ffe622 100644
--- a/includes/View/History/HistoryRenderer.php
+++ b/includes/View/History/HistoryRenderer.php
@@ -146,7 +146,7 @@
                        'message' => $record->getMessage(
                                // Arguments for the i18n messages' parameter 
callbacks.
                                $record->getData(),
-                               $this->templating->getUrlGenerator(),
+                               $this->templating,
                                $wgUser,
                                $this->block
                        ),
diff --git a/templates/edit-header.html.php b/templates/edit-header.html.php
index 0492f1f..47ac81d 100644
--- a/templates/edit-header.html.php
+++ b/templates/edit-header.html.php
@@ -26,7 +26,7 @@
 
 echo Html::textarea(
        $block->getName() . '[content]',
-       $header ? $header->getContent( $user, 'wikitext' ) : '',
+       $header ? $this->getContent( $header, 'wikitext', $user ) : '',
        array(
                'class' => 'mw-ui-input',
                'data-header-id' => $header ? 
$header->getRevisionId()->getHex() : ''
diff --git a/templates/edit-post.html.php b/templates/edit-post.html.php
index 32758da..479141a 100644
--- a/templates/edit-post.html.php
+++ b/templates/edit-post.html.php
@@ -22,7 +22,7 @@
                'name' => $block->getName() . '[postId]',
                'value' => $post->getPostId()->getHex(),
        ) ),
-       Html::textarea( $block->getName() . '[content]', $post->getContent( 
$user, 'wikitext' ) ),
+       Html::textarea( $block->getName() . '[content]', $this->getContent( 
$post, 'wikitext', $user ) ),
        Html::element( 'input', array(
                'type' => 'submit',
                'class' => 'mw-ui-button mw-ui-primary',
diff --git a/templates/edit-title.html.php b/templates/edit-title.html.php
index 34d6529..60143f2 100644
--- a/templates/edit-title.html.php
+++ b/templates/edit-title.html.php
@@ -15,7 +15,7 @@
                'action' => $this->generateUrl( $topicTitle->getPostId(), 
'edit-title' ),
        ) ),
        Html::element( 'input', array( 'type' => 'hidden', 'name' => 
'wpEditToken', 'value' => $editToken ) ),
-               Html::textarea( $block->getName() . '[content]', 
$topicTitle->getContent( $user, 'wikitext' ) ),
+               Html::textarea( $block->getName() . '[content]', 
$this->getContent( $topicTitlex, 'wikitext', $topicTitle ) ),
                Html::element( 'input',
                        array(
                                'type' => 'submit',
diff --git a/templates/header.html.php b/templates/header.html.php
index b46ab04..abe61a5 100644
--- a/templates/header.html.php
+++ b/templates/header.html.php
@@ -16,7 +16,7 @@
 }
 
 if ( $header ) {
-       $headerContent = $header->getContent( $user, 'html' );
+       $headerContent = $this->getContent( $header, 'html', $user );
        $class = 'flow-header-exists';
 } else {
        $headerContent = wfMessage( 'flow-header-empty' )->parse();
diff --git a/templates/post-history.html.php b/templates/post-history.html.php
index f8bc4a9..59a521a 100644
--- a/templates/post-history.html.php
+++ b/templates/post-history.html.php
@@ -1,6 +1,6 @@
 <?php
 
-$topicTitle = $root->getContent( $user, 'wikitext' );
+$topicTitle = $this->getContent( $root, 'wikitext', $user );
 $topicLink = $this->generateUrl( $topic );
 
 $creator = $post->getCreatorName();
diff --git a/templates/post.html.php b/templates/post.html.php
index 4fd1958..2d98357 100644
--- a/templates/post.html.php
+++ b/templates/post.html.php
@@ -7,7 +7,7 @@
        $replyForm .= '
                <span class="flow-creator">
                        <span class="flow-creator-simple" style="display: 
inline">
-                               ' .$this->getUserText( $user ) . '
+                               ' . htmlentities( $user->getName() ) . '
                        </span>
                        <span class="flow-creator-full" style="display: none">
                                ' . $this->userToolLinks( $user->getId(), 
$user->getName() ) .'
@@ -68,9 +68,9 @@
                        <p class="flow-post-moderated-message 
flow-post-moderated-<?php echo $post->getModerationState(); ?> 
flow-post-content-<?php echo $post->isAllowed( $user ) ? 'allowed' : 
'disallowed'; ?>">
                        <?php
                                // passing in null as user (unprivileged) will 
get the "hidden/deleted/suppressed by XYZ" text
-                               echo $post->getContent( null );
+                               echo $this->getContent( $post, 'html', null );
                        ?>
-               </p>
+                       </p>
                <?php endif; ?>
 
                <div class="flow-post-main">
@@ -86,7 +86,7 @@
                        </div>
 
                        <div class="flow-post-content">
-                               <?php echo $post->getContent( $user, 'html' ); 
?>
+                               <?php echo $this->getContent( $post, 'html', 
$user ); ?>
                        </div>
 
                        <?php echo $postView->editPostButton( $post, 
'flow-edit-post-link flow-icon flow-icon-bottom-aligned' ); ?>
diff --git a/templates/topic-history.html.php b/templates/topic-history.html.php
index 3151dee..299522d 100644
--- a/templates/topic-history.html.php
+++ b/templates/topic-history.html.php
@@ -4,7 +4,7 @@
 $pageLink = $this->urlGenerator->buildUrl( $pageTitle, 'view' );
 $pageTitle = $pageTitle->getText();
 
-$title = $root->getContent( $user, 'wikitext' );
+$title = $this->getContent( $root, 'wikitext', $user );
 $title = wfMessage( 'flow-topic-history', $title )->escaped();
 $this->getOutput()->setHtmlTitle( $title );
 $this->getOutput()->setPageTitle( $title );
diff --git a/templates/topic.html.php b/templates/topic.html.php
index 59360d3..1870346 100644
--- a/templates/topic.html.php
+++ b/templates/topic.html.php
@@ -1,7 +1,7 @@
 <?php
 
 // treat title like unparsed (wiki)text
-$title = $root->getContent( $user, 'wikitext' );
+$title = $this->getContent( $root, 'wikitext', $user );
 
 // pre-register recursive callbacks; will then be fetched all at once when the
 // first one's result is requested

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie42a5b1c6efd618a5bd2fa1e7ac43316c239cb50
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Werdna <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to