r106120 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106119‎ | r106120 | r106121 >
Date:22:46, 13 December 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
some cleanup work, bumped version to 0.2 alpha
Modified paths:
  • /trunk/extensions/Survey/INSTALL (modified) (history)
  • /trunk/extensions/Survey/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Survey/Survey.hooks.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/Survey.sql (deleted) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyPage.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyStats.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveys.php (modified) (history)
  • /trunk/extensions/Survey/sql/Survey.sql (added) (history)
  • /trunk/extensions/Survey/sql/Survey_indexQuestionId.sql (deleted) (history)
  • /trunk/extensions/Survey/sql/Survey_indexSubmissionId.sql (deleted) (history)
  • /trunk/extensions/Survey/sql/Survey_indexSurveyName.sql (deleted) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.sql
@@ -1,47 +0,0 @@
2 -
3 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/surveys (
4 - survey_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
5 - survey_name VARCHAR(255) NOT NULL, -- String indentifier for the survey
6 - survey_title VARCHAR(255) NOT NULL, -- Title of the survey
7 - survey_enabled TINYINT NOT NULL default '0', -- If the survey can be taken by users
8 - survey_header TEXT NOT NULL, -- Text to display above the survey
9 - survey_footer TEXT NOT NULL, -- Text to display below the survey
10 - survey_thanks TEXT NOT NULL, -- Text to display after survey submission
11 - survey_user_type TINYINT unsigned NOT NULL default '0', -- Type of users that can participate in the survey
12 - survey_namespaces BLOB NOT NULL, -- Namespaces on which the survey can be displayed
13 - survey_ratio TINYINT unsigned NOT NULL, -- Percentage of users to show the survey to
14 - survey_expiry INT unsigned NOT NULL, -- Coockie expiry time for the survey
15 - survey_min_pages TINYINT unsigned NOT NULL -- Min amount of pages the user needs to view before getting the survey
16 -) /*$wgDBTableOptions*/;
17 -
18 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/survey_questions (
19 - question_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY,
20 - question_survey_id SMALLINT unsigned NOT NULL, -- Foreign key: surveys.survey_id
21 - question_text TEXT NOT NULL,
22 - question_type INT(2) unsigned NOT NULL,
23 - question_required TINYINT NOT NULL,
24 - question_answers BLOB NOT NULL,
25 - question_removed TINYINT NOT NULL default '0'
26 -) /*$wgDBTableOptions*/;
27 -
28 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/survey_submissions (
29 - submission_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY,
30 - submission_survey_id SMALLINT unsigned NOT NULL, -- Foreign key: surveys.survey_id
31 - submission_user_name VARCHAR(255) NOT NULL, -- The person that made the submission (account name or ip)
32 - submission_page_id INT(10) unsigned NULL, -- The id of the page the submission was made on
33 - submission_time CHAR(14) binary NOT NULL default '' -- The time the submission was made
34 -) /*$wgDBTableOptions*/;
35 -
36 -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/survey_answers (
37 - answer_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
38 - answer_submission_id INT(10) unsigned NOT NULL, -- Foreign key: survey_submissions.submission_id
39 - answer_question_id INT(10) unsigned NOT NULL, -- Foreign key: survey_questions.question_id
40 - answer_text BLOB NOT NULL
41 -) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/Survey/sql/Survey_indexSurveyName.sql
@@ -1 +0,0 @@
2 -CREATE UNIQUE INDEX /*i*/surveys_survey_name ON /*_*/surveys (survey_name);
\ No newline at end of file
Index: trunk/extensions/Survey/sql/Survey_indexQuestionId.sql
@@ -1 +0,0 @@
2 -CREATE INDEX /*i*/surveys_question_id ON /*_*/survey_answers (answer_question_id);
\ No newline at end of file
Index: trunk/extensions/Survey/sql/Survey_indexSubmissionId.sql
@@ -1 +0,0 @@
2 -CREATE INDEX /*i*/surveys_submission_id ON /*_*/survey_answers (answer_submission_id);
\ No newline at end of file
Index: trunk/extensions/Survey/sql/Survey.sql
@@ -0,0 +1,52 @@
 2+-- MySQL version of the database schema for the Survey extension.
 3+-- Licence: GNU GPL v3+
 4+-- Author: Jeroen De Dauw < jeroendedauw@gmail.com >
 5+
 6+-- Surveys
 7+CREATE TABLE IF NOT EXISTS /*_*/surveys (
 8+ survey_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
 9+ survey_name VARCHAR(255) NOT NULL, -- String indentifier for the survey
 10+ survey_title VARCHAR(255) NOT NULL, -- Title of the survey
 11+ survey_enabled TINYINT NOT NULL default '0', -- If the survey can be taken by users
 12+ survey_header TEXT NOT NULL, -- Text to display above the survey
 13+ survey_footer TEXT NOT NULL, -- Text to display below the survey
 14+ survey_thanks TEXT NOT NULL, -- Text to display after survey submission
 15+ survey_user_type TINYINT unsigned NOT NULL default '0', -- Type of users that can participate in the survey
 16+ survey_namespaces BLOB NOT NULL, -- Namespaces on which the survey can be displayed
 17+ survey_ratio TINYINT unsigned NOT NULL, -- Percentage of users to show the survey to
 18+ survey_expiry INT unsigned NOT NULL, -- Coockie expiry time for the survey
 19+ survey_min_pages TINYINT unsigned NOT NULL -- Min amount of pages the user needs to view before getting the survey
 20+) /*$wgDBTableOptions*/;
 21+
 22+CREATE UNIQUE INDEX /*i*/surveys_survey_name ON /*_*/surveys (survey_name);
 23+
 24+-- Questions
 25+CREATE TABLE IF NOT EXISTS /*_*/survey_questions (
 26+ question_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY,
 27+ question_survey_id SMALLINT unsigned NOT NULL, -- Foreign key: surveys.survey_id
 28+ question_text TEXT NOT NULL,
 29+ question_type INT(2) unsigned NOT NULL,
 30+ question_required TINYINT NOT NULL,
 31+ question_answers BLOB NOT NULL,
 32+ question_removed TINYINT NOT NULL default '0'
 33+) /*$wgDBTableOptions*/;
 34+
 35+-- Submissions
 36+CREATE TABLE IF NOT EXISTS /*_*/survey_submissions (
 37+ submission_id INT(10) unsigned NOT NULL auto_increment PRIMARY KEY,
 38+ submission_survey_id SMALLINT unsigned NOT NULL, -- Foreign key: surveys.survey_id
 39+ submission_user_name VARCHAR(255) NOT NULL, -- The person that made the submission (account name or ip)
 40+ submission_page_id INT(10) unsigned NULL, -- The id of the page the submission was made on
 41+ submission_time CHAR(14) binary NOT NULL default '' -- The time the submission was made
 42+) /*$wgDBTableOptions*/;
 43+
 44+-- Answers
 45+CREATE TABLE IF NOT EXISTS /*_*/survey_answers (
 46+ answer_id SMALLINT unsigned NOT NULL auto_increment PRIMARY KEY,
 47+ answer_submission_id INT(10) unsigned NOT NULL, -- Foreign key: survey_submissions.submission_id
 48+ answer_question_id INT(10) unsigned NOT NULL, -- Foreign key: survey_questions.question_id
 49+ answer_text BLOB NOT NULL
 50+) /*$wgDBTableOptions*/;
 51+
 52+CREATE INDEX /*i*/surveys_submission_id ON /*_*/survey_answers (answer_submission_id);
 53+CREATE INDEX /*i*/surveys_question_id ON /*_*/survey_answers (answer_question_id);
Property changes on: trunk/extensions/Survey/sql/Survey.sql
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/extensions/Survey/Survey.php
@@ -24,11 +24,11 @@
2525 die( 'Not an entry point.' );
2626 }
2727
28 -if ( version_compare( $wgVersion, '1.17', '<' ) ) {
29 - die( '<b>Error:</b> Survey requires MediaWiki 1.17 or above.' );
 28+if ( version_compare( $wgVersion, '1.18c', '<' ) ) {
 29+ die( '<b>Error:</b> This version of Survey requires MediaWiki 1.18 or above. For MediaWiki 1.17.x, you can use Survey 0.1.2.' );
3030 }
3131
32 -define( 'Survey_VERSION', '0.1.2' );
 32+define( 'Survey_VERSION', '0.2 alpha' );
3333
3434 $wgExtensionCredits['other'][] = array(
3535 'path' => __FILE__,
Index: trunk/extensions/Survey/specials/SpecialSurveyPage.php
@@ -58,32 +58,6 @@
5959 }
6060
6161 /**
62 - * Get the OutputPage being used for this instance.
63 - * This overrides the getOutput method of Specialpage added in MediaWiki 1.18,
64 - * and returns $wgOut for older versions.
65 - *
66 - * @since 0.1
67 - *
68 - * @return OutputPage
69 - */
70 - public function getOutput() {
71 - return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut'];
72 - }
73 -
74 - /**
75 - * Shortcut to get user's language.
76 - * This overrides the getLang method of Specialpage added in MediaWiki 1.18,
77 - * and returns $wgLang for older versions.
78 - *
79 - * @since 0.1
80 - *
81 - * @return Language
82 - */
83 - public function getLang() {
84 - return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getLang() : $GLOBALS['wgLang'];
85 - }
86 -
87 - /**
8862 * Add resource loader modules or use fallback code for
8963 * earlier versions of MediaWiki.
9064 *
@@ -129,7 +103,7 @@
130104 * @param array $links
131105 */
132106 protected function displayNavigation( array $links ) {
133 - $this->getOutput()->addHTML( Html::rawElement( 'p', array(), $this->getLang()->pipeList( $links ) ) );
 107+ $this->getOutput()->addHTML( Html::rawElement( 'p', array(), $this->getLanguage()->pipeList( $links ) ) );
134108 }
135109
136110 }
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php
@@ -252,7 +252,7 @@
253253 'surveys-surveystats-question-answer',
254254 'parsemag',
255255 $answer,
256 - $this->getLang()->formatNum( $answerCount )
 256+ $this->getLanguage()->formatNum( $answerCount )
257257 )
258258 );
259259 }
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -34,9 +34,7 @@
3535 return;
3636 }
3737
38 - global $wgRequest, $wgUser;
39 -
40 - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 38+ if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
4139 $this->handleSubmission();
4240 } else {
4341 if ( is_null( $subPage ) || trim( $subPage ) === '' ) {
@@ -72,24 +70,24 @@
7371 * @since 0.1
7472 */
7573 protected function handleSubmission() {
76 - global $wgRequest;
 74+ $req = $this->getRequest();
7775
78 - $values = $wgRequest->getValues();
 76+ $values = $req->getValues();
7977
80 - if ( $wgRequest->getInt( 'survey-id' ) == 0 ) {
 78+ if ( $req->getInt( 'survey-id' ) == 0 ) {
8179 $survey = new Survey( null );
8280 } else {
83 - $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false );
 81+ $survey = Survey::newFromId( $req->getInt( 'survey-id' ), null, false );
8482 }
8583
8684 foreach ( array( 'name', 'title', 'header', 'footer', 'thanks' ) as $field ) {
87 - $survey->setField( $field, $wgRequest->getText( 'survey-' . $field ) );
 85+ $survey->setField( $field, $req->getText( 'survey-' . $field ) );
8886 }
8987
90 - $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) );
 88+ $survey->setField( 'enabled', $req->getCheck( 'survey-enabled' ) );
9189
9290 foreach ( array( 'user_type', 'ratio', 'min_pages', 'expiry' ) as $field ) {
93 - $survey->setField( $field, $wgRequest->getInt( 'survey-' . $field ) );
 91+ $survey->setField( $field, $req->getInt( 'survey-' . $field ) );
9492 }
9593
9694 $survey->setField( 'namespaces', array() );
@@ -132,7 +130,7 @@
133131 * @return SurveyQuestion
134132 */
135133 protected function getSubmittedQuestion( $questionId, $isNewQuestion = false ) {
136 - global $wgRequest;
 134+ $req = $this->getRequest();
137135
138136 if ( $isNewQuestion ) {
139137 $questionDbId = null;
@@ -142,7 +140,7 @@
143141 }
144142
145143 $answers = array_filter(
146 - explode( "\n", $wgRequest->getText( "survey-question-answers-$questionId" ) ),
 144+ explode( "\n", $req->getText( "survey-question-answers-$questionId" ) ),
147145 function( $line ) {
148146 return trim( $line ) != '';
149147 }
@@ -151,8 +149,8 @@
152150 $question = new SurveyQuestion( array(
153151 'id' => $questionDbId,
154152 'removed' => 0,
155 - 'text' => $wgRequest->getText( "survey-question-text-$questionId" ),
156 - 'type' => $wgRequest->getInt( "survey-question-type-$questionId" ),
 153+ 'text' => $req->getText( "survey-question-text-$questionId" ),
 154+ 'type' => $req->getInt( "survey-question-type-$questionId" ),
157155 'required' => 0, // $wgRequest->getCheck( "survey-question-required-$questionId" ),
158156 'answers' => $answers
159157 ) );
@@ -181,7 +179,7 @@
182180 * @return array
183181 */
184182 protected function getNumericalOptions( array $numbers ) {
185 - $lang = $this->getLang();
 183+ $lang = $this->getLanguage();
186184
187185 return array_flip( array_map(
188186 function( $n ) use( $lang ) { return $lang->formatNum( $n ); },
Index: trunk/extensions/Survey/specials/SpecialSurveys.php
@@ -34,12 +34,12 @@
3535 return;
3636 }
3737
38 - global $wgRequest, $wgUser;
 38+ $req = $this->getRequest();
3939
40 - if ( $wgRequest->wasPosted()
41 - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
42 - && $wgRequest->getCheck( 'newsurvey' ) ) {
43 - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'EditSurvey', $wgRequest->getVal( 'newsurvey' ) )->getLocalURL() );
 40+ if ( $req->wasPosted()
 41+ && $this->getUser()->matchEditToken( $req->getVal( 'wpEditToken' ) )
 42+ && $req->getCheck( 'newsurvey' ) ) {
 43+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'EditSurvey', $req->getVal( 'newsurvey' ) )->getLocalURL() );
4444 } else {
4545 $this->displaySurveys();
4646 }
Index: trunk/extensions/Survey/Survey.hooks.php
@@ -51,54 +51,15 @@
5252 *
5353 * @return true
5454 */
55 - public static function onSchemaUpdate( /* DatabaseUpdater */ $updater = null ) {
 55+ public static function onSchemaUpdate( DatabaseUpdater $updater ) {
5656 global $wgDBtype;
5757
5858 $updater->addExtensionUpdate( array(
5959 'addTable',
6060 'surveys',
61 - dirname( __FILE__ ) . '/Survey.sql',
 61+ dirname( __FILE__ ) . '/sql/Survey.sql',
6262 true
6363 ) );
64 - $updater->addExtensionUpdate( array(
65 - 'addTable',
66 - 'survey_questions',
67 - dirname( __FILE__ ) . '/Survey.sql',
68 - true
69 - ) );
70 - $updater->addExtensionUpdate( array(
71 - 'addTable',
72 - 'survey_submissions',
73 - dirname( __FILE__ ) . '/Survey.sql',
74 - true
75 - ) );
76 - $updater->addExtensionUpdate( array(
77 - 'addTable',
78 - 'survey_answers',
79 - dirname( __FILE__ ) . '/Survey.sql',
80 - true
81 - ) );
82 - $updater->addExtensionUpdate( array(
83 - 'addIndex',
84 - 'surveys',
85 - 'surveys_survey_name',
86 - dirname( __FILE__ ) . '/sql/Survey_indexSurveyName.sql',
87 - true
88 - ) );
89 - $updater->addExtensionUpdate( array(
90 - 'addIndex',
91 - 'survey_answers',
92 - 'surveys_question_id',
93 - dirname( __FILE__ ) . '/sql/Survey_indexQuestionId.sql',
94 - true
95 - ) );
96 - $updater->addExtensionUpdate( array(
97 - 'addIndex',
98 - 'survey_answers',
99 - 'surveys_submission_id',
100 - dirname( __FILE__ ) . '/sql/Survey_indexSubmissionId.sql',
101 - true
102 - ) );
10364
10465 return true;
10566 }
Index: trunk/extensions/Survey/INSTALL
@@ -8,7 +8,7 @@
99
1010 Survey requires:
1111
12 -* MediaWiki 1.17 or above
 12+* MediaWiki 1.18 or above (Use Survey 0.1.2 if you are running MediaWiki 1.17.x and cannot upgrade to 1.18 or later.)
1313 * PHP 5.3 or above
1414
1515 == Download ==
@@ -18,12 +18,12 @@
1919
2020 You can also get the code directly from SVN. Tags can be obtained via
2121
22 - svn checkout <nowiki>http://svn.wikimedia.org/svnroot/mediawiki/tags/extensions/Survey/REL_version</nowiki>
 22+ svn checkout http://svn.wikimedia.org/svnroot/mediawiki/tags/extensions/Survey/REL_version
2323
2424 Where 'version' is the version number of the tag, such as 0_1 (see the [http://svn.wikimedia.org/svnroot/mediawiki/tags/extensions/Survey/ available tags]).
2525 The latest code can be obtained from trunk:
2626
27 - svn checkout <nowiki>http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/Survey/</nowiki>
 27+ svn checkout http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/Survey/
2828
2929 == Installation ==
3030
Index: trunk/extensions/Survey/RELEASE-NOTES
@@ -4,6 +4,13 @@
55 Latest version of the release notes: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Survey/RELEASE-NOTES?view=co
66
77
 8+=== Version 0.2 ===
 9+(trunk)
 10+
 11+* Dropped compatibility with MediaWiki 1.17.
 12+* Use of RequestContext methods to get rid of globals.
 13+* Cleanup of database table index code.
 14+
815 === Version 0.1.2 ===
916 2011-11-14
1017

Status & tagging log