r96738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96737‎ | r96738 | r96739 >
Date:20:40, 10 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special:takesurvey
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyDBClass.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyTag.php (modified) (history)
  • /trunk/extensions/Survey/resources/jquery.survey.js (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialTakeSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.php
@@ -178,6 +178,7 @@
179179 'messages' => array(
180180 'survey-jquery-submit',
181181 'survey-jquery-finish',
 182+ 'survey-jquery-load-failed',
182183 )
183184 );
184185
Index: trunk/extensions/Survey/Survey.i18n.php
@@ -59,7 +59,10 @@
6060 'survey-user-type-anon' => 'Anonymouse users',
6161
6262 // Special:TakeSurvey
63 - 'surveys-takesurvey-loading' => 'Loading survey.',
 63+ 'surveys-takesurvey-loading' => 'Loading survey...',
 64+ 'surveys-takesurvey-nosuchsurvey' => 'There requested survey does not exist.',
 65+ 'surveys-takesurvey-warn-notenabled' => 'This survey has not been enabled yet, and therefore is not visible to users.',
 66+ 'surveys-takesurvey-surveynotenabled' => 'The requested survey has not been enabled yet.',
6467
6568 // Special:Survey
6669 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
@@ -88,4 +91,5 @@
8992 // Survey jQuery
9093 'survey-jquery-submit' => 'Submit',
9194 'survey-jquery-finish' => 'Finish',
 95+ 'survey-jquery-load-failed' => 'Could not load the survey.',
9296 );
Index: trunk/extensions/Survey/specials/SpecialTakeSurvey.php
@@ -32,13 +32,48 @@
3333 public function execute( $subPage ) {
3434 parent::execute( $subPage );
3535
 36+ $survey = Survey::selectRow(
 37+ array( 'enabled' ),
 38+ array( 'name' => $subPage )
 39+ );
 40+
 41+ if ( $survey === false ) {
 42+ $this->showError( 'surveys-takesurvey-nosuchsurvey' );
 43+ }
 44+ else if ( $survey->getField( 'enabled' ) ) {
 45+ $this->displaySurvey( $subPage );
 46+ }
 47+ else if ( $GLOBALS['wgUser']->isAllowed( 'surveyadmin' ) ) {
 48+ $this->showWarning( 'surveys-takesurvey-warn-notenabled' );
 49+ $this->getOutput()->addHTML( '<br /><br /><br /><br />' );
 50+ $this->displaySurvey( $subPage );
 51+ }
 52+ else {
 53+ $this->showError( 'surveys-takesurvey-surveynotenabled' );
 54+ }
 55+ }
 56+
 57+ protected function displaySurvey( $surveyName ) {
3658 $this->getOutput()->addWikiText( Xml::element(
3759 'survey',
3860 array(
39 - 'name' => $subPage
 61+ 'name' => $surveyName,
 62+ 'require-enabled' => $GLOBALS['wgUser']->isAllowed( 'surveyadmin' ) ? '0' : '1'
4063 ),
4164 wfMsg( 'surveys-takesurvey-loading' )
4265 ) );
4366 }
4467
 68+ protected function showError( $message ) {
 69+ $this->getOutput()->addHTML(
 70+ '<p class="visualClear errorbox">' . wfMsgHtml( $message ) . '</p>'
 71+ );
 72+ }
 73+
 74+ protected function showWarning( $message ) {
 75+ $this->getOutput()->addHTML(
 76+ '<p class="visualClear warningbox">' . wfMsgHtml( $message ) . '</p>'
 77+ );
 78+ }
 79+
4580 }
Index: trunk/extensions/Survey/includes/SurveyDBClass.php
@@ -179,6 +179,19 @@
180180 }
181181
182182 /**
 183+ * Returns if there is at least one record matching the provided conditions.
 184+ *
 185+ * @since 0.1
 186+ *
 187+ * @param array $conditions
 188+ *
 189+ * @return boolean
 190+ */
 191+ public static function has( array $conditions = array() ) {
 192+ return static::selectRow( array( static::getIDField() ), $conditions ) !== false;
 193+ }
 194+
 195+ /**
183196 * Selects the the specified fields of the records matching the provided
184197 * conditions.
185198 *
Index: trunk/extensions/Survey/includes/SurveyTag.php
@@ -34,6 +34,7 @@
3535 */
3636 public function __construct( array $args, $contents = null ) {
3737 $this->parameters = $args;
 38+ $this->contents = $contents;
3839
3940 $args = filter_var_array( $args, $this->getSurveyParameters() );
4041
@@ -89,6 +90,7 @@
9091 return array(
9192 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ),
9293 'name' => array(),
 94+ 'require-enabled' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 0, 'max_range' => 1 ) ),
9395 );
9496 }
9597
Index: trunk/extensions/Survey/resources/jquery.survey.js
@@ -20,10 +20,13 @@
2121 'list': 'surveys',
2222 'format': 'json',
2323 'suincquestions': 1,
24 - 'suenabled': 1,
2524 'suprops': '*'
2625 };
2726
 27+ if ( options.requireEnabled ) {
 28+ requestArgs['suenabled'] = 1;
 29+ }
 30+
2831 requestArgs[ 'su' + this.identifierType + 's' ] = this.identifier;
2932
3033 $.getJSON(
@@ -276,11 +279,16 @@
277280
278281 if ( this.identifier !== null ) {
279282 this.getSurveyData(
280 - {},
 283+ {
 284+ 'requireEnabled': $this.attr( 'survey-data-require-enabled' ) !== '0'
 285+ },
281286 function( surveyData ) {
282 - for ( i in surveyData ) {
283 - _this.initSurvey( surveyData[i] );
 287+ if ( 0 in surveyData ) {
 288+ _this.initSurvey( surveyData[0] );
284289 }
 290+ else {
 291+ $this.text( mw.msg( 'survey-jquery-load-failed' ) );
 292+ }
285293 }
286294 );
287295 }

Status & tagging log