Difference between revisions of "Extension:Wikiskin.php"
(changed capitalisation - not sure if it will help at all) |
(0.1.11 - changes to skin and css article naming) |
||
Line 8: | Line 8: | ||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
− | define('WIKISKIN_VERSION','0.1. | + | define('WIKISKIN_VERSION','0.1.11, 2007-09-20'); |
if (!isset($wgWikiSkinArticle)) $wgWikiSkinArticle = 'WikiSkin'; | if (!isset($wgWikiSkinArticle)) $wgWikiSkinArticle = 'WikiSkin'; | ||
Line 98: | Line 98: | ||
function initPage(&$out) { | function initPage(&$out) { | ||
+ | global $wgWikiSkinArticle; | ||
SkinTemplate::initPage($out); | SkinTemplate::initPage($out); | ||
− | $this->skinname = | + | $this->skinname = $wgWikiSkinArticle; |
− | $this->stylename = | + | $this->stylename = $wgWikiSkinArticle; |
$this->template = 'WikiSkinTemplate'; | $this->template = 'WikiSkinTemplate'; | ||
} | } | ||
Line 112: | Line 113: | ||
$css = $this->data[$data]; | $css = $this->data[$data]; | ||
$css = str_replace('action=raw','action=raw&templates=expand',$css); | $css = str_replace('action=raw','action=raw&templates=expand',$css); | ||
+ | $css = str_replace('&usemsgcache=yes','',$css); | ||
print $css; | print $css; | ||
} | } | ||
Line 127: | Line 129: | ||
<title><?php $this->text('pagetitle') ?></title> | <title><?php $this->text('pagetitle') ?></title> | ||
<meta http-equiv="imagetoolbar" content="no" /> | <meta http-equiv="imagetoolbar" content="no" /> | ||
− | <?php print Skin::makeGlobalVariablesScript($this->data); ?> | + | <?php print Skin::makeGlobalVariablesScript( $this->data ); ?> |
<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js"><!-- wikibits js --></script> | <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js"><!-- wikibits js --></script> | ||
<?php if($this->data['jsvarurl' ]) { ?> | <?php if($this->data['jsvarurl' ]) { ?> | ||
Line 215: | Line 217: | ||
# Read and parse the skin article | # Read and parse the skin article | ||
global $wgUser,$wgTitle,$wgParser,$wgWikiSkinArticle; | global $wgUser,$wgTitle,$wgParser,$wgWikiSkinArticle; | ||
− | $skin = new Article(Title::newFromText($wgWikiSkinArticle)); | + | $skin = new Article(Title::newFromText("MediaWiki:$wgWikiSkinArticle")); |
$opt = ParserOptions::newFromUser($wgUser); | $opt = ParserOptions::newFromUser($wgUser); | ||
$out = $wgParser->parse(preg_replace('/^\\s+/m','',$skin->fetchContent(0,false,false)),$wgTitle,$opt,true,true); | $out = $wgParser->parse(preg_replace('/^\\s+/m','',$skin->fetchContent(0,false,false)),$wgTitle,$opt,true,true); | ||
Line 245: | Line 247: | ||
function wfApplyWikiSkin() { | function wfApplyWikiSkin() { | ||
− | global $wgUser; | + | global $wgUser,$wgWikiSkinArticle; |
− | $wgUser->setOption('skin', | + | $wgUser->setOption('skin',$wgWikiSkinArticle); |
$wgUser->mSkin =& new SkinWikiSkin; | $wgUser->mSkin =& new SkinWikiSkin; | ||
return true; | return true; | ||
} | } | ||
?> | ?> |
Revision as of 01:41, 20 September 2007
<?php
- Extension:WikiSkinTemplate:Php
- - Uses a wikitext article for the skin instead of a PHP file. Special items like search box and login link use magic words
- - See http://www.mediawiki.org/wiki/Extension:WikiSkin for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('WIKISKIN_VERSION','0.1.11, 2007-09-20');
if (!isset($wgWikiSkinArticle)) $wgWikiSkinArticle = 'WikiSkin'; $wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : $wgWikiSkinArticle; $wgWikiSkinMagic = array( 'CURRENTUSER', 'TITLE', 'SUBTITLE', 'SITELOGO', 'TEXT', 'SEARCH', 'PERSONAL', 'LOGIN', 'ACTIONS', 'SITENOTICE', 'INFO', 'CATLINKS', 'FOOTER' );
$wgExtensionFunctions[] = 'wfSetupWikiSkin'; $wgHooks['MagicWordMagicWords'][] = 'wfWikiSkinMagicWord'; $wgHooks['MagicWordwgVariableIDs'][] = 'wfWikiSkinVariableID'; $wgHooks['LanguageGetMagic'][] = 'wfWikiSkinLangMagic'; $wgHooks['ParserGetVariableValueSwitch'][] = 'wfWikiSkinGetVariable';
$wgExtensionCredits['other'][] = array( 'name' => 'WikiSkin', 'author' => 'User:Nad', 'description' => 'Allows normal wikitext articles to define skin content and layout', 'url' => 'http://www.mediawiki.org/wiki/Extension:WikiSkin', 'version' => WIKISKIN_VERSION );
function wfWikiSkinMagicWord(&$magicWords) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $var) $magicWords[] = "MAG_$var"; return true; }
function wfWikiSkinVariableID(&$variables) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $var) $variables[] = constant("MAG_$var"); return true; }
function wfWikiSkinLangMagic(&$langMagic, $langCode = 0) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $var) { $magic = "MAG_$var"; $langMagic[defined($magic) ? constant($magic) : $magic] = array(0,$var); } return true; }
function wfWikiSkinGetVariable(&$parser,&$cache,&$index,&$ret) { switch ($index) {
case MAG_CURRENTUSER: $parser->disableCache(); $ret = $GLOBALS['wgUser']->mName; break;
# These ones are all replaced by a token to be filled by skin when rendering page case MAG_TITLE: case MAG_SUBTITLE: case MAG_SITELOGO: case MAG_TEXT: case MAG_SEARCH: case MAG_PERSONAL: case MAG_LOGIN: case MAG_ACTIONS: case MAG_SITENOTICE: case MAG_INFO: case MAG_CATLINKS: case MAG_FOOTER: $magic = constant($index); $ret = "((((WikiSkin:$magic))))"; break; } return true; }
- Define new skin class, create an instance and make it current
function wfSetupWikiSkin() {
# Create skin class based on monobook which parses the skin article and embeds the content class SkinWikiSkin extends SkinTemplate {
function initPage(&$out) { global $wgWikiSkinArticle; SkinTemplate::initPage($out); $this->skinname = $wgWikiSkinArticle; $this->stylename = $wgWikiSkinArticle; $this->template = 'WikiSkinTemplate'; }
}
class WikiSkinTemplate extends QuickTemplate {
# Expand templates in CSS before expanding function expandcss($data) { $css = $this->data[$data]; $css = str_replace('action=raw','action=raw&templates=expand',$css); $css = str_replace('&usemsgcache=yes',,$css); print $css; }
function execute() {
# Build the HTML, HEAD and BODY elements and send to output wfSuppressWarnings();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> text('lang') ?>" lang="text('lang') ?>" dir="text('dir') ?>"> html('headlinks') ?>
'; $replace['SITELOGO'] = '
' . '
'; $replace['SITENOTICE'] = $this->data['sitenotice'] ? '
' : ''; $replace['SUBTITLE'] = '
'.htmlspecialchars($this->translator->translate('tagline')).'
' . '
'; $replace['INFO'] = ($this->data['undelete'] ? '
' : '') . ($this->data['newtalk'] ? '
' : '') . ($this->data['showjumplinks'] ? '
' : ''); $replace['TEXT'] = $this->data['bodytext']; $replace['CATLINKS'] = $this->data['catlinks'] ? '
' : ''; $replace['ACTIONS'] = '
- ';
foreach ($this->data['content_actions'] as $key => $tab)
$replace['ACTIONS'] .= '
- '.htmlspecialchars($tab['text']).' '; $replace['ACTIONS'] .= '
'; $replace['PERSONAL'] = '
- ';
foreach ($this->data['personal_urls'] as $key => $item) {
$replace['PERSONAL'] .= '
- '.htmlspecialchars($item['text']).' '; if ($key == 'pt-login' || $key == 'pt-anonlogin') $replace['LOGIN'] = ''.htmlspecialchars($item['text']).''; } $replace['PERSONAL'] .= '
'; # Read and parse the skin article global $wgUser,$wgTitle,$wgParser,$wgWikiSkinArticle; $skin = new Article(Title::newFromText("MediaWiki:$wgWikiSkinArticle")); $opt = ParserOptions::newFromUser($wgUser); $out = $wgParser->parse(preg_replace('/^\\s+/m','',$skin->fetchContent(0,false,false)),$wgTitle,$opt,true,true); $content = $out->getText(); # Replace all the fields and send to output echo preg_replace('/\\({4}WikiSkin:MAG_(.+?)\\){4}/ie','$replace["$1"]',$content); ?>
html('reporttime') ?> <?php
wfRestoreWarnings();
}
} # end of class definition
# Make the new skin current (now and after login/logout) wfApplyWikiSkin(); global $wgHooks; $wgHooks['UserLoginComplete'][] = 'wfApplyWikiSkin'; $wgHooks['UserLogoutComplete'][] = 'wfApplyWikiSkin';
} # end of setup function
function wfApplyWikiSkin() {
global $wgUser,$wgWikiSkinArticle;
$wgUser->setOption('skin',$wgWikiSkinArticle);
$wgUser->mSkin =& new SkinWikiSkin;
return true;
}
?>