Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.87% covered (success)
97.87%
46 / 47
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialNewPagesFeed
97.87% covered (success)
97.87%
46 / 47
75.00% covered (warning)
75.00%
3 / 4
8
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
1 / 1
5
 getListViewHtml
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\PageTriage;
4
5use Exception;
6use MediaWiki\Config\ConfigException;
7use MediaWiki\Html\Html;
8use MediaWiki\Html\TemplateParser;
9use MediaWiki\SpecialPage\SpecialPage;
10
11/**
12 * This file defines the SpecialNewPagesFeed class which handles the functionality for the
13 * New Pages Feed (Special:NewPagesFeed).
14 *
15 * @file
16 * @ingroup Extensions
17 * @author Ryan Kaldari
18 */
19class SpecialNewPagesFeed extends SpecialPage {
20
21    /**
22     * Initialize the special page.
23     *
24     * @throws Exception
25     */
26    public function __construct() {
27        parent::__construct( 'NewPagesFeed' );
28    }
29
30    /**
31     * Define what happens when the special page is loaded by the user.
32     * @param string $sub The subpage, if any
33     * @throws ConfigException
34     */
35    public function execute( $sub ) {
36        $this->addHelpLink( 'Help:New_pages_feed' );
37
38        $config = $this->getConfig();
39
40        $request = $this->getRequest();
41        $showOresFilters = PageTriageUtil::oresIsAvailable() &&
42            ( $config->get( 'PageTriageEnableOresFilters' ) || $request->getBool( 'ores' ) );
43        $showCopyvio = $showOresFilters &&
44            ( $config->get( 'PageTriageEnableCopyvio' ) || $request->getBool( 'copyvio' ) );
45        $this->setHeaders();
46        $out = $this->getOutput();
47
48        // Output the title of the page
49        $out->setPageTitleMsg( $this->msg( 'newpagesfeed' ) );
50
51        // Load common interface css
52        $out->addModuleStyles( [ 'mediawiki.interface.helpers.styles' ] );
53
54        // Set the config flags in JavaScript
55        $globalVars = [
56            'pageTriageNamespaces' => PageTriageUtil::getNamespaces(),
57            'wgPageTriageEnableExtendedFeatures' => $config->get( 'PageTriageEnableExtendedFeatures' ),
58            'wgShowOresFilters' => $showOresFilters,
59            'wgShowCopyvio' => $showCopyvio,
60        ];
61        $out->addJsConfigVars( $globalVars );
62        // Load the JS
63        $out->addModules( [
64            'ext.pageTriage.external',
65            'ext.pageTriage.util',
66            'ext.pageTriage.newPagesFeed'
67        ] );
68
69        $header = '';
70        $header .= '<div id="mwe-pt-list-warnings" style="display: none;">';
71        $parsedWelcomeMessage = $this->msg(
72            'pagetriage-welcome',
73            $config->get( 'PageTriageLearnMoreUrl' ),
74            $config->get( 'PageTriageFeedbackUrl' )
75        )->parse();
76        $header .= Html::rawElement( 'div', [ 'class' => 'plainlinks' ], $parsedWelcomeMessage );
77        $header .= '</div>';
78        $out->addHTML( $header );
79        $out->addInlineStyle(
80            '.client-nojs #mwe-pt-list-view, .client-js #mwe-pt-list-view-no-js { display: none; }'
81        );
82        // Output the HTML for the triage interface
83        $out->addHTML( $this->getListViewHtml() );
84    }
85
86    /**
87     * Get the list control nav HTML.
88     *
89     * @return string
90     */
91    private function getListViewHtml() {
92        $templateParser = new TemplateParser( __DIR__ . '/templates' );
93
94        // HTML for this is located in includes/templates/ListView.mustache
95        return $templateParser->processTemplate(
96            'ListView',
97            [
98                'pagetriage-please-wait' => $this->msg( 'pagetriage-please-wait' ),
99                'pagetriage-js-required' => $this->msg( 'pagetriage-js-required' ),
100            ]
101        );
102    }
103
104    /**
105     * @inheritDoc
106     */
107    protected function getGroupName() {
108        return 'changes';
109    }
110
111}