From: Evan Prodromou Date: Sun, 28 Nov 2004 00:20:37 +0000 (+0000) Subject: Added hook events for article protection. Added sample code to Syslog X-Git-Tag: 1.5.0alpha1~1213 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=4c23bcc198986ec7d5412e38c3ace5ea4503595f;p=lhc%2Fweb%2Fwiklou.git Added hook events for article protection. Added sample code to Syslog extensions, and documented in hooks.doc. --- diff --git a/docs/hooks.doc b/docs/hooks.doc index 26e3fa4590..27f4cb7c53 100644 --- a/docs/hooks.doc +++ b/docs/hooks.doc @@ -226,6 +226,20 @@ 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. +'ArticleProtect': before an article is protected +$article: the article being protected +$user: the user doing the protection +$protect: boolean whether this is a protect or an unprotect +$reason: Reason for protect +$moveonly: boolean whether this is for move only or not + +'ArticleProtectComplete': after an article is protected +$article: the article that was protected +$user: the user who did the protection +$protect: boolean whether it was a protect or an unprotect +$reason: Reason for protect +$moveonly: boolean whether it was for move only or not + '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 ffd3127535..78bc9124df 100644 --- a/extensions/Syslog.php +++ b/extensions/Syslog.php @@ -47,11 +47,20 @@ if (defined('MEDIAWIKI')) { } function syslogBlockIp(&$block, &$user) { - syslog(LOG_INFO, "User '" . $user->getName() . + syslog(LOG_NOTICE, "User '" . $user->getName() . "' blocked '" . (($block->mUser) ? $block->mUser : $block->mAddress) . "' for '" . $block->mReason . "' until '" . $block->mExpiry . "'"); return true; } + + function syslogArticleProtect(&$article, &$user, $protect, &$reason, &$moveonly) { + $title = $article->mTitle; + syslog(LOG_NOTICE, "User '" . $user->getName() . "' " . + (($protect) ? "protected" : "unprotected") . " article '" . + $title->getPrefixedText() . + "' for '" . $reason . "' " . (($moveonly) ? "(moves only)" : "") ); + return true; + } # Setup -- called once environment is configured @@ -65,6 +74,7 @@ if (defined('MEDIAWIKI')) { $wgHooks['UserLoginComplete'][] = syslogUserLogin; $wgHooks['UserLogout'][] = syslogUserLogout; $wgHooks['BlockIpComplete'][] = syslogBlockIp; + $wgHooks['ArticleProtectComplete'][] = syslogArticleProtect; return true; } diff --git a/includes/Article.php b/includes/Article.php index 5437d46e30..1979b294ed 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1281,28 +1281,33 @@ class Article { $reason = $wgRequest->getText( 'wpReasonProtect' ); if ( $confirm ) { + $restrictions = "move=" . $limit; if( !$moveonly ) { $restrictions .= ":edit=" . $limit; } - - $dbw =& wfGetDB( DB_MASTER ); - $dbw->update( 'cur', - array( /* SET */ - 'cur_touched' => $dbw->timestamp(), - 'cur_restrictions' => $restrictions - ), array( /* WHERE */ - 'cur_id' => $id - ), 'Article::protect' - ); - - $log = new LogPage( 'protect' ); - if ( $limit === '' ) { + if (wfRunHooks('ArticleProtect', $this, $wgUser, $limit == 'sysop', $reason, $moveonly)) { + + $dbw =& wfGetDB( DB_MASTER ); + $dbw->update( 'cur', + array( /* SET */ + 'cur_touched' => $dbw->timestamp(), + 'cur_restrictions' => $restrictions + ), array( /* WHERE */ + 'cur_id' => $id + ), 'Article::protect' + ); + + wfRunHooks('ArticleProtectComplete', $this, $wgUser, $limit == 'sysop', $reason, $moveonly); + + $log = new LogPage( 'protect' ); + if ( $limit === '' ) { $log->addEntry( 'unprotect', $this->mTitle, $reason ); - } else { + } else { $log->addEntry( 'protect', $this->mTitle, $reason ); + } + $wgOut->redirect( $this->mTitle->getFullURL() ); } - $wgOut->redirect( $this->mTitle->getFullURL() ); return; } else { $reason = htmlspecialchars( wfMsg( 'protectreason' ) );