Difference between revisions of "Extension:NoViewSource.php"
(notes) |
|||
| Line 9: | Line 9: | ||
$wgExtensionFunctions[] = 'wfSetupNoViewSource'; | $wgExtensionFunctions[] = 'wfSetupNoViewSource'; | ||
| − | |||
| − | |||
$wgExtensionCredits['other'][] = array( | $wgExtensionCredits['other'][] = array( | ||
'name' => 'NoViewSource', | 'name' => 'NoViewSource', | ||
| Line 19: | Line 17: | ||
); | ); | ||
| − | + | 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(); | ||
| + | foreach (array_keys(get_class_vars('Out2')) as $k) $wgOut->$k = $oldOut->$k; | ||
| + | } | ||
function wfNoViewSourceUpdateActions(&$skin,&$actions) { | function wfNoViewSourceUpdateActions(&$skin,&$actions) { | ||
| − | + | if (isset($actions['viewsource'])) $actions['viewsource']['text'] = wfMsg('edit'), | |
| − | |||
| − | |||
| − | if (isset($actions['viewsource'])) | ||
| − | |||
| − | |||
return true; | return true; | ||
} | } | ||
Revision as of 07:47, 16 December 2007
<?php
- Extension:NoViewSource
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:Extension
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('NOVIEWSOURCE_VERSION','1.0.0, 2007-12-13');
$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(); foreach (array_keys(get_class_vars('Out2')) as $k) $wgOut->$k = $oldOut->$k; }
function wfNoViewSourceUpdateActions(&$skin,&$actions) { if (isset($actions['viewsource'])) $actions['viewsource']['text'] = wfMsg('edit'), return true; }



