Cicalese has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/405394 )
Change subject: Fix Special:AllComments, add optional button label, formatting ...................................................................... Fix Special:AllComments, add optional button label, formatting Bug:T184731 Bug:T175855 Change-Id: Ie4b4965a4a1df77d3135c8b4b897243617cafa40 --- A .phpcs.xml M composer.json M extension.json M i18n/en.json M i18n/qqq.json M includes/ApiCSBase.php M includes/ApiCSDeleteComment.php M includes/ApiCSPostComment.php M includes/Comment.php M includes/CommentStreams.php M includes/CommentStreamsAllComments.php M includes/CommentStreamsHooks.php M includes/EchoCSPresentationModel.php M resources/CommentStreams.css M resources/CommentStreams.js 15 files changed, 106 insertions(+), 69 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommentStreams refs/changes/94/405394/1 diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..b0464c3 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> + </rule> + <file>.</file> + <arg name="extensions" value="php,php5,inc" /> + <arg name="encoding" value="UTF-8" /> +</ruleset> diff --git a/composer.json b/composer.json index 7d306d5..182cb75 100644 --- a/composer.json +++ b/composer.json @@ -2,14 +2,17 @@ "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", "jakub-onderka/php-console-highlighter": "0.3.2", + "mediawiki/mediawiki-codesniffer": "^15.0", "mediawiki/minus-x": "0.2.1" }, "scripts": { "test": [ "parallel-lint . --exclude vendor --exclude node_modules", + "phpcs -p -s", "minus-x check ." ], "fix": [ + "phpcbf", "minus-x fix ." ] } diff --git a/extension.json b/extension.json index 23f6d2b..024b33f 100644 --- a/extension.json +++ b/extension.json @@ -67,6 +67,8 @@ "commentstreams-api-error-unwatch", "commentstreams-validation-error-nocommenttitle", "commentstreams-validation-error-nocommenttext", + "commentstreams-buttontext-add", + "commentstreams-buttontext-reply", "commentstreams-buttontooltip-add", "commentstreams-buttontooltip-reply", "commentstreams-buttontooltip-edit", @@ -154,6 +156,7 @@ "CommentStreamsEnableTalk": false, "CommentStreamsNewestStreamsOnTop": true, "CommentStreamsModeratorFastDelete": false, + "CommentStreamsShowLabels": true, "CommentStreamsEnableVoting": false, "CommentStreamsInitiallyCollapsedNamespaces" : [], "CommentStreamsUserRealNamePropertyName" : null, diff --git a/i18n/en.json b/i18n/en.json index 501fac6..22c2842 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -80,6 +80,8 @@ "commentstreams-api-error-unwatch": "Error unwatching comment.", "commentstreams-validation-error-nocommenttitle": "You must enter a comment title.", "commentstreams-validation-error-nocommenttext": "You must enter comment text.", + "commentstreams-buttontext-add": "ADD A COMMENT", + "commentstreams-buttontext-reply": "REPLY", "commentstreams-buttontooltip-add": "add a comment", "commentstreams-buttontooltip-reply": "reply", "commentstreams-buttontooltip-edit": "edit", diff --git a/i18n/qqq.json b/i18n/qqq.json index 113c5bc..bfaf1d4 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -82,6 +82,8 @@ "commentstreams-api-error-unwatch": "Error message.", "commentstreams-validation-error-nocommenttitle": "Error message.", "commentstreams-validation-error-nocommenttext": "Error message.", + "commentstreams-buttontext-add": "User interface button label. Upper case for stylistic reasons.", + "commentstreams-buttontext-reply": "User interface button label. Upper case for stylistic reasons.", "commentstreams-buttontooltip-add": "User interface button tooltip.", "commentstreams-buttontooltip-reply": "User interface button tooltip.\n{{Identical|Reply}}", "commentstreams-buttontooltip-edit": "User interface button tooltip.\n{{Identical|Edit}}", diff --git a/includes/ApiCSBase.php b/includes/ApiCSBase.php index 78ac2e2..e524e97 100644 --- a/includes/ApiCSBase.php +++ b/includes/ApiCSBase.php @@ -29,7 +29,7 @@ /** * @param ApiMain $main main module * @param string $action name of this module - * @param boolean $edit whether this API module will be editing the database + * @param bool $edit whether this API module will be editing the database */ public function __construct( $main, $action, $edit = false ) { parent::__construct( $main, $action ); @@ -56,7 +56,7 @@ /** * the real body of the execute function */ - protected abstract function executeBody(); + abstract protected function executeBody(); /** * @return array allowed parameters @@ -100,6 +100,8 @@ /** * log action * @param string $action the name of the action to be logged + * @param string|null $title the title of the page for the comment that the + * action was performed upon, if differen from the current comment */ protected function logAction( $action, $title = null ) { $logEntry = new ManualLogEntry( 'commentstreams', $action ); diff --git a/includes/ApiCSDeleteComment.php b/includes/ApiCSDeleteComment.php index 84c1d52..7609e2e 100644 --- a/includes/ApiCSDeleteComment.php +++ b/includes/ApiCSDeleteComment.php @@ -105,9 +105,9 @@ $result = $comment->delete(); $title = $comment->getWikiPage()->getTitle(); if ( is_null( $comment->getParentId() ) ) { - $this->logAction( 'comment-moderator-delete', $title ); + $this->logAction( 'comment-moderator-delete', $title ); } else { - $this->logAction( 'reply-moderator-delete', $title ); + $this->logAction( 'reply-moderator-delete', $title ); } return $result; } diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php index 34c78de..77b6a91 100644 --- a/includes/ApiCSPostComment.php +++ b/includes/ApiCSPostComment.php @@ -63,7 +63,7 @@ 'commentstreams-api-error-post-parentpagedoesnotexist' ); } $parent_comment = Comment::newFromWikiPage( $parent_page ); - if ( $parent_comment->getAssociatedId() !== (integer)$associatedid ) { + if ( $parent_comment->getAssociatedId() !== (int)$associatedid ) { $this->dieCustomUsageMessage( 'commentstreams-api-error-post-associatedpageidmismatch' ); } @@ -205,6 +205,8 @@ /** * log action * @param string $action the name of the action to be logged + * @param string|null $title the title of the page for the comment that the + * action was performed upon */ protected function logAction( $action, $title ) { $logEntry = new ManualLogEntry( 'commentstreams', $action ); diff --git a/includes/Comment.php b/includes/Comment.php index 17c5af0..48a46e0 100644 --- a/includes/Comment.php +++ b/includes/Comment.php @@ -119,7 +119,7 @@ } $wikipage = new WikiPage( $title ); $status = $wikipage->doEditContent( $content, '', - EDIT_NEW | EDIT_SUPPRESS_RC , false, $user, null ); + EDIT_NEW | EDIT_SUPPRESS_RC, false, $user, null ); if ( !$status->isOK() && !$status->isGood() ) { if ( $status->getMessage()->getKey() == 'edit-already-exists' ) { $index = wfRandomString(); @@ -179,7 +179,7 @@ * load comment data from database */ private function loadFromDatabase() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->selectRow( 'cs_comment_data', [ @@ -193,10 +193,10 @@ __METHOD__ ); if ( $result ) { - $this->assoc_page_id = (integer)$result->cst_assoc_page_id; + $this->assoc_page_id = (int)$result->cst_assoc_page_id; $this->parent_page_id = $result->cst_parent_page_id; if ( !is_null( $this->parent_page_id ) ) { - $this->parent_page_id = (integer)$this->parent_page_id; + $this->parent_page_id = (int)$this->parent_page_id; } $this->comment_title = $result->cst_comment_title; $this->loaded = true; @@ -213,10 +213,10 @@ */ private function loadFromValues( $assoc_page_id, $parent_page_id, $comment_title ) { - $this->assoc_page_id = (integer)$assoc_page_id; + $this->assoc_page_id = (int)$assoc_page_id; $this->parent_page_id = $parent_page_id; if ( !is_null( $this->parent_page_id ) ) { - $this->parent_page_id = (integer)$this->parent_page_id; + $this->parent_page_id = (int)$this->parent_page_id; } $this->comment_title = $comment_title; $this->loaded = true; @@ -307,7 +307,7 @@ } /** - * @return boolean true if the last edit to this comment was not done by the + * @return bool true if the last edit to this comment was not done by the * original author */ public function isLastEditModerated() { @@ -343,7 +343,8 @@ */ public function getAvatar() { if ( is_null( $this->avatar ) ) { - if ( class_exists( 'wAvatar' ) ) { // from Extension:SocialProfile + if ( class_exists( 'wAvatar' ) ) { + // from Extension:SocialProfile $avatar = new wAvatar( $this->getUser()->getId(), 'l' ); $this->avatar = $GLOBALS['wgUploadPath'] . '/avatars/' . $avatar->getAvatarImage(); @@ -407,7 +408,7 @@ */ public function getNumReplies() { if ( is_null( $this->num_replies ) ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $this->num_replies = $dbr->selectRowCount( 'cs_comment_data', '*', @@ -454,7 +455,7 @@ * @return +1 for up vote, -1 for down vote, 0 for no vote */ public function getVote( $user ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->selectRow( 'cs_votes', [ @@ -467,7 +468,7 @@ __METHOD__ ); if ( $result ) { - $vote = (integer)$result->cst_v_vote; + $vote = (int)$result->cst_v_vote; if ( $vote > 0 ) { return 1; } @@ -483,7 +484,7 @@ */ public function getNumUpVotes() { if ( is_null( $this->num_up_votes ) ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $this->num_up_votes = $dbr->selectRowCount( 'cs_votes', '*', @@ -502,7 +503,7 @@ */ public function getNumDownVotes() { if ( is_null( $this->num_down_votes ) ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $this->num_down_votes = $dbr->selectRowCount( 'cs_votes', '*', @@ -519,7 +520,7 @@ /** * record a vote * - * @param vote 1 for up vote, -1 for down vote, 0 for no vote + * @param string $vote 1 for up vote, -1 for down vote, 0 for no vote * @param User $user the user voting on the comment * @return database status code */ @@ -527,8 +528,8 @@ if ( $vote !== "-1" && $vote !== "0" && $vote !== "1" ) { return false; } - $vote = (integer)$vote; - $dbr = wfGetDB( DB_SLAVE ); + $vote = (int)$vote; + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->selectRow( 'cs_votes', [ @@ -541,7 +542,7 @@ __METHOD__ ); if ( $result ) { - if ( $vote === (integer)$result->cst_v_vote ) { + if ( $vote === (int)$result->cst_v_vote ) { return true; } if ( $vote === 1 || $vote === -1 ) { @@ -630,7 +631,7 @@ return true; } $dbw = wfGetDB( DB_MASTER ); - $result = $dbw->delete ( + $result = $dbw->delete( 'cs_watchlist', [ 'cst_wl_page_id' => $this->getId(), @@ -659,7 +660,7 @@ * @return database true for OK, false for error */ private static function isWatchingComment( $pageid, $user ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->selectRow( 'cs_watchlist', [ @@ -683,7 +684,7 @@ * @return array of user IDs */ public function getWatchers() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->select( 'cs_watchlist', [ @@ -712,7 +713,7 @@ * @param string $comment_title the new title for the comment * @param string $wikitext the wikitext to add * @param User $user the author of the edit - * @return boolean true if successful + * @return bool true if successful */ public function update( $comment_title, $wikitext, $user ) { if ( is_null( $comment_title ) && is_null( $this->getParentId() ) ) { @@ -726,7 +727,7 @@ $this->getAssociatedId() ); $content = new WikitextContent( $annotated_wikitext ); $status = $this->wikipage->doEditContent( $content, '', - EDIT_UPDATE | EDIT_SUPPRESS_RC , false, $user, null ); + EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user, null ); if ( !$status->isOK() && !$status->isGood() ) { return false; } @@ -756,7 +757,7 @@ /** * delete comment from database * - * @return boolean true if successful + * @return bool true if successful */ public function delete() { $pageid = $this->getId(); @@ -824,7 +825,7 @@ * @return array array of comments for the given page */ public static function getAssociatedComments( $assoc_page_id ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->select( 'cs_comment_data', [ @@ -854,7 +855,7 @@ * @return array array of comments for the given page */ public static function getReplies( $parent_page_id ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $result = $dbr->select( 'cs_comment_data', [ @@ -881,7 +882,7 @@ * return the text to use to represent the user at the top of a comment * * @param User $user the user - * @param boolean $linked whether to link the display name to the user page, + * @param bool $linked whether to link the display name to the user page, * if it exists * @return string display name for user */ @@ -993,7 +994,7 @@ $id = $event->getExtraParam( 'parent_id' ); $wikipage = WikiPage::newFromId( $id ); if ( !is_null( $wikipage ) ) { - $comment = Comment::newFromWikiPage( $wikipage ); + $comment = self::newFromWikiPage( $wikipage ); if ( !is_null( $comment ) ) { return $comment->getWatchers(); } diff --git a/includes/CommentStreams.php b/includes/CommentStreams.php index 4181aaf..0ca58bb 100644 --- a/includes/CommentStreams.php +++ b/includes/CommentStreams.php @@ -129,9 +129,9 @@ // only display comments in subject namespaces in the list of allowed // namespaces - elseif ( !in_array( $namespace, $csAllowedNamespaces ) ) { + elseif ( !in_array( $namespace, $csAllowedNamespaces ) ) { return false; - } + } return true; } @@ -204,6 +204,8 @@ $output->getUser()->getRights() ), 'moderatorFastDelete' => $GLOBALS['wgCommentStreamsModeratorFastDelete'] ? 1 : 0, + 'showLabels' => + $GLOBALS['wgCommentStreamsShowLabels'] ? 1 : 0, 'userDisplayName' => Comment::getDisplayNameFromUser( $output->getUser() ), 'userAvatar' => @@ -266,7 +268,7 @@ return $date1 < $date2 ? -1 : 1; } } - } + } ); return $array; } diff --git a/includes/CommentStreamsAllComments.php b/includes/CommentStreamsAllComments.php index fd188aa..52eea7b 100644 --- a/includes/CommentStreamsAllComments.php +++ b/includes/CommentStreamsAllComments.php @@ -24,11 +24,14 @@ class CommentStreamsAllComments extends SpecialPage { - function __construct() { + public function __construct() { parent::__construct( 'CommentStreamsAllComments' ); } - function execute( $par ) { + /** + * @inheritDoc + */ + public function execute( $par ) { $request = $this->getRequest(); $this->setHeaders(); $this->getOutput()->addModuleStyles( 'ext.CommentStreamsAllComments' ); @@ -73,7 +76,7 @@ $wikipage = WikiPage::newFromId( $page->page_id ); $comment = Comment::newFromWikiPage( $wikipage ); if ( !is_null( $comment ) ) { - $pagename = $comment->getWikiPage()->getTitle()->getPrefixedText() ; + $pagename = $comment->getWikiPage()->getTitle()->getPrefixedText(); $associatedpageid = $comment->getAssociatedId(); $associatedpage = WikiPage::newFromId( $associatedpageid ); if ( !is_null( $associatedpage ) ) { @@ -101,13 +104,13 @@ } $wikitext .= '|-' . PHP_EOL; $wikitext .= '|[[' . $pagename . ']]' . PHP_EOL; - $wikitext .= '|' . $associatedpagename . PHP_EOL; - $wikitext .= '|' . $comment->getCommentTitle() . PHP_EOL; - $wikitext .= '|' . $comment->getWikiText() . PHP_EOL; - $wikitext .= '|' . $author . PHP_EOL; - $wikitext .= '|' . $lasteditor . PHP_EOL; - $wikitext .= '|' . $comment->getCreationDate() . PHP_EOL; - $wikitext .= '|' . $modificationdate . PHP_EOL; + $wikitext .= '| ' . $associatedpagename . PHP_EOL; + $wikitext .= '| ' . $comment->getCommentTitle() . PHP_EOL; + $wikitext .= '| ' . $comment->getWikiText() . PHP_EOL; + $wikitext .= '| ' . $author . PHP_EOL; + $wikitext .= '| ' . $lasteditor . PHP_EOL; + $wikitext .= '| ' . $comment->getCreationDate() . PHP_EOL; + $wikitext .= '| ' . $modificationdate . PHP_EOL; $index ++; } } @@ -134,7 +137,6 @@ } private function addTableNavigation( $offset, $more, $limit, $paramname ) { - $title = Title::newFromText( 'Special:' . __CLASS__ ); $url = $title->getFullURL(); @@ -176,7 +178,7 @@ } private static function getCommentPages( $limit, $offset ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $pages = $dbr->select( [ 'cs_comment_data', diff --git a/includes/CommentStreamsHooks.php b/includes/CommentStreamsHooks.php index 54015ea..b1faaff 100644 --- a/includes/CommentStreamsHooks.php +++ b/includes/CommentStreamsHooks.php @@ -150,7 +150,7 @@ * @param Title &$title the title object in question * @param User &$user the user performing the action * @param string $action the action being performed - * @param boolean &$result true means the user is allowed, false means the + * @param bool &$result true means the user is allowed, false means the * user is not allowed, untouched means this hook has no opinion * @return bool continue checking hooks */ @@ -315,7 +315,7 @@ } } if ( !$found ) { - foreach ( $GLOBALS['wgGroupPermissions'] as $group => $groupperms) { + foreach ( $GLOBALS['wgGroupPermissions'] as $group => $groupperms ) { if ( isset( $groupperms['edit'] ) ) { $GLOBALS['wgGroupPermissions'][$group]['cs-comment'] = $groupperms['edit']; @@ -362,7 +362,7 @@ * * @param SMW\Store $store semantic data store * @param SMW\SemanticData $semanticData semantic data for page - * @return boolean true to continue + * @return bool true to continue */ public static function updateData( $store, $semanticData ) { $subject = $semanticData->getSubject(); @@ -430,7 +430,6 @@ */ public static function onBeforeCreateEchoEvent( &$notifications, &$notificationCategories, &$icons ) { - $notificationCategories['commentstreams-notification-category'] = [ 'priority' => 3 ]; diff --git a/includes/EchoCSPresentationModel.php b/includes/EchoCSPresentationModel.php index c95657c..bc6786c 100644 --- a/includes/EchoCSPresentationModel.php +++ b/includes/EchoCSPresentationModel.php @@ -24,17 +24,14 @@ class EchoCSPresentationModel extends EchoEventPresentationModel { /** - * @return string The symbolic icon name as defined in $wgEchoNotificationIcons + * @inheritDoc */ public function getIconType() { return 'chat'; } /** - * Array of primary link details, with possibly-relative URL & label. - * - * @return array|bool Array of link data, or false for no link: - * ['url' => (string) url, 'label' => (string) link text (non-escaped)] + * @inheritDoc */ public function getPrimaryLink() { $id = $this->event->getExtraParam( 'comment_id' ); @@ -45,11 +42,7 @@ } /** - * Get a message object and add the performer's name as - * a parameter. It is expected that subclasses will override - * this. - * - * @return Message + * @inheritDoc */ public function getHeaderMessage() { $msg = wfMessage( "notification-header-{$this->type}" ); @@ -66,6 +59,9 @@ return $msg; } + /** + * @inheritDoc + */ public function getBodyMessage() { $msg = wfMessage( "notification-body-{$this->type}" ); $msg->params( $this->event->getExtraParam( @@ -82,10 +78,7 @@ } /** - * If this function returns false, no other methods will be called - * on the object. - * - * @return bool + * @inheritDoc */ public function canRender() { return !is_null( $this->event->getTitle() ); diff --git a/resources/CommentStreams.css b/resources/CommentStreams.css index d5c18cb..992278d 100644 --- a/resources/CommentStreams.css +++ b/resources/CommentStreams.css @@ -103,6 +103,10 @@ padding-left: 5px; } +.cs-comment-button-label { + padding-left: 5px; +} + button:hover { background-color: #8eddf5; } diff --git a/resources/CommentStreams.js b/resources/CommentStreams.js index 63b6ae3..9ecf525 100644 --- a/resources/CommentStreams.js +++ b/resources/CommentStreams.js @@ -32,6 +32,7 @@ moderatorEdit: false, moderatorDelete: false, moderatorFastDelete: false, + showLabels: false, userDisplayName: null, newestStreamsOnTop: false, initiallyCollapsed: false, @@ -76,6 +77,7 @@ this.moderatorDelete = config.moderatorDelete; this.moderatorFastDelete = this.moderatorDelete ? config.moderatorFastDelete : false; + this.showLabels = config.showLabels; this.userDisplayName = config.userDisplayName; this.newestStreamsOnTop = config.newestStreamsOnTop; this.initiallyCollapsed = config.initiallyCollapsed; @@ -112,12 +114,18 @@ id: 'cs-add-button' } ) .addClass( 'cs-button' ); - var addimage = $( '<img>' ) + var addImage = $( '<img>' ) .attr( { title: mw.message( 'commentstreams-buttontooltip-add' ), src: this.imagepath + 'comment_add.png' } ); - addButton.append( addimage ); + addButton.append( addImage ); + if ( this.showLabels ) { + var addLabel = $( '<span>' ) + .text( mw.message( 'commentstreams-buttontext-add' ) ) + .addClass( 'cs-comment-button-label' ) + addButton.append( addLabel ); + } if ( this.newestStreamsOnTop ) { headerDiv.append( addButton ); @@ -223,12 +231,18 @@ type: 'button', 'data-stream-id': commentData.pageid } ); - var replyimage = $( '<img>' ) + var replyImage = $( '<img>' ) .attr( { title: mw.message( 'commentstreams-buttontooltip-reply' ), src: this.imagepath + 'comment_reply.png' } ); - replyButton.append( replyimage ); + replyButton.append( replyImage ); + if ( this.showLabels ) { + var replyLabel = $( '<span>' ) + .text( mw.message( 'commentstreams-buttontext-reply' ) ) + .addClass( 'cs-comment-button-label' ) + replyButton.append( replyLabel ); + } streamFooter.append( replyButton ); replyButton.click( function() { var pageId = $( this ).attr( 'data-stream-id' ); -- To view, visit https://gerrit.wikimedia.org/r/405394 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie4b4965a4a1df77d3135c8b4b897243617cafa40 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CommentStreams Gerrit-Branch: master Gerrit-Owner: Cicalese <ccical...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits