Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikimediaApiPortalTemplate
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 setSubpageDisplayTitle
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 getPrimaryNavSidebar
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * @file
18 */
19namespace MediaWiki\Skin\WikimediaApiPortal;
20
21use BaseTemplate;
22use MediaWiki\MediaWikiServices;
23use MediaWiki\Title\Title;
24
25/**
26 * Class WikimediaApiPortalTemplate
27 * @package MediaWiki\Skin\WikimediaApiPortal
28 * @method Skin getSkin()
29 */
30class WikimediaApiPortalTemplate extends BaseTemplate {
31
32    public function execute() {
33        $this->setSubpageDisplayTitle();
34
35        $templateParser = new TemplateParser( __DIR__ . '/../components' );
36        $templateParser->enableRecursivePartials( true );
37
38        $componentFactory = MediaWikiServices::getInstance()
39            ->getService( 'WAPSkinComponentFactory' );
40
41        echo $componentFactory
42            ->createMainComponent( $this )
43            ->parseTemplate( $templateParser );
44    }
45
46    /**
47     * Set page title to the last subpage only, since the subpage structure
48     * will be shown in the navigation and bread crumbs
49     *
50     * Subpages will display only the last part of the page as the page title.
51     * This is done to allow for the site to be structured using subpages,
52     * while still keeping the page names that are display nice
53     */
54    private function setSubpageDisplayTitle() {
55        $requestedAction = $this->getSkin()->getRequest()->getRawVal( 'action', 'view' );
56        if ( $requestedAction !== 'view' ) {
57            return;
58        }
59        $title = $this->getSkin()->getTitle();
60        if ( !MediaWikiServices::getInstance()
61            ->getNamespaceInfo()
62            ->hasSubpages( $title->getNamespace() ) ) {
63            return;
64        }
65        if ( $title->isSubpage() ) {
66            $newTitle = Title::makeTitle( $title->getNamespace(), $title->getSubpageText() );
67            $this->set( 'title', $newTitle->getPrefixedText() );
68        }
69    }
70
71    /** @return array */
72    public function getPrimaryNavSidebar() {
73        return $this->getSidebar( [
74            'search' => false,
75            'toolbox' => false,
76            'languages' => false,
77        ] );
78    }
79}