2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2018-04-15 23:21:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @file
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2018-04-15 23:21:12 +00:00
|
|
|
|
2022-03-04 16:40:54 +00:00
|
|
|
namespace MediaWiki\Minerva\Skins;
|
|
|
|
|
|
|
|
use Action;
|
|
|
|
use ExtensionRegistry;
|
|
|
|
use Hooks as MWHooks;
|
|
|
|
use Html;
|
|
|
|
use Language;
|
2020-03-04 02:53:53 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2017-07-12 15:12:40 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-08-02 09:00:18 +00:00
|
|
|
use MediaWiki\Minerva\Menu\Main\MainMenuDirector;
|
2022-03-04 16:40:54 +00:00
|
|
|
use MediaWiki\Minerva\Menu\PageActions\PageActionsDirector;
|
|
|
|
use MediaWiki\Minerva\Menu\User\UserMenuDirector;
|
2022-02-15 18:40:10 +00:00
|
|
|
use MediaWiki\Minerva\MinervaUI;
|
2019-05-24 00:07:27 +00:00
|
|
|
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
|
2019-04-08 17:08:57 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2022-03-04 16:40:54 +00:00
|
|
|
use MWException;
|
|
|
|
use MWTimestamp;
|
|
|
|
use ParserOptions;
|
|
|
|
use ParserOutput;
|
|
|
|
use RequestContext;
|
|
|
|
use RuntimeException;
|
|
|
|
use SkinMustache;
|
|
|
|
use SkinTemplate;
|
|
|
|
use SpecialMobileHistory;
|
|
|
|
use SpecialPage;
|
|
|
|
use Title;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Minerva: Born from the godhead of Jupiter with weapons!
|
|
|
|
* A skin that works on both desktop and mobile
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
2020-10-02 20:03:14 +00:00
|
|
|
class SkinMinerva extends SkinMustache {
|
2017-08-22 14:12:32 +00:00
|
|
|
/** @const LEAD_SECTION_NUMBER integer which corresponds to the lead section
|
2020-01-26 19:26:31 +00:00
|
|
|
* in editing mode
|
|
|
|
*/
|
2020-05-19 22:43:34 +00:00
|
|
|
public const LEAD_SECTION_NUMBER = 0;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2020-11-05 02:02:15 +00:00
|
|
|
/** @var string Name of this skin */
|
2017-07-12 15:12:40 +00:00
|
|
|
public $skinname = 'minerva';
|
2020-11-05 02:02:15 +00:00
|
|
|
/** @var string Name of this used template */
|
2017-07-12 15:12:40 +00:00
|
|
|
public $template = 'MinervaTemplate';
|
2019-04-10 12:52:34 +00:00
|
|
|
|
2020-01-26 19:26:31 +00:00
|
|
|
/** @var SkinOptions */
|
2019-04-10 21:43:50 +00:00
|
|
|
private $skinOptions;
|
|
|
|
|
2022-01-13 00:38:16 +00:00
|
|
|
/** @var array|null */
|
|
|
|
private $sidebarCachedResult;
|
|
|
|
|
2022-02-04 17:17:01 +00:00
|
|
|
/** @var array|null */
|
|
|
|
private $contentNavigationUrls;
|
|
|
|
|
2019-05-24 00:07:27 +00:00
|
|
|
/**
|
|
|
|
* This variable is lazy loaded, please use getPermissions() getter
|
|
|
|
* @see SkinMinerva::getPermissions()
|
|
|
|
* @var IMinervaPagePermissions
|
|
|
|
*/
|
|
|
|
private $permissions;
|
|
|
|
|
2019-04-10 21:43:50 +00:00
|
|
|
/**
|
2021-09-23 19:47:46 +00:00
|
|
|
* @return SkinOptions
|
|
|
|
*/
|
|
|
|
private function getSkinOptions() {
|
|
|
|
if ( !$this->skinOptions ) {
|
|
|
|
$this->skinOptions = MediaWikiServices::getInstance()->getService( 'Minerva.SkinOptions' );
|
|
|
|
}
|
|
|
|
return $this->skinOptions;
|
2019-04-10 21:43:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 18:16:43 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function hasPageActions() {
|
|
|
|
$title = $this->getTitle();
|
|
|
|
return !$title->isSpecialPage() && !$title->isMainPage() &&
|
|
|
|
Action::getActionName( $this->getContext() ) === 'view';
|
|
|
|
}
|
|
|
|
|
2021-10-20 16:40:25 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function hasSecondaryActions() {
|
|
|
|
return !$this->getUserPageHelper()->isUserPage();
|
|
|
|
}
|
|
|
|
|
2021-10-19 18:16:43 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isFallbackEditor() {
|
|
|
|
$action = $this->getRequest()->getVal( 'action' );
|
|
|
|
return $action === 'edit';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-19 18:49:54 +00:00
|
|
|
* Returns available page actions if the page has any.
|
|
|
|
*
|
2021-11-12 19:51:08 +00:00
|
|
|
* @param array $nav result of SkinTemplate::buildContentNavigationUrls
|
2021-10-19 18:49:54 +00:00
|
|
|
* @return array|null
|
2021-11-12 19:51:08 +00:00
|
|
|
* @throws MWException
|
2021-10-19 18:16:43 +00:00
|
|
|
*/
|
2021-11-12 19:51:08 +00:00
|
|
|
private function getPageActions( array $nav ) {
|
|
|
|
if ( $this->isFallbackEditor() || !$this->hasPageActions() ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$services = MediaWikiServices::getInstance();
|
2022-03-04 16:40:54 +00:00
|
|
|
/** @var PageActionsDirector $pageActionsDirector */
|
2021-11-12 19:51:08 +00:00
|
|
|
$pageActionsDirector = $services->getService( 'Minerva.Menu.PageActionsDirector' );
|
2022-02-08 03:34:37 +00:00
|
|
|
$sidebar = $this->buildSidebar();
|
2021-11-12 19:51:08 +00:00
|
|
|
$actions = $nav['actions'] ?? [];
|
|
|
|
return $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions );
|
2021-10-19 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 17:17:01 +00:00
|
|
|
/**
|
|
|
|
* Caches content navigation urls locally for use inside getTemplateData
|
|
|
|
*
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function runOnSkinTemplateNavigationHooks( SkinTemplate $skin, &$contentNavigationUrls ) {
|
|
|
|
parent::runOnSkinTemplateNavigationHooks( $skin, $contentNavigationUrls );
|
|
|
|
// There are some SkinTemplate modifications that occur after the execution of this hook
|
|
|
|
// to add rel attributes and ID attributes.
|
|
|
|
// The only one Minerva needs is this one so we manually add it.
|
|
|
|
foreach ( array_keys( $contentNavigationUrls['namespaces'] ) as $id ) {
|
|
|
|
if ( in_array( $id, [ 'user_talk', 'talk' ] ) ) {
|
|
|
|
$contentNavigationUrls['namespaces'][ $id ]['rel'] = 'discussion';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->contentNavigationUrls = $contentNavigationUrls;
|
|
|
|
}
|
|
|
|
|
2020-10-02 20:03:14 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-11-12 19:51:08 +00:00
|
|
|
public function getTemplateData(): array {
|
2020-10-02 20:03:14 +00:00
|
|
|
$data = parent::getTemplateData();
|
2021-11-12 19:51:08 +00:00
|
|
|
// FIXME: Can we use $data instead of calling buildContentNavigationUrls ?
|
2022-02-04 17:17:01 +00:00
|
|
|
$nav = $this->contentNavigationUrls;
|
|
|
|
if ( $nav === null ) {
|
|
|
|
throw new RuntimeException( 'contentNavigationUrls was not set as expected.' );
|
|
|
|
}
|
2021-04-28 21:58:51 +00:00
|
|
|
if ( !$this->hasCategoryLinks() ) {
|
|
|
|
unset( $data['html-categories'] );
|
|
|
|
}
|
|
|
|
|
2021-11-05 18:21:09 +00:00
|
|
|
// Special handling for certain pages.
|
|
|
|
// This is technical debt that should be upstreamed to core.
|
|
|
|
$isUserPage = $this->getUserPageHelper()->isUserPage();
|
|
|
|
$isUserPageAccessible = $this->getUserPageHelper()->isUserPageAccessibleToCurrentUser();
|
|
|
|
if ( $isUserPage && $isUserPageAccessible ) {
|
|
|
|
$data['html-title-heading'] = $this->getUserPageHeadingHtml( $data['html-title-heading' ] );
|
|
|
|
}
|
|
|
|
|
2022-02-02 23:19:57 +00:00
|
|
|
$usermessage = $data['html-user-message'] ?? '';
|
|
|
|
if ( $usermessage ) {
|
|
|
|
$data['html-user-message'] = Html::warningBox(
|
|
|
|
'<span class="mw-ui-icon mw-ui-icon-wikimedia-userTalk-warning"></span> '
|
|
|
|
. $usermessage,
|
|
|
|
'minerva-anon-talk-message'
|
|
|
|
);
|
|
|
|
}
|
2021-11-10 23:58:07 +00:00
|
|
|
return $data + [
|
|
|
|
'array-minerva-banners' => $this->prepareBanners( $data['html-site-notice'] ),
|
|
|
|
'html-minerva-user-notifications' => $this->prepareUserNotificationsButton( $this->getNewtalks() ),
|
2022-01-13 00:38:16 +00:00
|
|
|
'data-minerva-main-menu' => $this->getMainMenu()->getMenuData(
|
|
|
|
$nav,
|
2022-02-08 03:34:37 +00:00
|
|
|
$this->buildSidebar()
|
2022-01-13 00:38:16 +00:00
|
|
|
)['items'],
|
2021-11-10 23:58:07 +00:00
|
|
|
'html-minerva-tagline' => $this->getTaglineHtml(),
|
|
|
|
'html-minerva-post-heading' => $this->isTalkPageWithViewAction()
|
|
|
|
? $this->getTalkPagePostHeadingHtml()
|
|
|
|
: '',
|
2022-01-13 00:38:16 +00:00
|
|
|
'html-minerva-user-menu' => $this->getPersonalToolsMenu( $nav['user-menu'] ),
|
2021-11-10 23:58:07 +00:00
|
|
|
'is-minerva-beta' => $this->getSkinOptions()->get( SkinOptions::BETA_MODE ),
|
2021-11-12 19:51:08 +00:00
|
|
|
'data-minerva-tabs' => $this->getTabsData( $nav ),
|
|
|
|
'data-minerva-page-actions' => $this->getPageActions( $nav ),
|
|
|
|
'data-minerva-secondary-actions' => $this->getSecondaryActions( $nav ),
|
2021-10-04 22:03:29 +00:00
|
|
|
'html-minerva-subject-link' => $this->getSubjectPage(),
|
2021-10-29 19:47:02 +00:00
|
|
|
'data-minerva-history-link' => $this->getHistoryLink( $this->getTitle() ),
|
2021-10-04 22:03:29 +00:00
|
|
|
];
|
2020-10-02 20:03:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 18:16:43 +00:00
|
|
|
/**
|
|
|
|
* Tabs are available if a page has page actions but is not the talk page of
|
|
|
|
* the main page.
|
|
|
|
*
|
|
|
|
* Special pages have tabs if SkinOptions::TABS_ON_SPECIALS is enabled.
|
|
|
|
* This is used by Extension:GrowthExperiments
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function hasPageTabs() {
|
|
|
|
$title = $this->getTitle();
|
|
|
|
$skinOptions = $this->getSkinOptions();
|
|
|
|
$isSpecialPage = $title->isSpecialPage();
|
|
|
|
$subjectPage = MediaWikiServices::getInstance()->getNamespaceInfo()
|
|
|
|
->getSubjectPage( $title );
|
|
|
|
$isMainPageTalk = Title::newFromLinkTarget( $subjectPage )->isMainPage();
|
|
|
|
return (
|
|
|
|
$this->hasPageActions() && !$isMainPageTalk
|
|
|
|
) || (
|
|
|
|
$isSpecialPage &&
|
|
|
|
$skinOptions->get( SkinOptions::TABS_ON_SPECIALS )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-12 19:51:08 +00:00
|
|
|
* @param array $contentNavigationUrls
|
2021-10-19 18:16:43 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2021-11-12 19:51:08 +00:00
|
|
|
private function getTabsData( array $contentNavigationUrls ) {
|
2021-10-19 18:16:43 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
|
|
|
$hasTalkTabs = $skinOptions->get( SkinOptions::TALK_AT_TOP ) && $this->hasPageTabs();
|
|
|
|
if ( !$hasTalkTabs ) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-11-12 19:51:08 +00:00
|
|
|
return $contentNavigationUrls ? [
|
|
|
|
'items' => array_values( $contentNavigationUrls['namespaces'] ),
|
2021-10-19 18:16:43 +00:00
|
|
|
] : [];
|
|
|
|
}
|
|
|
|
|
2019-05-24 00:07:27 +00:00
|
|
|
/**
|
|
|
|
* Lazy load the permissions object. We don't want to initialize it as it requires many
|
|
|
|
* dependencies, sometimes some of those dependencies cannot be fulfilled (like missing Title
|
|
|
|
* object)
|
|
|
|
* @return IMinervaPagePermissions
|
|
|
|
*/
|
2019-06-21 16:52:22 +00:00
|
|
|
private function getPermissions(): IMinervaPagePermissions {
|
2019-05-24 00:07:27 +00:00
|
|
|
if ( $this->permissions === null ) {
|
|
|
|
$this->permissions = MediaWikiServices::getInstance()
|
2019-10-08 17:22:31 +00:00
|
|
|
->getService( 'Minerva.Permissions' )
|
|
|
|
->setContext( $this->getContext() );
|
2019-05-24 00:07:27 +00:00
|
|
|
}
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
|
|
|
|
2019-04-08 17:08:57 +00:00
|
|
|
/**
|
|
|
|
* Initalized main menu. Please use getter.
|
2019-07-14 14:44:29 +00:00
|
|
|
* @var MainMenuDirector
|
2019-04-08 17:08:57 +00:00
|
|
|
*/
|
|
|
|
private $mainMenu;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the Main Menu Director by passing the skin options
|
|
|
|
*
|
|
|
|
* @return MainMenuDirector
|
|
|
|
*/
|
2019-06-21 16:52:22 +00:00
|
|
|
protected function getMainMenu(): MainMenuDirector {
|
2019-04-08 17:08:57 +00:00
|
|
|
if ( !$this->mainMenu ) {
|
|
|
|
$this->mainMenu = MediaWikiServices::getInstance()->getService( 'Minerva.Menu.MainDirector' );
|
|
|
|
}
|
|
|
|
return $this->mainMenu;
|
|
|
|
}
|
|
|
|
|
2019-08-02 14:12:26 +00:00
|
|
|
/**
|
|
|
|
* Prepare all Minerva menus
|
2021-11-12 19:51:08 +00:00
|
|
|
*
|
2022-01-13 00:38:16 +00:00
|
|
|
* @param array $personalUrls result of SkinTemplate::buildPersonalUrls
|
2021-11-10 23:58:07 +00:00
|
|
|
* @return string|null
|
2019-08-02 14:12:26 +00:00
|
|
|
*/
|
2022-01-13 00:38:16 +00:00
|
|
|
private function getPersonalToolsMenu( array $personalUrls ) {
|
2019-08-02 14:12:26 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2022-03-04 16:40:54 +00:00
|
|
|
/** @var UserMenuDirector $userMenuDirector */
|
2019-08-02 14:12:26 +00:00
|
|
|
$userMenuDirector = $services->getService( 'Minerva.Menu.UserMenuDirector' );
|
2022-01-13 00:38:16 +00:00
|
|
|
return $userMenuDirector->renderMenuData( $personalUrls );
|
2019-08-02 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
2021-10-04 22:03:29 +00:00
|
|
|
* @return string
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-10-04 22:03:29 +00:00
|
|
|
protected function getSubjectPage() {
|
2019-08-02 15:02:28 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2017-07-12 15:12:40 +00:00
|
|
|
$title = $this->getTitle();
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// If it's a talk page, add a link to the main namespace page
|
2019-02-26 18:24:42 +00:00
|
|
|
// In AMC we do not need to do this as there is an easy way back to the article page
|
|
|
|
// via the talk/article tabs.
|
2021-09-23 19:47:46 +00:00
|
|
|
if ( $title->isTalkPage() && !$skinOptions->get( SkinOptions::TALK_AT_TOP ) ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
// if it's a talk page for which we have a special message, use it
|
|
|
|
switch ( $title->getNamespace() ) {
|
|
|
|
case NS_USER_TALK:
|
|
|
|
$msg = 'mobile-frontend-talk-back-to-userpage';
|
|
|
|
break;
|
|
|
|
case NS_PROJECT_TALK:
|
|
|
|
$msg = 'mobile-frontend-talk-back-to-projectpage';
|
|
|
|
break;
|
|
|
|
case NS_FILE_TALK:
|
|
|
|
$msg = 'mobile-frontend-talk-back-to-filepage';
|
|
|
|
break;
|
|
|
|
default: // generic (all other NS)
|
|
|
|
$msg = 'mobile-frontend-talk-back-to-page';
|
|
|
|
}
|
2019-08-02 15:02:28 +00:00
|
|
|
$subjectPage = $services->getNamespaceInfo()->getSubjectPage( $title );
|
|
|
|
|
2021-10-04 22:03:29 +00:00
|
|
|
return MediaWikiServices::getInstance()->getLinkRenderer()->makeLink(
|
2019-08-02 15:02:28 +00:00
|
|
|
$subjectPage,
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->msg( $msg, $title->getText() )->text(),
|
2021-11-05 00:52:30 +00:00
|
|
|
[
|
|
|
|
'data-event-name' => 'talk.returnto',
|
|
|
|
'class' => 'return-link'
|
|
|
|
]
|
2021-10-04 22:03:29 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return '';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides Skin::doEditSectionLink
|
2020-03-20 21:49:22 +00:00
|
|
|
* @param Title $nt The title being linked to (may not be the same as
|
|
|
|
* the current page, if the section is included from a template)
|
2017-07-12 15:12:40 +00:00
|
|
|
* @param string $section
|
|
|
|
* @param string|null $tooltip
|
2018-07-23 20:12:42 +00:00
|
|
|
* @param Language $lang
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-07-23 20:12:42 +00:00
|
|
|
public function doEditSectionLink( Title $nt, $section, $tooltip, Language $lang ) {
|
2019-08-27 20:27:57 +00:00
|
|
|
if ( $this->getPermissions()->isAllowed( IMinervaPagePermissions::EDIT_OR_CREATE ) &&
|
2019-05-24 00:07:27 +00:00
|
|
|
!$nt->isMainPage() ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$message = $this->msg( 'mobile-frontend-editor-edit' )->inLanguage( $lang )->text();
|
2018-09-21 01:38:10 +00:00
|
|
|
$html = Html::openElement( 'span', [ 'class' => 'mw-editsection' ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
$html .= Html::element( 'a', [
|
2020-03-20 21:49:22 +00:00
|
|
|
'href' => $nt->getLocalURL( [ 'action' => 'edit', 'section' => $section ] ),
|
2017-07-12 15:12:40 +00:00
|
|
|
'title' => $this->msg( 'editsectionhint', $tooltip )->inLanguage( $lang )->text(),
|
|
|
|
'data-section' => $section,
|
|
|
|
// Note visibility of the edit section link button is controlled by .edit-page in ui.less so
|
|
|
|
// we default to enabled even though this may not be true.
|
2019-09-11 12:19:47 +00:00
|
|
|
'class' => MinervaUI::iconClass(
|
2020-04-10 17:40:05 +00:00
|
|
|
'edit-base20', 'element', 'edit-page mw-ui-icon-flush-right', 'wikimedia'
|
2019-09-11 12:19:47 +00:00
|
|
|
),
|
2017-07-12 15:12:40 +00:00
|
|
|
], $message );
|
|
|
|
$html .= Html::closeElement( 'span' );
|
|
|
|
return $html;
|
|
|
|
}
|
2018-06-18 19:33:03 +00:00
|
|
|
return '';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a title and returns classes to apply to the body tag
|
|
|
|
* @param Title $title
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPageClasses( $title ) {
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2017-07-12 15:12:40 +00:00
|
|
|
$className = parent::getPageClasses( $title );
|
2021-09-23 19:47:46 +00:00
|
|
|
$className .= ' ' . ( $skinOptions->get( SkinOptions::BETA_MODE )
|
2019-04-10 21:43:50 +00:00
|
|
|
? 'beta' : 'stable' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
if ( $title->isMainPage() ) {
|
|
|
|
$className .= ' page-Main_Page ';
|
|
|
|
}
|
|
|
|
|
2020-12-18 03:09:15 +00:00
|
|
|
if ( $this->getUser()->isRegistered() ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$className .= ' is-authenticated';
|
|
|
|
}
|
2018-11-12 20:32:28 +00:00
|
|
|
// The new treatment should only apply to the main namespace
|
|
|
|
if (
|
|
|
|
$title->getNamespace() === NS_MAIN &&
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions->get( SkinOptions::PAGE_ISSUES )
|
2018-11-12 20:32:28 +00:00
|
|
|
) {
|
|
|
|
$className .= ' issues-group-B';
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
return $className;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the output page contains category links and the category feature is enabled.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function hasCategoryLinks() {
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
|
|
|
if ( !$skinOptions->get( SkinOptions::CATEGORIES ) ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$categoryLinks = $this->getOutput()->getCategoryLinks();
|
|
|
|
|
|
|
|
if ( !count( $categoryLinks ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !empty( $categoryLinks['normal'] ) || !empty( $categoryLinks['hidden'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return SkinUserPageHelper
|
|
|
|
*/
|
|
|
|
public function getUserPageHelper() {
|
2019-04-10 12:52:34 +00:00
|
|
|
return MediaWikiServices::getInstance()->getService( 'Minerva.SkinUserPageHelper' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the user button.
|
2019-05-07 20:27:56 +00:00
|
|
|
* @param string $newTalks New talk page messages for the current user
|
2021-11-10 23:58:07 +00:00
|
|
|
* @return string
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-11-10 23:58:07 +00:00
|
|
|
protected function prepareUserNotificationsButton( $newTalks ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$user = $this->getUser();
|
2020-12-18 03:09:15 +00:00
|
|
|
if ( $user->isRegistered() ) {
|
2021-11-10 23:58:07 +00:00
|
|
|
$currentTitle = $this->getTitle();
|
|
|
|
$notificationsMsg = $this->msg( 'mobile-frontend-user-button-tooltip' )->text();
|
|
|
|
$notificationIconClass = MinervaUI::iconClass( 'bellOutline-base20',
|
|
|
|
'element', '', 'wikimedia' );
|
2019-10-01 21:40:49 +00:00
|
|
|
$badge = Html::element( 'a', [
|
|
|
|
'class' => $notificationIconClass,
|
2020-05-26 13:19:57 +00:00
|
|
|
'href' => SpecialPage::getTitleFor( 'Mytalk' )->getLocalURL(
|
2019-10-01 21:40:49 +00:00
|
|
|
[ 'returnto' => $currentTitle->getPrefixedText() ]
|
|
|
|
),
|
|
|
|
], $notificationsMsg );
|
2022-03-04 16:40:54 +00:00
|
|
|
MWHooks::run( 'SkinMinervaReplaceNotificationsBadge',
|
2019-10-01 21:40:49 +00:00
|
|
|
[ $user, $currentTitle, &$badge ] );
|
2021-11-10 23:58:07 +00:00
|
|
|
return $badge;
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2021-11-10 23:58:07 +00:00
|
|
|
return '';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 18:55:24 +00:00
|
|
|
/**
|
|
|
|
* Get a history link which describes author and relative time of last edit
|
|
|
|
* @param Title $title The Title object of the page being viewed
|
2020-01-04 12:24:24 +00:00
|
|
|
* @param string $timestamp
|
2017-11-22 18:55:24 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getRelativeHistoryLink( Title $title, $timestamp ) {
|
|
|
|
$user = $this->getUser();
|
2019-05-14 10:40:56 +00:00
|
|
|
$userDate = $this->getLanguage()->userDate( $timestamp, $user );
|
2017-11-22 18:55:24 +00:00
|
|
|
$text = $this->msg(
|
2019-05-14 10:40:56 +00:00
|
|
|
'minerva-last-modified-date', $userDate,
|
2017-11-22 18:55:24 +00:00
|
|
|
$this->getLanguage()->userTime( $timestamp, $user )
|
|
|
|
)->parse();
|
|
|
|
return [
|
|
|
|
// Use $edit['timestamp'] (Unix format) instead of $timestamp (MW format)
|
|
|
|
'data-timestamp' => wfTimestamp( TS_UNIX, $timestamp ),
|
|
|
|
'href' => $this->getHistoryUrl( $title ),
|
|
|
|
'text' => $text,
|
|
|
|
] + $this->getRevisionEditorData( $title );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a history link which makes no reference to user or last edited time
|
|
|
|
* @param Title $title The Title object of the page being viewed
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getGenericHistoryLink( Title $title ) {
|
|
|
|
$text = $this->msg( 'mobile-frontend-history' )->plain();
|
|
|
|
return [
|
|
|
|
'href' => $this->getHistoryUrl( $title ),
|
|
|
|
'text' => $text,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL for the history page for the given title using Special:History
|
|
|
|
* when available.
|
|
|
|
* @param Title $title The Title object of the page being viewed
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getHistoryUrl( Title $title ) {
|
2019-04-04 16:03:48 +00:00
|
|
|
return ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) &&
|
|
|
|
SpecialMobileHistory::shouldUseSpecialHistory( $title, $this->getUser() ) ?
|
2017-11-22 18:55:24 +00:00
|
|
|
SpecialPage::getTitleFor( 'History', $title )->getLocalURL() :
|
|
|
|
$title->getLocalURL( [ 'action' => 'history' ] );
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Prepare the content for the 'last edited' message, e.g. 'Last edited on 30 August
|
|
|
|
* 2013, at 23:31'. This message is different for the main page since main page
|
2019-01-11 12:13:49 +00:00
|
|
|
* content is typically transcluded rather than edited directly.
|
2019-08-02 13:38:18 +00:00
|
|
|
*
|
|
|
|
* The relative time is only rendered on the latest revision.
|
|
|
|
* For older revisions the last modified information will not render with a relative time
|
|
|
|
* nor will it show the name of the editor.
|
2017-07-12 15:12:40 +00:00
|
|
|
* @param Title $title The Title object of the page being viewed
|
2021-10-29 19:47:02 +00:00
|
|
|
* @return array|null
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2017-11-22 18:55:24 +00:00
|
|
|
protected function getHistoryLink( Title $title ) {
|
2020-07-29 15:08:13 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$isLatestRevision = $out->getRevisionId() === $title->getLatestRevID();
|
2017-07-12 15:12:40 +00:00
|
|
|
// Get rev_timestamp of current revision (preloaded by MediaWiki core)
|
2020-07-29 15:08:13 +00:00
|
|
|
$timestamp = $out->getRevisionTimestamp();
|
2017-11-16 23:21:05 +00:00
|
|
|
# No cached timestamp, load it from the database
|
|
|
|
if ( $timestamp === null ) {
|
2020-03-04 02:19:05 +00:00
|
|
|
$timestamp = MediaWikiServices::getInstance()
|
|
|
|
->getRevisionLookup()
|
2020-07-29 15:08:13 +00:00
|
|
|
->getTimestampFromId( $out->getRevisionId() );
|
2017-11-16 23:21:05 +00:00
|
|
|
}
|
2021-11-29 20:34:09 +00:00
|
|
|
|
|
|
|
// Create history link and corresponding icons.
|
|
|
|
$historyLinkAndIcons = [];
|
|
|
|
if ( Action::getActionName( RequestContext::getMain() ) === 'view' ) {
|
|
|
|
$historyIconClasses = [
|
|
|
|
'historyIconClass' => MinervaUI::iconClass(
|
|
|
|
'history-base20', 'mw-ui-icon-small', '', 'wikimedia'
|
|
|
|
),
|
|
|
|
'arrowIconClass' => MinervaUI::iconClass(
|
|
|
|
'expand-gray', 'small',
|
|
|
|
'mf-mw-ui-icon-rotate-anti-clockwise indicator',
|
|
|
|
// Uses icon in MobileFrontend so must be prefixed mf.
|
|
|
|
// Without MobileFrontend it will not render.
|
|
|
|
// Rather than maintain 2 versions (and variants) of the arrow icon which can conflict
|
|
|
|
// with each othe and bloat CSS, we'll
|
|
|
|
// use the MobileFrontend one. Long term when T177432 and T160690 are resolved
|
|
|
|
// we should be able to use one icon definition and break this dependency.
|
|
|
|
'mf'
|
|
|
|
),
|
|
|
|
];
|
|
|
|
$historyLink = !$isLatestRevision || $title->isMainPage() ?
|
|
|
|
$this->getGenericHistoryLink( $title ) :
|
|
|
|
$this->getRelativeHistoryLink( $title, $timestamp );
|
|
|
|
|
|
|
|
$historyLinkAndIcons = $historyLink + $historyIconClasses;
|
|
|
|
}
|
2021-10-29 19:47:02 +00:00
|
|
|
|
2021-11-17 15:09:30 +00:00
|
|
|
$title = $this->getTitle();
|
2021-11-29 20:34:09 +00:00
|
|
|
return $title->canExist() && $title->exists() && !empty( $historyLinkAndIcons )
|
|
|
|
? $historyLinkAndIcons
|
2021-11-17 15:09:30 +00:00
|
|
|
: null;
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2017-09-06 15:20:16 +00:00
|
|
|
|
|
|
|
/**
|
2017-11-22 18:55:24 +00:00
|
|
|
* Returns data attributes representing the editor for the current revision.
|
2020-03-04 02:53:53 +00:00
|
|
|
* @param LinkTarget $title The Title object of the page being viewed
|
2017-11-22 18:55:24 +00:00
|
|
|
* @return array representing user with name and gender fields. Empty if the editor no longer
|
|
|
|
* exists in the database or is hidden from public view.
|
2017-09-06 15:20:16 +00:00
|
|
|
*/
|
2020-03-04 02:53:53 +00:00
|
|
|
private function getRevisionEditorData( LinkTarget $title ) {
|
2021-11-23 09:18:46 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$rev = $services->getRevisionLookup()
|
2020-03-04 02:53:53 +00:00
|
|
|
->getRevisionByTitle( $title );
|
2017-11-22 18:55:24 +00:00
|
|
|
$result = [];
|
|
|
|
if ( $rev ) {
|
2020-03-04 02:53:53 +00:00
|
|
|
$revUser = $rev->getUser();
|
2017-11-22 18:55:24 +00:00
|
|
|
// Note the user will only be returned if that information is public
|
2020-03-04 02:53:53 +00:00
|
|
|
if ( $revUser ) {
|
2017-11-22 18:55:24 +00:00
|
|
|
$editorName = $revUser->getName();
|
2021-11-23 09:18:46 +00:00
|
|
|
$editorGender = $services->getGenderCache()->getGenderOf( $revUser, __METHOD__ );
|
2017-11-22 18:55:24 +00:00
|
|
|
$result += [
|
|
|
|
'data-user-name' => $editorName,
|
|
|
|
'data-user-gender' => $editorGender,
|
|
|
|
];
|
|
|
|
}
|
2017-09-06 15:20:16 +00:00
|
|
|
}
|
2017-11-22 18:55:24 +00:00
|
|
|
return $result;
|
2017-09-06 15:20:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML representing the tagline
|
|
|
|
* @return string HTML for tagline
|
|
|
|
*/
|
|
|
|
protected function getTaglineHtml() {
|
2017-11-28 21:55:58 +00:00
|
|
|
$tagline = '';
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
if ( $this->getUserPageHelper()->isUserPage() ) {
|
|
|
|
$pageUser = $this->getUserPageHelper()->getPageUser();
|
|
|
|
$fromDate = $pageUser->getRegistration();
|
2021-04-29 20:24:13 +00:00
|
|
|
|
|
|
|
if ( $this->getUserPageHelper()->isUserPageAccessibleToCurrentUser() && is_string( $fromDate ) ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$fromDateTs = wfTimestamp( TS_UNIX, $fromDate );
|
2021-11-23 09:18:46 +00:00
|
|
|
$genderCache = MediaWikiServices::getInstance()->getGenderCache();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// This is shown when js is disabled. js enhancement made due to caching
|
|
|
|
$tagline = $this->msg( 'mobile-frontend-user-page-member-since',
|
|
|
|
$this->getLanguage()->userDate( new MWTimestamp( $fromDateTs ), $this->getUser() ),
|
2018-09-04 05:58:45 +00:00
|
|
|
$pageUser )->text();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// Define html attributes for usage with js enhancement (unix timestamp, gender)
|
|
|
|
$attrs = [ 'id' => 'tagline-userpage',
|
|
|
|
'data-userpage-registration-date' => $fromDateTs,
|
2021-11-23 09:18:46 +00:00
|
|
|
'data-userpage-gender' => $genderCache->getGenderOf( $pageUser, __METHOD__ ) ];
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$title = $this->getTitle();
|
|
|
|
if ( $title ) {
|
2018-10-31 21:37:17 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$tagline = $out->getProperty( 'wgMFDescription' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$attrs[ 'class' ] = 'tagline';
|
2017-11-28 21:55:58 +00:00
|
|
|
return Html::element( 'div', $attrs, $tagline );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-10-11 19:04:00 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML representing the heading.
|
2021-11-05 18:21:09 +00:00
|
|
|
*
|
|
|
|
* @param string $heading The heading suggested by core.
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return string HTML for header
|
|
|
|
*/
|
2021-11-05 18:21:09 +00:00
|
|
|
private function getUserPageHeadingHtml( $heading ) {
|
|
|
|
// The heading is just the username without namespace
|
|
|
|
// This is escaped as a precaution (user name should be safe).
|
|
|
|
return Html::rawElement( 'h1',
|
|
|
|
// These IDs and classes should match Skin::getTemplateData
|
|
|
|
[
|
|
|
|
'id' => 'firstHeading',
|
|
|
|
'class' => 'firstHeading mw-first-heading mw-minerva-user-heading',
|
|
|
|
],
|
|
|
|
htmlspecialchars(
|
|
|
|
$this->getUserPageHelper()->getPageUser()->getName()
|
|
|
|
)
|
|
|
|
);
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-06-21 20:07:11 +00:00
|
|
|
|
2019-11-13 01:48:59 +00:00
|
|
|
/**
|
|
|
|
* @return bool Whether or not current title is a Talk page with the default
|
|
|
|
* action ('view')
|
|
|
|
*/
|
|
|
|
private function isTalkPageWithViewAction() {
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
2021-06-09 04:01:43 +00:00
|
|
|
// Hook is @unstable and only for use by DiscussionTools. Do not use for any other purpose.
|
|
|
|
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
|
|
|
if ( !$hookContainer->run( 'MinervaNeueTalkPageOverlay', [ $title, $this->getOutput() ] ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-13 01:48:59 +00:00
|
|
|
return $title->isTalkPage() && Action::getActionName( $this->getContext() ) === "view";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-18 19:11:32 +00:00
|
|
|
* @internal Should not be used outside Minerva.
|
|
|
|
* @todo Find better place for this.
|
|
|
|
*
|
|
|
|
* @return bool Whether or not the simplified talk page is enabled and action is 'view'
|
2019-11-13 01:48:59 +00:00
|
|
|
*/
|
2020-06-18 19:11:32 +00:00
|
|
|
public function isSimplifiedTalkPageEnabled(): bool {
|
2019-11-25 22:29:11 +00:00
|
|
|
$title = $this->getTitle();
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2019-11-25 22:29:11 +00:00
|
|
|
|
2019-11-13 01:48:59 +00:00
|
|
|
return $this->isTalkPageWithViewAction() &&
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions->get( SkinOptions::SIMPLIFIED_TALK ) &&
|
2020-05-14 20:34:11 +00:00
|
|
|
// Only if viewing the latest revision, as we can't get the section numbers otherwise
|
|
|
|
// (and even if we could, they would be useless, because edits often add and remove sections).
|
2020-07-29 15:08:13 +00:00
|
|
|
$this->getOutput()->getRevisionId() === $title->getLatestRevID() &&
|
2019-11-25 22:29:11 +00:00
|
|
|
$title->getContentModel() === CONTENT_MODEL_WIKITEXT;
|
2019-11-13 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the postheadinghtml for the talk page with view action
|
|
|
|
*
|
|
|
|
* @return string HTML for postheadinghtml
|
|
|
|
*/
|
2019-10-17 22:46:07 +00:00
|
|
|
private function getTalkPagePostHeadingHtml() {
|
|
|
|
$title = $this->getTitle();
|
2019-11-13 01:48:59 +00:00
|
|
|
$html = '';
|
|
|
|
|
|
|
|
// T237589: We don't want to show the add discussion button on Flow pages,
|
|
|
|
// only wikitext pages
|
|
|
|
if ( $this->getPermissions()->isTalkAllowed() &&
|
|
|
|
$title->getContentModel() === CONTENT_MODEL_WIKITEXT
|
|
|
|
) {
|
|
|
|
$addTopicButton = $this->getTalkButton( $title, wfMessage(
|
|
|
|
'minerva-talk-add-topic' )->text(), true );
|
2021-11-05 00:52:30 +00:00
|
|
|
$html = Html::element( 'a', $addTopicButton['attributes'] + [
|
|
|
|
'data-event-name' => 'talkpage.add-topic'
|
|
|
|
], $addTopicButton['label'] );
|
2019-11-13 01:48:59 +00:00
|
|
|
}
|
2019-10-17 22:46:07 +00:00
|
|
|
|
2021-11-17 15:09:30 +00:00
|
|
|
$title = $this->getTitle();
|
|
|
|
if ( $this->isSimplifiedTalkPageEnabled() && $title->canExist() ) {
|
|
|
|
$parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
|
|
|
|
$parserOptions = ParserOptions::newFromContext( $this->getContext() );
|
|
|
|
$pageRecord = $title->toPageRecord();
|
|
|
|
$status = $parserOutputAccess->getParserOutput( $pageRecord, $parserOptions );
|
|
|
|
$statusValue = $status->getValue();
|
|
|
|
$sectionCount = ( $status->isGood() && $statusValue instanceof ParserOutput )
|
|
|
|
? count( $statusValue->getSections() )
|
|
|
|
: 0;
|
2019-11-13 01:48:59 +00:00
|
|
|
$message = $sectionCount > 0 ? wfMessage( 'minerva-talk-explained' )
|
|
|
|
: wfMessage( 'minerva-talk-explained-empty' );
|
2020-12-09 17:13:39 +00:00
|
|
|
$html .= Html::element( 'div', [ 'class' =>
|
2019-11-13 01:48:59 +00:00
|
|
|
'minerva-talk-content-explained' ], $message->text() );
|
2019-10-17 22:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* Load internal banner content to show in pre content in template
|
|
|
|
* Beware of HTML caching when using this function.
|
|
|
|
* Content set as "internalbanner"
|
2021-11-10 23:58:07 +00:00
|
|
|
* @param string $siteNotice HTML fragment
|
|
|
|
* @return array
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-11-10 23:58:07 +00:00
|
|
|
protected function prepareBanners( $siteNotice ) {
|
2021-12-10 11:11:35 +00:00
|
|
|
$banners = [];
|
|
|
|
if ( $siteNotice && $this->getConfig()->get( 'MinervaEnableSiteNotice' ) ) {
|
|
|
|
$banners[] = '<div id="siteNotice">' . $siteNotice . '</div>';
|
|
|
|
} else {
|
|
|
|
$banners[] = '<div id="siteNotice"></div>';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2021-11-10 23:58:07 +00:00
|
|
|
return $banners;
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array with details for a language button.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getLanguageButton() {
|
|
|
|
$languageUrl = SpecialPage::getTitleFor(
|
|
|
|
'MobileLanguages',
|
|
|
|
$this->getSkin()->getTitle()
|
|
|
|
)->getLocalURL();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'attributes' => [
|
|
|
|
'class' => 'language-selector',
|
|
|
|
'href' => $languageUrl,
|
|
|
|
],
|
|
|
|
'label' => $this->msg( 'mobile-frontend-language-article-heading' )->text()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array with details for a talk button.
|
|
|
|
* @param Title $talkTitle Title object of the talk page
|
2019-10-17 22:46:07 +00:00
|
|
|
* @param string $label Button label
|
2017-09-28 20:06:39 +00:00
|
|
|
* @param bool $addSection (optional) when added the talk button will render
|
|
|
|
* as an add topic button. Defaults to false.
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-10-17 22:46:07 +00:00
|
|
|
protected function getTalkButton( $talkTitle, $label, $addSection = false ) {
|
2017-09-28 20:06:39 +00:00
|
|
|
if ( $addSection ) {
|
|
|
|
$params = [ 'action' => 'edit', 'section' => 'new' ];
|
2019-10-17 22:46:07 +00:00
|
|
|
$className = 'minerva-talk-add-button ' . MinervaUI::buttonClass( 'progressive', 'button' );
|
2017-09-28 20:06:39 +00:00
|
|
|
} else {
|
|
|
|
$params = [];
|
|
|
|
$className = 'talk';
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
return [
|
|
|
|
'attributes' => [
|
2017-09-28 20:06:39 +00:00
|
|
|
'href' => $talkTitle->getLinkURL( $params ),
|
2017-07-12 15:12:40 +00:00
|
|
|
'data-title' => $talkTitle->getFullText(),
|
2017-09-28 20:06:39 +00:00
|
|
|
'class' => $className,
|
2017-07-12 15:12:40 +00:00
|
|
|
],
|
2019-10-17 22:46:07 +00:00
|
|
|
'label' => $label,
|
2017-07-12 15:12:40 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of links for page secondary actions
|
2021-11-12 19:51:08 +00:00
|
|
|
* @param array $contentNavigationUrls
|
2021-10-26 16:02:42 +00:00
|
|
|
* @return array|null
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-11-12 19:51:08 +00:00
|
|
|
protected function getSecondaryActions( array $contentNavigationUrls ) {
|
2021-10-26 16:02:42 +00:00
|
|
|
if ( $this->isFallbackEditor() || !$this->hasSecondaryActions() ) {
|
|
|
|
return null;
|
2021-10-20 16:40:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 15:02:28 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2019-08-02 15:02:28 +00:00
|
|
|
$namespaceInfo = $services->getNamespaceInfo();
|
2019-07-09 16:10:31 +00:00
|
|
|
/** @var \MediaWiki\Minerva\LanguagesHelper $languagesHelper */
|
2019-08-02 15:02:28 +00:00
|
|
|
$languagesHelper = $services->getService( 'Minerva.LanguagesHelper' );
|
2017-07-12 15:12:40 +00:00
|
|
|
$buttons = [];
|
|
|
|
// always add a button to link to the talk page
|
2019-10-17 22:46:07 +00:00
|
|
|
// it will link to the wikitext talk page
|
2017-07-12 15:12:40 +00:00
|
|
|
$title = $this->getTitle();
|
2019-08-02 15:02:28 +00:00
|
|
|
$subjectPage = Title::newFromLinkTarget( $namespaceInfo->getSubjectPage( $title ) );
|
2021-09-23 19:47:46 +00:00
|
|
|
$talkAtBottom = !$skinOptions->get( SkinOptions::TALK_AT_TOP ) ||
|
2019-10-17 22:46:07 +00:00
|
|
|
$subjectPage->isMainPage();
|
|
|
|
if ( !$this->getUserPageHelper()->isUserPage() &&
|
|
|
|
$this->getPermissions()->isTalkAllowed() && $talkAtBottom &&
|
2021-10-18 21:04:03 +00:00
|
|
|
// When showing talk at the bottom we restrict this so it is not shown to anons
|
|
|
|
// https://phabricator.wikimedia.org/T54165
|
|
|
|
// This whole code block can be removed when SkinOptions::TALK_AT_TOP is always true
|
|
|
|
$this->getUser()->isRegistered() &&
|
2019-10-17 22:46:07 +00:00
|
|
|
!$this->isTalkPageWithViewAction()
|
2019-01-10 22:59:56 +00:00
|
|
|
) {
|
2021-11-12 19:51:08 +00:00
|
|
|
$namespaces = $contentNavigationUrls['namespaces'];
|
2017-07-12 15:12:40 +00:00
|
|
|
// FIXME [core]: This seems unnecessary..
|
|
|
|
$subjectId = $title->getNamespaceKey( '' );
|
|
|
|
$talkId = $subjectId === 'main' ? 'talk' : "{$subjectId}_talk";
|
2017-09-28 20:06:39 +00:00
|
|
|
|
|
|
|
if ( isset( $namespaces[$talkId] ) ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$talkButton = $namespaces[$talkId];
|
2019-08-02 15:02:28 +00:00
|
|
|
$talkTitle = Title::newFromLinkTarget( $namespaceInfo->getTalkPage( $title ) );
|
|
|
|
|
2019-10-17 22:46:07 +00:00
|
|
|
$buttons['talk'] = $this->getTalkButton( $talkTitle, $talkButton['text'] );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:10:31 +00:00
|
|
|
if ( $languagesHelper->doesTitleHasLanguagesOrVariants( $title ) && $title->isMainPage() ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
$buttons['language'] = $this->getLanguageButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-21 22:44:18 +00:00
|
|
|
* @inheritDoc
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2021-07-23 00:57:37 +00:00
|
|
|
protected function getJsConfigVars(): array {
|
2019-09-18 23:07:21 +00:00
|
|
|
$title = $this->getTitle();
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2019-09-18 23:07:21 +00:00
|
|
|
|
2020-04-21 22:44:18 +00:00
|
|
|
return array_merge( parent::getJsConfigVars(), [
|
2019-09-18 23:07:21 +00:00
|
|
|
'wgMinervaPermissions' => [
|
|
|
|
'watch' => $this->getPermissions()->isAllowed( IMinervaPagePermissions::WATCH ),
|
|
|
|
'talk' => $this->getUserPageHelper()->isUserPage() ||
|
|
|
|
( $this->getPermissions()->isTalkAllowed() || $title->isTalkPage() ) &&
|
|
|
|
$this->isWikiTextTalkPage()
|
|
|
|
],
|
2021-09-23 19:47:46 +00:00
|
|
|
'wgMinervaFeatures' => $skinOptions->getAll(),
|
2017-11-28 21:17:27 +00:00
|
|
|
'wgMinervaDownloadNamespaces' => $this->getConfig()->get( 'MinervaDownloadNamespaces' ),
|
2020-04-21 22:44:18 +00:00
|
|
|
] );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 17:17:38 +00:00
|
|
|
/**
|
2017-07-12 15:12:40 +00:00
|
|
|
* Returns true, if the talk page of this page is wikitext-based.
|
2017-07-24 16:53:04 +00:00
|
|
|
* @return bool
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
protected function isWikiTextTalkPage() {
|
|
|
|
$title = $this->getTitle();
|
|
|
|
if ( !$title->isTalkPage() ) {
|
2019-08-02 15:02:28 +00:00
|
|
|
$namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
|
|
|
|
$title = Title::newFromLinkTarget( $namespaceInfo->getTalkPage( $title ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2017-08-22 14:12:32 +00:00
|
|
|
return $title->isWikitextPage();
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the javascript entry modules to load. Only modules that need to
|
|
|
|
* be overriden or added conditionally should be placed here.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDefaultModules() {
|
|
|
|
$modules = parent::getDefaultModules();
|
2019-05-14 09:01:04 +00:00
|
|
|
|
|
|
|
// FIXME: T223204: Dequeue default content modules except for the history
|
|
|
|
// action. Allow default history action content modules
|
2020-07-14 12:59:40 +00:00
|
|
|
// in order to enable toggling of the
|
2019-05-14 09:01:04 +00:00
|
|
|
// filters. Long term this won't be necessary when T111565 is resolved and a
|
|
|
|
// more general solution can be used.
|
|
|
|
if ( Action::getActionName( $this->getContext() ) !== 'history' ) {
|
|
|
|
// dequeue default content modules (toc, sortable, collapsible, etc.)
|
2020-07-14 12:59:40 +00:00
|
|
|
$modules['content'] = array_diff( $modules['content'], [
|
|
|
|
// T233340
|
|
|
|
'jquery.tablesorter',
|
|
|
|
// T111565
|
|
|
|
'jquery.makeCollapsible',
|
|
|
|
// Minerva provides its own implementation. Loading this will break display.
|
|
|
|
'mediawiki.toc'
|
|
|
|
] );
|
2019-05-14 09:01:04 +00:00
|
|
|
// dequeue styles associated with `content` key.
|
2020-07-14 12:59:40 +00:00
|
|
|
$modules['styles']['content'] = array_diff( $modules['styles']['content'], [
|
|
|
|
// T233340
|
|
|
|
'jquery.tablesorter.styles',
|
|
|
|
// T111565
|
|
|
|
'jquery.makeCollapsible.styles',
|
|
|
|
] );
|
2019-05-14 09:01:04 +00:00
|
|
|
}
|
2018-05-04 23:40:59 +00:00
|
|
|
$modules['styles']['core'] = $this->getSkinStyles();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2021-04-28 21:58:51 +00:00
|
|
|
$modules['minerva'] = [
|
|
|
|
'skins.minerva.scripts'
|
|
|
|
];
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
return $modules;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-06 15:28:47 +00:00
|
|
|
* Provide styles required to present the server rendered page in this skin. Additional styles
|
|
|
|
* may be loaded dynamically by the client.
|
|
|
|
*
|
|
|
|
* Any styles returned by this method are loaded on the critical rendering path as linked
|
|
|
|
* stylesheets. I.e., they are required to load on the client before first paint.
|
|
|
|
*
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-08-06 15:28:47 +00:00
|
|
|
protected function getSkinStyles(): array {
|
2017-07-12 15:12:40 +00:00
|
|
|
$title = $this->getTitle();
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions = $this->getSkinOptions();
|
2017-07-12 15:12:40 +00:00
|
|
|
$styles = [
|
|
|
|
'skins.minerva.base.styles',
|
2018-06-14 16:51:50 +00:00
|
|
|
'skins.minerva.content.styles.images',
|
2017-06-01 23:09:24 +00:00
|
|
|
'mediawiki.hlist',
|
2017-07-12 15:12:40 +00:00
|
|
|
'mediawiki.ui.icon',
|
|
|
|
'mediawiki.ui.button',
|
2019-07-09 19:12:51 +00:00
|
|
|
'skins.minerva.icons.wikimedia',
|
2019-12-18 19:23:09 +00:00
|
|
|
'skins.minerva.mainMenu.icons',
|
|
|
|
'skins.minerva.mainMenu.styles',
|
2017-07-12 15:12:40 +00:00
|
|
|
];
|
|
|
|
if ( $title->isMainPage() ) {
|
|
|
|
$styles[] = 'skins.minerva.mainPage.styles';
|
2018-02-14 00:14:54 +00:00
|
|
|
} elseif ( $this->getUserPageHelper()->isUserPage() ) {
|
|
|
|
$styles[] = 'skins.minerva.userpage.styles';
|
2019-10-17 22:46:07 +00:00
|
|
|
} elseif ( $this->isTalkPageWithViewAction() ) {
|
|
|
|
$styles[] = 'skins.minerva.talk.styles';
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-10-17 22:46:07 +00:00
|
|
|
|
2021-04-28 21:58:51 +00:00
|
|
|
if ( $this->hasCategoryLinks() ) {
|
|
|
|
$styles[] = 'skins.minerva.categories.styles';
|
|
|
|
}
|
|
|
|
|
2020-12-18 03:09:15 +00:00
|
|
|
if ( $this->getUser()->isRegistered() ) {
|
2017-12-13 01:25:10 +00:00
|
|
|
$styles[] = 'skins.minerva.loggedin.styles';
|
|
|
|
$styles[] = 'skins.minerva.icons.loggedin';
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-08-22 20:31:31 +00:00
|
|
|
// When any of these features are enabled in production
|
|
|
|
// remove the if condition
|
|
|
|
// and move the associated LESS file inside `skins.minerva.amc.styles`
|
|
|
|
// into a more appropriate module.
|
|
|
|
if (
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions->get( SkinOptions::PERSONAL_MENU ) ||
|
|
|
|
$skinOptions->get( SkinOptions::TALK_AT_TOP ) ||
|
|
|
|
$skinOptions->get( SkinOptions::HISTORY_IN_PAGE_ACTIONS ) ||
|
|
|
|
$skinOptions->get( SkinOptions::TOOLBAR_SUBMENU )
|
2019-08-22 20:31:31 +00:00
|
|
|
) {
|
2021-10-19 18:45:43 +00:00
|
|
|
// SkinOptions::PERSONAL_MENU + SkinOptions::TOOLBAR_SUBMENU uses ToggleList
|
2019-08-22 20:31:31 +00:00
|
|
|
// SkinOptions::TALK_AT_TOP uses tabs.less
|
|
|
|
// SkinOptions::HISTORY_IN_PAGE_ACTIONS + SkinOptions::TOOLBAR_SUBMENU uses pageactions.less
|
2019-01-10 22:59:56 +00:00
|
|
|
$styles[] = 'skins.minerva.amc.styles';
|
2019-08-22 20:31:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 19:47:46 +00:00
|
|
|
if ( $skinOptions->get( SkinOptions::PERSONAL_MENU ) ) {
|
2019-08-22 22:13:57 +00:00
|
|
|
// If ever enabled as the default, please remove the duplicate icons
|
|
|
|
// inside skins.minerva.mainMenu.icons. See comment for MAIN_MENU_EXPANDED
|
|
|
|
$styles[] = 'skins.minerva.personalMenu.icons';
|
|
|
|
}
|
|
|
|
|
2020-03-25 02:02:02 +00:00
|
|
|
if (
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions->get( SkinOptions::MAIN_MENU_EXPANDED )
|
2020-03-25 02:02:02 +00:00
|
|
|
) {
|
2019-08-22 22:13:57 +00:00
|
|
|
// If ever enabled as the default, please review skins.minerva.mainMenu.icons
|
|
|
|
// and remove any unneeded icons
|
|
|
|
$styles[] = 'skins.minerva.mainMenu.advanced.icons';
|
|
|
|
}
|
2019-08-22 20:31:31 +00:00
|
|
|
if (
|
2021-09-23 19:47:46 +00:00
|
|
|
$skinOptions->get( SkinOptions::PERSONAL_MENU ) ||
|
|
|
|
$skinOptions->get( SkinOptions::TOOLBAR_SUBMENU )
|
2019-08-22 20:31:31 +00:00
|
|
|
) {
|
|
|
|
// SkinOptions::PERSONAL_MENU requires the `userTalk` icon.
|
2020-03-25 02:02:02 +00:00
|
|
|
// SkinOptions::TOOLBAR_SUBMENU requires the rest of the icons including `overflow`.
|
2020-04-01 23:25:04 +00:00
|
|
|
// Note `skins.minerva.overflow.icons` is pulled down by skins.minerva.scripts but the menu can
|
2019-08-22 20:31:31 +00:00
|
|
|
// work without JS.
|
2020-04-01 23:25:04 +00:00
|
|
|
$styles[] = 'skins.minerva.overflow.icons';
|
2019-01-10 22:59:56 +00:00
|
|
|
}
|
2019-08-02 14:23:28 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
return $styles;
|
|
|
|
}
|
|
|
|
}
|