Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -165,6 +165,9 @@ |
166 | 166 | 'contest-contestant-header-comments' => 'Amount of comments', |
167 | 167 | 'contest-contestant-submission-url' => 'Submission', |
168 | 168 | 'contest-contestant-notsubmitted' => 'Not submitted yet', |
| 169 | + 'contest-contestant-comments' => 'Comments', |
| 170 | + 'contest-contestant-submit' => 'Save changes', |
| 171 | + 'contest-contestant-comment-by' => 'Comment by $1' |
169 | 172 | ); |
170 | 173 | |
171 | 174 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Contest/specials/SpecialContestPage.php |
— | — | @@ -146,8 +146,12 @@ |
147 | 147 | * |
148 | 148 | * @since 0.1 |
149 | 149 | */ |
150 | | - protected function displayNavigation() { |
151 | | - $this->getOutput()->addHTML( self::getNavigation( $this->subPage, $this->getUser(), $this->getLang(), $this->getName() ) ); |
| 150 | + protected function displayNavigation( $subPage = null ) { |
| 151 | + if ( is_null( $subPage ) ) { |
| 152 | + $subPage = $this->subPage; |
| 153 | + } |
| 154 | + |
| 155 | + $this->getOutput()->addHTML( self::getNavigation( $subPage, $this->getUser(), $this->getLang(), $this->getName() ) ); |
152 | 156 | } |
153 | 157 | |
154 | 158 | } |
Index: trunk/extensions/Contest/specials/SpecialContestant.php |
— | — | @@ -34,30 +34,80 @@ |
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | | - $out = $this->getOutput(); |
39 | | - |
40 | 38 | $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) ); |
41 | 39 | |
42 | 40 | if ( $contestant === false ) { |
43 | | - $out->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
| 41 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
44 | 42 | } |
45 | 43 | else { |
46 | | - $out->setPageTitle( wfMsgExt( |
47 | | - 'contest-contestant-title', |
48 | | - 'parseinline', |
49 | | - $contestant->getField( 'id' ), |
50 | | - $contestant->getContest()->getField( 'name' ) |
| 44 | + if ( $this->getRequest()->wasPosted() |
| 45 | + && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
| 46 | + $this->handleSubmission( $contestant ); |
| 47 | + } |
| 48 | + |
| 49 | + $this->showPage( $contestant ); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Handle a submission by inserting/updating the vote |
| 55 | + * and (optionally) adding the comment. |
| 56 | + * |
| 57 | + * @since 0.1 |
| 58 | + * |
| 59 | + * @param ContestContestant $contestant |
| 60 | + * |
| 61 | + * @return boolean Success indicator |
| 62 | + */ |
| 63 | + protected function handleSubmission( ContestContestant $contestant ) { |
| 64 | + $success = true; |
| 65 | + |
| 66 | + if ( trim( $this->getRequest()->getText( 'new-comment-text' ) ) !== '' ) { |
| 67 | + $comment = new ContestComment( array( |
| 68 | + 'user_id' => $this->getUser()->getId(), |
| 69 | + 'contestant_id' => $contestant->getId(), |
| 70 | + |
| 71 | + 'text' => $this->getRequest()->getText( 'new-comment-text' ), |
| 72 | + 'time' => wfTimestampNow() |
51 | 73 | ) ); |
52 | 74 | |
53 | | - $this->subPage = str_replace( ' ', '_', $contestant->getContest()->getField( 'name' ) ); |
54 | | - $this->displayNavigation(); |
| 75 | + $success = $comment->writeToDB(); |
55 | 76 | |
56 | | - $this->showGeneralInfo( $contestant ); |
57 | | - $this->showRating( $contestant ); |
58 | | - $this->showComments( $contestant ); |
| 77 | + if ( $success ) { |
| 78 | + ContestContestant::s()->addToField( 'comments', 1 ); |
| 79 | + } |
59 | 80 | } |
| 81 | + |
| 82 | + if ( $success ) { |
| 83 | + // TODO: rating shizzle |
| 84 | + } |
| 85 | + |
| 86 | + return $success; |
60 | 87 | } |
61 | 88 | |
| 89 | + protected function showPage( ContestContestant $contestant ) { |
| 90 | + $out = $this->getOutput(); |
| 91 | + |
| 92 | + $out->setPageTitle( wfMsgExt( |
| 93 | + 'contest-contestant-title', |
| 94 | + 'parseinline', |
| 95 | + $contestant->getField( 'id' ), |
| 96 | + $contestant->getContest()->getField( 'name' ) |
| 97 | + ) ); |
| 98 | + |
| 99 | + $this->displayNavigation( str_replace( ' ', '_', $contestant->getContest()->getField( 'name' ) ) ); |
| 100 | + |
| 101 | + $this->showGeneralInfo( $contestant ); |
| 102 | + |
| 103 | + $out->addHTML( '<form method="post" action="' . htmlspecialchars( $this->getTitle( $this->subPage )->getLocalURL() ) . '">' ); |
| 104 | + $out->addHTML( Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) ); |
| 105 | + |
| 106 | + $this->showRating( $contestant ); |
| 107 | + $this->showComments( $contestant ); |
| 108 | + |
| 109 | + $out->addHTML( '</form>' ); |
| 110 | + } |
| 111 | + |
62 | 112 | /** |
63 | 113 | * Display the general contestant info. |
64 | 114 | * |
— | — | @@ -139,8 +189,6 @@ |
140 | 190 | return $stats; |
141 | 191 | } |
142 | 192 | |
143 | | - // TODO: show rating and commenting controls |
144 | | - |
145 | 193 | /** |
146 | 194 | * Display the current rating the judge gave if any and a control to |
147 | 195 | * (re)-rate. |
— | — | @@ -161,7 +209,62 @@ |
162 | 210 | * @param ContestContestant $contestant |
163 | 211 | */ |
164 | 212 | protected function showComments( ContestContestant $contestant ) { |
| 213 | + $out = $this->getOutput(); |
165 | 214 | |
| 215 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-comments' ) ) ); |
| 216 | + |
| 217 | + $out->addHTML( '<div class="contestant-comments">' ); |
| 218 | + |
| 219 | + foreach ( $contestant->getComments() as /* ContestComment */ $comment ) { |
| 220 | + $out->addHTML( $this->getCommentHTML( $comment ) ); |
| 221 | + } |
| 222 | + |
| 223 | + $out->addHTML( '</div>' ); |
| 224 | + |
| 225 | + $out->addHTML( |
| 226 | + '<div class="contestant-new-comment"> |
| 227 | + <textarea cols="40" rows="10" name="new-comment-text"></textarea> |
| 228 | + </div>' |
| 229 | + ); |
| 230 | + |
| 231 | + $out->addHTML( Html::input( 'submitChanges', wfMsg( 'contest-contestant-submit' ), 'submit' ) ); |
166 | 232 | } |
167 | 233 | |
| 234 | + /** |
| 235 | + * Get the HTML for a single comment. |
| 236 | + * |
| 237 | + * @since 0.1 |
| 238 | + * |
| 239 | + * @param ContestComment $comment |
| 240 | + * |
| 241 | + * @return string |
| 242 | + */ |
| 243 | + protected function getCommentHTML( ContestComment $comment ) { |
| 244 | + $user = User::newFromId( $comment->getField( 'user_id' ) ); |
| 245 | + |
| 246 | + $html = Html::rawElement( |
| 247 | + 'div', |
| 248 | + array( 'class' => 'contestant-comment-meta' ), |
| 249 | + wfMsgHtml( |
| 250 | + 'contest-contestant-comment-by', |
| 251 | + Linker::userLink( $comment->getField( 'user_id' ), $user->getName() ) . |
| 252 | + Linker::userToolLinks( $comment->getField( 'user_id' ), $user->getName() ) |
| 253 | + ) . '   ' .$this->getLang()->timeanddate( $comment->getField( 'time' ), true ) |
| 254 | + ); |
| 255 | + |
| 256 | + $html .= Html::rawElement( |
| 257 | + 'div', |
| 258 | + array( 'class' => 'contestant-comment-text' ), |
| 259 | + $this->getOutput()->parse( $comment->getField( 'text' ) ) |
| 260 | + ); |
| 261 | + |
| 262 | + return Html::rawElement( |
| 263 | + 'div', |
| 264 | + array( |
| 265 | + 'class' => 'contestant-comment', |
| 266 | + ), |
| 267 | + $html |
| 268 | + ); |
| 269 | + } |
| 270 | + |
168 | 271 | } |