r64532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64531‎ | r64532 | r64533 >
Date:21:08, 2 April 2010
Author:catrope
Status:deferred
Tags:
Comment:
PrefSwitch: Some cleanup, documentation
Modified paths:
  • /trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.classes.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.classes.php
@@ -16,6 +16,13 @@
1717
1818 /* Static Functions */
1919
 20+ /**
 21+ * Render the HTML for a survey.
 22+ * @param $name string Survey name
 23+ * @param $questions array Array containing question data
 24+ * @param $loadFromDB bool Load previous survey data from the database
 25+ * @return string HTML
 26+ */
2027 public static function render( $name, $questions, $loadFromDB = false ) {
2128 global $wgUser, $wgOut;
2229 // Load existing data from the database - allowing the user to change their answers
@@ -36,17 +43,23 @@
3744 foreach ( $questions as $field => $config ) {
3845 $answer = isset( $loaded[$field] ) ? $loaded[$field][0] : null;
3946 $answerData = isset( $loaded[$field] ) ? $loaded[$field][1] : null;
40 - $html .= call_user_func(
41 - array( self::$fieldTypes[$config['type']], 'render' ), $field, $config, $answer, $answerData
 47+ $html .= call_user_func( array( self::$fieldTypes[$config['type']], 'render' ),
 48+ $field, $config, $answer, $answerData
4249 );
4350 }
4451 $html .= Xml::closeElement( 'dl' );
4552 return $html;
4653 }
 54+
 55+ /**
 56+ * Save a survey to the database
 57+ * @param $name string Survey name
 58+ * @param $survey array Survey configuration data
 59+ */
4760 public static function save( $name, $survey ) {
4861 global $wgRequest, $wgUser;
4962 $dbw = wfGetDb( DB_MASTER );
50 - $now = $dbw->timestamp( wfTimestamp() );
 63+ $now = $dbw->timestamp();
5164 foreach ( $survey['questions'] as $question => $config ) {
5265 $dbw->insert(
5366 'prefswitch_survey',
@@ -68,7 +81,22 @@
6982
7083 /* Static Functions */
7184
 85+ /**
 86+ * Render the HTML for a question
 87+ * @param $question string Question ID
 88+ * @param $config array Configuration array, including answers. See $wgPrefSwitchSurveys for format
 89+ * @param $answer string ID of currently selected answer
 90+ * @param $answerData string Data for currently selected answer
 91+ * @return string HTML
 92+ */
7293 public static function render( $question, $config, $answer, $answerData );
 94+
 95+ /**
 96+ * Get values to insert into the database for a question
 97+ * @param $question Question ID
 98+ * @param $request WebRequest object containing answer data
 99+ * @return array( field => value )
 100+ */
73101 public static function save( $question, $request );
74102 }
75103 class PrefSwitchSurveyFieldSelect implements PrefSwitchSurveyField {
@@ -106,6 +134,7 @@
107135 $html .= Xml::closeElement( 'dd' );
108136 return $html;
109137 }
 138+
110139 public static function save( $question, $request ) {
111140 $answer = $request->getVal( "prefswitch-survey-{$question}", '' );
112141 switch ( $answer ) {
@@ -262,10 +291,11 @@
263292 return $html;
264293 }
265294 public static function save( $question, $request ) {
 295+ $answer = $request->getVal( "prefswitch-survey-{$question}", null );
266296 return array(
267 - 'pss_answer' => $request->getVal( "prefswitch-survey-{$question}", null ),
268 - 'pss_answer_data' => $insert['pss_answer'] == 'true' || $insert['pss_answer'] == 'false' ?
269 - $request->getVal( "prefswitch-survey-{$question}-if{$insert['pss_answer']}", null ) : null,
 297+ 'pss_answer' => $answer
 298+ 'pss_answer_data' => $answer == 'true' || $answer == 'false' ?
 299+ $request->getVal( "prefswitch-survey-{$question}-if{$answer}", null ) : null,
270300 );
271301 }
272302 }
@@ -290,17 +320,10 @@
291321 public static function save( $question, $request ) {
292322 $x = $request->getVal( "prefswitch-survey-{$question}-x" );
293323 $y = $request->getVal( "prefswitch-survey-{$question}-y" );
294 - if ( $x === '' && $y === '' ) {
295 - return array(
296 - 'pss_answer' => null,
297 - 'pss_answer_data' => null,
298 - );
299 - } else {
300 - return array(
301 - 'pss_answer' => null,
302 - 'pss_answer_data' => $x . 'x' . $y,
303 - );
304 - }
 324+ return array(
 325+ 'pss_answer' => null,
 326+ 'pss_answer_data' => ( $x != '' || $y != '' ) ? "{$x}x{$y}" : null,
 327+ );
305328 }
306329 }
307330 class PrefSwitchSurveyFieldText implements PrefSwitchSurveyField {
@@ -316,16 +339,9 @@
317340 }
318341 public static function save( $question, $request ) {
319342 $answer = $request->getVal( "prefswitch-survey-{$question}" );
320 - if ( $answer === '' ) {
321 - return array(
322 - 'pss_answer' => null,
323 - 'pss_answer_data' => null,
324 - );
325 - } else {
326 - return array(
327 - 'pss_answer' => null,
328 - 'pss_answer_data' => $answer,
329 - );
330 - }
 343+ return array(
 344+ 'pss_answer' => null,
 345+ 'pss_answer_data' => $answer !== '' ? $answer : null,
 346+ );
331347 }
332348 }
Index: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php
@@ -20,10 +20,10 @@
2121
2222 $wgPrefSwitchStyleVersion = 1;
2323
24 -// Preferences to set when users swtich prefs
 24+// Preferences to set when users switch prefs
2525 // array(
26 -// in => array( pref => value ),
27 -// out => array( pref => value ),
 26+// 'off' => array( pref => value ),
 27+// 'on' => array( pref => value ),
2828 // )
2929 $wgPrefSwitchPrefs = array(
3030 'off' => array(
@@ -41,18 +41,22 @@
4242 // Survey questions to ask when users switch prefs
4343 // array(
4444 // survey-id => array(
45 -// field-id => array(
46 -// question => msg-id,
47 -// type => msg-id,
48 -// answers => array(
49 -// answer => msg-id,
50 -// ...
 45+// 'submit-msg' => message key for submit button caption
 46+// 'updateable' => boolean,
 47+// 'questions' => array(
 48+// field-id => array(
 49+// 'question' => msg-id,
 50+// 'type' => msg-id,
 51+// 'answers' => array(
 52+// answer => msg-id,
 53+// ...
 54+// ),
 55+// 'other' => msg-id,
 56+// 'ifyes' => msg-id
5157 // ),
52 -// other => msg-id,
53 -// ifyes => msg-id
 58+// ...
5459 // ),
55 -// ...
56 -// ),
 60+// )
5761 // )
5862 $wgPrefSwitchSurveys = array();
5963 $wgPrefSwitchSurveys['feedback'] = array(
@@ -131,8 +135,8 @@
132136 // Credits
133137 $wgExtensionCredits['other'][] = array(
134138 'path' => __FILE__,
135 - 'name' => 'PrefStat',
136 - 'author' => 'Roan Kattouw',
 139+ 'name' => 'PrefSwitch',
 140+ 'author' => array( 'Trevor Parscal', 'Roan Kattouw' ),
137141 'version' => '0.1.2',
138142 'url' => 'http://www.mediawiki.org/wiki/Extension:UsabilityInitiative',
139143 'descriptionmsg' => 'prefswitch-desc',
Index: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.sql
@@ -22,4 +22,4 @@
2323 pss_answer_data text NULL
2424 ) /*$wgDBTableOptions*/;
2525
26 -CREATE UNIQUE INDEX /*i*/pss_user_timestamp_question ON /*_*/prefswitch_survey (pss_user, pss_timestamp, pss_question, pss_name);
 26+CREATE UNIQUE INDEX /*i*/pss_user_timestamp_name_question ON /*_*/prefswitch_survey (pss_user, pss_timestamp, pss_name, pss_question);

Follow-up revisions

RevisionCommit summaryAuthorDate
r64533Followup to r64532: forgot to commit a filecatrope21:15, 2 April 2010

Status & tagging log