1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?php
/**
* A size filter field for use on query-type special pages. It looks a bit like:
*
* (o) Min size ( ) Max size: [ ] bytes
*
* Minimum size limits are represented using a positive integer, while maximum
* size limits are represented using a negative integer.
*/
class HTMLSizeFilterField extends HTMLIntField {
public function getSize() {
return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 9;
}
public function getInputHTML( $value ) {
$attribs = [];
if ( !empty( $this->mParams['disabled'] ) ) {
$attribs['disabled'] = 'disabled';
}
$html = Xml::radioLabel(
$this->msg( 'minimum-size' )->text(),
$this->mName . '-mode',
'min',
$this->mID . '-mode-min',
$value >= 0,
$attribs
);
$html .= ' ' . Xml::radioLabel(
$this->msg( 'maximum-size' )->text(),
$this->mName . '-mode',
'max',
$this->mID . '-mode-max',
$value < 0,
$attribs
);
$html .= ' ' . parent::getInputHTML( $value ? abs( $value ) : '' );
$html .= ' ' . $this->msg( 'pagesize' )->parse();
return $html;
}
protected function getInputWidget( $params ) {
$this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SizeFilterWidget.styles' );
// negative numbers represent "max", positive numbers represent "min"
$value = $params['value'];
$params['value'] = $value ? abs( $value ) : '';
return new MediaWiki\Widget\SizeFilterWidget( [
'selectMin' => $value >= 0,
'textinput' => $params,
'radioselectinput' => [
'name' => $this->mName . '-mode',
'disabled' => !empty( $this->mParams['disabled'] ),
],
] );
}
protected function getOOUIModules() {
return [ 'mediawiki.widgets.SizeFilterWidget' ];
}
/**
* @param WebRequest $request
*
* @return string|int
*/
public function loadDataFromRequest( $request ) {
$size = $request->getInt( $this->mName );
if ( !$size ) {
return $this->getDefault();
}
$size = abs( $size );
// negative numbers represent "max", positive numbers represent "min"
if ( $request->getVal( $this->mName . '-mode' ) === 'max' ) {
return -$size;
} else {
return $size;
}
}
protected function needsLabel() {
return false;
}
}
|