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