Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 86 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ConfiguredPages | |
0.00% |
0 / 86 |
|
0.00% |
0 / 6 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
showForm | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
12 | |||
showPageList | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
formatRow | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
30 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\Html\Html; |
4 | use MediaWiki\MainConfigNames; |
5 | use MediaWiki\SpecialPage\SpecialPage; |
6 | use MediaWiki\Title\Title; |
7 | |
8 | // Assumes $wgFlaggedRevsProtection is off |
9 | class ConfiguredPages extends SpecialPage { |
10 | /** @var ConfiguredPagesPager|null */ |
11 | private $pager = null; |
12 | |
13 | /** @var int|null */ |
14 | private $namespace; |
15 | |
16 | /** @var int|null */ |
17 | private $override; |
18 | |
19 | /** @var string|null */ |
20 | private $autoreview; |
21 | |
22 | public function __construct() { |
23 | parent::__construct( 'ConfiguredPages' ); |
24 | } |
25 | |
26 | /** |
27 | * @inheritDoc |
28 | */ |
29 | public function execute( $par ) { |
30 | $request = $this->getRequest(); |
31 | |
32 | $this->setHeaders(); |
33 | $this->addHelpLink( 'Help:Extension:FlaggedRevs' ); |
34 | |
35 | $this->namespace = $request->getIntOrNull( 'namespace' ); |
36 | $this->override = $request->getIntOrNull( 'stable' ); |
37 | $this->autoreview = $request->getVal( 'restriction', '' ); |
38 | |
39 | $this->pager = new ConfiguredPagesPager( |
40 | $this, [], $this->namespace, $this->override, $this->autoreview ); |
41 | |
42 | $this->showForm(); |
43 | $this->showPageList(); |
44 | } |
45 | |
46 | private function showForm() { |
47 | # Explanatory text |
48 | $this->getOutput()->addWikiMsg( 'configuredpages-list', |
49 | $this->getLanguage()->formatNum( $this->pager->getNumRows() ) ); |
50 | |
51 | $form = Html::openElement( 'form', [ |
52 | 'name' => 'configuredpages', |
53 | 'action' => $this->getConfig()->get( MainConfigNames::Script ), |
54 | 'method' => 'get', |
55 | 'class' => 'mw-fr-form-container' |
56 | ] ) . "\n"; |
57 | |
58 | $form .= Html::openElement( 'fieldset', [ 'class' => 'cdx-field' ] ) . "\n"; |
59 | |
60 | $form .= Html::openElement( 'legend', [ 'class' => 'cdx-label' ] ) . "\n"; |
61 | $form .= Html::rawElement( 'span', [ 'class' => 'cdx-label__label' ], |
62 | Html::element( 'span', [ 'class' => 'cdx-label__label__text' ], |
63 | $this->msg( 'configuredpages' )->text() ) |
64 | ); |
65 | $form .= Html::closeElement( 'legend' ) . "\n"; |
66 | |
67 | $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) . "\n"; |
68 | |
69 | $form .= Html::openElement( 'div', [ 'class' => 'cdx-field__control' ] ) . "\n"; |
70 | |
71 | # Namespace selector |
72 | if ( count( FlaggedRevs::getReviewNamespaces() ) > 1 ) { |
73 | $form .= Html::rawElement( |
74 | 'div', |
75 | [ 'class' => 'cdx-field__item' ], |
76 | FlaggedRevsHTML::getNamespaceMenu( $this->namespace, '' ) |
77 | ); |
78 | } |
79 | |
80 | # Default version selector |
81 | $form .= Html::rawElement( |
82 | 'div', |
83 | [ 'class' => 'cdx-field__item' ], |
84 | FlaggedRevsHTML::getDefaultFilterMenu( $this->override ) |
85 | ); |
86 | |
87 | # Restriction level selector |
88 | if ( FlaggedRevs::getRestrictionLevels() ) { |
89 | $form .= Html::rawElement( |
90 | 'div', |
91 | [ 'class' => 'cdx-field__item' ], |
92 | FlaggedRevsHTML::getRestrictionFilterMenu( $this->autoreview ) |
93 | ); |
94 | } |
95 | |
96 | $form .= Html::closeElement( 'div' ) . "\n"; |
97 | |
98 | $form .= Html::rawElement( |
99 | 'div', |
100 | [ 'class' => 'cdx-field__control' ], |
101 | Html::submitButton( $this->msg( 'go' )->text(), [ |
102 | 'class' => 'cdx-button cdx-button--action-progressive' |
103 | ] ) |
104 | ) . "\n"; |
105 | |
106 | $form .= Html::closeElement( 'fieldset' ) . "\n"; |
107 | $form .= Html::closeElement( 'form' ) . "\n"; |
108 | |
109 | $this->getOutput()->addHTML( $form ); |
110 | } |
111 | |
112 | private function showPageList() { |
113 | if ( $this->pager->getNumRows() ) { |
114 | $this->getOutput()->addHTML( $this->pager->getNavigationBar() ); |
115 | $this->getOutput()->addHTML( $this->pager->getBody() ); |
116 | $this->getOutput()->addHTML( $this->pager->getNavigationBar() ); |
117 | } else { |
118 | $this->getOutput()->addWikiMsg( 'configuredpages-none' ); |
119 | } |
120 | } |
121 | |
122 | /** |
123 | * @param stdClass $row |
124 | * @return string HTML |
125 | */ |
126 | public function formatRow( $row ) { |
127 | $title = Title::newFromRow( $row ); |
128 | # Link to page |
129 | $linkRenderer = $this->getLinkRenderer(); |
130 | $link = $linkRenderer->makeLink( $title ); |
131 | # Link to page configuration |
132 | $config = $linkRenderer->makeKnownLink( |
133 | SpecialPage::getTitleFor( 'Stabilization' ), |
134 | $this->msg( 'configuredpages-config' )->text(), |
135 | [], |
136 | [ 'page' => $title->getPrefixedDBkey() ] |
137 | ); |
138 | # Show which version is the default (stable or draft) |
139 | $msg = $row->fpc_override ? 'configuredpages-def-stable' : 'configuredpages-def-draft'; |
140 | $default = $this->msg( $msg )->escaped(); |
141 | # Autoreview/review restriction level |
142 | $restr = ''; |
143 | if ( $row->fpc_level != '' ) { |
144 | $restr = '[autoreview=' . htmlspecialchars( $row->fpc_level ) . ']'; |
145 | } |
146 | # When these configuration settings expire |
147 | if ( $row->fpc_expiry != 'infinity' && strlen( $row->fpc_expiry ) ) { |
148 | $expiry_description = " (" . $this->msg( |
149 | 'protect-expiring', |
150 | $this->getLanguage()->timeanddate( $row->fpc_expiry ), |
151 | $this->getLanguage()->date( $row->fpc_expiry ), |
152 | $this->getLanguage()->time( $row->fpc_expiry ) |
153 | )->inContentLanguage()->text() . ")"; |
154 | } else { |
155 | $expiry_description = ""; |
156 | } |
157 | return "<li>{$link} ({$config}) <b>[$default]</b> " . |
158 | "{$restr}<i>{$expiry_description}</i></li>"; |
159 | } |
160 | |
161 | /** |
162 | * @return string |
163 | */ |
164 | protected function getGroupName() { |
165 | return 'quality'; |
166 | } |
167 | } |