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