Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | * @param $key string - the name of a property |
41 | 41 | */ |
42 | 42 | public function getProperty( $key ) { |
43 | | - if( array_key_exists( $key, $this->property) ) { |
| 43 | + if ( array_key_exists( $key, $this->property ) ) { |
44 | 44 | return $this->property[$key]; |
45 | 45 | } else { |
46 | 46 | return null; |
— | — | @@ -48,11 +48,11 @@ |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Setter method |
52 | | - * @param $key string - the name of the property |
| 52 | + * @param $key string - the name of the property |
53 | 53 | * @param $value mixed - the valud of the property |
54 | 54 | */ |
55 | 55 | public function setProperty( $key, $value ) { |
56 | | - if( array_key_exists( $key, $this->property) ) { |
| 56 | + if ( array_key_exists( $key, $this->property ) ) { |
57 | 57 | $this->property[$key] = $value; |
58 | 58 | } |
59 | 59 | } |
— | — | @@ -137,23 +137,23 @@ |
138 | 138 | * @exception MWMarkAsHelpFulItemSearchKeyException |
139 | 139 | */ |
140 | 140 | public function loadFromDatabase( $conds ) { |
141 | | - |
| 141 | + |
142 | 142 | $searchKey = array_keys ( $conds ); |
143 | | - |
| 143 | + |
144 | 144 | $flag = sort( $searchKey ); |
145 | | - |
| 145 | + |
146 | 146 | if ( !$flag ) { |
147 | 147 | return false; |
148 | 148 | } |
149 | | - |
150 | | - $searchKey = implode(',', $searchKey ); |
151 | | - |
| 149 | + |
| 150 | + $searchKey = implode( ',', $searchKey ); |
| 151 | + |
152 | 152 | $allowableSearchKey = array ( 'mah_id', 'mah_item,mah_type,mah_user_id,mah_user_ip' ); |
153 | | - |
| 153 | + |
154 | 154 | if ( !in_array( $searchKey, $allowableSearchKey ) ) { |
155 | 155 | throw new MWMarkAsHelpFulItemSearchKeyException( 'Invalid search key!' ); |
156 | 156 | } |
157 | | - |
| 157 | + |
158 | 158 | $dbr = wfGetDB( DB_SLAVE ); |
159 | 159 | |
160 | 160 | $res = $dbr->selectRow( |
— | — | @@ -163,8 +163,8 @@ |
164 | 164 | __METHOD__ |
165 | 165 | ); |
166 | 166 | |
167 | | - if( $res !== false ) { |
168 | | - foreach( $this->property as $key => $val ) { |
| 167 | + if ( $res !== false ) { |
| 168 | + foreach ( $this->property as $key => $val ) { |
169 | 169 | $this->setProperty( $key, $res->$key ); |
170 | 170 | } |
171 | 171 | |
— | — | @@ -178,7 +178,7 @@ |
179 | 179 | /** |
180 | 180 | * To mark an item as helpful, this function should be called after either loadFromRequest() or setProperty() |
181 | 181 | * data must be validated if called from setProperty() |
182 | | - * |
| 182 | + * |
183 | 183 | */ |
184 | 184 | public function mark() { |
185 | 185 | if ( $this->userHasMarked() ) { |
— | — | @@ -205,15 +205,15 @@ |
206 | 206 | * @param $currentUser Object - the current user who is browsing the site |
207 | 207 | */ |
208 | 208 | public function unmark( $currentUser ) { |
209 | | - |
| 209 | + |
210 | 210 | if ( $currentUser->isAnon() ) { |
211 | 211 | return; |
212 | 212 | } |
213 | | - |
| 213 | + |
214 | 214 | if ( $this->getProperty( 'mah_id' ) ) { |
215 | | - |
| 215 | + |
216 | 216 | if ( !$this->getProperty( 'mah_type' ) ) { |
217 | | - if( !$this->loadFromDatabase( array( 'mah_id' => $this->getProperty( 'mah_id' ) ) ) ) { |
| 217 | + if ( !$this->loadFromDatabase( array( 'mah_id' => $this->getProperty( 'mah_id' ) ) ) ) { |
218 | 218 | return; |
219 | 219 | } |
220 | 220 | } |
— | — | @@ -221,11 +221,11 @@ |
222 | 222 | $user = $this->getUser(); |
223 | 223 | |
224 | 224 | if ( $user ) { |
225 | | - |
| 225 | + |
226 | 226 | if ( !$user->isAnon() ) { |
227 | | - |
| 227 | + |
228 | 228 | if ( $currentUser->getId() == $user->getId() ) { |
229 | | - |
| 229 | + |
230 | 230 | $dbw = wfGetDB( DB_MASTER ); |
231 | 231 | |
232 | 232 | $dbw->delete( |
— | — | @@ -233,11 +233,11 @@ |
234 | 234 | array( 'mah_id' => $this->getProperty( 'mah_id' ) ), |
235 | 235 | __METHOD__ |
236 | 236 | ); |
237 | | - |
| 237 | + |
238 | 238 | } |
239 | | - |
| 239 | + |
240 | 240 | } |
241 | | - |
| 241 | + |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
— | — | @@ -310,9 +310,9 @@ |
311 | 311 | |
312 | 312 | $list = array(); |
313 | 313 | |
314 | | - foreach( $res AS $val ) { |
315 | | - $list[$val->user_id] = array( 'user_name' => $val->user_name, |
316 | | - 'user_id' => $val->user_id, |
| 314 | + foreach ( $res AS $val ) { |
| 315 | + $list[$val->user_id] = array( 'user_name' => $val->user_name, |
| 316 | + 'user_id' => $val->user_id, |
317 | 317 | 'user_ip' => $val->mah_user_ip ); |
318 | 318 | } |
319 | 319 | |