New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap-mediawiki /BootstrapMediaWiki.skin.php #83
Open
chatchay
wants to merge
6
commits into
borkweb:master
Choose a base branch
from
chatchay:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…n (add this to LocalSettings.php to enable, see code).
* @author Creative Commons Corporation
* @copyright Matthew Batchelder 2012 - http://borkweb.com/
* @copyright Creative Commons Corporation 2015 - https://github.com/creativecommons/bootstrap-mediawiki
* @license: GPLv2 (http://www.gnu.org/copyleft/gpl.html)
*/
if ( ! defined( 'MEDIAWIKI' ) ) {
die( -1 );
}//end if
//File removed on new mediawiki versions (1.24.1 at least).
//require_once('includes/SkinTemplate.php');
if(file_exists('includes/SkinTemplate.php')){
require_once('includes/SkinTemplate.php');
}
/**
* Inherit main code from SkinTemplate, set the CSS and template filter.
* @Package MediaWiki
* @subpackage Skins
*/
class SkinBootstrapMediaWiki extends SkinTemplate {
/** Using Bootstrap */
public $skinname = 'bootstrap-mediawiki';
public $stylename = 'bootstrap-mediawiki';
public $template = 'BootstrapMediaWikiTemplate';
public $useHeadElement = true;
/**
* initialize the page
*/
public function initPage( OutputPage $out ) {
global $wgSiteJS;
parent::initPage( $out );
$out->addModuleScripts( 'skins.bootstrapmediawiki' );
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1, maximum-scale=1' );
}//end initPage
/**
* prepares the skin's CSS
*/
public function setupSkinUserCss( OutputPage $out ) {
global $wgSiteCSS;
parent::setupSkinUserCss( $out );
$out->addModuleStyles( 'skins.bootstrapmediawiki' );
// we need to include this here so the file pathing is right
$out->addStyle( 'bootstrap-mediawiki/font-awesome/css/font-awesome.min.css' );
}//end setupSkinUserCss
}
/**
* @Package MediaWiki
* @subpackage Skins
*/
class BootstrapMediaWikiTemplate extends QuickTemplate {
/**
* @var Cached skin object
*/
//public $skin;
/**
* Template filter callback for Bootstrap skin.
* Takes an associative array of data set from a SkinTemplate-based
* class, and a wrapper for MediaWiki's localization database, and
* outputs a formatted page.
*
* @access private
*/
public function execute() {
global $wgRequest, $wgUser, $wgSitename, $wgSitenameshort, $wgCopyrightLink, $wgCopyright, $wgBootstrap, $wgArticlePath, $wgGoogleAnalyticsID, $wgSiteCSS;
global $wgEnableUploads;
global $wgLogo;
global $wgTOCLocation;
global $wgNavBarClasses;
global $wgSubnavBarClasses;
//$this->skin = $this->data['skin'];
$action = $wgRequest->getText( 'action' );
$url_prefix = str_replace( '$1', '', $wgArticlePath );
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
$this->html('headelement');
?>
} |
tone2526
suggested changes
Jan 5, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @author Creative Commons Corporation
* @copyright Matthew Batchelder 2012 - http://borkweb.com/
* @copyright Creative Commons Corporation 2015 - https://github.com/creativecommons/bootstrap-mediawiki
* @license: GPLv2 (http://www.gnu.org/copyleft/gpl.html)
*/
if ( ! defined( 'MEDIAWIKI' ) ) {
die( -1 );
}//end if
//File removed on new mediawiki versions (1.24.1 at least).
//require_once('includes/SkinTemplate.php');
if(file_exists('includes/SkinTemplate.php')){
require_once('includes/SkinTemplate.php');
}
/**
* Inherit main code from SkinTemplate, set the CSS and template filter.
* @Package MediaWiki
* @subpackage Skins
*/
class SkinBootstrapMediaWiki extends SkinTemplate {
/** Using Bootstrap */
public $skinname = 'bootstrap-mediawiki';
public $stylename = 'bootstrap-mediawiki';
public $template = 'BootstrapMediaWikiTemplate';
public $useHeadElement = true;
/**
* initialize the page
*/
public function initPage( OutputPage $out ) {
global $wgSiteJS;
parent::initPage( $out );
$out->addModuleScripts( 'skins.bootstrapmediawiki' );
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1, maximum-scale=1' );
}//end initPage
/**
* prepares the skin's CSS
*/
public function setupSkinUserCss( OutputPage $out ) {
global $wgSiteCSS;
parent::setupSkinUserCss( $out );
$out->addModuleStyles( 'skins.bootstrapmediawiki' );
// we need to include this here so the file pathing is right
$out->addStyle( 'bootstrap-mediawiki/font-awesome/css/font-awesome.min.css' );
}//end setupSkinUserCss
}
/**
* @Package MediaWiki
* @subpackage Skins
*/
class BootstrapMediaWikiTemplate extends QuickTemplate {
/**
* @var Cached skin object
*/
//public $skin;
/**
* Template filter callback for Bootstrap skin.
* Takes an associative array of data set from a SkinTemplate-based
* class, and a wrapper for MediaWiki's localization database, and
* outputs a formatted page.
*
* @access private
*/
public function execute() {
global $wgRequest, $wgUser, $wgSitename, $wgSitenameshort, $wgCopyrightLink, $wgCopyright, $wgBootstrap, $wgArticlePath, $wgGoogleAnalyticsID, $wgSiteCSS;
global $wgEnableUploads;
global $wgLogo;
global $wgTOCLocation;
global $wgNavBarClasses;
global $wgSubnavBarClasses;
//$this->skin = $this->data['skin'];
$action = $wgRequest->getText( 'action' );
$url_prefix = str_replace( '$1', '', $wgArticlePath );
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
$this->html('headelement');
?>
<div class="navbar navbar-default navbar-fixed-top <?php echo $wgNavBarClasses; ?>" role="navigation">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<div class="navbar-header">
<button class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<?php echo $this->data['nav_urls']['mainpage']['href'] ?>" title="<?php echo $wgSitename ?>"><?php echo isset( $wgLogo ) && $wgLogo ? "<img src='{$wgLogo}' alt='Logo'/> " : ''; echo $wgSitenameshort ?: $wgSitename; ?></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
<a href="<?php echo $this->data['nav_urls']['mainpage']['href'] ?>">Home</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tools <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="<?php echo $url_prefix; ?>Special:RecentChanges" class="recent-changes"><i class="fa fa-edit"></i> Recent Changes</a></li>
<li><a href="<?php echo $url_prefix; ?>Special:SpecialPages" class="special-pages"><i class="fa fa-star-o"></i> Special Pages</a></li>
<?php if ( $wgEnableUploads ) { ?>
<li><a href="<?php echo $url_prefix; ?>Special:Upload" class="upload-a-file"><i class="fa fa-upload"></i> Upload a File</a></li>
<?php } ?>
</ul>
</li>
<?php echo $this->nav( $this->get_page_links( 'Bootstrap:TitleBar' ) ); ?>
</ul>
<?php
if ( $wgUser->isLoggedIn() ) {
if ( count( $this->data['personal_urls'] ) > 0 ) {
$user_icon = '<span class="user-icon"><img src="https://secure.gravatar.com/avatar/'.md5(strtolower( $wgUser->getEmail())).'.jpg?s=20&r=g"/></span>';
$user_nav = $this->get_array_links( $this->data['personal_urls'], $user_icon . $wgUser->getName(), 'user' );
?>
<ul<?php $this->html('userlangattributes') ?> class="nav navbar-nav navbar-right">
<?php echo $user_nav; ?>
</ul>
<?php
}//end if
if ( count( $this->data['content_actions']) > 0 ) {
$content_nav = $this->get_array_links( $this->data['content_actions'], 'Page', 'page' );
?>
<ul class="nav navbar-nav navbar-right content-actions"><?php echo $content_nav; ?></ul>
<?php
}//end if
} else { // else if is logged in
?>
<ul class="nav navbar-nav navbar-right">
<li>
<?php echo Linker::linkKnown( SpecialPage::getTitleFor( 'Userlogin' ), wfMessage( 'login' ), array(/*"title" => wfMessage( 'login' )*/), array("returnto" => trim($_GET['title']))); ?>
</li>
</ul>
<?php
}
?>
<form class="navbar-search navbar-form navbar-right" action="<?php $this->text( 'wgScript' ) ?>" id="searchform" role="search">
<div>
<input class="form-control" type="search" name="search" placeholder="Search" title="Search <?php echo $wgSitename; ?> [ctrl-option-f]" accesskey="f" id="searchInput" autocomplete="off">
<input type="hidden" name="title" value="Special:Search">
</div>
</form>
</div>
</div>
</div><!-- topbar -->
<?php
if( $subnav_links = $this->get_page_links('Bootstrap:Subnav') ) {
?>
<div class="subnav subnav-fixed">
<div class="container">
<?php
$subnav_select = $this->nav_select( $subnav_links );
if ( trim( $subnav_select ) ) {
?>
<select id="subnav-select">
<?php echo $subnav_select; ?>
</select>
<?php
}//end if
?>
<ul class="nav nav-pills">
<?php echo $this->nav( $subnav_links ); ?>
</ul>
</div>
</div>
<?php
}//end if
?>
<div id="wiki-outer-body">
<div id="wiki-body" class="container">
<?php
if ( 'sidebar' == $wgTOCLocation ) {
?>
<div class="row">
<section class="col-md-3 toc-sidebar"></section>
<section class="col-md-9 wiki-body-section">
<?php
}//end if
?>
<?php if( $this->data['sitenotice'] ) { ?><div id="siteNotice" class="alert-message warning"><?php $this->html('sitenotice') ?></div><?php } ?>
<?php if ( $this->data['undelete'] ): ?>
<!-- undelete -->
<div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
<!-- /undelete -->
<?php endif; ?>
<?php if($this->data['newtalk'] ): ?>
<!-- newtalk -->
<div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
<!-- /newtalk -->
<?php endif; ?>
<div class="pagetitle page-header">
<h1><?php $this->html( 'title' ) ?> <small><?php $this->html('subtitle') ?></small></h1>
</div>
<div class="body">
<?php $this->html( 'bodytext' ) ?>
</div>
<?php if ( $this->data['catlinks'] ): ?>
<div class="category-links">
<!-- catlinks -->
<?php $this->html( 'catlinks' ); ?>
<!-- /catlinks -->
</div>
<?php endif; ?>
<?php if ( $this->data['dataAfterContent'] ): ?>
<div class="data-after-content">
<!-- dataAfterContent -->
<?php $this->html( 'dataAfterContent' ); ?>
<!-- /dataAfterContent -->
</div>
<?php endif; ?>
<?php
if ( 'sidebar' == $wgTOCLocation ) {
?>
</section></section>
<?php
}//end if
?>
</div><!-- container -->
</div>
<div class="bottom">
<div class="container">
<footer>
<div class="row"><div class="col-md-6">This wiki is licensed to the public under a <a class="external" rel="nofollow" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0</a> license.<br> Your use of this wiki is governed by the <a href="/CcWiki:Terms_of_Use">Terms of Use</a>.<br><a href="/wiki/CCWiki:Privacy_policy" title="CCWiki:Privacy policy">Privacy policy</a><br><a href="/wiki/CCWiki:About" title="CCWiki:About">About Creative Commons</a><br><a href="/wiki/CCWiki:General_disclaimer" title="CCWiki:General disclaimer">Disclaimers</a></div>
<div class="col-md-6"><?php echo $this->data['lastmod']; ?><br>Theme based on <a href="https://github.com/creativecommons/bootstrap-mediawiki">bootstrap-mediawiki</a> by BorkWeb.<br><br><a href="https://creativecommons.org/licenses/by/4.0/"><img src="https://licensebuttons.net/l/by/4.0/88x31.png" alt="Creative Commons Attribution 4.0" width="88" height="31"></a> <a href="//www.mediawiki.org/"><img src="/resources/assets/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" srcset="/resources/assets/poweredby_mediawiki_132x47.png 1.5x, /resources/assets/poweredby_mediawiki_176x62.png 2x" width="88" height="31"></div></div>
</footer>
</div><!-- container -->
</div><!-- bottom -->
<?php
$this->html('bottomscripts'); /* JS call to runBodyOnloadHook */
$this->html('reporttime');
if ( $this->data['debug'] ) {
?>
<!-- Debug output:
<?php $this->text( 'debug' ); ?>
-->
<?php
}//end if
?>
</body>
</html>
<?php
}//end execute
/**
* Render one or more navigations elements by name, automatically reveresed
* when UI is in RTL mode
*/
private function nav( $nav ) {
$output = '';
foreach ( $nav as $topItem ) {
$pageTitle = Title::newFromText( $topItem['link'] ?: $topItem['title'] );
if ( array_key_exists( 'sublinks', $topItem ) ) {
$output .= '<li class="dropdown">';
$output .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $topItem['title'] . ' <b class="caret"></b></a>';
$output .= '<ul class="dropdown-menu">';
foreach ( $topItem['sublinks'] as $subLink ) {
if ( 'divider' == $subLink ) {
$output .= "<li class='divider'></li>\n";
} elseif ( $subLink['textonly'] ) {
$output .= "<li class='nav-header'>{$subLink['title']}</li>\n";
} else {
if( $subLink['local'] && $pageTitle = Title::newFromText( $subLink['link'] ) ) {
$href = $pageTitle->getLocalURL();
} else {
$href = $subLink['link'];
}//end else
$slug = strtolower( str_replace(' ', '-', preg_replace( '/[^a-zA-Z0-9 ]/', '', trim( strip_tags( $subLink['title'] ) ) ) ) );
$output .= "<li {$subLink['attributes']}><a href='{$href}' class='{$subLink['class']} {$slug}'>{$subLink['title']}</a>";
}//end else
}
$output .= '</ul>';
$output .= '</li>';
} else {
if( $pageTitle ) {
$output .= '<li' . ($this->data['title'] == $topItem['title'] ? ' class="active"' : '') . '><a href="' . ( $topItem['external'] ? $topItem['link'] : $pageTitle->getLocalURL() ) . '">' . $topItem['title'] . '</a></li>';
}//end if
}//end else
}//end foreach
return $output;
}//end nav
/**
* Render one or more navigations elements by name, automatically reveresed
* when UI is in RTL mode
*/
private function nav_select( $nav ) {
$output = '';
foreach ( $nav as $topItem ) {
$pageTitle = Title::newFromText( $topItem['link'] ?: $topItem['title'] );
$output .= '<optgroup label="'.strip_tags( $topItem['title'] ).'">';
if ( array_key_exists( 'sublinks', $topItem ) ) {
foreach ( $topItem['sublinks'] as $subLink ) {
if ( 'divider' == $subLink ) {
$output .= "<option value='' disabled='disabled' class='unclickable'>----</option>\n";
} elseif ( $subLink['textonly'] ) {
$output .= "<option value='' disabled='disabled' class='unclickable'>{$subLink['title']}</option>\n";
} else {
if( $subLink['local'] && $pageTitle = Title::newFromText( $subLink['link'] ) ) {
$href = $pageTitle->getLocalURL();
} else {
$href = $subLink['link'];
}//end else
$output .= "<option value='{$href}'>{$subLink['title']}</option>";
}//end else
}//end foreach
} elseif ( $pageTitle ) {
$output .= '<option value="' . $pageTitle->getLocalURL() . '">' . $topItem['title'] . '</option>';
}//end else
$output .= '</optgroup>';
}//end foreach
return $output;
}//end nav_select
private function get_page_links( $source ) {
$titleBar = $this->getPageRawText( $source );
$nav = array();
foreach(explode("\n", $titleBar) as $line) {
if(trim($line) == '') continue;
if( preg_match('/^\*\*\s*divider/', $line ) ) {
$nav[ count( $nav ) - 1]['sublinks'][] = 'divider';
continue;
}//end if
$sub = false;
$link = false;
$external = false;
if(preg_match('/^\*\s*([^\*]*)\[\[:?(.+)\]\]/', $line, $match)) {
$sub = false;
$link = true;
}elseif(preg_match('/^\*\s*([^\*\[]*)\[([^\[ ]+) (.+)\]/', $line, $match)) {
$sub = false;
$link = true;
$external = true;
}elseif(preg_match('/^\*\*\s*([^\*\[]*)\[([^\[ ]+) (.+)\]/', $line, $match)) {
$sub = true;
$link = true;
$external = true;
}elseif(preg_match('/\*\*\s*([^\*]*)\[\[:?(.+)\]\]/', $line, $match)) {
$sub = true;
$link = true;
}elseif(preg_match('/\*\*\s*([^\* ]*)(.+)/', $line, $match)) {
$sub = true;
$link = false;
}elseif(preg_match('/^\*\s*(.+)/', $line, $match)) {
$sub = false;
$link = false;
}
if( strpos( $match[2], '|' ) !== false ) {
$item = explode( '|', $match[2] );
$item = array(
'title' => $match[1] . $item[1],
'link' => $item[0],
'local' => true,
);
} else {
if( $external ) {
$item = $match[2];
$title = $match[1] . $match[3];
} else {
$item = $match[1] . $match[2];
$title = $item;
}//end else
if( $link ) {
$item = array('title'=> $title, 'link' => $item, 'local' => ! $external , 'external' => $external );
} else {
$item = array('title'=> $title, 'link' => $item, 'textonly' => true, 'external' => $external );
}//end else
}//end else
if( $sub ) {
$nav[count( $nav ) - 1]['sublinks'][] = $item;
} else {
$nav[] = $item;
}//end else
}
return $nav;
}//end get_page_links
private function get_array_links( $array, $title, $which ) {
$nav = array();
$nav[] = array('title' => $title );
foreach( $array as $key => $item ) {
$link = array(
'id' => Sanitizer::escapeId( $key ),
'attributes' => $item['attributes'],
'link' => htmlspecialchars( $item['href'] ),
'key' => $item['key'],
'class' => htmlspecialchars( $item['class'] ),
'title' => htmlspecialchars( $item['text'] ),
);
if( 'page' == $which ) {
switch( $link['title'] ) {
case 'Page': $icon = 'file'; break;
case 'Discussion': $icon = 'comment'; break;
case 'Edit': $icon = 'pencil'; break;
case 'History': $icon = 'clock-o'; break;
case 'Delete': $icon = 'remove'; break;
case 'Move': $icon = 'arrows'; break;
case 'Protect': $icon = 'lock'; break;
case 'Watch': $icon = 'eye-open'; break;
case 'Unwatch': $icon = 'eye-slash'; break;
}//end switch
$link['title'] = '<i class="fa fa-' . $icon . '"></i> ' . $link['title'];
} elseif( 'user' == $which ) {
switch( $link['title'] ) {
case 'My talk': $icon = 'comment'; break;
case 'My preferences': $icon = 'cog'; break;
case 'My watchlist': $icon = 'eye-close'; break;
case 'My contributions': $icon = 'list-alt'; break;
case 'Log out': $icon = 'off'; break;
default: $icon = 'user'; break;
}//end switch
$link['title'] = '<i class="fa fa-' . $icon . '"></i> ' . $link['title'];
}//end elseif
$nav[0]['sublinks'][] = $link;
}//end foreach
return $this->nav( $nav );
}//end get_array_links
function getPageRawText($title) {
global $wgParser, $wgUser;
$pageTitle = Title::newFromText($title);
if(!$pageTitle->exists()) {
return 'Create the page [[Bootstrap:TitleBar]]';
} else {
$article = new Article($pageTitle);
$wgParserOptions = new ParserOptions($wgUser);
// get the text as static wiki text, but with already expanded templates,
// which also e.g. to use {{#dpl}} (DPL third party extension) for dynamic menus.
$parserOutput = $wgParser->preprocess($article->getRawText(), $pageTitle, $wgParserOptions );
return $parserOutput;
}
}
function includePage($title) {
global $wgParser, $wgUser;
$pageTitle = Title::newFromText($title);
if(!$pageTitle->exists()) {
echo 'The page [[' . $title . ']] was not found.';
} else {
$article = new Article($pageTitle);
$wgParserOptions = new ParserOptions($wgUser);
$parserOutput = $wgParser->parse($article->getRawText(), $pageTitle, $wgParserOptions);
echo $parserOutput->getText();
}
}
public static function link() { }
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
bootstrap-mediawiki /BootstrapMediaWiki.skin.php