Cicalese has submitted this change and it was merged. Change subject: Fixed avatar bug plus two new features. ......................................................................
Fixed avatar bug plus two new features. Added DISPLAYTITLE option for user real name. Added <comment-streams-initially-collapsed> tag function. Change-Id: I774b94072f1d3cb42d1f5a6810c7975761eb7b45 --- M includes/Comment.php M includes/CommentStreams.php M includes/CommentStreamsHooks.php 3 files changed, 71 insertions(+), 19 deletions(-) Approvals: Cicalese: Verified; Looks good to me, approved diff --git a/includes/Comment.php b/includes/Comment.php index 698b5b3..bb3c8c6 100644 --- a/includes/Comment.php +++ b/includes/Comment.php @@ -552,10 +552,20 @@ * @return string display name for user */ public static function getDisplayNameFromUser( $user ) { + $userpage = $user->getUserPage(); $displayname = null; if ( !is_null( $GLOBALS['wgCommentStreamsUserRealNamePropertyName'] ) ) { $displayname = self::getUserProperty( $user, $GLOBALS['wgCommentStreamsUserRealNamePropertyName'] ); + } + if ( is_null( $displayname ) || strlen( $displayname ) == 0 ) { + if ( class_exists( 'PageProps' ) ) { + $values = PageProps::getInstance()->getProperties( $userpage, + 'displaytitle' ); + } + if ( array_key_exists( $userpage->getArticleID(), $values ) ) { + $displayname = $values[$userpage->getArticleID()]; + } } if ( is_null( $displayname ) || strlen( $displayname ) == 0 ) { $displayname = $user->getRealName(); @@ -563,7 +573,6 @@ if ( is_null( $displayname ) || strlen( $displayname ) == 0 ) { $displayname = $user->getName(); } - $userpage = $user->getUserPage(); if ( $userpage->exists() ) { $displayname = Linker::link( $userpage, $displayname ); } @@ -585,11 +594,11 @@ if ( gettype( $avatar ) === 'string' ) { $avatar = Title::newFromText( $avatar ); if ( is_null( $avatar ) ) { - return false; + return null; } } if ( !get_class( $avatar ) === 'Title' ) { - return false; + return null; } if ( $avatar->isKnown() && $avatar->getNamespace() === NS_FILE ) { $file = wfFindFile( $avatar ); diff --git a/includes/CommentStreams.php b/includes/CommentStreams.php index 6dd5326..f29603b 100644 --- a/includes/CommentStreams.php +++ b/includes/CommentStreams.php @@ -38,14 +38,25 @@ return self::$instance; } + // no CommentStreams flag private $noCommentStreams = false; /** * disables the display of comments on the current page - * by default, a warning message is displayed instead */ public function disableCommentsOnPage() { $this->noCommentStreams = true; + } + + // initially collapse CommentStreams flag + private $initiallyCollapseCommentStreams = false; + + /** + * makes the comments appear initially collapsed when the current page + * is viewed + */ + public function initiallyCollapseCommentsOnPage() { + $this->initiallyCollapseCommentStreams = true; } /** @@ -154,8 +165,13 @@ if ( $title->isTalkPage() ) { $namespace = MWNamespace::getSubject( $namespace ); } - $initiallyCollapsed = in_array( $namespace, - $GLOBALS['wgCommentStreamsInitiallyCollapsedNamespaces'] ); + + if ( $this->initiallyCollapseCommentStreams ) { + $initiallyCollapsed = true; + } else { + $initiallyCollapsed = in_array( $namespace, + $GLOBALS['wgCommentStreamsInitiallyCollapsedNamespaces'] ); + } $commentStreamsParams = [ 'userDisplayName' => diff --git a/includes/CommentStreamsHooks.php b/includes/CommentStreamsHooks.php index 6a8e2a6..cfec455 100644 --- a/includes/CommentStreamsHooks.php +++ b/includes/CommentStreamsHooks.php @@ -167,7 +167,8 @@ /** * Implements ParserFirstCallInit hook. * See https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit - * Adds no-comment-streams magic word. + * Adds no-comment-streams and comment-streams-initially-collapsed magic + * words. * * @param Parser $parser the parser * @return bool continue checking hooks @@ -175,11 +176,13 @@ public static function onParserSetup( Parser $parser ) { $parser->setHook( 'no-comment-streams', 'CommentStreamsHooks::hideCommentStreams' ); + $parser->setHook( 'comment-streams-initially-collapsed', + 'CommentStreamsHooks::initiallyCollapseCommentStreams' ); return true; } /** - * Implements tag function, <no-comment-streams \>, which disables + * Implements tag function, <no-comment-streams/>, which disables * CommentStreams on a page. * * @param string $input input between the tags (ignored) @@ -193,6 +196,24 @@ $parser->disableCache(); $cs = CommentStreams::singleton(); $cs->disableCommentsOnPage(); + return ""; + } + + /** + * Implements tag function, <comment-streams-initially-collapsed/>, which + * makes CommentStreams on a page start as collapsed when the page is viewed. + * + * @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 initiallyCollapseCommentStreams( $input, array $args, + Parser $parser, PPFrame $frame ) { + $parser->disableCache(); + $cs = CommentStreams::singleton(); + $cs->initiallyCollapseCommentsOnPage(); return ""; } @@ -278,24 +299,30 @@ $wikipage = WikiPage::newFromId( $page_id ); $comment = Comment::newFromWikiPage( $wikipage ); - $assoc_page_id = $comment->getAssociatedId(); - if ( is_null( $assoc_page_id ) ) { + if ( is_null( $comment ) ) { return true; } - $assoc_wikipage = WikiPage::newFromId( $assoc_page_id ); - $propertyDI = new SMW\DIProperty( '___CS_ASSOCPG' ); - $dataItem = - SMW\DIWikiPage::newFromTitle( $assoc_wikipage->getTitle() ); - $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); + $assoc_page_id = $comment->getAssociatedId(); + if ( !is_null( $assoc_page_id ) ) { + $assoc_wikipage = WikiPage::newFromId( $assoc_page_id ); + if ( !is_null( $assoc_wikipage ) ) { + $propertyDI = new SMW\DIProperty( '___CS_ASSOCPG' ); + $dataItem = + SMW\DIWikiPage::newFromTitle( $assoc_wikipage->getTitle() ); + $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); + } + } $parent_page_id = $comment->getParentId(); if ( !is_null( $parent_page_id ) ) { $parent_wikipage = WikiPage::newFromId( $parent_page_id ); - $propertyDI = new SMW\DIProperty( '___CS_REPLYTO' ); - $dataItem = - SMW\DIWikiPage::newFromTitle( $parent_wikipage->getTitle() ); - $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); + if ( !is_null( $parent_wikipage ) ) { + $propertyDI = new SMW\DIProperty( '___CS_REPLYTO' ); + $dataItem = + SMW\DIWikiPage::newFromTitle( $parent_wikipage->getTitle() ); + $semanticData->addPropertyObjectValue( $propertyDI, $dataItem ); + } } $commentTitle = $comment->getCommentTitle(); -- To view, visit https://gerrit.wikimedia.org/r/321682 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I774b94072f1d3cb42d1f5a6810c7975761eb7b45 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CommentStreams Gerrit-Branch: master Gerrit-Owner: Cicalese <cical...@mitre.org> Gerrit-Reviewer: Cicalese <cical...@mitre.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits