From 031949ee659b5dce2aa1366c3a5364c24f37ee09 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Nov 2004 06:15:22 +0000 Subject: [PATCH] Add event hooking for article deletion. Add a hook for article deletion in the Syslog extension to test/demonstrate/whatever. Document the events in hooks.doc. --- docs/hooks.doc | 10 ++++++++++ extensions/Syslog.php | 10 ++++++++++ includes/Article.php | 36 ++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/docs/hooks.doc b/docs/hooks.doc index bd4740d2f2..277cd8d50c 100644 --- a/docs/hooks.doc +++ b/docs/hooks.doc @@ -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 diff --git a/extensions/Syslog.php b/extensions/Syslog.php index 52877396e8..acb1c05b90 100644 --- a/extensions/Syslog.php +++ b/extensions/Syslog.php @@ -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; } diff --git a/includes/Article.php b/includes/Article.php index 1979b294ed..b638ac5937 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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( '

' . $text . "

\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( '

' . $text . "

\n" ); + $wgOut->returnToMain( false ); + wfRunHooks('ArticleDeleteComplete', $this, $wgUser, $reason); + } else { + $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); + } } } -- 2.20.1