r96158 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96157‎ | r96158 | r96159 >
Date:22:41, 2 September 2011
Author:hashar
Status:reverted (Comments)
Tags:
Comment:
(bug 26084) add some ajax to easily delete tags

TODO: implements functionality to add tags easily!
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.tags.css (added) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.tags.js (added) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -186,6 +186,12 @@
187187 'messages' => array( 'codereview-overview-title', 'codereview-overview-desc' ),
188188 ) + $commonModuleInfo;
189189
 190+// Add, remove tags from a revision view
 191+$wgResourceModules['ext.codereview.tags'] = array(
 192+ 'scripts' => 'ext.codereview.tags.js',
 193+ 'styles' => 'ext.codereview.tags.css',
 194+) + $commonModuleInfo;
 195+
190196 // If you are running a closed svn, fill the following two lines with the username and password
191197 // of a user allowed to access it. Otherwise, leave it false.
192198 // This is only necessary if using the shell method to access Subversion
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -82,6 +82,8 @@
8383 'code-rev-tags' => 'Tags:',
8484 'code-rev-tag-add' => 'Add tags:',
8585 'code-rev-tag-remove' => 'Remove tags:',
 86+ 'code-rev-tag-addtag-tooltip' => 'Add new tags to this revision',
 87+ 'code-rev-tag-removetag-tooltip' => 'Click to remove tag "$1"',
8688 'code-rev-comment-by' => 'Comment by $1',
8789 'code-rev-comment-preview' => 'Preview',
8890 'code-rev-comment-preview-accesskey' => 'p',
Index: trunk/extensions/CodeReview/modules/ext.codereview.tags.css
@@ -0,0 +1,17 @@
 2+/* Unique green box to add new tags */
 3+#codereview-add-tag {
 4+ color: #00FF00;
 5+ font-size: 1.2em;
 6+
 7+ background-color: #EDFFED;
 8+ padding: 0 0.5em;
 9+ border: 1px solid #00FF00;
 10+ cursor: pointer;
 11+}
 12+
 13+/* Red 'erase to the left' signs to remove a tag */
 14+.codereview-remove-tag {
 15+ color: #FF0000;
 16+ font-size: 1.2em;
 17+ cursor: crosshair;
 18+}
Index: trunk/extensions/CodeReview/modules/ext.codereview.tags.js
@@ -0,0 +1,59 @@
 2+( function( $ ) {
 3+var $rev = 0;
 4+
 5+window.CodeReview = $.extend( window.CodeReview, {
 6+
 7+ /* TODO we should probably add that click handling from PHP
 8+ * ui/CodeRevisionView.php */
 9+ tagInit: function( rev ) {
 10+ $rev = rev;
 11+ $('.codereview-remove-tag').click( function() {
 12+ CodeReview.tagRemove( $(this).attr( 'id' ) )
 13+ });
 14+ },
 15+ tagAdd: function() {
 16+
 17+ },
 18+ tagRemove: function( HTMLId ) {
 19+ var tag = HTMLId.replace( /codereview-remove-tag-(.*)/, "$1" );
 20+ $.ajax({
 21+ url: mw.util.wikiScript( 'api' ),
 22+ data: {
 23+ 'action': 'coderevisionupdate',
 24+
 25+ 'repo' : mw.config.get( 'wgCodeReviewRepository' ),
 26+ 'rev' : $rev,
 27+
 28+ 'removetags': tag,
 29+
 30+ 'format': 'json',
 31+ },
 32+ dataType: 'json',
 33+ type: 'POST',
 34+ success: function( data ) {
 35+ var remover = $( '#'+HTMLId );
 36+ // remove tag:
 37+ remover.prev().fadeOut().remove();
 38+
 39+ /**
 40+ * tag might be followed by a text node ', '
 41+ * which can not be reached with jQuery next()
 42+ */
 43+ var nextNode = remover[0].nextSibling;
 44+ console.log( nextNode );
 45+ if( nextNode.nodeType === 3
 46+ && nextNode.nodeValue === ", " ) {
 47+ nextNode.parentNode.removeChild( nextNode );
 48+ }
 49+ // finally remove the tag removal sign
 50+ remover.fadeOut().remove();
 51+ },
 52+ error: function() {
 53+ // TODO
 54+ },
 55+ });
 56+ },
 57+
 58+
 59+}); // window.CodeReview
 60+})( jQuery );
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php
@@ -193,12 +193,19 @@
194194 }
195195 $html .= xml::closeElement( 'form' );
196196
 197+ // Encode revision id for our modules
 198+ $encRev = Xml::encodeJsVar( $this->mRev->getId() );
 199+
197200 $wgOut->addModules( 'ext.codereview.linecomment' );
198 - $encRev = Xml::encodeJsVar( $this->mRev->getId() );
199201 $wgOut->addInLineScript(
200202 "CodeReview.lcInit( $encRev );"
201203 );
202204
 205+ $wgOut->addModules( 'ext.codereview.tags' );
 206+ $wgOut->addInlineScript(
 207+ "CodeReview.tagInit( $encRev );"
 208+ );
 209+
203210 $wgOut->addHTML( $html );
204211 }
205212
@@ -337,6 +344,10 @@
338345 ) . ' ';
339346 }
340347 if ( $wgUser->isAllowed( 'codereview-add-tag' ) ) {
 348+ $list .= Xml::Element( 'span', array(
 349+ 'id' => "codereview-add-tag",
 350+ 'title' => wfMsg( 'code-rev-tag-addtag-tooltip' ),
 351+ ), '+' ); // TODO: replace '+' with a message
341352 $list .= $this->addTagForm( $this->mAddTags, $this->mRemoveTags );
342353 }
343354 return $list;
@@ -415,9 +426,27 @@
416427 * @return string
417428 */
418429 protected function formatTag( $tag ) {
 430+ global $wgUser;
 431+
419432 $repo = $this->mRepo->getName();
420433 $special = SpecialPage::getTitleFor( 'Code', "$repo/tag/$tag" );
421 - return $this->skin->link( $special, htmlspecialchars( $tag ) );
 434+ $link = $this->skin->link(
 435+ $special,
 436+ htmlspecialchars( $tag ),
 437+ array( 'class' => 'mw-codereview-tag' )
 438+ );
 439+
 440+ # Let allowed users to remove tags using JS
 441+ if( $wgUser->isAllowed( 'codereview-add-tag' ) ) {
 442+ $link .= ' '.
 443+ Xml::Element( 'span', array(
 444+ 'id' => "codereview-remove-tag-{$tag}",
 445+ 'class' => 'codereview-remove-tag',
 446+ 'title' => wfMsg( 'code-rev-tag-removetag-tooltip', $tag ),
 447+ ), '⌫' ); // TODO: replace '⌫' with a message
 448+ }
 449+
 450+ return $link;
422451 }
423452
424453 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r96159Get ride of old Tag form...hashar22:41, 2 September 2011
r96160Followup r96158, fix syn:eol-stylereedy22:42, 2 September 2011
r105518Reverting r96158, r96159: incomplete project, can't be deployed as is, see CR...tstarling06:33, 8 December 2011

Comments

#Comment by Reedy (talk | contribs)   22:41, 2 September 2011

Are you using a new machine Hashar? You're missing svn props... Subversion/auto-props

#Comment by Hashar (talk | contribs)   22:50, 2 September 2011

That one comes from git. Not sure I can set svn properties with git svn. Will have to look at it.

#Comment by Hashar (talk | contribs)   22:52, 2 September 2011

The tag removal code takes care of the ", " textnode but should take care of " " before the tag name.

Code does not have error handling in case the API has an issue.

#Comment by Tim Starling (talk | contribs)   06:19, 8 December 2011

The "+" and "⌫" do not look like buttons. Please replace them with images. You can get appropriate images from the Crystal theme or you can put simple placeholder images in there for now.

I don't think the crosshair cursor is appropriate for a delete button, it's for drawing or for shooting alien invaders.

In the AJAX success callback, you should check the response body to see if the request was actually successful, and pass the error message through to the user if it wasn't.

As with r95435, the click handlers should be registered on DOM ready.

Presumably tagAdd() is meant to be registered as a click handler for the plus sign and it's meant to do something.

Reverting for now since this is incomplete and not deployable.

Status & tagging log