Merge "OOUI forms: Remove infusable = false"
[lhc/web/wiklou.git] / includes / skins / SkinTemplate.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 use MediaWiki\Auth\AuthManager;
22 use MediaWiki\MediaWikiServices;
23
24 /**
25 * Base class for template-based skins.
26 *
27 * Template-filler skin base class
28 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
29 * Based on Brion's smarty skin
30 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
31 *
32 * @todo Needs some serious refactoring into functions that correspond
33 * to the computations individual esi snippets need. Most importantly no body
34 * parsing for most of those of course.
35 *
36 * @ingroup Skins
37 */
38 class SkinTemplate extends Skin {
39 /**
40 * @var string Name of our skin, it probably needs to be all lower case.
41 * Child classes should override the default.
42 */
43 public $skinname = 'monobook';
44
45 /**
46 * @var string For QuickTemplate, the name of the subclass which will
47 * actually fill the template. Child classes should override the default.
48 */
49 public $template = QuickTemplate::class;
50
51 public $thispage;
52 public $titletxt;
53 public $userpage;
54 public $thisquery;
55 public $loggedin;
56 public $username;
57 public $userpageUrlDetails;
58
59 /**
60 * Create the template engine object; we feed it a bunch of data
61 * and eventually it spits out some HTML. Should have interface
62 * roughly equivalent to PHPTAL 0.7.
63 *
64 * @param string $classname
65 * @param bool|string $repository Subdirectory where we keep template files
66 * @param bool|string $cache_dir
67 * @return QuickTemplate
68 * @private
69 */
70 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
71 return new $classname( $this->getConfig() );
72 }
73
74 /**
75 * Generates array of language links for the current page
76 *
77 * @return array
78 */
79 public function getLanguages() {
80 global $wgHideInterlanguageLinks;
81 if ( $wgHideInterlanguageLinks ) {
82 return [];
83 }
84
85 $userLang = $this->getLanguage();
86 $languageLinks = [];
87
88 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
89 $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
90
91 $languageLinkTitle = Title::newFromText( $languageLinkText );
92 if ( $languageLinkTitle ) {
93 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
94 $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
95
96 if ( strval( $ilLangName ) === '' ) {
97 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
98 if ( !$ilDisplayTextMsg->isDisabled() ) {
99 // Use custom MW message for the display text
100 $ilLangName = $ilDisplayTextMsg->text();
101 } else {
102 // Last resort: fallback to the language link target
103 $ilLangName = $languageLinkText;
104 }
105 } else {
106 // Use the language autonym as display text
107 $ilLangName = $this->formatLanguageName( $ilLangName );
108 }
109
110 // CLDR extension or similar is required to localize the language name;
111 // otherwise we'll end up with the autonym again.
112 $ilLangLocalName = Language::fetchLanguageName(
113 $ilInterwikiCode,
114 $userLang->getCode()
115 );
116
117 $languageLinkTitleText = $languageLinkTitle->getText();
118 if ( $ilLangLocalName === '' ) {
119 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
120 if ( !$ilFriendlySiteName->isDisabled() ) {
121 if ( $languageLinkTitleText === '' ) {
122 $ilTitle = wfMessage(
123 'interlanguage-link-title-nonlangonly',
124 $ilFriendlySiteName->text()
125 )->text();
126 } else {
127 $ilTitle = wfMessage(
128 'interlanguage-link-title-nonlang',
129 $languageLinkTitleText,
130 $ilFriendlySiteName->text()
131 )->text();
132 }
133 } else {
134 // we have nothing friendly to put in the title, so fall back to
135 // displaying the interlanguage link itself in the title text
136 // (similar to what is done in page content)
137 $ilTitle = $languageLinkTitle->getInterwiki() .
138 ":$languageLinkTitleText";
139 }
140 } elseif ( $languageLinkTitleText === '' ) {
141 $ilTitle = wfMessage(
142 'interlanguage-link-title-langonly',
143 $ilLangLocalName
144 )->text();
145 } else {
146 $ilTitle = wfMessage(
147 'interlanguage-link-title',
148 $languageLinkTitleText,
149 $ilLangLocalName
150 )->text();
151 }
152
153 $ilInterwikiCodeBCP47 = LanguageCode::bcp47( $ilInterwikiCode );
154 $languageLink = [
155 'href' => $languageLinkTitle->getFullURL(),
156 'text' => $ilLangName,
157 'title' => $ilTitle,
158 'class' => $class,
159 'link-class' => 'interlanguage-link-target',
160 'lang' => $ilInterwikiCodeBCP47,
161 'hreflang' => $ilInterwikiCodeBCP47,
162 ];
163 Hooks::run(
164 'SkinTemplateGetLanguageLink',
165 [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
166 );
167 $languageLinks[] = $languageLink;
168 }
169 }
170
171 return $languageLinks;
172 }
173
174 /**
175 * @return QuickTemplate
176 */
177 protected function setupTemplateForOutput() {
178 $request = $this->getRequest();
179 $user = $this->getUser();
180 $title = $this->getTitle();
181
182 $tpl = $this->setupTemplate( $this->template, 'skins' );
183
184 $this->thispage = $title->getPrefixedDBkey();
185 $this->titletxt = $title->getPrefixedText();
186 $this->userpage = $user->getUserPage()->getPrefixedText();
187 $query = [];
188 if ( !$request->wasPosted() ) {
189 $query = $request->getValues();
190 unset( $query['title'] );
191 unset( $query['returnto'] );
192 unset( $query['returntoquery'] );
193 }
194 $this->thisquery = wfArrayToCgi( $query );
195 $this->loggedin = $user->isLoggedIn();
196 $this->username = $user->getName();
197
198 if ( $this->loggedin ) {
199 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
200 } else {
201 # This won't be used in the standard skins, but we define it to preserve the interface
202 # To save time, we check for existence
203 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
204 }
205
206 return $tpl;
207 }
208
209 /**
210 * initialize various variables and generate the template
211 *
212 * @param OutputPage|null $out
213 */
214 function outputPage( OutputPage $out = null ) {
215 Profiler::instance()->setTemplated( true );
216
217 $oldContext = null;
218 if ( $out !== null ) {
219 // Deprecated since 1.20, note added in 1.25
220 wfDeprecated( __METHOD__, '1.25' );
221 $oldContext = $this->getContext();
222 $this->setContext( $out->getContext() );
223 }
224
225 $out = $this->getOutput();
226
227 $this->initPage( $out );
228 $tpl = $this->prepareQuickTemplate();
229 // execute template
230 $res = $tpl->execute();
231
232 // result may be an error
233 $this->printOrError( $res );
234
235 if ( $oldContext ) {
236 $this->setContext( $oldContext );
237 }
238 }
239
240 /**
241 * Wrap the body text with language information and identifiable element
242 *
243 * @param Title $title
244 * @param string $html body text
245 * @return string html
246 */
247 protected function wrapHTML( $title, $html ) {
248 # An ID that includes the actual body text; without categories, contentSub, ...
249 $realBodyAttribs = [ 'id' => 'mw-content-text' ];
250
251 # Add a mw-content-ltr/rtl class to be able to style based on text
252 # direction when the content is different from the UI language (only
253 # when viewing)
254 # Most information on special pages and file pages is in user language,
255 # rather than content language, so those will not get this
256 if ( Action::getActionName( $this ) === 'view' &&
257 ( !$title->inNamespaces( NS_SPECIAL, NS_FILE ) || $title->isRedirect() ) ) {
258 $pageLang = $title->getPageViewLanguage();
259 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
260 $realBodyAttribs['dir'] = $pageLang->getDir();
261 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
262 }
263
264 return Html::rawElement( 'div', $realBodyAttribs, $html );
265 }
266
267 /**
268 * initialize various variables and generate the template
269 *
270 * @since 1.23
271 * @return QuickTemplate The template to be executed by outputPage
272 */
273 protected function prepareQuickTemplate() {
274 global $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
275 $wgSitename, $wgLogo, $wgMaxCredits,
276 $wgShowCreditsIfMax, $wgArticlePath,
277 $wgScriptPath, $wgServer;
278
279 $title = $this->getTitle();
280 $request = $this->getRequest();
281 $out = $this->getOutput();
282 $tpl = $this->setupTemplateForOutput();
283
284 $tpl->set( 'title', $out->getPageTitle() );
285 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
286 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
287
288 $tpl->set( 'thispage', $this->thispage );
289 $tpl->set( 'titleprefixeddbkey', $this->thispage );
290 $tpl->set( 'titletext', $title->getText() );
291 $tpl->set( 'articleid', $title->getArticleID() );
292
293 $tpl->set( 'isarticle', $out->isArticle() );
294
295 $subpagestr = $this->subPageSubtitle();
296 if ( $subpagestr !== '' ) {
297 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
298 }
299 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
300
301 $undelete = $this->getUndeleteLink();
302 if ( $undelete === '' ) {
303 $tpl->set( 'undelete', '' );
304 } else {
305 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
306 }
307
308 $tpl->set( 'catlinks', $this->getCategories() );
309 if ( $out->isSyndicated() ) {
310 $feeds = [];
311 foreach ( $out->getSyndicationLinks() as $format => $link ) {
312 $feeds[$format] = [
313 // Messages: feed-atom, feed-rss
314 'text' => $this->msg( "feed-$format" )->text(),
315 'href' => $link
316 ];
317 }
318 $tpl->set( 'feeds', $feeds );
319 } else {
320 $tpl->set( 'feeds', false );
321 }
322
323 $tpl->set( 'mimetype', $wgMimeType );
324 $tpl->set( 'jsmimetype', $wgJsMimeType );
325 $tpl->set( 'charset', 'UTF-8' );
326 $tpl->set( 'wgScript', $wgScript );
327 $tpl->set( 'skinname', $this->skinname );
328 $tpl->set( 'skinclass', static::class );
329 $tpl->set( 'skin', $this );
330 $tpl->set( 'stylename', $this->stylename );
331 $tpl->set( 'printable', $out->isPrintable() );
332 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
333 $tpl->set( 'loggedin', $this->loggedin );
334 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
335 $tpl->set( 'searchaction', $this->escapeSearchLink() );
336 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
337 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
338 $tpl->set( 'stylepath', $wgStylePath );
339 $tpl->set( 'articlepath', $wgArticlePath );
340 $tpl->set( 'scriptpath', $wgScriptPath );
341 $tpl->set( 'serverurl', $wgServer );
342 $tpl->set( 'logopath', $wgLogo );
343 $tpl->set( 'sitename', $wgSitename );
344
345 $userLang = $this->getLanguage();
346 $userLangCode = $userLang->getHtmlCode();
347 $userLangDir = $userLang->getDir();
348
349 $tpl->set( 'lang', $userLangCode );
350 $tpl->set( 'dir', $userLangDir );
351 $tpl->set( 'rtl', $userLang->isRTL() );
352
353 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
354 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
355 $tpl->set( 'username', $this->loggedin ? $this->username : null );
356 $tpl->set( 'userpage', $this->userpage );
357 $tpl->set( 'userpageurl', $this->userpageUrlDetails['href'] );
358 $tpl->set( 'userlang', $userLangCode );
359
360 // Users can have their language set differently than the
361 // content of the wiki. For these users, tell the web browser
362 // that interface elements are in a different language.
363 $tpl->set( 'userlangattributes', '' );
364 $tpl->set( 'specialpageattributes', '' ); # obsolete
365 // Used by VectorBeta to insert HTML before content but after the
366 // heading for the page title. Defaults to empty string.
367 $tpl->set( 'prebodyhtml', '' );
368
369 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
370 if (
371 $userLangCode !== $contLang->getHtmlCode() ||
372 $userLangDir !== $contLang->getDir()
373 ) {
374 $escUserlang = htmlspecialchars( $userLangCode );
375 $escUserdir = htmlspecialchars( $userLangDir );
376 // Attributes must be in double quotes because htmlspecialchars() doesn't
377 // escape single quotes
378 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
379 $tpl->set( 'userlangattributes', $attrs );
380 }
381
382 $tpl->set( 'newtalk', $this->getNewtalks() );
383 $tpl->set( 'logo', $this->logoText() );
384
385 $tpl->set( 'copyright', false );
386 // No longer used
387 $tpl->set( 'viewcount', false );
388 $tpl->set( 'lastmod', false );
389 $tpl->set( 'credits', false );
390 $tpl->set( 'numberofwatchingusers', false );
391 if ( $title->exists() ) {
392 if ( $out->isArticle() ) {
393 if ( $this->isRevisionCurrent() ) {
394 if ( $wgMaxCredits != 0 ) {
395 /** @var CreditsAction $action */
396 $action = Action::factory(
397 'credits', $this->getWikiPage(), $this->getContext() );
398 $tpl->set( 'credits',
399 $action->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
400 } else {
401 $tpl->set( 'lastmod', $this->lastModified() );
402 }
403 }
404 }
405 if ( $out->showsCopyright() ) {
406 $tpl->set( 'copyright', $this->getCopyright() );
407 }
408 }
409
410 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
411 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
412 $tpl->set( 'disclaimer', $this->disclaimerLink() );
413 $tpl->set( 'privacy', $this->privacyLink() );
414 $tpl->set( 'about', $this->aboutLink() );
415
416 $tpl->set( 'footerlinks', [
417 'info' => [
418 'lastmod',
419 'numberofwatchingusers',
420 'credits',
421 'copyright',
422 ],
423 'places' => [
424 'privacy',
425 'about',
426 'disclaimer',
427 ],
428 ] );
429
430 global $wgFooterIcons;
431 $tpl->set( 'footericons', $wgFooterIcons );
432 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
433 if ( count( $footerIconsBlock ) > 0 ) {
434 foreach ( $footerIconsBlock as &$footerIcon ) {
435 if ( isset( $footerIcon['src'] ) ) {
436 if ( !isset( $footerIcon['width'] ) ) {
437 $footerIcon['width'] = 88;
438 }
439 if ( !isset( $footerIcon['height'] ) ) {
440 $footerIcon['height'] = 31;
441 }
442 }
443 }
444 } else {
445 unset( $tpl->data['footericons'][$footerIconsKey] );
446 }
447 }
448
449 $tpl->set( 'indicators', $out->getIndicators() );
450
451 $tpl->set( 'sitenotice', $this->getSiteNotice() );
452 $tpl->set( 'printfooter', $this->printSource() );
453 // Wrap the bodyText with #mw-content-text element
454 $out->mBodytext = $this->wrapHTML( $title, $out->mBodytext );
455 $tpl->set( 'bodytext', $out->mBodytext );
456
457 $language_urls = $this->getLanguages();
458 if ( count( $language_urls ) ) {
459 $tpl->set( 'language_urls', $language_urls );
460 } else {
461 $tpl->set( 'language_urls', false );
462 }
463
464 # Personal toolbar
465 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
466 $content_navigation = $this->buildContentNavigationUrls();
467 $content_actions = $this->buildContentActionUrls( $content_navigation );
468 $tpl->set( 'content_navigation', $content_navigation );
469 $tpl->set( 'content_actions', $content_actions );
470
471 $tpl->set( 'sidebar', $this->buildSidebar() );
472 $tpl->set( 'nav_urls', $this->buildNavUrls() );
473
474 // Do this last in case hooks above add bottom scripts
475 $tpl->set( 'bottomscripts', $this->bottomScripts() );
476
477 // Set the head scripts near the end, in case the above actions resulted in added scripts
478 $tpl->set( 'headelement', $out->headElement( $this ) );
479
480 $tpl->set( 'debug', '' );
481 $tpl->set( 'debughtml', $this->generateDebugHTML() );
482 $tpl->set( 'reporttime', wfReportTime( $out->getCSPNonce() ) );
483
484 // Avoid PHP 7.1 warning of passing $this by reference
485 $skinTemplate = $this;
486 // original version by hansm
487 if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
488 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
489 }
490
491 // Set the bodytext to another key so that skins can just output it on its own
492 // and output printfooter and debughtml separately
493 $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
494
495 // Append printfooter and debughtml onto bodytext so that skins that
496 // were already using bodytext before they were split out don't suddenly
497 // start not outputting information.
498 $tpl->data['bodytext'] .= Html::rawElement(
499 'div',
500 [ 'class' => 'printfooter' ],
501 "\n{$tpl->data['printfooter']}"
502 ) . "\n";
503 $tpl->data['bodytext'] .= $tpl->data['debughtml'];
504
505 // allow extensions adding stuff after the page content.
506 // See Skin::afterContentHook() for further documentation.
507 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
508
509 return $tpl;
510 }
511
512 /**
513 * Get the HTML for the p-personal list
514 * @return string
515 */
516 public function getPersonalToolsList() {
517 return $this->makePersonalToolsList();
518 }
519
520 /**
521 * Get the HTML for the personal tools list
522 *
523 * @since 1.31
524 *
525 * @param array|null $personalTools
526 * @param array $options
527 * @return string
528 */
529 public function makePersonalToolsList( $personalTools = null, $options = [] ) {
530 $tpl = $this->setupTemplateForOutput();
531 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
532 $html = '';
533
534 if ( $personalTools === null ) {
535 $personalTools = ( $tpl instanceof BaseTemplate )
536 ? $tpl->getPersonalTools()
537 : [];
538 }
539
540 foreach ( $personalTools as $key => $item ) {
541 $html .= $tpl->makeListItem( $key, $item, $options );
542 }
543
544 return $html;
545 }
546
547 /**
548 * Get personal tools for the user
549 *
550 * @since 1.31
551 *
552 * @return array Array of personal tools
553 */
554 public function getStructuredPersonalTools() {
555 $tpl = $this->setupTemplateForOutput();
556 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
557
558 return ( $tpl instanceof BaseTemplate ) ? $tpl->getPersonalTools() : [];
559 }
560
561 /**
562 * Format language name for use in sidebar interlanguage links list.
563 * By default it is capitalized.
564 *
565 * @param string $name Language name, e.g. "English" or "español"
566 * @return string
567 * @private
568 */
569 function formatLanguageName( $name ) {
570 return $this->getLanguage()->ucfirst( $name );
571 }
572
573 /**
574 * Output the string, or print error message if it's
575 * an error object of the appropriate type.
576 * For the base class, assume strings all around.
577 *
578 * @param string $str
579 * @private
580 */
581 function printOrError( $str ) {
582 echo $str;
583 }
584
585 /**
586 * Output a boolean indicating if buildPersonalUrls should output separate
587 * login and create account links or output a combined link
588 * By default we simply return a global config setting that affects most skins
589 * This is setup as a method so that like with $wgLogo and getLogo() a skin
590 * can override this setting and always output one or the other if it has
591 * a reason it can't output one of the two modes.
592 * @return bool
593 */
594 function useCombinedLoginLink() {
595 global $wgUseCombinedLoginLink;
596 return $wgUseCombinedLoginLink;
597 }
598
599 /**
600 * build array of urls for personal toolbar
601 * @return array
602 */
603 protected function buildPersonalUrls() {
604 $title = $this->getTitle();
605 $request = $this->getRequest();
606 $pageurl = $title->getLocalURL();
607 $authManager = AuthManager::singleton();
608
609 /* set up the default links for the personal toolbar */
610 $personal_urls = [];
611
612 # Due to T34276, if a user does not have read permissions,
613 # $this->getTitle() will just give Special:Badtitle, which is
614 # not especially useful as a returnto parameter. Use the title
615 # from the request instead, if there was one.
616 if ( $this->getUser()->isAllowed( 'read' ) ) {
617 $page = $this->getTitle();
618 } else {
619 $page = Title::newFromText( $request->getVal( 'title', '' ) );
620 }
621 $page = $request->getVal( 'returnto', $page );
622 $a = [];
623 if ( strval( $page ) !== '' ) {
624 $a['returnto'] = $page;
625 $query = $request->getVal( 'returntoquery', $this->thisquery );
626 if ( $query != '' ) {
627 $a['returntoquery'] = $query;
628 }
629 }
630
631 $returnto = wfArrayToCgi( $a );
632 if ( $this->loggedin ) {
633 $personal_urls['userpage'] = [
634 'text' => $this->username,
635 'href' => &$this->userpageUrlDetails['href'],
636 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
637 'exists' => $this->userpageUrlDetails['exists'],
638 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
639 'dir' => 'auto'
640 ];
641 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
642 $personal_urls['mytalk'] = [
643 'text' => $this->msg( 'mytalk' )->text(),
644 'href' => &$usertalkUrlDetails['href'],
645 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
646 'exists' => $usertalkUrlDetails['exists'],
647 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
648 ];
649 $href = self::makeSpecialUrl( 'Preferences' );
650 $personal_urls['preferences'] = [
651 'text' => $this->msg( 'mypreferences' )->text(),
652 'href' => $href,
653 'active' => ( $href == $pageurl )
654 ];
655
656 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
657 $href = self::makeSpecialUrl( 'Watchlist' );
658 $personal_urls['watchlist'] = [
659 'text' => $this->msg( 'mywatchlist' )->text(),
660 'href' => $href,
661 'active' => ( $href == $pageurl )
662 ];
663 }
664
665 # We need to do an explicit check for Special:Contributions, as we
666 # have to match both the title, and the target, which could come
667 # from request values (Special:Contributions?target=Jimbo_Wales)
668 # or be specified in "sub page" form
669 # (Special:Contributions/Jimbo_Wales). The plot
670 # thickens, because the Title object is altered for special pages,
671 # so it doesn't contain the original alias-with-subpage.
672 $origTitle = Title::newFromText( $request->getText( 'title' ) );
673 if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
674 list( $spName, $spPar ) =
675 MediaWikiServices::getInstance()->getSpecialPageFactory()->
676 resolveAlias( $origTitle->getText() );
677 $active = $spName == 'Contributions'
678 && ( ( $spPar && $spPar == $this->username )
679 || $request->getText( 'target' ) == $this->username );
680 } else {
681 $active = false;
682 }
683
684 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
685 $personal_urls['mycontris'] = [
686 'text' => $this->msg( 'mycontris' )->text(),
687 'href' => $href,
688 'active' => $active
689 ];
690
691 // if we can't set the user, we can't unset it either
692 if ( $request->getSession()->canSetUser() ) {
693 $personal_urls['logout'] = [
694 'text' => $this->msg( 'pt-userlogout' )->text(),
695 'href' => self::makeSpecialUrl( 'Userlogout',
696 // userlogout link must always contain an & character, otherwise we might not be able
697 // to detect a buggy precaching proxy (T19790)
698 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto ),
699 'active' => false
700 ];
701 }
702 } else {
703 $useCombinedLoginLink = $this->useCombinedLoginLink();
704 if ( !$authManager->canCreateAccounts() || !$authManager->canAuthenticateNow() ) {
705 // don't show combined login/signup link if one of those is actually not available
706 $useCombinedLoginLink = false;
707 }
708
709 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
710 ? 'nav-login-createaccount'
711 : 'pt-login';
712
713 $login_url = [
714 'text' => $this->msg( $loginlink )->text(),
715 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
716 'active' => $title->isSpecial( 'Userlogin' )
717 || $title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink,
718 ];
719 $createaccount_url = [
720 'text' => $this->msg( 'pt-createaccount' )->text(),
721 'href' => self::makeSpecialUrl( 'CreateAccount', $returnto ),
722 'active' => $title->isSpecial( 'CreateAccount' ),
723 ];
724
725 // No need to show Talk and Contributions to anons if they can't contribute!
726 if ( User::groupHasPermission( '*', 'edit' ) ) {
727 // Because of caching, we can't link directly to the IP talk and
728 // contributions pages. Instead we use the special page shortcuts
729 // (which work correctly regardless of caching). This means we can't
730 // determine whether these links are active or not, but since major
731 // skins (MonoBook, Vector) don't use this information, it's not a
732 // huge loss.
733 $personal_urls['anontalk'] = [
734 'text' => $this->msg( 'anontalk' )->text(),
735 'href' => self::makeSpecialUrlSubpage( 'Mytalk', false ),
736 'active' => false
737 ];
738 $personal_urls['anoncontribs'] = [
739 'text' => $this->msg( 'anoncontribs' )->text(),
740 'href' => self::makeSpecialUrlSubpage( 'Mycontributions', false ),
741 'active' => false
742 ];
743 }
744
745 if (
746 $authManager->canCreateAccounts()
747 && $this->getUser()->isAllowed( 'createaccount' )
748 && !$useCombinedLoginLink
749 ) {
750 $personal_urls['createaccount'] = $createaccount_url;
751 }
752
753 if ( $authManager->canAuthenticateNow() ) {
754 $key = User::groupHasPermission( '*', 'read' )
755 ? 'login'
756 : 'login-private';
757 $personal_urls[$key] = $login_url;
758 }
759 }
760
761 Hooks::runWithoutAbort( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
762 return $personal_urls;
763 }
764
765 /**
766 * Builds an array with tab definition
767 *
768 * @param Title $title Page Where the tab links to
769 * @param string|array $message Message key or an array of message keys (will fall back)
770 * @param bool $selected Display the tab as selected
771 * @param string $query Query string attached to tab URL
772 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
773 *
774 * @return array
775 */
776 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
777 $classes = [];
778 if ( $selected ) {
779 $classes[] = 'selected';
780 }
781 $exists = true;
782 if ( $checkEdit && !$title->isKnown() ) {
783 $classes[] = 'new';
784 $exists = false;
785 if ( $query !== '' ) {
786 $query = 'action=edit&redlink=1&' . $query;
787 } else {
788 $query = 'action=edit&redlink=1';
789 }
790 }
791
792 $linkClass = MediaWikiServices::getInstance()->getLinkRenderer()->getLinkClasses( $title );
793
794 // wfMessageFallback will nicely accept $message as an array of fallbacks
795 // or just a single key
796 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
797 if ( is_array( $message ) ) {
798 // for hook compatibility just keep the last message name
799 $message = end( $message );
800 }
801 if ( $msg->exists() ) {
802 $text = $msg->text();
803 } else {
804 $text = MediaWikiServices::getInstance()->getContentLanguage()->getConverter()->
805 convertNamespace( MWNamespace::getSubject( $title->getNamespace() ) );
806 }
807
808 // Avoid PHP 7.1 warning of passing $this by reference
809 $skinTemplate = $this;
810 $result = [];
811 if ( !Hooks::run( 'SkinTemplateTabAction', [ &$skinTemplate,
812 $title, $message, $selected, $checkEdit,
813 &$classes, &$query, &$text, &$result ] ) ) {
814 return $result;
815 }
816
817 $result = [
818 'class' => implode( ' ', $classes ),
819 'text' => $text,
820 'href' => $title->getLocalURL( $query ),
821 'exists' => $exists,
822 'primary' => true ];
823 if ( $linkClass !== '' ) {
824 $result['link-class'] = $linkClass;
825 }
826
827 return $result;
828 }
829
830 function makeTalkUrlDetails( $name, $urlaction = '' ) {
831 $title = Title::newFromText( $name );
832 if ( !is_object( $title ) ) {
833 throw new MWException( __METHOD__ . " given invalid pagename $name" );
834 }
835 $title = $title->getTalkPage();
836 self::checkTitle( $title, $name );
837 return [
838 'href' => $title->getLocalURL( $urlaction ),
839 'exists' => $title->isKnown(),
840 ];
841 }
842
843 /**
844 * @todo is this even used?
845 * @param string $name
846 * @param string $urlaction
847 * @return array
848 */
849 function makeArticleUrlDetails( $name, $urlaction = '' ) {
850 $title = Title::newFromText( $name );
851 $title = $title->getSubjectPage();
852 self::checkTitle( $title, $name );
853 return [
854 'href' => $title->getLocalURL( $urlaction ),
855 'exists' => $title->exists(),
856 ];
857 }
858
859 /**
860 * a structured array of links usually used for the tabs in a skin
861 *
862 * There are 4 standard sections
863 * namespaces: Used for namespace tabs like special, page, and talk namespaces
864 * views: Used for primary page views like read, edit, history
865 * actions: Used for most extra page actions like deletion, protection, etc...
866 * variants: Used to list the language variants for the page
867 *
868 * Each section's value is a key/value array of links for that section.
869 * The links themselves have these common keys:
870 * - class: The css classes to apply to the tab
871 * - text: The text to display on the tab
872 * - href: The href for the tab to point to
873 * - rel: An optional rel= for the tab's link
874 * - redundant: If true the tab will be dropped in skins using content_actions
875 * this is useful for tabs like "Read" which only have meaning in skins that
876 * take special meaning from the grouped structure of content_navigation
877 *
878 * Views also have an extra key which can be used:
879 * - primary: If this is not true skins like vector may try to hide the tab
880 * when the user has limited space in their browser window
881 *
882 * content_navigation using code also expects these ids to be present on the
883 * links, however these are usually automatically generated by SkinTemplate
884 * itself and are not necessary when using a hook. The only things these may
885 * matter to are people modifying content_navigation after it's initial creation:
886 * - id: A "preferred" id, most skins are best off outputting this preferred
887 * id for best compatibility.
888 * - tooltiponly: This is set to true for some tabs in cases where the system
889 * believes that the accesskey should not be added to the tab.
890 *
891 * @return array
892 */
893 protected function buildContentNavigationUrls() {
894 global $wgDisableLangConversion;
895
896 // Display tabs for the relevant title rather than always the title itself
897 $title = $this->getRelevantTitle();
898 $onPage = $title->equals( $this->getTitle() );
899
900 $out = $this->getOutput();
901 $request = $this->getRequest();
902 $user = $this->getUser();
903
904 $content_navigation = [
905 'namespaces' => [],
906 'views' => [],
907 'actions' => [],
908 'variants' => []
909 ];
910
911 // parameters
912 $action = $request->getVal( 'action', 'view' );
913
914 $userCanRead = $title->quickUserCan( 'read', $user );
915
916 // Avoid PHP 7.1 warning of passing $this by reference
917 $skinTemplate = $this;
918 $preventActiveTabs = false;
919 Hooks::run( 'SkinTemplatePreventOtherActiveTabs', [ &$skinTemplate, &$preventActiveTabs ] );
920
921 // Checks if page is some kind of content
922 if ( $title->canExist() ) {
923 // Gets page objects for the related namespaces
924 $subjectPage = $title->getSubjectPage();
925 $talkPage = $title->getTalkPage();
926
927 // Determines if this is a talk page
928 $isTalk = $title->isTalkPage();
929
930 // Generates XML IDs from namespace names
931 $subjectId = $title->getNamespaceKey( '' );
932
933 if ( $subjectId == 'main' ) {
934 $talkId = 'talk';
935 } else {
936 $talkId = "{$subjectId}_talk";
937 }
938
939 $skname = $this->skinname;
940
941 // Adds namespace links
942 $subjectMsg = [ "nstab-$subjectId" ];
943 if ( $subjectPage->isMainPage() ) {
944 array_unshift( $subjectMsg, 'mainpage-nstab' );
945 }
946 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
947 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
948 );
949 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
950 $content_navigation['namespaces'][$talkId] = $this->tabAction(
951 $talkPage, [ "nstab-$talkId", 'talk' ], $isTalk && !$preventActiveTabs, '', $userCanRead
952 );
953 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
954
955 if ( $userCanRead ) {
956 // Adds "view" view link
957 if ( $title->isKnown() ) {
958 $content_navigation['views']['view'] = $this->tabAction(
959 $isTalk ? $talkPage : $subjectPage,
960 [ "$skname-view-view", 'view' ],
961 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
962 );
963 // signal to hide this from simple content_actions
964 $content_navigation['views']['view']['redundant'] = true;
965 }
966
967 $page = $this->canUseWikiPage() ? $this->getWikiPage() : false;
968 $isRemoteContent = $page && !$page->isLocal();
969
970 // If it is a non-local file, show a link to the file in its own repository
971 // @todo abstract this for remote content that isn't a file
972 if ( $isRemoteContent ) {
973 $content_navigation['views']['view-foreign'] = [
974 'class' => '',
975 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
976 setContext( $this->getContext() )->
977 params( $page->getWikiDisplayName() )->text(),
978 'href' => $page->getSourceURL(),
979 'primary' => false,
980 ];
981 }
982
983 // Checks if user can edit the current page if it exists or create it otherwise
984 if ( $title->quickUserCan( 'edit', $user )
985 && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
986 ) {
987 // Builds CSS class for talk page links
988 $isTalkClass = $isTalk ? ' istalk' : '';
989 // Whether the user is editing the page
990 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
991 // Whether to show the "Add a new section" tab
992 // Checks if this is a current rev of talk page and is not forced to be hidden
993 $showNewSection = !$out->forceHideNewSectionLink()
994 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
995 $section = $request->getVal( 'section' );
996
997 if ( $title->exists()
998 || ( $title->getNamespace() == NS_MEDIAWIKI
999 && $title->getDefaultMessageText() !== false
1000 )
1001 ) {
1002 $msgKey = $isRemoteContent ? 'edit-local' : 'edit';
1003 } else {
1004 $msgKey = $isRemoteContent ? 'create-local' : 'create';
1005 }
1006 $content_navigation['views']['edit'] = [
1007 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
1008 ? 'selected'
1009 : ''
1010 ) . $isTalkClass,
1011 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
1012 ->setContext( $this->getContext() )->text(),
1013 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1014 'primary' => !$isRemoteContent, // don't collapse this in vector
1015 ];
1016
1017 // section link
1018 if ( $showNewSection ) {
1019 // Adds new section link
1020 // $content_navigation['actions']['addsection']
1021 $content_navigation['views']['addsection'] = [
1022 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
1023 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1024 ->setContext( $this->getContext() )->text(),
1025 'href' => $title->getLocalURL( 'action=edit&section=new' )
1026 ];
1027 }
1028 // Checks if the page has some kind of viewable source content
1029 } elseif ( $title->hasSourceText() ) {
1030 // Adds view source view link
1031 $content_navigation['views']['viewsource'] = [
1032 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
1033 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1034 ->setContext( $this->getContext() )->text(),
1035 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1036 'primary' => true, // don't collapse this in vector
1037 ];
1038 }
1039
1040 // Checks if the page exists
1041 if ( $title->exists() ) {
1042 // Adds history view link
1043 $content_navigation['views']['history'] = [
1044 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
1045 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1046 ->setContext( $this->getContext() )->text(),
1047 'href' => $title->getLocalURL( 'action=history' ),
1048 ];
1049
1050 if ( $title->quickUserCan( 'delete', $user ) ) {
1051 $content_navigation['actions']['delete'] = [
1052 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
1053 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1054 ->setContext( $this->getContext() )->text(),
1055 'href' => $title->getLocalURL( 'action=delete' )
1056 ];
1057 }
1058
1059 if ( $title->quickUserCan( 'move', $user ) ) {
1060 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1061 $content_navigation['actions']['move'] = [
1062 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
1063 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1064 ->setContext( $this->getContext() )->text(),
1065 'href' => $moveTitle->getLocalURL()
1066 ];
1067 }
1068 } else {
1069 // article doesn't exist or is deleted
1070 if ( $title->quickUserCan( 'deletedhistory', $user ) ) {
1071 $n = $title->isDeleted();
1072 if ( $n ) {
1073 $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
1074 // If the user can't undelete but can view deleted
1075 // history show them a "View .. deleted" tab instead.
1076 $msgKey = $title->quickUserCan( 'undelete', $user ) ? 'undelete' : 'viewdeleted';
1077 $content_navigation['actions']['undelete'] = [
1078 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
1079 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1080 ->setContext( $this->getContext() )->numParams( $n )->text(),
1081 'href' => $undelTitle->getLocalURL()
1082 ];
1083 }
1084 }
1085 }
1086
1087 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1088 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
1089 ) {
1090 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1091 $content_navigation['actions'][$mode] = [
1092 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1093 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1094 ->setContext( $this->getContext() )->text(),
1095 'href' => $title->getLocalURL( "action=$mode" )
1096 ];
1097 }
1098
1099 // Checks if the user is logged in
1100 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1101 /**
1102 * The following actions use messages which, if made particular to
1103 * the any specific skins, would break the Ajax code which makes this
1104 * action happen entirely inline. OutputPage::getJSVars
1105 * defines a set of messages in a javascript object - and these
1106 * messages are assumed to be global for all skins. Without making
1107 * a change to that procedure these messages will have to remain as
1108 * the global versions.
1109 */
1110 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1111 $content_navigation['actions'][$mode] = [
1112 'class' => 'mw-watchlink ' . (
1113 $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : ''
1114 ),
1115 // uses 'watch' or 'unwatch' message
1116 'text' => $this->msg( $mode )->text(),
1117 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
1118 // Set a data-mw=interface attribute, which the mediawiki.page.ajax
1119 // module will look for to make sure it's a trusted link
1120 'data' => [
1121 'mw' => 'interface',
1122 ],
1123 ];
1124 }
1125 }
1126
1127 // Avoid PHP 7.1 warning of passing $this by reference
1128 $skinTemplate = $this;
1129 Hooks::runWithoutAbort(
1130 'SkinTemplateNavigation',
1131 [ &$skinTemplate, &$content_navigation ]
1132 );
1133
1134 if ( $userCanRead && !$wgDisableLangConversion ) {
1135 $pageLang = $title->getPageLanguage();
1136 // Checks that language conversion is enabled and variants exist
1137 // And if it is not in the special namespace
1138 if ( $pageLang->hasVariants() ) {
1139 // Gets list of language variants
1140 $variants = $pageLang->getVariants();
1141 // Gets preferred variant (note that user preference is
1142 // only possible for wiki content language variant)
1143 $preferred = $pageLang->getPreferredVariant();
1144 if ( Action::getActionName( $this ) === 'view' ) {
1145 $params = $request->getQueryValues();
1146 unset( $params['title'] );
1147 } else {
1148 $params = [];
1149 }
1150 // Loops over each variant
1151 foreach ( $variants as $code ) {
1152 // Gets variant name from language code
1153 $varname = $pageLang->getVariantname( $code );
1154 // Appends variant link
1155 $content_navigation['variants'][] = [
1156 'class' => ( $code == $preferred ) ? 'selected' : false,
1157 'text' => $varname,
1158 'href' => $title->getLocalURL( [ 'variant' => $code ] + $params ),
1159 'lang' => LanguageCode::bcp47( $code ),
1160 'hreflang' => LanguageCode::bcp47( $code ),
1161 ];
1162 }
1163 }
1164 }
1165 } else {
1166 // If it's not content, it's got to be a special page
1167 $content_navigation['namespaces']['special'] = [
1168 'class' => 'selected',
1169 'text' => $this->msg( 'nstab-special' )->text(),
1170 'href' => $request->getRequestURL(), // @see: T4457, T4510
1171 'context' => 'subject'
1172 ];
1173
1174 // Avoid PHP 7.1 warning of passing $this by reference
1175 $skinTemplate = $this;
1176 Hooks::runWithoutAbort( 'SkinTemplateNavigation::SpecialPage',
1177 [ &$skinTemplate, &$content_navigation ] );
1178 }
1179
1180 // Avoid PHP 7.1 warning of passing $this by reference
1181 $skinTemplate = $this;
1182 // Equiv to SkinTemplateContentActions
1183 Hooks::runWithoutAbort( 'SkinTemplateNavigation::Universal',
1184 [ &$skinTemplate, &$content_navigation ] );
1185
1186 // Setup xml ids and tooltip info
1187 foreach ( $content_navigation as $section => &$links ) {
1188 foreach ( $links as $key => &$link ) {
1189 $xmlID = $key;
1190 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1191 $xmlID = 'ca-nstab-' . $xmlID;
1192 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1193 $xmlID = 'ca-talk';
1194 $link['rel'] = 'discussion';
1195 } elseif ( $section == 'variants' ) {
1196 $xmlID = 'ca-varlang-' . $xmlID;
1197 } else {
1198 $xmlID = 'ca-' . $xmlID;
1199 }
1200 $link['id'] = $xmlID;
1201 }
1202 }
1203
1204 # We don't want to give the watch tab an accesskey if the
1205 # page is being edited, because that conflicts with the
1206 # accesskey on the watch checkbox. We also don't want to
1207 # give the edit tab an accesskey, because that's fairly
1208 # superfluous and conflicts with an accesskey (Ctrl-E) often
1209 # used for editing in Safari.
1210 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1211 if ( isset( $content_navigation['views']['edit'] ) ) {
1212 $content_navigation['views']['edit']['tooltiponly'] = true;
1213 }
1214 if ( isset( $content_navigation['actions']['watch'] ) ) {
1215 $content_navigation['actions']['watch']['tooltiponly'] = true;
1216 }
1217 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1218 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1219 }
1220 }
1221
1222 return $content_navigation;
1223 }
1224
1225 /**
1226 * an array of edit links by default used for the tabs
1227 * @param array $content_navigation
1228 * @return array
1229 */
1230 private function buildContentActionUrls( $content_navigation ) {
1231 // content_actions has been replaced with content_navigation for backwards
1232 // compatibility and also for skins that just want simple tabs content_actions
1233 // is now built by flattening the content_navigation arrays into one
1234
1235 $content_actions = [];
1236
1237 foreach ( $content_navigation as $links ) {
1238 foreach ( $links as $key => $value ) {
1239 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1240 // Redundant tabs are dropped from content_actions
1241 continue;
1242 }
1243
1244 // content_actions used to have ids built using the "ca-$key" pattern
1245 // so the xmlID based id is much closer to the actual $key that we want
1246 // for that reason we'll just strip out the ca- if present and use
1247 // the latter potion of the "id" as the $key
1248 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1249 $key = substr( $value['id'], 3 );
1250 }
1251
1252 if ( isset( $content_actions[$key] ) ) {
1253 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
1254 "content_navigation into content_actions.\n" );
1255 continue;
1256 }
1257
1258 $content_actions[$key] = $value;
1259 }
1260 }
1261
1262 return $content_actions;
1263 }
1264
1265 /**
1266 * build array of common navigation links
1267 * @return array
1268 */
1269 protected function buildNavUrls() {
1270 global $wgUploadNavigationUrl;
1271
1272 $out = $this->getOutput();
1273 $request = $this->getRequest();
1274
1275 $nav_urls = [];
1276 $nav_urls['mainpage'] = [ 'href' => self::makeMainPageUrl() ];
1277 if ( $wgUploadNavigationUrl ) {
1278 $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
1279 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1280 $nav_urls['upload'] = [ 'href' => self::makeSpecialUrl( 'Upload' ) ];
1281 } else {
1282 $nav_urls['upload'] = false;
1283 }
1284 $nav_urls['specialpages'] = [ 'href' => self::makeSpecialUrl( 'Specialpages' ) ];
1285
1286 $nav_urls['print'] = false;
1287 $nav_urls['permalink'] = false;
1288 $nav_urls['info'] = false;
1289 $nav_urls['whatlinkshere'] = false;
1290 $nav_urls['recentchangeslinked'] = false;
1291 $nav_urls['contributions'] = false;
1292 $nav_urls['log'] = false;
1293 $nav_urls['blockip'] = false;
1294 $nav_urls['emailuser'] = false;
1295 $nav_urls['userrights'] = false;
1296
1297 // A print stylesheet is attached to all pages, but nobody ever
1298 // figures that out. :) Add a link...
1299 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1300 $nav_urls['print'] = [
1301 'text' => $this->msg( 'printableversion' )->text(),
1302 'href' => $this->getTitle()->getLocalURL(
1303 $request->appendQueryValue( 'printable', 'yes' ) )
1304 ];
1305 }
1306
1307 if ( $out->isArticle() ) {
1308 // Also add a "permalink" while we're at it
1309 $revid = $this->getRevisionId();
1310 if ( $revid ) {
1311 $nav_urls['permalink'] = [
1312 'text' => $this->msg( 'permalink' )->text(),
1313 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1314 ];
1315 }
1316
1317 // Avoid PHP 7.1 warning of passing $this by reference
1318 $skinTemplate = $this;
1319 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1320 Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1321 [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
1322 }
1323
1324 if ( $out->isArticleRelated() ) {
1325 $nav_urls['whatlinkshere'] = [
1326 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1327 ];
1328
1329 $nav_urls['info'] = [
1330 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1331 'href' => $this->getTitle()->getLocalURL( "action=info" )
1332 ];
1333
1334 if ( $this->getTitle()->exists() || $this->getTitle()->inNamespace( NS_CATEGORY ) ) {
1335 $nav_urls['recentchangeslinked'] = [
1336 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1337 ];
1338 }
1339 }
1340
1341 $user = $this->getRelevantUser();
1342 if ( $user ) {
1343 $rootUser = $user->getName();
1344
1345 $nav_urls['contributions'] = [
1346 'text' => $this->msg( 'contributions', $rootUser )->text(),
1347 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1348 'tooltip-params' => [ $rootUser ],
1349 ];
1350
1351 $nav_urls['log'] = [
1352 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1353 ];
1354
1355 if ( $this->getUser()->isAllowed( 'block' ) ) {
1356 $nav_urls['blockip'] = [
1357 'text' => $this->msg( 'blockip', $rootUser )->text(),
1358 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1359 ];
1360 }
1361
1362 if ( $this->showEmailUser( $user ) ) {
1363 $nav_urls['emailuser'] = [
1364 'text' => $this->msg( 'tool-link-emailuser', $rootUser )->text(),
1365 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1366 'tooltip-params' => [ $rootUser ],
1367 ];
1368 }
1369
1370 if ( !$user->isAnon() ) {
1371 $sur = new UserrightsPage;
1372 $sur->setContext( $this->getContext() );
1373 $canChange = $sur->userCanChangeRights( $user );
1374 $nav_urls['userrights'] = [
1375 'text' => $this->msg(
1376 $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
1377 $rootUser
1378 )->text(),
1379 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1380 ];
1381 }
1382 }
1383
1384 return $nav_urls;
1385 }
1386
1387 /**
1388 * Generate strings used for xml 'id' names
1389 * @return string
1390 */
1391 protected function getNameSpaceKey() {
1392 return $this->getTitle()->getNamespaceKey();
1393 }
1394 }