Extension:SpecialNamespaces/sourcecode

For installations based on previous MediaWiki versions, use Extension:SpecialNamespaces/sourcecode (ver 0.1).

The code below is intended for MediaWiki 1.16 to 1.17. See Extension:SpecialNamespaces for installation instructions. The following five files need to be created in .../extensions/Namespaces/ in your MediaWiki installation. In MediaWiki 1.18 - 1.19 all instances of 'Xml::Hidden' must be replaced with 'Html::Hidden'.

SpecialNamespaces_body.php
';					$defaultname = $row->ns_name; $nsdefault = $row->ns_default; $nscanonical = $row->ns_canonical; $old = Xml::hidden( 'wpNamespacesID', $row->ns_id ); $topmessage = wfMsgExt( 'namespaces_edittext', array( 'parseinline' ) ); $intromessage = wfMsgExt( 'namespaces_editintro', array( 'parseinline' ) ); $button = wfMsg( 'edit' ); } else { $nsid = $wgRequest->getVal( 'wpNamespacesID' ) ? $wgRequest->getVal( 'wpNamespacesID' ) : $wgRequest->getVal( 'prefix' ); $nsid = Xml::input( 'wpNamespacesID', 20, $nsid, array( 'tabindex' => '1', 'id' => 'mw-namespaces-nsid', 'maxlength' => '20' ) ); $nsdefault = $wgRequest->getCheck( 'wpNamespacesDefault' ); $nscanonical = $wgRequest->getCheck( 'wpNamespacesCanonical' ); $old = ''; $defaultname = $wgRequest->getVal( 'wpNamespacesName' ) ? $wgRequest->getVal( 'wpNamespacesName' ) : wfMsg( 'namespaces_defaultname' ); $topmessage = wfMsgExt( 'namespaces_addtext', array( 'parseinline' ) ); $intromessage = wfMsgExt( 'namespaces_addintro', array( 'parseinline' ) ); $button = wfMsg( 'namespaces_addbutton' ); }

$nsidmessage = wfMsgHtml( 'namespaces_nsid' ); $nsdefaultmessage = wfMsg( 'namespaces_default' ); $nscanonicalmessage = wfMsg( 'namespaces_canonical' ); $reasonmessage = wfMsg( 'namespaces_reasonfield' ); $nsnamemessage = wfMsg( 'namespaces_nsname' );

$wgOut->addHTML(					Xml::openElement( 'fieldset' ) .					Xml::element( 'legend', null, $topmessage ) .					$intromessage .					Xml::openElement( 'form', array( 'id' => 'mw-namespaces-editform', 'method' => 'post', 'action' => $actionUrl ) ) .					Xml::openElement( 'table', array( 'id' => "mw-namespaces-$action" ) ) .					" $nsidmessage   " .					' ' . Xml::label( $nsdefaultmessage, 'mw-namespaces-nsdefault' ) . ' ' .					"" . Xml::check( 'wpNamespacesDefault', $nsdefault, array( 'id' => 'mw-namespaces-nsdefault' ) ) . '  ' .					' ' . Xml::label( $nscanonicalmessage, 'mw-namespaces-nscanonical' ) . ' ' .					'' .  Xml::check( 'wpNamespacesCanonical', $nscanonical, array( 'id' => 'mw-namespaces-nscanonical' ) ) . '  ' .					' ' . Xml::label( $nsnamemessage, 'mw-namespaces-nsname' ). ' ' .					''. Xml::input( 'wpNamespacesName', 60, $defaultname, array( 'tabindex' => '1', 'maxlength' => '200', 'id' => 'mw-namespaces-nsname' ) ). ' ' .					' '. Xml::label( $reasonmessage, 'mw-namespaces-editreason' ). ' ' .					''. Xml::input( 'wpNamespacesReason', 60, $defaultreason, array( 'tabindex' => '1', 'id' => 'mw-namespaces-editreason', 'maxlength' => '200') ). Xml::hidden( 'wpNamespacesAction', $action ). $old. Xml::hidden( 'wpEditToken', $token ). ' ' .					' '. Xml::submitButton( $button, array( 'id' => 'mw-namespaces-submit' ) ). ' ' .					Xml::closeElement( 'table' ). Xml::closeElement( 'form' ). Xml::closeElement( 'fieldset' ) );				break;		}	}

function doSubmit { global $wgRequest, $wgOut; $nsid = $wgRequest->getVal( 'wpNamespacesID' ); $do = $wgRequest->getVal( 'wpNamespacesAction' ); if( preg_match( '/[\s:&=]/', $nsid ) ) { $this->error( 'namespaces-badprefix', htmlspecialchars( $nsid ) ); $this->showForm( $do ); return; }		$reason = $wgRequest->getText( 'wpNamespacesReason' ); $selfTitle = $this->getTitle; $dbw = wfGetDB( DB_MASTER ); switch( $do ) { case 'delete': $dbw->delete(					'namespace_names',					array( 'ns_id' => $nsid ),					__METHOD__				);

if ( $dbw->affectedRows == 0 ) { $this->error( 'namespaces_delfailed', $nsid ); $this->showForm( $do ); } else { $wgOut->addWikiMsg( 'namespaces_deleted', $nsid ); $wgOut->returnToMain( false, $selfTitle ); $log = new LogPage( 'namespaces' ); $log->addEntry( 'ns_delete', $selfTitle, $reason, array( $nsid ) ); }				$this->discard; break; case 'edit': case 'add': $theurl = $wgRequest->getVal( 'wpNamespacesName' ); $nsdefault = $wgRequest->getCheck( 'wpNamespacesDefault' ) ? 1 : 0;				$nscanonical = $wgRequest->getCheck( 'wpNamespacesCanonical' ) ? 1 : 0;				$data = array(					'ns_id' => $nsid,					'ns_name' => $theurl,					'ns_default' => $nsdefault,					'ns_canonical' => $nscanonical				);

if( $do == 'add' ) { $dbw->insert(						'namespace_names',						$data,						__METHOD__,						'IGNORE'					); } else { $dbw->update(						'namespace_names',						$data,						array( 'ns_id' => $nsid ),						__METHOD__,						'IGNORE'					); }

if( $dbw->affectedRows == 0 ) { $this->error( "namespaces_{$do}failed", $nsid ); $this->showForm( $do ); } else { $wgOut->addWikiMsg( "namespaces_{$do}ed", $nsid ); $wgOut->returnToMain( false, $selfTitle ); $log = new LogPage( 'namespaces' ); $log->addEntry(						'ns_' . $do, $selfTitle, $reason,						array( $nsid, $theurl, $nsdefault, $nscanonical )					); }				$this->discard; break; }	}

function trans_default( $tl, $msg0, $msg1 ) { if( $tl === '0' ) { return $msg0; }		if( $tl === '1' ) { return $msg1; }		return htmlspecialchars( $tl ); }

function showList( $admin ) { global $wgUser, $wgOut, $wgScriptPath;

$wgOut->addExtensionStyle( "{$wgScriptPath}/extensions/Namespaces/SpecialNamespaces.css" );

$nsidmessage = wfMsgHtml( 'namespaces_nsid' ); $nsnamemessage = wfMsgHtml( 'namespaces_nsname' ); $nsdefaultmessage = wfMsgHtml( 'namespaces_default' ); $nscanonicalmessage = wfMsgHtml( 'namespaces_canonical' ); $message_0 = wfMsgHtml( 'namespaces_0' ); $message_1 = wfMsgHtml( 'namespaces_1' );

$out = ' ';		$wgOut->addWikiMsg( 'namespaces_intro' ); $wgOut->addHTML( $out ); $wgOut->addWikiMsg( 'namespaces_intro_footer' ); $selfTitle = $this->getTitle;

if ( $admin ) { $skin = $wgUser->getSkin; $addtext = wfMsgHtml( 'namespaces_addtext' ); $addlink = $skin->link( $selfTitle, $addtext, array, array( 'action' => 'add' ) ); $wgOut->addHTML( ' ' . $addlink . ' ' ); }

$dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(			'namespace_names',			'*',			1,			__METHOD__,			array( 'ORDER BY' => 'ns_id' )		); $numrows = $res->numRows; if ( $numrows == 0 ) { $this->error( 'namespaces_error' ); return; }

$out = " ';		$wgOut->addHTML( $out );	}

function error { global $wgOut; $args = func_get_args; $wgOut->wrapWikiMsg( "$1 ", $args ); }

protected function getGroupName { return 'wiki'; } }