r41956 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41955‎ | r41956 | r41957 >
Date:01:10, 11 October 2008
Author:aaron
Status:old
Tags:
Comment:
* Centralize submit code
* Check 'codereview-add-remove' right
* Add revLink() function
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionCommitter.php (added) (history)
  • /trunk/extensions/CodeReview/CodeRevisionStatusSetter.php (deleted) (history)
  • /trunk/extensions/CodeReview/CodeRevisionTagger.php (deleted) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevisionTagger.php
@@ -1,38 +0,0 @@
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->mAddTags = $this->splitTags( $wgRequest->getText( 'wpTag' ) );
11 - $this->mRemoveTags = $this->splitTags( $wgRequest->getText( 'wpRemoveTag' ) );
12 - }
13 -
14 - function execute() {
15 - if( $this->validPost( 'codereview-add-tag' ) ) {
16 - if( count($this->mAddTags) )
17 - $this->mRev->addTags( $this->mAddTags );
18 - if( count($this->mRemoveTags) )
19 - $this->mRev->removeTags( $this->mRemoveTags );
20 - }
21 - }
22 -
23 - function splitTags( $input ) {
24 - $tags = array_map( 'trim', explode( ",", $input ) );
25 - foreach( $tags as $key => $tag ) {
26 - $normal = $this->mRev->normalizeTag( $tag );
27 - if( $normal === false ) {
28 - return null;
29 - }
30 - $tags[$key] = $normal;
31 - }
32 - return $tags;
33 - }
34 -
35 - function validPost( $permission ) {
36 - return parent::validPost( $permission ) &&
37 - ( !empty( $this->mAddTags ) || !empty( $this->mRemoveTags ) );
38 - }
39 -}
Index: trunk/extensions/CodeReview/CodeRevisionStatusSetter.php
@@ -1,25 +0,0 @@
2 -<?php
3 -
4 -class CodeRevisionStatusSetter extends CodeRevisionView {
5 -
6 - function __construct( $repoName, $rev ){
7 - parent::__construct( $repoName, $rev );
8 -
9 - global $wgRequest;
10 - $this->mStatus = $wgRequest->getText( 'wpStatus' );
11 - }
12 -
13 - function execute() {
14 - if( $this->validPost( 'codereview-set-status' ) ) {
15 - $this->mRev->setStatus( $this->mStatus );
16 -
17 - $repo = $this->mRepo->getName();
18 - $rev = $this->mRev->getId();
19 - }
20 - }
21 -
22 - function validPost( $permission ) {
23 - return parent::validPost( $permission ) &&
24 - $this->mRev->isValidStatus( $this->mStatus );
25 - }
26 -}
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -47,9 +47,8 @@
4848 $wgAutoloadClasses['CodeRevisionAuthorView'] = $dir . 'CodeRevisionAuthorView.php';
4949 $wgAutoloadClasses['CodeRevisionAuthorLink'] = $dir . 'CodeRevisionAuthorLink.php';
5050 $wgAutoloadClasses['CodeRevisionListView'] = $dir . 'CodeRevisionListView.php';
51 -$wgAutoloadClasses['CodeRevisionStatusSetter'] = $dir . 'CodeRevisionStatusSetter.php';
 51+$wgAutoloadClasses['CodeRevisionCommitter'] = $dir . 'CodeRevisionCommitter.php';
5252 $wgAutoloadClasses['CodeRevisionStatusView'] = $dir . 'CodeRevisionStatusView.php';
53 -$wgAutoloadClasses['CodeRevisionTagger'] = $dir . 'CodeRevisionTagger.php';
5453 $wgAutoloadClasses['CodeRevisionTagView'] = $dir . 'CodeRevisionTagView.php';
5554 $wgAutoloadClasses['CodeRevisionView'] = $dir . 'CodeRevisionView.php';
5655 $wgAutoloadClasses['CodeAuthorListView'] = $dir . 'CodeAuthorListView.php';
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -24,15 +24,10 @@
2525 break;
2626 case 2:
2727 if( $wgRequest->wasPosted() && $wgRequest->getCheck('wpSave') ) {
28 - # Add any tags
29 - $crt = new CodeRevisionTagger( $params[0], $params[1] );
30 - $crt->execute();
31 - # Set status
32 - $crs = new CodeRevisionStatusSetter( $params[0], $params[1] );
33 - $crs->execute();
34 - # Adds comments and makes output
35 - $view = new CodeRevisionView( $params[0], $params[1] );
36 - break;
 28+ # Add any tags, Set status, Adds comments
 29+ $submit = new CodeRevisionCommitter( $params[0], $params[1] );
 30+ $submit->execute();
 31+ return;
3732 } else if( $params[1] === 'tag' ) {
3833 $view = new CodeTagListView( $params[0] );
3934 break;
@@ -76,12 +71,6 @@
7772 if( $params[2] == 'reply' ) {
7873 $view = new CodeRevisionView( $params[0], $params[1], $params[3] );
7974 break;
80 - } elseif( $params[2] == 'add' && $params[3] == 'tag' ) {
81 - $view = new CodeRevisionTagger( $params[0], $params[1] );
82 - break;
83 - } elseif( $params[2] == 'set' && $params[3] == 'status' ) {
84 - $view = new CodeRevisionStatusSetter( $params[0], $params[1] );
85 - break;
8675 }
8776 $wgOut->addWikiText( wfMsg('nosuchactiontext') );
8877 $wgOut->returnToMain( null, SpecialPage::getTitleFor( 'Code' ) );
Index: trunk/extensions/CodeReview/CodeRevisionCommitter.php
@@ -0,0 +1,59 @@
 2+<?php
 3+
 4+class CodeRevisionCommitter extends CodeRevisionView {
 5+
 6+ function __construct( $repoName, $rev ){
 7+ // Parent should set $this->mRepo, $this->mRev, $this->mReplyTarget
 8+ parent::__construct( $repoName, $rev );
 9+
 10+ global $wgRequest;
 11+ $this->mAddTags = $this->splitTags( $wgRequest->getText( 'wpTag' ) );
 12+ $this->mRemoveTags = $this->splitTags( $wgRequest->getText( 'wpRemoveTag' ) );
 13+ $this->mStatus = $wgRequest->getText( 'wpStatus' );
 14+ $this->text = $wgRequest->getText( "wpReply{$this->mReplyTarget}" );
 15+ }
 16+
 17+ function execute() {
 18+ global $wgRequest, $wgOut;
 19+ if( $this->validPost('codereview-add-tag') && count($this->mAddTags) ) {
 20+ $this->mRev->addTags( $this->mAddTags );
 21+ }
 22+ if( $this->validPost('codereview-add-remove') && count($this->mRemoveTags) ) {
 23+ $this->mRev->removeTags( $this->mRemoveTags );
 24+ }
 25+ if( $this->validPost('codereview-set-status') && $this->mRev->isValidStatus($this->mStatus) ) {
 26+ $this->mRev->setStatus( $this->mStatus );
 27+ }
 28+ if( $this->validPost('codereview-post-comment') && strlen($this->text) ) {
 29+ $parent = $wgRequest->getIntOrNull( 'wpParent' );
 30+ $review = $wgRequest->getInt( 'wpReview' );
 31+ $isPreview = $wgRequest->getCheck( 'wpPreview' );
 32+ $id = $this->mRev->saveComment( $this->text, $review, $parent );
 33+ // For comments, take us back to the rev page focused on the new comment
 34+ $permaLink = $this->commentLink( $id );
 35+ $wgOut->redirect( $permaLink->getFullUrl() );
 36+ return;
 37+ }
 38+ // Return to rev page
 39+ $permaLink = $this->revLink();
 40+ $wgOut->redirect( $permaLink->getFullUrl() );
 41+ }
 42+
 43+ function splitTags( $input ) {
 44+ $tags = array_map( 'trim', explode( ",", $input ) );
 45+ foreach( $tags as $key => $tag ) {
 46+ $normal = $this->mRev->normalizeTag( $tag );
 47+ if( $normal === false ) {
 48+ return null;
 49+ }
 50+ $tags[$key] = $normal;
 51+ }
 52+ return $tags;
 53+ }
 54+
 55+ public function validPost( $permission ) {
 56+ global $wgUser, $wgRequest;
 57+ return parent::validPost($permission) && $wgRequest->wasPosted()
 58+ && $wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') );
 59+ }
 60+}
Property changes on: trunk/extensions/CodeReview/CodeRevisionCommitter.php
___________________________________________________________________
Name: svn:eol-style
161 + native
Index: trunk/extensions/CodeReview/CodeRevisionView.php
@@ -131,12 +131,6 @@
132132 if( $isPreview ) {
133133 // Save the text for reference on later comment display...
134134 $this->mPreviewText = $text;
135 - } else if( $wgUser->isAllowed('codereview-post-comment') && strlen($text) ) {
136 - $id = $this->mRev->saveComment( $text, $review, $parent );
137 - // Redirect to the just-saved comment; this avoids POST
138 - // horrors on forward/rewind. Hope we don't have slave issues?
139 - $permaLink = $this->commentLink( $id );
140 - return $permaLink->getFullUrl();
141135 }
142136 }
143137 return false;
@@ -277,6 +271,13 @@
278272 return $title;
279273 }
280274
 275+ function revLink() {
 276+ $repo = $this->mRepo->getName();
 277+ $rev = $this->mRev->getId();
 278+ $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" );
 279+ return $title;
 280+ }
 281+
281282 function previewComment( $text, $review=0 ) {
282283 $comment = $this->mRev->previewComment( $text, $review );
283284 return $this->formatComment( $comment );

Status & tagging log