Instead of accessing $data property use set/get/html methods
For better encapsulation and future possibility to create Skin API we have to stop accesing properties and start using getters/setters instead. Once we start doing that we should be able to provide a clear interface for our templating system. Bug: T246161 Change-Id: Ib3539b1e3bc12341c79913af3c95acad8619cff4
This commit is contained in:
parent
611c4ae035
commit
48988c8ab0
|
@ -58,10 +58,11 @@ class VectorTemplate extends BaseTemplate {
|
||||||
* Outputs the entire contents of the HTML page
|
* Outputs the entire contents of the HTML page
|
||||||
*/
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$this->data['namespace_urls'] = $this->data['content_navigation']['namespaces'];
|
$contentNavigation = $this->get( 'content_navigation', [] );
|
||||||
$this->data['view_urls'] = $this->data['content_navigation']['views'];
|
$this->set( 'namespace_urls', $contentNavigation[ 'namespaces' ] );
|
||||||
$this->data['action_urls'] = $this->data['content_navigation']['actions'];
|
$this->set( 'view_urls', $contentNavigation[ 'views' ] );
|
||||||
$this->data['variant_urls'] = $this->data['content_navigation']['variants'];
|
$this->set( 'action_urls', $contentNavigation[ 'actions' ] );
|
||||||
|
$this->set( 'variant_urls', $contentNavigation[ 'variants' ] );
|
||||||
|
|
||||||
// Move the watch/unwatch star outside of the collapsed "actions" menu to the main "views" menu
|
// Move the watch/unwatch star outside of the collapsed "actions" menu to the main "views" menu
|
||||||
if ( $this->config->get( 'VectorUseIconWatch' ) ) {
|
if ( $this->config->get( 'VectorUseIconWatch' ) ) {
|
||||||
|
@ -76,9 +77,13 @@ class VectorTemplate extends BaseTemplate {
|
||||||
)
|
)
|
||||||
) ? 'unwatch' : 'watch';
|
) ? 'unwatch' : 'watch';
|
||||||
|
|
||||||
if ( isset( $this->data['action_urls'][$mode] ) ) {
|
$actionUrls = $this->get( 'action_urls', [] );
|
||||||
$this->data['view_urls'][$mode] = $this->data['action_urls'][$mode];
|
if ( array_key_exists( $mode, $actionUrls ) ) {
|
||||||
unset( $this->data['action_urls'][$mode] );
|
$viewUrls = $this->get( 'view_urls' );
|
||||||
|
$viewUrls[ $mode ] = $actionUrls[ $mode ];
|
||||||
|
unset( $actionUrls[ $mode ] );
|
||||||
|
$this->set( 'view_urls', $viewUrls );
|
||||||
|
$this->set( 'action_urls', $actionUrls );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +107,7 @@ class VectorTemplate extends BaseTemplate {
|
||||||
'html-sitenotice' => $this->get( 'sitenotice', null ),
|
'html-sitenotice' => $this->get( 'sitenotice', null ),
|
||||||
'html-indicators' => $this->getIndicators(),
|
'html-indicators' => $this->getIndicators(),
|
||||||
'page-langcode' => $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode(),
|
'page-langcode' => $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode(),
|
||||||
'page-isarticle' => (bool)$this->data['isarticle'],
|
'page-isarticle' => (bool)$this->get( 'isarticle' ),
|
||||||
|
|
||||||
// Remember that the string '0' is a valid title.
|
// Remember that the string '0' is a valid title.
|
||||||
// From OutputPage::getPageTitle, via ::setPageTitle().
|
// From OutputPage::getPageTitle, via ::setPageTitle().
|
||||||
|
@ -158,7 +163,7 @@ class VectorTemplate extends BaseTemplate {
|
||||||
'href' => Skin::makeMainPageUrl(),
|
'href' => Skin::makeMainPageUrl(),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
] + $this->buildSidebarProps( $this->data['sidebar'] )
|
] + $this->buildSidebarProps( $this->get( 'sidebar', [] ) )
|
||||||
),
|
),
|
||||||
] ),
|
] ),
|
||||||
];
|
];
|
||||||
|
@ -253,9 +258,9 @@ class VectorTemplate extends BaseTemplate {
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 'LANGUAGES':
|
case 'LANGUAGES':
|
||||||
if ( $this->data['language_urls'] !== false ) {
|
if ( $this->get( 'language_urls' ) !== false ) {
|
||||||
$props[] = $this->buildPortalProps(
|
$props[] = $this->buildPortalProps(
|
||||||
'lang', $this->data['language_urls'], 'otherlanguages'
|
'lang', $this->get( 'language_urls' ), 'otherlanguages'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -288,7 +293,7 @@ class VectorTemplate extends BaseTemplate {
|
||||||
'html-tooltip' => Linker::tooltip( 'p-' . $name ),
|
'html-tooltip' => Linker::tooltip( 'p-' . $name ),
|
||||||
'msg-label' => $msgObj->exists() ? $msgObj->text() : $msg,
|
'msg-label' => $msgObj->exists() ? $msgObj->text() : $msg,
|
||||||
'msg-label-id' => "p-$name-label",
|
'msg-label-id' => "p-$name-label",
|
||||||
'html-userlangattributes' => $this->data['userlangattributes'] ?? '',
|
'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
|
||||||
'html-portal-content' => '',
|
'html-portal-content' => '',
|
||||||
'html-after-portal' => $this->getAfterPortlet( $name ),
|
'html-after-portal' => $this->getAfterPortlet( $name ),
|
||||||
];
|
];
|
||||||
|
@ -349,14 +354,14 @@ class VectorTemplate extends BaseTemplate {
|
||||||
private function buildNamespacesProps() : array {
|
private function buildNamespacesProps() : array {
|
||||||
$props = [
|
$props = [
|
||||||
'tabs-id' => 'p-namespaces',
|
'tabs-id' => 'p-namespaces',
|
||||||
'empty-portlet' => ( count( $this->data['namespace_urls'] ) == 0 ) ? 'emptyPortlet' : '',
|
'empty-portlet' => ( count( $this->get( 'namespace_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '',
|
||||||
'label-id' => 'p-namespaces-label',
|
'label-id' => 'p-namespaces-label',
|
||||||
'msg-label' => $this->getMsg( 'namespaces' )->text(),
|
'msg-label' => $this->getMsg( 'namespaces' )->text(),
|
||||||
'html-userlangattributes' => $this->data['userlangattributes'] ?? '',
|
'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
|
||||||
'html-items' => '',
|
'html-items' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ( $this->data['namespace_urls'] as $key => $item ) {
|
foreach ( $this->get( 'namespace_urls', [] ) as $key => $item ) {
|
||||||
$props[ 'html-items' ] .= $this->makeListItem( $key, $item );
|
$props[ 'html-items' ] .= $this->makeListItem( $key, $item );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +373,7 @@ class VectorTemplate extends BaseTemplate {
|
||||||
*/
|
*/
|
||||||
private function buildVariantsProps() : array {
|
private function buildVariantsProps() : array {
|
||||||
$props = [
|
$props = [
|
||||||
'empty-portlet' => ( count( $this->data['variant_urls'] ) == 0 ) ? 'emptyPortlet' : '',
|
'empty-portlet' => ( count( $this->get( 'variant_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '',
|
||||||
'menu-id' => 'p-variants',
|
'menu-id' => 'p-variants',
|
||||||
'menu-label-id' => 'p-variants-label',
|
'menu-label-id' => 'p-variants-label',
|
||||||
'msg-label' => $this->getMsg( 'variants' )->text(),
|
'msg-label' => $this->getMsg( 'variants' )->text(),
|
||||||
|
@ -376,14 +381,15 @@ class VectorTemplate extends BaseTemplate {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Replace the label with the name of currently chosen variant, if any
|
// Replace the label with the name of currently chosen variant, if any
|
||||||
foreach ( $this->data['variant_urls'] as $item ) {
|
$variantUrls = $this->get( 'variant_urls', [] );
|
||||||
|
foreach ( $variantUrls as $item ) {
|
||||||
if ( isset( $item['class'] ) && stripos( $item['class'], 'selected' ) !== false ) {
|
if ( isset( $item['class'] ) && stripos( $item['class'], 'selected' ) !== false ) {
|
||||||
$props['msg-label'] = $item['text'];
|
$props['msg-label'] = $item['text'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $this->data['variant_urls'] as $key => $item ) {
|
foreach ( $variantUrls as $key => $item ) {
|
||||||
$props['html-items'] .= $this->makeListItem( $key, $item );
|
$props['html-items'] .= $this->makeListItem( $key, $item );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,14 +402,14 @@ class VectorTemplate extends BaseTemplate {
|
||||||
private function buildViewsProps() : array {
|
private function buildViewsProps() : array {
|
||||||
$props = [
|
$props = [
|
||||||
'tabs-id' => 'p-views',
|
'tabs-id' => 'p-views',
|
||||||
'empty-portlet' => ( count( $this->data['view_urls'] ) == 0 ) ? 'emptyPortlet' : '',
|
'empty-portlet' => ( count( $this->get( 'view_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '',
|
||||||
'label-id' => 'p-views-label',
|
'label-id' => 'p-views-label',
|
||||||
'msg-label' => $this->getMsg( 'views' )->text(),
|
'msg-label' => $this->getMsg( 'views' )->text(),
|
||||||
'html-userlangattributes' => $this->data['userlangattributes'] ?? '',
|
'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
|
||||||
'html-items' => '',
|
'html-items' => '',
|
||||||
];
|
];
|
||||||
|
$viewUrls = $this->get( 'view_urls', [] );
|
||||||
foreach ( $this->data['view_urls'] as $key => $item ) {
|
foreach ( $viewUrls as $key => $item ) {
|
||||||
$props[ 'html-items' ] .= $this->makeListItem( $key, $item, [
|
$props[ 'html-items' ] .= $this->makeListItem( $key, $item, [
|
||||||
'vector-collapsible' => true,
|
'vector-collapsible' => true,
|
||||||
] );
|
] );
|
||||||
|
@ -417,15 +423,16 @@ class VectorTemplate extends BaseTemplate {
|
||||||
*/
|
*/
|
||||||
private function buildActionsProps() : array {
|
private function buildActionsProps() : array {
|
||||||
$props = [
|
$props = [
|
||||||
'empty-portlet' => ( count( $this->data['action_urls'] ) == 0 ) ? 'emptyPortlet' : '',
|
'empty-portlet' => ( count( $this->get( 'action_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '',
|
||||||
'msg-label' => $this->getMsg( 'vector-more-actions' )->text(),
|
'msg-label' => $this->getMsg( 'vector-more-actions' )->text(),
|
||||||
'menu-id' => 'p-cactions',
|
'menu-id' => 'p-cactions',
|
||||||
'menu-label-id' => 'p-cactions-label',
|
'menu-label-id' => 'p-cactions-label',
|
||||||
'html-userlangattributes' => $this->data[ 'userlangattributes' ] ?? '',
|
'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
|
||||||
'html-items' => '',
|
'html-items' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ( $this->data['action_urls'] as $key => $item ) {
|
$actionUrls = $this->get( 'action_urls', [] );
|
||||||
|
foreach ( $actionUrls as $key => $item ) {
|
||||||
$props['html-items'] .= $this->makeListItem( $key, $item );
|
$props['html-items'] .= $this->makeListItem( $key, $item );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,9 +445,9 @@ class VectorTemplate extends BaseTemplate {
|
||||||
private function buildPersonalProps() : array {
|
private function buildPersonalProps() : array {
|
||||||
$personalTools = $this->getPersonalTools();
|
$personalTools = $this->getPersonalTools();
|
||||||
$props = [
|
$props = [
|
||||||
'empty-portlet' => ( count( $this->data['personal_urls'] ) == 0 ) ? 'emptyPortlet' : '',
|
'empty-portlet' => ( count( $this->get( 'personal_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '',
|
||||||
'msg-label' => $this->getMsg( 'personaltools' )->text(),
|
'msg-label' => $this->getMsg( 'personaltools' )->text(),
|
||||||
'html-userlangattributes' => $this->data[ 'userlangattributes' ] ?? '',
|
'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
|
||||||
'html-loggedin' => '',
|
'html-loggedin' => '',
|
||||||
'html-personal-tools' => '',
|
'html-personal-tools' => '',
|
||||||
'html-lang-selector' => '',
|
'html-lang-selector' => '',
|
||||||
|
@ -472,11 +479,11 @@ class VectorTemplate extends BaseTemplate {
|
||||||
*/
|
*/
|
||||||
private function buildSearchProps() : array {
|
private function buildSearchProps() : array {
|
||||||
$props = [
|
$props = [
|
||||||
'searchHeaderAttrsHTML' => $this->data[ 'userlangattributes' ] ?? '',
|
'searchHeaderAttrsHTML' => $this->get( 'userlangattributes', '' ),
|
||||||
'searchActionURL' => $this->data[ 'wgScript' ] ?? '',
|
'searchActionURL' => $this->get( 'wgScript', '' ),
|
||||||
'searchDivID' => $this->config->get( 'VectorUseSimpleSearch' ) ? 'simpleSearch' : '',
|
'searchDivID' => $this->config->get( 'VectorUseSimpleSearch' ) ? 'simpleSearch' : '',
|
||||||
'searchInputHTML' => $this->makeSearchInput( [ 'id' => 'searchInput' ] ),
|
'searchInputHTML' => $this->makeSearchInput( [ 'id' => 'searchInput' ] ),
|
||||||
'titleHTML' => Html::hidden( 'title', $this->data[ 'searchtitle' ] ?? null ),
|
'titleHTML' => Html::hidden( 'title', $this->get( 'searchtitle', null ) ),
|
||||||
'fallbackSearchButtonHTML' => $this->makeSearchButton(
|
'fallbackSearchButtonHTML' => $this->makeSearchButton(
|
||||||
'fulltext',
|
'fulltext',
|
||||||
[ 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ]
|
[ 'id' => 'mw-searchButton', 'class' => 'searchButton mw-fallbackSearchButton' ]
|
||||||
|
|
Loading…
Reference in New Issue