2019-08-15 17:40:13 +00:00
|
|
|
<?php
|
2019-12-25 23:20:04 +00:00
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
/**
|
|
|
|
* BaseTemplate class for the Citizen skin
|
2019-12-25 23:20:04 +00:00
|
|
|
* TODO: Add missing title to buttons
|
2019-08-15 17:40:13 +00:00
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
|
|
|
class CitizenTemplate extends BaseTemplate {
|
|
|
|
/**
|
|
|
|
* Outputs the entire contents of the page
|
|
|
|
*/
|
|
|
|
public function execute() {
|
2019-12-25 23:20:04 +00:00
|
|
|
$html = $this->get( 'headelement' );
|
|
|
|
$loggedInClass = 'not-logged';
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
// Add class if logged in
|
|
|
|
if ( $this->getSkin()->getUser()->isLoggedIn() ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
$loggedInClass = 'logged-in';
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => $loggedInClass, 'id' => 'mw-wrapper' ],
|
|
|
|
$this->getHeader() .
|
|
|
|
$this->getMainBody() .
|
|
|
|
$this->getFooterBlock() .
|
|
|
|
$this->getSideTitle() .
|
|
|
|
$this->getBottomBar()
|
2019-08-15 17:40:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$html .= $this->getTrail();
|
|
|
|
$html .= Html::closeElement( 'body' );
|
|
|
|
$html .= Html::closeElement( 'html' );
|
|
|
|
|
|
|
|
echo $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-25 23:20:04 +00:00
|
|
|
* The header containing the mobile site navigation and user icons + search
|
|
|
|
*
|
|
|
|
* @return string Header
|
2019-08-15 17:40:13 +00:00
|
|
|
*/
|
2019-12-25 23:20:04 +00:00
|
|
|
protected function getHeader() {
|
|
|
|
$header =
|
|
|
|
Html::openElement( 'header',
|
|
|
|
[ 'class' => 'mw-header-container', 'id' => 'mw-navigation' ] );
|
|
|
|
|
|
|
|
// Site navigation menu
|
|
|
|
$navigation =
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-header-icons' ],
|
|
|
|
$this->getHamburgerMenu()
|
|
|
|
);
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
// User icons and Search bar
|
|
|
|
$userIconsSearchBar =
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-header-icons' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-header', 'id' => 'user-icons' ],
|
|
|
|
$this->getUserIcons()
|
|
|
|
) .
|
|
|
|
$this->getSearchToggle()
|
|
|
|
);
|
2019-12-20 20:38:26 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $header . $navigation . $userIconsSearchBar . Html::closeElement( 'header' );
|
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
/**
|
|
|
|
* The main body holding all content
|
|
|
|
*
|
|
|
|
* @return string Main Body
|
|
|
|
*/
|
|
|
|
protected function getMainBody() {
|
|
|
|
return Html::rawElement(
|
|
|
|
'main',
|
|
|
|
[ 'class' => 'mw-body', 'id' => 'content', 'role' => 'main' ],
|
|
|
|
// Container for compatibility with extensions
|
|
|
|
Html::rawElement(
|
|
|
|
'section',
|
|
|
|
[ 'id' => 'mw-body-container' ],
|
|
|
|
$this->getSiteNotice() .
|
|
|
|
$this->getNewTalk() .
|
|
|
|
$this->getIndicators() .
|
|
|
|
$this->getPageTools() .
|
|
|
|
Html::rawElement(
|
|
|
|
'h1',
|
|
|
|
[ 'class' => 'firstHeading', 'lang' => $this->get( 'pageLanguage' ) ],
|
|
|
|
$this->get( 'title' )
|
|
|
|
) .
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'siteSub' ],
|
|
|
|
$this->getMsg( 'tagline' )->parse()
|
|
|
|
) .
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-body-content' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'contentSub' ],
|
|
|
|
$this->getPageSubtitle() .
|
|
|
|
Html::rawElement(
|
|
|
|
'p',
|
|
|
|
[],
|
|
|
|
$this->get( 'undelete' )
|
|
|
|
)
|
|
|
|
) .
|
|
|
|
$this->get( 'bodycontent' ) .
|
|
|
|
$this->getClear() .
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'printfooter' ],
|
|
|
|
$this->get( 'printfooter' )
|
|
|
|
) .
|
|
|
|
$this->getPageLinks() .
|
|
|
|
$this->getCategoryLinks()
|
|
|
|
) .
|
|
|
|
$this->getDataAfterContent() .
|
|
|
|
$this->get( 'debughtml' )
|
2019-08-15 17:40:13 +00:00
|
|
|
)
|
|
|
|
);
|
2019-12-25 23:20:04 +00:00
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
/**
|
|
|
|
* The rotated site title
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getSideTitle() {
|
|
|
|
return Html::rawElement(
|
|
|
|
'div',
|
2020-01-06 23:36:56 +00:00
|
|
|
[ 'class' => 'mw-sidebar-sitename', 'role' => 'banner' ],
|
2019-12-25 23:20:04 +00:00
|
|
|
$this->getSiteTitle( 'link' )
|
|
|
|
);
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-25 23:20:04 +00:00
|
|
|
* Generates the bottom bar
|
2019-08-15 17:40:13 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
2019-12-25 23:20:04 +00:00
|
|
|
protected function getBottomBar() {
|
|
|
|
try {
|
|
|
|
$buttonEnabled = $this->config->get( 'CitizenEnableButton' );
|
|
|
|
$buttonLink = $this->config->get( 'CitizenButtonLink' );
|
|
|
|
$buttonTitle = $this->config->get( 'CitizenButtonTitle' );
|
|
|
|
$buttonText = $this->config->get( 'CitizenButtonText' );
|
|
|
|
} catch ( ConfigException $e ) {
|
|
|
|
return '';
|
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
if ( $buttonEnabled === false ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'mw-bottombar' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'mw-bottombar-buttons' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'citizen-ui-icon', 'id' => 'citizen-ui-button' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'a',
|
|
|
|
[
|
|
|
|
'href' => $buttonLink,
|
|
|
|
'title' => $buttonTitle,
|
|
|
|
'rel' => 'noopener noreferrer',
|
|
|
|
'target' => '_blank',
|
|
|
|
],
|
|
|
|
$buttonText
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
/**
|
|
|
|
* Generates the search button
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getSearchToggle() {
|
|
|
|
return Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-header-end', 'id' => 'site-search' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'input',
|
|
|
|
[
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'role' => 'button',
|
|
|
|
'title' => 'Toggle Search',
|
|
|
|
'id' => 'search-toggle',
|
|
|
|
]
|
|
|
|
) .
|
2019-08-15 17:40:13 +00:00
|
|
|
// Search button
|
2019-12-25 23:20:04 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'search-toggle-icon-container' ],
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[ 'id' => 'search-toggle-icon' ]
|
|
|
|
)
|
2019-08-15 17:40:13 +00:00
|
|
|
) .
|
|
|
|
// Search form
|
|
|
|
$this->getSearch()
|
|
|
|
);
|
2019-12-25 23:20:04 +00:00
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the hamburger menu
|
|
|
|
* @return string html
|
|
|
|
*/
|
2019-12-25 23:20:04 +00:00
|
|
|
protected function getHamburgerMenu() {
|
|
|
|
$html = Html::openElement(
|
|
|
|
'div',
|
2020-01-06 23:42:52 +00:00
|
|
|
[ 'class' => 'mw-header-end mw-header-menu' ]
|
2019-12-25 23:20:04 +00:00
|
|
|
);
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::rawElement(
|
|
|
|
'input',
|
|
|
|
[ 'type' => 'checkbox', 'role' => 'button', 'title' => 'Toggle Menu' ]
|
|
|
|
);
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
// Actual hamburger
|
2020-01-06 23:42:52 +00:00
|
|
|
$html .= Html::openElement( 'div', [ 'class' => 'mw-header-menu-toggle' ] );
|
2019-12-25 23:20:04 +00:00
|
|
|
|
|
|
|
for ( $i = 1; $i <= 3; $i++ ) {
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= Html::rawElement( 'span' );
|
|
|
|
}
|
|
|
|
$html .= Html::closeElement( 'div' );
|
2019-12-25 23:20:04 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
// Get sidebar links
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::rawElement(
|
|
|
|
'div',
|
2020-01-06 23:36:56 +00:00
|
|
|
[ 'class' => 'mw-header-menu-drawer' ],
|
2019-12-25 23:20:04 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
2020-01-06 23:36:56 +00:00
|
|
|
[ 'class' => 'mw-header-menu-drawer-container' ],
|
2020-01-06 23:10:28 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
2020-01-06 23:36:56 +00:00
|
|
|
[ 'class' => 'mw-header-banner', 'role' => 'banner' ],
|
2020-01-06 23:22:17 +00:00
|
|
|
$this->getLogo() .
|
2020-01-06 23:10:28 +00:00
|
|
|
$this->getSiteTitle( 'text' )
|
|
|
|
) .
|
2019-08-15 17:40:13 +00:00
|
|
|
// Container for navigation and tools
|
2019-12-25 23:20:04 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
2020-01-06 23:56:04 +00:00
|
|
|
[ 'class' => 'mw-nav-links' ],
|
2019-08-15 17:40:13 +00:00
|
|
|
$this->getSiteNavigation()
|
|
|
|
) .
|
|
|
|
$this->getUserLinks()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . Html::closeElement( 'div' );
|
|
|
|
}
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the sitetitle
|
2019-12-25 23:20:04 +00:00
|
|
|
* @param string $option
|
2019-08-15 17:40:13 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getSiteTitle( $option ) {
|
|
|
|
$html = '';
|
|
|
|
$language = $this->getSkin()->getLanguage();
|
|
|
|
$siteTitle = $language->convert( $this->getMsg( 'sitetitle' )->escaped() );
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
if ( $option === 'link' ) {
|
|
|
|
$html .= Html::rawElement(
|
|
|
|
'a',
|
|
|
|
[
|
|
|
|
'id' => 'p-banner',
|
|
|
|
'class' => 'mw-wiki-title',
|
|
|
|
'href' => $this->data['nav_urls']['mainpage']['href'],
|
|
|
|
] + Linker::tooltipAndAccesskeyAttribs( 'p-logo' ),
|
|
|
|
$siteTitle
|
|
|
|
);
|
|
|
|
} elseif ( $option === 'text' ) {
|
|
|
|
$html .= Html::rawElement(
|
|
|
|
'span',
|
|
|
|
[
|
|
|
|
'id' => 'p-banner',
|
|
|
|
'class' => 'mw-wiki-title',
|
|
|
|
],
|
|
|
|
$siteTitle
|
|
|
|
);
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the description for footer
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getFooterDesc() {
|
|
|
|
$html = '';
|
|
|
|
$language = $this->getSkin()->getLanguage();
|
|
|
|
$siteDesc = $language->convert( $this->getMsg( 'citizen-footer-desc' )->escaped() );
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . Html::rawElement( 'span', [
|
|
|
|
'id' => 'mw-footer-desc',
|
|
|
|
], $siteDesc );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the tagline for footer
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getFooterTagline() {
|
|
|
|
$html = '';
|
|
|
|
$language = $this->getSkin()->getLanguage();
|
|
|
|
$siteTagline = $language->convert( $this->getMsg( 'citizen-footer-tagline' )->escaped() );
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . Html::rawElement( 'span', [
|
|
|
|
'id' => 'mw-footer-tagline',
|
|
|
|
], $siteTagline );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the logo
|
|
|
|
* @return string html
|
|
|
|
*/
|
2020-01-06 23:44:24 +00:00
|
|
|
protected function getLogo() {
|
2020-01-06 23:44:41 +00:00
|
|
|
$html = Html::rawElement( 'a', [
|
2019-08-15 17:40:13 +00:00
|
|
|
'href' => $this->data['nav_urls']['mainpage']['href'],
|
2020-01-06 23:32:44 +00:00
|
|
|
'id' => 'p-logo',
|
2019-08-15 17:40:13 +00:00
|
|
|
'class' => 'mw-wiki-logo',
|
2020-01-07 02:15:24 +00:00
|
|
|
] + Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) );
|
2020-01-06 23:45:35 +00:00
|
|
|
return $html;
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the search form
|
2019-12-11 22:14:36 +00:00
|
|
|
* In order to use the old opensearch, change search-input to searchInput
|
|
|
|
* See T219590 for more details
|
2019-08-15 17:40:13 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getSearch() {
|
2019-12-25 23:20:04 +00:00
|
|
|
$html = Html::openElement( 'form', [
|
|
|
|
'action' => $this->get( 'wgScript' ),
|
|
|
|
'role' => 'search',
|
|
|
|
'id' => 'search-form',
|
|
|
|
] );
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= Html::hidden( 'title', $this->get( 'searchtitle' ) );
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::label( $this->getMsg( 'search' )->text(), 'search-input',
|
|
|
|
[ 'class' => 'screen-reader-text' ] );
|
2019-12-11 21:47:07 +00:00
|
|
|
$html .= $this->makeSearchInput( [ 'id' => 'search-input', 'type' => 'search' ] );
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= $this->makeSearchButton( 'image', [
|
|
|
|
'id' => 'search-button',
|
|
|
|
'src' => $this->getSkin()->getSkinStylePath( 'resources/images/icons/search.svg' ),
|
|
|
|
] );
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . Html::closeElement( 'form' );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the sidebar
|
|
|
|
* Set the elements to true to allow them to be part of the sidebar
|
|
|
|
* Or get rid of this entirely, and take the specific bits to use wherever you actually want them
|
|
|
|
* * Toolbox is the page/site tools that appears under the sidebar in vector
|
|
|
|
* * Languages is the interlanguage links on the page via en:... es:... etc
|
2019-12-25 23:20:04 +00:00
|
|
|
* * Default is each user-specified box as defined on MediaWiki:Sidebar;
|
|
|
|
* you will still need a foreach loop to parse these.
|
2019-08-15 17:40:13 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getSiteNavigation() {
|
|
|
|
$html = '';
|
|
|
|
|
|
|
|
$sidebar = $this->getSidebar();
|
|
|
|
$sidebar['SEARCH'] = false;
|
|
|
|
$sidebar['TOOLBOX'] = true;
|
|
|
|
$sidebar['LANGUAGES'] = false;
|
|
|
|
|
|
|
|
foreach ( $sidebar as $name => $content ) {
|
|
|
|
if ( $content === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Numeric strings gets an integer when set as key, cast back - T73639
|
|
|
|
$name = (string)$name;
|
|
|
|
|
|
|
|
switch ( $name ) {
|
|
|
|
case 'SEARCH':
|
|
|
|
$html .= $this->getSearch();
|
|
|
|
break;
|
|
|
|
case 'TOOLBOX':
|
|
|
|
$html .= $this->getPortlet( 'tb', $this->getToolbox(), 'toolbox' );
|
|
|
|
break;
|
|
|
|
case 'LANGUAGES':
|
|
|
|
$html .= $this->getLanguageLinks();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$html .= $this->getPortlet( $name, $content['content'] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
return $html;
|
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
/**
|
|
|
|
* Generates user icon bar
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getUserIcons() {
|
|
|
|
$personalTools = $this->getPersonalTools();
|
|
|
|
$html = '';
|
|
|
|
|
|
|
|
// Create the Echo badges and ULS
|
|
|
|
$extraTools = [];
|
|
|
|
if ( isset( $personalTools['notifications-alert'] ) ) {
|
|
|
|
$extraTools['notifications-alert'] = $personalTools['notifications-alert'];
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['notifications-notice'] ) ) {
|
|
|
|
$extraTools['notifications-notice'] = $personalTools['notifications-notice'];
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['uls'] ) ) {
|
|
|
|
$extraTools['uls'] = $personalTools['uls'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place the extra icons/outside stuff
|
|
|
|
if ( !empty( $extraTools ) ) {
|
|
|
|
$iconList = '';
|
|
|
|
foreach ( $extraTools as $key => $item ) {
|
|
|
|
$iconList .= $this->makeListItem( $key, $item );
|
|
|
|
}
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::rawElement( 'div', [ 'id' => 'p-personal-extra', 'class' => 'p-body' ],
|
|
|
|
Html::rawElement( 'ul', [], $iconList ) );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates user tools menu
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getUserLinks() {
|
|
|
|
$personalTools = $this->getPersonalTools();
|
|
|
|
|
|
|
|
$html = '';
|
|
|
|
|
|
|
|
// Move the Echo badges and ULS out of default list
|
|
|
|
if ( isset( $personalTools['notifications-alert'] ) ) {
|
|
|
|
unset( $personalTools['notifications-alert'] );
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['notifications-notice'] ) ) {
|
|
|
|
unset( $personalTools['notifications-notice'] );
|
|
|
|
}
|
|
|
|
if ( isset( $personalTools['uls'] ) ) {
|
|
|
|
unset( $personalTools['uls'] );
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:36:56 +00:00
|
|
|
$html .= Html::openElement( 'div', [ 'class' => 'mw-user-links' ] );
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= $this->getPortlet( 'personal', $personalTools, 'personaltools' );
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . Html::closeElement( 'div' );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In other languages list
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getLanguageLinks() {
|
|
|
|
$html = '';
|
|
|
|
if ( $this->data['language_urls'] !== false ) {
|
|
|
|
$html .= $this->getPortlet( 'lang', $this->data['language_urls'], 'otherlanguages' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Language variants. Displays list for converting between different scripts in the same language,
|
|
|
|
* if using a language where this is applicable (such as latin vs cyric display for serbian).
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getVariants() {
|
|
|
|
$html = '';
|
|
|
|
if ( count( $this->data['content_navigation']['variants'] ) > 0 ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= $this->getPortlet( 'variants', $this->data['content_navigation']['variants'] );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates page-related tools
|
2019-12-25 23:20:04 +00:00
|
|
|
* Possible visibility conditions:
|
|
|
|
* * true: always visible (bool)
|
|
|
|
* * false: never visible (bool)
|
|
|
|
* * 'login': only visible if logged in (string)
|
|
|
|
* * 'permission-*': only visible if user has permission
|
|
|
|
* e.g. permission-edit = only visible if user can edit pages
|
2019-08-15 17:40:13 +00:00
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getPageTools() {
|
|
|
|
$html = '';
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
try {
|
|
|
|
$condition = $this->config->get( 'CitizenShowPageTools' );
|
|
|
|
} catch ( ConfigException $e ) {
|
|
|
|
$condition = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $condition === 'login' ) {
|
|
|
|
$condition = $this->getSkin()->getUser()->isLoggedIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_string( $condition ) && strpos( $condition, 'permission' ) === 0 ) {
|
|
|
|
$permission = substr( $condition, 11 );
|
|
|
|
try {
|
|
|
|
$condition = MediaWikiServices::getInstance()->getPermissionManager()->userCan(
|
|
|
|
$permission, $this->getSkin()->getUser(), $this->getSkin()->getTitle() );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
$condition = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only display if user is logged in
|
|
|
|
if ( $condition === true ) {
|
|
|
|
$html .= Html::openElement( 'div', [ 'class' => 'mw-side', 'id' => 'page-tools' ] );
|
2019-08-15 17:40:13 +00:00
|
|
|
// 'View' actions for the page: view, edit, view history, etc
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= $this->getPortlet( 'views', $this->data['content_navigation']['views'] );
|
2019-08-15 17:40:13 +00:00
|
|
|
// Other actions for the page: move, delete, protect, everything else
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= $this->getPortlet( 'actions', $this->data['content_navigation']['actions'] );
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= Html::closeElement( 'div' );
|
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates page-related links at the bottom
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getPageLinks() {
|
2019-12-25 23:20:04 +00:00
|
|
|
// Namespaces: links for 'content' and 'talk' for namespaces with talkpages.
|
|
|
|
// Otherwise is just the content.
|
2019-08-15 17:40:13 +00:00
|
|
|
// Usually rendered as tabs on the top of the page.
|
2019-12-25 23:20:04 +00:00
|
|
|
$html = $this->getPortlet( 'namespaces', $this->data['content_navigation']['namespaces'] );
|
|
|
|
|
2019-08-15 17:40:13 +00:00
|
|
|
// Language variant options
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . $this->getVariants();
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates siteNotice, if any
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getSiteNotice() {
|
|
|
|
return $this->getIfExists( 'sitenotice', [
|
|
|
|
'wrapper' => 'div',
|
2019-12-25 23:20:04 +00:00
|
|
|
'parameters' => [ 'id' => 'siteNotice' ],
|
2019-08-15 17:40:13 +00:00
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates new talk message banner, if any
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getNewTalk() {
|
|
|
|
return $this->getIfExists( 'newtalk', [
|
|
|
|
'wrapper' => 'div',
|
2019-12-25 23:20:04 +00:00
|
|
|
'parameters' => [ 'class' => 'usermessage' ],
|
2019-08-15 17:40:13 +00:00
|
|
|
] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates subtitle stuff, if any
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getPageSubtitle() {
|
|
|
|
return $this->getIfExists( 'subtitle', [ 'wrapper' => 'p' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates category links, if any
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getCategoryLinks() {
|
|
|
|
return $this->getIfExists( 'catlinks' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates data after content stuff, if any
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getDataAfterContent() {
|
|
|
|
return $this->getIfExists( 'dataAfterContent' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple wrapper for random if-statement-wrapped $this->data things
|
|
|
|
*
|
|
|
|
* @param string $object name of thing
|
|
|
|
* @param array $setOptions
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getIfExists( $object, $setOptions = [] ) {
|
|
|
|
$options = $setOptions + [
|
2019-12-25 23:20:04 +00:00
|
|
|
'wrapper' => 'none',
|
|
|
|
'parameters' => [],
|
|
|
|
];
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
$html = '';
|
|
|
|
|
|
|
|
if ( $this->data[$object] ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
if ( $options['wrapper'] === 'none' ) {
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= $this->get( $object );
|
|
|
|
} else {
|
2019-12-25 23:20:04 +00:00
|
|
|
$html .= Html::rawElement( $options['wrapper'], $options['parameters'],
|
|
|
|
$this->get( $object ) );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a block of navigation links with a header
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param array|string $content array of links for use with makeListItem, or a block of text
|
|
|
|
* @param null|string|array $msg
|
|
|
|
* @param array $setOptions random crap to rename/do/whatever
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getPortlet( $name, $content, $msg = null, $setOptions = [] ) {
|
|
|
|
// random stuff to override with any provided options
|
|
|
|
$options = $setOptions + [
|
2019-12-25 23:20:04 +00:00
|
|
|
// extra classes/ids
|
|
|
|
'id' => 'p-' . $name,
|
|
|
|
'class' => 'mw-portlet',
|
|
|
|
'extra-classes' => '',
|
|
|
|
// what to wrap the body list in, if anything
|
|
|
|
'body-wrapper' => 'nav',
|
|
|
|
'body-id' => null,
|
|
|
|
'body-class' => 'mw-portlet-body',
|
|
|
|
// makeListItem options
|
|
|
|
'list-item' => [ 'text-wrapper' => [ 'tag' => 'span' ] ],
|
|
|
|
// option to stick arbitrary stuff at the beginning of the ul
|
|
|
|
'list-prepend' => '',
|
|
|
|
// old toolbox hook support (use: [ 'SkinTemplateToolboxEnd' => [ &$skin, true ] ])
|
|
|
|
'hooks' => '',
|
|
|
|
];
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
// Handle the different $msg possibilities
|
|
|
|
if ( $msg === null ) {
|
|
|
|
$msg = $name;
|
|
|
|
} elseif ( is_array( $msg ) ) {
|
|
|
|
$msgString = array_shift( $msg );
|
|
|
|
$msgParams = $msg;
|
|
|
|
$msg = $msgString;
|
|
|
|
}
|
|
|
|
$msgObj = $this->getMsg( $msg );
|
|
|
|
if ( $msgObj->exists() ) {
|
|
|
|
if ( isset( $msgParams ) && !empty( $msgParams ) ) {
|
|
|
|
$msgString = $this->getMsg( $msg, $msgParams )->parse();
|
|
|
|
} else {
|
|
|
|
$msgString = $msgObj->parse();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msgString = htmlspecialchars( $msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
$labelId = Sanitizer::escapeIdForAttribute( "p-$name-label" );
|
|
|
|
|
|
|
|
if ( is_array( $content ) ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
$contentText =
|
|
|
|
Html::openElement( 'ul',
|
|
|
|
[ 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ] );
|
2019-08-15 17:40:13 +00:00
|
|
|
$contentText .= $options['list-prepend'];
|
|
|
|
foreach ( $content as $key => $item ) {
|
|
|
|
$contentText .= $this->makeListItem( $key, $item, $options['list-item'] );
|
|
|
|
}
|
|
|
|
// Compatibility with extensions still using SkinTemplateToolboxEnd or similar
|
|
|
|
if ( is_array( $options['hooks'] ) ) {
|
|
|
|
foreach ( $options['hooks'] as $hook ) {
|
|
|
|
if ( is_string( $hook ) ) {
|
|
|
|
$hookOptions = [];
|
|
|
|
} else {
|
|
|
|
// it should only be an array otherwise
|
|
|
|
$hookOptions = array_values( $hook )[0];
|
|
|
|
$hook = array_keys( $hook )[0];
|
|
|
|
}
|
|
|
|
$contentText .= $this->deprecatedHookHack( $hook, $hookOptions );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$contentText .= Html::closeElement( 'ul' );
|
|
|
|
} else {
|
|
|
|
$contentText = $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special handling for role=search and other weird things
|
|
|
|
$divOptions = [
|
|
|
|
'role' => 'navigation',
|
|
|
|
'id' => Sanitizer::escapeIdForAttribute( $options['id'] ),
|
|
|
|
'title' => Linker::titleAttrib( $options['id'] ),
|
2019-12-25 23:20:04 +00:00
|
|
|
'aria-labelledby' => $labelId,
|
2019-08-15 17:40:13 +00:00
|
|
|
];
|
|
|
|
if ( !is_array( $options['class'] ) ) {
|
|
|
|
$class = [ $options['class'] ];
|
|
|
|
}
|
|
|
|
if ( !is_array( $options['extra-classes'] ) ) {
|
|
|
|
$extraClasses = [ $options['extra-classes'] ];
|
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
$divOptions['class'] =
|
|
|
|
array_merge( $class ?? $options['class'], $extraClasses ?? $options['extra-classes'] );
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
$labelOptions = [
|
|
|
|
'id' => $labelId,
|
|
|
|
'lang' => $this->get( 'userlang' ),
|
2019-12-25 23:20:04 +00:00
|
|
|
'dir' => $this->get( 'dir' ),
|
2019-08-15 17:40:13 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if ( $options['body-wrapper'] !== 'none' ) {
|
|
|
|
$bodyDivOptions = [ 'class' => $options['body-class'] ];
|
|
|
|
if ( is_string( $options['body-id'] ) ) {
|
|
|
|
$bodyDivOptions['id'] = $options['body-id'];
|
|
|
|
}
|
2019-12-25 23:20:04 +00:00
|
|
|
$body =
|
|
|
|
Html::rawElement( $options['body-wrapper'], $bodyDivOptions,
|
|
|
|
$contentText . $this->getAfterPortlet( $name ) );
|
2019-08-15 17:40:13 +00:00
|
|
|
} else {
|
|
|
|
$body = $contentText . $this->getAfterPortlet( $name );
|
|
|
|
}
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return Html::rawElement( 'div', $divOptions,
|
|
|
|
Html::rawElement( 'h3', $labelOptions, $msgString ) . $body );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to catch output of old hooks expecting to write directly to page
|
|
|
|
* We no longer do things that way.
|
|
|
|
*
|
|
|
|
* @param string $hook event
|
|
|
|
* @param array $hookOptions args
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function deprecatedHookHack( $hook, $hookOptions = [] ) {
|
|
|
|
ob_start();
|
2019-12-25 23:20:04 +00:00
|
|
|
try {
|
|
|
|
Hooks::run( $hook, $hookOptions );
|
|
|
|
} catch ( Exception $e ) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
$hookContents = ob_get_clean();
|
2019-08-15 17:40:13 +00:00
|
|
|
if ( !trim( $hookContents ) ) {
|
|
|
|
$hookContents = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hookContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Better renderer for getFooterIcons and getFooterLinks, based on Vector
|
|
|
|
*
|
|
|
|
* @param array $setOptions Miscellaneous other options
|
|
|
|
* * 'id' for footer id
|
|
|
|
* * 'order' to determine whether icons or links appear first: 'iconsfirst' or links, though in
|
|
|
|
* practice we currently only check if it is or isn't 'iconsfirst'
|
|
|
|
* * 'link-prefix' to set the prefix for all link and block ids; most skins use 'f' or 'footer',
|
|
|
|
* as in id='f-whatever' vs id='footer-whatever'
|
|
|
|
* * 'icon-style' to pass to getFooterIcons: "icononly", "nocopyright"
|
|
|
|
* nested array
|
|
|
|
*
|
|
|
|
* @return string html
|
|
|
|
*/
|
|
|
|
protected function getFooterBlock( $setOptions = [] ) {
|
|
|
|
// Set options and fill in defaults
|
|
|
|
$options = $setOptions + [
|
2019-12-25 23:20:04 +00:00
|
|
|
'id' => 'footer',
|
|
|
|
'order' => 'linksfirst',
|
|
|
|
'link-prefix' => 'footer',
|
|
|
|
'icon-style' => 'icononly',
|
|
|
|
];
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
$validFooterIcons = $this->getFooterIcons( $options['icon-style'] );
|
2020-01-06 22:56:43 +00:00
|
|
|
$validFooterLinks = $this->getFooterLinks();
|
2019-08-15 17:40:13 +00:00
|
|
|
$html = '';
|
|
|
|
|
|
|
|
$html .= Html::openElement( 'footer', [
|
|
|
|
'id' => $options['id'],
|
|
|
|
'role' => 'contentinfo',
|
|
|
|
'lang' => $this->get( 'userlang' ),
|
2019-12-25 23:20:04 +00:00
|
|
|
'dir' => $this->get( 'dir' ),
|
2019-08-15 17:40:13 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
$iconsHTML = '';
|
|
|
|
if ( count( $validFooterIcons ) > 0 ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
$iconsHTML .= Html::openElement( 'div',
|
|
|
|
[ 'id' => "{$options['link-prefix']}-container-icons" ] );
|
|
|
|
$iconsHTML .= Html::openElement( 'div', [ 'id' => 'footer-bottom-container' ] );
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
// Get tagline
|
2019-12-25 23:20:04 +00:00
|
|
|
$iconsHTML .= $this->getFooterTagline();
|
2019-08-15 17:40:13 +00:00
|
|
|
|
|
|
|
$iconsHTML .= Html::openElement( 'ul', [ 'id' => "{$options['link-prefix']}-icons" ] );
|
|
|
|
foreach ( $validFooterIcons as $blockName => $footerIcons ) {
|
|
|
|
$iconsHTML .= Html::openElement( 'li', [
|
2019-12-25 23:20:04 +00:00
|
|
|
'id' => Sanitizer::escapeIdForAttribute( "{$options['link-prefix']}-{$blockName}ico" ),
|
|
|
|
'class' => 'footer-icons',
|
2019-08-15 17:40:13 +00:00
|
|
|
] );
|
|
|
|
foreach ( $footerIcons as $icon ) {
|
|
|
|
$iconsHTML .= $this->getSkin()->makeFooterIcon( $icon );
|
|
|
|
}
|
|
|
|
$iconsHTML .= Html::closeElement( 'li' );
|
|
|
|
}
|
|
|
|
$iconsHTML .= Html::closeElement( 'ul' );
|
|
|
|
$iconsHTML .= Html::closeElement( 'div' );
|
|
|
|
$iconsHTML .= Html::closeElement( 'div' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$linksHTML = '';
|
|
|
|
if ( count( $validFooterLinks ) > 0 ) {
|
2019-12-25 23:20:04 +00:00
|
|
|
$linksHTML .= Html::openElement( 'div',
|
|
|
|
[ 'id' => "{$options['link-prefix']}-container-list" ] );
|
2020-01-06 22:56:43 +00:00
|
|
|
$linksHTML .= Html::openElement( 'ul', [
|
|
|
|
'id' => "{$options['link-prefix']}-list",
|
|
|
|
'class' => 'footer-places',
|
|
|
|
] );
|
|
|
|
|
|
|
|
// Site title
|
|
|
|
$linksHTML .= Html::rawElement( 'li', [ 'id' => 'sitetitle' ],
|
|
|
|
$this->getSiteTitle( 'text' ) );
|
|
|
|
// Site description
|
|
|
|
$linksHTML .= Html::rawElement( 'li', [ 'id' => 'sitedesc' ],
|
|
|
|
$this->getFooterDesc() );
|
|
|
|
|
|
|
|
foreach ( $validFooterLinks as $link ) {
|
|
|
|
$linksHTML .= Html::rawElement( 'li',
|
|
|
|
[ 'id' => Sanitizer::escapeIdForAttribute( $link ) ], $this->get( $link ) );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
2020-01-06 22:56:43 +00:00
|
|
|
$linksHTML .= Html::closeElement( 'ul' );
|
2019-08-15 17:40:13 +00:00
|
|
|
$linksHTML .= Html::closeElement( 'div' );
|
|
|
|
}
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
if ( $options['order'] === 'iconsfirst' ) {
|
2019-08-15 17:40:13 +00:00
|
|
|
$html .= $iconsHTML . $linksHTML;
|
|
|
|
} else {
|
|
|
|
$html .= $linksHTML . $iconsHTML;
|
|
|
|
}
|
|
|
|
|
2019-12-25 23:20:04 +00:00
|
|
|
return $html . $this->getClear() . Html::closeElement( 'footer' );
|
2019-08-15 17:40:13 +00:00
|
|
|
}
|
|
|
|
}
|