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