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