Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -178,6 +178,7 @@ |
179 | 179 | 'messages' => array( |
180 | 180 | 'survey-jquery-submit', |
181 | 181 | 'survey-jquery-finish', |
| 182 | + 'survey-jquery-load-failed', |
182 | 183 | ) |
183 | 184 | ); |
184 | 185 | |
Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -59,7 +59,10 @@ |
60 | 60 | 'survey-user-type-anon' => 'Anonymouse users', |
61 | 61 | |
62 | 62 | // 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.', |
64 | 67 | |
65 | 68 | // Special:Survey |
66 | 69 | 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
— | — | @@ -88,4 +91,5 @@ |
89 | 92 | // Survey jQuery |
90 | 93 | 'survey-jquery-submit' => 'Submit', |
91 | 94 | 'survey-jquery-finish' => 'Finish', |
| 95 | + 'survey-jquery-load-failed' => 'Could not load the survey.', |
92 | 96 | ); |
Index: trunk/extensions/Survey/specials/SpecialTakeSurvey.php |
— | — | @@ -32,13 +32,48 @@ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | parent::execute( $subPage ); |
35 | 35 | |
| 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 ) { |
36 | 58 | $this->getOutput()->addWikiText( Xml::element( |
37 | 59 | 'survey', |
38 | 60 | array( |
39 | | - 'name' => $subPage |
| 61 | + 'name' => $surveyName, |
| 62 | + 'require-enabled' => $GLOBALS['wgUser']->isAllowed( 'surveyadmin' ) ? '0' : '1' |
40 | 63 | ), |
41 | 64 | wfMsg( 'surveys-takesurvey-loading' ) |
42 | 65 | ) ); |
43 | 66 | } |
44 | 67 | |
| 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 | + |
45 | 80 | } |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -179,6 +179,19 @@ |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
| 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 | + /** |
183 | 196 | * Selects the the specified fields of the records matching the provided |
184 | 197 | * conditions. |
185 | 198 | * |
Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | */ |
36 | 36 | public function __construct( array $args, $contents = null ) { |
37 | 37 | $this->parameters = $args; |
| 38 | + $this->contents = $contents; |
38 | 39 | |
39 | 40 | $args = filter_var_array( $args, $this->getSurveyParameters() ); |
40 | 41 | |
— | — | @@ -89,6 +90,7 @@ |
90 | 91 | return array( |
91 | 92 | 'id' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 1 ) ), |
92 | 93 | 'name' => array(), |
| 94 | + 'require-enabled' => array( 'filter' => FILTER_VALIDATE_INT, 'options' => array( 'min_range' => 0, 'max_range' => 1 ) ), |
93 | 95 | ); |
94 | 96 | } |
95 | 97 | |
Index: trunk/extensions/Survey/resources/jquery.survey.js |
— | — | @@ -20,10 +20,13 @@ |
21 | 21 | 'list': 'surveys', |
22 | 22 | 'format': 'json', |
23 | 23 | 'suincquestions': 1, |
24 | | - 'suenabled': 1, |
25 | 24 | 'suprops': '*' |
26 | 25 | }; |
27 | 26 | |
| 27 | + if ( options.requireEnabled ) { |
| 28 | + requestArgs['suenabled'] = 1; |
| 29 | + } |
| 30 | + |
28 | 31 | requestArgs[ 'su' + this.identifierType + 's' ] = this.identifier; |
29 | 32 | |
30 | 33 | $.getJSON( |
— | — | @@ -276,11 +279,16 @@ |
277 | 280 | |
278 | 281 | if ( this.identifier !== null ) { |
279 | 282 | this.getSurveyData( |
280 | | - {}, |
| 283 | + { |
| 284 | + 'requireEnabled': $this.attr( 'survey-data-require-enabled' ) !== '0' |
| 285 | + }, |
281 | 286 | function( surveyData ) { |
282 | | - for ( i in surveyData ) { |
283 | | - _this.initSurvey( surveyData[i] ); |
| 287 | + if ( 0 in surveyData ) { |
| 288 | + _this.initSurvey( surveyData[0] ); |
284 | 289 | } |
| 290 | + else { |
| 291 | + $this.text( mw.msg( 'survey-jquery-load-failed' ) ); |
| 292 | + } |
285 | 293 | } |
286 | 294 | ); |
287 | 295 | } |