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