2014-08-07 11:38:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Vector - Modern version of MonoBook with fresh look and many usability
|
|
|
|
* improvements.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* @ingroup Skins
|
|
|
|
*/
|
2020-04-20 16:38:01 +00:00
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use Vector\Constants;
|
2020-06-03 21:57:03 +00:00
|
|
|
use Wikimedia\WrappedString;
|
2014-08-07 11:38:34 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-30 23:56:42 +00:00
|
|
|
* Skin subclass for Vector
|
2014-08-07 11:38:34 +00:00
|
|
|
* @ingroup Skins
|
2020-03-25 15:11:54 +00:00
|
|
|
* @final skins extending SkinVector are not supported
|
|
|
|
* @unstable
|
2014-08-07 11:38:34 +00:00
|
|
|
*/
|
|
|
|
class SkinVector extends SkinTemplate {
|
2020-05-18 20:56:13 +00:00
|
|
|
public $skinname = Constants::SKIN_NAME;
|
2014-08-07 11:38:34 +00:00
|
|
|
public $stylename = 'Vector';
|
|
|
|
public $template = 'VectorTemplate';
|
2014-08-13 18:39:38 +00:00
|
|
|
|
2019-11-18 20:54:37 +00:00
|
|
|
private $responsiveMode = false;
|
2014-08-07 11:38:34 +00:00
|
|
|
|
2017-06-30 19:21:16 +00:00
|
|
|
/**
|
|
|
|
* Enables the responsive mode
|
|
|
|
*/
|
|
|
|
public function enableResponsiveMode() {
|
|
|
|
if ( !$this->responsiveMode ) {
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1' );
|
|
|
|
$out->addModuleStyles( 'skins.vector.styles.responsive' );
|
|
|
|
$this->responsiveMode = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 11:38:34 +00:00
|
|
|
/**
|
|
|
|
* Initializes output page and sets up skin-specific parameters
|
|
|
|
* @param OutputPage $out Object to initialize
|
|
|
|
*/
|
|
|
|
public function initPage( OutputPage $out ) {
|
|
|
|
parent::initPage( $out );
|
|
|
|
|
2019-11-18 20:54:37 +00:00
|
|
|
if ( $this->getConfig()->get( 'VectorResponsive' ) ) {
|
2017-06-30 19:21:16 +00:00
|
|
|
$this->enableResponsiveMode();
|
2015-06-25 00:21:28 +00:00
|
|
|
}
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 14:30:26 +00:00
|
|
|
/**
|
|
|
|
* Called by OutputPage::headElement when it is creating the
|
|
|
|
* `<body>` tag. Overrides method in Skin class.
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @param array &$bodyAttrs
|
|
|
|
*/
|
|
|
|
public function addToBodyAttributes( $out, &$bodyAttrs ) {
|
|
|
|
if ( $this->isLegacy() ) {
|
|
|
|
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 11:38:34 +00:00
|
|
|
/**
|
2019-11-18 20:41:37 +00:00
|
|
|
* @inheritDoc
|
|
|
|
* @return array
|
2014-08-07 11:38:34 +00:00
|
|
|
*/
|
2019-11-18 20:41:37 +00:00
|
|
|
public function getDefaultModules() {
|
|
|
|
$modules = parent::getDefaultModules();
|
2020-03-30 20:07:35 +00:00
|
|
|
|
|
|
|
if ( $this->isLegacy() ) {
|
|
|
|
$modules['styles']['skin'][] = 'skins.vector.styles.legacy';
|
|
|
|
$modules[Constants::SKIN_NAME] = 'skins.vector.legacy.js';
|
|
|
|
} else {
|
|
|
|
$modules['styles'] = array_merge(
|
|
|
|
$modules['styles'],
|
|
|
|
[ 'skins.vector.styles', 'mediawiki.ui.icon', 'skins.vector.icons' ]
|
|
|
|
);
|
|
|
|
$modules[Constants::SKIN_NAME][] = 'skins.vector.js';
|
|
|
|
}
|
2014-08-07 11:38:34 +00:00
|
|
|
|
2019-11-18 20:41:37 +00:00
|
|
|
return $modules;
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 21:11:54 +00:00
|
|
|
/**
|
2020-03-25 15:11:54 +00:00
|
|
|
* Set up the VectorTemplate. Overrides the default behaviour of SkinTemplate allowing
|
|
|
|
* the safe calling of constructor with additional arguments. If dropping this method
|
|
|
|
* please ensure that VectorTemplate constructor arguments match those in SkinTemplate.
|
2020-01-16 21:11:54 +00:00
|
|
|
*
|
2020-03-25 15:11:54 +00:00
|
|
|
* @internal
|
2020-01-16 21:11:54 +00:00
|
|
|
* @param string $classname
|
|
|
|
* @return VectorTemplate
|
|
|
|
*/
|
2020-03-25 15:11:54 +00:00
|
|
|
protected function setupTemplate( $classname ) {
|
Add opt-out link to Sidebar for Vector/Logged-in Users Without Abstractions
This commit is singularly focused on adding a link to the sidebar for
Vector, logged-in users. It does the bare minimum to fulfill the
requirements of T243281.
Additionally, it will help to answer the question "Do we need to use
abstractions (other than maybe different templates) to separate Legacy
Vector from Vector" by intentionally leaving out any abstractions in
order to make it easier to compare with a follow-up patch
(Ib2ef15180df73360cc1de25b893e49d415d23e1a) which does use abstractions.
It is a good thing to question whether or not we need addtional
abstractions in VectorTemplate and if they will help us as unnecessary
abstractions can have the opposite effect and just lead to further
frustrations down the road.
Therefore, I urge you, the reviewer, to let me know your thoughts! If
abstractions are viewed as not making our lives any easier, the
follow-up patches may be completely discarded and that's totally okay
with me. :) I think it's a good think to talk about now though.
Important changes:
* The VectorTemplate constructor was changed to allow injecting the
config, templateParser, and isLegacy boolean (only the config was
allowed before this commit). According to MediaWiki's Stable Interface
Policy, "Constructor signatures are generally considered unstable unless
explicitly declared stable for calling" [3]. Given that VecorTemplate's
constructor is not marked as stable, it is justified to do this without
warning according to the policy.
* Due to the above, the 'setTemplate' method is no longer needed and was
marked as deprecated.
* VectorTemplateTest was made to adapt to the new VectorTemplate
constructor. Additionally, it now extends from
MediaWikiIntegrationTestCase which my intelliphense server can pick up.
I *think* MediaWikiTestCase is just an alias to
MediaWikiIntegrationTestCase [1] and MediaWikiTestCase file was renamed
to MediaWikiIntegrationTestCase in [2], but I'm willing to change it
back if there is pushback to this.
Open questions:
* What are VectorTemplate's responsibilities? To me, it acts right now
as a controller (because it echos the full HTML string from the
template), a model (because SkinTemplate::prepareQuickTemplate sets data
on it which it later retrieves through `$this->get()`), a presenter
(because it adds data tailored for a web-centric view), and a view
(because it renders HTML strings instead of letting the view/template be
solely responsible for that). Arguably, some business logic might be
mixed in there as well (because it checks to see if a User is logged
in/has necessary permissions to show x which my changes here add to).
This might not be a problem if we keep VectorTemplate relatively small,
but will it remain this way as we progress further in Desktop
Improvements?
* How do we write tests for VectorTemplate without exposing unnecessary
public methods? For example, if I want to test the `getSkinData()`
method to see what state will be sent to the template, how should I do
this? One option might be to use `TestingAccessWrapper` to expose these
private methods which is what
`VectorTemplateTest::testbuildViewsProps()` does. Another option is to
accept this method as public. Is there a better way? Keep in mind that
even with access to this method, there might be many things to mock.
[1] https://github.com/wikimedia/mediawiki/blob/0030cb525be6cabc1d63de80586b2017d4bbe354/tests/common/TestsAutoLoader.php#L64
[2] Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
[3] https://www.mediawiki.org/wiki/Stable_interface_policy
Bug: T243281
Change-Id: I0571b041bcd7f19bec9f103fa7bccdd093f6394d
2020-03-17 20:21:33 +00:00
|
|
|
$tp = new TemplateParser( __DIR__ . '/templates' );
|
2020-04-20 16:38:01 +00:00
|
|
|
return new VectorTemplate( $this->getConfig(), $tp, $this->isLegacy() );
|
2020-01-16 21:11:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 12:59:59 +00:00
|
|
|
/**
|
|
|
|
* Whether the logo should be preloaded with an HTTP link header or not
|
|
|
|
* @since 1.29
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function shouldPreloadLogo() {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-20 16:38:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the legacy version of the skin is being used.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isLegacy() : bool {
|
|
|
|
$isLatestSkinFeatureEnabled = MediaWikiServices::getInstance()
|
|
|
|
->getService( Constants::SERVICE_FEATURE_MANAGER )
|
|
|
|
->isFeatureEnabled( Constants::FEATURE_LATEST_SKIN );
|
|
|
|
|
|
|
|
return !$isLatestSkinFeatureEnabled;
|
|
|
|
}
|
2020-05-18 18:55:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal only for use inside VectorTemplate
|
|
|
|
* @return array of data for a Mustache template
|
|
|
|
*/
|
|
|
|
public function getTemplateData() {
|
|
|
|
$out = $this->getOutput();
|
|
|
|
$title = $out->getTitle();
|
|
|
|
|
2020-06-03 19:41:59 +00:00
|
|
|
$indicators = [];
|
|
|
|
foreach ( $out->getIndicators() as $id => $content ) {
|
|
|
|
$indicators[] = [
|
|
|
|
'id' => Sanitizer::escapeIdForAttribute( "mw-indicator-$id" ),
|
|
|
|
'class' => 'mw-indicator',
|
|
|
|
'html' => $content,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-05-18 18:55:52 +00:00
|
|
|
return [
|
2020-06-03 19:41:59 +00:00
|
|
|
// Data objects:
|
|
|
|
'data-indicators' => $indicators,
|
2020-06-03 21:57:03 +00:00
|
|
|
// HTML strings:
|
|
|
|
'html-printtail' => WrappedString::join( "\n", [
|
|
|
|
MWDebug::getDebugHTML( $this->getContext() ),
|
|
|
|
$this->bottomScripts(),
|
|
|
|
wfReportTime( $out->getCSP()->getNonce() )
|
|
|
|
] ) . '</body></html>',
|
2020-05-18 18:55:52 +00:00
|
|
|
'html-sitenotice' => $this->getSiteNotice(),
|
|
|
|
'html-userlangattributes' => $this->prepareUserLanguageAttributes(),
|
|
|
|
'html-subtitle' => $this->prepareSubtitle(),
|
|
|
|
// Always returns string, cast to null if empty.
|
|
|
|
'html-undelete' => $this->prepareUndeleteLink() ?: null,
|
|
|
|
// Result of OutputPage::addHTML calls
|
|
|
|
'html-bodycontent' => $this->wrapHTML( $title, $out->mBodytext ),
|
|
|
|
'html-dataAfterContent' => $this->afterContentHook(),
|
|
|
|
// From MWDebug::getHTMLDebugLog (when $wgShowDebug is enabled)
|
|
|
|
'html-debuglog' => $this->generateDebugHTML(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal only for use inside VectorTemplate
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMenuProps() {
|
|
|
|
return $this->buildContentNavigationUrls();
|
|
|
|
}
|
2014-08-07 11:38:34 +00:00
|
|
|
}
|