r99360 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99359‎ | r99360 | r99361 >
Date:18:05, 9 October 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
initial woek on commenting amd voting ui for judges
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestPage.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestant.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -165,6 +165,9 @@
166166 'contest-contestant-header-comments' => 'Amount of comments',
167167 'contest-contestant-submission-url' => 'Submission',
168168 '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'
169172 );
170173
171174 /** Message documentation (Message documentation)
Index: trunk/extensions/Contest/specials/SpecialContestPage.php
@@ -146,8 +146,12 @@
147147 *
148148 * @since 0.1
149149 */
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() ) );
152156 }
153157
154158 }
Index: trunk/extensions/Contest/specials/SpecialContestant.php
@@ -34,30 +34,80 @@
3535 return;
3636 }
3737
38 - $out = $this->getOutput();
39 -
4038 $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) );
4139
4240 if ( $contestant === false ) {
43 - $out->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
 41+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
4442 }
4543 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()
5173 ) );
5274
53 - $this->subPage = str_replace( ' ', '_', $contestant->getContest()->getField( 'name' ) );
54 - $this->displayNavigation();
 75+ $success = $comment->writeToDB();
5576
56 - $this->showGeneralInfo( $contestant );
57 - $this->showRating( $contestant );
58 - $this->showComments( $contestant );
 77+ if ( $success ) {
 78+ ContestContestant::s()->addToField( 'comments', 1 );
 79+ }
5980 }
 81+
 82+ if ( $success ) {
 83+ // TODO: rating shizzle
 84+ }
 85+
 86+ return $success;
6087 }
6188
 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+
62112 /**
63113 * Display the general contestant info.
64114 *
@@ -139,8 +189,6 @@
140190 return $stats;
141191 }
142192
143 - // TODO: show rating and commenting controls
144 -
145193 /**
146194 * Display the current rating the judge gave if any and a control to
147195 * (re)-rate.
@@ -161,7 +209,62 @@
162210 * @param ContestContestant $contestant
163211 */
164212 protected function showComments( ContestContestant $contestant ) {
 213+ $out = $this->getOutput();
165214
 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' ) );
166232 }
167233
 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+ ) . '&#160;&#160;&#160;' .$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+
168271 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r99366follow up to r99360 & updated urlsjeroendedauw18:51, 9 October 2011
r99745Address fixme in r99360: submit to $wgScript and set a hidden title fieldcatrope23:26, 13 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   16:57, 11 October 2011

This will not work on certain url configurations.

+$out->addHTML( '<form method="post" action="' . htmlspecialchars( $this->getTitle( $this->subPage )->getLocalURL() ) . '">' );
#Comment by Jeroen De Dauw (talk | contribs)   17:08, 11 October 2011

Can you elaborate on that? What will not work, and how can it be fixed?

#Comment by Nikerabbit (talk | contribs)   17:30, 11 October 2011

If the article path is /index.php?title=bar&daa=lasagne, browsers will submit to index.php and ignore everything after ?. The usual fix is to submit to $wgScript, and add Html::hidden( 'title', $title );.

Status & tagging log