Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -186,6 +186,12 @@ |
187 | 187 | 'messages' => array( 'codereview-overview-title', 'codereview-overview-desc' ), |
188 | 188 | ) + $commonModuleInfo; |
189 | 189 | |
| 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 | + |
190 | 196 | // If you are running a closed svn, fill the following two lines with the username and password |
191 | 197 | // of a user allowed to access it. Otherwise, leave it false. |
192 | 198 | // This is only necessary if using the shell method to access Subversion |
Index: trunk/extensions/CodeReview/CodeReview.i18n.php |
— | — | @@ -82,6 +82,8 @@ |
83 | 83 | 'code-rev-tags' => 'Tags:', |
84 | 84 | 'code-rev-tag-add' => 'Add tags:', |
85 | 85 | '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"', |
86 | 88 | 'code-rev-comment-by' => 'Comment by $1', |
87 | 89 | 'code-rev-comment-preview' => 'Preview', |
88 | 90 | '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 @@ |
194 | 194 | } |
195 | 195 | $html .= xml::closeElement( 'form' ); |
196 | 196 | |
| 197 | + // Encode revision id for our modules |
| 198 | + $encRev = Xml::encodeJsVar( $this->mRev->getId() ); |
| 199 | + |
197 | 200 | $wgOut->addModules( 'ext.codereview.linecomment' ); |
198 | | - $encRev = Xml::encodeJsVar( $this->mRev->getId() ); |
199 | 201 | $wgOut->addInLineScript( |
200 | 202 | "CodeReview.lcInit( $encRev );" |
201 | 203 | ); |
202 | 204 | |
| 205 | + $wgOut->addModules( 'ext.codereview.tags' ); |
| 206 | + $wgOut->addInlineScript( |
| 207 | + "CodeReview.tagInit( $encRev );" |
| 208 | + ); |
| 209 | + |
203 | 210 | $wgOut->addHTML( $html ); |
204 | 211 | } |
205 | 212 | |
— | — | @@ -337,6 +344,10 @@ |
338 | 345 | ) . ' '; |
339 | 346 | } |
340 | 347 | 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 |
341 | 352 | $list .= $this->addTagForm( $this->mAddTags, $this->mRemoveTags ); |
342 | 353 | } |
343 | 354 | return $list; |
— | — | @@ -415,9 +426,27 @@ |
416 | 427 | * @return string |
417 | 428 | */ |
418 | 429 | protected function formatTag( $tag ) { |
| 430 | + global $wgUser; |
| 431 | + |
419 | 432 | $repo = $this->mRepo->getName(); |
420 | 433 | $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; |
422 | 451 | } |
423 | 452 | |
424 | 453 | /** |