r96748 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96747‎ | r96748 | r96749 >
Date:22:06, 10 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special:surveystats
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiSubmitSurvey.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyDBClass.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyTag.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.i18n.php
@@ -67,6 +67,12 @@
6868
6969 // Special:SurveyStats
7070 'surveys-surveystats-nosuchsurvey' => 'The requested survey does not exist. A list of available surveys can be found on [[Special:Surveys]]',
 71+ 'surveys-surveystats-name' => 'Survey name',
 72+ 'surveys-surveystats-status' => 'Survey status',
 73+ 'surveys-surveystats-questioncount' => 'Number of questions',
 74+ 'surveys-surveystats-submissioncount' => 'Number of submissions',
 75+ 'surveys-surveystats-enabled' => 'Enabled',
 76+ 'surveys-surveystats-disabled' => 'Disabled',
7177
7278 // Special:Survey
7379 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php
@@ -47,7 +47,51 @@
4848 }
4949
5050 protected function displayStats( Survey $survey ) {
51 - // TODO
 51+ $this->displaySummary( $this->getSummaryData( $survey ) );
 52+
 53+ // TODO: magic
 54+ //$this->displayQuestionStats();
5255 }
5356
 57+ protected function getSummaryData( Survey $survey ) {
 58+ $stats = array();
 59+
 60+ $stats['name'] = $survey->getField( 'name' );
 61+ $stats['status'] = wfMsg( 'surveys-surveystats-' . ( $survey->getField( 'enabled' ) ? 'enabled' : 'disabled' ) );
 62+ $stats['questioncount'] = count( $survey->getQuestions() ) ;
 63+ $stats['submissioncount'] = SurveySubmission::count( array( 'survey_id' => $survey->getId() ) );
 64+
 65+ return $stats;
 66+ }
 67+
 68+ protected function displaySummary( array $stats ) {
 69+ $out = $this->getOutput();
 70+
 71+ $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable survey-stats' ) ) );
 72+
 73+ foreach ( $stats as $stat => $value ) {
 74+ $out->addHTML( '<tr>' );
 75+
 76+ $out->addHTML( Html::element(
 77+ 'th',
 78+ array( 'class' => 'survey-stat-name' ),
 79+ wfMsg( 'surveys-surveystats-' . $stat )
 80+ ) );
 81+
 82+ $out->addHTML( Html::element(
 83+ 'td',
 84+ array( 'class' => 'survey-stat-value' ),
 85+ $value
 86+ ) );
 87+
 88+ $out->addHTML( '</tr>' );
 89+ }
 90+
 91+ $out->addHTML( Html::closeElement( 'table' ) );
 92+ }
 93+
 94+ protected function displayQuestionStats( SurveyQuestion $question ) {
 95+
 96+ }
 97+
5498 }
Index: trunk/extensions/Survey/includes/SurveyDBClass.php
@@ -137,7 +137,7 @@
138138
139139 /**
140140 * Selects the the specified fields of the records matching the provided
141 - * conditions.
 141+ * conditions. Field names get prefixed.
142142 *
143143 * @since 0.1
144144 *
@@ -148,8 +148,16 @@
149149 * @return array of self
150150 */
151151 public static function select( $fields = null, array $conditions = array(), array $options = array() ) {
152 - $result = static::rawSelect( $fields, $conditions, $options );
 152+ if ( is_null( $fields ) ) {
 153+ $fields = array_keys( static::getFieldTypes() );
 154+ }
153155
 156+ $result = static::rawSelect(
 157+ static::getPrefixedFields( $fields ),
 158+ static::getPrefixedValues( $conditions ),
 159+ $options
 160+ );
 161+
154162 $objects = array();
155163
156164 foreach ( $result as $record ) {
@@ -161,6 +169,7 @@
162170
163171 /**
164172 * Selects the the specified fields of the first matching record.
 173+ * Field names get prefixed.
165174 *
166175 * @since 0.1
167176 *
@@ -180,6 +189,7 @@
181190
182191 /**
183192 * Returns if there is at least one record matching the provided conditions.
 193+ * Condition field names get prefixed.
184194 *
185195 * @since 0.1
186196 *
@@ -192,8 +202,29 @@
193203 }
194204
195205 /**
 206+ * Returns the amount of matching records.
 207+ * Condition field names get prefixed.
 208+ *
 209+ * @since 0.1
 210+ *
 211+ * @param array $conditions
 212+ * @param array $options
 213+ *
 214+ * @return integer
 215+ */
 216+ public static function count( array $conditions = array(), array $options = array() ) {
 217+ $res = static::rawSelect(
 218+ array( 'COUNT(*) AS rowcount' ),
 219+ static::getPrefixedValues( $conditions ),
 220+ $options
 221+ )->fetchObject();
 222+
 223+ return $res->rowcount;
 224+ }
 225+
 226+ /**
196227 * Selects the the specified fields of the records matching the provided
197 - * conditions.
 228+ * conditions. Field names do NOT get prefixed.
198229 *
199230 * @since 0.1
200231 *
@@ -203,17 +234,13 @@
204235 *
205236 * @return ResultWrapper
206237 */
207 - public static function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
208 - if ( is_null( $fields ) ) {
209 - $fields = array_keys( static::getFieldTypes() );
210 - }
211 -
 238+ public static function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
212239 $dbr = wfGetDB( DB_SLAVE );
213240
214241 return $dbr->select(
215242 static::getDBTable(),
216 - static::getPrefixedFields( $fields ),
217 - count( $conditions ) == 0 ? '' : static::getPrefixedValues( $conditions ),
 243+ $fields,
 244+ count( $conditions ) == 0 ? '' : $conditions,
218245 '',
219246 $options
220247 );
Index: trunk/extensions/Survey/includes/SurveyTag.php
@@ -48,7 +48,8 @@
4949 }
5050
5151 $this->parameters['class'] = 'surveytag';
52 - $this->parameters['survey-data-token'] = $GLOBALS['wgUser']->editToken();
 52+ $this->parameters['survey-data-token'] =
 53+ $GLOBALS['wgUser']->editToken( serialize( array( 'submitsurvey', $GLOBALS['wgUser']->getName() ) ) );
5354 } else {
5455 throw new MWException( 'Invalid parameters for survey tag.' );
5556 }
Index: trunk/extensions/Survey/api/ApiSubmitSurvey.php
@@ -64,7 +64,7 @@
6565 }
6666
6767 public function getTokenSalt() {
68 - return 'submitsurvey';
 68+ return serialize( array( 'submitsurvey', $GLOBALS['wgUser']->getName() ) );
6969 }
7070
7171 public function mustBePosted() {

Status & tagging log