summaryrefslogtreecommitdiff
path: root/www/wiki/skins/chameleon/src/Components/MainContent.php
blob: c732bd24da9a20d8ac09aeddd42d768074a52957 (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/**
 * File holding the MainContent class
 *
 * This file is part of the MediaWiki skin Chameleon.
 *
 * @copyright 2013 - 2016, Stephan Gambke
 * @license   GNU General Public License, version 3 (or any later version)
 *
 * The Chameleon skin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * The Chameleon skin is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * @file
 * @ingroup   Skins
 */

namespace Skins\Chameleon\Components;

use Skins\Chameleon\IdRegistry;

/**
 * The MainContent class.
 *
 * @author Stephan Gambke
 * @since 1.0
 * @ingroup Skins
 */
class MainContent extends Component {

	/**
	 * Builds the HTML code for this component
	 *
	 * @return String the HTML code
	 */
	public function getHtml() {

		$skintemplate = $this->getSkinTemplate();
		$idRegistry = IdRegistry::getRegistry();

		// START content
		$ret =
			$this->indent() . '<!-- start the content area -->' .
			$this->indent() . $idRegistry->openElement( 'div',
				array( 'id' => 'content', 'class' => 'mw-body ' . $this->getClassString() )
			) .

			$idRegistry->element( 'a', array( 'id' => 'top' ) ) .
			$this->indent(1) . $idRegistry->element( 'div', array( 'id' => 'mw-indicators', 'class' => 'mw-indicators',  ), $this->buildMwIndicators() ) .

			$this->indent() . '<div ' . \Html::expandAttributes( array(
					'id'    => $idRegistry->getId( 'mw-js-message' ),
					'style' => 'display:none;'
				)
			) . $skintemplate->get( 'userlangattributes' ) . '></div>';

		$ret .= $this->buildContentHeader();

		// if ( $skintemplate->get( 'subtitle' ) ) {

			// TODO: should not use class 'small', better use class 'contentSub' and do styling in a less file
			$ret .=
				$this->indent() . '<!-- subtitle line; used for various things like the subpage hierarchy -->' .
				$this->indent() . $idRegistry->element( 'div', array( 'id' => 'contentSub', 'class' => 'small' ), $skintemplate->get( 'subtitle' ) );

		// }

		if ( $skintemplate->get( 'undelete' ) ) {
			// TODO: should not use class 'small', better use class 'contentSub2' and do styling in a less file
			$ret .=
				$this->indent() . '<!-- undelete message -->' .
				$this->indent() . $idRegistry->element( 'div', array( 'id' => 'contentSub2', 'class' => 'small' ), $skintemplate->get( 'undelete' ) );
		}


		$ret .= $this->buildContentBody();
		$ret .= $this->buildCategoryLinks();

		$ret .= $this->indent( -1 ) . '</div>';
		// END content

		return $ret;
	}

	/**
	 * @return string
	 */
	protected function buildContentHeader() {

		$skintemplate = $this->getSkinTemplate();
		$idRegistry = IdRegistry::getRegistry();

		$ret = $this->indent() . '<div class ="contentHeader">' .

			$this->indent( 1 ) . '<!-- title of the page -->' .
			$this->indent() . $idRegistry->element( 'h1', array( 'id' => 'firstHeading', 'class' => 'firstHeading' ), $skintemplate->get( 'title' ) ) .

			$this->indent() . '<!-- tagline; usually goes something like "From WikiName" primary purpose of this seems to be for printing to identify the source of the content -->' .
			$this->indent() . $idRegistry->element( 'div', array( 'id'=> 'siteSub' ), $skintemplate->getMsg( 'tagline' )->escaped() );

		if ( $skintemplate->get( 'subtitle' ) ) {

			// TODO: should not use class 'small', better use class 'contentSub' and do styling in a less file
			$ret .=
				$this->indent() . '<!-- subtitle line; used for various things like the subpage hierarchy -->' .
				$this->indent() . $idRegistry->element( 'div', array( 'id' => 'contentSub', 'class' => 'small' ), $skintemplate->get( 'subtitle' ) );

		}

		if ( $skintemplate->get( 'undelete' ) ) {
			// TODO: should not use class 'small', better use class 'contentSub2' and do styling in a less file
			$ret .=
				$this->indent() . '<!-- undelete message -->' .
				$this->indent() . $idRegistry->element( 'div', array( 'id' => 'contentSub2', 'class' => 'small' ), $skintemplate->get( 'undelete' ) );
		}

		// TODO: Do we need this? Seems to be an accessibility thing. It's used
		// in vector to jump to the nav which is at the bottom of the document,
		// but our nav is usually at the top
		$ret .= $idRegistry->element( 'div', array( 'id' => 'jump-to-nav', 'class' => 'mw-jump' ),
			$skintemplate->getMsg( 'jumpto' )->escaped() . '<a href="#mw-navigation">' . $skintemplate->getMsg( 'jumptonavigation' )->escaped() . '</a>' .
			$skintemplate->getMsg( 'comma-separator' )->escaped() . '<a href="#p-search">' . $skintemplate->getMsg( 'jumptosearch' )->escaped() . '</a>'
		);

		$ret .= $this->indent( -1 ) . '</div>';
		return $ret;
	}

	/**
	 * @return string
	 */
	protected function buildContentBody() {
		return $this->indent() . IdRegistry::getRegistry()->element( 'div', array( 'id' => 'bodyContent' ),
			$this->indent( 1 ) . '<!-- body text -->' . "\n" .
			$this->indent() . $this->getSkinTemplate()->get( 'bodytext' ) .
			$this->indent() . '<!-- end body text -->' .
			$this->buildDataAfterContent() .
			$this->indent( -1 )
		);
	}

	/**
	 * @return string
	 */
	protected function buildCategoryLinks() {
		// TODO: Category links should be a separate component, but
		// * dataAfterContent should come after the the category links.
		// * only one extension is known to use it dataAfterContent and it is geared specifically towards MonoBook
		// => provide an attribute hideCatLinks for the XML and -if present- hide category links and assume somebody knows what they are doing
		return
			$this->indent() . '<!-- category links -->' .
			$this->indent() . $this->getSkinTemplate()->get( 'catlinks' );
	}

	/**
	 * @return string
	 */
	protected function buildDataAfterContent() {

		$skinTemplate = $this->getSkinTemplate();

		if ( $skinTemplate->get( 'dataAfterContent' ) ) {
			return
				$this->indent() . '<!-- data blocks which should go somewhere after the body text, but not before the catlinks block-->' .
				$this->indent() . $skinTemplate->get( 'dataAfterContent' );
		}

		return '';
	}

	/**
	 * @return string
	 */
	private function buildMwIndicators() {

		$idRegistry = IdRegistry::getRegistry();
		$indicators = $this->getSkinTemplate()->get( 'indicators' );

		if ( !is_array( $indicators ) || count( $indicators ) === 0 ) {
			return '';
		}

		$this->indent( 1 );

		$ret = '';

		foreach ( $indicators as $id => $content ) {
			$id = \Sanitizer::escapeId( "mw-indicator-$id" );

			$ret .=
				$this->indent() .
				$idRegistry->element( 'div',
					array(
						'id' => $id,
						'class' => "mw-indicator $id",
					),
					$content
				);
		}

		$ret .= $this->indent( -1 );

		return $ret;
	}

}