PageProtection/Patch for PageProtection1.4 and MediaWiki1.7.1

 
A proposal to move this page to MediaWiki.org was rejected.


diff -u PageProtection-1.4\AccessList.php PageProtection-1.4-for-1.7.1\AccessList.php
--- PageProtection-1.4\AccessList.php	Fri Sep 01 11:31:31 2006
+++ PageProtection-1.4-for-1.7.1\AccessList.php	Sat Aug 05 18:06:58 2006
@@ -135,7 +135,7 @@
     {
         foreach($users as $user)
         {
-            $this->AddUSer($user);
+            $this->AddUser($user);
         }
     }
     
diff -u PageProtection-1.4\ErrorHandler.php PageProtection-1.4-for-1.7.1\ErrorHandler.php
--- PageProtection-1.4\ErrorHandler.php	Fri Sep 01 11:31:31 2006
+++ PageProtection-1.4-for-1.7.1\ErrorHandler.php	Fri Sep 01 11:52:24 2006
@@ -8,6 +8,7 @@
     var $mShow;
     var $mPage;
     var $mAccess;
+    var $mParser1;
 
     /**
     * Constructor.
@@ -16,11 +17,12 @@
     *                (warning, page, none, text, crypt)
     * @param page Optional name of page to display if show="page"
     */
-    function ErrorHandler($access, $show = "warning", $page = "")
+    function ErrorHandler($access, $parser, $show = "warning", $page = "")
     {
         $this->mShow = $show;
         $this->mPage = $page;
         $this->mAccess = $access;
+        $this->mParser1 = $parser;
     }
     
     /**
@@ -67,7 +69,7 @@
         $msg = str_replace(VAR_GROUPS, $this->mAccess->getGroupList(), $msg);
     
         if ($parseWiki) {
-            return $wgOut->parse($msg);
+            return ($this->mParser1->parseTag($msg));
         } else {
             return $msg;
         }
@@ -79,7 +81,7 @@
     */
     function getErrorPage() {
         $tit = Title::newFromText($this->mPage);
-        $art = new Article(&$tit);
+        $art = new Article($tit);
         return $this->formatMessage($art->getContent());
     }
     
diff -u PageProtection-1.4\PageProtection.php PageProtection-1.4-for-1.7.1\PageProtection.php
--- PageProtection-1.4\PageProtection.php	Fri Sep 01 11:36:32 2006
+++ PageProtection-1.4-for-1.7.1\PageProtection.php	Fri Sep 01 11:53:40 2006
@@ -61,12 +61,14 @@
     global $wgUser;
     global $wgOut;
     
-    $protect = new ProtectPage();
+    $protect = new ProtectPage($parser);
     $protect->initShow($params["users"], $params["groups"], $params["show"]);
     
-    if ($protect->hasAccess(&$wgUser)) {
+    if ($protect->hasAccess($wgUser)) {
         global $wgRequest;
-        return $wgOut->parse($protect->mEnc->decrypt($text));
+        $text = $protect->mEnc->decrypt($text);
+        $text = $protect->parseTag($text);
+        return ($text);
     }
     
     $show = $params["show"];
@@ -76,7 +78,8 @@
     }
     
     
-    $err = new ErrorHandler($protect->mAccess, 
+    $err = new ErrorHandler($protect->mAccess,
+                                $parser, 
                                 $show,
                                 $page);
     return $err->showError($text);
@@ -89,8 +92,8 @@
 */
 function protectSave(&$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor) {
 //    die($text);
-    $protect = new ProtectPage();
-    $protect->mParser = new ProtectionParser($text,&$protect->mEnc);
+    $protect = new ProtectPage($parser);
+    $protect->mParser = new ProtectionParser($text, $protect->mEnc);
     $protect->mParser->parseText();
     $protect->encryptTags($text, $user->getName());
     
@@ -107,18 +110,18 @@
 function protectedEdit($editpage) {
     global $wgUser;
     
-    $protect = new ProtectPage();
+    $protect = new ProtectPage($parser);
     $protect->initEdit($editpage);
    
     if (!$protect->mParser->isProtected() ) {
         return $editpage;
     }
     
-    if ($protect->mAccess->hasAccess(&$wgUser) ) {
+    if ($protect->mAccess->hasAccess($wgUser) ) {
         $editpage->mArticle->mContent =  $protect->decryptPage();
         return true;
     } else {    
-        $err = new ErrorHandler($protect->mAccess);
+        $err = new ErrorHandler($protect->mAccess, null);
         return $err->stopEditing();
     }
     
diff -u PageProtection-1.4\ProtectionParser.php PageProtection-1.4-for-1.7.1\ProtectionParser.php
--- PageProtection-1.4\ProtectionParser.php	Fri Sep 01 11:42:38 2006
+++ PageProtection-1.4-for-1.7.1\ProtectionParser.php	Sun Aug 06 10:52:42 2006
@@ -8,7 +8,6 @@
 class ProtectionParser
 {
     var $mContent = array();
-    var $mTags = array();
     var $mParams = array();
     var $mParsedText;
     var $mText;
@@ -59,25 +58,24 @@
 
     /**
     * Parses a text for protect-tags and stores the texts in member-fields.
-    * The resulting array are mContent, mTags, mParams and mSections.
+    * The resulting array are mContent, mParams and mSections.
     */
     function parseText() {
         $this->mContent = array();
-        $this->mTags = array();
         $this->mParams = array();
-
-        $this->mParsedText = Parser::extractTagsAndParams(PROTECT_TAG, 
-            $this->mText,
-            &$this->mContent, 
-            &$this->mTags,
-            &$this->mParams );
-
+       
+        $this->mElements = array (PROTECT_TAG);
+       $this->mParsedText = Parser::extractTagsAndParams(
+               $this->mElements,
+               $this->mText,
+               $this->mContent );
+        
         // decrypt all tags that are stored encrypted
         foreach($this->mContent as $key => $content)
         {
-            $dec = $this->mEnc->decrypt($content);
+            $dec = $this->mEnc->decrypt($content[1]);
             if ($dec != "") {
-                $this->mContent[$key] = $dec;
+                $this->mContent[$key][1] = $dec;
             }
         }
     }
@@ -91,9 +89,9 @@
     function getAccessList()
     {
         $list = new AccessList();
-        foreach ($this->mParams as $param) {
-            $list->RestrictUsers($param["users"]);
-            $list->RestrictGroups($param["groups"]);
+        foreach ($this->mContent as $param) {
+            $list->RestrictUsers($param[2]["users"]);
+            $list->RestrictGroups($param[2]["groups"]);
         }
         return $list;
     }
@@ -106,9 +104,13 @@
     function getDecrypted() {
         $text = $this->mParsedText;
         foreach ($this->mContent as $rand => $cnt) {
+            $mTags = $cnt[0];
+           foreach ($cnt[2] as $tag => $value) {
+                $mTags .= " $tag=\"$value\"";
+            }
             $text = str_replace($rand,
-                $this->mTags[$rand]
-                    .$this->mEnc->decrypt($cnt)
+                "<" . $mTags . ">"
+                    .$this->mEnc->decrypt($cnt[1])
                     ."</protect>",
                 $text);
         }
@@ -120,7 +122,7 @@
     * @return true if Page is protected.
     */
     function isProtected() {
-        if (count($this->mTags) != 0) {
+        if (count($this->mContent) != 0) {
             return true;
         }
         return false;
@@ -136,18 +138,18 @@
         require_once("ProtectTag.php");
         $text = $this->mParsedText;
         foreach ($this->mContent as $rand => $cnt) {
-            $access = new AccessList(   $this->mParams[$rand]["users"],
-                                        $this->mParams[$rand]["groups"]);
+            $access = new AccessList($cnt[2]["users"],
+                                     $cnt[2]["groups"]);
             $access->AddUser($userName);
             
             $tag = new ProtectTag();
             $tag->setAccessList($access);
-            $tag->setShow($this->mParams[$rand]["show"]);
-            $tag->setErrorPage($this->mParams[$rand]["errorpage"]);
+            $tag->setShow($cnt[2]["show"]);
+            $tag->setErrorPage($cnt[2]["errorpage"]);
             
             $text = str_replace($rand,
                 $tag->getStart()."\n"
-                    .$this->mEnc->encrypt($cnt)."\n"
+                    .$this->mEnc->encrypt($cnt[1])."\n"
                     .$tag->getEnd(),
                 $text);
         }
diff -u PageProtection-1.4\ProtectPage.php PageProtection-1.4-for-1.7.1\ProtectPage.php
--- PageProtection-1.4\ProtectPage.php	Fri Sep 01 11:45:04 2006
+++ PageProtection-1.4-for-1.7.1\ProtectPage.php	Fri Aug 25 10:25:44 2006
@@ -15,13 +15,15 @@
     var $mEnc = null;
     var $mAccess = null;
     var $mParser = null;
+    var $mParser1 = null;
     var $mShow = "";
     
     /**
     * Constructor.
     */
-    function ProtectPage() {
+    function ProtectPage(&$parser) {
         $this->mEnc = new Encryption();
+        $this->mParser1 = $parser;
     }
 
     /**
@@ -55,7 +57,7 @@
     *                   (usually current username)
     */
     function encryptTags(&$text, $userName) {
-        $this->mParser = new ProtectionParser($text, &$this->mEnc);
+        $this->mParser = new ProtectionParser($text, $this->mEnc);
         $this->mParser->parseText();
         $text = $this->mParser->getEncrypted($userName);
     }
@@ -66,7 +68,7 @@
     * @editpage EditPage object
     */
     function initEdit($editpage) {
-        $this->mParser = new ProtectionParser($editpage, &$this->mEnc);
+        $this->mParser = new ProtectionParser($editpage, $this->mEnc);
         $this->mParser->parseText();
         $this->mAccess = $this->mParser->getAccessList();
     }
@@ -77,6 +79,20 @@
     */
     function decryptPage() {
         return $this->mParser->getDecrypted();
+    }
+    /*
+     * From Cipe.php
+     */
+    function parseTag ($text) {
+        $text = $this->mParser1->parse( $text,
+                                        $this->mParser1->mTitle,
+                                        $this->mParser1->mOptions,
+                                        false, false );
+        $text = $text->getText();
+        $text = preg_replace ('~^<p>\s*~', '', $text );
+        $text = preg_replace ('~\s*</p>\s*~', '', $text );
+        $text = preg_replace ('~\n$~', '', $text );
+        return ($text);
     }
 }