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 @@ |
48 | 48 | $wgAutoloadClasses['CodeRevisionAuthorView'] = $dir . 'CodeRevisionAuthorView.php'; |
49 | 49 | $wgAutoloadClasses['CodeRevisionAuthorLink'] = $dir . 'CodeRevisionAuthorLink.php'; |
50 | 50 | $wgAutoloadClasses['CodeRevisionListView'] = $dir . 'CodeRevisionListView.php'; |
51 | | -$wgAutoloadClasses['CodeRevisionStatusSetter'] = $dir . 'CodeRevisionStatusSetter.php'; |
| 51 | +$wgAutoloadClasses['CodeRevisionCommitter'] = $dir . 'CodeRevisionCommitter.php'; |
52 | 52 | $wgAutoloadClasses['CodeRevisionStatusView'] = $dir . 'CodeRevisionStatusView.php'; |
53 | | -$wgAutoloadClasses['CodeRevisionTagger'] = $dir . 'CodeRevisionTagger.php'; |
54 | 53 | $wgAutoloadClasses['CodeRevisionTagView'] = $dir . 'CodeRevisionTagView.php'; |
55 | 54 | $wgAutoloadClasses['CodeRevisionView'] = $dir . 'CodeRevisionView.php'; |
56 | 55 | $wgAutoloadClasses['CodeAuthorListView'] = $dir . 'CodeAuthorListView.php'; |
Index: trunk/extensions/CodeReview/SpecialCode.php |
— | — | @@ -24,15 +24,10 @@ |
25 | 25 | break; |
26 | 26 | case 2: |
27 | 27 | 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; |
37 | 32 | } else if( $params[1] === 'tag' ) { |
38 | 33 | $view = new CodeTagListView( $params[0] ); |
39 | 34 | break; |
— | — | @@ -76,12 +71,6 @@ |
77 | 72 | if( $params[2] == 'reply' ) { |
78 | 73 | $view = new CodeRevisionView( $params[0], $params[1], $params[3] ); |
79 | 74 | 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; |
86 | 75 | } |
87 | 76 | $wgOut->addWikiText( wfMsg('nosuchactiontext') ); |
88 | 77 | $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 |
1 | 61 | + native |
Index: trunk/extensions/CodeReview/CodeRevisionView.php |
— | — | @@ -131,12 +131,6 @@ |
132 | 132 | if( $isPreview ) { |
133 | 133 | // Save the text for reference on later comment display... |
134 | 134 | $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(); |
141 | 135 | } |
142 | 136 | } |
143 | 137 | return false; |
— | — | @@ -277,6 +271,13 @@ |
278 | 272 | return $title; |
279 | 273 | } |
280 | 274 | |
| 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 | + |
281 | 282 | function previewComment( $text, $review=0 ) { |
282 | 283 | $comment = $this->mRev->previewComment( $text, $review ); |
283 | 284 | return $this->formatComment( $comment ); |