Index: trunk/extensions/QPoll/i18n/qp.i18n.php |
— | — | @@ -126,6 +126,7 @@ |
127 | 127 | 'qp_error_no_answer' => 'Unanswered proposal.', |
128 | 128 | 'qp_error_unique' => 'Question of type unique() has more proposals than possible answers defined: Impossible to complete.', |
129 | 129 | 'qp_error_no_more_attempts' => 'You have reached maximal number of submitting attempts for this poll.', |
| 130 | + 'qp_error_no_interpretation' => 'Interpretation script does not exist', |
130 | 131 | 'qp_error_interpretation_no_return' => 'Interpretation script returned no result.', |
131 | 132 | 'qp_error_structured_interpretation_is_too_long' => 'Structured interpretation is too long to be stored in database. Please correct your interpretation script.', |
132 | 133 | 'qp_error_no_json_decode' => 'Interpretation of poll answers requires json_decode() PHP function.', |
— | — | @@ -2670,6 +2671,7 @@ |
2671 | 2672 | 'qp_error_no_answer' => 'Нет ответа на вопрос', |
2672 | 2673 | 'qp_error_unique' => 'Опрос, имеющий тип unique(), не должен иметь больше ответов чем вопросов', |
2673 | 2674 | 'qp_error_no_more_attempts' => 'Исчерпано количество попыток ответа на данный опрос', |
| 2675 | + 'qp_error_no_interpretation' => 'Скрипт интерпретации не найден', |
2674 | 2676 | 'qp_error_interpretation_no_return' => 'Скрипт интерпретации не вернул результат', |
2675 | 2677 | 'qp_error_structured_interpretation_is_too_long' => 'Структурированная интерпретация слишком длинна для хранения в базе данных. Пожалуйста скорректируйте Ваш скрипт интерпретации.', |
2676 | 2678 | ); |
Index: trunk/extensions/QPoll/model/qp_pollstore.php |
— | — | @@ -33,8 +33,11 @@ |
34 | 34 | /*** optional attributes ***/ |
35 | 35 | # dependance from other poll address in the following format: "page#otherpollid" |
36 | 36 | var $dependsOn = null; |
37 | | - # NS & DBkey of Title object representing interpretation template for Special:Pollresults page |
| 37 | + ## NS of Title object representing interpretation template |
38 | 38 | var $interpNS = 0; |
| 39 | + ## DBkey of Title object representing interpretation template |
| 40 | + # '' indicates that interpretation template does not exists (a poll without quiz) |
| 41 | + # null indicates that value is unknown (uninitialized yet) |
39 | 42 | var $interpDBkey = null; |
40 | 43 | # interpretation of user answer |
41 | 44 | var $interpResult; |
— | — | @@ -222,12 +225,12 @@ |
223 | 226 | # non-checked fields: |
224 | 227 | # 'pid' is key (result of insert); |
225 | 228 | # 'article_id' is always created by constructor |
226 | | - # 'poll_id' is a mandatory parameter of constructor |
| 229 | + # 'poll_id' is mandatory parameter of constructor |
| 230 | + # 'interpretation_namespace' is determined by 'interpretation_title' (dbkey) |
227 | 231 | return |
228 | 232 | !is_null( $this->mOrderId ) && |
229 | 233 | !is_null( $this->dependsOn ) && |
230 | | - !is_null( $this->interpNS ) && |
231 | | - !is_null ( $this->interpDBkey ) && |
| 234 | + !is_null( $this->interpDBkey ) && |
232 | 235 | !is_null ( $this->randomQuestionCount ); |
233 | 236 | } |
234 | 237 | |
— | — | @@ -251,11 +254,19 @@ |
252 | 255 | } |
253 | 256 | |
254 | 257 | /** |
255 | | - * @return Title instance of interpretation template |
| 258 | + * @return mixed Title instance of interpretation template |
| 259 | + * false, when no interpretation template is defined in poll header |
| 260 | + * null, when interpretation template does not exist (error) |
256 | 261 | */ |
257 | 262 | function getInterpTitle() { |
| 263 | + if ( is_null( $this->interpDBkey ) ) { |
| 264 | + throw new MWException( 'interpDBkey is uninitialized in ' . __METHOD__ ); |
| 265 | + } |
| 266 | + if ( $this->interpNS === 0 && $this->interpDBkey === '' ) { |
| 267 | + return false; |
| 268 | + } |
258 | 269 | $title = Title::newFromText( $this->interpDBkey, $this->interpNS ); |
259 | | - return ( $title instanceof Title ) ? $title : null; |
| 270 | + return ( $title instanceof Title ) ? ( $title->exists() ? $title : null ) : null; |
260 | 271 | } |
261 | 272 | |
262 | 273 | // warning: will work only after successful loadUserAlreadyVoted() or loadUserVote() |
— | — | @@ -750,7 +761,7 @@ |
751 | 762 | if ( $this->dependsOn === null ) { |
752 | 763 | $this->dependsOn = $row->dependance; |
753 | 764 | } |
754 | | - if ( $this->interpDBkey === null ) { |
| 765 | + if ( is_null( $this->interpDBkey ) ) { |
755 | 766 | $this->interpNS = $row->interpretation_namespace; |
756 | 767 | $this->interpDBkey = $row->interpretation_title; |
757 | 768 | } |
— | — | @@ -771,6 +782,20 @@ |
772 | 783 | 'poll_id=' . self::$db->addQuotes( $this->mPollId ) ); |
773 | 784 | $row = self::$db->fetchObject( $res ); |
774 | 785 | if ( $row == false ) { |
| 786 | + # paranoiac checks; |
| 787 | + # commented out because it is worth to fight bugs instead of hiding them |
| 788 | + /* |
| 789 | + if ( is_null( $this->interpDBkey ) ) { |
| 790 | + $this->interpDBkey = 0; |
| 791 | + } |
| 792 | + if ( is_null( $this->randomQuestionCount ) ) { |
| 793 | + $this->randomQuestionCount = 0; |
| 794 | + } |
| 795 | + if ( is_null( $this->dependsOn ) ) { |
| 796 | + $this->dependsOn = ''; |
| 797 | + } |
| 798 | + */ |
| 799 | + # end of paranoiac checks |
775 | 800 | self::$db->insert( 'qp_poll_desc', |
776 | 801 | array( 'article_id' => $this->mArticleId, 'poll_id' => $this->mPollId, 'order_id' => $this->mOrderId, 'dependance' => $this->dependsOn, 'interpretation_namespace' => $this->interpNS, 'interpretation_title' => $this->interpDBkey, 'random_question_count' => $this->randomQuestionCount ), |
777 | 802 | __METHOD__ . ':update poll' ); |
— | — | @@ -863,13 +888,15 @@ |
864 | 889 | private function interpretVote() { |
865 | 890 | $this->interpResult = new qp_InterpResult(); |
866 | 891 | $interpTitle = $this->getInterpTitle(); |
| 892 | + if ( $interpTitle === false ) { |
| 893 | + return; |
| 894 | + } |
867 | 895 | if ( $interpTitle === null ) { |
| 896 | + $this->interpResult->storeErroneous = false; |
| 897 | + $this->interpResult->setError( wfMsg( 'qp_error_no_interpretation' ) ); |
868 | 898 | return; |
869 | 899 | } |
870 | 900 | $interpArticle = new Article( $interpTitle, 0 ); |
871 | | - if ( !$interpArticle->exists() ) { |
872 | | - return; |
873 | | - } |
874 | 901 | |
875 | 902 | # prepare array of user answers that will be passed to the interpreter |
876 | 903 | $poll_answer = array(); |
Index: trunk/extensions/QPoll/ctrl/poll/qp_poll.php |
— | — | @@ -200,7 +200,8 @@ |
201 | 201 | # generate or regenerate random questions |
202 | 202 | $this->questions->randomize( $this->randomQuestionCount ); |
203 | 203 | $this->pollStore->randomQuestions = $this->questions->getUsedQuestions(); |
204 | | - # store random questions into DB |
| 204 | + # store random questions for current user into DB |
| 205 | + $this->pollStore->setLastUser( $this->username ); |
205 | 206 | $this->pollStore->setRandomQuestions(); |
206 | 207 | } |
207 | 208 | |