Difference between revisions of "Extension:Wikiskin.php"
(read skin and replace magic words) |
(actions and personal tools) |
||
Line 9: | Line 9: | ||
$wgWikiSkin = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin'; | $wgWikiSkin = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin'; | ||
− | $wgWikiSkinMagic = array('CURRENTUSER','LOGO','TEXT','SEARCH','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER'); | + | $wgWikiSkinMagic = array('CURRENTUSER','LOGO','TEXT','SEARCH','PERSONAL','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER'); |
$wgExtensionFunctions[] = 'wfSetupWikiSkin'; | $wgExtensionFunctions[] = 'wfSetupWikiSkin'; | ||
$wgHooks['MagicWordMagicWords'][] = 'wfWikiSkinMagicWord'; | $wgHooks['MagicWordMagicWords'][] = 'wfWikiSkinMagicWord'; | ||
Line 42: | Line 42: | ||
break; | break; | ||
+ | # These ones are all replaced by a token to be filled by skin when rendering page | ||
case MAG_LOGO: | case MAG_LOGO: | ||
− | |||
− | |||
− | |||
− | |||
case MAG_TEXT: | case MAG_TEXT: | ||
case MAG_SEARCH: | case MAG_SEARCH: | ||
+ | case MAG_PERSONAL: | ||
case MAG_ACTIONS: | case MAG_ACTIONS: | ||
case MAG_SITENOTICE: | case MAG_SITENOTICE: | ||
Line 117: | Line 115: | ||
<?php if($this->data['body_onload' ]) { ?>onload="<?php $this->text('body_onload') ?>"<?php } ?> | <?php if($this->data['body_onload' ]) { ?>onload="<?php $this->text('body_onload') ?>"<?php } ?> | ||
class="<?php $this->text('nsclass') ?> <?php $this->text('dir') ?>"> | class="<?php $this->text('nsclass') ?> <?php $this->text('dir') ?>"> | ||
+ | <a name="top" id="top"></a> | ||
<?php | <?php | ||
# Build list of special fields and their content | # Build list of special fields and their content | ||
$replace = array( | $replace = array( | ||
+ | 'SEARCH' => '<div id="p-search" class="portlet">' | ||
+ | .'<h5><label for="searchInput">'.$this->msg('search').'</label></h5>' | ||
+ | .'<div id="searchBody" class="pBody">' | ||
+ | .'<form action="'.$this->text('searchaction').'" id="searchform"><div>' | ||
+ | .'<input id="searchInput" name="search" type="text" ' | ||
+ | .($this->haveMsg('accesskey-search') ? 'accesskey="'.$this->msg('accesskey-search').'"') | ||
+ | .(isset($this->data['search']) ? ' value="'.$this->text('search').'"') | ||
+ | .' /><input type="submit" name="go" class="searchButton" id="searchGoButton" value="'.$this->msg('go').'" /> ' | ||
+ | .'<input type="submit" name="fulltext" class="searchButton" value="'.$this->msg('search').'" /></div></form>' | ||
+ | .'</div></div>'; | ||
+ | 'LOGO' => '<div class="portlet" id="p-logo"><a style="background-image: url('.$this->text('logopath').');" ' | ||
+ | .'href="'.htmlspecialchars($this->data['nav_urls']['mainpage']['href']).'" ' | ||
+ | .'title="'.$this->msg('mainpage').'"></a></div>' | ||
+ | .'<script type="'.$this->text('jsmimetype').'"> if (window.isMSIE55) fixalpha(); </script>', | ||
'SITENOTICE' => $this->data['sitenotice'] ? '<div id="siteNotice">'.$this->html('sitenotice').'</div>' : '', | 'SITENOTICE' => $this->data['sitenotice'] ? '<div id="siteNotice">'.$this->html('sitenotice').'</div>' : '', | ||
'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>', | ||
− | '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="#searchInput">'.$this->msg('jumptosearch').'</a></div>' : ''), | |
'TEXT' => $this->html('bodytext'), | 'TEXT' => $this->html('bodytext'), | ||
'CATLINKS' => $this->html('catlinks') ? '<div id="catlinks">'.$this->html('catlinks').'</div>' : '' | 'CATLINKS' => $this->html('catlinks') ? '<div id="catlinks">'.$this->html('catlinks').'</div>' : '' | ||
); | ); | ||
+ | |||
+ | # Actions | ||
+ | $replace['ACTIONS'] = '<ul>'; | ||
+ | foreach ($this->data['content_actions'] as $key => $tab) $replace['ACTIONS'] .= | ||
+ | '<li id="ca-'.htmlspecialchars($key).'"' | ||
+ | .($tab['class'] ? ' class="'.htmlspecialchars($tab['class']).'"' : '') | ||
+ | .'><a href="'.htmlspecialchars($tab['href']).'">'.htmlspecialchars($tab['text']).'</a></li>'; | ||
+ | $replace['ACTIONS'] .= '</ul>'; | ||
+ | |||
+ | # Personal tools | ||
+ | $replace['PERSONAL'] = '<ul>'; | ||
+ | foreach ($this->data['personal_urls'] as $key => $item) $replace['PERSONAL'] .= | ||
+ | '<li id="pt-'.htmlspecialchars($key).'"' | ||
+ | .($item['active'] ? ' class="active"' : '') | ||
+ | .'><a href="'.htmlspecialchars($item['href']).'"' | ||
+ | .(!empty($item['class']) ? ' class="'.htmlspecialchars($item['class']).'"') | ||
+ | .'>'.htmlspecialchars($item['text']).'</a></li>'; | ||
+ | $replace['PERSONAL'] .= '</ul>'; | ||
# Read and parse the skin article | # Read and parse the skin article |
Revision as of 10:49, 5 April 2007
<?
- Extension:Livelets
- - Uses a wikitext article for the skin instead of a PHP file. Special items like search box and login link use magic words
- - Version 0.1 (2007-04-05)
- - 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
$wgWikiSkin = isset($_REQUEST['skin']) ? $_REQUEST['skin'] : 'WikiSkin';
$wgWikiSkinMagic = array('CURRENTUSER','LOGO','TEXT','SEARCH','PERSONAL','ACTIONS','SITENOTICE','SUBTITLE','INFO','CATLINKS','FOOTER'); $wgExtensionFunctions[] = 'wfSetupWikiSkin'; $wgHooks['MagicWordMagicWords'][] = 'wfWikiSkinMagicWord'; $wgHooks['MagicWordwgVariableIDs'][] = 'wfWikiSkinMagicWordID'; $wgHooks['LanguageGetMagic'][] = 'wfWikiSkinWordLang'; $wgHooks['ParserGetVariableValueSwitch'][] = 'wfGetWikiSkinMagicWord';
function wfWikiSkinMagicWord(&$magicWords) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $magic) $magicWords[] = "MAG_$magic"; return true; }
function wfWikiSkinMagicWordID(&$magicWords) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $magic) $magicWords[] = constant("MAG_$magic"); return true; }
function wfWikiSkinWordLang(&$magicWords, $langCode = 0) { global $wgWikiSkinMagic; foreach($wgWikiSkinMagic as $magic) $magicWords[constant("MAG_$magic")] = array(0,$magic); return true; }
function wfGetWikiSkinMagicWord(&$this,&$cache,&$index,&$ret) { global $wgMagicWordsEn; 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 = $wgMagicWordsEn[$index]; $ret = "((((WikiSkin:$magic))))"; break; } return true; }
- 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') ?>
'; 'LOGO' => '
' .'
', 'SITENOTICE' => $this->data['sitenotice'] ? '
' : '', 'SUBTITLE' => '
'.$this->msg('tagline').'
', 'INFO' => ($this->data['undelete'] ? '
' : '') .($this->data['newtalk'] ? '
' : '') .($this->data['showjumplinks'] ? '
' : ''), 'TEXT' => $this->html('bodytext'), 'CATLINKS' => $this->html('catlinks') ? '
' : '' ); # Actions $replace['ACTIONS'] = '
- ';
foreach ($this->data['content_actions'] as $key => $tab) $replace['ACTIONS'] .=
'
- '.htmlspecialchars($tab['text']).' '; $replace['ACTIONS'] .= '
'; # Personal tools $replace['PERSONAL'] = '
- ';
foreach ($this->data['personal_urls'] as $key => $item) $replace['PERSONAL'] .=
'
- '.htmlspecialchars($item['text']).' '; $replace['PERSONAL'] .= '
'; # Read and parse the skin article global $wgUser,$wgTitle,$wgParser,$wgWikiSkin; $skin = new Article(Title::newFromText($wgWikiSkin)); $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:(.+?)\\){4}/ie','$replace["$1"]',$content->getText()); ?> html('reporttime') ?> <?php wfRestoreWarnings();
}
}
- Make the new skin current
function wfSetupWikiSkin() { global $wgUser; $wgUser->setOption('skin','WikiSkin'); $wgUser->mSkin =& new SkinWikiSkin; }
?>