http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95780

Revision: 95780
Author:   ialex
Date:     2011-08-30 13:57:33 +0000 (Tue, 30 Aug 2011)
Log Message:
-----------
* Removed usage of $wgArticle
* Moved all hooks to FavoritesHooks class
* Removed FavArticle, FavTitle, FavUser and Favorites; merged their methods 
where needed
* Changed calls to Xml::hidden() to Html::hidden() since the former doesn't 
exist anymore
* Unconditionally define $wgFavoritesPersonalURL and $wgUseIconFavorite to 
avoid register_globals vulnerability; check their values in the hooks
* Whitespaces fixes

Modified Paths:
--------------
    trunk/extensions/Favorites/FavParser.php
    trunk/extensions/Favorites/FavoritelistEditor.php
    trunk/extensions/Favorites/Favorites.php
    trunk/extensions/Favorites/SpecialFavoritelist.php

Added Paths:
-----------
    trunk/extensions/Favorites/FavoritesHooks.php

Removed Paths:
-------------
    trunk/extensions/Favorites/FavArticle.php
    trunk/extensions/Favorites/FavTitle.php
    trunk/extensions/Favorites/FavUser.php
    trunk/extensions/Favorites/Favorites_body.php

Deleted: trunk/extensions/Favorites/FavArticle.php
===================================================================
--- trunk/extensions/Favorites/FavArticle.php   2011-08-30 13:45:03 UTC (rev 
95779)
+++ trunk/extensions/Favorites/FavArticle.php   2011-08-30 13:57:33 UTC (rev 
95780)
@@ -1,96 +0,0 @@
-<?php
-
-
-class FavArticle extends Article {
-
-               
-       var $mTitle;
-       
-       
-               
-       /**
-        * User-interface handler for the "favorite" action
-        */
-       public function favorite() {
-               global $wgUser, $wgOut, $wgArticle;
-               
-               $this->mTitle = $wgArticle->mTitle;
-               
-               if ( $wgUser->isAnon() ) {
-                       $wgOut->showErrorPage( 'favoritenologin', 
'favoritenologintext' );
-                       return;
-               }
-               if ( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
-               if ( $this->doFavorite() ) {
-                       $wgOut->setPagetitle( wfMsg( 'addedfavorite' ) );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addWikiMsg( 'addedfavoritetext', 
$this->mTitle->getPrefixedText() );
-               }
-               $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
-       }
-
-       /**
-        * Add this page to $wgUser's favoritelist
-        * @return bool true on successful favorite operation
-        */
-       public function doFavorite() {
-               global $wgUser;
-               $favUser = new FavUser();
-               if ( $wgUser->isAnon() ) {
-                       return false;
-               }
-               if ( wfRunHooks( 'FavoriteArticle', array( &$wgUser, &$this ) ) 
) {
-                       $favUser->addFavorite( $this->mTitle );
-                       return wfRunHooks( 'FavoriteArticleComplete', array( 
&$wgUser, &$this ) );
-               }
-
-       }
-
-       /**
-        * User interface handler for the "unfavorite" action.
-        */
-       public function unfavorite($action, $wgArticle) {
-               global $wgUser, $wgOut, $wgArticle;
-               $this->mTitle = $wgArticle->mTitle;
-               if ( $wgUser->isAnon() ) {
-                       $wgOut->showErrorPage( 'favoritenologin', 
'favoritenologintext' );
-                       return;
-               }
-               if ( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
-               if ( $this->doUnfavorite() ) {
-                       $wgOut->setPagetitle( wfMsg( 'removedfavorite' ) );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addWikiMsg( 'removedfavoritetext', 
$wgArticle->mTitle->getPrefixedText() );
-               }
-               $wgOut->returnToMain( true, 
$wgArticle->mTitle->getPrefixedText() );
-               
-               return false;
-               
-       }
-
-       /**
-        * Stop favoriting a page
-        * @return bool true on successful unfavorite
-        */
-       public function doUnfavorite() {
-               global $wgUser;
-               
-               $favUser = new FavUser();
-               if ( $wgUser->isAnon() ) {
-                       return false;
-               }
-               if ( wfRunHooks( 'UnfavoriteArticle', array( &$wgUser, &$this ) 
) ) {
-                       $favUser->removeFavorite( $this->mTitle );
-                       return wfRunHooks( 'UnfavoriteArticleComplete', array( 
&$wgUser, &$this ) );
-               }
-               return false;
-       }
-       
-       
-}

Modified: trunk/extensions/Favorites/FavParser.php
===================================================================
--- trunk/extensions/Favorites/FavParser.php    2011-08-30 13:45:03 UTC (rev 
95779)
+++ trunk/extensions/Favorites/FavParser.php    2011-08-30 13:57:33 UTC (rev 
95780)
@@ -4,7 +4,7 @@
 
        function wfSpecialFavoritelist($argv, $parser) {
                
-               global $wgUser, $wgOut, $wgLang, $wgRequest, $wgArticle;
+               global $wgUser, $wgOut, $wgLang, $wgRequest;
                global $wgRCShowFavoritingUsers, $wgEnotifFavoritelist, 
$wgShowUpdatedMarker;
                $output = '';
        
@@ -12,7 +12,7 @@
                $specialTitle = SpecialPage::getTitleFor( 'Favoritelist' );
                //$wgOut->setRobotPolicy( 'noindex,nofollow' );
                
-               $this->mTitle = $wgArticle->mTitle;
+               $this->mTitle = $parser->getTitle();
                
                if ($this->mTitle->getNamespace() == NS_USER && 
array_key_exists('userpage', $argv) && $argv['userpage']) {
                        $parts = explode( '/', $this->mTitle->getText() );

Deleted: trunk/extensions/Favorites/FavTitle.php
===================================================================
--- trunk/extensions/Favorites/FavTitle.php     2011-08-30 13:45:03 UTC (rev 
95779)
+++ trunk/extensions/Favorites/FavTitle.php     2011-08-30 13:57:33 UTC (rev 
95780)
@@ -1,44 +0,0 @@
-<?php
-
-
-class FavTitle extends Title {
-       
-       
-       var $mFav = null;  
-       var $mTextform;
-       var $mTitle;
-       
-       function __construct() {}
-       
-       /**
-        * Is $wgUser watching this page?
-        * @return \type{\bool}
-        */
-       public function userIsFavoriting() {
-               
-               global $wgUser, $wgArticle; 
-               $favUser = new FavUser();
-               if ($wgArticle) {
-                       if ( is_null( $this->mFav ) ) {
-                               if ( NS_SPECIAL == $this->mNamespace || 
!$wgUser->isLoggedIn()) {
-                                       $this->mFav = false;
-                               } else {
-                                       $this->mFav = $favUser->isFavorited( 
$wgArticle->mTitle ); 
-                               }
-                       }
-               }
-               return $this->mFav;
-       }
-       
-       public function moveToFav($title, &$nt ) {
-               # Update watchlists
-               $oldnamespace = $title->getNamespace() & ~1;
-               $newnamespace = $nt->getNamespace() & ~1;
-               $oldtitle = $title->getDBkey();
-               $newtitle = $nt->getDBkey();
-
-               if( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) {
-                       FavoritedItem::duplicateEntries( $title, $nt );
-               }
-       }
-}

Deleted: trunk/extensions/Favorites/FavUser.php
===================================================================
--- trunk/extensions/Favorites/FavUser.php      2011-08-30 13:45:03 UTC (rev 
95779)
+++ trunk/extensions/Favorites/FavUser.php      2011-08-30 13:57:33 UTC (rev 
95780)
@@ -1,36 +0,0 @@
-<?php
-class FavUser extends User {
-       /**
-        * Check the Favorited status of an article.
-        * @param $title \type{Title} Title of the article to look at
-        * @return \bool True if article is Favorited
-        */
-       function isFavorited( $title ) {
-               global $wgUser;
-               $fl = FavoritedItem::fromUserTitle( $wgUser, $title );
-               return $fl->isFavorited();
-               
-       }
-
-       /**
-        * Favorite an article.
-        * @param $title \type{Title} Title of the article to look at
-        */
-       function addFavorite( $title ) {
-               global $wgUser;
-               $fl = FavoritedItem::fromUserTitle( $wgUser, $title );
-               $fl->addFavorite();
-               $title->invalidateCache();
-       }
-
-       /**
-        * Stop Favoriting an article.
-        * @param $title \type{Title} Title of the article to look at
-        */
-       function removeFavorite( $title ) {
-               global $wgUser;
-               $fl = FavoritedItem::fromUserTitle( $wgUser, $title );
-               $fl->removeFavorite();
-               $title->invalidateCache();
-       }
-}

Modified: trunk/extensions/Favorites/FavoritelistEditor.php
===================================================================
--- trunk/extensions/Favorites/FavoritelistEditor.php   2011-08-30 13:45:03 UTC 
(rev 95779)
+++ trunk/extensions/Favorites/FavoritelistEditor.php   2011-08-30 13:57:33 UTC 
(rev 95780)
@@ -325,7 +325,7 @@
                        $self = SpecialPage::getTitleFor( 'Favoritelist' );
                        $form  = Xml::openElement( 'form', array( 'method' => 
'post',
                                'action' => $self->getLocalUrl( array( 'action' 
=> 'edit' ) ) ) );
-                       $form .= Xml::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
+                       $form .= Html::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
                        $form .= "<fieldset>\n<legend>" . wfMsgHtml( 
'favoritelistedit-normal-legend' ) . "</legend>";
                        $form .= wfMsgExt( 'favoritelistedit-normal-explain', 
'parse' );
                        $form .= $this->buildRemoveList( $user, 
$wgUser->getSkin() );
@@ -443,7 +443,7 @@
                $self = SpecialPage::getTitleFor( 'Favoritelist' );
                $form  = Xml::openElement( 'form', array( 'method' => 'post',
                        'action' => $self->getLocalUrl( array( 'action' => 
'raw' ) ) ) );
-               $form .= Xml::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
+               $form .= Html::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
                $form .= '<fieldset><legend>' . wfMsgHtml( 
'favoritelistedit-raw-legend' ) . '</legend>';
                $form .= wfMsgExt( 'favoritelistedit-raw-explain', 'parse' );
                $form .= Xml::label( wfMsg( 'favoritelistedit-raw-titles' ), 
'titles' );

Modified: trunk/extensions/Favorites/Favorites.php
===================================================================
--- trunk/extensions/Favorites/Favorites.php    2011-08-30 13:45:03 UTC (rev 
95779)
+++ trunk/extensions/Favorites/Favorites.php    2011-08-30 13:57:33 UTC (rev 
95780)
@@ -1,22 +1,22 @@
 <?php
-/*
-Copyright (C) 2011 Jeremy Lemley
+/**
+ * Copyright (C) 2011 Jeremy Lemley
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-    
-*/
-
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'Favorites',
@@ -25,156 +25,39 @@
        'version' => '0.2.6',
        'url' => "http://www.mediawiki.org/wiki/Extension:Favorites";,
 );
- 
-global $wgUseIconFavorite, $wgFavoritesPersonalURL;
 
 $dir = dirname(__FILE__) . '/';
 $wgExtensionMessagesFiles['Favorites'] = $dir . 'favorites.i18n.php';
-$wgAutoloadClasses['Favorites'] = $dir . 'Favorites_body.php';
 $wgAutoloadClasses['FavoritelistEditor'] = $dir . 'FavoritelistEditor.php';
 $wgAutoloadClasses['FavoritedItem'] = $dir . 'FavoritedItem.php';
 $wgAutoloadClasses['SpecialFavoritelist'] = $dir . 'SpecialFavoritelist.php';
-$wgAutoloadClasses['FavUser'] = $dir . 'FavUser.php';
-$wgAutoloadClasses['FavArticle'] = $dir . 'FavArticle.php';
-$wgAutoloadClasses['FavTitle'] = $dir . 'FavTitle.php';
+$wgAutoloadClasses['FavoritesHooks'] = $dir . 'FavoritesHooks.php';
 $wgAutoloadClasses['FavParser'] =  $dir . 'FavParser.php';
-$wgHooks['LoadExtensionSchemaUpdates'][] = 'FavSQLUpdate';
+
 $wgSpecialPages['Favoritelist'] = 'SpecialFavoritelist';
 $wgSpecialPageGroups['Favoritelist'] = 'other';
 
+$wgHooks['LoadExtensionSchemaUpdates'][] = 
'FavoritesHooks::onLoadExtensionSchemaUpdates';
 
 //tag hook
-$wgHooks['ParserFirstCallInit'][] = 'ParseFavorites';
+$wgHooks['ParserFirstCallInit'][] = 'FavoritesHooks::onParserFirstCallInit';
 
-
 //add the icon / link
-$wgHooks['SkinTemplateNavigation'][] = 'fnNavUrls';  // For Vector
-$wgHooks['SkinTemplateTabs'][] = 'fnNavTabs';  // For other skins
+$wgHooks['SkinTemplateNavigation'][] = 
'FavoritesHooks::onSkinTemplateNavigation';  // For Vector
+$wgHooks['SkinTemplateTabs'][] = 'FavoritesHooks::onSkinTemplateTabs';  // For 
other skins
 
-if ($wgUseIconFavorite){
-       //add CSS - only needed for icon display
-       $wgHooks['BeforePageDisplay'][] = 'fnAddCss';
-}
+//add CSS - only needed for icon display
+$wgHooks['BeforePageDisplay'][] = 'FavoritesHooks::onBeforePageDisplay';
 
 //add or remove
-$wgHooks['UnknownAction'][] = 'fnAction';
+$wgHooks['UnknownAction'][] = 'FavoritesHooks::onUnknownAction';
 
 //handle page moves and deletes
-$wgHooks['TitleMoveComplete'][] = 'fnHookMoveToFav';
-$wgHooks['ArticleDeleteComplete'][] = 'fnHookDeleteFav';
+$wgHooks['TitleMoveComplete'][] = 'FavoritesHooks::onTitleMoveComplete';
+$wgHooks['ArticleDeleteComplete'][] = 
'FavoritesHooks::onArticleDeleteComplete';
 
-// Do we want to display a "My Favorites" link in the personal urls area?
-if ($wgFavoritesPersonalURL) {
-       $wgHooks['PersonalUrls'][] = 'onAddPersonalUrls';
-} 
+// Display a "My Favorites" link in the personal urls area
+$wgHooks['PersonalUrls'][] = 'FavoritesHooks::onPersonalUrls';
 
-function onAddPersonalUrls( &$personal_urls, &$wgTitle ) {
-      global $wgUser;
- 
- //     $skin = $wgUser->getSkin();
-               $title = Title::newFromText( 'Special:Favoritelist' );
-      if( $wgUser->getID() ) {
-        $url['userpage'] = array_shift( $personal_urls );
-        $url[] = array_shift( $personal_urls );
-        $url[] = array_shift( $personal_urls );
-        
-         $url[] = array( 'text' => wfMsg( 'myfavoritelist' ),
-                         'href' => $title->getLocalURL( )
-                               );
-            
-       
-         $personal_urls = $url + $personal_urls;
-      }
- 
-      return true;
-}
-
-function fnAction ($action, $article) {
-       $title = new Title();
-       $favArticle = new FavArticle($title); 
-       
-       if ($action == 'unfavorite') {
-               $favArticle->unfavorite($action, $article);
-               
-       } elseif ($action == 'favorite') {
-               $favArticle->favorite($action, $article);
-       } else {
-               return true;
-       }
-       return false;
-}
-
-function fnNavUrls($sktemplate, &$links) {
-       $fNav = new Favorites();
-       $fNav->favoritesIcon($sktemplate, $links);
-       return true;
-}
-
-function fnNavTabs( $skin, &$content_actions ){
-       $fNav = new Favorites();
-       $fNav->favoritesTabs($skin, $content_actions);
-       return true;
-}
-
-
-function fnHookMoveToFav(&$title, &$nt, &$wgUser, $pageid, $redirid ) {
-       $favTitle = new FavTitle();
-       $favTitle->moveToFav($title, $nt, $wgUser, $pageid, $redirid );
-       return true;
-}
-
-function fnHookDeleteFav(&$article, &$user, $reason, $id ){
-       $dbw = wfGetDB( DB_MASTER );
-       $dbw->delete('favoritelist', array(
-               'fl_title' => $article->mTitle->getDBKey()), 
-               $fname = 'Database::delete');
-       return true;
-}
-
-function fnAddCss (&$out) {
-       global $wgExtensionAssetsPath;
-       $out->addStyle($wgExtensionAssetsPath . '/Favorites/favorites.css');
-       return true;
-}
-
-function ParseFavorites(Parser &$parser) {
-       
-       $parser->setHook( 'favorites', 'favParser_Render' );
-       
-       return true;
-}
-
- 
-$markerList = array();
-function favParser_Render ( $input, $argv, $parser) {
-        # The parser function itself
-        # The input parameters are wikitext with templates expanded
-        # The output should be wikitext too
-        //$output = "Parser Output goes here.";
-        
-        $favParse = new FavParser();
-        $output = $favParse->wfSpecialFavoritelist($argv, $parser);
-               $parser->disableCache();
-        return $output;
-        
-}
-
-
-# Schema updates for update.php
-function FavSQLUpdate( $updater = null ) {
-        if ( $updater === null ) {
-                // <= 1.16 support
-                global $wgExtNewTables, $wgExtModifiedFields;
-                $wgExtNewTables[] = array(
-                        'favoritelist',
-                        dirname( __FILE__ ) . '/favorites.sql'
-                );
-
-        } else {
-                // >= 1.17 support
-                $updater->addExtensionUpdate( array( 'addTable', 
'favoritelist',
-                        dirname( __FILE__ ) . '/favorites.sql', true ) );
-
-        }
-        return true;
-}
\ No newline at end of file
+$wgFavoritesPersonalURL = true;
+$wgUseIconFavorite = true;

Copied: trunk/extensions/Favorites/FavoritesHooks.php (from rev 95687, 
trunk/extensions/Favorites/FavArticle.php)
===================================================================
--- trunk/extensions/Favorites/FavoritesHooks.php                               
(rev 0)
+++ trunk/extensions/Favorites/FavoritesHooks.php       2011-08-30 13:57:33 UTC 
(rev 95780)
@@ -0,0 +1,199 @@
+<?php
+
+class FavoritesHooks {
+
+       public static function onLoadExtensionSchemaUpdates( $updater = null ) {
+               if ( $updater === null ) { // <= 1.16 support
+                       global $wgExtNewTables, $wgExtModifiedFields;
+                       $wgExtNewTables[] = array(
+                               'favoritelist',
+                               dirname( __FILE__ ) . '/favorites.sql'
+                       );
+               } else { // >= 1.17 support
+                       $updater->addExtensionUpdate( array( 'addTable', 
'favoritelist',
+                               dirname( __FILE__ ) . '/favorites.sql', true ) 
);
+               }
+               return true;
+       }
+
+       public static function onUnknownAction( $action, $article ) {
+               global $wgUser, $wgOut;
+
+               if ( $action !== 'unfavorite' && $action !== 'favorite' ) {
+                       return true;
+               }
+
+               if ( $wgUser->isAnon() ) {
+                       $wgOut->showErrorPage( 'favoritenologin', 
'favoritenologintext' );
+                       return;
+               }
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+
+               if ( $action === 'favorite' ) {
+                       if ( self::doFavorite( $article ) ) {
+                               $wgOut->setPagetitle( wfMsg( 'addedfavorite' ) 
);
+                               $wgOut->addWikiMsg( 'addedfavoritetext', 
$article->getTitle()->getPrefixedText() );
+                       }
+               } else {
+                       if ( self::doUnfavorite( $article ) ) {
+                               $wgOut->setPagetitle( wfMsg( 'removedfavorite' 
) );
+                               $wgOut->addWikiMsg( 'removedfavoritetext', 
$article->getTitle()->getPrefixedText() );
+                       }
+               }
+
+               $wgOut->returnToMain( true, 
$article->getTitle()->getPrefixedText() );
+
+               return false;
+       }
+
+       /**
+        * Add this page to $wgUser's favoritelist
+        * @return bool true on successful favorite operation
+        */
+       private static function doFavorite( $article ) {
+               global $wgUser;
+
+               if ( $wgUser->isAnon() ) {
+                       return false;
+               }
+               if ( wfRunHooks( 'FavoriteArticle', array( &$wgUser, &$article 
) ) ) {
+                       $fl = FavoritedItem::fromUserTitle( $wgUser, 
$article->getTitle() );
+                       $fl->addFavorite();
+                       $article->getTitle()->invalidateCache();
+                       return wfRunHooks( 'FavoriteArticleComplete', array( 
&$wgUser, &$article ) );
+               }
+
+       }
+
+       /**
+        * Stop favoriting a page
+        * @return bool true on successful unfavorite
+        */
+       private static function doUnfavorite( $article ) {
+               global $wgUser;
+
+               if ( $wgUser->isAnon() ) {
+                       return false;
+               }
+               if ( wfRunHooks( 'UnfavoriteArticle', array( &$wgUser, 
&$article ) ) ) {
+                       $fl = FavoritedItem::fromUserTitle( $wgUser, 
$article->getTitle() );
+                       $fl->removeFavorite();
+                       $article->getTitle()->invalidateCache();
+                       return wfRunHooks( 'UnfavoriteArticleComplete', array( 
&$wgUser, &$article ) );
+               }
+               return false;
+       }
+
+       public static function onPersonalUrls( &$personal_urls, &$wgTitle ) {
+               global $wgFavoritesPersonalURL, $wgUser;
+
+               if ( $wgFavoritesPersonalURL && $wgUser->isLoggedIn() ) {
+                       $url['userpage'] = array_shift( $personal_urls );
+                       $url[] = array_shift( $personal_urls );
+                       $url[] = array_shift( $personal_urls );
+
+                       $url[] = array( 'text' => wfMsg( 'myfavoritelist' ),
+                               'href' => SpecialPage::getTitleFor( 
'Favoritelist' )->getLocalURL() );
+                       $personal_urls = $url + $personal_urls;
+               }
+
+               return true;
+       }
+
+       public static function onParserFirstCallInit( &$parser ) {
+               $parser->setHook( 'favorites', array( __CLASS__, 
'renderFavorites' ) );
+               return true;
+       }
+
+       function renderFavorites( $input, $argv, $parser ) {
+               # The parser function itself
+               # The input parameters are wikitext with templates expanded
+               # The output should be wikitext too
+               //$output = "Parser Output goes here.";
+
+               $favParse = new FavParser();
+               $output = $favParse->wfSpecialFavoritelist( $argv, $parser );
+               $parser->disableCache();
+               return $output;
+       }
+
+       public static function onSkinTemplateNavigation( $skin, &$links ) {
+               global $wgUseIconFavorite, $wgRequest, $wgUser;
+
+               $action = $wgRequest->getText( 'action' );
+               $title =  $skin->getTitle();
+       
+               if ( $title->getNamespace() >= NS_MAIN ) {
+                       if ( $wgUseIconFavorite ) {
+                                       $class = 'icon ';
+                                       $place = 'views';
+                               } else {
+                                       $class = '';
+                                       $place = 'actions';
+                               }
+
+                               $fl = FavoritedItem::fromUserTitle( $wgUser, 
$title );
+
+                               $mode = $fl->isFavorited() ? 'unfavorite' : 
'favorite';
+                               $links[$place][$mode] = array(
+                                       'class' => $class . ( ( $action == 
'favorite' || $action == 'unfavorite' ) ? ' selected' : false ),
+                                       'text' => wfMsg( $mode ), // uses 
'favorite' or 'unfavorite' message
+                                       'href' => $title->getLocalUrl( 
'action=' . $mode )
+                               );
+               }
+               return true;
+       }
+
+       public static function onSkinTemplateTabs( $skin, &$content_actions ) {
+               global $wgUseIconFavorite, $wgUser, $wgRequest;
+       
+               $action = $wgRequest->getText( 'action' );
+               $title = $skin->getTitle();
+               if ( $title->getNamespace() >= NS_MAIN ) {
+                       $fl = FavoritedItem::fromUserTitle( $wgUser, $title );
+                       $mode = $fl->isFavorited() ? 'unfavorite' : 'favorite';
+                       $content_actions[$mode] = array (
+                               'class' => (( $action == 'favorite' || $action 
== 'unfavorite' ) ? ' selected' : false ),
+                               'text' => wfMsg( $mode ), // uses 'favorite' or 
'unfavorite' message
+                               'href' => $title->getLocalUrl( 'action=' . 
$mode )
+                       );
+               }
+               return true;
+       }
+
+       public static function onTitleMoveComplete( &$title, &$nt, &$user, 
$pageid, $redirid ) {
+               # Update watchlists
+               $oldnamespace = $title->getNamespace() & ~1;
+               $newnamespace = $nt->getNamespace() & ~1;
+               $oldtitle = $title->getDBkey();
+               $newtitle = $nt->getDBkey();
+
+               if ( $oldnamespace != $newnamespace || $oldtitle != $newtitle ) 
{
+                       FavoritedItem::duplicateEntries( $title, $nt );
+               }
+               return true;
+       }
+
+       public static function onArticleDeleteComplete(&$article, &$user, 
$reason, $id ){
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->delete( 'favoritelist', array(
+                       'fl_title' => $article->mTitle->getDBKey() ),
+                       __METHOD__ );
+               return true;
+       }
+
+       public static function onBeforePageDisplay( $out ) {
+               global $wgUseIconFavorite, $wgExtensionAssetsPath;
+
+               if ( $wgUseIconFavorite ) {
+                       $out->addStyle( $wgExtensionAssetsPath . 
'/Favorites/favorites.css' );
+               }
+
+               return true;
+       }
+}

Deleted: trunk/extensions/Favorites/Favorites_body.php
===================================================================
--- trunk/extensions/Favorites/Favorites_body.php       2011-08-30 13:45:03 UTC 
(rev 95779)
+++ trunk/extensions/Favorites/Favorites_body.php       2011-08-30 13:57:33 UTC 
(rev 95780)
@@ -1,64 +0,0 @@
-<?php
-
-class Favorites extends QuickTemplate {
- 
-       var $mTitle;
-       
-       function execute() {
-
-       }
-       
- function favoritesIcon( &$sktemplate, &$links ) {
-       
-       global $wgUseIconFavorite, $wgRequest, $wgArticle;
-                       
-       //$sktemplate->skin = $sktemplate->data['skin'];
-       $action = $wgRequest->getText( 'action' );
-       
-       // See if this object even exists - if the user can't read it, the 
object doesn't get created.
-       if ($wgArticle) {  
-                       
-                       if ( $wgUseIconFavorite ) {
-                                       $class = 'icon ';
-                                       $place = 'views';
-                               } else {
-                                       $class = '';
-                                       $place = 'actions';
-                               }
-                               $favTitle = new FavTitle();
-                               
-                               //$mode = $this->mTitle->userIsFavoriting() ? 
'unfavorite' : 'favorite';
-                               $mode = $favTitle->userIsFavoriting() ? 
'unfavorite' : 'favorite';
-                               $links[$place][$mode] = array(
-                                       'class' => $class . ( ( $action == 
'favorite' || $action == 'unfavorite' ) ? ' selected' : false ),
-                                       'text' => wfMsg( $mode ), // uses 
'favorite' or 'unfavorite' message
-                                       'href' => 
$wgArticle->mTitle->getLocalUrl( 'action=' . $mode )
-                               );
-                               
-       
-                       return false;
-       }
-       
-}
-
-function favoritesTabs($skin, &$content_actions) {
-       global $wgUseIconFavorite, $wgRequest, $wgArticle;
-       
-       $action = $wgRequest->getText( 'action' );
-       $favTitle = new FavTitle();
-       $mode = $favTitle->userIsFavoriting() ? 'unfavorite' : 'favorite';
-       // See if this object even exists - if the user can't read it, the 
object doesn't get created.
-       if ($wgArticle) {
-                $content_actions[$mode] = array (
-                       'class' => (( $action == 'favorite' || $action == 
'unfavorite' ) ? ' selected' : false ),
-                       'text' => wfMsg( $mode ), // uses 'favorite' or 
'unfavorite' message
-                       'href' => $wgArticle->mTitle->getLocalUrl( 'action=' . 
$mode )
-               );
-       return true;
-       }
-
- 
-}
-
-}
-

Modified: trunk/extensions/Favorites/SpecialFavoritelist.php
===================================================================
--- trunk/extensions/Favorites/SpecialFavoritelist.php  2011-08-30 13:45:03 UTC 
(rev 95779)
+++ trunk/extensions/Favorites/SpecialFavoritelist.php  2011-08-30 13:57:33 UTC 
(rev 95780)
@@ -343,7 +343,7 @@
                        $self = SpecialPage::getTitleFor( 'Favoritelist' );
                        $form  = Xml::openElement( 'form', array( 'method' => 
'post',
                                'action' => $self->getLocalUrl( array( 'action' 
=> 'edit' ) ) ) );
-                       $form .= Xml::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
+                       $form .= Html::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
                        //$form .= "<fieldset>\n<legend>" . wfMsgHtml( 
'favoritelistedit-normal-legend' ) . "</legend>";
                        //$form .= wfMsgExt( 'favoritelistedit-normal-explain', 
'parse' );
                        $form .= $this->buildRemoveList( $user, 
$wgUser->getSkin() );
@@ -459,7 +459,7 @@
                $self = SpecialPage::getTitleFor( 'Favoritelist' );
                $form  = Xml::openElement( 'form', array( 'method' => 'post',
                        'action' => $self->getLocalUrl( array( 'action' => 
'raw' ) ) ) );
-               $form .= Xml::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
+               $form .= Html::hidden( 'token', $wgUser->editToken( 
'favoritelistedit' ) );
                $form .= '<fieldset><legend>' . wfMsgHtml( 
'favoritelistedit-raw-legend' ) . '</legend>';
                $form .= wfMsgExt( 'favoritelistedit-raw-explain', 'parse' );
                $form .= Xml::label( wfMsg( 'favoritelistedit-raw-titles' ), 
'titles' );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to