Extension:NoViewSource.php

From Organic Design wiki
Revision as of 23:29, 17 December 2007 by Nad (talk | contribs) (voodoo)

<?php

  1. Extension:NoViewSource
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

Voodoo.svg

In computer programming, "Voodoo", or "Magic" refers to techniques that are secret or not widely known, and may be deliberately kept secret. The Jargon File makes a distinction between "deep magic", which refers to code based on esoteric theoretical knowledge; "black magic" (voodoo), which refers to code based on techniques that appear to work but which lack a theoretical explanation; and "heavy wizardry", which refers to code based on obscure or undocumented intricacies of particular hardware or software.

At Organic Design 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. Another is reading in a class file, declaring it under a different name, then sub-classing that with a new class of the original name - that way the environment uses the new extended class thinking it's the original one.

See also

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension
  3. - 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' => '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; }