http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99626
Revision: 99626
Author: questpc
Date: 2011-10-12 09:24:23 +0000 (Wed, 12 Oct 2011)
Log Message:
-----------
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
trunk/extensions/QPoll/i18n/qp.i18n.php
trunk/extensions/QPoll/model/qp_pollstore.php
Modified: trunk/extensions/QPoll/ctrl/poll/qp_poll.php
===================================================================
--- trunk/extensions/QPoll/ctrl/poll/qp_poll.php 2011-10-12 09:17:44 UTC
(rev 99625)
+++ trunk/extensions/QPoll/ctrl/poll/qp_poll.php 2011-10-12 09:24:23 UTC
(rev 99626)
@@ -200,7 +200,8 @@
# generate or regenerate random questions
$this->questions->randomize( $this->randomQuestionCount );
$this->pollStore->randomQuestions =
$this->questions->getUsedQuestions();
- # store random questions into DB
+ # store random questions for current user into DB
+ $this->pollStore->setLastUser( $this->username );
$this->pollStore->setRandomQuestions();
}
Modified: trunk/extensions/QPoll/i18n/qp.i18n.php
===================================================================
--- trunk/extensions/QPoll/i18n/qp.i18n.php 2011-10-12 09:17:44 UTC (rev
99625)
+++ trunk/extensions/QPoll/i18n/qp.i18n.php 2011-10-12 09:24:23 UTC (rev
99626)
@@ -126,6 +126,7 @@
'qp_error_no_answer' => 'Unanswered proposal.',
'qp_error_unique' => 'Question of type unique() has more proposals than
possible answers defined: Impossible to complete.',
'qp_error_no_more_attempts' => 'You have reached maximal number of
submitting attempts for this poll.',
+ 'qp_error_no_interpretation' => 'Interpretation script does not exist',
'qp_error_interpretation_no_return' => 'Interpretation script returned
no result.',
'qp_error_structured_interpretation_is_too_long' => 'Structured
interpretation is too long to be stored in database. Please correct your
interpretation script.',
'qp_error_no_json_decode' => 'Interpretation of poll answers requires
json_decode() PHP function.',
@@ -2670,6 +2671,7 @@
'qp_error_no_answer' => 'Нет ответа на вопрос',
'qp_error_unique' => 'Опрос, имеющий тип unique(), не должен иметь
больше ответов чем вопросов',
'qp_error_no_more_attempts' => 'Исчерпано количество попыток ответа на
данный опрос',
+ 'qp_error_no_interpretation' => 'Скрипт интерпретации не найден',
'qp_error_interpretation_no_return' => 'Скрипт интерпретации не вернул
результат',
'qp_error_structured_interpretation_is_too_long' => 'Структурированная
интерпретация слишком длинна для хранения в базе данных. Пожалуйста
скорректируйте Ваш скрипт интерпретации.',
);
Modified: trunk/extensions/QPoll/model/qp_pollstore.php
===================================================================
--- trunk/extensions/QPoll/model/qp_pollstore.php 2011-10-12 09:17:44 UTC
(rev 99625)
+++ trunk/extensions/QPoll/model/qp_pollstore.php 2011-10-12 09:24:23 UTC
(rev 99626)
@@ -33,8 +33,11 @@
/*** optional attributes ***/
# dependance from other poll address in the following format:
"page#otherpollid"
var $dependsOn = null;
- # NS & DBkey of Title object representing interpretation template for
Special:Pollresults page
+ ## NS of Title object representing interpretation template
var $interpNS = 0;
+ ## DBkey of Title object representing interpretation template
+ # '' indicates that interpretation template does not exists (a poll
without quiz)
+ # null indicates that value is unknown (uninitialized yet)
var $interpDBkey = null;
# interpretation of user answer
var $interpResult;
@@ -222,12 +225,12 @@
# non-checked fields:
# 'pid' is key (result of insert);
# 'article_id' is always created by constructor
- # 'poll_id' is a mandatory parameter of constructor
+ # 'poll_id' is mandatory parameter of constructor
+ # 'interpretation_namespace' is determined by
'interpretation_title' (dbkey)
return
!is_null( $this->mOrderId ) &&
!is_null( $this->dependsOn ) &&
- !is_null( $this->interpNS ) &&
- !is_null ( $this->interpDBkey ) &&
+ !is_null( $this->interpDBkey ) &&
!is_null ( $this->randomQuestionCount );
}
@@ -251,11 +254,19 @@
}
/**
- * @return Title instance of interpretation template
+ * @return mixed Title instance of interpretation template
+ * false, when no interpretation template is defined in
poll header
+ * null, when interpretation template does not exist
(error)
*/
function getInterpTitle() {
+ if ( is_null( $this->interpDBkey ) ) {
+ throw new MWException( 'interpDBkey is uninitialized in
' . __METHOD__ );
+ }
+ if ( $this->interpNS === 0 && $this->interpDBkey === '' ) {
+ return false;
+ }
$title = Title::newFromText( $this->interpDBkey,
$this->interpNS );
- return ( $title instanceof Title ) ? $title : null;
+ return ( $title instanceof Title ) ? ( $title->exists() ?
$title : null ) : null;
}
// warning: will work only after successful loadUserAlreadyVoted() or
loadUserVote()
@@ -750,7 +761,7 @@
if ( $this->dependsOn === null ) {
$this->dependsOn = $row->dependance;
}
- if ( $this->interpDBkey === null ) {
+ if ( is_null( $this->interpDBkey ) ) {
$this->interpNS =
$row->interpretation_namespace;
$this->interpDBkey = $row->interpretation_title;
}
@@ -771,6 +782,20 @@
'poll_id=' . self::$db->addQuotes( $this->mPollId ) );
$row = self::$db->fetchObject( $res );
if ( $row == false ) {
+ # paranoiac checks;
+ # commented out because it is worth to fight bugs
instead of hiding them
+ /*
+ if ( is_null( $this->interpDBkey ) ) {
+ $this->interpDBkey = 0;
+ }
+ if ( is_null( $this->randomQuestionCount ) ) {
+ $this->randomQuestionCount = 0;
+ }
+ if ( is_null( $this->dependsOn ) ) {
+ $this->dependsOn = '';
+ }
+ */
+ # end of paranoiac checks
self::$db->insert( 'qp_poll_desc',
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 ),
__METHOD__ . ':update poll' );
@@ -863,13 +888,15 @@
private function interpretVote() {
$this->interpResult = new qp_InterpResult();
$interpTitle = $this->getInterpTitle();
+ if ( $interpTitle === false ) {
+ return;
+ }
if ( $interpTitle === null ) {
+ $this->interpResult->storeErroneous = false;
+ $this->interpResult->setError( wfMsg(
'qp_error_no_interpretation' ) );
return;
}
$interpArticle = new Article( $interpTitle, 0 );
- if ( !$interpArticle->exists() ) {
- return;
- }
# prepare array of user answers that will be passed to the
interpreter
$poll_answer = array();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs