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