hooks.doc, and an example in Syslog extension.
$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
'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
+
$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) {
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() {
$wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
$wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave';
$wgHooks['EmailUserComplete'][] = 'syslogEmailUser';
+ $wgHooks['WatchArticleComplete'][] = 'syslogWatch';
+ $wgHooks['UnwatchArticleComplete'][] = 'syslogUnwatch';
return true;
}
/**
- * 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() ) {
$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() );
}
/**