Index: branches/REL1_17/extensions/Favorites/FavParser.php |
— | — | @@ -4,14 +4,28 @@ |
5 | 5 | |
6 | 6 | function wfSpecialFavoritelist($argv, $parser) { |
7 | 7 | |
8 | | - global $wgUser, $wgOut, $wgLang, $wgRequest; |
| 8 | + global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle; |
9 | 9 | global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker; |
10 | 10 | $output = ''; |
11 | | - |
| 11 | + |
12 | 12 | $skin = $wgUser->getSkin(); |
13 | 13 | $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' ); |
14 | 14 | //$wgOut->setRobotPolicy( 'noindex,nofollow' ); |
15 | | - |
| 15 | + |
| 16 | + $this->mTitle = $wgArticle->mTitle; |
| 17 | + |
| 18 | + if ($this->mTitle->getNamespace() == NS_USER && array_key_exists('userpage', $argv) && $argv['userpage']) { |
| 19 | + $parts = explode( '/', $this->mTitle->getText() ); |
| 20 | + $rootPart = $parts[0]; |
| 21 | + $user = User::newFromName( $rootPart, true /* don't allow IP users*/ ); |
| 22 | + //echo "Userpage: $user"; |
| 23 | + $output = $this->viewFavList($user, $output, $wgRequest, $argv); |
| 24 | + $output .= $this->editlink($argv, $skin); |
| 25 | + return $output ; |
| 26 | + } else { |
| 27 | + $user = $wgUser; |
| 28 | + } |
| 29 | + |
16 | 30 | # Anons don't get a favoritelist |
17 | 31 | if( $wgUser->isAnon() ) { |
18 | 32 | //$wgOut->setPageTitle( wfMsg( 'favoritenologin' ) ); |
— | — | @@ -22,34 +36,21 @@ |
23 | 37 | array( 'returnto' => $specialTitle->getPrefixedText() ) |
24 | 38 | ); |
25 | 39 | $output = wfMsgHtml( 'favoritelistanontext', $llink ) ; |
26 | | - |
27 | | - |
28 | 40 | return $output ; |
29 | 41 | |
30 | 42 | } |
31 | 43 | |
32 | | - $output = $this->viewFavList($wgUser, $output, $wgRequest); |
33 | | - if ( array_key_exists('editlink', $argv) && $argv['editlink']) { |
34 | | - # Add an edit link if you want it: |
35 | | - $output .= "<div id='contentSub'><br>" . |
36 | | - $skin->link( |
37 | | - SpecialPage::getTitleFor( 'Favoritelist', 'edit' ), |
38 | | - wfMsgHtml( "favoritelisttools-edit" ), |
39 | | - array(), |
40 | | - array(), |
41 | | - array( 'known', 'noclasses' ) |
42 | | - ) . "</div>"; |
43 | | - } |
| 44 | + $output = $this->viewFavList($user, $output, $wgRequest, $argv); |
| 45 | + $output .= $this->editlink($argv, $skin); |
44 | 46 | |
45 | 47 | return $output ; |
46 | 48 | } |
47 | 49 | |
48 | 50 | |
49 | | - private function viewFavList ($user, $output, $request) { |
50 | | - global $wgUser, $wgOut, $wgLang, $wgRequest; |
51 | | - $uid = $wgUser->getId(); |
| 51 | + private function viewFavList ($user, $output, $request, $argv) { |
| 52 | + global $wgOut, $wgLang, $wgRequest; |
52 | 53 | $output = $this->showNormalForm( $output, $user ); |
53 | | - |
| 54 | + $uid=$user->getId(); |
54 | 55 | $dbr = wfGetDB( DB_SLAVE, 'favoritelist' ); |
55 | 56 | |
56 | 57 | $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)', |
— | — | @@ -60,11 +61,35 @@ |
61 | 62 | $output = wfmsg('nofavoritelist'); |
62 | 63 | |
63 | 64 | } |
| 65 | + |
64 | 66 | return $output; |
65 | 67 | } |
66 | 68 | |
67 | | - |
68 | 69 | /** |
| 70 | + * Does the user want to display an editlink? |
| 71 | + * |
| 72 | + * @param $argv Array of values from the parser |
| 73 | + * $param $skin User skin |
| 74 | + * @return Output |
| 75 | + */ |
| 76 | + private function editlink($argv, $skin) { |
| 77 | + $output=''; |
| 78 | + if ( array_key_exists('editlink', $argv) && $argv['editlink']) { |
| 79 | + # Add an edit link if you want it: |
| 80 | + $output = "<div id='contentSub'><br>" . |
| 81 | + $skin->link( |
| 82 | + SpecialPage::getTitleFor( 'Favoritelist', 'edit' ), |
| 83 | + wfMsgHtml( "favoritelisttools-edit" ), |
| 84 | + array(), |
| 85 | + array(), |
| 86 | + array( 'known', 'noclasses' ) |
| 87 | + ) . "</div>"; |
| 88 | + } |
| 89 | + return $output; |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + /** |
69 | 94 | * Extract a list of titles from a blob of text, returning |
70 | 95 | * (prefixed) strings; unfavoritable titles are ignored |
71 | 96 | * |
— | — | @@ -201,8 +226,8 @@ |
202 | 227 | * @param $user User |
203 | 228 | */ |
204 | 229 | private function showNormalForm( $output, $user ) { |
205 | | - global $wgUser, $wgOut; |
206 | | - $skin = $wgUser->getSkin(); |
| 230 | + global $wgOut; |
| 231 | + $skin = $user->getSkin(); |
207 | 232 | if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) { |
208 | 233 | $form = $this->buildRemoveList( $user, $skin ); |
209 | 234 | $output .= $form ; |
Index: branches/REL1_17/extensions/Favorites/SpecialFavoritelist.php |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | $dbr = wfGetDB( DB_SLAVE, 'favoritelist' ); |
107 | 107 | // $recentchanges = $dbr->tableName( 'recentchanges' ); |
108 | 108 | |
109 | | - $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(*)', |
| 109 | + $favoritelistCount = $dbr->selectField( 'favoritelist', 'COUNT(fl_user)', |
110 | 110 | array( 'fl_user' => $uid ), __METHOD__ ); |
111 | 111 | // Adjust for page X, talk:page X, which are both stored separately, |
112 | 112 | // but treated together |
— | — | @@ -199,7 +199,7 @@ |
200 | 200 | */ |
201 | 201 | private function countFavoritelist( $user ) { |
202 | 202 | $dbr = wfGetDB( DB_MASTER ); |
203 | | - $res = $dbr->select( 'favoritelist', 'COUNT(*) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ ); |
| 203 | + $res = $dbr->select( 'favoritelist', 'COUNT(fl_user) AS count', array( 'fl_user' => $user->getId() ), __METHOD__ ); |
204 | 204 | $row = $dbr->fetchObject( $res ); |
205 | 205 | return ceil( $row->count ); // Paranoia |
206 | 206 | } |
— | — | @@ -216,8 +216,11 @@ |
217 | 217 | $dbr = wfGetDB( DB_MASTER ); |
218 | 218 | $res = $dbr->select( |
219 | 219 | 'favoritelist', |
220 | | - '*', |
221 | 220 | array( |
| 221 | + 'fl_namespace', |
| 222 | + 'fl_title' |
| 223 | + ), |
| 224 | + array( |
222 | 225 | 'fl_user' => $user->getId(), |
223 | 226 | ), |
224 | 227 | __METHOD__ |
— | — | @@ -270,35 +273,8 @@ |
271 | 274 | return $titles; |
272 | 275 | } |
273 | 276 | |
274 | | - /** |
275 | | - * Show a message indicating the number of items on the user's favoritelist, |
276 | | - * and return this count for additional checking |
277 | | - * |
278 | | - * @param $output OutputPage |
279 | | - * @param $user User |
280 | | - * @return int |
281 | | - */ |
282 | | - private function showItemCount( $output, $user ) { |
283 | | - if( ( $count = $this->countFavoritelist( $user ) ) > 0 ) { |
284 | | - //$output->addHTML( wfMsgExt( 'favoritelistedit-numitems', 'parse', |
285 | | - // $GLOBALS['wgLang']->formatNum( $count ) ) ); |
286 | | - } else { |
287 | | - //$output->addHTML( wfMsgExt( 'favoritelistedit-noitems', 'parse' ) ); |
288 | | - } |
289 | | - return $count; |
290 | | - } |
291 | 277 | |
292 | | - /** |
293 | | - * Remove all titles from a user's favoritelist |
294 | | - * |
295 | | - * @param $user User |
296 | | - */ |
297 | | - private function clearFavoritelist( $user ) { |
298 | | - $dbw = wfGetDB( DB_MASTER ); |
299 | | - $dbw->delete( 'favoritelist', array( 'fl_user' => $user->getId() ), __METHOD__ ); |
300 | | - } |
301 | | - |
302 | | - /** |
| 278 | +/** |
303 | 279 | * Add a list of titles to a user's favoritelist |
304 | 280 | * |
305 | 281 | * $titles can be an array of strings or Title objects; the former |
— | — | @@ -316,12 +292,6 @@ |
317 | 293 | if( $title instanceof Title ) { |
318 | 294 | $rows[] = array( |
319 | 295 | 'fl_user' => $user->getId(), |
320 | | - 'fl_namespace' => ( $title->getNamespace() & ~1 ), |
321 | | - 'fl_title' => $title->getDBkey(), |
322 | | - 'fl_notificationtimestamp' => null, |
323 | | - ); |
324 | | - $rows[] = array( |
325 | | - 'fl_user' => $user->getId(), |
326 | 296 | 'fl_namespace' => ( $title->getNamespace() | 1 ), |
327 | 297 | 'fl_title' => $title->getDBkey(), |
328 | 298 | 'fl_notificationtimestamp' => null, |
— | — | @@ -350,15 +320,6 @@ |
351 | 321 | 'favoritelist', |
352 | 322 | array( |
353 | 323 | 'fl_user' => $user->getId(), |
354 | | - 'fl_namespace' => ( $title->getNamespace() & ~1 ), |
355 | | - 'fl_title' => $title->getDBkey(), |
356 | | - ), |
357 | | - __METHOD__ |
358 | | - ); |
359 | | - $dbw->delete( |
360 | | - 'favoritelist', |
361 | | - array( |
362 | | - 'fl_user' => $user->getId(), |
363 | 324 | 'fl_namespace' => ( $title->getNamespace() | 1 ), |
364 | 325 | 'fl_title' => $title->getDBkey(), |
365 | 326 | ), |
— | — | @@ -378,7 +339,7 @@ |
379 | 340 | */ |
380 | 341 | private function showNormalForm( $output, $user ) { |
381 | 342 | global $wgUser; |
382 | | - if( ( $count = $this->showItemCount( $output, $user ) ) > 0 ) { |
| 343 | + if( ( $count = $this->countFavoritelist($user ) ) > 0 ) { |
383 | 344 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
384 | 345 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
385 | 346 | 'action' => $self->getLocalUrl( array( 'action' => 'edit' ) ) ) ); |
— | — | @@ -494,7 +455,7 @@ |
495 | 456 | */ |
496 | 457 | public function showRawForm( $output, $user ) { |
497 | 458 | global $wgUser; |
498 | | - $this->showItemCount( $output, $user ); |
| 459 | + $this->countFavoritelist( $user ); |
499 | 460 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
500 | 461 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
501 | 462 | 'action' => $self->getLocalUrl( array( 'action' => 'raw' ) ) ) ); |
Index: branches/REL1_17/extensions/Favorites/Favorites.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | 'name' => 'Favorites', |
24 | 24 | 'author' => 'Jeremy Lemley', |
25 | 25 | 'descriptionmsg' => 'favorites-desc', |
26 | | - 'version' => '0.1.4', |
| 26 | + 'version' => '0.2.0', |
27 | 27 | 'url' => "http://www.mediawiki.org/wiki/Extension:Favorites", |
28 | 28 | ); |
29 | 29 | |