Extension:IncludeOnlyNS

IncludeOnlyNS is designed to allow for one or more namespaces within a wiki to be designated as "Include Only", meaning that the page content may only be viewed if it is included on another page. The idea is to replicate the theoretical functionality of having a transcluded page with in the code. The use case for which this was developed was a wiki using Semantic MediaWiki and Semantic Forms. Semantic Forms does not allow for a form-based template to be placed in the middle of a page, so the solution was to "hide" the template on a related page in another namespace, and transclude it via a template.
 * 1) REDIRECT

IncludeOnlyNS.php
Save the following code as extensions/IncludeOnlyNS/IncludeOnlyNS.php  __FILE__,        'name'           => 'IncludeOnlyNS',        'version'        => '0.9.1',        'author'         => 'Christopher Wilson',        'description' => 'Forced redirection to main namespace on view of articles in an "include only" namespace',        'url'            => 'http://www.mediawiki.org/wiki/Extension:IncludeOnlyNS', );

function getAddress {   /*** check for https ***/ if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol = 'https'; } else { $protocol = 'http'; }   /*** return the full address ***/ return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; }

function fnRedirectByNS( &$title, &$article, &$output, &$user, $request, $mediaWiki ) { global $wgIncludeOnlyNamespaces; global $wgContLang; $currentaddress = getAddress; $namespace = $title->getNamespace; $namespaceText = $wgContLang->getNsText( $namespace ); if ( in_array( $namespace, $wgIncludeOnlyNamespaces ) ) { if ( $_GET['action'] ) { return true; } else { $redirAddress = preg_replace("/$namespaceText:/", '', $currentaddress); header("Location: $redirAddress"); return false; }        } else { return true; }       }

$wgHooks['BeforeInitialize'][] = 'fnRedirectByNS';

Changes to LocalSettings.php
Add the following line to LocalSettings: require_once( "$IP/extensions/IncludeOnlyNS/IncludeOnlyNS.php" );

Defining Namespaces as "Include-Only"
This would likely be done only with a custom namespace. For information on setting up custom namespaces, see the Manual on using custom namespaces.

Below the line to include the extension, define the array of namespaces which should be include-only. To define a "Data:" namespace as include-only, you would use: $wgIncludeOnlyNamespaces = array(       NS_DATA );