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