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