Difference between revisions of "Extension:Wikiskin.php"

From Organic Design wiki
m
(mark CURRENTUSER as uncacheable)
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.2, 2007-05-10');
+
define('WIKISKIN_VERSION','0.1.3, 2007-05-19');
  
 
$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin';
 
$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin';
Line 61: Line 61:
 
}
 
}
  
function wfWikiSkinGetVariable(&$this,&$cache,&$index,&$ret) {
+
function wfWikiSkinGetVariable(&$parser,&$cache,&$index,&$ret) {
 
switch ($index) {
 
switch ($index) {
  
 
case MAG_CURRENTUSER:
 
case MAG_CURRENTUSER:
 +
$parser->disableCache();
 
$ret = $GLOBALS['wgUser']->mName;
 
$ret = $GLOBALS['wgUser']->mName;
 
break;
 
break;

Revision as of 23:36, 18 May 2007

<?php

  1. Extension:WikiSkin{{#Security:*|dev}}{{#Security:view|*}}Template:Php
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.
  1. - Uses a wikitext article for the skin instead of a PHP file. Special items like search box and login link use magic words
  2. - See http://www.mediawiki.org/wiki/Extension:WikiSkin for installation and usage details
  3. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  4. - Author: http://www.organicdesign.co.nz/nad

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

define('WIKISKIN_VERSION','0.1.3, 2007-05-19');

$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin'; $wgWikiSkinMagic = array( 'CURRENTUSER', 'SITELOGO', 'TEXT', 'SEARCH', 'PERSONAL', 'LOGIN', 'ACTIONS', 'SITENOTICE', 'SUBTITLE', '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_SITELOGO: case MAG_TEXT: case MAG_SEARCH: case MAG_PERSONAL: case MAG_LOGIN: case MAG_ACTIONS: case MAG_SITENOTICE: case MAG_SUBTITLE: case MAG_INFO: case MAG_CATLINKS: case MAG_FOOTER: $magic = constant($index); $ret = "((((WikiSkin:$magic))))"; break; } return true; }

  1. 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) { SkinTemplate::initPage($out); $this->skinname = 'wikiskin'; $this->stylename = 'wikiskin'; $this->template = 'WikiSkinTemplate'; }

}

class WikiSkinTemplate extends QuickTemplate { 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') ?> <?php $this->text('pagetitle') ?> data['printable']) ) { ?>media="print" href="text('stylepath') ?>/common/commonPrint.css" /> data['jsvarurl' ]) { ?> data['pagecss' ]) { ?> data['usercss' ]) { ?> data['userjs' ]) { ?> data['userjsprev']) { ?> data['trackbackhtml']) print $this->data['trackbackhtml']; ?> html('headscripts') ?> data['body_ondblclick']) { ?>ondblclick="text('body_ondblclick') ?>" data['body_onload' ]) { ?>onload="text('body_onload') ?>" class="text('nsclass') ?> text('dir') ?>">

' . '
' . '
' . '
' . 'haveMsg('accesskey-search') ? 'accesskey="'.htmlspecialchars($this->translator->translate('accesskey-search')).'"' : '') . (isset($this->data['search']) ? ' value="'.htmlspecialchars($this->data['search']).'"' : '') . ' /> ' . '
' . '

'; $replace['SITELOGO'] = '

MastodonRSSCodeEmail

' . '

'; $replace['SITENOTICE'] = $this->data['sitenotice'] ? '

'.$this->data['sitenotice'].'

' : ''; $replace['SUBTITLE'] = '

'.htmlspecialchars($this->translator->translate('tagline')).'

' . '

'.$this->data['subtitle'].'

'; $replace['INFO'] = ($this->data['undelete'] ? '

'.$this->data['undelete'].'

' : '') . ($this->data['newtalk'] ? '

'.$this->data['newtalk'].'

' : '') . ($this->data['showjumplinks'] ? '

' : ''); $replace['TEXT'] = $this->data['bodytext']; $replace['CATLINKS'] = $this->data['catlinks'] ? '

' : ''; $replace['ACTIONS'] = '

'; $replace['PERSONAL'] = '

'; # Read and parse the skin article global $wgUser,$wgTitle,$wgParser,$wgWikiSkinArticle; $skin = new Article(Title::newFromText($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 global $wgUser; $wgUser->setOption('skin','WikiSkin'); $wgUser->mSkin =& new SkinWikiSkin;

} # end of setup function

?>