User:Agbad/SandBox

From mediawiki.org

For the extension "Lock User Space":

New SpecialPages list[edit]

  • Special:RightsToSpace

Rights[edit]

  • makerightsspace
  • lockspace

LockUserSpace.php[edit]

Index: trunk/extensions/lockspace/LockUserSpace.php
===================================================================
+++ trunk/extensions/lockspace/LockUserSpace.php	(working copy)
@@ +1,55 @@
+<?php
+if( !defind('MEDIAWIKI') ) die( -1 );
+$wgExtensionCredits['specialpage'][] = array(
+	'name' => 'Lock User Space',
+	'author' => 'Agbad',
+	'url' => 'http://www.mediawiki.org/wiki/Extension:Lock_User_Space',
+	'description' => 'Make an option for regular user to (un)protect/delete their pages.',
+	'descriptionmsg' => 'LockUser-msg',
+	'svn-date' => '$LastChangedDate$',
+	'svn-revision' => '$LastChangedRevision$',
+);
+$folder = dirname(__FILE__);
+$wgAvailabelRights[] = 'makerightsspace';
+$wgAvailabelRights[] = 'lockspace';
+$wgGroupPermissions['bureaucrat']['makerightsspace'] = true;
+$wgGroupPermissions['stweard']['makerightsspace'] = true;
+$wgGroupPermissions['lockspace']['lockspace'] = true;
+function addRightOtomat() {
+	global $wgUser;
+	if ( !$wgUser->isBlocked() && !$wgUser->isAnon() && !$wgUser->isAllowed( 'protect' ) && ($wgUser->getOption( 'canlockspace' ) == true or $wgUser->getOptions( 'canlockspace' ) == NULL) ) {
+		$wgUser->addGroup( 'lockspace' );
+	} else {
+		$wgUser->removeGroup( 'lockspace' );
+	}
+}
+$wgSpecialPages['makeRightsSpace'] = 'MakeRightsSpacePage';
+$wgSpecialPagesGroup['makeRightsSpace'] = 'users';
+$wgAutoloadClasses['SpecialMakeRightsSpace'] = '$folder/SpecialMakeRightsSpace.php';
+$wgExtensionMessagesFiles['LockSpace'] = '$folder/LockUserSpace.i18n.php';
+// Logs
+$wgLogTypes[] = 'rightsspace';
+$wgLogNames['rightsspace'] = 'rightsspace-logpage';
+$wgLogHeaders['rightsspace'] = 'rightsspace-logpagetext';
+$wgLogAction['rightsspace/add'] = 'rightsspace-logaddtext';
+$wgLogAction['rightsspace/remove'] = 'rightsspace-logremovetext';
+function RightsForRight() {
+	global $wgTitle, $wgUser;
+	$name = $wgUser->getName();
+	$lockspace = $wgUser->isAllowed( 'lockspace' );
+	if ( $lockspace ) {
+		if( ( $wgTitle->getNameSpace() == NS_USER or $wgTitle->getNameSpace() == NS_USER_TALK ) && $wgTitle->getBasePage() == $name ) {
+			$wgGroupPermissions['lockspace']['protect'] = true;
+			$wgGroupPermissions['lockspace']['delete'] = true;
+			$wgGroupPermissions['lockspace']['autoconfirmed'] = true;
+			$wgGroupPermissions['lockspace']['editprotected'] = true;
+		} else {
+			$wgGroupPermissions['lockspace']['protect'] = false;
+			$wgGroupPermissions['lockspace']['delete'] = false;
+			$wgGroupPermissions['lockspace']['editprotected'] = false;
+			if ( !$wgUser->isAllowed( 'move' ) { //If the user isn't old user
+				$wgGroupPermissions['lockspace']['autoconfirmed'] = false;
+			}
+		}
+	}
+}

SpecialMakeRightsSpace.php[edit]

Index: trunk/extensions/lockspace/SpecialMakeRightsSpace.php
===================================================================
+++ trunk/extensions/lockspace/SpecialMakeRightsSpace.php	(working copy)
@@ +1,73 @@
+<?php
+if( !defind('MEDIAWIKI') ) die( -1 );
+class SpecialMakeRightsSpace extends SpecialPage {
+	function __construct() {
+		parent::__construct( 'MakeRightsSpace' );
+		wfLoadExtensionMessages( 'LockSpace' );
+	}
+	function execute( $subpages ) {
+		global $wgOut, $wgUser, $wgRequest, $wgAuth, $wgScript;
+		if( !$wgUser->isAllowed( 'makerightsspace' ) ) {
+			$wgOut->permissionRequired( 'makerightsspace' );
+			return;
+		}
+		if( $wgRequest->getVal( 'user' ) <> NULL ) {
+			$user = $wgRequest->getVal( 'user' );
+		} elseif ( $subpages <> NULL ) {
+			$user = $subpages;
+		} else {
+			$user = NULL;
+		}
+		if( $wgRequest->getVal( 'action' ) == 'submit' && $wgRequest->wasPosted() ) {
+			$action = 'submit';
+		} else {
+			$action = 'work';
+		}
+		if( !is_null( $user ) && !$wgAuth->userExsits( $user ) ) {
+			$wgOut->showErrorPage( 'lock-nouser', 'lock-nousertext' );
+			return;
+		}
+		if( is_null( $user ) ) {
+			$wgOut->showErrorPage( 'lock-notwriteuser', 'lock-notwriteusertext' );
+			return;
+		}
+		$u = User::newFromName( $user );
+		if( $u->isAllowed( 'protect' ) ) {
+			$wgOut->showErrorPage( 'lockspace-cant', 'lockspace-canttext' );
+			return;
+		}
+		if( $action == 'work' ) {
+			$wgOut->setPageTitle( wfMsg( 'RightsToSpace' ) );
+			if ( $u->isAllowed( 'lockspace' ) ) {
+				$before = wfMsg( 'lockuser-true' );
+				$after = wfMsg( 'lockuser-false-after' );
+			} else {
+				$before = wfMsg( 'lockuser-false' );
+				$after = wfMsg( 'lockuser-true-after' );
+			}
+			$linkToUserPage = $wgUser->getSkin()->makeKnownLinkObj( Title::MakeTitle( NS_USER, $u->getName() ), $u->getName() );
+			$wgOut->addWikiText( wfMsg( 'rightsTolock-text', $linkToUserPage, $before, $after ) );
+			$form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgScript ) ) .
+				Xml::inputLabel( wfMsg( 'lockuser-reason' ), 'wpReason', 'wpReason', 100, $reason, array( 'maxlegnth' => '100' ) ) .
+				Xml::submitButoon( wfMsg( 'lock-submit' ) ) .
+				Xml::closeElement( 'form' );
+			$wgOut->addHtml( $form );
+		} elseif( $action == 'submit' ) {
+			$log = new LogPage( 'rightsspace' );
+			if ( $u->isAllowed( 'lockspace' ) {
+				$after = wfMsg( 'lock-removefrom' );
+				$actionLog = 'remove';
+				$u->removeGroup( 'lockspace' );
+				$u->setOption( 'canlockspace', false );
+			} else {
+				$after = wfMsg( 'lock-addto' );
+				$actionLog = 'add';
+				$u->addGroup( 'lockspace' );
+				$u->setOption( 'canlockspace', true );
+			}
+			$log->addEntry( $actionLog, $wgUser->getUserPage(), wfMsg( 'lockuser-log-change', $after ), $reason );
+			$wgOut->showErrorPage( 'lockpermissions-complete', 'lockpermissions-completetext' ) //This isn't error page, but I need its format
+			}
+		}
+	}
+}

Messages:[edit]

Message Name Content (en) Content (he)
LockUser-msg Make an option for regular users to (un)protect/delete their pages. ื™ื•ืฆืจ ืืคืฉืจื•ืช ืœืžืฉืชืžืฉื™ื ืจื’ื™ืœื™ื (ืœื) ืœื”ื’ืŸ/ืœืžื—ื•ืง ื“ืคื™ื ืžืžืจื—ื‘ ื”ืžืฉืชืžืฉ ืฉืœื”ื.
rightsspace-logpage Permissions for user space ื”ืจืฉืื•ืช ืœืžืจื—ื‘ ื”ืžืฉืชืžืฉ
rightsspace-logpagetext ื‘ื™ื•ืžืŸ ื–ื” ืžื•ืคื™ืขื™ื ื”ืฉื™ื ื•ื™ื™ื ื‘ื”ืจืฉืื•ืช ืฉืœ ื”ืžืฉืชืžืฉื™ื ื‘ื ื•ื’ืข ืœืžื—ื™ืงื”/ื”ื’ื ื” ืขืฆืžื™ืช ืฉืœ ื“ืคื™ื”ื.
rightsspace-logaddtext ื›ืืŸ ืžื•ืคื™ืขื™ื ื›ืœ ืชื•ืกืคื•ืช ื”ืจืฉืืช ื”ื”ื’ื ื”/ืžื—ื™ืงื” ืขืฆืžื™ืช ื‘ืžืจื—ื‘ ื”ืžืฉืชืžืฉ.
rightsspace-logremovetext ื›ืืŸ ืžื•ืคื™ืขื™ื ื›ืœ ื”ื•ืจื“ื•ืช ื”ืจืฉืืช ื”ื”ื’ื ื”/ืžื—ื™ืงื” ืขืฆืžื™ืช ื‘ืžืจื—ื‘ ื”ืžืฉืชืžืฉ.
lock-nouser ืื™ืŸ ืžืฉืชืžืฉ ื›ื–ื”
lock-nousertext ืฉื ื”ืžืฉืชืžืฉ ืฉื‘ื—ืจืช ืœืฉื ื•ืช ืœื• ืืช ื”ื”ืจืฉืื” ืื™ื ื• ืงื™ื™ื.
lock-notwriteuser You did'nt choose username ืœื ื‘ื—ืจืช ืฉื ืžืฉืชืžืฉ
lock-notwriteusertext ืœื ื‘ื—ืจืช ืฉื ืžืฉืชืžืฉ ืœืฉื™ื ื•ื™ ื”ื”ืจืฉืื•ืช ืฉืœื• ื‘ืขื ื™ื™ืŸ ื‘ืžื—ื™ืงื”/ื”ื’ื ื” ื‘ืžืจื—ื‘ ื”ืื™ืฉื™.
lockspace-cant ืžืฉืชืžืฉ ื–ื” ืื™ื ื• ื™ื›ื•ืœ ืœืงื‘ืœ ื”ื”ืจืฉืื”
lockspace-canttext ืื™ืŸ ื‘ืืคืฉืจื•ืชืš ืœืฉื ื•ืช ืœืžืฉืชืžืฉ ื–ื” ืืช ื”ืจืฉืื•ืชื™ื• ื‘ื ื•ื’ืข ืœื”ื’ื ื”/ืžื—ื™ืงื” ื‘ืžืจื—ื‘ ื”ืื™ืฉื™.
RightsToSpace ื”ืจืฉืื•ืช ืœื ืขื™ืœื” ืื™ืฉื™ืช ืฉืœ ื”ืžืจื—ื‘ ื”ืื™ืฉื™
lockuser-true ื ื™ืชื ื” ื”ื”ืจืฉืื”
lockuser-false ืœื ื ื™ืชื ื” ื”ื”ืจืฉืื”
lockuser-false-after ืชื™ืœืงื— ืœืžืฉืชืžืฉ ื”ื”ืจืฉืื”
lockuser-true-after ืชื™ื ืชืŸ ืœืžืฉืชืžืฉ ื”ื”ืจืฉืื”
rightsTolock-text ืœืžืฉืชืžืฉ $1 $2 ืœืžื—ื•ืง/ืœื”ื’ืŸ ืขืœ ื”ื“ืคื™ื ืฉื‘ืžืจื—ื‘ื• ื”ืื™ืฉื™. ืื ื‘ืจืฆื•ื ืš ืœืฉื ื•ืช ืืช ื”ืจืฉืื•ืชื™ื• ืฉืœ ื”ืžืฉืชืžืฉ, ืื–ื™ $3.
lock-submit Change the permissions ืฉื ื” ืืช ื”ื”ืจืฉืื•ืช
lock-addto added to ื”ื•ืกื™ืฃ ืœ
lock-removefrom removed from ื”ืกื™ืจ ืž
lockuser-reason Reason: ืกื™ื‘ื”:
lockpermissions-complete ื”ืฉื™ื ื•ื™ ื‘ื”ืจืฉืื•ืช ื”ื•ืฉืœื
lockpermissions-completetext ื”ืฉื™ื ื•ื™ ื‘ื”ืจืฉืืช ื”ื”ื’ื ื”/ืžื—ื™ืงื” ื‘ืžืจื—ื‘ ื”ืื™ืฉื™ ืขื‘ืจื” ื‘ื”ืฆืœื—ื”.
right-lockspace Protect/delete pages in their space. ืœืžื—ื•ืง/ืœื”ื’ืŸ ืขืœ ื“ืคื™ื ื‘ืžืจื—ื‘ ื”ืื™ืฉื™ ืฉืœื”ื.
right-makerightsspace Add/remove the permission "lockspace". ื”ื•ืกืคื”/ื”ืกืจื” ืฉืœ ื”ื”ืจืฉืื” "lockspace".
group-lockspace Admins in their space ืžืคืขื™ืœื™ื ื‘ืžืจื—ื‘ื
group-lockspsace-member Admin to his space ืžืคืขื™ืœ ืœืžืจื—ื‘ื•
grouppage-lockspace Project:Admin to his space Project:ืžืคืขื™ืœ ืœืžืจื—ื‘ื•