r96763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96762‎ | r96763 | r96764 >
Date:00:16, 11 September 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
work on special:surveystats
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyQuestion.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.i18n.php
@@ -44,6 +44,10 @@
4545 'survey-question-type-textarea' => 'Multi line text field',
4646 'survey-question-type-check' => 'Checkbox',
4747
 48+ 'survey-navigation-edit' => '[[Special:Survey/$1|Edit this survey]]',
 49+ 'survey-navigation-take' => '[[Special:TakeSurvey/$1|Take this survey]]',
 50+ 'survey-navigation-list' => '[[Special:Surveys|Surveys list]]',
 51+
4852 // Special:Surveys
4953 'surveys-special-addnew' => 'Add a new survey',
5054 'surveys-special-namedoc' => 'Enter the name for the new survey.',
@@ -88,6 +92,7 @@
8993 'surveys-surveystats-question-text' => 'Question text',
9094 'surveys-surveystats-question-answercount' => 'Amount of answers',
9195 'surveys-surveystats-question-answers' => 'Most provided answers',
 96+ 'surveys-surveystats-question-answer' => '$1 ($2 {{PLURAL:$3|answer|answers}})',
9297
9398 // Special:Survey
9499 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php
@@ -38,7 +38,9 @@
3939 $subPage = trim( $subPage );
4040
4141 if ( Survey::has( array( 'name' => $subPage ) ) ) {
42 - $this->displayStats( Survey::newFromName( $subPage ) );
 42+ $survey = Survey::newFromName( $subPage );
 43+ $this->displayNavigation( $survey );
 44+ $this->displayStats( $survey );
4345 }
4446 else {
4547 $this->showError( 'surveys-surveystats-nosuchsurvey' );
@@ -47,6 +49,23 @@
4850 }
4951
5052 /**
 53+ * Display links to edit and take the survey.
 54+ *
 55+ * @since 0.1
 56+ *
 57+ * @param Survey $survey
 58+ */
 59+ protected function displayNavigation( Survey $survey ) {
 60+ $links = array(
 61+ wfMsgExt( 'survey-navigation-edit', 'parseinline', $survey->getField( 'name' ) ),
 62+ wfMsgExt( 'survey-navigation-take', 'parseinline', $survey->getField( 'name' ) ),
 63+ wfMsgExt( 'survey-navigation-list', 'parseinline' )
 64+ );
 65+
 66+ $this->getOutput()->addHTML( Html::rawElement( 'p', array(), implode( ' - ', $links ) ) );
 67+ }
 68+
 69+ /**
5170 * Display the statistics that go with the survey.
5271 *
5372 * @since 0.1
@@ -136,7 +155,7 @@
137156 '<th>' . wfMsgHtml( 'surveys-surveystats-question-type' ) . '</th>' .
138157 '<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-text' ) . '</th>' .
139158 '<th>' . wfMsgHtml( 'surveys-surveystats-question-answercount' ) . '</th>' .
140 - //'<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-answers' ) . '</th>' .
 159+ '<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-answers' ) . '</th>' .
141160 '</tr></thead>'
142161 );
143162
@@ -189,13 +208,46 @@
190209 SurveyAnswer::count( array( 'question_id' => $question->getId() ) )
191210 ) );
192211
193 -// $out->addHTML( Html::element(
194 -// 'td',
195 -// array(),
196 -// '...'
197 -// ) );
 212+ $out->addHTML( Html::rawElement(
 213+ 'td',
 214+ array(),
 215+ $this->getAnswerList( $question )
 216+ ) );
198217
199218 $out->addHTML( '</tr>' );
200219 }
201220
 221+ protected function getAnswerList( SurveyQuestion $question ) {
 222+ if ( $question->isRestrictiveType() ) {
 223+ $list = '<ul>';
 224+
 225+ $answers = array();
 226+
 227+ foreach ( $question->getField( 'answers' ) as $answer ) {
 228+ $answers[$answer] = SurveyAnswer::count( array( 'text' => $answer ) );
 229+ }
 230+
 231+ asort( $answers, SORT_NUMERIC );
 232+
 233+ foreach ( array_reverse( $answers ) as $answer => $answerCount ) {
 234+ $list .= Html::element(
 235+ 'li',
 236+ array(),
 237+ wfMsgExt(
 238+ 'surveys-surveystats-question-answer',
 239+ 'parsemag',
 240+ $answer,
 241+ $GLOBALS['wgLang']->formatNum( $answerCount ),
 242+ $answerCount
 243+ )
 244+ );
 245+ }
 246+
 247+ return $list . '</ul>';
 248+ }
 249+ else {
 250+ return '';
 251+ }
 252+ }
 253+
202254 }
Index: trunk/extensions/Survey/includes/SurveyQuestion.php
@@ -162,16 +162,28 @@
163163
164164 if ( $messageMap === false ) {
165165 $messageMap = array(
166 - self::$TYPE_TEXT = 'text',
167 - self::$TYPE_NUMBER = 'number',
168 - self::$TYPE_SELECT = 'select',
169 - self::$TYPE_RADIO = 'radio',
170 - self::$TYPE_TEXTAREA = 'textarea',
171 - self::$TYPE_CHECK = 'check',
 166+ self::$TYPE_TEXT => 'text',
 167+ self::$TYPE_NUMBER => 'number',
 168+ self::$TYPE_SELECT => 'select',
 169+ self::$TYPE_RADIO => 'radio',
 170+ self::$TYPE_TEXTAREA => 'textarea',
 171+ self::$TYPE_CHECK => 'check',
172172 );
173173 }
174174
175175 return 'survey-question-type-' . $messageMap[$type];
176176 }
177177
 178+ /**
 179+ * Returns if the type of the question is restrictive,
 180+ * ie if the question input only allows certain answers.
 181+ *
 182+ * @since 0.1
 183+ *
 184+ * @return boolean
 185+ */
 186+ public function isRestrictiveType() {
 187+ return in_array( $this->getField( 'type' ), array( self::$TYPE_SELECT, self::$TYPE_RADIO ) );
 188+ }
 189+
178190 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96780Follow up to r96763; fixed i18n issuesjeroendedauw14:39, 11 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   10:02, 11 September 2011

At least 'surveys-surveystats-question-answer' needs documentation. And you don't need to provide the number twice, {{PLURAL}} handles formatted numbers very well (it might even cause bugs with unformatted numbers).

#Comment by Jeroen De Dauw (talk | contribs)   14:40, 11 September 2011

Oh, neat. Fixed by r96780 :)

Status & tagging log