r40892 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40891‎ | r40892 | r40893 >
Date:01:05, 16 September 2008
Author:brion
Status:old
Tags:
Comment:
Start on tagging capability for code review UI:
* Can add tags
* Can't delete them ;)
* Link to filtered view but it's NYI
* Tag name validation is crap
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionTagger.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)
  • /trunk/extensions/CodeReview/codereview.css (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -145,4 +145,52 @@
146146 $result->free();
147147 return $comments;
148148 }
 149+
 150+ function getTags() {
 151+ $dbr = wfGetDB( DB_SLAVE );
 152+ $result = $dbr->select( 'code_tags',
 153+ array( 'ct_tag' ),
 154+ array(
 155+ 'ct_repo_id' => $this->mRepo,
 156+ 'ct_rev_id' => $this->mId ),
 157+ __METHOD__ );
 158+
 159+ $tags = array();
 160+ foreach( $result as $row ) {
 161+ $tags[] = $row->ct_tag;
 162+ }
 163+ return $tags;
 164+ }
 165+
 166+ function addTags( $tags ) {
 167+ $dbw = wfGetDB( DB_MASTER );
 168+ $result = $dbw->insert( 'code_tags',
 169+ $this->tagData( $tags ),
 170+ __METHOD__,
 171+ array( 'IGNORE' ) );
 172+ }
 173+
 174+ function removeTags( $tags ) {
 175+ $dbw = wfGetDB( DB_MASTER );
 176+ $result = $dbw->delete( 'code_tags',
 177+ $this->tagData( $tags ),
 178+ __METHOD__ );
 179+ }
 180+
 181+ protected function tagData( $tags ) {
 182+ $data = array();
 183+ foreach( $tags as $tag ) {
 184+ $data[] = array(
 185+ 'ct_repo_id' => $this->mRepo,
 186+ 'ct_rev_id' => $this->mId,
 187+ 'ct_tag' => $tag );
 188+ }
 189+ return $data;
 190+ }
 191+
 192+ function isValidTag( $tag ) {
 193+ // fixme?
 194+ $title = Title::newFromText( $tag );
 195+ return $title && $title->getPrefixedText() === $tag;
 196+ }
149197 }
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -42,6 +42,7 @@
4343 $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php';
4444 $wgAutoloadClasses['CodeRevision'] = $dir . 'CodeRevision.php';
4545 $wgAutoloadClasses['CodeRevisionListView'] = $dir . 'CodeRevisionListView.php';
 46+$wgAutoloadClasses['CodeRevisionTagger'] = $dir . 'CodeRevisionTagger.php';
4647 $wgAutoloadClasses['CodeRevisionView'] = $dir . 'CodeRevisionView.php';
4748 $wgAutoloadClasses['CodeComment'] = $dir . 'CodeComment.php';
4849 $wgAutoloadClasses['SpecialCode'] = $dir . 'SpecialCode.php';
@@ -52,6 +53,11 @@
5354 $wgExtensionAliasesFiles['CodeReview'] = $dir . 'CodeReview.alias.php';
5455
5556 $wgAvailableRights[] = 'repoadmin';
 57+$wgGroupPermissions['*']['codereview-add-tag'] = true;
 58+$wgGroupPermissions['*']['codereview-remove-tag'] = true;
 59+$wgGroupPermissions['*']['codereview-post-comment'] = true;
5660
 61+$wgGroupPermissions['steward']['repoadmin'] = true; // temp
 62+
5763 $wgSpecialPages['Code'] = 'SpecialCode';
5864 $wgSpecialPages['RepoAdmin'] = 'SpecialRepoAdmin';
Index: trunk/extensions/CodeReview/codereview.css
@@ -1,3 +1,7 @@
 2+table.mw-codereview-meta td {
 3+ vertical-align: top;
 4+}
 5+
26 .mw-codereview-comment {
37 border: solid 1px #aaaab3;
48 padding: 0px;
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -26,6 +26,7 @@
2727 'code-rev-modified-c' => 'copied',
2828 'code-rev-modified-d' => 'deleted',
2929 'code-rev-modified-m' => 'modified',
 30+ 'code-rev-tags' => 'Tags:',
3031 'code-rev-comment-by' => 'Comment by $1',
3132 'code-rev-comment-submit' => 'Submit comment',
3233 'code-rev-comment-preview' => 'Preview',
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -29,6 +29,9 @@
3030 if( $params[2] == 'reply' ) {
3131 $view = new CodeRevisionView( $params[0], $params[1], $params[3] );
3232 break;
 33+ } elseif( $params[2] == 'add' && $params[3] == 'tag' ) {
 34+ $view = new CodeRevisionTagger( $params[0], $params[1] );
 35+ break;
3336 }
3437 default:
3538 throw new MWException( "Unexpected number of parameters" );
@@ -48,6 +51,13 @@
4952 global $wgUser;
5053 $this->mSkin = $wgUser->getSkin();
5154 }
 55+
 56+ function validPost( $permission ) {
 57+ global $wgRequest, $wgUser;
 58+ return $wgRequest->wasPosted()
 59+ && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
 60+ && $wgUser->isAllowed( $permission );
 61+ }
5262
5363 abstract function execute();
5464
Index: trunk/extensions/CodeReview/CodeRevisionTagger.php
@@ -0,0 +1,32 @@
 2+<?php
 3+
 4+class CodeRevisionTagger extends CodeRevisionView {
 5+
 6+ function __construct( $repoName, $rev ){
 7+ parent::__construct( $repoName, $rev );
 8+
 9+ global $wgRequest;
 10+ $this->mTag = $wgRequest->getText( 'wpTag' );
 11+ }
 12+
 13+ function execute() {
 14+ global $wgOut;
 15+
 16+ if( $this->validPost( 'codereview-add-tag' ) ) {
 17+ $this->mRev->addTags( array( $this->mTag ) );
 18+
 19+ $repo = $this->mRepo->getName();
 20+ $rev = $this->mRev->getId();
 21+ $special = SpecialPage::getTitleFor( 'Code', "$repo/$rev" );
 22+
 23+ $wgOut->redirect( $special->getFullUrl() );
 24+ } else {
 25+ throw new MWException( 'barf' );
 26+ }
 27+ }
 28+
 29+ function validPost( $permission ) {
 30+ return parent::validPost( $permission ) &&
 31+ $this->mRev->isValidTag( $this->mTag );
 32+ }
 33+}
Property changes on: trunk/extensions/CodeReview/CodeRevisionTagger.php
___________________________________________________________________
Added: svn:eol-style
134 + native
Index: trunk/extensions/CodeReview/CodeRevisionView.php
@@ -42,13 +42,20 @@
4343 if( $paths ){
4444 $paths = "<ul>\n$paths</ul>";
4545 }
46 - $html = '<table>
47 -<tr><td valign="top">' . wfMsgHtml( 'code-rev-repo' ) . '</td><td valign="top">' . $repoLink . '</td></tr>
48 -<tr><td valign="top">' . wfMsgHtml( 'code-rev-rev' ) . '</td><td valign="top">' . $revText . '</td></tr>
49 -<tr><td valign="top">' . wfMsgHtml( 'code-rev-author' ) . '</td><td valign="top">' . $this->authorLink( $this->mRev->getAuthor() ) . '</td></tr>
50 -<tr><td valign="top">' . wfMsgHtml( 'code-rev-message' ) . '</td><td valign="top">' . $this->formatMessage( $this->mRev->getMessage() ) . '</td></tr>
51 -<tr><td valign="top">' . wfMsgHtml( 'code-rev-paths' ) . '</td><td valign="top">' . $paths . '</td></tr>
52 -</table>';
 46+ $fields = array(
 47+ 'code-rev-repo' => $repoLink,
 48+ 'code-rev-rev' => $revText,
 49+ 'code-rev-author' => $this->authorLink( $this->mRev->getAuthor() ),
 50+ 'code-rev-message' => $this->formatMessage( $this->mRev->getMessage() ),
 51+ 'code-rev-paths' => $paths,
 52+ 'code-rev-tags' => $this->formatTags(),
 53+ );
 54+ $html = '<table class="mw-codereview-meta">';
 55+ foreach( $fields as $label => $data ) {
 56+ $html .= "<tr><td>" . wfMsgHtml( $label ) . "</td><td>$data</td></tr>\n";
 57+ }
 58+ $html .= '</table>';
 59+
5360 $html .=
5461 "<h2>" . wfMsgHtml( 'code-rev-diff' ) . "</h2>" .
5562 "<div class='mw-codereview-diff'>" .
@@ -107,6 +114,48 @@
108115 }
109116 return "<li>$link ($desc)</li>\n";
110117 }
 118+
 119+ function formatTags() {
 120+ global $wgUser;
 121+
 122+ $tags = $this->mRev->getTags();
 123+ $list = implode( ", ",
 124+ array_map(
 125+ array( $this, 'formatTag' ),
 126+ $tags ) );
 127+
 128+ if( $wgUser->isAllowed( 'codereview-add-tag' ) ) {
 129+ $list .= $this->addTagForm();
 130+ }
 131+
 132+ return $list;
 133+ }
 134+
 135+ function addTagForm() {
 136+ global $wgUser;
 137+ $repo = $this->mRepo->getName();
 138+ $rev = $this->mRev->getId();
 139+ $special = SpecialPage::getTitleFor( 'Code', "$repo/$rev/add/tag" );
 140+ return
 141+ Xml::openElement( 'form',
 142+ array(
 143+ 'action' => $special->getLocalUrl(),
 144+ 'method' => 'post' ) ) .
 145+ Xml::input( 'wpTag', '' ) .
 146+ Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
 147+ '&nbsp;' .
 148+ Xml::submitButton( 'Add tag' ) .
 149+ '</form>';
 150+ }
 151+
 152+ function formatTag( $tag ) {
 153+ global $wgUser;
 154+
 155+ $repo = $this->mRepo->getName();
 156+ $special = SpecialPage::getTitleFor( 'Code', "$repo/tag/$tag" );
 157+
 158+ return $this->mSkin->link( $special, htmlspecialchars( $tag ) );
 159+ }
111160
112161 function formatDiff() {
113162 $diff = $this->mRepo->getDiff( $this->mRev->getId() );

Status & tagging log