PageProtection/Patch for PageProtection1.4 and MediaWiki1.6.8
Appearance
This page is kept for historical interest. Its content is outdated or may be wrong. You may find more up-to-date information at on the www.mediawiki.org website. |
diff -r -u PageProtection-1.4/AccessList.php PageProtection-1.4-for-1.6.8/AccessList.php --- PageProtection-1.4/AccessList.php 2006-07-21 09:30:12.000000000 +0200 +++ PageProtection-1.4-for-1.6.8/AccessList.php 2006-07-21 09:31:21.000000000 +0200 @@ -135,7 +135,7 @@ { foreach($users as $user) { - $this->AddUSer($user); + $this->AddUser($user); } } diff -r -u PageProtection-1.4/ErrorHandler.php PageProtection-1.4-for-1.6.8/ErrorHandler.php --- PageProtection-1.4/ErrorHandler.php 2006-07-21 09:30:24.000000000 +0200 +++ PageProtection-1.4-for-1.6.8/ErrorHandler.php 2006-07-21 13:09:43.000000000 +0200 @@ -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 -r -u PageProtection-1.4/PageProtection.php PageProtection-1.4-for-1.6.8/PageProtection.php --- PageProtection-1.4/PageProtection.php 2006-07-21 09:30:45.000000000 +0200 +++ PageProtection-1.4-for-1.6.8/PageProtection.php 2006-07-21 13:14:11.000000000 +0200 @@ -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"]; @@ -90,7 +92,7 @@ function protectSave(&$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor) { // die($text); $protect = new ProtectPage(); - $protect->mParser = new ProtectionParser($text,&$protect->mEnc); + $protect->mParser = new ProtectionParser($text, $protect->mEnc); $protect->mParser->parseText(); $protect->encryptTags($text, $user->getName()); @@ -114,11 +116,11 @@ 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 -r -u PageProtection-1.4/ProtectionParser.php PageProtection-1.4-for-1.6.8/ProtectionParser.php --- PageProtection-1.4/ProtectionParser.php 2006-07-21 09:30:51.000000000 +0200 +++ PageProtection-1.4-for-1.6.8/ProtectionParser.php 2006-07-21 13:16:48.000000000 +0200 @@ -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 -r -u PageProtection-1.4/ProtectPage.php PageProtection-1.4-for-1.6.8/ProtectPage.php --- PageProtection-1.4/ProtectPage.php 2006-07-21 09:30:56.000000000 +0200 +++ PageProtection-1.4-for-1.6.8/ProtectPage.php 2006-07-21 13:19:10.000000000 +0200 @@ -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(); } @@ -78,6 +80,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); + } } ?>