summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CommentStreams')
-rw-r--r--CommentStreams/includes/CommentStreams.php56
-rw-r--r--CommentStreams/includes/CommentStreamsHooks.php25
2 files changed, 65 insertions, 16 deletions
diff --git a/CommentStreams/includes/CommentStreams.php b/CommentStreams/includes/CommentStreams.php
index 07d4e4a2..3954dc19 100644
--- a/CommentStreams/includes/CommentStreams.php
+++ b/CommentStreams/includes/CommentStreams.php
@@ -26,6 +26,13 @@ class CommentStreams {
// CommentStreams singleton instance
private static $instance = null;
+ const COMMENTS_ENABLED = 1;
+ const COMMENTS_DISABLED = -1;
+ const COMMENTS_INHERITED = 0;
+
+ // no CommentStreams flag
+ private $areCommentsEnabled = self::COMMENTS_INHERITED;
+
/**
* create a CommentStreams singleton instance
*
@@ -38,14 +45,18 @@ class CommentStreams {
return self::$instance;
}
- // no CommentStreams flag
- private $noCommentStreams = false;
+ /**
+ * enables the display of comments on the current page
+ */
+ public function enableCommentsOnPage() {
+ $this->areCommentsEnabled = self::COMMENTS_ENABLED;
+ }
/**
* disables the display of comments on the current page
*/
public function disableCommentsOnPage() {
- $this->noCommentStreams = true;
+ $this->areCommentsEnabled = self::COMMENTS_DISABLED;
}
// initially collapse CommentStreams flag
@@ -79,7 +90,7 @@ class CommentStreams {
*/
private function checkDisplayComments( $output ) {
// don't display comments on this page if they are explicitly disabled
- if ( $this->noCommentStreams ) {
+ if ( $this->areCommentsEnabled === self::COMMENTS_DISABLED ) {
return false;
}
@@ -97,12 +108,35 @@ class CommentStreams {
$csAllowedNamespaces = [ $csAllowedNamespaces ];
}
+ $title = $output->getTitle();
+ $namespace = $title->getNamespace();
+
+ // don't display comments in CommentStreams namespace
+ if ( $namespace === NS_COMMENTSTREAMS ) {
+ return false;
+ }
+
+ // don't display comments on pages that do not exist
+ if ( !$title->exists() ) {
+ return false;
+ }
+
+ // don't display comments on redirect pages
+ if ( $title->isRedirect() ) {
+ return false;
+ }
+
+ // display comments on this page if they are explicitly enabled
+ if ( $this->areCommentsEnabled === self::COMMENTS_ENABLED ) {
+ return true;
+ }
+
// don't display comments in a talk namespace unless:
// 1) $wgCommentStreamsEnableTalk is true, OR
// 2) the namespace is a talk namespace for a namespace in the array of
// allowed namespaces
- $title = $output->getTitle();
- $namespace = $title->getNamespace();
+ // 3) comments have been explicitly enabled on that namespace with
+ // <comment-streams/>
if ( $title->isTalkPage() ) {
$subject_namespace = MWNamespace::getSubject( $namespace );
if ( !$GLOBALS['wgCommentStreamsEnableTalk'] &&
@@ -113,16 +147,6 @@ class CommentStreams {
return false;
}
- // don't display comments in CommentStreams namespace
- if ( $namespace === NS_COMMENTSTREAMS ) {
- return false;
- }
-
- // don't display comments on pages that do not exist
- if ( !$title->exists() ) {
- return false;
- }
-
return true;
}
diff --git a/CommentStreams/includes/CommentStreamsHooks.php b/CommentStreams/includes/CommentStreamsHooks.php
index ab21cbd9..42a9ed6e 100644
--- a/CommentStreams/includes/CommentStreamsHooks.php
+++ b/CommentStreams/includes/CommentStreamsHooks.php
@@ -203,6 +203,8 @@ class CommentStreamsHooks {
* @return bool continue checking hooks
*/
public static function onParserSetup( Parser $parser ) {
+ $parser->setHook( 'comment-streams',
+ 'CommentStreamsHooks::enableCommentStreams' );
$parser->setHook( 'no-comment-streams',
'CommentStreamsHooks::hideCommentStreams' );
$parser->setHook( 'comment-streams-initially-collapsed',
@@ -211,6 +213,29 @@ class CommentStreamsHooks {
}
/**
+ * Implements tag function, <comment-streams/>, which enables
+ * CommentStreams on a page.
+ *
+ * @param string $input input between the tags (ignored)
+ * @param array $args tag arguments
+ * @param Parser $parser the parser
+ * @param PPFrame $frame the parent frame
+ * @return string to replace tag with
+ */
+ public static function enableCommentStreams( $input, array $args,
+ Parser $parser, PPFrame $frame ) {
+ $parser->disableCache();
+ $cs = CommentStreams::singleton();
+ $cs->enableCommentsOnPage();
+ if ( isset( $args['location'] ) && $args['location'] === 'footer' ) {
+ $ret = '';
+ } else {
+ $ret = '<div id="cs-comments"></div>';
+ }
+ return $ret;
+ }
+
+ /**
* Implements tag function, <no-comment-streams/>, which disables
* CommentStreams on a page.
*