Skip to content

Instantly share code, notes, and snippets.

@sk89q
Created May 11, 2013 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sk89q/5558891 to your computer and use it in GitHub Desktop.
Save sk89q/5558891 to your computer and use it in GitHub Desktop.
Extensions from wiki.sk89q.com
<?php
if (!defined('MEDIAWIKI')) {
exit(1);
}
$wgExtensionCredits['other'][] = array(
"name" => "ContextualLogo",
"author" => "sk89q",
"version" => '0.1.0',
"url" => "http://www.sk89q.com",
"description" => "Custom main logo that can be set per-page as needed."
);
class ContextualLogo {
public function onArticlePageDataBefore( $article, $fields ) {
global $wgLogo, $wgCustomLogos;
if ( !isset( $wgCustomLogos ) || !is_array( $wgCustomLogos ) ) {
return;
}
$basename = preg_replace( "#/.*$#", "", $article->getTitle() );
if ( isset( $wgCustomLogos[$basename] ) ) {
$file = wfFindFile( $wgCustomLogos[$basename] );
if ( $file ) {
$tnOpt = array(
'width' => 135,
'height' => 135
);
$thumb = $file->transform( $tnOpt );
$wgLogo = $thumb->getUrl();
$tpl->data['nav_urls']['mainpage']['href'] = Title::newFromText( $basename )->getLocalURL();
}
}
return true;
}
}
$contextualLogo = new ContextualLogo();
$wgHooks['ArticlePageDataBefore'][] = $contextualLogo;
<?php
# Not a valid entry point, skip unless MEDIAWIKI is defined
if (!defined('MEDIAWIKI')) {
exit(1);
}
$wgExtensionCredits['other'][] = array(
"name" => "TitleFix",
"author" => "sk89q",
"version" => '1.0.1',
"url" => "http://www.sk89q.com",
"description" => "Make the rendering of subpage names much better using graphics."
);
$titleFixExt = new TitleFix_MediaWiki();
$titleFixExt->registerHooks();
class TitleFix_MediaWiki
{
function onSkinTemplateOutputPageBeforeExec(&$m_skinTemplate, &$m_tpl) {
if (!$m_tpl->data['isarticle']) {
return true;
}
$html = "";
$parts = explode("/", $m_tpl->data['title']);
$i = 0;
foreach ($parts as $part) {
if ($html != "") {
$html .= '<img src="/images/subpage_arrow.png" alt="/">';
}
if ($i == count($parts) - 1) {
$html .= $part;
} else {
$html .= '<small>' . $part . '</small>';
}
$i++;
}
$m_tpl->set('title', $html);
return true;
}
public function registerHooks() {
global $wgHooks;
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = array($this, 'onSkinTemplateOutputPageBeforeExec');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment