Difference between revisions of "Extension:NoViewSource.php"

From Organic Design wiki
(another patch)
m (legacy, formatting)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{legacy}}
 +
{{voodoo}}
 +
<source lang="php">
 
<?php
 
<?php
# Extension:NoViewSource{{Category:Extensions|NoViewSource}}{{php}}
+
# Extension:NoViewSource
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
 
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
Line 42: Line 45:
 
return true;
 
return true;
 
}
 
}
 +
</source>
 +
[[Category:Extensions|NoViewSource]]

Latest revision as of 14:57, 31 October 2016

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.


Voodoo.svg This code exhibits voodoo programming techniques. The most common of these is extending an instance's class at runtime after it has been instantiated, a technique that can be used to provide additional hooks into existing code without requiring modification of code-base files. For a list of all our scripts which exhibit voodoo, see Category:Code that uses voodoo.
<?php
# Extension:NoViewSource
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
# - Started: 2007-12-16

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('NOVIEWSOURCE_VERSION','1.0.2, 2007-12-18');

$wgExtensionFunctions[]        = 'wfSetupNoViewSource';
$wgExtensionCredits['other'][] = array(
	'name'        => 'NoViewSource',
	'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
	'description' => 'Replaces the "view source" action with "edit" which links to login page.',
	'url'         => 'http://www.organicdesign.co.nz/Extension:NoViewSource.php',
	'version'     => NOVIEWSOURCE_VERSION
	);

function wfSetupNoViewSource() {
	global $wgHooks,$wgOut,$wgUser;
	if ($wgUser->isLoggedIn()) return;

	$wgHooks['SkinTemplateTabs'][] = 'wfNoViewSourceUpdateActions';

	# Create a new OutputPage class (Out2) which has its readOnlyPage (view source) method replaced with loginToUse
	class Out2 extends OutputPage {
		public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
			parent::loginToUse();
			}
		}

	# Replace $wgOut with a sub-classed replica
	$oldOut = $wgOut;
	$wgOut  = new Out2();
	$vars   = get_class_vars('oldOut');
	if (is_array($vars)) foreach (array_keys($vars) as $k) $wgOut->$k = $oldOut->$k;
	}

function wfNoViewSourceUpdateActions(&$skin,&$actions) {
	if (isset($actions['viewsource'])) $actions['viewsource']['text'] = wfMsg('edit');
	return true;
	}