r92228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92227‎ | r92228 | r92229 >
Date:07:11, 15 July 2011
Author:questpc
Status:deferred
Tags:
Comment:
Random question generation fixes
Modified paths:
  • /trunk/extensions/QPoll/README (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_poll.php (modified) (history)
  • /trunk/extensions/QPoll/qp_pollstore.php (modified) (history)
  • /trunk/extensions/QPoll/qp_results.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/qp_results.php
@@ -345,10 +345,10 @@
346346 if ( $userName === false ) {
347347 return '';
348348 }
349 - $pollStore->loadRandomQuestions( $userName );
350349 $userTitle = Title::makeTitleSafe( NS_USER, $userName );
351350 $user_link = $this->qpLink( $userTitle, $userName );
352351 $pollStore->setLastUser( $userName, false );
 352+ $pollStore->loadRandomQuestions();
353353 if ( !$pollStore->loadUserVote() ) {
354354 return '';
355355 }
Index: trunk/extensions/QPoll/README
@@ -1,5 +1,7 @@
2 -MediaWiki extension QPoll, version 0.8.0a
 2+== MediaWiki extension QPoll, version 0.8.0a ==
33
 4+=== v0.7.0 ===
 5+
46 This extension allows to create polls embedded into the wikipages. Every poll
57 may contain a set of the questions of various types. The polls can be "chained"
68 (when the dependent poll would be available for voting only after a successful
@@ -8,7 +10,7 @@
911 the groups (metacategories also known as category spans) to make a
1012 "subquestions" inside a question. Optional dependence of the question's
1113 proposal text on the user's choice of category in another previously voted
12 -poll.
 14+poll. Categories can be checkboxes, radiobuttons or text fields.
1315
1416 === v0.8.0a ===
1517 Now it is possible to:
@@ -17,7 +19,11 @@
1820 * Generate and store interpretations / marks / scores
1921 * Highlight wrong answers to question proposals
2022 * Log and limit number of answer attempts
 23+* Select number of random questions for every user of the particular poll
 24+ (similar to Russian EGE test)
2125
2226 which allows to use the extension as education tool.
2327
24 -See http://mediawiki.org/wiki/Extension:QPoll for further details.
\ No newline at end of file
 28+Documentation will be updated when the extension will become stable enough.
 29+
 30+See http://mediawiki.org/wiki/Extension:QPoll for further details.
Index: trunk/extensions/QPoll/ctrl/qp_poll.php
@@ -174,7 +174,8 @@
175175
176176 function setUsedQuestions() {
177177 # load random questions from DB (when available)
178 - $this->pollStore->loadRandomQuestions( $this->username );
 178+ $this->pollStore->setLastUser( $this->username );
 179+ $this->pollStore->loadRandomQuestions();
179180 if ( $this->randomQuestionCount > 0 ) {
180181 if ( $this->randomQuestionCount > $this->questions->totalCount() ) {
181182 $this->randomQuestionCount = $this->questions->totalCount();
Index: trunk/extensions/QPoll/qp_pollstore.php
@@ -184,7 +184,9 @@
185185 /// DB keys
186186 var $pid = null;
187187 var $last_uid = null;
188 - # username is used for caching of setLastUser() method (which now may be called multiple times)
 188+
 189+ # username is used for caching of setLastUser() method (which now may be called multiple times);
 190+ # also used by randomizer
189191 var $username = '';
190192 /// common properties
191193 var $mArticleId = null;
@@ -678,16 +680,28 @@
679681 }
680682 }
681683
 684+ /**
 685+ * Checks, whether particular question belongs to user's random seed
 686+ * @param $question_id question_id from DB
 687+ * @return true: question belongs to the seed;
 688+ * false: question does not belong to the seed;
 689+ */
682690 function isUsedQuestion( $question_id ) {
683691 return !is_array( $this->randomQuestions ) ||
684692 in_array( $question_id, $this->randomQuestions, true );
685693 }
686694
687 - function loadRandomQuestions( $username ) {
 695+ /**
 696+ * Loads $this->randomQuestions from DB for current user
 697+ * Will be overriden in memory when number of random questions was changed
 698+ */
 699+ function loadRandomQuestions() {
 700+ if ( is_null( $this->last_uid ) ) {
 701+ throw new Exception( 'User was not set, cannot load random questions in ' . __METHOD__ );
 702+ }
688703 if ( is_null( $this->pid ) ) {
689704 $this->setPid();
690705 }
691 - $this->setLastUser( $username );
692706 $res = self::$db->select( 'qp_random_questions', 'question_id', array( 'uid' => $this->last_uid, 'pid' => $this->pid ), __METHOD__ );
693707 $this->randomQuestions = array();
694708 while ( $row = self::$db->fetchObject( $res ) ) {
@@ -698,6 +712,12 @@
699713 }
700714 }
701715
 716+ /**
 717+ * Stores $this->randomQuestions into DB
 718+ * Should be called:
 719+ * when user views the page with the poll first time
 720+ * when number of random questions for poll was changed
 721+ */
702722 function setRandomQuestions() {
703723 if ( is_null( $this->pid ) || is_null( $this->last_uid ) ) {
704724 throw new MWException( __METHOD__ . ' cannot be called when pid/uid was not set' );
@@ -707,12 +727,17 @@
708728 foreach( $this->randomQuestions as $qidx ) {
709729 $data[] = array( 'pid' => $this->pid, 'uid' => $this->last_uid, 'question_id' => $qidx );
710730 }
711 - $res = self::$db->replace( 'qp_random_questions',
712 - 'user_poll_question',
 731+ self::$db->begin();
 732+ self::$db->delete( 'qp_random_questions',
 733+ array( 'pid' => $this->pid, 'uid' => $this->last_uid ),
 734+ __METHOD__ );
 735+ $res = self::$db->insert( 'qp_random_questions',
713736 $data,
714 - __METHOD__ . ':random questions seed update' );
 737+ __METHOD__ . ':set random questions seed' );
 738+ self::$db->commit();
715739 return;
716740 }
 741+ # this->randomQuestions === false; this poll is not randomized anymore
717742 self::$db->delete( 'qp_random_questions',
718743 array( 'pid'=>$this->pid ),
719744 __METHOD__ . ':remove question random seed'

Status & tagging log