Added hook events for article protection. Added sample code to Syslog
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 00:20:37 +0000 (00:20 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 00:20:37 +0000 (00:20 +0000)
extensions, and documented in hooks.doc.

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

index 26e3fa4..27f4cb7 100644 (file)
@@ -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)
index ffd3127..78bc912 100644 (file)
@@ -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;
        }
index 5437d46..1979b29 100644 (file)
@@ -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' ) );