Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 74
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
StablePages
0.00% covered (danger)
0.00%
0 / 74
0.00% covered (danger)
0.00%
0 / 6
156
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 showForm
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
12
 showPageList
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 formatRow
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
20
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3use MediaWiki\Html\Html;
4use MediaWiki\MainConfigNames;
5use MediaWiki\SpecialPage\SpecialPage;
6use MediaWiki\Title\Title;
7
8/**
9 * Assumes $wgFlaggedRevsProtection is on
10 */
11class StablePages extends SpecialPage {
12    /** @var StablePagesPager */
13    private $pager = null;
14
15    /** @var int|null */
16    private $namespace;
17
18    /** @var string|null */
19    private $autoreview;
20
21    /** @var bool */
22    private $indef;
23
24    public function __construct() {
25        parent::__construct( 'StablePages' );
26    }
27
28    /**
29     * @inheritDoc
30     */
31    public function execute( $par ) {
32        $request = $this->getRequest();
33
34        $this->setHeaders();
35        $this->addHelpLink( 'Help:Extension:FlaggedRevs' );
36
37        $this->namespace = $request->getIntOrNull( 'namespace' );
38        $this->autoreview = $request->getVal( 'restriction', '' );
39        $this->indef = $request->getBool( 'indef' );
40
41        $this->pager = new StablePagesPager( $this, [],
42            $this->namespace, $this->autoreview, $this->indef );
43
44        $this->showForm();
45        $this->showPageList();
46    }
47
48    private function showForm() {
49        $this->getOutput()->addWikiMsg( 'stablepages-list',
50            $this->getLanguage()->formatNum( $this->pager->getNumRows() ) );
51
52        $fields = [];
53        // Namespace selector
54        if ( count( FlaggedRevs::getReviewNamespaces() ) > 1 ) {
55            $fields[] = FlaggedRevsHTML::getNamespaceMenu( $this->namespace, '' );
56        }
57        // Restriction level selector
58        if ( FlaggedRevs::getRestrictionLevels() ) {
59            $fields[] = FlaggedRevsHTML::getRestrictionFilterMenu( $this->autoreview );
60        }
61        $fields[] = Html::element( 'input', [
62            'type' => 'checkbox', 'name' => 'indef', 'value' => '1',
63            'checked' => $this->indef,
64            'id' => 'stablepages-indef',
65        ] )
66            . '&nbsp;'
67            . Html::label( $this->msg( 'stablepages-indef' )->text(), 'stablepages-indef' );
68
69        $form = Html::openElement( 'form', [
70            'name' => 'stablepages',
71            'action' => $this->getConfig()->get( MainConfigNames::Script ),
72            'method' => 'get',
73        ] );
74        $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() );
75        $form .= "<fieldset><legend>" . $this->msg( 'stablepages' )->escaped() . "</legend>\n";
76        $form .= implode( '&#160;', $fields ) . '&nbsp';
77        $form .= ' ' . Html::submitButton( $this->msg( 'go' )->text() );
78        $form .= "</fieldset>\n";
79        $form .= Html::closeElement( 'form' ) . "\n";
80
81        $this->getOutput()->addHTML( $form );
82    }
83
84    private function showPageList() {
85        $out = $this->getOutput();
86        if ( $this->pager->getNumRows() ) {
87            $out->addHTML( $this->pager->getNavigationBar() );
88            $out->addHTML( $this->pager->getBody() );
89            $out->addHTML( $this->pager->getNavigationBar() );
90        } else {
91            $out->addWikiMsg( 'stablepages-none' );
92        }
93    }
94
95    /**
96     * @param stdClass $row
97     * @return string HTML
98     */
99    public function formatRow( $row ) {
100        $title = Title::makeTitle( $row->page_namespace, $row->page_title );
101        $linkRenderer = $this->getLinkRenderer();
102        // Link to page
103        $link = $linkRenderer->makeLink( $title );
104        // Helpful utility links
105        $utilLinks = [];
106        $utilLinks[] = $linkRenderer->makeKnownLink(
107            $title,
108            $this->msg( 'stablepages-config' )->text(),
109            [], [ 'action' => 'protect' ] );
110        $utilLinks[] = $linkRenderer->makeKnownLink(
111            $title,
112            $this->msg( 'history' )->text(),
113            [], [ 'action' => 'history' ] );
114        $utilLinks[] = $linkRenderer->makeKnownLink(
115            SpecialPage::getTitleFor( 'Log', 'stable' ),
116            $this->msg( 'stable-logpage' )->text(),
117            [], [ 'page' => $title->getPrefixedText() ] );
118        // Autoreview/review restriction level
119        $restr = '';
120        if ( $row->fpc_level != '' ) {
121            $restr = 'autoreview=' . htmlspecialchars( $row->fpc_level );
122            $restr = "[$restr]";
123        }
124        // When these configuration settings expire
125        if ( $row->fpc_expiry != 'infinity' && strlen( $row->fpc_expiry ) ) {
126            $expiry_description = " (" . $this->msg(
127                'protect-expiring',
128                $this->getLanguage()->timeanddate( $row->fpc_expiry ),
129                $this->getLanguage()->date( $row->fpc_expiry ),
130                $this->getLanguage()->time( $row->fpc_expiry )
131            )->inContentLanguage()->text() . ")";
132        } else {
133            $expiry_description = "";
134        }
135        $utilLinks = $this->getLanguage()->pipeList( $utilLinks );
136        return "<li>{$link} ({$utilLinks}{$restr}<i>{$expiry_description}</i></li>";
137    }
138
139    /**
140     * @return string
141     */
142    protected function getGroupName() {
143        return 'quality';
144    }
145}