Added hooks for watching and unwatching articles. Documented in
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Tue, 30 Nov 2004 05:45:56 +0000 (05:45 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Tue, 30 Nov 2004 05:45:56 +0000 (05:45 +0000)
hooks.doc, and an example in Syslog extension.

docs/hooks.doc
extensions/Syslog.php
includes/Article.php

index 2032aac..6f5120e 100644 (file)
@@ -293,6 +293,14 @@ $text: text of the mail
 $action: action name
 $article: article "acted on"
 
+'UnwatchArticle': before a watch is removed from an article
+$user: user watching
+$article: article object to be removed
+
+'UnwatchArticle': after a watch is removed from an article
+$user: user that was watching
+$article: article object removed
+
 'UserLoginComplete': after a user has logged in
 $user: the user object that was created on login
                    
@@ -302,3 +310,11 @@ $user: the user object that is about to be logged out
 'UserLogoutComplete': after a user has logged out
 $user: the user object _after_ logout (won't have name, ID, etc.)
                      
+'WatchArticle': before a watch is added to an article
+$user: user that will watch
+$article: article object to be watched
+
+'WatchArticleComplete': after a watch is added to an article
+$user: user that watched
+$article: article object watched
+
index 3f69bf9..d499bb9 100644 (file)
@@ -32,29 +32,6 @@ if (defined('MEDIAWIKI')) {
                $wgSyslogFacility = LOG_USER;
        }
 
-       # Hook for login
-       
-       function syslogUserLogin(&$user) {
-               syslog(LOG_INFO, "User '" . $user->getName() . "' logged in.");
-               return true;
-       }
-
-       # Hook for logout
-       
-       function syslogUserLogout(&$user) {
-               syslog(LOG_INFO, "User '" . $user->getName() . "' logged out.");
-               return true;
-       }
-
-       # Hook for IP & user blocks
-       
-       function syslogBlockIp(&$block, &$user) {
-               syslog(LOG_NOTICE, "User '" . $user->getName() . 
-                          "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) .
-                          "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'");
-               return true;
-       }
-
        # Hook for article protection
        
        function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) {
@@ -88,10 +65,47 @@ if (defined('MEDIAWIKI')) {
                return true;
        }
 
+       # Hook for IP & user blocks
+       
+       function syslogBlockIp(&$block, &$user) {
+               syslog(LOG_NOTICE, "User '" . $user->getName() . 
+                          "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) .
+                          "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'");
+               return true;
+       }
+
        function syslogEmailUser(&$to, &$from, &$subject, &$text) {
                syslog(LOG_INFO, "Email sent from '$from' to '$to' with subject '$subject'");
        }
+
+       # Hook for unwatch
+       
+       function syslogUnwatch(&$user, &$article) {
+               syslog(LOG_INFO, "User '" . $user->getName() . "' stopped watching '" .
+                          $article->mTitle->getPrefixedText() . "'");
+       }
+       
+       # Hook for login
+
+       function syslogUserLogin(&$user) {
+               syslog(LOG_INFO, "User '" . $user->getName() . "' logged in");
+               return true;
+       }
+
+       # Hook for logout
+       
+       function syslogUserLogout(&$user) {
+               syslog(LOG_INFO, "User '" . $user->getName() . "' logged out");
+               return true;
+       }
+
+       # Hook for watch
        
+       function syslogWatch(&$user, &$article) {
+               syslog(LOG_INFO, "User '" . $user->getName() . "' started watching '" .
+                          $article->mTitle->getPrefixedText() . "'");
+       }
+
        # Setup -- called once environment is configured
        
        function setupSyslog() {
@@ -108,6 +122,8 @@ if (defined('MEDIAWIKI')) {
                $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
                $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
                $wgHooks['EmailUserComplete'][] = 'syslogEmailUser';
+               $wgHooks['WatchArticleComplete'][] = 'syslogWatch';
+               $wgHooks['UnwatchArticleComplete'][] = 'syslogUnwatch';
                
                return true;
        }
index 2a4f5e0..0ad959c 100644 (file)
@@ -1210,9 +1210,11 @@ class Article {
 
 
        /**
-        * Add or remove this page to my watchlist based on value of $add
+        * Add this page to $wgUser's watchlist
         */
-       function watch( $add = true ) {
+       
+       function watch() {
+               
                global $wgUser, $wgOut;
 
                if ( 0 == $wgUser->getID() ) {
@@ -1223,33 +1225,58 @@ class Article {
                        $wgOut->readOnlyPage();
                        return;
                }
-               if( $add )
-                       $wgUser->addWatch( $this->mTitle );
-               else
-                       $wgUser->removeWatch( $this->mTitle );
 
-               $wgOut->setPagetitle( wfMsg( $add ? 'addedwatch' : 'removedwatch' ) );
-               $wgOut->setRobotpolicy( 'noindex,follow' );
-
-               $sk = $wgUser->getSkin() ;
-               $link = $this->mTitle->getPrefixedText();
+               if (wfRunHooks('WatchArticle', $wgUser, $this)) {
+                       
+                       $wgUser->addWatch( $this->mTitle );
+                       $wgUser->saveSettings();
 
-               if($add)
+                       wfRunHooks('WatchArticleComplete', $wgUser, $this);
+                       
+                       $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
+                       $wgOut->setRobotpolicy( 'noindex,follow' );
+                       
+                       $link = $this->mTitle->getPrefixedText();
                        $text = wfMsg( 'addedwatchtext', $link );
-               else
-                       $text = wfMsg( 'removedwatchtext', $link );
-               $wgOut->addWikiText( $text );
-
-               $wgUser->saveSettings();
+                       $wgOut->addWikiText( $text );
+               }
                
                $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
        }
 
        /**
-        * Stop watching a page, it act just like a call to watch(false)
+        * Stop watching a page
         */
+       
        function unwatch() {
-               $this->watch( false );
+
+               global $wgUser, $wgOut;
+
+               if ( 0 == $wgUser->getID() ) {
+                       $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
+                       return;
+               }
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+
+               if (wfRunHooks('UnwatchArticle', $wgUser, $this)) {
+                       
+                       $wgUser->removeWatch( $this->mTitle );
+                       $wgUser->saveSettings();
+                       
+                       wfRunHooks('UnwatchArticleComplete', $wgUser, $this);
+                       
+                       $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
+                       $wgOut->setRobotpolicy( 'noindex,follow' );
+                       
+                       $link = $this->mTitle->getPrefixedText();
+                       $text = wfMsg( 'removedwatchtext', $link );
+                       $wgOut->addWikiText( $text );
+               }
+               
+               $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
        }
 
        /**