Add event hooks for article save. Documented in hooks.doc, and example
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 06:45:24 +0000 (06:45 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Sun, 28 Nov 2004 06:45:24 +0000 (06:45 +0000)
in Syslog extension.

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

index 277cd8d..d140e24 100644 (file)
@@ -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)
index acb1c05..5d64c9a 100644 (file)
@@ -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;
        }
index cf64b00..3ed2882 100644 (file)
@@ -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