MediaWiki  1.31.0
MonoBookTemplate.php
Go to the documentation of this file.
1 <?php
31 
38  public function execute() {
39  // Open html, body elements, etc
40  $html = $this->get( 'headelement' );
41  $html .= Html::openElement( 'div', [ 'id' => 'globalWrapper' ] );
42 
43  $html .= Html::openElement( 'div', [ 'id' => 'column-content' ] );
44  $html .= Html::rawElement( 'div', [ 'id' => 'content', 'class' => 'mw-body', 'role' => 'main' ],
45  Html::element( 'a', [ 'id' => 'top' ] ) .
46  $this->getIfExists( 'sitenotice', [
47  'wrapper' => 'div',
48  'parameters' => [ 'id' => 'siteNotice', 'class' => 'mw-body-content' ]
49  ] ) .
50  $this->getIndicators() .
51  $this->getIfExists( 'title', [
52  'loose' => true,
53  'wrapper' => 'h1',
54  'parameters' => [
55  'id' => 'firstHeading',
56  'class' => 'firstHeading',
57  'lang' => $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode()
58  ]
59  ] ) .
60  Html::rawElement( 'div', [ 'id' => 'bodyContent', 'class' => 'mw-body-content' ],
61  Html::rawElement( 'div', [ 'id' => 'siteSub' ], $this->getMsg( 'tagline' )->parse() ) .
63  'div',
64  [ 'id' => 'contentSub', 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ],
65  $this->get( 'subtitle' )
66  ) .
67  $this->getIfExists( 'undelete', [ 'wrapper' => 'div', [ 'id' => 'contentSub2' ] ] ) .
68  $this->getIfExists( 'newtalk', [ 'wrapper' => 'div', [ 'class' => 'usermessage' ] ] ) .
69  Html::rawElement( 'div', [ 'id' => 'jump-to-nav', 'class' => 'mw-jump' ],
70  $this->getMsg( 'jumpto' )->escaped() .
71  Html::element( 'a', [ 'href' => '#column-one' ],
72  $this->getMsg( 'jumptonavigation' )->text()
73  ) .
74  $this->getMsg( 'comma-separator' )->escaped() .
75  Html::element( 'a', [ 'href' => '#searchInput' ],
76  $this->getMsg( 'jumptosearch' )->text()
77  )
78  ) .
79  '<!-- start content -->' .
80 
81  $this->get( 'bodytext' ) .
82  $this->getIfExists( 'catlinks' ) .
83 
84  '<!-- end content -->' .
85  $this->getIfExists( 'dataAfterContent' ) .
86  $this->getClear()
87  )
88  );
89  $html .= $this->deprecatedHookHack( 'MonoBookAfterContent' );
90  $html .= Html::closeElement( 'div' );
91 
92  $html .= Html::rawElement( 'div',
93  [
94  'id' => 'column-one',
95  'lang' => $this->get( 'userlang' ),
96  'dir' => $this->get( 'dir' )
97  ],
98  Html::element( 'h2', [], $this->getMsg( 'navigation-heading' )->text() ) .
99  $this->getBox( 'cactions', $this->data['content_actions'], 'views' ) .
100  $this->getBox( 'personal', $this->getPersonalTools(), 'personaltools' ) .
101  Html::rawElement( 'div', [ 'class' => 'portlet', 'id' => 'p-logo', 'role' => 'banner' ],
102  Html::element( 'a',
103  [
104  'href' => $this->data['nav_urls']['mainpage']['href'],
105  'class' => 'mw-wiki-logo',
106  ]
108  )
109  ) .
110  $this->getRenderedSidebar()
111  );
112  $html .= '<!-- end of the left (by default at least) column -->';
113 
114  $html .= $this->getClear();
115  $html .= $this->getSimpleFooter();
116  $html .= Html::closeElement( 'div' );
117 
118  $html .= $this->getTrail();
119 
120  $html .= Html::closeElement( 'body' );
121  $html .= Html::closeElement( 'html' );
122 
123  // The unholy echo
124  echo $html;
125  }
126 
132  protected function getRenderedSidebar() {
133  $sidebar = $this->data['sidebar'];
134  $html = '';
135 
136  if ( !isset( $sidebar['SEARCH'] ) ) {
137  $sidebar['SEARCH'] = true;
138  }
139  if ( !isset( $sidebar['TOOLBOX'] ) ) {
140  $sidebar['TOOLBOX'] = true;
141  }
142  if ( !isset( $sidebar['LANGUAGES'] ) ) {
143  $sidebar['LANGUAGES'] = true;
144  }
145 
146  foreach ( $sidebar as $boxName => $content ) {
147  if ( $content === false ) {
148  continue;
149  }
150 
151  // Numeric strings gets an integer when set as key, cast back - T73639
152  $boxName = (string)$boxName;
153 
154  if ( $boxName == 'SEARCH' ) {
155  $html .= $this->getSearchBox();
156  } elseif ( $boxName == 'TOOLBOX' ) {
157  $html .= $this->getToolboxBox();
158  } elseif ( $boxName == 'LANGUAGES' ) {
159  $html .= $this->getLanguageBox();
160  } else {
161  $html .= $this->getBox(
162  $boxName,
163  $content,
164  null,
165  [ 'extra-classes' => 'generated-sidebar' ]
166  );
167  }
168  }
169 
170  return $html;
171  }
172 
178  protected function getSearchBox() {
179  $html = '';
180 
181  if ( $this->config->get( 'UseTwoButtonsSearchForm' ) ) {
182  $optionButtons = '&#160; ' . $this->makeSearchButton(
183  'fulltext',
184  [ 'id' => 'mw-searchButton', 'class' => 'searchButton' ]
185  );
186  } else {
187  $optionButtons = Html::rawElement( 'div', [],
188  Html::rawElement( 'a', [ 'href' => $this->get( 'searchaction' ), 'rel' => 'search' ],
189  $this->getMsg( 'powersearch-legend' )->escaped()
190  )
191  );
192  }
193  $searchInputId = 'searchInput';
194  $searchForm = Html::rawElement( 'form', [
195  'action' => $this->get( 'wgScript' ),
196  'id' => 'searchform'
197  ],
198  Html::hidden( 'title', $this->get( 'searchtitle' ) ) .
199  $this->makeSearchInput( [ 'id' => $searchInputId ] ) .
200  $this->makeSearchButton( 'go', [ 'id' => 'searchGoButton', 'class' => 'searchButton' ] ) .
201  $optionButtons
202  );
203 
204  $html .= $this->getBox( 'search', $searchForm, null, [
205  'search-input-id' => $searchInputId,
206  'role' => 'search',
207  'body-id' => 'searchBody'
208  ] );
209 
210  return $html;
211  }
212 
218  protected function getToolboxBox() {
219  $html = '';
220  $skin = $this;
221 
222  $html .= $this->getBox( 'tb', $this->getToolbox(), 'toolbox', [ 'hooks' => [
223  // Deprecated hooks
224  'MonoBookTemplateToolboxEnd' => [ &$skin ],
225  'SkinTemplateToolboxEnd' => [ &$skin, true ]
226  ] ] );
227 
228  $html .= $this->deprecatedHookHack( 'MonoBookAfterToolbox' );
229 
230  return $html;
231  }
232 
238  protected function getLanguageBox() {
239  $html = '';
240 
241  if ( $this->data['language_urls'] !== false ) {
242  $html .= $this->getBox( 'lang', $this->data['language_urls'], 'otherlanguages' );
243  }
244 
245  return $html;
246  }
247 
258  protected function getBox( $name, $contents, $msg = null, $setOptions = [] ) {
259  $options = [
260  'class' => 'portlet',
261  'body-class' => 'pBody',
262  'text-wrapper' => ''
263  ];
264  foreach ( $setOptions as $key => $value ) {
265  $options[$key] = $value;
266  }
267 
268  // Do some special stuff for the personal menu
269  if ( $name == 'personal' ) {
270  $prependiture = '';
271 
272  // Extension:UniversalLanguageSelector order - T121793
273  if ( array_key_exists( 'uls', $contents ) ) {
274  $prependiture .= $this->makeListItem( 'uls', $contents['uls'] );
275  unset( $contents['uls'] );
276  }
277  if ( !$this->getSkin()->getUser()->isLoggedIn() &&
278  User::groupHasPermission( '*', 'edit' )
279  ) {
280  $prependiture .= Html::rawElement(
281  'li',
282  [ 'id' => 'pt-anonuserpage' ],
283  $this->getMsg( 'notloggedin' )->escaped()
284  );
285  }
286  $options['list-prepend'] = $prependiture;
287  }
288 
289  return $this->getPortlet( $name, $contents, $msg, $options );
290  }
291 
302  protected function getPortlet( $name, $content, $msg = null, $setOptions = [] ) {
303  // random stuff to override with any provided options
304  $options = [
305  // handle role=search a little differently
306  'role' => 'navigation',
307  'search-input-id' => 'searchInput',
308  // extra classes/ids
309  'id' => 'p-' . $name,
310  'class' => 'mw-portlet',
311  'extra-classes' => '',
312  'body-id' => null,
313  'body-class' => 'mw-portlet-body',
314  'body-extra-classes' => '',
315  // wrapper for individual list items
316  'text-wrapper' => [ 'tag' => 'span' ],
317  // old toolbox hook support (use: [ 'SkinTemplateToolboxEnd' => [ &$skin, true ] ])
318  'hooks' => '',
319  // option to stick arbitrary stuff at the beginning of the ul
320  'list-prepend' => ''
321  ];
322  // set options based on input
323  foreach ( $setOptions as $key => $value ) {
324  $options[$key] = $value;
325  }
326 
327  // Handle the different $msg possibilities
328  if ( $msg === null ) {
329  $msg = $name;
330  $msgParams = [];
331  } elseif ( is_array( $msg ) ) {
332  $msgString = array_shift( $msg );
333  $msgParams = $msg;
334  $msg = $msgString;
335  } else {
336  $msgParams = [];
337  }
338  $msgObj = $this->getMsg( $msg, $msgParams );
339  if ( $msgObj->exists() ) {
340  $msgString = $msgObj->parse();
341  } else {
342  $msgString = htmlspecialchars( $msg );
343  }
344 
345  $labelId = Sanitizer::escapeIdForAttribute( "p-$name-label" );
346 
347  if ( is_array( $content ) ) {
348  $contentText = Html::openElement( 'ul',
349  [ 'lang' => $this->get( 'userlang' ), 'dir' => $this->get( 'dir' ) ]
350  );
351  $contentText .= $options['list-prepend'];
352  foreach ( $content as $key => $item ) {
353  if ( is_array( $options['text-wrapper'] ) ) {
354  $contentText .= $this->makeListItem(
355  $key,
356  $item,
357  [ 'text-wrapper' => $options['text-wrapper'] ]
358  );
359  } else {
360  $contentText .= $this->makeListItem(
361  $key,
362  $item
363  );
364  }
365  }
366  // Compatibility with extensions still using SkinTemplateToolboxEnd or similar
367  if ( is_array( $options['hooks'] ) ) {
368  foreach ( $options['hooks'] as $hook => $hookOptions ) {
369  $contentText .= $this->deprecatedHookHack( $hook, $hookOptions );
370  }
371  }
372 
373  $contentText .= Html::closeElement( 'ul' );
374  } else {
375  $contentText = $content;
376  }
377 
378  // Special handling for role=search
379  $divOptions = [
380  'role' => $options['role'],
381  'class' => $this->mergeClasses( $options['class'], $options['extra-classes'] ),
382  'id' => Sanitizer::escapeIdForAttribute( $options['id'] ),
383  'title' => Linker::titleAttrib( $options['id'] )
384  ];
385  if ( $options['role'] !== 'search' ) {
386  $divOptions['aria-labelledby'] = $labelId;
387  }
388  $labelOptions = [
389  'id' => $labelId,
390  'lang' => $this->get( 'userlang' ),
391  'dir' => $this->get( 'dir' )
392  ];
393  if ( $options['role'] == 'search' ) {
394  $msgString = Html::rawElement( 'label', [ 'for' => $options['search-input-id'] ], $msgString );
395  }
396 
397  $bodyDivOptions = [
398  'class' => $this->mergeClasses( $options['body-class'], $options['body-extra-classes'] )
399  ];
400  if ( is_string( $options['body-id'] ) ) {
401  $bodyDivOptions['id'] = $options['body-id'];
402  }
403 
404  $html = Html::rawElement( 'div', $divOptions,
405  Html::rawElement( 'h3', $labelOptions, $msgString ) .
406  Html::rawElement( 'div', $bodyDivOptions,
407  $contentText .
408  $this->getAfterPortlet( $name )
409  )
410  );
411 
412  return $html;
413  }
414 
426  protected function mergeClasses( $class, $extraClasses ) {
427  if ( !is_array( $class ) ) {
428  $class = [ $class ];
429  }
430  if ( !is_array( $extraClasses ) ) {
431  $extraClasses = [ $extraClasses ];
432  }
433 
434  return array_merge( $class, $extraClasses );
435  }
436 
446  protected function deprecatedHookHack( $hook, $hookOptions = [] ) {
447  $hookContents = '';
448  ob_start();
449  Hooks::run( $hook, $hookOptions );
450  $hookContents = ob_get_contents();
451  ob_end_clean();
452  if ( !trim( $hookContents ) ) {
453  $hookContents = '';
454  }
455 
456  return $hookContents;
457  }
458 
467  protected function getIfExists( $object, $setOptions = [] ) {
468  $options = [
469  'loose' => false,
470  'wrapper' => 'none',
471  'parameters' => []
472  ];
473  foreach ( $setOptions as $key => $value ) {
474  $options[$key] = $value;
475  }
476 
477  $html = '';
478 
479  if ( ( $options['loose'] && $this->data[$object] != '' ) ||
480  ( !$options['loose'] && $this->data[$object] ) ) {
481  if ( $options['wrapper'] == 'none' ) {
482  $html .= $this->get( $object );
483  } else {
485  $options['wrapper'],
486  $options['parameters'],
487  $this->get( $object )
488  );
489  }
490  }
491 
492  return $html;
493  }
494 
500  protected function getSimpleFooter() {
501  $validFooterIcons = $this->getFooterIcons( 'icononly' );
502  $validFooterLinks = $this->getFooterLinks( 'flat' );
503 
504  $html = '';
505 
506  $html .= Html::openElement( 'div', [
507  'id' => 'footer',
508  'role' => 'contentinfo',
509  'lang' => $this->get( 'userlang' ),
510  'dir' => $this->get( 'dir' )
511  ] );
512 
513  foreach ( $validFooterIcons as $blockName => $footerIcons ) {
514  $html .= Html::openElement( 'div', [
515  'id' => Sanitizer::escapeIdForAttribute( "f-{$blockName}ico" ),
516  'class' => 'footer-icons'
517  ] );
518  foreach ( $footerIcons as $icon ) {
519  $html .= $this->getSkin()->makeFooterIcon( $icon );
520  }
521  $html .= Html::closeElement( 'div' );
522  }
523  if ( count( $validFooterLinks ) > 0 ) {
524  $html .= Html::openElement( 'ul', [ 'id' => 'f-list' ] );
525  foreach ( $validFooterLinks as $aLink ) {
527  'li',
528  [ 'id' => Sanitizer::escapeIdForAttribute( $aLink ) ],
529  $this->get( $aLink )
530  );
531  }
532  $html .= Html::closeElement( 'ul' );
533  }
534  $html .= Html::closeElement( 'div' );
535 
536  return $html;
537  }
538 }
BaseTemplate\getPersonalTools
getPersonalTools()
Create an array of personal tools items from the data in the quicktemplate stored by SkinTemplate.
Definition: BaseTemplate.php:124
BaseTemplate\getFooterLinks
getFooterLinks( $option=null)
Returns an array of footerlinks trimmed down to only those footer links that are valid.
Definition: BaseTemplate.php:582
MonoBookTemplate\mergeClasses
mergeClasses( $class, $extraClasses)
Helper function for getPortlet.
Definition: MonoBookTemplate.php:426
BaseTemplate\makeSearchButton
makeSearchButton( $mode, $attrs=[])
Definition: BaseTemplate.php:530
MonoBookTemplate\execute
execute()
Template filter callback for MonoBook skin.
Definition: MonoBookTemplate.php:38
MonoBookTemplate\getBox
getBox( $name, $contents, $msg=null, $setOptions=[])
Generate a sidebar box using getPortlet(); prefill some common stuff.
Definition: MonoBookTemplate.php:258
captcha-old.count
count
Definition: captcha-old.py:249
BaseTemplate\getClear
getClear()
Get a div with the core visualClear class, for clearing floats.
Definition: BaseTemplate.php:710
MonoBookTemplate\getToolboxBox
getToolboxBox()
Generate the toolbox, complete with all three old hooks.
Definition: MonoBookTemplate.php:218
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
MonoBookTemplate\getPortlet
getPortlet( $name, $content, $msg=null, $setOptions=[])
Generates a block of navigation links with a header.
Definition: MonoBookTemplate.php:302
User\groupHasPermission
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: User.php:4927
QuickTemplate\getSkin
getSkin()
Get the Skin object related to this object.
Definition: QuickTemplate.php:190
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2135
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1987
BaseTemplate\getAfterPortlet
getAfterPortlet( $name)
Allows extensions to hook into known portlets and add stuff to them.
Definition: BaseTemplate.php:294
BaseTemplate\makeListItem
makeListItem( $key, $item, $options=[])
Generates a list item for a navigation, portlet, portal, sidebar...
Definition: BaseTemplate.php:473
MonoBookTemplate\getSimpleFooter
getSimpleFooter()
Renderer for getFooterIcons and getFooterLinks as a generic footer block.
Definition: MonoBookTemplate.php:500
BaseTemplate\getIndicators
getIndicators()
Get the suggested HTML for page status indicators: icons (or short text snippets) usually displayed i...
Definition: BaseTemplate.php:729
string
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:175
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:774
QuickTemplate\text
text( $str)
Definition: QuickTemplate.php:125
BaseTemplate\getMsg
getMsg( $name)
Get a Message object with its context set.
Definition: BaseTemplate.php:35
$value
$value
Definition: styleTest.css.php:45
BaseTemplate\makeSearchInput
makeSearchInput( $attrs=[])
Definition: BaseTemplate.php:520
MonoBookTemplate\getLanguageBox
getLanguageBox()
Generate the languages box.
Definition: MonoBookTemplate.php:238
MonoBookTemplate
Definition: MonoBookTemplate.php:30
MonoBookTemplate\getSearchBox
getSearchBox()
Generate the search, using config options for buttons (?)
Definition: MonoBookTemplate.php:178
Linker\titleAttrib
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
Definition: Linker.php:1969
MonoBookTemplate\getRenderedSidebar
getRenderedSidebar()
Generate the full sidebar.
Definition: MonoBookTemplate.php:132
BaseTemplate\getToolbox
getToolbox()
Create an array of common toolbox items from the data in the quicktemplate stored by SkinTemplate.
Definition: BaseTemplate.php:58
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1987
MonoBookTemplate\getIfExists
getIfExists( $object, $setOptions=[])
Simple wrapper for random if-statement-wrapped $this->data things.
Definition: MonoBookTemplate.php:467
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
BaseTemplate\getTrail
getTrail()
Get the basic end-page trail including bottomscripts, reporttime, and debug stuff.
Definition: BaseTemplate.php:760
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
$skin
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1987
MonoBookTemplate\deprecatedHookHack
deprecatedHookHack( $hook, $hookOptions=[])
Wrapper to catch output of old hooks expecting to write directly to page We no longer do things that ...
Definition: MonoBookTemplate.php:446
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
BaseTemplate\getFooterIcons
getFooterIcons( $option=null)
Returns an array of footer icons filtered down by options relevant to how the skin wishes to display ...
Definition: BaseTemplate.php:622
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
BaseTemplate
New base template for a skin's template extended from QuickTemplate this class features helper method...
Definition: BaseTemplate.php:26
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6