Add event hooking for article deletion. Add a hook for article
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 06:15:22 +0000 (06:15 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 06:15:22 +0000 (06:15 +0000)
deletion in the Syslog extension to test/demonstrate/whatever.
Document the events in hooks.doc.

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

index bd4740d..277cd8d 100644 (file)
@@ -226,6 +226,16 @@ hooks than for "complete" hooks.
 This is a list of known events and parameters; please add to it if
 you're going to add events to the MediaWiki code.
 
+'ArticleDelete': before an article is deleted
+$article: the article (object) being deleted
+$user: the user (object) deleting the article
+$reason: the reason (string) the article is being deleted
+
+'ArticleDeleteComplete': after an article is deleted
+$article: the article that was deleted
+$user: the user that deleted the article
+$reason: the reason the article was deleted
+
 'ArticleProtect': before an article is protected
 $article: the article being protected
 $user: the user doing the protection
index 5287739..acb1c05 100644 (file)
@@ -61,7 +61,16 @@ if (defined('MEDIAWIKI')) {
                           "' for '" . $reason . "' " . (($moveonly) ? "(moves only)" : "") );
                return true;
        }
+
+       function syslogArticleDelete(&$article, &$user, &$reason) {
+               $title = $article->mTitle;
+               syslog(LOG_NOTICE, "User '" . $user->getName() . "' deleted '" .
+                          $title->getPrefixedText() .
+                          "' for '" . $reason . "' ");
+               return true;
+       }
        
+
        # Setup -- called once environment is configured
        
        function setupSyslog() {
@@ -75,6 +84,7 @@ if (defined('MEDIAWIKI')) {
                $wgHooks['UserLogout'][] = 'syslogUserLogout';
                $wgHooks['BlockIpComplete'][] = 'syslogBlockIp';
                $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect';
+               $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete';
                
                return true;
        }
index 1979b29..b638ac5 100644 (file)
@@ -1573,22 +1573,26 @@ class Article {
                $fname = 'Article::doDelete';
                wfDebug( $fname."\n" );
 
-               if ( $this->doDeleteArticle( $reason ) ) {
-                       $deleted = $this->mTitle->getPrefixedText();
-
-                       $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
-
-                       $sk = $wgUser->getSkin();
-                       $loglink = $sk->makeKnownLink( $wgContLang->getNsText( NS_PROJECT ) .
-                         ':' . wfMsgForContent( 'dellogpage' ), wfMsg( 'deletionlog' ) );
-
-                       $text = wfMsg( 'deletedtext', $deleted, $loglink );
-
-                       $wgOut->addHTML( '<p>' . $text . "</p>\n" );
-                       $wgOut->returnToMain( false );
-               } else {
-                       $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+               if (wfRunHooks('ArticleDelete', $this, $wgUser, $reason)) {
+                       if ( $this->doDeleteArticle( $reason ) ) {
+                               $deleted = $this->mTitle->getPrefixedText();
+                               
+                               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
+                               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                               
+                               $sk = $wgUser->getSkin();
+                               $loglink = $sk->makeKnownLink( $wgContLang->getNsText( NS_PROJECT ) .
+                                                                                          ':' . wfMsgForContent( 'dellogpage' ),
+                                                                                          wfMsg( 'deletionlog' ) );
+                               
+                               $text = wfMsg( 'deletedtext', $deleted, $loglink );
+                               
+                               $wgOut->addHTML( '<p>' . $text . "</p>\n" );
+                               $wgOut->returnToMain( false );
+                               wfRunHooks('ArticleDeleteComplete', $this, $wgUser, $reason);
+                       } else {
+                               $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+                       }
                }
        }