From f2b7dcc7b1774c0fcdcd1bb008b972941dc6f67f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 28 Nov 2004 06:45:24 +0000 Subject: [PATCH] Add event hooks for article save. Documented in hooks.doc, and example in Syslog extension. --- docs/hooks.doc | 18 ++++++++++++++++++ extensions/Syslog.php | 16 ++++++++++++++++ includes/EditPage.php | 30 +++++++++++++++++++++++------- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/docs/hooks.doc b/docs/hooks.doc index 277cd8d50c..d140e24e3b 100644 --- a/docs/hooks.doc +++ b/docs/hooks.doc @@ -250,6 +250,24 @@ $protect: boolean whether it was a protect or an unprotect $reason: Reason for protect $moveonly: boolean whether it was for move only or not +'ArticleSave': before an article is saved +$article: the article (object) being saved +$user: the user (object) saving the article +$text: the new article text +$summary: the article summary (comment) +$isminor: minor flag +$iswatch: watch flag +$section: section # + +'ArticleSaveComplete': after an article is saved +$article: the article (object) saved +$user: the user (object) who saved the article +$text: the new article text +$summary: the article summary (comment) +$isminor: minor flag +$iswatch: watch flag +$section: section # + 'BlockIp': before an IP address or user is blocked $block: the Block object about to be saved $user: the user _doing_ the block (not the one being blocked) diff --git a/extensions/Syslog.php b/extensions/Syslog.php index acb1c05b90..5d64c9a423 100644 --- a/extensions/Syslog.php +++ b/extensions/Syslog.php @@ -46,6 +46,8 @@ 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) . @@ -53,6 +55,8 @@ if (defined('MEDIAWIKI')) { return true; } + # Hook for article protection + function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) { $title = $article->mTitle; syslog(LOG_NOTICE, "User '" . $user->getName() . "' " . @@ -62,6 +66,8 @@ if (defined('MEDIAWIKI')) { return true; } + # Hook for article deletion + function syslogArticleDelete(&$article, &$user, &$reason) { $title = $article->mTitle; syslog(LOG_NOTICE, "User '" . $user->getName() . "' deleted '" . @@ -69,7 +75,16 @@ if (defined('MEDIAWIKI')) { "' for '" . $reason . "' "); return true; } + + # Hook for article save + function syslogArticleSave(&$article, &$user, &$text, $summary, $isminor, $iswatch, $section) { + $title = $article->mTitle; + syslog(LOG_NOTICE, "User '" . $user->getName() . "' saved '" . + $title->getPrefixedText() . + "' with comment '" . $summary . "' "); + return true; + } # Setup -- called once environment is configured @@ -85,6 +100,7 @@ if (defined('MEDIAWIKI')) { $wgHooks['BlockIpComplete'][] = 'syslogBlockIp'; $wgHooks['ArticleProtectComplete'][] = 'syslogArticleProtect'; $wgHooks['ArticleDeleteComplete'][] = 'syslogArticleDelete'; + $wgHooks['ArticleSaveComplete'][] = 'syslogArticleSave'; return true; } diff --git a/includes/EditPage.php b/includes/EditPage.php index cf64b002f5..3ed2882625 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -179,7 +179,14 @@ class EditPage { $wgOut->redirect( $this->mTitle->getFullURL() ); return; } - $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, $this->minoredit, $this->watchthis ); + if (wfRunHooks('ArticleSave', $this->mArticle, $wgUser, $this->textbox1, + $this->summary, $this->minoredit, $this->watchthis, NULL)) + { + $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, + $this->minoredit, $this->watchthis ); + wfRunHooks('ArticleSaveComplete', $this->mArticle, $wgUser, $this->textbox1, + $this->summary, $this->minoredit, $this->watchthis, NULL); + } return; } @@ -238,12 +245,21 @@ class EditPage { $sectionanchor = $this->sectionAnchor( $matches[2] ); } } - - # update the article here - if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis, '', $sectionanchor )) - return; - else - $isConflict = true; + + if (wfRunHooks('ArticleSave', $this, $wgUser, $text, $this->summary, + $this->minoredit, $this->watchthis, $sectionanchor)) + { + # update the article here + if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, + $this->watchthis, '', $sectionanchor )) + { + wfRunHooks('ArticleSaveComplete', $this, $wgUser, $text, $this->summary, + $this->minoredit, $this->watchthis, $sectionanchor); + return; + } + else + $isConflict = true; + } } } # First time through: get contents, set time for conflict -- 2.20.1