File: HTMLInfoField.php

package info (click to toggle)
mediawiki 1%3A1.35.13-1%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 274,932 kB
  • sloc: php: 677,563; javascript: 572,709; sql: 11,565; python: 4,447; xml: 3,145; sh: 892; perl: 788; ruby: 496; pascal: 365; makefile: 128
file content (125 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php

/**
 * An information field (text blob), not a proper input.
 * @stable to extend
 */
class HTMLInfoField extends HTMLFormField {
	/**
	 * @stable to call
	 *
	 * @param array $info
	 *   In adition to the usual HTMLFormField parameters, this can take the following fields:
	 *   - default: the value (text) of the field. Unlike other form field types, HTMLInfoField can
	 *     take a closure as a default value, which will be evaluated with $info as its only parameter.
	 *   - raw: if true, the value won't be escaped.
	 *   - rawrow: if true, the usual wrapping of form fields (e.g. into a table row + cell when
	 *     display mode is table) will not happen and the value must contain it already.
	 */
	public function __construct( $info ) {
		$info['nodata'] = true;

		parent::__construct( $info );
	}

	/**
	 * @inheritDoc
	 * @stable to override
	 */
	public function getDefault() {
		$default = parent::getDefault();
		if ( $default instanceof Closure ) {
			$default = $default( $this->mParams );
		}
		return $default;
	}

	/**
	 * @inheritDoc
	 * @stable to override
	 */
	public function getInputHTML( $value ) {
		return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value );
	}

	/**
	 * @inheritDoc
	 * @stable to override
	 */
	public function getInputOOUI( $value ) {
		if ( !empty( $this->mParams['raw'] ) ) {
			$value = new OOUI\HtmlSnippet( $value );
		}

		return new OOUI\LabelWidget( [
			'label' => $value,
		] );
	}

	/**
	 * @inheritDoc
	 * @stable to override
	 */
	public function getTableRow( $value ) {
		if ( !empty( $this->mParams['rawrow'] ) ) {
			return $value;
		}

		return parent::getTableRow( $value );
	}

	/**
	 * @stable to override
	 * @param string $value
	 * @return string
	 * @since 1.20
	 */
	public function getDiv( $value ) {
		if ( !empty( $this->mParams['rawrow'] ) ) {
			return $value;
		}

		return parent::getDiv( $value );
	}

	/**
	 * @stable to override
	 * @param string $value
	 * @return string
	 * @since 1.20
	 */
	public function getRaw( $value ) {
		if ( !empty( $this->mParams['rawrow'] ) ) {
			return $value;
		}

		return parent::getRaw( $value );
	}

	/**
	 * @stable to override
	 * @param mixed $value If not FieldLayout or subclass has been deprecated.
	 * @return OOUI\FieldLayout
	 * @since 1.32
	 */
	public function getOOUI( $value ) {
		if ( !empty( $this->mParams['rawrow'] ) ) {
			if ( !( $value instanceof OOUI\FieldLayout ) ) {
				wfDeprecatedMsg( __METHOD__ . ": 'default' parameter as a string when using " .
					"'rawrow' was deprecated in MediaWiki 1.32 (must be a FieldLayout or subclass)",
					'1.32' );
			}
			return $value;
		}

		return parent::getOOUI( $value );
	}

	/**
	 * @inheritDoc
	 * @stable to override
	 */
	protected function needsLabel() {
		return false;
	}
}