Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[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 * @param bool|string $repository Subdirectory where we keep template files
66 * @param bool|string $cache_dir
67 * @return QuickTemplate
68 * @private
69 */
70 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
71 return new $classname( $this->getConfig() );
72 }
73
74 /**
75 * Generates array of language links for the current page
76 *
77 * @return array
78 */
79 public function getLanguages() {
80 global $wgHideInterlanguageLinks;
81 if ( $wgHideInterlanguageLinks ) {
82 return [];
83 }
84
85 $userLang = $this->getLanguage();
86 $languageLinks = [];
87
88 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
89 $class = 'interlanguage-link interwiki-' . explode( ':', $languageLinkText, 2 )[0];
90
91 $languageLinkTitle = Title::newFromText( $languageLinkText );
92 if ( $languageLinkTitle ) {
93 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
94 $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
95
96 if ( strval( $ilLangName ) === '' ) {
97 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
98 if ( !$ilDisplayTextMsg->isDisabled() ) {
99 // Use custom MW message for the display text
100 $ilLangName = $ilDisplayTextMsg->text();
101 } else {
102 // Last resort: fallback to the language link target
103 $ilLangName = $languageLinkText;
104 }
105 } else {
106 // Use the language autonym as display text
107 $ilLangName = $this->formatLanguageName( $ilLangName );
108 }
109
110 // CLDR extension or similar is required to localize the language name;
111 // otherwise we'll end up with the autonym again.
112 $ilLangLocalName = Language::fetchLanguageName(
113 $ilInterwikiCode,
114 $userLang->getCode()
115 );
116
117 $languageLinkTitleText = $languageLinkTitle->getText();
118 if ( $ilLangLocalName === '' ) {
119 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
120 if ( !$ilFriendlySiteName->isDisabled() ) {
121 if ( $languageLinkTitleText === '' ) {
122 $ilTitle = wfMessage(
123 'interlanguage-link-title-nonlangonly',
124 $ilFriendlySiteName->text()
125 )->text();
126 } else {
127 $ilTitle = wfMessage(
128 'interlanguage-link-title-nonlang',
129 $languageLinkTitleText,
130 $ilFriendlySiteName->text()
131 )->text();
132 }
133 } else {
134 // we have nothing friendly to put in the title, so fall back to
135 // displaying the interlanguage link itself in the title text
136 // (similar to what is done in page content)
137 $ilTitle = $languageLinkTitle->getInterwiki() .
138 ":$languageLinkTitleText";
139 }
140 } elseif ( $languageLinkTitleText === '' ) {
141 $ilTitle = wfMessage(
142 'interlanguage-link-title-langonly',
143 $ilLangLocalName
144 )->text();
145 } else {
146 $ilTitle = wfMessage(
147 'interlanguage-link-title',
148 $languageLinkTitleText,
149 $ilLangLocalName
150 )->text();
151 }
152
153 $ilInterwikiCodeBCP47 = LanguageCode::bcp47( $ilInterwikiCode );
154 $languageLink = [
155 'href' => $languageLinkTitle->getFullURL(),
156 'text' => $ilLangName,
157 'title' => $ilTitle,
158 'class' => $class,
159 'link-class' => 'interlanguage-link-target',
160 'lang' => $ilInterwikiCodeBCP47,
161 'hreflang' => $ilInterwikiCodeBCP47,
162 ];
163 Hooks::run(
164 'SkinTemplateGetLanguageLink',
165 [ &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() ]
166 );
167 $languageLinks[] = $languageLink;
168 }
169 }
170
171 return $languageLinks;
172 }
173
174 protected function setupTemplateForOutput() {
175 $request = $this->getRequest();
176 $user = $this->getUser();
177 $title = $this->getTitle();
178
179 $tpl = $this->setupTemplate( $this->template, 'skins' );
180
181 $this->thispage = $title->getPrefixedDBkey();
182 $this->titletxt = $title->getPrefixedText();
183 $this->userpage = $user->getUserPage()->getPrefixedText();
184 $query = [];
185 if ( !$request->wasPosted() ) {
186 $query = $request->getValues();
187 unset( $query['title'] );
188 unset( $query['returnto'] );
189 unset( $query['returntoquery'] );
190 }
191 $this->thisquery = wfArrayToCgi( $query );
192 $this->loggedin = $user->isLoggedIn();
193 $this->username = $user->getName();
194
195 if ( $this->loggedin ) {
196 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
197 } else {
198 # This won't be used in the standard skins, but we define it to preserve the interface
199 # To save time, we check for existence
200 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
201 }
202
203 return $tpl;
204 }
205
206 /**
207 * initialize various variables and generate the template
208 *
209 * @param OutputPage $out
210 */
211 function outputPage( OutputPage $out = null ) {
212 Profiler::instance()->setTemplated( true );
213
214 $oldContext = null;
215 if ( $out !== null ) {
216 // Deprecated since 1.20, note added in 1.25
217 wfDeprecated( __METHOD__, '1.25' );
218 $oldContext = $this->getContext();
219 $this->setContext( $out->getContext() );
220 }
221
222 $out = $this->getOutput();
223
224 $this->initPage( $out );
225 $tpl = $this->prepareQuickTemplate();
226 // execute template
227 $res = $tpl->execute();
228
229 // result may be an error
230 $this->printOrError( $res );
231
232 if ( $oldContext ) {
233 $this->setContext( $oldContext );
234 }
235 }
236
237 /**
238 * Wrap the body text with language information and identifiable element
239 *
240 * @param Title $title
241 * @param string $html body text
242 * @return string html
243 */
244 protected function wrapHTML( $title, $html ) {
245 # An ID that includes the actual body text; without categories, contentSub, ...
246 $realBodyAttribs = [ 'id' => 'mw-content-text' ];
247
248 # Add a mw-content-ltr/rtl class to be able to style based on text
249 # direction when the content is different from the UI language (only
250 # when viewing)
251 # Most information on special pages and file pages is in user language,
252 # rather than content language, so those will not get this
253 if ( Action::getActionName( $this ) === 'view' &&
254 ( !$title->inNamespaces( NS_SPECIAL, NS_FILE ) || $title->isRedirect() ) ) {
255 $pageLang = $title->getPageViewLanguage();
256 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
257 $realBodyAttribs['dir'] = $pageLang->getDir();
258 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
259 }
260
261 return Html::rawElement( 'div', $realBodyAttribs, $html );
262 }
263
264 /**
265 * initialize various variables and generate the template
266 *
267 * @since 1.23
268 * @return QuickTemplate The template to be executed by outputPage
269 */
270 protected function prepareQuickTemplate() {
271 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
272 $wgSitename, $wgLogo, $wgMaxCredits,
273 $wgShowCreditsIfMax, $wgArticlePath,
274 $wgScriptPath, $wgServer;
275
276 $title = $this->getTitle();
277 $request = $this->getRequest();
278 $out = $this->getOutput();
279 $tpl = $this->setupTemplateForOutput();
280
281 $tpl->set( 'title', $out->getPageTitle() );
282 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
283 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
284
285 $tpl->set( 'thispage', $this->thispage );
286 $tpl->set( 'titleprefixeddbkey', $this->thispage );
287 $tpl->set( 'titletext', $title->getText() );
288 $tpl->set( 'articleid', $title->getArticleID() );
289
290 $tpl->set( 'isarticle', $out->isArticle() );
291
292 $subpagestr = $this->subPageSubtitle();
293 if ( $subpagestr !== '' ) {
294 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
295 }
296 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
297
298 $undelete = $this->getUndeleteLink();
299 if ( $undelete === '' ) {
300 $tpl->set( 'undelete', '' );
301 } else {
302 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
303 }
304
305 $tpl->set( 'catlinks', $this->getCategories() );
306 if ( $out->isSyndicated() ) {
307 $feeds = [];
308 foreach ( $out->getSyndicationLinks() as $format => $link ) {
309 $feeds[$format] = [
310 // Messages: feed-atom, feed-rss
311 'text' => $this->msg( "feed-$format" )->text(),
312 'href' => $link
313 ];
314 }
315 $tpl->set( 'feeds', $feeds );
316 } else {
317 $tpl->set( 'feeds', false );
318 }
319
320 $tpl->set( 'mimetype', $wgMimeType );
321 $tpl->set( 'jsmimetype', $wgJsMimeType );
322 $tpl->set( 'charset', 'UTF-8' );
323 $tpl->set( 'wgScript', $wgScript );
324 $tpl->set( 'skinname', $this->skinname );
325 $tpl->set( 'skinclass', static::class );
326 $tpl->set( 'skin', $this );
327 $tpl->set( 'stylename', $this->stylename );
328 $tpl->set( 'printable', $out->isPrintable() );
329 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
330 $tpl->set( 'loggedin', $this->loggedin );
331 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
332 $tpl->set( 'searchaction', $this->escapeSearchLink() );
333 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
334 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
335 $tpl->set( 'stylepath', $wgStylePath );
336 $tpl->set( 'articlepath', $wgArticlePath );
337 $tpl->set( 'scriptpath', $wgScriptPath );
338 $tpl->set( 'serverurl', $wgServer );
339 $tpl->set( 'logopath', $wgLogo );
340 $tpl->set( 'sitename', $wgSitename );
341
342 $userLang = $this->getLanguage();
343 $userLangCode = $userLang->getHtmlCode();
344 $userLangDir = $userLang->getDir();
345
346 $tpl->set( 'lang', $userLangCode );
347 $tpl->set( 'dir', $userLangDir );
348 $tpl->set( 'rtl', $userLang->isRTL() );
349
350 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
351 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
352 $tpl->set( 'username', $this->loggedin ? $this->username : null );
353 $tpl->set( 'userpage', $this->userpage );
354 $tpl->set( 'userpageurl', $this->userpageUrlDetails['href'] );
355 $tpl->set( 'userlang', $userLangCode );
356
357 // Users can have their language set differently than the
358 // content of the wiki. For these users, tell the web browser
359 // that interface elements are in a different language.
360 $tpl->set( 'userlangattributes', '' );
361 $tpl->set( 'specialpageattributes', '' ); # obsolete
362 // Used by VectorBeta to insert HTML before content but after the
363 // heading for the page title. Defaults to empty string.
364 $tpl->set( 'prebodyhtml', '' );
365
366 if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
367 $escUserlang = htmlspecialchars( $userLangCode );
368 $escUserdir = htmlspecialchars( $userLangDir );
369 // Attributes must be in double quotes because htmlspecialchars() doesn't
370 // escape single quotes
371 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
372 $tpl->set( 'userlangattributes', $attrs );
373 }
374
375 $tpl->set( 'newtalk', $this->getNewtalks() );
376 $tpl->set( 'logo', $this->logoText() );
377
378 $tpl->set( 'copyright', false );
379 // No longer used
380 $tpl->set( 'viewcount', false );
381 $tpl->set( 'lastmod', false );
382 $tpl->set( 'credits', false );
383 $tpl->set( 'numberofwatchingusers', false );
384 if ( $out->isArticle() && $title->exists() ) {
385 if ( $this->isRevisionCurrent() ) {
386 if ( $wgMaxCredits != 0 ) {
387 $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
388 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
389 } else {
390 $tpl->set( 'lastmod', $this->lastModified() );
391 }
392 }
393 $tpl->set( 'copyright', $this->getCopyright() );
394 }
395
396 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
397 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
398 $tpl->set( 'disclaimer', $this->disclaimerLink() );
399 $tpl->set( 'privacy', $this->privacyLink() );
400 $tpl->set( 'about', $this->aboutLink() );
401
402 $tpl->set( 'footerlinks', [
403 'info' => [
404 'lastmod',
405 'numberofwatchingusers',
406 'credits',
407 'copyright',
408 ],
409 'places' => [
410 'privacy',
411 'about',
412 'disclaimer',
413 ],
414 ] );
415
416 global $wgFooterIcons;
417 $tpl->set( 'footericons', $wgFooterIcons );
418 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
419 if ( count( $footerIconsBlock ) > 0 ) {
420 foreach ( $footerIconsBlock as &$footerIcon ) {
421 if ( isset( $footerIcon['src'] ) ) {
422 if ( !isset( $footerIcon['width'] ) ) {
423 $footerIcon['width'] = 88;
424 }
425 if ( !isset( $footerIcon['height'] ) ) {
426 $footerIcon['height'] = 31;
427 }
428 }
429 }
430 } else {
431 unset( $tpl->data['footericons'][$footerIconsKey] );
432 }
433 }
434
435 $tpl->set( 'indicators', $out->getIndicators() );
436
437 $tpl->set( 'sitenotice', $this->getSiteNotice() );
438 $tpl->set( 'printfooter', $this->printSource() );
439 // Wrap the bodyText with #mw-content-text element
440 $out->mBodytext = $this->wrapHTML( $title, $out->mBodytext );
441 $tpl->set( 'bodytext', $out->mBodytext );
442
443 $language_urls = $this->getLanguages();
444 if ( count( $language_urls ) ) {
445 $tpl->set( 'language_urls', $language_urls );
446 } else {
447 $tpl->set( 'language_urls', false );
448 }
449
450 # Personal toolbar
451 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
452 $content_navigation = $this->buildContentNavigationUrls();
453 $content_actions = $this->buildContentActionUrls( $content_navigation );
454 $tpl->set( 'content_navigation', $content_navigation );
455 $tpl->set( 'content_actions', $content_actions );
456
457 $tpl->set( 'sidebar', $this->buildSidebar() );
458 $tpl->set( 'nav_urls', $this->buildNavUrls() );
459
460 // Do this last in case hooks above add bottom scripts
461 $tpl->set( 'bottomscripts', $this->bottomScripts() );
462
463 // Set the head scripts near the end, in case the above actions resulted in added scripts
464 $tpl->set( 'headelement', $out->headElement( $this ) );
465
466 $tpl->set( 'debug', '' );
467 $tpl->set( 'debughtml', $this->generateDebugHTML() );
468 $tpl->set( 'reporttime', wfReportTime() );
469
470 // Avoid PHP 7.1 warning of passing $this by reference
471 $skinTemplate = $this;
472 // original version by hansm
473 if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
474 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
475 }
476
477 // Set the bodytext to another key so that skins can just output it on its own
478 // and output printfooter and debughtml separately
479 $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
480
481 // Append printfooter and debughtml onto bodytext so that skins that
482 // were already using bodytext before they were split out don't suddenly
483 // start not outputting information.
484 $tpl->data['bodytext'] .= Html::rawElement(
485 'div',
486 [ 'class' => 'printfooter' ],
487 "\n{$tpl->data['printfooter']}"
488 ) . "\n";
489 $tpl->data['bodytext'] .= $tpl->data['debughtml'];
490
491 // allow extensions adding stuff after the page content.
492 // See Skin::afterContentHook() for further documentation.
493 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
494
495 return $tpl;
496 }
497
498 /**
499 * Get the HTML for the p-personal list
500 * @return string
501 */
502 public function getPersonalToolsList() {
503 return $this->makePersonalToolsList();
504 }
505
506 /**
507 * Get the HTML for the personal tools list
508 *
509 * @since 1.31
510 *
511 * @param array $personalTools
512 * @param array $options
513 * @return string
514 */
515 public function makePersonalToolsList( $personalTools = null, $options = [] ) {
516 $tpl = $this->setupTemplateForOutput();
517 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
518 $html = '';
519
520 if ( $personalTools === null ) {
521 $personalTools = $tpl->getPersonalTools();
522 }
523
524 foreach ( $personalTools as $key => $item ) {
525 $html .= $tpl->makeListItem( $key, $item, $options );
526 }
527
528 return $html;
529 }
530
531 /**
532 * Get personal tools for the user
533 *
534 * @since 1.31
535 *
536 * @return array Array of personal tools
537 */
538 public function getStructuredPersonalTools() {
539 $tpl = $this->setupTemplateForOutput();
540 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
541
542 return $tpl->getPersonalTools();
543 }
544
545 /**
546 * Format language name for use in sidebar interlanguage links list.
547 * By default it is capitalized.
548 *
549 * @param string $name Language name, e.g. "English" or "español"
550 * @return string
551 * @private
552 */
553 function formatLanguageName( $name ) {
554 return $this->getLanguage()->ucfirst( $name );
555 }
556
557 /**
558 * Output the string, or print error message if it's
559 * an error object of the appropriate type.
560 * For the base class, assume strings all around.
561 *
562 * @param string $str
563 * @private
564 */
565 function printOrError( $str ) {
566 echo $str;
567 }
568
569 /**
570 * Output a boolean indicating if buildPersonalUrls should output separate
571 * login and create account links or output a combined link
572 * By default we simply return a global config setting that affects most skins
573 * This is setup as a method so that like with $wgLogo and getLogo() a skin
574 * can override this setting and always output one or the other if it has
575 * a reason it can't output one of the two modes.
576 * @return bool
577 */
578 function useCombinedLoginLink() {
579 global $wgUseCombinedLoginLink;
580 return $wgUseCombinedLoginLink;
581 }
582
583 /**
584 * build array of urls for personal toolbar
585 * @return array
586 */
587 protected function buildPersonalUrls() {
588 $title = $this->getTitle();
589 $request = $this->getRequest();
590 $pageurl = $title->getLocalURL();
591 $authManager = AuthManager::singleton();
592
593 /* set up the default links for the personal toolbar */
594 $personal_urls = [];
595
596 # Due to T34276, if a user does not have read permissions,
597 # $this->getTitle() will just give Special:Badtitle, which is
598 # not especially useful as a returnto parameter. Use the title
599 # from the request instead, if there was one.
600 if ( $this->getUser()->isAllowed( 'read' ) ) {
601 $page = $this->getTitle();
602 } else {
603 $page = Title::newFromText( $request->getVal( 'title', '' ) );
604 }
605 $page = $request->getVal( 'returnto', $page );
606 $a = [];
607 if ( strval( $page ) !== '' ) {
608 $a['returnto'] = $page;
609 $query = $request->getVal( 'returntoquery', $this->thisquery );
610 if ( $query != '' ) {
611 $a['returntoquery'] = $query;
612 }
613 }
614
615 $returnto = wfArrayToCgi( $a );
616 if ( $this->loggedin ) {
617 $personal_urls['userpage'] = [
618 'text' => $this->username,
619 'href' => &$this->userpageUrlDetails['href'],
620 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
621 'exists' => $this->userpageUrlDetails['exists'],
622 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
623 'dir' => 'auto'
624 ];
625 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
626 $personal_urls['mytalk'] = [
627 'text' => $this->msg( 'mytalk' )->text(),
628 'href' => &$usertalkUrlDetails['href'],
629 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
630 'exists' => $usertalkUrlDetails['exists'],
631 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
632 ];
633 $href = self::makeSpecialUrl( 'Preferences' );
634 $personal_urls['preferences'] = [
635 'text' => $this->msg( 'mypreferences' )->text(),
636 'href' => $href,
637 'active' => ( $href == $pageurl )
638 ];
639
640 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
641 $href = self::makeSpecialUrl( 'Watchlist' );
642 $personal_urls['watchlist'] = [
643 'text' => $this->msg( 'mywatchlist' )->text(),
644 'href' => $href,
645 'active' => ( $href == $pageurl )
646 ];
647 }
648
649 # We need to do an explicit check for Special:Contributions, as we
650 # have to match both the title, and the target, which could come
651 # from request values (Special:Contributions?target=Jimbo_Wales)
652 # or be specified in "sub page" form
653 # (Special:Contributions/Jimbo_Wales). The plot
654 # thickens, because the Title object is altered for special pages,
655 # so it doesn't contain the original alias-with-subpage.
656 $origTitle = Title::newFromText( $request->getText( 'title' ) );
657 if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
658 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
659 $active = $spName == 'Contributions'
660 && ( ( $spPar && $spPar == $this->username )
661 || $request->getText( 'target' ) == $this->username );
662 } else {
663 $active = false;
664 }
665
666 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
667 $personal_urls['mycontris'] = [
668 'text' => $this->msg( 'mycontris' )->text(),
669 'href' => $href,
670 'active' => $active
671 ];
672
673 // if we can't set the user, we can't unset it either
674 if ( $request->getSession()->canSetUser() ) {
675 $personal_urls['logout'] = [
676 'text' => $this->msg( 'pt-userlogout' )->text(),
677 'href' => self::makeSpecialUrl( 'Userlogout',
678 // userlogout link must always contain an & character, otherwise we might not be able
679 // to detect a buggy precaching proxy (T19790)
680 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto ),
681 'active' => false
682 ];
683 }
684 } else {
685 $useCombinedLoginLink = $this->useCombinedLoginLink();
686 if ( !$authManager->canCreateAccounts() || !$authManager->canAuthenticateNow() ) {
687 // don't show combined login/signup link if one of those is actually not available
688 $useCombinedLoginLink = false;
689 }
690
691 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
692 ? 'nav-login-createaccount'
693 : 'pt-login';
694
695 $login_url = [
696 'text' => $this->msg( $loginlink )->text(),
697 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
698 'active' => $title->isSpecial( 'Userlogin' )
699 || $title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink,
700 ];
701 $createaccount_url = [
702 'text' => $this->msg( 'pt-createaccount' )->text(),
703 'href' => self::makeSpecialUrl( 'CreateAccount', $returnto ),
704 'active' => $title->isSpecial( 'CreateAccount' ),
705 ];
706
707 // No need to show Talk and Contributions to anons if they can't contribute!
708 if ( User::groupHasPermission( '*', 'edit' ) ) {
709 // Because of caching, we can't link directly to the IP talk and
710 // contributions pages. Instead we use the special page shortcuts
711 // (which work correctly regardless of caching). This means we can't
712 // determine whether these links are active or not, but since major
713 // skins (MonoBook, Vector) don't use this information, it's not a
714 // huge loss.
715 $personal_urls['anontalk'] = [
716 'text' => $this->msg( 'anontalk' )->text(),
717 'href' => self::makeSpecialUrlSubpage( 'Mytalk', false ),
718 'active' => false
719 ];
720 $personal_urls['anoncontribs'] = [
721 'text' => $this->msg( 'anoncontribs' )->text(),
722 'href' => self::makeSpecialUrlSubpage( 'Mycontributions', false ),
723 'active' => false
724 ];
725 }
726
727 if (
728 $authManager->canCreateAccounts()
729 && $this->getUser()->isAllowed( 'createaccount' )
730 && !$useCombinedLoginLink
731 ) {
732 $personal_urls['createaccount'] = $createaccount_url;
733 }
734
735 if ( $authManager->canAuthenticateNow() ) {
736 $key = User::groupHasPermission( '*', 'read' )
737 ? 'login'
738 : 'login-private';
739 $personal_urls[$key] = $login_url;
740 }
741 }
742
743 Hooks::runWithoutAbort( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
744 return $personal_urls;
745 }
746
747 /**
748 * Builds an array with tab definition
749 *
750 * @param Title $title Page Where the tab links to
751 * @param string|array $message Message key or an array of message keys (will fall back)
752 * @param bool $selected Display the tab as selected
753 * @param string $query Query string attached to tab URL
754 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
755 *
756 * @return array
757 */
758 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
759 $classes = [];
760 if ( $selected ) {
761 $classes[] = 'selected';
762 }
763 $exists = true;
764 if ( $checkEdit && !$title->isKnown() ) {
765 $classes[] = 'new';
766 $exists = false;
767 if ( $query !== '' ) {
768 $query = 'action=edit&redlink=1&' . $query;
769 } else {
770 $query = 'action=edit&redlink=1';
771 }
772 }
773
774 $linkClass = MediaWikiServices::getInstance()->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 global $wgContLang;
787 $text = $wgContLang->getConverter()->convertNamespace(
788 MWNamespace::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 ( $user->isAllowed( 'deletedhistory' ) ) {
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 = $user->isAllowed( 'undelete' ) ? '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 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
1072 ) {
1073 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1074 $content_navigation['actions'][$mode] = [
1075 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1076 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1077 ->setContext( $this->getContext() )->text(),
1078 'href' => $title->getLocalURL( "action=$mode" )
1079 ];
1080 }
1081
1082 // Checks if the user is logged in
1083 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1084 /**
1085 * The following actions use messages which, if made particular to
1086 * the any specific skins, would break the Ajax code which makes this
1087 * action happen entirely inline. OutputPage::getJSVars
1088 * defines a set of messages in a javascript object - and these
1089 * messages are assumed to be global for all skins. Without making
1090 * a change to that procedure these messages will have to remain as
1091 * the global versions.
1092 */
1093 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1094 $content_navigation['actions'][$mode] = [
1095 'class' => 'mw-watchlink ' . (
1096 $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : ''
1097 ),
1098 // uses 'watch' or 'unwatch' message
1099 'text' => $this->msg( $mode )->text(),
1100 'href' => $title->getLocalURL( [ 'action' => $mode ] ),
1101 // Set a data-mw=interface attribute, which the mediawiki.page.ajax
1102 // module will look for to make sure it's a trusted link
1103 'data' => [
1104 'mw' => 'interface',
1105 ],
1106 ];
1107 }
1108 }
1109
1110 // Avoid PHP 7.1 warning of passing $this by reference
1111 $skinTemplate = $this;
1112 Hooks::runWithoutAbort(
1113 'SkinTemplateNavigation',
1114 [ &$skinTemplate, &$content_navigation ]
1115 );
1116
1117 if ( $userCanRead && !$wgDisableLangConversion ) {
1118 $pageLang = $title->getPageLanguage();
1119 // Gets list of language variants
1120 $variants = $pageLang->getVariants();
1121 // Checks that language conversion is enabled and variants exist
1122 // And if it is not in the special namespace
1123 if ( count( $variants ) > 1 ) {
1124 // Gets preferred variant (note that user preference is
1125 // only possible for wiki content language variant)
1126 $preferred = $pageLang->getPreferredVariant();
1127 if ( Action::getActionName( $this ) === 'view' ) {
1128 $params = $request->getQueryValues();
1129 unset( $params['title'] );
1130 } else {
1131 $params = [];
1132 }
1133 // Loops over each variant
1134 foreach ( $variants as $code ) {
1135 // Gets variant name from language code
1136 $varname = $pageLang->getVariantname( $code );
1137 // Appends variant link
1138 $content_navigation['variants'][] = [
1139 'class' => ( $code == $preferred ) ? 'selected' : false,
1140 'text' => $varname,
1141 'href' => $title->getLocalURL( [ 'variant' => $code ] + $params ),
1142 'lang' => LanguageCode::bcp47( $code ),
1143 'hreflang' => LanguageCode::bcp47( $code ),
1144 ];
1145 }
1146 }
1147 }
1148 } else {
1149 // If it's not content, it's got to be a special page
1150 $content_navigation['namespaces']['special'] = [
1151 'class' => 'selected',
1152 'text' => $this->msg( 'nstab-special' )->text(),
1153 'href' => $request->getRequestURL(), // @see: T4457, T4510
1154 'context' => 'subject'
1155 ];
1156
1157 // Avoid PHP 7.1 warning of passing $this by reference
1158 $skinTemplate = $this;
1159 Hooks::runWithoutAbort( 'SkinTemplateNavigation::SpecialPage',
1160 [ &$skinTemplate, &$content_navigation ] );
1161 }
1162
1163 // Avoid PHP 7.1 warning of passing $this by reference
1164 $skinTemplate = $this;
1165 // Equiv to SkinTemplateContentActions
1166 Hooks::runWithoutAbort( 'SkinTemplateNavigation::Universal',
1167 [ &$skinTemplate, &$content_navigation ] );
1168
1169 // Setup xml ids and tooltip info
1170 foreach ( $content_navigation as $section => &$links ) {
1171 foreach ( $links as $key => &$link ) {
1172 $xmlID = $key;
1173 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1174 $xmlID = 'ca-nstab-' . $xmlID;
1175 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1176 $xmlID = 'ca-talk';
1177 $link['rel'] = 'discussion';
1178 } elseif ( $section == 'variants' ) {
1179 $xmlID = 'ca-varlang-' . $xmlID;
1180 } else {
1181 $xmlID = 'ca-' . $xmlID;
1182 }
1183 $link['id'] = $xmlID;
1184 }
1185 }
1186
1187 # We don't want to give the watch tab an accesskey if the
1188 # page is being edited, because that conflicts with the
1189 # accesskey on the watch checkbox. We also don't want to
1190 # give the edit tab an accesskey, because that's fairly
1191 # superfluous and conflicts with an accesskey (Ctrl-E) often
1192 # used for editing in Safari.
1193 if ( in_array( $action, [ 'edit', 'submit' ] ) ) {
1194 if ( isset( $content_navigation['views']['edit'] ) ) {
1195 $content_navigation['views']['edit']['tooltiponly'] = true;
1196 }
1197 if ( isset( $content_navigation['actions']['watch'] ) ) {
1198 $content_navigation['actions']['watch']['tooltiponly'] = true;
1199 }
1200 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1201 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1202 }
1203 }
1204
1205 return $content_navigation;
1206 }
1207
1208 /**
1209 * an array of edit links by default used for the tabs
1210 * @param array $content_navigation
1211 * @return array
1212 */
1213 private function buildContentActionUrls( $content_navigation ) {
1214 // content_actions has been replaced with content_navigation for backwards
1215 // compatibility and also for skins that just want simple tabs content_actions
1216 // is now built by flattening the content_navigation arrays into one
1217
1218 $content_actions = [];
1219
1220 foreach ( $content_navigation as $links ) {
1221 foreach ( $links as $key => $value ) {
1222 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1223 // Redundant tabs are dropped from content_actions
1224 continue;
1225 }
1226
1227 // content_actions used to have ids built using the "ca-$key" pattern
1228 // so the xmlID based id is much closer to the actual $key that we want
1229 // for that reason we'll just strip out the ca- if present and use
1230 // the latter potion of the "id" as the $key
1231 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1232 $key = substr( $value['id'], 3 );
1233 }
1234
1235 if ( isset( $content_actions[$key] ) ) {
1236 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
1237 "content_navigation into content_actions.\n" );
1238 continue;
1239 }
1240
1241 $content_actions[$key] = $value;
1242 }
1243 }
1244
1245 return $content_actions;
1246 }
1247
1248 /**
1249 * build array of common navigation links
1250 * @return array
1251 */
1252 protected function buildNavUrls() {
1253 global $wgUploadNavigationUrl;
1254
1255 $out = $this->getOutput();
1256 $request = $this->getRequest();
1257
1258 $nav_urls = [];
1259 $nav_urls['mainpage'] = [ 'href' => self::makeMainPageUrl() ];
1260 if ( $wgUploadNavigationUrl ) {
1261 $nav_urls['upload'] = [ 'href' => $wgUploadNavigationUrl ];
1262 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1263 $nav_urls['upload'] = [ 'href' => self::makeSpecialUrl( 'Upload' ) ];
1264 } else {
1265 $nav_urls['upload'] = false;
1266 }
1267 $nav_urls['specialpages'] = [ 'href' => self::makeSpecialUrl( 'Specialpages' ) ];
1268
1269 $nav_urls['print'] = false;
1270 $nav_urls['permalink'] = false;
1271 $nav_urls['info'] = false;
1272 $nav_urls['whatlinkshere'] = false;
1273 $nav_urls['recentchangeslinked'] = false;
1274 $nav_urls['contributions'] = false;
1275 $nav_urls['log'] = false;
1276 $nav_urls['blockip'] = false;
1277 $nav_urls['emailuser'] = false;
1278 $nav_urls['userrights'] = false;
1279
1280 // A print stylesheet is attached to all pages, but nobody ever
1281 // figures that out. :) Add a link...
1282 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1283 $nav_urls['print'] = [
1284 'text' => $this->msg( 'printableversion' )->text(),
1285 'href' => $this->getTitle()->getLocalURL(
1286 $request->appendQueryValue( 'printable', 'yes' ) )
1287 ];
1288 }
1289
1290 if ( $out->isArticle() ) {
1291 // Also add a "permalink" while we're at it
1292 $revid = $this->getRevisionId();
1293 if ( $revid ) {
1294 $nav_urls['permalink'] = [
1295 'text' => $this->msg( 'permalink' )->text(),
1296 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1297 ];
1298 }
1299
1300 // Avoid PHP 7.1 warning of passing $this by reference
1301 $skinTemplate = $this;
1302 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1303 Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1304 [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
1305 }
1306
1307 if ( $out->isArticleRelated() ) {
1308 $nav_urls['whatlinkshere'] = [
1309 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1310 ];
1311
1312 $nav_urls['info'] = [
1313 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1314 'href' => $this->getTitle()->getLocalURL( "action=info" )
1315 ];
1316
1317 if ( $this->getTitle()->exists() || $this->getTitle()->inNamespace( NS_CATEGORY ) ) {
1318 $nav_urls['recentchangeslinked'] = [
1319 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1320 ];
1321 }
1322 }
1323
1324 $user = $this->getRelevantUser();
1325 if ( $user ) {
1326 $rootUser = $user->getName();
1327
1328 $nav_urls['contributions'] = [
1329 'text' => $this->msg( 'contributions', $rootUser )->text(),
1330 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1331 'tooltip-params' => [ $rootUser ],
1332 ];
1333
1334 $nav_urls['log'] = [
1335 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1336 ];
1337
1338 if ( $this->getUser()->isAllowed( 'block' ) ) {
1339 $nav_urls['blockip'] = [
1340 'text' => $this->msg( 'blockip', $rootUser )->text(),
1341 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1342 ];
1343 }
1344
1345 if ( $this->showEmailUser( $user ) ) {
1346 $nav_urls['emailuser'] = [
1347 'text' => $this->msg( 'tool-link-emailuser', $rootUser )->text(),
1348 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1349 'tooltip-params' => [ $rootUser ],
1350 ];
1351 }
1352
1353 if ( !$user->isAnon() ) {
1354 $sur = new UserrightsPage;
1355 $sur->setContext( $this->getContext() );
1356 $canChange = $sur->userCanChangeRights( $user );
1357 $nav_urls['userrights'] = [
1358 'text' => $this->msg(
1359 $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
1360 $rootUser
1361 )->text(),
1362 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1363 ];
1364 }
1365 }
1366
1367 return $nav_urls;
1368 }
1369
1370 /**
1371 * Generate strings used for xml 'id' names
1372 * @return string
1373 */
1374 protected function getNameSpaceKey() {
1375 return $this->getTitle()->getNamespaceKey();
1376 }
1377 }