r99626 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99625‎ | r99626 | r99627 >
Date:09:24, 12 October 2011
Author:questpc
Status:deferred (Comments)
Tags:
Comment:
Fix an bugcheck exception when storing the first poll with randomized questions into fresh database. Display error when interpretation script is defined in poll attribute but the specified page does not exist.
Modified paths:
  • /trunk/extensions/QPoll/ctrl/poll/qp_poll.php (modified) (history)
  • /trunk/extensions/QPoll/i18n/qp.i18n.php (modified) (history)
  • /trunk/extensions/QPoll/model/qp_pollstore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/i18n/qp.i18n.php
@@ -126,6 +126,7 @@
127127 'qp_error_no_answer' => 'Unanswered proposal.',
128128 'qp_error_unique' => 'Question of type unique() has more proposals than possible answers defined: Impossible to complete.',
129129 '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',
130131 'qp_error_interpretation_no_return' => 'Interpretation script returned no result.',
131132 'qp_error_structured_interpretation_is_too_long' => 'Structured interpretation is too long to be stored in database. Please correct your interpretation script.',
132133 'qp_error_no_json_decode' => 'Interpretation of poll answers requires json_decode() PHP function.',
@@ -2670,6 +2671,7 @@
26712672 'qp_error_no_answer' => 'Нет ответа на вопрос',
26722673 'qp_error_unique' => 'Опрос, имеющий тип unique(), не должен иметь больше ответов чем вопросов',
26732674 'qp_error_no_more_attempts' => 'Исчерпано количество попыток ответа на данный опрос',
 2675+ 'qp_error_no_interpretation' => 'Скрипт интерпретации не найден',
26742676 'qp_error_interpretation_no_return' => 'Скрипт интерпретации не вернул результат',
26752677 'qp_error_structured_interpretation_is_too_long' => 'Структурированная интерпретация слишком длинна для хранения в базе данных. Пожалуйста скорректируйте Ваш скрипт интерпретации.',
26762678 );
Index: trunk/extensions/QPoll/model/qp_pollstore.php
@@ -33,8 +33,11 @@
3434 /*** optional attributes ***/
3535 # dependance from other poll address in the following format: "page#otherpollid"
3636 var $dependsOn = null;
37 - # NS & DBkey of Title object representing interpretation template for Special:Pollresults page
 37+ ## NS of Title object representing interpretation template
3838 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)
3942 var $interpDBkey = null;
4043 # interpretation of user answer
4144 var $interpResult;
@@ -222,12 +225,12 @@
223226 # non-checked fields:
224227 # 'pid' is key (result of insert);
225228 # '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)
227231 return
228232 !is_null( $this->mOrderId ) &&
229233 !is_null( $this->dependsOn ) &&
230 - !is_null( $this->interpNS ) &&
231 - !is_null ( $this->interpDBkey ) &&
 234+ !is_null( $this->interpDBkey ) &&
232235 !is_null ( $this->randomQuestionCount );
233236 }
234237
@@ -251,11 +254,19 @@
252255 }
253256
254257 /**
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)
256261 */
257262 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+ }
258269 $title = Title::newFromText( $this->interpDBkey, $this->interpNS );
259 - return ( $title instanceof Title ) ? $title : null;
 270+ return ( $title instanceof Title ) ? ( $title->exists() ? $title : null ) : null;
260271 }
261272
262273 // warning: will work only after successful loadUserAlreadyVoted() or loadUserVote()
@@ -750,7 +761,7 @@
751762 if ( $this->dependsOn === null ) {
752763 $this->dependsOn = $row->dependance;
753764 }
754 - if ( $this->interpDBkey === null ) {
 765+ if ( is_null( $this->interpDBkey ) ) {
755766 $this->interpNS = $row->interpretation_namespace;
756767 $this->interpDBkey = $row->interpretation_title;
757768 }
@@ -771,6 +782,20 @@
772783 'poll_id=' . self::$db->addQuotes( $this->mPollId ) );
773784 $row = self::$db->fetchObject( $res );
774785 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
775800 self::$db->insert( 'qp_poll_desc',
776801 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 ),
777802 __METHOD__ . ':update poll' );
@@ -863,13 +888,15 @@
864889 private function interpretVote() {
865890 $this->interpResult = new qp_InterpResult();
866891 $interpTitle = $this->getInterpTitle();
 892+ if ( $interpTitle === false ) {
 893+ return;
 894+ }
867895 if ( $interpTitle === null ) {
 896+ $this->interpResult->storeErroneous = false;
 897+ $this->interpResult->setError( wfMsg( 'qp_error_no_interpretation' ) );
868898 return;
869899 }
870900 $interpArticle = new Article( $interpTitle, 0 );
871 - if ( !$interpArticle->exists() ) {
872 - return;
873 - }
874901
875902 # prepare array of user answers that will be passed to the interpreter
876903 $poll_answer = array();
Index: trunk/extensions/QPoll/ctrl/poll/qp_poll.php
@@ -200,7 +200,8 @@
201201 # generate or regenerate random questions
202202 $this->questions->randomize( $this->randomQuestionCount );
203203 $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 );
205206 $this->pollStore->setRandomQuestions();
206207 }
207208

Comments

#Comment by Siebrand (talk | contribs)   10:33, 12 October 2011

Error messages should have correct punctuation.

Please add message documentation for the newly added messages. Thanks.

#Comment by QuestPC (talk | contribs)   16:09, 14 October 2011

Tried to fix in r99779

#Comment by QuestPC (talk | contribs)   07:35, 18 October 2011

Is that better? r100109

Status & tagging log