r93113 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93112‎ | r93113 | r93114 >
Date:21:03, 25 July 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Trim trailing whitespace
Modified paths:
  • /trunk/extensions/MoodBar/ApiMoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/FeedbackItem.php (modified) (history)
  • /trunk/extensions/MoodBar/Formatter.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.hooks.php (modified) (history)
  • /trunk/extensions/MoodBar/MoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/SpecialMoodBar.php (modified) (history)
  • /trunk/extensions/MoodBar/exportMoodBar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/ApiMoodBar.php
@@ -3,28 +3,28 @@
44 class ApiMoodBar extends ApiBase {
55 public function execute() {
66 $params = $this->extractRequestParams();
7 -
 7+
88 $params['page'] = Title::newFromText( $params['page'] );
9 -
 9+
1010 // Params are deliberately named the same as the properties,
1111 // just slurp them through.
1212 $item = MBFeedbackItem::create( array() );
13 -
 13+
1414 $setParams = array();
1515 foreach( $params as $key => $value ) {
1616 if ( $item->isValidKey( $key ) ) {
1717 $setParams[$key] = $value;
1818 }
1919 }
20 -
 20+
2121 $item->setProperties( $setParams );
22 -
 22+
2323 $item->save();
24 -
 24+
2525 $result = array( 'result' => 'success' );
2626 $this->getResult()->addValue( null, $this->getModuleName(), $result );
2727 }
28 -
 28+
2929 public function needsToken() {
3030 return true;
3131 }
@@ -70,13 +70,7 @@
7171 public function getVersion() {
7272 return __CLASS__ . ': $Id$';
7373 }
74 -
75 - public function getPossibleErrors() {
76 - return array_merge( parent::getPossibleErrors(), array(
77 -
78 - ) );
79 - }
80 -
 74+
8175 public function getParamDescription() {
8276 return array(
8377 'page' => 'The page the feedback is on',
@@ -91,7 +85,7 @@
9286 'token' => 'An edit token',
9387 );
9488 }
95 -
 89+
9690 public function getDescription() {
9791 return 'Allows users to submit feedback about their experiences on the site';
9892 }
Index: trunk/extensions/MoodBar/FeedbackItem.php
@@ -13,12 +13,12 @@
1414 'comment', // The feedback itself
1515 'page', // The page where it was submitted
1616 'type',
17 -
 17+
1818 // Housekeeping
1919 'timestamp',
2020 'user', // User object who submitted the feedback
2121 'anonymize',
22 -
 22+
2323 // Statistics
2424 'useragent',
2525 'system',
@@ -27,22 +27,22 @@
2828 'bucket',
2929 'user-editcount',
3030 );
31 -
 31+
3232 /** Valid values for the 'type' parameter. **/
3333 protected static $validTypes = array( 'happy', 'sad', 'confused' );
34 -
 34+
3535 /**
3636 * Default constructor.
3737 * Don't use this, use either MBFeedbackItem::newFromRow or MBFeedbackItem::create
3838 */
3939 protected function __construct() {
4040 $this->data = array_fill_keys( $this->validMembers, null );
41 -
 41+
4242 // Non-nullable boolean fields
4343 $this->setProperty('anonymize', false);
4444 $this->setProperty('editmode', false);
4545 }
46 -
 46+
4747 /**
4848 * Factory function to create a new MBFeedbackItem
4949 * @param $info Associative array of values
@@ -55,7 +55,7 @@
5656 $newObject->initialiseNew( $info );
5757 return $newObject;
5858 }
59 -
 59+
6060 /**
6161 * Initialiser for new MBFeedbackItems
6262 * @param $info Associative array of values
@@ -63,16 +63,16 @@
6464 */
6565 protected function initialiseNew( $info ) {
6666 global $wgUser;
67 -
 67+
6868 $template = array(
6969 'user' => $wgUser,
7070 'timestamp' => wfTimestampNow(),
7171 );
72 -
 72+
7373 $this->setProperties( $template );
7474 $this->setProperties( $info );
7575 }
76 -
 76+
7777 /**
7878 * Factory function to load an MBFeedbackItem from a DB row.
7979 * @param $row A row, from DatabaseBase::fetchObject
@@ -83,7 +83,7 @@
8484 $newObject->initialiseFromRow( $row );
8585 return $newObject;
8686 }
87 -
 87+
8888 /**
8989 * Initialiser for MBFeedbackItems loaded from the database
9090 * @param $row A row object from DatabaseBase::fetchObject
@@ -103,9 +103,9 @@
104104 'editmode' => $row->mbf_editing,
105105 'user-editcount' => $row->mbf_user_editcount,
106106 );
107 -
 107+
108108 $properties['page'] = Title::makeTitleSafe( $row->mbf_namespace, $row->mbf_title );
109 -
 109+
110110 if ( !empty($row->user_id) ) {
111111 $properties['user'] = User::newFromRow( $row );
112112 } elseif ( $row->mbf_user_id > 0 ) {
@@ -113,10 +113,10 @@
114114 } else {
115115 $properties['user'] = User::newFromName( $row->mbf_user_ip );
116116 }
117 -
 117+
118118 $this->setProperties( $properties );
119119 }
120 -
 120+
121121 /**
122122 * Set a group of properties. Throws an exception on invalid property.
123123 * @param $values An associative array of properties to set.
@@ -126,15 +126,15 @@
127127 if ( ! $this->isValidKey($key) ) {
128128 throw new MWException( "Attempt to set invalid property $key" );
129129 }
130 -
 130+
131131 if ( ! $this->validatePropertyValue($key, $value) ) {
132132 throw new MWException( "Attempt to set invalid value for $key" );
133133 }
134 -
 134+
135135 $this->data[$key] = $value;
136136 }
137137 }
138 -
 138+
139139 /**
140140 * Set a group of values.
141141 * @param $key The property to set.
@@ -143,7 +143,7 @@
144144 public function setProperty( $key, $value ) {
145145 $this->setProperties( array( $key => $value ) );
146146 }
147 -
 147+
148148 /**
149149 * Get a property.
150150 * @param $key The property to get
@@ -153,10 +153,10 @@
154154 if ( ! $this->isValidKey($key) ) {
155155 throw new MWException( "Attempt to get invalid property $key" );
156156 }
157 -
 157+
158158 return $this->data[$key];
159159 }
160 -
 160+
161161 /**
162162 * Check a property key for validity.
163163 * If a property key is valid, it will be prefilled to NULL.
@@ -165,7 +165,7 @@
166166 public function isValidKey( $key ) {
167167 return in_array( $key, $this->validMembers );
168168 }
169 -
 169+
170170 /**
171171 * Check if a property value is valid for that property
172172 * @param $key The key of the property to check.
@@ -182,36 +182,36 @@
183183 } elseif ( $key == 'comment' ) {
184184 return mb_strlen( $value ) <= 140;
185185 }
186 -
 186+
187187 return true;
188188 }
189 -
 189+
190190 /**
191191 * Writes this MBFeedbackItem to the database.
192192 * Throws an exception if this it is already in the database.
193193 * @return The MBFeedbackItem's new ID.
194194 */
195195 public function save() {
196 -
 196+
197197 if ( $this->getProperty('id') ) {
198198 throw new MWException( "This ".__CLASS__." is already in the database." );
199199 }
200 -
 200+
201201 // Add edit count if necessary
202202 if ( $this->getProperty('user-editcount') === null &&
203203 $this->getProperty('user') )
204204 {
205205 $value = $this->getProperty('user');
206 -
 206+
207207 if ( $value->isAnon() ) {
208208 $this->setProperty( 'user-editcount', 0 );
209209 } else {
210210 $this->setProperty( 'user-editcount', $value->getEditCount() );
211211 }
212212 }
213 -
 213+
214214 $dbw = wfGetDB( DB_MASTER );
215 -
 215+
216216 $row = array(
217217 'mbf_id' => $dbw->nextSequenceValue( 'moodbar_feedback_mbf_id' ),
218218 'mbf_type' => $this->getProperty('type'),
@@ -225,7 +225,7 @@
226226 'mbf_editing' => $this->getProperty('editmode'),
227227 'mbf_user_editcount' => $this->getProperty('user-editcount'),
228228 );
229 -
 229+
230230 $user = $this->getProperty('user');
231231 if ( $user->isAnon() ) {
232232 $row['mbf_user_id'] = 0;
@@ -233,25 +233,25 @@
234234 } else {
235235 $row['mbf_user_id'] = $user->getId();
236236 }
237 -
 237+
238238 $page = $this->getProperty('page');
239239 if ( $page ) {
240240 $row['mbf_namespace'] = $page->getNamespace();
241241 $row['mbf_title'] = $page->getDBkey();
242242 }
243 -
 243+
244244 $dbw->insert( 'moodbar_feedback', $row, __METHOD__ );
245 -
 245+
246246 $this->setProperty( 'id', $dbw->insertId() );
247 -
 247+
248248 return $this->getProperty('id');
249249 }
250 -
 250+
251251 /**
252252 * Gets the valid types of a feedback item.
253253 */
254254 public static function getValidTypes() {
255255 return self::$validTypes;
256256 }
257 -
 257+
258258 }
Index: trunk/extensions/MoodBar/Formatter.php
@@ -15,7 +15,7 @@
1616 switch( $field ) {
1717 case 'page':
1818 $title = $data->getProperty('page');
19 -
 19+
2020 global $wgUser;
2121 $linker = $wgUser->getSkin();
2222 $outData = $linker->link( $title );
@@ -38,10 +38,10 @@
3939 $outData = htmlspecialchars( $outData );
4040 break;
4141 }
42 -
 42+
4343 return $outData;
4444 }
45 -
 45+
4646 /**
4747 * Gets an internal representation of $field from $data.
4848 * @param $data MBFeedbackItem to retrieve the data from.
@@ -50,7 +50,7 @@
5151 */
5252 public static function getInternalRepresentation( $data, $field ) {
5353 $outData = null;
54 -
 54+
5555 switch( $field ) {
5656 case 'namespace':
5757 $page = $data->getProperty('page');
@@ -86,7 +86,7 @@
8787 default:
8888 $outData = $data->getProperty($field);
8989 }
90 -
 90+
9191 return $outData;
9292 }
9393 }
Index: trunk/extensions/MoodBar/MoodBar.php
@@ -119,7 +119,6 @@
120120 ),
121121 );
122122
123 -
124123 /** Configuration **/
125124 /** The registration time after which users will be shown the MoodBar **/
126125 $wgMoodBarCutoffTime = null;
Index: trunk/extensions/MoodBar/SpecialMoodBar.php
@@ -17,24 +17,24 @@
1818 'mbf_user_agent' => 'useragent',
1919 'mbf_comment' => 'comment',
2020 );
21 -
 21+
2222 function __construct() {
2323 parent::__construct( 'MoodBar', 'moodbar-view' );
2424 }
25 -
 25+
2626 function execute($par) {
2727 global $wgUser, $wgOut;
28 -
 28+
2929 if ( !$this->userCanExecute( $wgUser ) ) {
3030 $this->displayRestrictionError();
3131 return;
3232 }
33 -
 33+
3434 $wgOut->setPageTitle( wfMsg( 'moodbar-admin-title' ) );
3535 $wgOut->addWikiMsg( 'moodbar-admin-intro' );
36 -
 36+
3737 $pager = new MoodBarPager();
38 -
 38+
3939 if ( $pager->getNumRows() > 0 ) {
4040 $wgOut->addHTML(
4141 $pager->getNavigationBar() .
@@ -50,38 +50,38 @@
5151 class MoodBarPager extends TablePager {
5252 function getFieldNames() {
5353 static $headers = null;
54 -
 54+
5555 if ( is_null( $headers ) ) {
5656 $headers = array();
5757 foreach( SpecialMoodBar::$fields as $field => $property ) {
5858 $headers[$field] = wfMessage("moodbar-header-$property")->text();
5959 }
6060 }
61 -
 61+
6262 return $headers;
6363 }
64 -
 64+
6565 // Overridden from TablePager, it's just easier because
6666 // we're doing things with a proper object model
6767 function formatRow( $row ) {
6868 $out = '';
69 -
 69+
7070 $data = MBFeedbackItem::load( $row );
7171 $outData = null;
72 -
 72+
7373 foreach( SpecialMoodBar::$fields as $field ) {
7474 $outData = MoodBarFormatter::getHTMLRepresentation( $data, $field );
7575 $out .= Xml::tags( 'td', null, $outData );
7676 }
77 -
 77+
7878 $out = Xml::tags( 'tr', $this->getRowAttrs($row), $out ) . "\n";
7979 return $out;
8080 }
81 -
 81+
8282 function formatValue( $name, $value ) {
8383 return '';
8484 }
85 -
 85+
8686 function getQueryInfo() {
8787 $info = array(
8888 'tables' => array('moodbar_feedback', 'user'),
@@ -93,14 +93,14 @@
9494 ),
9595 ),
9696 );
97 -
 97+
9898 return $info;
9999 }
100 -
 100+
101101 function getDefaultSort() {
102102 return 'mbf_id';
103103 }
104 -
 104+
105105 function isFieldSortable( $name ) {
106106 $sortable = array(
107107 'mbf_id',
@@ -108,10 +108,10 @@
109109 'mbf_user_id',
110110 'mbf_namespace',
111111 );
112 -
 112+
113113 return in_array( $name, $sortable );
114114 }
115 -
 115+
116116 function getTitle() {
117117 return SpecialPage::getTitleFor( 'MoodBar' );
118118 }
Index: trunk/extensions/MoodBar/MoodBar.hooks.php
@@ -8,10 +8,10 @@
99 if ( self::shouldShowMoodbar( $output, $skin ) ) {
1010 $output->addModules( array( 'ext.moodBar.init', 'ext.moodBar.core' ) );
1111 }
12 -
 12+
1313 return true;
1414 }
15 -
 15+
1616 /**
1717 * Determines whether or not we should show the MoodBar.
1818 */
@@ -26,11 +26,11 @@
2727 }
2828 global $wgUser;
2929 $user = $wgUser;
30 -
 30+
3131 if ( $user->isAnon() ) {
3232 return false;
3333 }
34 -
 34+
3535 // Only show MoodBar for users registered after a certain time
3636 global $wgMoodBarCutoffTime;
3737 if ( $wgMoodBarCutoffTime &&
@@ -38,14 +38,14 @@
3939 {
4040 return false;
4141 }
42 -
 42+
4343 if ( class_exists('EditPageTracking') ) {
4444 return ((bool)EditPageTracking::getFirstEditPage($user));
4545 }
46 -
 46+
4747 return true;
4848 }
49 -
 49+
5050 /**
5151 * ResourceLoaderGetConfigVars hook
5252 */
@@ -57,27 +57,27 @@
5858 ) + $wgMoodBarConfig;
5959 return true;
6060 }
61 -
 61+
6262 public static function makeGlobalVariablesScript( &$vars ) {
6363 global $wgUser;
6464 $vars['mbEditToken'] = $wgUser->editToken();
6565 return true;
6666 }
67 -
 67+
6868 /**
6969 * Runs MoodBar schema updates
7070 */
7171 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
7272 $updater->addExtensionUpdate( array( 'addTable', 'moodbar_feedback',
7373 dirname(__FILE__).'/sql/MoodBar.sql', true ) );
74 -
 74+
7575 $updater->addExtensionUpdate( array( 'addField', 'moodbar_feedback',
7676 'mbf_user_editcount', dirname(__FILE__).'/sql/mbf_user_editcount.sql', true )
7777 );
78 -
 78+
7979 return true;
8080 }
81 -
 81+
8282 /**
8383 * Gets the MoodBar testing bucket that a user is in.
8484 * @param $user The user to check
@@ -86,9 +86,9 @@
8787 public static function getUserBuckets( $user ) {
8888 $id = $user->getID();
8989 $buckets = array();
90 -
 90+
9191 // No show-time bucketing yet. This method is a stub.
92 -
 92+
9393 sort($buckets);
9494 return $buckets;
9595 }
Index: trunk/extensions/MoodBar/exportMoodBar.php
@@ -24,33 +24,33 @@
2525 'useragent',
2626 'comment',
2727 );
28 -
 28+
2929 public function __construct() {
3030 parent::__construct();
3131 $this->mDescription = "Exports MoodBar feedback";
3232 $this->addOption( 'since-id', 'Get feedback after this ID' );
3333 $this->addOption( 'since-time', 'Get feedback after this time' );
3434 }
35 -
 35+
3636 public function execute() {
3737 $dbr = wfGetDB( DB_SLAVE );
3838 $lastRowCount = 1;
3939 $fh = fopen('php://stdout', 'w');
40 -
 40+
4141 $offsetCond = array( 1 );
42 -
 42+
4343 if ( $this->getOption('since-id') ) {
4444 $offsetCond[] = 'mbf_id > '.$dbr->addQuotes( $this->getArg('since-id') );
4545 }
46 -
 46+
4747 if ( $this->getOption('since-time') ) {
4848 $ts = $dbr->timestamp( $this->getArg('since-id') );
4949 $offsetCond[] = 'mbf_timestamp > '.$dbr->addQuotes( $ts );
5050 }
51 -
 51+
5252 fputcsv( $fh, $this->fields );
5353 $lastId = 0;
54 -
 54+
5555 while ( $lastRowCount > 0 ) {
5656 $res = $dbr->select(
5757 array('moodbar_feedback','user'),
@@ -65,27 +65,27 @@
6666 )
6767 )
6868 );
69 -
 69+
7070 $lastRowCount = $dbr->numRows( $res );
71 -
 71+
7272 foreach( $res as $row ) {
7373 $this->outputRow( $fh, $row );
7474 $lastId = $row->mbf_id;
7575 }
76 -
 76+
7777 $offsetCond = 'mbf_id > ' . $dbr->addQuotes( $lastId );
7878 }
7979 }
80 -
 80+
8181 protected function outputRow( $fh, $row ) {
8282 $item = MBFeedbackItem::load( $row );
8383 $user = User::newFromRow( $row );
8484 $outData = array();
85 -
 85+
8686 foreach( $this->fields as $field ) {
8787 $outData[] = MoodBarFormatter::getInternalRepresentation( $item, $field );
8888 }
89 -
 89+
9090 fputcsv( $fh, $outData );
9191 }
9292 }

Comments

#Comment by Aaron Schulz (talk | contribs)   21:10, 25 July 2011

getPossibleErrors change wasn't whitespace ;)

#Comment by Reedy (talk | contribs)   21:11, 25 July 2011

It became whitespace!

Status & tagging log