Extension talk:ProtectText

Fixes
It is probably waste of computing power to use memc as it is only called during editing, and then the cache will always be rebuilt. Jeblad 18:10, 28 May 2008 (UTC)

Problem
After "installing" this I can't access my wiki at all. Just get a blank page, html source code shows nothing. On version 1.13.3. I also have PHPBB/Users_Integration. / Erik 03:19, 21 December 2008 (UTC)

Extension Status?
This extension is listed as being in "Beta" version but there's no discussion in the past 8 years. Any reason not to change status to unsupported?

Updated version
HY I checked and modified the old not working version so i could use it with MediaWiki 1.25.5

The below is file inside ... extensions/ProtectABC/ProtectABC.php  * * This program is not free software therefore you can-not redistribute * it and/or modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * Please consult and/or request the administrator of QBox4u * to use the information and samples * To copy the data an written autorisation of the developer as stated in  *  the $wgExtensionCredits is required * *  You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * http://www.gnu.org/copyleft/gpl.html * * To activate this extension, add the following into your LocalSettings.php file: * require_once( "$IP/extensions/ProtectABCText/ProtectABCText.php"); * * @ingroup Extensions * @author Jan boer  * @version 1.0 * @link http://QBox4u.com * */ /****************** * Include all the required library's  * This line must be present before any global variable is referenced. */

if( !defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone. \n" ); echo( "Use this php file only locally on the QNAP TS-459 proII server \n" ); echo( "****************************  WARNING  WARNING  WARNING ****************************** \n" ); echo( "This is an restricted application only tested for application purposes inside QBox4u.com \n" ); echo( "This application wil malfunction if illegal and/or unautorised access has been detected \n" ); die( -1 ); }

$wgExtensionCredits['other'][] = array(   'path'           	=> __FILE__,	'name'				=> 'Protect ABC Text',	'version'			=> '1.0.1',	'author' 			=>  array( 'https://www.linkedin.com/in/jan-boer-a24640113','qbox4u@gmail.com', 'note:modified from the first base source of ThomasV and John Erling Blad'),	'description' 		=> 'Allow authorised users to protect parts of a Page text by the tag  ',	'license-name' 		=> 'Licence',	'url' 				=> 'https://www.mediawiki.org/wiki/Extension_talk:ProtectText' );

// Keep i18n globals so mergeMessageFileList.php doesn't break $wgMessagesDirs['ProtectABC'] 	= __DIR__. '/i18n'; $wgmodifyProtect 				= false; $wgOriginal_ABC_Page 			= '';

// Two new permissions $wgAvailableRights[] = 'protectABC'; $wgAvailableRights[] = 'protectsolecontributor';

// Set the appropiate rights $wgGroupPermissions['*']['protectABC']        				= false; $wgGroupPermissions['*']['protectsolecontributor'] 		= false; $wgGroupPermissions['sysop']['protectABC']        			= true; $wgGroupPermissions['sysop']['protectsolecontributor'] 	= true; $wgGroupPermissions['bureaucrat']['protectABC']   			= true; $wgGroupPermissions['bureaucrat']['protectsolecontributor']	= true;

// Register hooks $wgHooks['ParserBeforeStrip'][] = 'wfStripProtectTags' ; $wgHooks['EditFilter'][] 		= 'wfAllocateOriginalText' ; $wgHooks['PageContentSave'][] 	= 'wfCheckProtectText' ;

function wfCheckProtectText ( &$wikiPage, &$user, &$content, &$summary, $isMinor, $isWatch, $section, &$flags, &$status) { global $wgUser, $wgTitle, $wgVersion, $wgOriginal_ABC_Page;

if ( !$wgUser->isAllowed( 'protectABC' ) ) { $Submitted_page_text = $content->getNativeData; // Retrieve all the area's with protected text // the original text preg_match_all( "/(.*?)<\/protectABC>|\n;?:*;?§(.*?)\n|\{§(.*?)§\}/si", $wgOriginal_ABC_Page, $list1, PREG_SET_ORDER ); // the text as the user want to save preg_match_all( "/(.*?)<\/protectABC>|\n;?:*;?§(.*?)\n|\{§(.*?)§\}/si", $Submitted_page_text, $list2, PREG_SET_ORDER ); if( count($list1) < count($list2)) { # indeed an addition of an tag, we will have to protect the text $wgmodifyProtect = true; // create an error status, than the page is not saved $message = ' '.wfMessage( 'protecttext_add' )->parse.' '; } if( count($list1) > count($list2)) { # indeed an removal of the tag, we will have to protect the text $wgmodifyProtect = true; // create an error status, than the page is not saved $message = ' '.wfMessage( 'protecttext_remove' )->parse.' ';	} else for ( $i=0 ; $i < count( $list1 ); $i++ ) { // compair the content of an enclosed protected text if( $list1[$i][0] != $list2[$i][0]) { // create an error status if the encosed data differs ,than the page is not saved $wgmodifyProtect = true; $message = ' '. wfMessage( 'protecttext_modify' )->parse. ' ';					break; }			}			//************** Check on protectsolecontributor ************ //* Whenever we have an protection breach, but the user is an allowed contributer //***********************************************************						if ( $wgmodifyProtect && $wgUser->isAllowed( 'protectsolecontributor' ) ) { $conds['rev_page'] = $wgTitle->getArticleID; if( version_compare( $wgVersion, '1.11alpha', '>=' ) ) $conds[] = 'rev_deleted & '. Revision::DELETED_USER. ' = 0';				$contributors = array; $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(					'revision',					array( 'COUNT(*) AS count', 'rev_user', 'rev_user_text', ),				$conds,				__METHOD__,				array( 'GROUP BY' => 'rev_user_text', 'ORDER BY' => 'count DESC', )				);				if( $res && $dbr->numRows( $res ) > 0 ) while( $row = $dbr->fetchObject( $res ) ) $contributors[ $row->rev_user_text ] = array( $row->rev_user ); $total = 0; foreach( $contributors as $username => $info ) { list( $id ) = $info; if ($wgUser->getID != $id) { $total++; break; }				}				// if we have the same page owner and not an different contributer, and he is aowed to contributer // than cancel the protection of the previous part if (!$total){ $wgmodifyProtect = false; } }

// If we have an protection breach, terminate the save and show an fatal error if($wgmodifyProtect){ $status->fatal(new RawMessage("$message")); } }

return; }

/** * @param &$parser The parser object * @param &$text The text being parsed * @param &$x Something not used */ function wfStripProtectTags ( &$parser, &$text, &$x ) {

$text = preg_replace(			array('/(.*?)<\/protectABC>/si', '/(\n;?:*;?)§(.*?)\n/si', '/(\n;?:*;?)§(.*?)$/si', '/\{§(.*?)§\}/si'),			array("$1", "$1$2\n", "$1$2", "$1"),			$text); return true; }

/** * @param $editor * @param $text * @param $section * @param &$error * @param $summary */

function wfAllocateOriginalText ( $editor, $text, $section, &$error, $summary ) { global $wgOriginal_ABC_Page;

$wgOriginal_ABC_Page = $editor->mArticle->getContent(true); return true; }

?>

The below is file inside ... extensions/ProtectABC/i18n/en.json

{	"@metadata": { "authors": [ "Jan Boer", "QBox4u" ]	},	"protecttext_add": 			"You are not granted to add protection to a text fragment, or protect an existing text fragment", "protecttext_modify": 		"You are not granted to modify the ABC text enclosed by the tag:  ABC text  or try to remove the tags", "protecttext_remove": 		"You are not granted to remove the protection from a text fragment, or remove a protected text fragment", "protecttext_rejected": 	"All modifications will be therefore rejected. Please press cancel !!!!!!" }