tosfos has uploaded a new change for review.
https://gerrit.wikimedia.org/r/146995
Change subject: fix documentation, file encoding
......................................................................
fix documentation, file encoding
Change-Id: I5dd3647384b6589fe4b2bb2c8280472720020010
---
M QuizTabulate.class.php
M QuizTabulate.hooks.php
M QuizTabulate.php
M QuizTabulate.sql
4 files changed, 99 insertions(+), 61 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuizTabulate
refs/changes/95/146995/1
diff --git a/QuizTabulate.class.php b/QuizTabulate.class.php
index 77aad39..6231413 100644
--- a/QuizTabulate.class.php
+++ b/QuizTabulate.class.php
@@ -1,4 +1,5 @@
-<?php
+<?php
+
class QuestionTabulate extends Question {
/**
* Constructor
@@ -8,7 +9,17 @@
* @param $questionId Integer: the Identifier of the question used to
generate input names.
* @param $parser Parser the wikitext parser.
*/
- public function __construct( $beingCorrected, $caseSensitive,
$questionId, &$parser ) {
+
+ /**
+ * Constructor
+ *
+ * @global int $wgQuizPageLatestRevID
+ * @param boolean $beingCorrected
+ * @param boolean $caseSensitive
+ * @param int $questionId
+ * @param Parser $parser
+ */
+ public function __construct( $beingCorrected, $caseSensitive,
$questionId, Parser &$parser ) {
global $wgQuizPageLatestRevID;
parent::__construct( $beingCorrected, $caseSensitive,
$questionId, $parser );
@@ -22,11 +33,10 @@
/**
* Convert a basic type object from quiz syntax to HTML.
- * Save answers to the database
*
- * @param $input string A question object in quiz syntax
- * @param $inputType string
- *
+ * @global int $wgQuizPageLatestRevID
+ * @param string $input A question object in quiz syntax
+ * @param string $inputType
* @return string A question object in HTML.
*/
function basicTypeParseObject( $input, $inputType ) {
@@ -45,8 +55,8 @@
$allAnswers = array();
$rightAnswer = false;
$answerChosen = '';
- foreach( $raws as $proposalId => $raw ) {
- if( preg_match( $this->mProposalPattern, $raw, $matches
) ) {
+ foreach ( $raws as $proposalId => $raw ) {
+ if ( preg_match( $this->mProposalPattern, $raw,
$matches ) ) {
array_shift( $matches );
$sign = $matches[0];
@@ -57,10 +67,10 @@
$allAnswers[$proposalId]['answerText'] =
$answerText;
array_pop( $matches );
# Determine a type ID, according to the
questionType and the number of signes.
- $typeId = substr( $this->mType, 0, 1 );
+ $typeId = substr( $this->mType, 0, 1 );
$typeId .= array_key_exists( 1, $matches ) ?
'c' : 'n';
- switch( $typeId ) {
+ switch ( $typeId ) {
#@todo extension only set up to track a
linear right/wrong answer, which likely limits it to this type.
case 'sn':
$name = "q$this->mQuestionId";
@@ -78,10 +88,16 @@
}
$this->tabulate( $allAnswers );
- return $output;
+ return $output;
}
- function tabulate( $allAnswers ){
+ /**
+ * Save answers to the database.
+ *
+ * @global int $wgQuizPageLatestRevID
+ * @param array $allAnswers
+ */
+ function tabulate( $allAnswers ) {
global $wgQuizPageLatestRevID;
$fullTableName = QUIZ_TABULATE_TABLE;
@@ -95,24 +111,22 @@
return;
}
$existingProposalObject = $dbr->select(
- $fullTableName,
- array( 'count_attempt' ),
+ $fullTableName, array( 'count_attempt'
),
"quiz_rev_id=$wgQuizPageLatestRevID AND
question_id=$this->mQuestionId AND answer_id=$answerId",
__METHOD__
);
$dbw = wfGetDB( DB_MASTER );
if ( $existingProposalObject->numRows() !== 0 )
{
$dbw->update(
- $fullTableName,
- array( 'count_attempt =
count_attempt + 1' ),
+ $fullTableName, array(
'count_attempt = count_attempt + 1' ),
array( 'quiz_rev_id' =>
$wgQuizPageLatestRevID, 'question_id' => $this->mQuestionId, 'answer_id' =>
$answerId ),
- __METHOD__
+ __METHOD__
);
} else {
$dbw->insert(
$fullTableName,
- array( 'quiz_rev_id' =>
$wgQuizPageLatestRevID, 'question_id' => $this->mQuestionId, 'answer_id' =>
$answerId, 'answer_text' => $proposal['answerText'], 'count_attempt' => 1 ),
- __METHOD__
+ array( 'quiz_rev_id' =>
$wgQuizPageLatestRevID, 'question_id' => $this->mQuestionId, 'answer_id' =>
$answerId,
+ 'answer_text' =>
$proposal['answerText'], 'count_attempt' => 1 ), __METHOD__
);
}
}
@@ -122,8 +136,8 @@
/**
* Convert the question's header into HTML.
* Store question in db
- *
- * @param $input String: the quiz header in quiz syntax.
+ * @global int $wgQuizPageLatestRevID
+ * @param string $input The quiz header in quiz syntax.
* @return string
*/
function parseHeader( $input ) {
@@ -135,17 +149,15 @@
$dbr = wfGetDB( DB_SLAVE );
#check if question already exists
$existingQuestion = $dbr->select(
- $fullTableName,
- array( 'question_id' ),
- "quiz_rev_id=$wgQuizPageLatestRevID AND
question_id = $this->mQuestionId",
- __METHOD__
+ $fullTableName, array( 'question_id' ),
+ "quiz_rev_id=$wgQuizPageLatestRevID AND
question_id = $this->mQuestionId", __METHOD__
);
if ( $existingQuestion->numRows() == 0 ) {
$dbw = wfGetDB( DB_MASTER );
$dbw->insert(
$fullTableName,
array( 'quiz_rev_id' =>
$wgQuizPageLatestRevID, 'question_id' => $this->mQuestionId, 'question_text' =>
$output ),
- __METHOD__
+ __METHOD__
);
}
}
diff --git a/QuizTabulate.hooks.php b/QuizTabulate.hooks.php
index 51f97e3..f07af73 100644
--- a/QuizTabulate.hooks.php
+++ b/QuizTabulate.hooks.php
@@ -1,28 +1,36 @@
-<?php
+<?php
final class QuizTabulateHooks {
/**
* Schema update to set up the needed database tables.
+ *
+ * @global string $wgDBtype
+ * @param DatabaseUpdater $updater
+ * @return boolean
*/
public static function quizTabulateSchemaUpdate( DatabaseUpdater
$updater = null ) {
global $wgDBtype;
// Set up the current schema.
$updater->addExtensionTable(
- QUIZ_TABULATE_TABLE,
- __DIR__ . '/QuizTabulate.sql',
- true
+ QUIZ_TABULATE_TABLE, __DIR__ . '/QuizTabulate.sql', true
);
$updater->addExtensionTable(
- QUIZ_TABULATE_QUESTIONS_TABLE,
- __DIR__ . '/QuizTabulate.sql',
- true
+ QUIZ_TABULATE_QUESTIONS_TABLE, __DIR__ .
'/QuizTabulate.sql', true
);
return true;
}
+ /**
+ * Add quiz tabulation to output
+ *
+ * @global int $wgQuizNamespace
+ * @param OutputPage $outputpage
+ * @param string $text
+ * @return boolean
+ */
public static function outputQuizTabulate( OutputPage $outputpage,
&$text ) {
global $wgQuizNamespace;
@@ -46,10 +54,8 @@
$dbr = wfGetDB( DB_SLAVE );
$fullTableName = QUIZ_TABULATE_TABLE;
$proposals = $dbr->select(
- $fullTableName,
- array( 'question_id', 'answer_id', 'count_attempt',
'answer_text' ),
- "quiz_rev_id=$revisionId",
- __METHOD__
+ $fullTableName, array( 'question_id', 'answer_id',
'count_attempt', 'answer_text' ),
+ "quiz_rev_id=$revisionId", __METHOD__
);
if ( $proposals->numRows() == 0 ) {
return true; #no quizzes submitted
@@ -66,42 +72,58 @@
#then spit it out nice-like
$text .= XML::openElement( 'div', array( 'id' =>
'quiz_tabulate', 'style' => 'clear:both;' ) );
- $text .= Xml::element( 'h2', array( 'id' =>
'quiz_tabulate_title' ), wfMessage( 'quiz-tabulate-results' )->text() );
+ $text .= Xml::element( 'h2', array( 'id' =>
'quiz_tabulate_title' ),
+ wfMessage( 'quiz-tabulate-results' )->text() );
$fullTableName = QUIZ_TABULATE_QUESTIONS_TABLE;
foreach ( $allResults as $question_id => $results ) {
$totalAnswers = 0;
- foreach( $results as $answer ) {
+ foreach ( $results as $answer ) {
$totalAnswers += $answer['countAttempt'];
}
$questionTextObject = $dbr->select(
- $fullTableName,
- array( 'question_text' ),
- "quiz_rev_id=$revisionId AND question_id =
$question_id",
- __METHOD__
+ $fullTableName, array( 'question_text' ),
+ "quiz_rev_id=$revisionId AND question_id =
$question_id", __METHOD__
);
- $headingText = 'Question #' . ( $question_id + 1 ). ':
' . $questionTextObject->fetchObject()->question_text;
+ $headingText = 'Question #' . ( $question_id + 1 ) . ':
' . $questionTextObject->fetchObject()->question_text;
$text .= Xml::element( 'h3', array( 'class' =>
'quiz_tabulate_question' ), $headingText );
$text .= Xml::element( 'p', array( 'class' =>
'quiz_tabulate_total' ), "Answers: $totalAnswers" );
$tableRows = array();
- foreach( $results as $answer ) {
- $tableRows[] = array( $answer['answerText'],
$answer['countAttempt'], number_format( $answer['countAttempt'] / $totalAnswers
* 100, 0 ) . '%' );
+ foreach ( $results as $answer ) {
+ $tableRows[] = array( $answer['answerText'],
$answer['countAttempt'], number_format( $answer['countAttempt']
+ / $totalAnswers * 100, 0 ) .
'%' );
}
- $text .= Xml::buildTable( $tableRows, array( 'class' =>
'wikitable quiz_tabulate_answers' ), array( 'Answer', 'Count', 'Percentage' ) );
+ $text .= Xml::buildTable( $tableRows, array( 'class' =>
'wikitable quiz_tabulate_answers' ),
+ array( 'Answer', 'Count', 'Percentage'
) );
}
$text .= XML::closeElement( 'div' );
return true;
}
- public static function quizTabulateSetupParserFunction( &$parser ) {
- $parser->setFunctionHook( 'quiztabulate',
'QuizTabulateHooks::quizTabulateRenderParserFunction' );
-
+ /**
+ * quiztabulate parser function
+ *
+ * @param Parser $parser
+ * @return boolean
+ */
+ public static function quizTabulateSetupParserFunction( Parser &$parser
) {
+ $parser->setFunctionHook( 'quiztabulate', __CLASS__ .
'::quizTabulateRenderParserFunction' );
return true;
}
- public static function quizTabulateRenderParserFunction( $parser,
$quizName = '', $includeQuizTags = false ) {
+ /**
+ *
+ * @global int $wgQuizPageLatestRevID
+ * @global int $wgQuizNamespace
+ * @param Parser $parser
+ * @param string $quizName
+ * @param boolean $includeQuizTags
+ * @return array
+ */
+ public static function quizTabulateRenderParserFunction( Parser
$parser, $quizName = '',
+ $includeQuizTags = false ) {
global $wgQuizPageLatestRevID, $wgQuizNamespace;
if ( $quizName == '' ) {
@@ -125,20 +147,24 @@
return array( $output, 'noparse' => false );
}
- #override Question object with our own Question child
- public static function quizTabulateSetupTabulator ( $quiz, &$question )
{
+ /**
+ * Override Question object with our own Question child
+ *
+ * @global int $wgQuizPageLatestRevID
+ * @global int $wgQuizNamespace
+ * @param Quiz $quiz
+ * @param QuestionTabulate $question
+ * @return boolean
+ */
+ public static function quizTabulateSetupTabulator( Quiz $quiz,
QuestionTabulate &$question ) {
global $wgQuizPageLatestRevID, $wgQuizNamespace;
#if this isn't in the Quiz namespace and wgQuizPageLatestRevID
wasn't set (in other words, the #quiztabulate: function wasn't called)
- if ( $quiz->mParser->getTitle()->getNamespace() !=
$wgQuizNamespace
- && !$wgQuizPageLatestRevID ) {
+ if ( $quiz->mParser->getTitle()->getNamespace() !=
$wgQuizNamespace && !$wgQuizPageLatestRevID ) {
return true;
}
$question = new QuestionTabulate(
- $quiz->mBeingCorrected,
- $quiz->mCaseSensitive,
- $quiz->mQuestionId,
- $quiz->mParser
+ $quiz->mBeingCorrected, $quiz->mCaseSensitive,
$quiz->mQuestionId, $quiz->mParser
);
return true;
diff --git a/QuizTabulate.php b/QuizTabulate.php
index 33b9158..1c37b12 100644
--- a/QuizTabulate.php
+++ b/QuizTabulate.php
@@ -1,4 +1,4 @@
-<?php
+<?php
/**
* QuizTabulate is a quiz tabulation tool for MediaWiki. It requires the Quiz
extension.
*
diff --git a/QuizTabulate.sql b/QuizTabulate.sql
index 3b40c08..6e9a32b 100644
--- a/QuizTabulate.sql
+++ b/QuizTabulate.sql
@@ -1,4 +1,4 @@
--- SQL for database schema for the QuizTabulate extension.
+-- SQL for database schema for the QuizTabulate extension.
CREATE TABLE IF NOT EXISTS /*_*/quiz_tabulate (
quiz_tabulate_id INT unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
quiz_rev_id INT(10) unsigned NOT NULL,
--
To view, visit https://gerrit.wikimedia.org/r/146995
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5dd3647384b6589fe4b2bb2c8280472720020010
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuizTabulate
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits