Difference between revisions of "Extension:Wikiskin.php"

From Organic Design wiki
m
m
Line 8: Line 8:
  
 
$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin';
 
$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin';
$wgWikiSkinMagic  = array('CURRENTUSER','LOGO','TEXT','SEARCH','PERSONAL','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER');
+
$wgWikiSkinMagic  = array('LOGO','TEXT','SEARCH','PERSONAL','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER');
  
 
$wgExtensionFunctions[]                    = 'wfSetupWikiSkin';
 
$wgExtensionFunctions[]                    = 'wfSetupWikiSkin';
Line 128: Line 128:
 
# Build list of special fields and their content
 
# Build list of special fields and their content
 
$replace = array(
 
$replace = array(
MAG_SEARCH     => '<div id="p-search" class="portlet">'
+
'SEARCH'     => '<div id="p-search" class="portlet">'
                  .'<h5><label for="searchInput">'.$this->msg('search').'</label></h5>'
+
                .'<h5><label for="searchInput">'.$this->msg('search').'</label></h5>'
                  .'<div id="searchBody" class="pBody">'
+
                .'<div id="searchBody" class="pBody">'
                  .'<form action="'.$this->text('searchaction').'" id="searchform"><div>'
+
                .'<form action="'.$this->text('searchaction').'" id="searchform"><div>'
                  .'<input id="searchInput" name="search" type="text" '
+
                .'<input id="searchInput" name="search" type="text" '
                  .($this->haveMsg('accesskey-search') ? 'accesskey="'.$this->msg('accesskey-search').'"' : '')
+
                .($this->haveMsg('accesskey-search') ? 'accesskey="'.$this->msg('accesskey-search').'"' : '')
                  .(isset($this->data['search']) ? ' value="'.$this->text('search').'"' : '')
+
                .(isset($this->data['search']) ? ' value="'.$this->text('search').'"' : '')
                  .' /><input type="submit" name="go" class="searchButton" id="searchGoButton" value="'.$this->msg('go').'" />&nbsp;'
+
                .' /><input type="submit" name="go" class="searchButton" id="searchGoButton" value="'.$this->msg('go').'" />&nbsp;'
                  .'<input type="submit" name="fulltext" class="searchButton" value="'.$this->msg('search').'" /></div></form>'
+
                .'<input type="submit" name="fulltext" class="searchButton" value="'.$this->msg('search').'" /></div></form>'
                  .'</div></div>',
+
                .'</div></div>',
MAG_LOGO       => '<div class="portlet" id="p-logo"><a style="background-image: url('.$this->text('logopath').');" '
+
'LOGO'       => '<div class="portlet" id="p-logo"><a style="background-image: url('.$this->text('logopath').');" '
                  .'href="'.htmlspecialchars($this->data['nav_urls']['mainpage']['href']).'" '
+
                .'href="'.htmlspecialchars($this->data['nav_urls']['mainpage']['href']).'" '
                  .'title="'.$this->msg('mainpage').'"></a></div>'
+
                .'title="'.$this->msg('mainpage').'"></a></div>'
                  .'<script type="'.$this->text('jsmimetype').'"> if (window.isMSIE55) fixalpha(); </script>',
+
                .'<script type="'.$this->text('jsmimetype').'"> if (window.isMSIE55) fixalpha(); </script>',
MAG_SITENOTICE => $this->data['sitenotice'] ? '<div id="siteNotice">'.$this->html('sitenotice').'</div>' : '',
+
'SITENOTICE' => $this->data['sitenotice'] ? '<div id="siteNotice">'.$this->html('sitenotice').'</div>' : '',
MAG_SUBTITLE   => '<h3 id="siteSub">'.$this->msg('tagline').'</h3><div id="contentSub">'.$this->html('subtitle').'</div>',
+
'SUBTITLE'   => '<h3 id="siteSub">'.$this->msg('tagline').'</h3><div id="contentSub">'.$this->html('subtitle').'</div>',
MAG_INFO       => ($this->data['undelete'] ? '<div id="contentSub2">'.$this->html('undelete').'</div>' : '')
+
'INFO'       => ($this->data['undelete'] ? '<div id="contentSub2">'.$this->html('undelete').'</div>' : '')
                  .($this->data['newtalk'] ? '<div class="usermessage">'.$this->html('newtalk').'</div>' : '')
+
                .($this->data['newtalk'] ? '<div class="usermessage">'.$this->html('newtalk').'</div>' : '')
                  .($this->data['showjumplinks'] ? '<div id="jump-to-nav">'.$this->msg('jumpto')
+
                .($this->data['showjumplinks'] ? '<div id="jump-to-nav">'.$this->msg('jumpto')
 
                    .'<a href="#column-one">'.$this->msg('jumptonavigation').'</a>'
 
                    .'<a href="#column-one">'.$this->msg('jumptonavigation').'</a>'
 
                    .', <a href="#searchInput">'.$this->msg('jumptosearch').'</a></div>' : ''),
 
                    .', <a href="#searchInput">'.$this->msg('jumptosearch').'</a></div>' : ''),
MAG_TEXT       => $this->html('bodytext'),
+
'TEXT'       => $this->html('bodytext'),
MAG_CATLINKS   => $this->html('catlinks') ? '<div id="catlinks">'.$this->html('catlinks').'</div>' : ''
+
'CATLINKS'   => $this->html('catlinks') ? '<div id="catlinks">'.$this->html('catlinks').'</div>' : ''
 
);
 
);
  
 
# Actions
 
# Actions
$replace[MAG_ACTIONS] = '<ul>';
+
$replace['ACTIONS'] = '<ul>';
 
foreach ($this->data['content_actions'] as $key => $tab) $replace['ACTIONS'] .=  
 
foreach ($this->data['content_actions'] as $key => $tab) $replace['ACTIONS'] .=  
 
'<li id="ca-'.htmlspecialchars($key).'"'
 
'<li id="ca-'.htmlspecialchars($key).'"'
 
.($tab['class'] ? ' class="'.htmlspecialchars($tab['class']).'"' : '')
 
.($tab['class'] ? ' class="'.htmlspecialchars($tab['class']).'"' : '')
 
.'><a href="'.htmlspecialchars($tab['href']).'">'.htmlspecialchars($tab['text']).'</a></li>';
 
.'><a href="'.htmlspecialchars($tab['href']).'">'.htmlspecialchars($tab['text']).'</a></li>';
$replace[MAG_ACTIONS] .= '</ul>';
+
$replace['ACTIONS'] .= '</ul>';
  
 
# Personal tools
 
# Personal tools
$replace[MAG_PERSONAL] = '<ul>';
+
$replace['PERSONAL'] = '<ul>';
 
foreach ($this->data['personal_urls'] as $key => $item) $replace['PERSONAL'] .=
 
foreach ($this->data['personal_urls'] as $key => $item) $replace['PERSONAL'] .=
 
'<li id="pt-'.htmlspecialchars($key).'"'
 
'<li id="pt-'.htmlspecialchars($key).'"'
Line 169: Line 169:
 
.(!empty($item['class']) ? ' class="'.htmlspecialchars($item['class']).'"' : '')
 
.(!empty($item['class']) ? ' class="'.htmlspecialchars($item['class']).'"' : '')
 
.'>'.htmlspecialchars($item['text']).'</a></li>';
 
.'>'.htmlspecialchars($item['text']).'</a></li>';
$replace[MAG_PERSONAL] .= '</ul>';
+
$replace['PERSONAL'] .= '</ul>';
  
 
# Read and parse the skin article
 
# Read and parse the skin article
Line 178: Line 178:
  
 
# Replace all the fields and send to output
 
# Replace all the fields and send to output
echo preg_replace('/\\({4}WikiSkin:(.+?)\\){4}/ie','"($1)".$replace[$1]."(/$1)"',$content->getText());
+
#echo preg_replace('/\\({4}WikiSkin:MAG_(.+?)\\){4}/ie','$replace["$1"]',$content->getText());
#echo $content->getText();
+
echo $content->getText();
 
?>
 
?>
 
<script type="text/javascript"> if (window.runOnloadHook) runOnloadHook();</script>
 
<script type="text/javascript"> if (window.runOnloadHook) runOnloadHook();</script>

Revision as of 02:47, 6 April 2007

<?

  1. Extension:WikiSkin
  2. - Uses a wikitext article for the skin instead of a PHP file. Special items like search box and login link use magic words
  3. - Version 0.1 (2007-04-06)
  4. - See http://www.mediawiki.org/wiki/Extension:WikiSkin for installation and usage details
  5. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  6. - Author: http://www.organicdesign.co.nz/nad

$wgWikiSkinArticle = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin'; $wgWikiSkinMagic = array('LOGO','TEXT','SEARCH','PERSONAL','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER');

$wgExtensionFunctions[] = 'wfSetupWikiSkin'; $wgHooks['MagicWordMagicWords'][] = 'wfWikiSkinMagicWord'; $wgHooks['MagicWordwgVariableIDs'][] = 'wfWikiSkinVariableID'; $wgHooks['LanguageGetMagic'][] = 'wfWikiSkinLangMagic'; $wgHooks['ParserGetVariableValueSwitch'][] = 'wfWikiSkinGetVariable';

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(&$this,&$cache,&$index,&$ret) { switch ($index) {

case MAG_CURRENTUSER: $ret = $GLOBALS['wgUser']->mName; break;

# These ones are all replaced by a token to be filled by skin when rendering page case MAG_LOGO: case MAG_TEXT: case MAG_SEARCH: case MAG_PERSONAL: 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') ?>">

'', 'LOGO' => '
MastodonRSSCodeEmail
' .'', 'SITENOTICE' => $this->data['sitenotice'] ? '
'.$this->html('sitenotice').'
' : '', 'SUBTITLE' => '

'.$this->msg('tagline').'

'.$this->html('subtitle').'
', 'INFO' => ($this->data['undelete'] ? '
'.$this->html('undelete').'
' : '') .($this->data['newtalk'] ? '
'.$this->html('newtalk').'
' : '') .($this->data['showjumplinks'] ? '' : ''), 'TEXT' => $this->html('bodytext'), 'CATLINKS' => $this->html('catlinks') ? '' : '' ); # Actions $replace['ACTIONS'] = ''; # Personal tools $replace['PERSONAL'] = ''; # Read and parse the skin article global $wgUser,$wgTitle,$wgParser,$wgWikiSkinArticle; $skin = new Article(Title::newFromText($wgWikiSkinArticle)); $opt = ParserOptions::newFromUser($wgUser); $content = $wgParser->parse($skin->fetchContent(0,false,false),$wgTitle,$opt,true,true); # Replace all the fields and send to output #echo preg_replace('/\\({4}WikiSkin:MAG_(.+?)\\){4}/ie','$replace["$1"]',$content->getText()); echo $content->getText(); ?>

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

?>