Extension:LockTitle

Enables locking of certain titles to prohibit unprivileged users to create said page. The locking is per page basis and utilizing a table in the database to store the pages. A simple special page is available to create or remove locks.

License
Copyright © 2006 Carl Fürstenberg This program is free software; you can 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Author
Carl Fürstenberg (AzaToth) 

Pre-requisites
This extension has only yet been tested with 1.9.2 SVN trunk

Files to install
Place these files in extension/LockTitle

install.php
 modified to fit by Carl Fürstenberg (AzaToth)  * @copyright © 2006 Rob Church * @licence Copyright holder allows use of the code for any purpose */

require_once( '../../maintenance/commandLine.inc' );

$sql = dirname( __FILE__ ). '/LockTitle.sql'; $check_for_table = 'locktitle';

$dba = & wfGetDB( DB_MASTER );

if( !$dba->isOpen ) { echo( "A connection to the database could not be established.\n\n" ); die( 1 ); }
 * 1) Check we're connected

if( !$dba->tableExists( $dba->tableName( $check_for_table ) ) ) { $res = $dba->sourceFile( $sql ); if( gettype($res) === boolean && $res === true ) { echo( "The table has been set up correctly.\n" ); } else { echo( "$res\n" );
 * 1) Do nothing if the table exists

}

} else { echo( "The table already exists. No action was taken.\n" ); }

$dba->close; echo( "\n" );
 * 1) Close the connection

?>

LockTitle.i18n.php
 "Couldn't find the locktitle table, please ensure it's installed", ); ?>

LockTitle.php
 * @copyright Copyright © 2006 Carl Fürstenberg * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */

// Some new permissions $wgGroupPermissions['sysop']['locktitle']		= true; $wgGroupPermissions['bureaucrat']['locktitle']	= true; $wgGroupPermissions['steward']['locktitle']		= true; $wgGroupPermissions['developer']['locktitle']	= true; $wgAvailableRights[] = 'locktitle';

$wgExtensionFunctions[] = 'wfLockTitleSetup'; $wgExtensionCredits['other'][] = array(	'name' => 'LockTitle',	'author' => 'Carl Fürstenberg (AzaToth)',	'description' => 'Locks titles from creation by unpriviledged users',	'url' => 'http://www.mediawiki.org/wiki/Extension:LockTitle',	'version' => '0.99.0', ); $wgHooks['userCan'][] = 'wfLockTitle';

require_once( 'LockTitle.i18n.php');

function wfLockTitleSetup { global $wgLockTitleLoaded, $wgLockTitleMessages, $wgMessageCache; foreach( $wgLockTitleMessages as $key => $value ) { $wgMessageCache->addMessages( $value, $key ); }	$dbw =& wfGetDB( DB_MASTER );

// We might not have the table in the database

if(!$dbw->tableExists('locktitle')){ throw new FatalError(wfMsg('locktitle_no_table')); } }

function wfLockTitle( $title, $user , $action , &$result ) { if( $action != 'create' ) { // We only are checking for creation return; }

$key = $title->getPrefixedDBkey; $dbw =& wfGetDB( DB_MASTER );

$field = $dbw->selectField( 		'locktitle', 		'`key`' , 		array( '`key`' => $key )	);

if( $field === false ){ // no entry found return; } else { // "title" is locked down

if( $user->isAllowed( 'locktitle' ) ) { // some users may bypass the locktitle return; }

$result = false; return; }

} ?>

LockTitle.sql
CREATE TABLE /*$wgDBprefix*/locktitle ( `key` varchar(255) binary NOT NULL,  PRIMARY KEY  (`key`) ) ENGINE=InnoDB;

SpecialLockTitle_body.php
setHeaders; global $wgUser, $wgRequest, $wgOut;

if( ! $wgUser->isAllowed( 'locktitle' ) ) { $wgOut->permissionRequired('locktitle'); } else { $wgOut->addWikiText(wfMsg('locktitle_init_text'));

if( $wgRequest->getCheck( 'locktitle' ) && $wgRequest->wasPosted ) { $dbw =& wfGetDB( DB_MASTER );

$act = $wgRequest->getVal( 'act' ); $target_title = $wgRequest->getVal( 'target_title' );

if( $target_title ) {

$target_title = Title::newFromText( $target_title ); $key = $target_title->getPrefixedDBkey;

if( $act == 'add' ) { $dbw->insert(							'locktitle',							array( '`key`' => $key, ),							'SpecialLockTitle::execute',							array( 'IGNORE' )						);

$wgOut->addHTML( wfElement( 'div', null , $target_title->getPrefixedText. ' is now locked' ) );

} else if ( $act == 'del' ) { $dbw->delete(							'locktitle',							array( '`key`' => $key, ),							'SpecialLockTitle::execute',							array( 'IGNORE' )						);

$wgOut->addHTML( wfElement( 'div', null , $target_title->getPrefixedText. ' is now unlocked' ) ); }

}			} 			$self = $this->getTitle; $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl ) ). wfOpenElement( 'table' ). wfOpenElement( 'tr' ). wfOpenElement( 'td' ). wfLabel( wfMsg('locktitle_add'), 'add' ). wfCloseElement( 'td' ). wfOpenElement( 'td' ). wfRadio( 'act', 'add' , true , array ( 'id' => 'add' ) ). wfCloseElement( 'td' ). wfCloseElement( 'tr' ). wfOpenElement( 'tr' ). wfOpenElement( 'td' ). wfLabel( wfMsg('locktitle_del'), 'del' ). wfCloseElement( 'td' ). wfOpenElement( 'td' ). wfRadio( 'act', 'del' , false , array ( 'id' => 'del' ) ). wfCloseElement( 'td' ). wfCloseElement( 'tr' ). wfOpenElement( 'tr' ). wfOpenElement( 'td' ). wfLabel( wfMsg('locktitle_title'), 'title' ). wfCloseElement( 'td' ). wfOpenElement( 'td' ). wfInput( 'target_title', 40, '' , array( 'type' => 'text' ) ). wfCloseElement( 'td' ). wfCloseElement( 'tr' ). wfOpenElement( 'tr' ). wfOpenElement( 'td', array( 'colspan' => 2 ) ). wfSubmitButton( 'locktitle', array( 'name' => 'locktitle' ) ). wfCloseElement( 'td' ). wfCloseElement( 'tr' ). wfCloseElement( 'table' ). wfCloseElement( 'form' );

$wgOut->addHTML( $form ); }	} }

?>

SpecialLockTitle.i18n.php
 'Locks down a title from the ability for creation by non-priviledged users.',	'locktitle' => 'Lock titles',	'locktitle_add' => 'Add lock',	'locktitle_del' => 'Remove lock',	'locktitle_title' => 'Title',

); ?>

SpecialLockTitle.php
 * @copyright Copyright © 2006 Carl Fürstenberg * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */

$wgExtensionFunctions[] = 'wfSpecialLockTitle'; $wgExtensionCredits['specialpage'][] = array(	'name' => 'LockTitle',	'author' => 'Carl Fürstenberg (AzaToth)',	'description' => 'Interface to add and remove locks',	'url' => 'http://www.mediawiki.org/wiki/Extension:LockTitle',	'version' => '0.99.0',	);

require_once( 'SpecialLockTitle.i18n.php');

$wgAutoloadClasses['SpecialLockTitle_body'] = dirname( __FILE__ ). '/SpecialLockTitle_body.php'; $wgSpecialPages['LockTitle'] = 'SpecialLockTitle_body';

function wfSpecialLockTitle { global $wgSpecialLockTitleMessages, $wgMessageCache, $wgAvailableRights;

foreach( $wgSpecialLockTitleMessages as $key => $value ) { $wgMessageCache->addMessages( $value, $key ); } } ?>

Instructions
run this command in the top directory (to create the table needed):

extensions/LockTitles/install.php

In your MediaWiki LocalSettings.php, add the following line some place towards the bottom of the file:

require_once("$IP/extensions/LockTitles/LockTitles.php"); require_once("$IP/extensions/LockTitles/SpecialLockTitles.php");

Configuration
Priviledged users have acess to the page Special:LockTitle where adding and removing of locks can be done.