Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | die( 'Not an entry point.' ); |
26 | 26 | } |
27 | 27 | |
28 | | -if ( version_compare( $wgVersion, '1.16', '<' ) ) { |
29 | | - die( '<b>Error:</b> Survey requires MediaWiki 1.16 or above.' ); |
| 28 | +if ( version_compare( $wgVersion, '1.17', '<' ) ) { |
| 29 | + die( '<b>Error:</b> Survey requires MediaWiki 1.17 or above.' ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | define( 'Survey_VERSION', '0.1 alpha' ); |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | $egSurveyScriptPath .= '/Survey/resources'; |
110 | 110 | |
111 | 111 | $egSurveyMessages = array( |
112 | | - 'ext.survey.special' => array( |
| 112 | + 'ext.survey.special.surveys' => array( |
113 | 113 | 'surveys-special-confirm-delete' |
114 | 114 | ), |
115 | 115 | 'jquery.survey' => array( |
— | — | @@ -127,12 +127,12 @@ |
128 | 128 | ), |
129 | 129 | ); |
130 | 130 | |
131 | | -$wgResourceModules['ext.survey.special'] = $moduleTemplate + array( |
| 131 | +$wgResourceModules['ext.survey.special.surveys'] = $moduleTemplate + array( |
132 | 132 | 'scripts' => array( |
133 | | - 'ext.survey.special.survey.js' |
| 133 | + 'ext.survey.special.surveys.js' |
134 | 134 | ), |
135 | 135 | 'dependencies' => array( 'ext.survey' ), |
136 | | - 'messages' => $egSurveyMessages['ext.survey.special'] |
| 136 | + 'messages' => $egSurveyMessages['ext.survey.special.surveys'] |
137 | 137 | ); |
138 | 138 | |
139 | 139 | $wgResourceModules['ext.survey.jquery'] = $moduleTemplate + array( |
Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -52,5 +52,13 @@ |
53 | 53 | 'surveys-special-delete-failed' => 'Failed to delete survey.', |
54 | 54 | |
55 | 55 | // Special:TakeSurvey |
56 | | - 'surveys-takesurvey-loading' => 'Loading survey.' |
| 56 | + 'surveys-takesurvey-loading' => 'Loading survey.', |
| 57 | + |
| 58 | + // Special:Survey |
| 59 | + 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
| 60 | + 'survey-special-label-name' => 'Survey name', |
| 61 | + 'survey-special-label-enabled' => 'Survey enabled', |
| 62 | + 'survey-special-label-question' => 'Question text', |
| 63 | + 'survey-special-label-button' => 'Add question', |
| 64 | + 'survey-special-label-add' => 'New question name', |
57 | 65 | ); |
Index: trunk/extensions/Survey/specials/SpecialSurveyPage.php |
— | — | @@ -77,16 +77,7 @@ |
78 | 78 | * @param string|array $modules |
79 | 79 | */ |
80 | 80 | public function addModules( $modules ) { |
81 | | - $out = $this->getOutput(); |
82 | | - $modules = (array)$modules; |
83 | | - |
84 | | - // For backward compatibility with MW < 1.17. |
85 | | - if ( is_callable( array( $out, 'addModules' ) ) ) { |
86 | | - $out->addModules( $modules ); |
87 | | - } |
88 | | - else { |
89 | | - SurveyCompat::addResourceModules( $out, $modules ); |
90 | | - } |
| 81 | + $this->getOutput()->addModules( $modules ); |
91 | 82 | } |
92 | 83 | |
93 | 84 | } |
Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -32,6 +32,146 @@ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | parent::execute( $subPage ); |
35 | 35 | |
| 36 | + $survey = Survey::newFromName( $subPage, true ); |
| 37 | + |
| 38 | + if ( $survey === false ) { |
| 39 | + $this->showNameError(); |
| 40 | + } |
| 41 | + else { |
| 42 | + $this->showSurvey( $survey ); |
| 43 | + } |
36 | 44 | } |
37 | 45 | |
| 46 | + /** |
| 47 | + * Show error when requesting a non-existing survey. |
| 48 | + * |
| 49 | + * @since 0.1 |
| 50 | + */ |
| 51 | + protected function showNameError() { |
| 52 | + $this->getOutput()->addHTML( |
| 53 | + '<p class="errorbox">' . wfMsgHtml( 'surveys-special-unknown-name' ) . '</p>' |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Show the survey. |
| 59 | + * |
| 60 | + * @since 0.1 |
| 61 | + * |
| 62 | + * @param Survey $survey |
| 63 | + */ |
| 64 | + protected function showSurvey( Survey $survey ) { |
| 65 | + $fields = array(); |
| 66 | + |
| 67 | + $fields[] = array( |
| 68 | + 'type' => 'text', |
| 69 | + //'options' => array(), |
| 70 | + 'default' => 'ohi', |
| 71 | + 'label-message' => 'survey-special-label-name', |
| 72 | + 'required' => true |
| 73 | + ); |
| 74 | + |
| 75 | + $fields[] = array( |
| 76 | + 'type' => 'check', |
| 77 | + //'options' => array(), |
| 78 | + 'default' => 'there', |
| 79 | + 'label-message' => 'survey-special-label-enabled', |
| 80 | + 'required' => true |
| 81 | + ); |
| 82 | + |
| 83 | + foreach ( $survey->getQuestions() as $question ) { |
| 84 | + $fields[] = array( |
| 85 | + 'class' => 'SurveyQuestionField', |
| 86 | + 'options' => array( |
| 87 | + 'required' => $question->isRequired(), |
| 88 | + 'text' => $question->getText(), |
| 89 | + 'type' => $question->getType() |
| 90 | + ) |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + $fields[] = array( |
| 95 | + 'class' => 'SurveyAddQuestionField', |
| 96 | + 'default' => 'foo', |
| 97 | + 'label-message' => 'survey-special-label-add', |
| 98 | + 'id' => 'survey-add-question-text' |
| 99 | + ); |
| 100 | + |
| 101 | + // getContext was added in 1.18 and since that version is |
| 102 | + // the second argument for the HTMLForm constructor. |
| 103 | + if ( is_callable( array( $this, 'getContext' ) ) ) { |
| 104 | + $form = new HTMLForm( $fields, $this->getContext() ); |
| 105 | + } |
| 106 | + else { |
| 107 | + $form = new HTMLForm( $fields ); |
| 108 | + } |
| 109 | + |
| 110 | +// $q = new SurveyQuestion( null, 5, 'foo bar', 0, false, array(), false ); |
| 111 | +// var_dump($q->toUrlData());exit; |
| 112 | + $form->displayForm( '' ); |
| 113 | + } |
| 114 | + |
38 | 115 | } |
| 116 | + |
| 117 | +class SurveyAddQuestionField extends HTMLTextField { |
| 118 | + |
| 119 | + /* |
| 120 | + $fields[] = array( |
| 121 | + 'type' => 'text', |
| 122 | + //'options' => array(), |
| 123 | + 'default' => $question->getText(), |
| 124 | + 'label-message' => 'survey-special-label-question', |
| 125 | + 'required' => $question->isRequired() |
| 126 | + ); |
| 127 | + |
| 128 | + $fields[] = array( |
| 129 | + 'type' => 'select', |
| 130 | + 'options' => array( |
| 131 | + |
| 132 | + ), |
| 133 | + 'label-message' => 'survey-special-label-type', |
| 134 | + 'required' => $question->isRequired() |
| 135 | + ); |
| 136 | + |
| 137 | + $fields[] = array( |
| 138 | + 'class' => 'SurveyQuestionValuesField', |
| 139 | + //'options' => array(), |
| 140 | + 'default' => '', |
| 141 | + 'label-message' => 'survey-special-label-required', |
| 142 | + 'required' => true |
| 143 | + ); |
| 144 | + */ |
| 145 | + |
| 146 | + public function getInputHTML( $value ) { |
| 147 | + return parent::getInputHTML( $value ) . ' ' . Html::element( |
| 148 | + 'button', |
| 149 | + array(), |
| 150 | + wfMsg( 'survey-special-label-button' ) |
| 151 | + ); |
| 152 | + } |
| 153 | + |
| 154 | +} |
| 155 | + |
| 156 | +class SurveyQuestionField extends HTMLFormField { |
| 157 | + |
| 158 | + public function getInputHTML( $value ) { |
| 159 | + $attribs = array(); |
| 160 | + |
| 161 | + foreach ( $this->mParams['options'] as $name => $value ) { |
| 162 | + if ( is_bool( $value ) ) { |
| 163 | + $value = $value ? '1' : '0'; |
| 164 | + } |
| 165 | + elseif( is_object( $value ) || is_array( $value ) ) { |
| 166 | + $value = FormatJson::encode( $value ); |
| 167 | + } |
| 168 | + |
| 169 | + $attribs['data-' . $name] = $value; |
| 170 | + } |
| 171 | + |
| 172 | + return Html::element( |
| 173 | + 'div', |
| 174 | + $attribs |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | +} |
\ No newline at end of file |
Index: trunk/extensions/Survey/specials/SpecialSurveys.php |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | $this->displaySurveysTable( $surveys ); |
69 | 69 | } |
70 | 70 | |
71 | | - $this->addModules( 'ext.survey.special' ); |
| 71 | + $this->addModules( 'ext.survey.special.surveys' ); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
Index: trunk/extensions/Survey/INSTALL |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | |
10 | 10 | Survey requires: |
11 | 11 | |
12 | | -* MediaWiki 1.16 or above |
| 12 | +* MediaWiki 1.17 or above |
13 | 13 | * PHP 5.2 or above |
14 | 14 | |
15 | 15 | == Download == |
Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -66,15 +66,7 @@ |
67 | 67 | static $loadedJs = false; |
68 | 68 | |
69 | 69 | if ( !$loadedJs ) { |
70 | | - $po /* ParserOutput */ = $parser->getOutput(); |
71 | | - |
72 | | - // For backward compatibility with MW < 1.17. |
73 | | -// if ( is_callable( array( $po, 'addModules' ) ) ) { |
74 | | -// $po->addModules( 'ext.survey.jquery' ); |
75 | | -// } |
76 | | -// else { |
77 | | - SurveyCompat::addResourceModules( $po, 'ext.survey.jquery' ); |
78 | | -// } |
| 70 | + $parser->getOutput()->addModules( 'ext.survey.jquery' ); |
79 | 71 | } |
80 | 72 | |
81 | 73 | return Html::element( |
Index: trunk/extensions/Survey/includes/SurveyCompat.php |
— | — | @@ -15,66 +15,6 @@ |
16 | 16 | |
17 | 17 | class SurveyCompat { |
18 | 18 | |
19 | | - /** |
20 | | - * Add the resources for a resource loader module. |
21 | | - * This is needed for MediaWiki < 1.17. |
22 | | - * |
23 | | - * @since 0.1 |
24 | | - * |
25 | | - * @param OuputPage|ParserOutput $out |
26 | | - * @param array|string $modules |
27 | | - */ |
28 | | - public static function addResourceModules( $out, $modules ) { |
29 | | - global $egSurveyScriptPath, $egSurveyMessages; |
30 | | - static $addedJsMessages = false, $addedBaseJs = false; |
31 | | - |
32 | | - $modules = (array)$modules; |
33 | | - |
34 | | - if ( !$addedBaseJs ) { |
35 | | - $out->addHeadItem( |
36 | | - Html::linkedScript( $egSurveyScriptPath . '/ext.survey.js' ), |
37 | | - 'ext.survey' |
38 | | - ); |
39 | | - |
40 | | - $addedBaseJs = true; |
41 | | - } |
42 | | - |
43 | | - foreach ( $modules as $module ) { |
44 | | - switch ( $module ) { |
45 | | - case 'ext.survey.special': |
46 | | - $out->addHeadItem( |
47 | | - Html::linkedScript( $egSurveyScriptPath . '/ext.survey.special.survey.js' ), |
48 | | - $module |
49 | | - ); |
50 | | - break; |
51 | | - case 'ext.survey.jquery': |
52 | | - $out->addHeadItem( |
53 | | - Html::linkedStyle( $egSurveyScriptPath . '/fancybox/jquery.fancybox-1.3.4.css' ) . |
54 | | - Html::linkedScript( $egSurveyScriptPath . '/fancybox/jquery.fancybox-1.3.4.js' ) . |
55 | | - Html::linkedScript( $egSurveyScriptPath . '/jquery.survey.js' ), |
56 | | - $module |
57 | | - ); |
58 | | - break; |
59 | | - } |
60 | | - |
61 | | - if ( array_key_exists( $module, $egSurveyMessages ) ) { |
62 | | - if ( !$addedJsMessages ) { |
63 | | - $out->addHeadItem( Html::inlineScript( 'var wgSurveyMessages = [];' ), uniqid() ); |
64 | | - |
65 | | - $addedJsMessages = true; |
66 | | - } |
67 | | - |
68 | | - $messages = array(); |
69 | | - |
70 | | - foreach ( $egSurveyMessages[$module] as $msg ) { |
71 | | - $messages[$msg] = wfMsgNoTrans( $msg ); |
72 | | - } |
73 | | - |
74 | | - $out->addHeadItem( Html::inlineScript( |
75 | | - 'Array.push.apply( wgSurveyMessages, ' . FormatJson::encode( $messages ) . ');' |
76 | | - ), uniqid() ); |
77 | | - } |
78 | | - } |
79 | | - } |
80 | 19 | |
| 20 | + |
81 | 21 | } |
\ No newline at end of file |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | $this->surveyId = (int)$surveyId; |
90 | 90 | $this->text = $text; |
91 | 91 | $this->type = $type; |
92 | | - $this->required = $required; |
| 92 | + $this->required = (boolean)$required; |
93 | 93 | $this->answers = $answers; |
94 | 94 | $this->removed = $removed; |
95 | 95 | } |
— | — | @@ -120,6 +120,7 @@ |
121 | 121 | public static function newFromArray( array $args ) { |
122 | 122 | return new self( |
123 | 123 | array_key_exists( 'id', $args ) ? $args['id'] : null, |
| 124 | + array_key_exists( 'surveyId', $args ) ? $args['surveyId'] : null, |
124 | 125 | $args['text'], |
125 | 126 | $args['type'], |
126 | 127 | $args['required'], |
— | — | @@ -150,6 +151,7 @@ |
151 | 152 | */ |
152 | 153 | public function toArray() { |
153 | 154 | $args = array( |
| 155 | + 'surveyId' => $this->surveyId, |
154 | 156 | 'text' => $this->text, |
155 | 157 | 'type' => $this->type, |
156 | 158 | 'required' => $this->required, |
— | — | @@ -255,4 +257,37 @@ |
256 | 258 | ); |
257 | 259 | } |
258 | 260 | |
| 261 | + /** |
| 262 | + * Gets the question text. |
| 263 | + * |
| 264 | + * @since 0.1 |
| 265 | + * |
| 266 | + * @return string |
| 267 | + */ |
| 268 | + public function getText() { |
| 269 | + return $this->text; |
| 270 | + } |
| 271 | + |
| 272 | + /** |
| 273 | + * Gets the questions type. |
| 274 | + * |
| 275 | + * @since 0.1 |
| 276 | + * |
| 277 | + * @return string |
| 278 | + */ |
| 279 | + public function getType() { |
| 280 | + return $this->type; |
| 281 | + } |
| 282 | + |
| 283 | + /** |
| 284 | + * Gets if the question is required. |
| 285 | + * |
| 286 | + * @since 0.1 |
| 287 | + * |
| 288 | + * @return boolean |
| 289 | + */ |
| 290 | + public function isRequired() { |
| 291 | + return $this->required; |
| 292 | + } |
| 293 | + |
259 | 294 | } |
Index: trunk/extensions/Survey/resources/ext.survey.special.survey.js |
— | — | @@ -8,40 +8,6 @@ |
9 | 9 | |
10 | 10 | (function( $ ) { $( document ).ready( function() { |
11 | 11 | |
12 | | - function deleteSurvey( options, successCallback, failCallback ) { |
13 | | - $.getJSON( |
14 | | - wgScriptPath + '/api.php', |
15 | | - { |
16 | | - 'action': 'deletesurvey', |
17 | | - 'format': 'json', |
18 | | - 'ids': options.id |
19 | | - }, |
20 | | - function( data ) { |
21 | | - if ( data.success ) { |
22 | | - successCallback(); |
23 | | - } |
24 | | - else { |
25 | | - failCallback( survey.msg( 'surveys-special-delete-failed' ) ); |
26 | | - } |
27 | | - } |
28 | | - ); |
29 | | - } |
| 12 | + |
30 | 13 | |
31 | | - $( '.survey-delete' ).click( function() { |
32 | | - $this = $( this ); |
33 | | - |
34 | | - if ( confirm( survey.msg( 'surveys-special-confirm-delete' ) ) ) { |
35 | | - deleteSurvey( |
36 | | - { id: $this.attr( 'data-survey-id' ) }, |
37 | | - function() { |
38 | | - $this.closest( 'tr' ).slideUp( 'slow', function() { $( this ).remove(); } ); |
39 | | - }, |
40 | | - function( error ) { |
41 | | - alert( error ); |
42 | | - } |
43 | | - ); |
44 | | - } |
45 | | - return false; |
46 | | - } ); |
47 | | - |
48 | 14 | } ); })( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/Survey/resources/ext.survey.special.surveys.js |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Survey MediaWiki extension. |
| 4 | + * @see https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:Survey |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $ ) { $( document ).ready( function() { |
| 11 | + |
| 12 | + function deleteSurvey( options, successCallback, failCallback ) { |
| 13 | + $.getJSON( |
| 14 | + wgScriptPath + '/api.php', |
| 15 | + { |
| 16 | + 'action': 'deletesurvey', |
| 17 | + 'format': 'json', |
| 18 | + 'ids': options.id |
| 19 | + }, |
| 20 | + function( data ) { |
| 21 | + if ( data.success ) { |
| 22 | + successCallback(); |
| 23 | + } |
| 24 | + else { |
| 25 | + failCallback( survey.msg( 'surveys-special-delete-failed' ) ); |
| 26 | + } |
| 27 | + } |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + $( '.survey-delete' ).click( function() { |
| 32 | + $this = $( this ); |
| 33 | + |
| 34 | + if ( confirm( survey.msg( 'surveys-special-confirm-delete' ) ) ) { |
| 35 | + deleteSurvey( |
| 36 | + { id: $this.attr( 'data-survey-id' ) }, |
| 37 | + function() { |
| 38 | + $this.closest( 'tr' ).slideUp( 'slow', function() { $( this ).remove(); } ); |
| 39 | + }, |
| 40 | + function( error ) { |
| 41 | + alert( error ); |
| 42 | + } |
| 43 | + ); |
| 44 | + } |
| 45 | + return false; |
| 46 | + } ); |
| 47 | + |
| 48 | +} ); })( jQuery ); |
\ No newline at end of file |
Property changes on: trunk/extensions/Survey/resources/ext.survey.special.surveys.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 49 | + native |