config = $config; $this->localizer = $localizer; $this->title = $title; $this->user = $user; $this->numLanguages = $numLanguages; $this->sidebarData = $sidebarData; $this->languagesData = $languagesData; $this->variantsData = $variantsData; } /** * Extract article tools from sidebar and return the data * * The reason we do this is because: * 1. We removed some site-wide tools from the toolbar in Drawer.php, * now we just want the leftovers * 2. Toolbox is not currently avaliable as data-portlet, have to wait * till Desktop Improvements * * @return array */ private function getArticleToolsData(): array { $data = [ 'is-empty' => true, ]; foreach ( $this->sidebarData['array-portlets-rest'] as $portlet ) { if ( $portlet['id'] === 'p-tb' ) { $data = $portlet; $data['is-empty'] = false; break; } } return $data; } /** * Check if views and actions should show * * 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 * * @return bool */ private function shouldShowPageTools(): bool { $condition = $this->config->get( 'CitizenShowPageTools' ); $user = $this->user; // Login-based condition, return true if condition is met if ( $condition === 'login' ) { $condition = $user->isRegistered(); } // Permission-based condition, return true if condition is met if ( is_string( $condition ) && strpos( $condition, 'permission' ) === 0 ) { $permission = substr( $condition, 11 ); try { $title = $this->title; $condition = MediaWikiServices::getInstance()->getPermissionManager()->userCan( $permission, $user, $title ); } catch ( Exception $e ) { $condition = false; } } return (bool)$condition; } /** * @inheritDoc */ public function getTemplateData(): array { $hasLanguages = ( $this->languagesData && $this->languagesData[ 'is-empty' ] !== true ) || ( $this->variantsData && $this->variantsData[ 'is-empty' ] !== true ); $articleTools = $this->getArticleToolsData(); return [ 'data-article-tools' => $articleTools, 'is-visible' => $this->shouldShowPageTools(), // There are edge cases where the menu is completely empty 'has-overflow' => (bool)$articleTools, 'has-languages' => $hasLanguages, /* * FIXME: ULS does not trigger for some reason, disabling it for now * 'is-uls-ready' => $this->shouldShowULS( $variantsData ), */ 'is-uls-ready' => false, 'int-language-count' => $this->numLanguages ]; } }