diff options
author | Brian Evans <grknight@gentoo.org> | 2018-12-20 10:18:48 -0500 |
---|---|---|
committer | Brian Evans <grknight@gentoo.org> | 2018-12-20 10:27:40 -0500 |
commit | 60a7a4ed4faed4de6d248dd6ca92070a902baab8 (patch) | |
tree | 2c7a391650e2bc5168579f073fe6caed8f589551 /CommentStreams | |
parent | Add CommentStreams (diff) | |
download | extensions-60a7a4ed4faed4de6d248dd6ca92070a902baab8.tar.gz extensions-60a7a4ed4faed4de6d248dd6ca92070a902baab8.tar.bz2 extensions-60a7a4ed4faed4de6d248dd6ca92070a902baab8.zip |
CommentStreams: backport enable tag code
Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'CommentStreams')
-rw-r--r-- | CommentStreams/includes/CommentStreams.php | 56 | ||||
-rw-r--r-- | CommentStreams/includes/CommentStreamsHooks.php | 25 |
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. * |