Index: trunk/extensions/MarkAsHelpful/sql/mark_as_helpful.sql |
— | — | @@ -18,4 +18,4 @@ |
19 | 19 | mah_locale varchar(32) binary NULL -- The locale of the user's browser |
20 | 20 | ) /*$wgDBTableOptions*/; |
21 | 21 | |
22 | | -CREATE INDEX /*i*/mah_type_item ON /*_*/mark_as_helpful (mah_type, mah_item); |
| 22 | +CREATE INDEX /*i*/mah_type_item_user_id_ip ON /*_*/mark_as_helpful (mah_type, mah_item, mah_user_id, mah_user_ip); |
Index: trunk/extensions/MarkAsHelpful/MarkAsHelpful.hooks.php |
— | — | @@ -32,8 +32,7 @@ |
33 | 33 | * @param $updater DatabasEUpdater |
34 | 34 | */ |
35 | 35 | public static function onLoadExtensionSchemaUpdates( $updater = null ) { |
36 | | - $updater->addExtensionUpdate( array( 'addTable', 'mark_as_helpful', |
37 | | - dirname( __FILE__ ) . '/sql/mark_as_helpful.sql', true ) ); |
| 36 | + $updater->addExtensionTable( 'mark_as_helpful', dirname( __FILE__ ) . '/sql/mark_as_helpful.sql' ); |
38 | 37 | |
39 | 38 | return true; |
40 | 39 | } |
Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php |
— | — | @@ -136,8 +136,17 @@ |
137 | 137 | */ |
138 | 138 | public function loadFromDatabase( $conds ) { |
139 | 139 | |
140 | | - $searchKey = array_keys( $conds ); |
| 140 | + $searchKey = array(); |
141 | 141 | |
| 142 | + foreach ( $conds AS $key => $value) { |
| 143 | + if ( $value == 'mah_user_ip IS NULL' ) { |
| 144 | + $searchKey[] = 'mah_user_ip'; |
| 145 | + } |
| 146 | + else { |
| 147 | + $searchKey[] = $key; |
| 148 | + } |
| 149 | + } |
| 150 | + |
142 | 151 | $flag = sort( $searchKey ); |
143 | 152 | |
144 | 153 | if ( !$flag ) { |
— | — | @@ -146,7 +155,7 @@ |
147 | 156 | |
148 | 157 | $searchKey = implode(',', $searchKey ); |
149 | 158 | |
150 | | - $allowableSearchKey = array ( 'mah_id', 'mah_item,mah_type,mah_user_id', 'mah_item,mah_type,mah_user_ip' ); |
| 159 | + $allowableSearchKey = array ( 'mah_id', 'mah_item,mah_type,mah_user_id,mah_user_ip' ); |
151 | 160 | |
152 | 161 | if ( !in_array( $searchKey, $allowableSearchKey ) ) { |
153 | 162 | throw new MWMarkAsHelpFulItemSearchKeyException( 'Invalid search key!' ); |
— | — | @@ -203,34 +212,36 @@ |
204 | 213 | * @param $currentUser Object - the current user who is browsing the site |
205 | 214 | */ |
206 | 215 | public function unmark( $currentUser ) { |
| 216 | + |
207 | 217 | if ( $this->getProperty( 'mah_id' ) ) { |
| 218 | + |
208 | 219 | if ( !$this->getProperty( 'mah_type' ) ) { |
209 | 220 | if( !$this->loadFromDatabase( array( 'mah_id' => $this->getProperty( 'mah_id' ) ) ) ) { |
210 | 221 | return; |
211 | 222 | } |
212 | 223 | } |
213 | 224 | |
214 | | - // for sure this is an invalid item |
215 | | - if( !$this->getProperty( 'mah_item' ) ) { |
216 | | - return; |
217 | | - } |
218 | | - |
219 | 225 | $user = $this->getUser(); |
220 | 226 | |
221 | 227 | if ( $user ) { |
222 | | - if ( |
223 | | - $currentUser->getId() == $user->getId() || |
224 | | - $currentUser->getName() == $user->getName() |
225 | | - ) |
226 | | - { |
227 | | - $dbw = wfGetDB( DB_MASTER ); |
| 228 | + |
| 229 | + if ( $currentUser->isAnon() == $user->isAnon() ) { |
| 230 | + |
| 231 | + if ( $currentUser->getId() == $user->getId() || |
| 232 | + $currentUser->getName() == $user->getName() ) { |
| 233 | + |
| 234 | + $dbw = wfGetDB( DB_MASTER ); |
228 | 235 | |
229 | | - $dbw->delete( |
230 | | - 'mark_as_helpful', |
231 | | - array( 'mah_id' => $this->getProperty( 'mah_id' ) ), |
232 | | - __METHOD__ |
233 | | - ); |
| 236 | + $dbw->delete( |
| 237 | + 'mark_as_helpful', |
| 238 | + array( 'mah_id' => $this->getProperty( 'mah_id' ) ), |
| 239 | + __METHOD__ |
| 240 | + ); |
| 241 | + |
| 242 | + } |
| 243 | + |
234 | 244 | } |
| 245 | + |
235 | 246 | } |
236 | 247 | } |
237 | 248 | |
Index: trunk/extensions/MarkAsHelpful/api/ApiMarkAsHelpful.php |
— | — | @@ -28,19 +28,19 @@ |
29 | 29 | case 'unmark': |
30 | 30 | $item = new MarkAsHelpfulItem(); |
31 | 31 | |
| 32 | + $conds = array ( 'mah_type' => $params['type'], |
| 33 | + 'mah_item' => $params['item'] ); |
| 34 | + |
32 | 35 | if( $wgUser->isAnon() ) { |
33 | | - $status = $item->loadFromDatabase( array( |
34 | | - 'mah_type' => $params['type'], |
35 | | - 'mah_item' => $params['item'], |
36 | | - 'mah_user_ip' => $wgUser->getName() |
37 | | - ) ); |
| 36 | + $conds['mah_user_id'] = 0; |
| 37 | + $conds['mah_user_ip'] = $wgUser->getName(); |
38 | 38 | } else { |
39 | | - $status = $item->loadFromDatabase( array( |
40 | | - 'mah_type' => $params['type'], |
41 | | - 'mah_item' => $params['item'], |
42 | | - 'mah_user_id' => $wgUser->getId() |
43 | | - ) ); |
| 39 | + $conds['mah_user_id'] = $wgUser->getId(); |
| 40 | + $conds[] = 'mah_user_ip IS NULL'; |
44 | 41 | } |
| 42 | + |
| 43 | + $status = $item->loadFromDatabase( $conds ); |
| 44 | + |
45 | 45 | if ( $status ) { |
46 | 46 | $item->unmark( $wgUser ); |
47 | 47 | } |