Skip to content

Instantly share code, notes, and snippets.

@waldyrious
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldyrious/b23f3f55ee2caf04bdf0 to your computer and use it in GitHub Desktop.
Save waldyrious/b23f3f55ee2caf04bdf0 to your computer and use it in GitHub Desktop.
Debug mediawiki skin sidebar
<?php
// Code to output sidebar on original Example skin:
// https://github.com/wikimedia/mediawiki-skins-Example/blob/master/Example.skin.php#L177-L179
foreach ( $this->getSidebar() as $boxName => $box ) {
$this->outputPortlet( $box );
}
// Code to output sidebar in my modified Example skin:
$this->outputPortlet( array(
'id' => 'p-navigation',
'headerMessage' => 'navigation',
// 'content' => $this->data['nav_urls'],
'content' => $this->data['sidebar']['navigation'],
) );
// What does $this->outputPortlet() do?
// https://github.com/wikimedia/mediawiki-skins-Example/blob/master/Example.skin.php#L40-L74
private function outputPortlet( $box ) {
// ...
if ( is_array( $box['content'] ) ) {
echo '<ul>';
foreach ( $box['content'] as $key => $item ) {
if ( $item ) {
echo $this->makeListItem( $key, $item );
}
}
echo '</ul>';
} else {
echo $box['content'];
}
// ...
}
// I originally used $this->data['nav_urls'] while the original Example code uses $this->getSidebar()
// 1) How is this->data['nav_urls'] set?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/SkinTemplate.php#L456-L457
$tpl->set( 'sidebar', $this->buildSidebar() );
$tpl->set( 'nav_urls', $this->buildNavUrls() );
// What is $tpl?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/SkinTemplate.php#L183
$tpl = $this->setupTemplate( $this->template, 'skins' );
// What does $this->setupTemplate do?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/SkinTemplate.php#L72-L74
function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
return new $classname( $this->getConfig() );
}
// Where is $this->template defined?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/SkinTemplate.php#L42-L46
public $template = 'QuickTemplate';
// What does $tpl->set() do?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/QuickTemplate.php#L49-L51
public function set( $name, $value ) {
$this->data[$name] = $value; // <####################
}
// What does $this->buildSidebar() do?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/Skin.php#L1201-L1247
function buildSidebar() {
//...
$this->addToSidebar( $bar, 'sidebar' );
//...
}
// What does $this->addToSidebar() do?
// Add content from MediaWiki:Sidebar
function addToSidebar( &$bar, $message ) {
$this->addToSidebarPlain( $bar, wfMessage( $message )->inContentLanguage()->plain() );
}
// Add content from plain text
function addToSidebarPlain &$bar, $text ) {
$lines = explode( "\n", $text );
foreach ( $lines as $line ) {
// ...
}
// ...
}
// What does $this->buildNavUrls() do?
// https://github.com/wikimedia/mediawiki/blob/master/includes/skins/SkinTemplate.php#L1159-L1272
protected function buildNavUrls() { // <####################
//...
}
// 2) What does $this->getSidebar() return?
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment