Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93953
Change subject: Move output functionality from AbstractRevision to Templating
......................................................................
Move output functionality from AbstractRevision to Templating
AbstractRevision::getUserText() & ::getContent() had some functionality that
didnot 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 FlowActions.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/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
17 files changed, 180 insertions(+), 148 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/53/93953/1
diff --git a/Flow.i18n.php b/Flow.i18n.php
index a61f185..8392119 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' => '[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/FlowActions.php b/FlowActions.php
index ad54194..645fee0 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -3,8 +3,8 @@
use Flow\Model\PostRevision;
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.
@@ -37,8 +37,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',
@@ -58,8 +58,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',
@@ -75,20 +75,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 '';
@@ -105,14 +105,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',
@@ -131,12 +131,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',
@@ -155,15 +155,15 @@
'history' => array(
'i18n-message' => 'flow-rev-message-hid-post',
'i18n-params' => array(
- function ( PostRevision $revision, UrlGenerator
$urlGenerator, User $user, Block $block ) {
+ function ( PostRevision $revision, Templating
$templating, User $user, Block $block ) {
return
$revision->getModeratedByUserText();
},
- 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',
@@ -180,15 +180,15 @@
'history' => array(
'i18n-message' => 'flow-rev-message-deleted-post',
'i18n-params' => array(
- function ( PostRevision $revision, UrlGenerator
$urlGenerator, User $user, Block $block ) {
+ function ( PostRevision $revision, Templating
$templating, User $user, Block $block ) {
return
$revision->getModeratedByUserText();
},
- 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',
@@ -206,15 +206,15 @@
'history' => array(
'i18n-message' => 'flow-rev-message-censored-post',
'i18n-params' => array(
- function ( PostRevision $revision, UrlGenerator
$urlGenerator, User $user, Block $block ) {
+ function ( PostRevision $revision, Templating
$templating, User $user, Block $block ) {
return
$revision->getModeratedByUserText();
},
- 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',
@@ -238,15 +238,17 @@
'history' => array(
'i18n-message' => 'flow-rev-message-restored-post',
'i18n-params' => array(
- function ( PostRevision $revision, UrlGenerator
$urlGenerator, User $user, Block $block ) {
- return
$revision->getModeratedByUserText();
+ function ( PostRevision $revision, Templating
$templating, User $user, Block $block ) {
+ // moderatedByUserText is null for
restored (because that
+ // actually reverts any moderation to
MODERATED_NONE)
+ 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',
@@ -285,19 +287,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/includes/Block/Header.php b/includes/Block/Header.php
index 61e4345..f3cd387 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -75,9 +75,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;
@@ -127,7 +132,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 1fcd240..0961398 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 6fa7fa8..859e909 100644
--- a/includes/Data/RecentChanges.php
+++ b/includes/Data/RecentChanges.php
@@ -136,7 +136,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 ) {
@@ -151,7 +151,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 69bd811..b7f12e1 100644
--- a/includes/Model/AbstractRevision.php
+++ b/includes/Model/AbstractRevision.php
@@ -20,10 +20,6 @@
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/Templating.php b/includes/Templating.php
index d126138..9569ce0 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;
@@ -205,4 +206,62 @@
$secondMostRecentPoster
)->parse();
}
+
+ /**
+ * Formats a post's usertext for displaying. Usually, the post'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 $post Post to display usertext for
+ * @param User[optional] $permissionsUser User to display usertext to
+ * @return string
+ */
+ public function getUserText( AbstractRevision $post, User
$permissionsUser = null ) {
+ $state = $post->getModerationState();
+ $username = $post->getUserText();
+
+ // Messages: flow-hide-usertext, flow-delete-usertext,
flow-censor-usertext
+ $message = wfMessage( "flow-$state-usertext", $username );
+
+ if ( !$post->isAllowed( $permissionsUser ) &&
$message->exists() ) {
+ return $message->text();
+ } else {
+ return $username;
+ }
+ }
+
+ /**
+ * Formats a post's content for displaying. Usually, the post'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 $post Post 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 $post, $format = 'html',
User $permissionsUser = null ) {
+ $state = $post->getModerationState();
+ $user = $post->getModeratedByUserText();
+ $moderatedAt = new MWTimestamp( $post->getModerationTimestamp()
);
+
+ // Messages: flow-hide-content, flow-delete-content,
flow-censor-content
+ $message = wfMessage( "flow-$state-content", $user,
$moderatedAt->getHumanTimestamp() );
+
+ if ( !$post->isAllowed( $permissionsUser ) &&
$message->exists() ) {
+ return $message->text();
+ } else {
+ return $post->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 5b125aa..64b7cdd 100644
--- a/templates/post.html.php
+++ b/templates/post.html.php
@@ -54,9 +54,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">
@@ -72,7 +72,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 944b606..6bcf08e 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: newchange
Gerrit-Change-Id: Ie42a5b1c6efd618a5bd2fa1e7ac43316c239cb50
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits