Index: trunk/extensions/Favorites/FavUser.php |
— | — | @@ -1,36 +0,0 @@ |
2 | | -<?php |
3 | | -class FavUser extends User { |
4 | | - /** |
5 | | - * Check the Favorited status of an article. |
6 | | - * @param $title \type{Title} Title of the article to look at |
7 | | - * @return \bool True if article is Favorited |
8 | | - */ |
9 | | - function isFavorited( $title ) { |
10 | | - global $wgUser; |
11 | | - $fl = FavoritedItem::fromUserTitle( $wgUser, $title ); |
12 | | - return $fl->isFavorited(); |
13 | | - |
14 | | - } |
15 | | - |
16 | | - /** |
17 | | - * Favorite an article. |
18 | | - * @param $title \type{Title} Title of the article to look at |
19 | | - */ |
20 | | - function addFavorite( $title ) { |
21 | | - global $wgUser; |
22 | | - $fl = FavoritedItem::fromUserTitle( $wgUser, $title ); |
23 | | - $fl->addFavorite(); |
24 | | - $title->invalidateCache(); |
25 | | - } |
26 | | - |
27 | | - /** |
28 | | - * Stop Favoriting an article. |
29 | | - * @param $title \type{Title} Title of the article to look at |
30 | | - */ |
31 | | - function removeFavorite( $title ) { |
32 | | - global $wgUser; |
33 | | - $fl = FavoritedItem::fromUserTitle( $wgUser, $title ); |
34 | | - $fl->removeFavorite(); |
35 | | - $title->invalidateCache(); |
36 | | - } |
37 | | -} |
Index: trunk/extensions/Favorites/FavTitle.php |
— | — | @@ -1,44 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | - |
5 | | -class FavTitle extends Title { |
6 | | - |
7 | | - |
8 | | - var $mFav = null; |
9 | | - var $mTextform; |
10 | | - var $mTitle; |
11 | | - |
12 | | - function __construct() {} |
13 | | - |
14 | | - /** |
15 | | - * Is $wgUser watching this page? |
16 | | - * @return \type{\bool} |
17 | | - */ |
18 | | - public function userIsFavoriting() { |
19 | | - |
20 | | - global $wgUser, $wgArticle; |
21 | | - $favUser = new FavUser(); |
22 | | - if ($wgArticle) { |
23 | | - if ( is_null( $this->mFav ) ) { |
24 | | - if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn()) { |
25 | | - $this->mFav = false; |
26 | | - } else { |
27 | | - $this->mFav = $favUser->isFavorited( $wgArticle->mTitle ); |
28 | | - } |
29 | | - } |
30 | | - } |
31 | | - return $this->mFav; |
32 | | - } |
33 | | - |
34 | | - public function moveToFav($title, &$nt ) { |
35 | | - # Update watchlists |
36 | | - $oldnamespace = $title->getNamespace() & ~1; |
37 | | - $newnamespace = $nt->getNamespace() & ~1; |
38 | | - $oldtitle = $title->getDBkey(); |
39 | | - $newtitle = $nt->getDBkey(); |
40 | | - |
41 | | - if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) { |
42 | | - FavoritedItem::duplicateEntries( $title, $nt ); |
43 | | - } |
44 | | - } |
45 | | -} |
Index: trunk/extensions/Favorites/Favorites_body.php |
— | — | @@ -1,64 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class Favorites extends QuickTemplate { |
5 | | - |
6 | | - var $mTitle; |
7 | | - |
8 | | - function execute() { |
9 | | - |
10 | | - } |
11 | | - |
12 | | - function favoritesIcon( &$sktemplate, &$links ) { |
13 | | - |
14 | | - global $wgUseIconFavorite, $wgRequest, $wgArticle; |
15 | | - |
16 | | - //$sktemplate->skin = $sktemplate->data['skin']; |
17 | | - $action = $wgRequest->getText( 'action' ); |
18 | | - |
19 | | - // See if this object even exists - if the user can't read it, the object doesn't get created. |
20 | | - if ($wgArticle) { |
21 | | - |
22 | | - if ( $wgUseIconFavorite ) { |
23 | | - $class = 'icon '; |
24 | | - $place = 'views'; |
25 | | - } else { |
26 | | - $class = ''; |
27 | | - $place = 'actions'; |
28 | | - } |
29 | | - $favTitle = new FavTitle(); |
30 | | - |
31 | | - //$mode = $this->mTitle->userIsFavoriting() ? 'unfavorite' : 'favorite'; |
32 | | - $mode = $favTitle->userIsFavoriting() ? 'unfavorite' : 'favorite'; |
33 | | - $links[$place][$mode] = array( |
34 | | - 'class' => $class . ( ( $action == 'favorite' || $action == 'unfavorite' ) ? ' selected' : false ), |
35 | | - 'text' => wfMsg( $mode ), // uses 'favorite' or 'unfavorite' message |
36 | | - 'href' => $wgArticle->mTitle->getLocalUrl( 'action=' . $mode ) |
37 | | - ); |
38 | | - |
39 | | - |
40 | | - return false; |
41 | | - } |
42 | | - |
43 | | -} |
44 | | - |
45 | | -function favoritesTabs($skin, &$content_actions) { |
46 | | - global $wgUseIconFavorite, $wgRequest, $wgArticle; |
47 | | - |
48 | | - $action = $wgRequest->getText( 'action' ); |
49 | | - $favTitle = new FavTitle(); |
50 | | - $mode = $favTitle->userIsFavoriting() ? 'unfavorite' : 'favorite'; |
51 | | - // See if this object even exists - if the user can't read it, the object doesn't get created. |
52 | | - if ($wgArticle) { |
53 | | - $content_actions[$mode] = array ( |
54 | | - 'class' => (( $action == 'favorite' || $action == 'unfavorite' ) ? ' selected' : false ), |
55 | | - 'text' => wfMsg( $mode ), // uses 'favorite' or 'unfavorite' message |
56 | | - 'href' => $wgArticle->mTitle->getLocalUrl( 'action=' . $mode ) |
57 | | - ); |
58 | | - return true; |
59 | | - } |
60 | | - |
61 | | - |
62 | | -} |
63 | | - |
64 | | -} |
65 | | - |
Index: trunk/extensions/Favorites/FavArticle.php |
— | — | @@ -1,96 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | - |
5 | | -class FavArticle extends Article { |
6 | | - |
7 | | - |
8 | | - var $mTitle; |
9 | | - |
10 | | - |
11 | | - |
12 | | - /** |
13 | | - * User-interface handler for the "favorite" action |
14 | | - */ |
15 | | - public function favorite() { |
16 | | - global $wgUser, $wgOut, $wgArticle; |
17 | | - |
18 | | - $this->mTitle = $wgArticle->mTitle; |
19 | | - |
20 | | - if ( $wgUser->isAnon() ) { |
21 | | - $wgOut->showErrorPage( 'favoritenologin', 'favoritenologintext' ); |
22 | | - return; |
23 | | - } |
24 | | - if ( wfReadOnly() ) { |
25 | | - $wgOut->readOnlyPage(); |
26 | | - return; |
27 | | - } |
28 | | - if ( $this->doFavorite() ) { |
29 | | - $wgOut->setPagetitle( wfMsg( 'addedfavorite' ) ); |
30 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
31 | | - $wgOut->addWikiMsg( 'addedfavoritetext', $this->mTitle->getPrefixedText() ); |
32 | | - } |
33 | | - $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() ); |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * Add this page to $wgUser's favoritelist |
38 | | - * @return bool true on successful favorite operation |
39 | | - */ |
40 | | - public function doFavorite() { |
41 | | - global $wgUser; |
42 | | - $favUser = new FavUser(); |
43 | | - if ( $wgUser->isAnon() ) { |
44 | | - return false; |
45 | | - } |
46 | | - if ( wfRunHooks( 'FavoriteArticle', array( &$wgUser, &$this ) ) ) { |
47 | | - $favUser->addFavorite( $this->mTitle ); |
48 | | - return wfRunHooks( 'FavoriteArticleComplete', array( &$wgUser, &$this ) ); |
49 | | - } |
50 | | - |
51 | | - } |
52 | | - |
53 | | - /** |
54 | | - * User interface handler for the "unfavorite" action. |
55 | | - */ |
56 | | - public function unfavorite($action, $wgArticle) { |
57 | | - global $wgUser, $wgOut, $wgArticle; |
58 | | - $this->mTitle = $wgArticle->mTitle; |
59 | | - if ( $wgUser->isAnon() ) { |
60 | | - $wgOut->showErrorPage( 'favoritenologin', 'favoritenologintext' ); |
61 | | - return; |
62 | | - } |
63 | | - if ( wfReadOnly() ) { |
64 | | - $wgOut->readOnlyPage(); |
65 | | - return; |
66 | | - } |
67 | | - if ( $this->doUnfavorite() ) { |
68 | | - $wgOut->setPagetitle( wfMsg( 'removedfavorite' ) ); |
69 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
70 | | - $wgOut->addWikiMsg( 'removedfavoritetext', $wgArticle->mTitle->getPrefixedText() ); |
71 | | - } |
72 | | - $wgOut->returnToMain( true, $wgArticle->mTitle->getPrefixedText() ); |
73 | | - |
74 | | - return false; |
75 | | - |
76 | | - } |
77 | | - |
78 | | - /** |
79 | | - * Stop favoriting a page |
80 | | - * @return bool true on successful unfavorite |
81 | | - */ |
82 | | - public function doUnfavorite() { |
83 | | - global $wgUser; |
84 | | - |
85 | | - $favUser = new FavUser(); |
86 | | - if ( $wgUser->isAnon() ) { |
87 | | - return false; |
88 | | - } |
89 | | - if ( wfRunHooks( 'UnfavoriteArticle', array( &$wgUser, &$this ) ) ) { |
90 | | - $favUser->removeFavorite( $this->mTitle ); |
91 | | - return wfRunHooks( 'UnfavoriteArticleComplete', array( &$wgUser, &$this ) ); |
92 | | - } |
93 | | - return false; |
94 | | - } |
95 | | - |
96 | | - |
97 | | -} |
Index: trunk/extensions/Favorites/FavParser.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | |
6 | 6 | function wfSpecialFavoritelist($argv, $parser) { |
7 | 7 | |
8 | | - global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle; |
| 8 | + global $wgUser, $wgOut, $wgLang, $wgRequest; |
9 | 9 | global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, $wgShowUpdatedMarker; |
10 | 10 | $output = ''; |
11 | 11 | |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' ); |
14 | 14 | //$wgOut->setRobotPolicy( 'noindex,nofollow' ); |
15 | 15 | |
16 | | - $this->mTitle = $wgArticle->mTitle; |
| 16 | + $this->mTitle = $parser->getTitle(); |
17 | 17 | |
18 | 18 | if ($this->mTitle->getNamespace() == NS_USER && array_key_exists('userpage', $argv) && $argv['userpage']) { |
19 | 19 | $parts = explode( '/', $this->mTitle->getText() ); |
Index: trunk/extensions/Favorites/SpecialFavoritelist.php |
— | — | @@ -343,7 +343,7 @@ |
344 | 344 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
345 | 345 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
346 | 346 | 'action' => $self->getLocalUrl( array( 'action' => 'edit' ) ) ) ); |
347 | | - $form .= Xml::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
| 347 | + $form .= Html::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
348 | 348 | //$form .= "<fieldset>\n<legend>" . wfMsgHtml( 'favoritelistedit-normal-legend' ) . "</legend>"; |
349 | 349 | //$form .= wfMsgExt( 'favoritelistedit-normal-explain', 'parse' ); |
350 | 350 | $form .= $this->buildRemoveList( $user, $wgUser->getSkin() ); |
— | — | @@ -459,7 +459,7 @@ |
460 | 460 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
461 | 461 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
462 | 462 | 'action' => $self->getLocalUrl( array( 'action' => 'raw' ) ) ) ); |
463 | | - $form .= Xml::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
| 463 | + $form .= Html::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
464 | 464 | $form .= '<fieldset><legend>' . wfMsgHtml( 'favoritelistedit-raw-legend' ) . '</legend>'; |
465 | 465 | $form .= wfMsgExt( 'favoritelistedit-raw-explain', 'parse' ); |
466 | 466 | $form .= Xml::label( wfMsg( 'favoritelistedit-raw-titles' ), 'titles' ); |
Index: trunk/extensions/Favorites/FavoritelistEditor.php |
— | — | @@ -325,7 +325,7 @@ |
326 | 326 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
327 | 327 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
328 | 328 | 'action' => $self->getLocalUrl( array( 'action' => 'edit' ) ) ) ); |
329 | | - $form .= Xml::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
| 329 | + $form .= Html::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
330 | 330 | $form .= "<fieldset>\n<legend>" . wfMsgHtml( 'favoritelistedit-normal-legend' ) . "</legend>"; |
331 | 331 | $form .= wfMsgExt( 'favoritelistedit-normal-explain', 'parse' ); |
332 | 332 | $form .= $this->buildRemoveList( $user, $wgUser->getSkin() ); |
— | — | @@ -443,7 +443,7 @@ |
444 | 444 | $self = SpecialPage::getTitleFor( 'Favoritelist' ); |
445 | 445 | $form = Xml::openElement( 'form', array( 'method' => 'post', |
446 | 446 | 'action' => $self->getLocalUrl( array( 'action' => 'raw' ) ) ) ); |
447 | | - $form .= Xml::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
| 447 | + $form .= Html::hidden( 'token', $wgUser->editToken( 'favoritelistedit' ) ); |
448 | 448 | $form .= '<fieldset><legend>' . wfMsgHtml( 'favoritelistedit-raw-legend' ) . '</legend>'; |
449 | 449 | $form .= wfMsgExt( 'favoritelistedit-raw-explain', 'parse' ); |
450 | 450 | $form .= Xml::label( wfMsg( 'favoritelistedit-raw-titles' ), 'titles' ); |
Index: trunk/extensions/Favorites/Favorites.php |
— | — | @@ -1,22 +1,22 @@ |
2 | 2 | <?php |
3 | | -/* |
4 | | -Copyright (C) 2011 Jeremy Lemley |
| 3 | +/** |
| 4 | + * Copyright (C) 2011 Jeremy Lemley |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + * |
| 19 | + */ |
5 | 20 | |
6 | | - This program is free software: you can redistribute it and/or modify |
7 | | - it under the terms of the GNU General Public License as published by |
8 | | - the Free Software Foundation, either version 3 of the License, or |
9 | | - (at your option) any later version. |
10 | | - |
11 | | - This program is distributed in the hope that it will be useful, |
12 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | - GNU General Public License for more details. |
15 | | - |
16 | | - You should have received a copy of the GNU General Public License |
17 | | - along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | | - |
19 | | -*/ |
20 | | - |
21 | 21 | $wgExtensionCredits['specialpage'][] = array( |
22 | 22 | 'path' => __FILE__, |
23 | 23 | 'name' => 'Favorites', |
— | — | @@ -25,156 +25,39 @@ |
26 | 26 | 'version' => '0.2.6', |
27 | 27 | 'url' => "http://www.mediawiki.org/wiki/Extension:Favorites", |
28 | 28 | ); |
29 | | - |
30 | | -global $wgUseIconFavorite, $wgFavoritesPersonalURL; |
31 | 29 | |
32 | 30 | $dir = dirname(__FILE__) . '/'; |
33 | 31 | $wgExtensionMessagesFiles['Favorites'] = $dir . 'favorites.i18n.php'; |
34 | | -$wgAutoloadClasses['Favorites'] = $dir . 'Favorites_body.php'; |
35 | 32 | $wgAutoloadClasses['FavoritelistEditor'] = $dir . 'FavoritelistEditor.php'; |
36 | 33 | $wgAutoloadClasses['FavoritedItem'] = $dir . 'FavoritedItem.php'; |
37 | 34 | $wgAutoloadClasses['SpecialFavoritelist'] = $dir . 'SpecialFavoritelist.php'; |
38 | | -$wgAutoloadClasses['FavUser'] = $dir . 'FavUser.php'; |
39 | | -$wgAutoloadClasses['FavArticle'] = $dir . 'FavArticle.php'; |
40 | | -$wgAutoloadClasses['FavTitle'] = $dir . 'FavTitle.php'; |
| 35 | +$wgAutoloadClasses['FavoritesHooks'] = $dir . 'FavoritesHooks.php'; |
41 | 36 | $wgAutoloadClasses['FavParser'] = $dir . 'FavParser.php'; |
42 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'FavSQLUpdate'; |
| 37 | + |
43 | 38 | $wgSpecialPages['Favoritelist'] = 'SpecialFavoritelist'; |
44 | 39 | $wgSpecialPageGroups['Favoritelist'] = 'other'; |
45 | 40 | |
| 41 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'FavoritesHooks::onLoadExtensionSchemaUpdates'; |
46 | 42 | |
47 | 43 | //tag hook |
48 | | -$wgHooks['ParserFirstCallInit'][] = 'ParseFavorites'; |
| 44 | +$wgHooks['ParserFirstCallInit'][] = 'FavoritesHooks::onParserFirstCallInit'; |
49 | 45 | |
50 | | - |
51 | 46 | //add the icon / link |
52 | | -$wgHooks['SkinTemplateNavigation'][] = 'fnNavUrls'; // For Vector |
53 | | -$wgHooks['SkinTemplateTabs'][] = 'fnNavTabs'; // For other skins |
| 47 | +$wgHooks['SkinTemplateNavigation'][] = 'FavoritesHooks::onSkinTemplateNavigation'; // For Vector |
| 48 | +$wgHooks['SkinTemplateTabs'][] = 'FavoritesHooks::onSkinTemplateTabs'; // For other skins |
54 | 49 | |
55 | | -if ($wgUseIconFavorite){ |
56 | | - //add CSS - only needed for icon display |
57 | | - $wgHooks['BeforePageDisplay'][] = 'fnAddCss'; |
58 | | -} |
| 50 | +//add CSS - only needed for icon display |
| 51 | +$wgHooks['BeforePageDisplay'][] = 'FavoritesHooks::onBeforePageDisplay'; |
59 | 52 | |
60 | 53 | //add or remove |
61 | | -$wgHooks['UnknownAction'][] = 'fnAction'; |
| 54 | +$wgHooks['UnknownAction'][] = 'FavoritesHooks::onUnknownAction'; |
62 | 55 | |
63 | 56 | //handle page moves and deletes |
64 | | -$wgHooks['TitleMoveComplete'][] = 'fnHookMoveToFav'; |
65 | | -$wgHooks['ArticleDeleteComplete'][] = 'fnHookDeleteFav'; |
| 57 | +$wgHooks['TitleMoveComplete'][] = 'FavoritesHooks::onTitleMoveComplete'; |
| 58 | +$wgHooks['ArticleDeleteComplete'][] = 'FavoritesHooks::onArticleDeleteComplete'; |
66 | 59 | |
67 | | -// Do we want to display a "My Favorites" link in the personal urls area? |
68 | | -if ($wgFavoritesPersonalURL) { |
69 | | - $wgHooks['PersonalUrls'][] = 'onAddPersonalUrls'; |
70 | | -} |
| 60 | +// Display a "My Favorites" link in the personal urls area |
| 61 | +$wgHooks['PersonalUrls'][] = 'FavoritesHooks::onPersonalUrls'; |
71 | 62 | |
72 | | -function onAddPersonalUrls( &$personal_urls, &$wgTitle ) { |
73 | | - global $wgUser; |
74 | | - |
75 | | - // $skin = $wgUser->getSkin(); |
76 | | - $title = Title::newFromText( 'Special:Favoritelist' ); |
77 | | - if( $wgUser->getID() ) { |
78 | | - $url['userpage'] = array_shift( $personal_urls ); |
79 | | - $url[] = array_shift( $personal_urls ); |
80 | | - $url[] = array_shift( $personal_urls ); |
81 | | - |
82 | | - $url[] = array( 'text' => wfMsg( 'myfavoritelist' ), |
83 | | - 'href' => $title->getLocalURL( ) |
84 | | - ); |
85 | | - |
86 | | - |
87 | | - $personal_urls = $url + $personal_urls; |
88 | | - } |
89 | | - |
90 | | - return true; |
91 | | -} |
92 | | - |
93 | | -function fnAction ($action, $article) { |
94 | | - $title = new Title(); |
95 | | - $favArticle = new FavArticle($title); |
96 | | - |
97 | | - if ($action == 'unfavorite') { |
98 | | - $favArticle->unfavorite($action, $article); |
99 | | - |
100 | | - } elseif ($action == 'favorite') { |
101 | | - $favArticle->favorite($action, $article); |
102 | | - } else { |
103 | | - return true; |
104 | | - } |
105 | | - return false; |
106 | | -} |
107 | | - |
108 | | -function fnNavUrls($sktemplate, &$links) { |
109 | | - $fNav = new Favorites(); |
110 | | - $fNav->favoritesIcon($sktemplate, $links); |
111 | | - return true; |
112 | | -} |
113 | | - |
114 | | -function fnNavTabs( $skin, &$content_actions ){ |
115 | | - $fNav = new Favorites(); |
116 | | - $fNav->favoritesTabs($skin, $content_actions); |
117 | | - return true; |
118 | | -} |
119 | | - |
120 | | - |
121 | | -function fnHookMoveToFav(&$title, &$nt, &$wgUser, $pageid, $redirid ) { |
122 | | - $favTitle = new FavTitle(); |
123 | | - $favTitle->moveToFav($title, $nt, $wgUser, $pageid, $redirid ); |
124 | | - return true; |
125 | | -} |
126 | | - |
127 | | -function fnHookDeleteFav(&$article, &$user, $reason, $id ){ |
128 | | - $dbw = wfGetDB( DB_MASTER ); |
129 | | - $dbw->delete('favoritelist', array( |
130 | | - 'fl_title' => $article->mTitle->getDBKey()), |
131 | | - $fname = 'Database::delete'); |
132 | | - return true; |
133 | | -} |
134 | | - |
135 | | -function fnAddCss (&$out) { |
136 | | - global $wgExtensionAssetsPath; |
137 | | - $out->addStyle($wgExtensionAssetsPath . '/Favorites/favorites.css'); |
138 | | - return true; |
139 | | -} |
140 | | - |
141 | | -function ParseFavorites(Parser &$parser) { |
142 | | - |
143 | | - $parser->setHook( 'favorites', 'favParser_Render' ); |
144 | | - |
145 | | - return true; |
146 | | -} |
147 | | - |
148 | | - |
149 | | -$markerList = array(); |
150 | | -function favParser_Render ( $input, $argv, $parser) { |
151 | | - # The parser function itself |
152 | | - # The input parameters are wikitext with templates expanded |
153 | | - # The output should be wikitext too |
154 | | - //$output = "Parser Output goes here."; |
155 | | - |
156 | | - $favParse = new FavParser(); |
157 | | - $output = $favParse->wfSpecialFavoritelist($argv, $parser); |
158 | | - $parser->disableCache(); |
159 | | - return $output; |
160 | | - |
161 | | -} |
162 | | - |
163 | | - |
164 | | -# Schema updates for update.php |
165 | | -function FavSQLUpdate( $updater = null ) { |
166 | | - if ( $updater === null ) { |
167 | | - // <= 1.16 support |
168 | | - global $wgExtNewTables, $wgExtModifiedFields; |
169 | | - $wgExtNewTables[] = array( |
170 | | - 'favoritelist', |
171 | | - dirname( __FILE__ ) . '/favorites.sql' |
172 | | - ); |
173 | | - |
174 | | - } else { |
175 | | - // >= 1.17 support |
176 | | - $updater->addExtensionUpdate( array( 'addTable', 'favoritelist', |
177 | | - dirname( __FILE__ ) . '/favorites.sql', true ) ); |
178 | | - |
179 | | - } |
180 | | - return true; |
181 | | -} |
\ No newline at end of file |
| 63 | +$wgFavoritesPersonalURL = true; |
| 64 | +$wgUseIconFavorite = true; |
Index: trunk/extensions/Favorites/FavoritesHooks.php |
— | — | @@ -0,0 +1,199 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class FavoritesHooks { |
| 5 | + |
| 6 | + public static function onLoadExtensionSchemaUpdates( $updater = null ) { |
| 7 | + if ( $updater === null ) { // <= 1.16 support |
| 8 | + global $wgExtNewTables, $wgExtModifiedFields; |
| 9 | + $wgExtNewTables[] = array( |
| 10 | + 'favoritelist', |
| 11 | + dirname( __FILE__ ) . '/favorites.sql' |
| 12 | + ); |
| 13 | + } else { // >= 1.17 support |
| 14 | + $updater->addExtensionUpdate( array( 'addTable', 'favoritelist', |
| 15 | + dirname( __FILE__ ) . '/favorites.sql', true ) ); |
| 16 | + } |
| 17 | + return true; |
| 18 | + } |
| 19 | + |
| 20 | + public static function onUnknownAction( $action, $article ) { |
| 21 | + global $wgUser, $wgOut; |
| 22 | + |
| 23 | + if ( $action !== 'unfavorite' && $action !== 'favorite' ) { |
| 24 | + return true; |
| 25 | + } |
| 26 | + |
| 27 | + if ( $wgUser->isAnon() ) { |
| 28 | + $wgOut->showErrorPage( 'favoritenologin', 'favoritenologintext' ); |
| 29 | + return; |
| 30 | + } |
| 31 | + if ( wfReadOnly() ) { |
| 32 | + $wgOut->readOnlyPage(); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 37 | + |
| 38 | + if ( $action === 'favorite' ) { |
| 39 | + if ( self::doFavorite( $article ) ) { |
| 40 | + $wgOut->setPagetitle( wfMsg( 'addedfavorite' ) ); |
| 41 | + $wgOut->addWikiMsg( 'addedfavoritetext', $article->getTitle()->getPrefixedText() ); |
| 42 | + } |
| 43 | + } else { |
| 44 | + if ( self::doUnfavorite( $article ) ) { |
| 45 | + $wgOut->setPagetitle( wfMsg( 'removedfavorite' ) ); |
| 46 | + $wgOut->addWikiMsg( 'removedfavoritetext', $article->getTitle()->getPrefixedText() ); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + $wgOut->returnToMain( true, $article->getTitle()->getPrefixedText() ); |
| 51 | + |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Add this page to $wgUser's favoritelist |
| 57 | + * @return bool true on successful favorite operation |
| 58 | + */ |
| 59 | + private static function doFavorite( $article ) { |
| 60 | + global $wgUser; |
| 61 | + |
| 62 | + if ( $wgUser->isAnon() ) { |
| 63 | + return false; |
| 64 | + } |
| 65 | + if ( wfRunHooks( 'FavoriteArticle', array( &$wgUser, &$article ) ) ) { |
| 66 | + $fl = FavoritedItem::fromUserTitle( $wgUser, $article->getTitle() ); |
| 67 | + $fl->addFavorite(); |
| 68 | + $article->getTitle()->invalidateCache(); |
| 69 | + return wfRunHooks( 'FavoriteArticleComplete', array( &$wgUser, &$article ) ); |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Stop favoriting a page |
| 76 | + * @return bool true on successful unfavorite |
| 77 | + */ |
| 78 | + private static function doUnfavorite( $article ) { |
| 79 | + global $wgUser; |
| 80 | + |
| 81 | + if ( $wgUser->isAnon() ) { |
| 82 | + return false; |
| 83 | + } |
| 84 | + if ( wfRunHooks( 'UnfavoriteArticle', array( &$wgUser, &$article ) ) ) { |
| 85 | + $fl = FavoritedItem::fromUserTitle( $wgUser, $article->getTitle() ); |
| 86 | + $fl->removeFavorite(); |
| 87 | + $article->getTitle()->invalidateCache(); |
| 88 | + return wfRunHooks( 'UnfavoriteArticleComplete', array( &$wgUser, &$article ) ); |
| 89 | + } |
| 90 | + return false; |
| 91 | + } |
| 92 | + |
| 93 | + public static function onPersonalUrls( &$personal_urls, &$wgTitle ) { |
| 94 | + global $wgFavoritesPersonalURL, $wgUser; |
| 95 | + |
| 96 | + if ( $wgFavoritesPersonalURL && $wgUser->isLoggedIn() ) { |
| 97 | + $url['userpage'] = array_shift( $personal_urls ); |
| 98 | + $url[] = array_shift( $personal_urls ); |
| 99 | + $url[] = array_shift( $personal_urls ); |
| 100 | + |
| 101 | + $url[] = array( 'text' => wfMsg( 'myfavoritelist' ), |
| 102 | + 'href' => SpecialPage::getTitleFor( 'Favoritelist' )->getLocalURL() ); |
| 103 | + $personal_urls = $url + $personal_urls; |
| 104 | + } |
| 105 | + |
| 106 | + return true; |
| 107 | + } |
| 108 | + |
| 109 | + public static function onParserFirstCallInit( &$parser ) { |
| 110 | + $parser->setHook( 'favorites', array( __CLASS__, 'renderFavorites' ) ); |
| 111 | + return true; |
| 112 | + } |
| 113 | + |
| 114 | + function renderFavorites( $input, $argv, $parser ) { |
| 115 | + # The parser function itself |
| 116 | + # The input parameters are wikitext with templates expanded |
| 117 | + # The output should be wikitext too |
| 118 | + //$output = "Parser Output goes here."; |
| 119 | + |
| 120 | + $favParse = new FavParser(); |
| 121 | + $output = $favParse->wfSpecialFavoritelist( $argv, $parser ); |
| 122 | + $parser->disableCache(); |
| 123 | + return $output; |
| 124 | + } |
| 125 | + |
| 126 | + public static function onSkinTemplateNavigation( $skin, &$links ) { |
| 127 | + global $wgUseIconFavorite, $wgRequest, $wgUser; |
| 128 | + |
| 129 | + $action = $wgRequest->getText( 'action' ); |
| 130 | + $title = $skin->getTitle(); |
| 131 | + |
| 132 | + if ( $title->getNamespace() >= NS_MAIN ) { |
| 133 | + if ( $wgUseIconFavorite ) { |
| 134 | + $class = 'icon '; |
| 135 | + $place = 'views'; |
| 136 | + } else { |
| 137 | + $class = ''; |
| 138 | + $place = 'actions'; |
| 139 | + } |
| 140 | + |
| 141 | + $fl = FavoritedItem::fromUserTitle( $wgUser, $title ); |
| 142 | + |
| 143 | + $mode = $fl->isFavorited() ? 'unfavorite' : 'favorite'; |
| 144 | + $links[$place][$mode] = array( |
| 145 | + 'class' => $class . ( ( $action == 'favorite' || $action == 'unfavorite' ) ? ' selected' : false ), |
| 146 | + 'text' => wfMsg( $mode ), // uses 'favorite' or 'unfavorite' message |
| 147 | + 'href' => $title->getLocalUrl( 'action=' . $mode ) |
| 148 | + ); |
| 149 | + } |
| 150 | + return true; |
| 151 | + } |
| 152 | + |
| 153 | + public static function onSkinTemplateTabs( $skin, &$content_actions ) { |
| 154 | + global $wgUseIconFavorite, $wgUser, $wgRequest; |
| 155 | + |
| 156 | + $action = $wgRequest->getText( 'action' ); |
| 157 | + $title = $skin->getTitle(); |
| 158 | + if ( $title->getNamespace() >= NS_MAIN ) { |
| 159 | + $fl = FavoritedItem::fromUserTitle( $wgUser, $title ); |
| 160 | + $mode = $fl->isFavorited() ? 'unfavorite' : 'favorite'; |
| 161 | + $content_actions[$mode] = array ( |
| 162 | + 'class' => (( $action == 'favorite' || $action == 'unfavorite' ) ? ' selected' : false ), |
| 163 | + 'text' => wfMsg( $mode ), // uses 'favorite' or 'unfavorite' message |
| 164 | + 'href' => $title->getLocalUrl( 'action=' . $mode ) |
| 165 | + ); |
| 166 | + } |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
| 170 | + public static function onTitleMoveComplete( &$title, &$nt, &$user, $pageid, $redirid ) { |
| 171 | + # Update watchlists |
| 172 | + $oldnamespace = $title->getNamespace() & ~1; |
| 173 | + $newnamespace = $nt->getNamespace() & ~1; |
| 174 | + $oldtitle = $title->getDBkey(); |
| 175 | + $newtitle = $nt->getDBkey(); |
| 176 | + |
| 177 | + if ( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) { |
| 178 | + FavoritedItem::duplicateEntries( $title, $nt ); |
| 179 | + } |
| 180 | + return true; |
| 181 | + } |
| 182 | + |
| 183 | + public static function onArticleDeleteComplete(&$article, &$user, $reason, $id ){ |
| 184 | + $dbw = wfGetDB( DB_MASTER ); |
| 185 | + $dbw->delete( 'favoritelist', array( |
| 186 | + 'fl_title' => $article->mTitle->getDBKey() ), |
| 187 | + __METHOD__ ); |
| 188 | + return true; |
| 189 | + } |
| 190 | + |
| 191 | + public static function onBeforePageDisplay( $out ) { |
| 192 | + global $wgUseIconFavorite, $wgExtensionAssetsPath; |
| 193 | + |
| 194 | + if ( $wgUseIconFavorite ) { |
| 195 | + $out->addStyle( $wgExtensionAssetsPath . '/Favorites/favorites.css' ); |
| 196 | + } |
| 197 | + |
| 198 | + return true; |
| 199 | + } |
| 200 | +} |
Property changes on: trunk/extensions/Favorites/FavoritesHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 201 | + native |