MediaWiki  master
Skin.php
Go to the documentation of this file.
1 <?php
26 
38 abstract class Skin extends ContextSource {
42  protected $skinname = null;
43 
44  protected $mRelevantTitle = null;
45  protected $mRelevantUser = null;
46 
51  public $stylename = null;
52 
57  static function getSkinNames() {
58  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
59  return $skinFactory->getSkinNames();
60  }
61 
66  static function getSkinNameMessages() {
67  $messages = [];
68  foreach ( self::getSkinNames() as $skinKey => $skinName ) {
69  $messages[] = "skinname-$skinKey";
70  }
71  return $messages;
72  }
73 
81  public static function getAllowedSkins() {
82  global $wgSkipSkins;
83 
84  $allowedSkins = self::getSkinNames();
85 
86  foreach ( $wgSkipSkins as $skip ) {
87  unset( $allowedSkins[$skip] );
88  }
89 
90  return $allowedSkins;
91  }
92 
102  static function normalizeKey( $key ) {
104 
105  $skinNames = self::getSkinNames();
106 
107  // Make keys lowercase for case-insensitive matching.
108  $skinNames = array_change_key_case( $skinNames, CASE_LOWER );
109  $key = strtolower( $key );
110  $defaultSkin = strtolower( $wgDefaultSkin );
111  $fallbackSkin = strtolower( $wgFallbackSkin );
112 
113  if ( $key == '' || $key == 'default' ) {
114  // Don't return the default immediately;
115  // in a misconfiguration we need to fall back.
116  $key = $defaultSkin;
117  }
118 
119  if ( isset( $skinNames[$key] ) ) {
120  return $key;
121  }
122 
123  // Older versions of the software used a numeric setting
124  // in the user preferences.
125  $fallback = [
126  0 => $defaultSkin,
127  2 => 'cologneblue'
128  ];
129 
130  if ( isset( $fallback[$key] ) ) {
131  $key = $fallback[$key];
132  }
133 
134  if ( isset( $skinNames[$key] ) ) {
135  return $key;
136  } elseif ( isset( $skinNames[$defaultSkin] ) ) {
137  return $defaultSkin;
138  } else {
139  return $fallbackSkin;
140  }
141  }
142 
147  public function __construct( $skinname = null ) {
148  if ( is_string( $skinname ) ) {
149  $this->skinname = $skinname;
150  }
151  }
152 
156  public function getSkinName() {
157  return $this->skinname;
158  }
159 
163  public function initPage( OutputPage $out ) {
164  $this->preloadExistence();
165  }
166 
177  public function getDefaultModules() {
178  $out = $this->getOutput();
179  $user = $this->getUser();
180 
181  // Modules declared in the $modules literal are loaded
182  // for ALL users, on ALL pages, in ALL skins.
183  // Keep this list as small as possible!
184  $modules = [
185  'styles' => [
186  // The 'styles' key sets render-blocking style modules
187  // Unlike other keys in $modules, this is an associative array
188  // where each key is its own group pointing to a list of modules
189  'core' => [
190  'mediawiki.legacy.shared',
191  'mediawiki.legacy.commonPrint',
192  ],
193  'content' => [],
194  'syndicate' => [],
195  ],
196  'core' => [
197  'site',
198  'mediawiki.page.startup',
199  ],
200  // modules that enhance the content in some way
201  'content' => [
202  'mediawiki.page.ready',
203  ],
204  // modules relating to search functionality
205  'search' => [
206  'mediawiki.searchSuggest',
207  ],
208  // modules relating to functionality relating to watching an article
209  'watch' => [],
210  // modules which relate to the current users preferences
211  'user' => [],
212  // modules relating to RSS/Atom Feeds
213  'syndicate' => [],
214  ];
215 
216  // Preload jquery.tablesorter for mediawiki.page.ready
217  if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
218  $modules['content'][] = 'jquery.tablesorter';
219  $modules['styles']['content'][] = 'jquery.tablesorter.styles';
220  }
221 
222  // Preload jquery.makeCollapsible for mediawiki.page.ready
223  if ( strpos( $out->getHTML(), 'mw-collapsible' ) !== false ) {
224  $modules['content'][] = 'jquery.makeCollapsible';
225  $modules['styles']['content'][] = 'jquery.makeCollapsible.styles';
226  }
227 
228  // Deprecated since 1.26: Unconditional loading of mediawiki.ui.button
229  // on every page is deprecated. Express a dependency instead.
230  if ( strpos( $out->getHTML(), 'mw-ui-button' ) !== false ) {
231  $modules['styles']['content'][] = 'mediawiki.ui.button';
232  }
233 
234  if ( $out->isTOCEnabled() ) {
235  $modules['content'][] = 'mediawiki.toc';
236  $modules['styles']['content'][] = 'mediawiki.toc.styles';
237  }
238 
239  // Add various resources if required
240  if ( $user->isLoggedIn()
241  && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
242  && $this->getRelevantTitle()->canExist()
243  ) {
244  $modules['watch'][] = 'mediawiki.page.watch.ajax';
245  }
246 
247  if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
248  $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
249  }
250 
251  // Crazy edit-on-double-click stuff
252  if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
253  $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
254  }
255 
256  if ( $out->isSyndicated() ) {
257  $modules['styles']['syndicate'][] = 'mediawiki.feedlink';
258  }
259 
260  return $modules;
261  }
262 
266  protected function preloadExistence() {
267  $titles = [];
268 
269  // User/talk link
270  $user = $this->getUser();
271  if ( $user->isLoggedIn() ) {
272  $titles[] = $user->getUserPage();
273  $titles[] = $user->getTalkPage();
274  }
275 
276  // Check, if the page can hold some kind of content, otherwise do nothing
277  $title = $this->getRelevantTitle();
278  if ( $title->canExist() && $title->canHaveTalkPage() ) {
279  if ( $title->isTalkPage() ) {
280  $titles[] = $title->getSubjectPage();
281  } else {
282  $titles[] = $title->getTalkPage();
283  }
284  }
285 
286  // Footer links (used by SkinTemplate::prepareQuickTemplate)
287  foreach ( [
288  $this->footerLinkTitle( 'privacy', 'privacypage' ),
289  $this->footerLinkTitle( 'aboutsite', 'aboutpage' ),
290  $this->footerLinkTitle( 'disclaimers', 'disclaimerpage' ),
291  ] as $title ) {
292  if ( $title ) {
293  $titles[] = $title;
294  }
295  }
296 
297  Hooks::run( 'SkinPreloadExistence', [ &$titles, $this ] );
298 
299  if ( $titles ) {
300  $lb = new LinkBatch( $titles );
301  $lb->setCaller( __METHOD__ );
302  $lb->execute();
303  }
304  }
305 
311  public function getRevisionId() {
312  return $this->getOutput()->getRevisionId();
313  }
314 
320  public function isRevisionCurrent() {
321  $revID = $this->getRevisionId();
322  return $revID == 0 || $revID == $this->getTitle()->getLatestRevID();
323  }
324 
330  public function setRelevantTitle( $t ) {
331  $this->mRelevantTitle = $t;
332  }
333 
344  public function getRelevantTitle() {
345  return $this->mRelevantTitle ?? $this->getTitle();
346  }
347 
353  public function setRelevantUser( $u ) {
354  $this->mRelevantUser = $u;
355  }
356 
365  public function getRelevantUser() {
366  if ( isset( $this->mRelevantUser ) ) {
367  return $this->mRelevantUser;
368  }
369  $title = $this->getRelevantTitle();
370  if ( $title->hasSubjectNamespace( NS_USER ) ) {
371  $rootUser = $title->getRootText();
372  if ( User::isIP( $rootUser ) ) {
373  $this->mRelevantUser = User::newFromName( $rootUser, false );
374  } else {
375  $user = User::newFromName( $rootUser, false );
376 
377  if ( $user ) {
378  $user->load( User::READ_NORMAL );
379 
380  if ( $user->isLoggedIn() ) {
381  $this->mRelevantUser = $user;
382  }
383  }
384  }
385  return $this->mRelevantUser;
386  }
387  return null;
388  }
389 
393  abstract function outputPage();
394 
400  public static function makeVariablesScript( $data, $nonce = null ) {
401  if ( $data ) {
404  $nonce
405  );
406  }
407  return '';
408  }
409 
416  public static function getDynamicStylesheetQuery() {
417  return [
418  'action' => 'raw',
419  'ctype' => 'text/css',
420  ];
421  }
422 
429  public function setupSkinUserCss( OutputPage $out ) {
430  // Stub.
431  }
432 
438  function getPageClasses( $title ) {
439  $numeric = 'ns-' . $title->getNamespace();
440  $user = $this->getUser();
441 
442  if ( $title->isSpecialPage() ) {
443  $type = 'ns-special';
444  // T25315: provide a class based on the canonical special page name without subpages
445  list( $canonicalName ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
446  resolveAlias( $title->getDBkey() );
447  if ( $canonicalName ) {
448  $type .= ' ' . Sanitizer::escapeClass( "mw-special-$canonicalName" );
449  } else {
450  $type .= ' mw-invalidspecialpage';
451  }
452  } else {
453  if ( $title->isTalkPage() ) {
454  $type = 'ns-talk';
455  } else {
456  $type = 'ns-subject';
457  }
458  // T208315: add HTML class when the user can edit the page
459  if ( $title->quickUserCan( 'edit', $user ) ) {
460  $type .= ' mw-editable';
461  }
462  }
463 
464  $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
465  $root = Sanitizer::escapeClass( 'rootpage-' . $title->getRootTitle()->getPrefixedText() );
466 
467  return "$numeric $type $name $root";
468  }
469 
474  public function getHtmlElementAttributes() {
475  $lang = $this->getLanguage();
476  return [
477  'lang' => $lang->getHtmlCode(),
478  'dir' => $lang->getDir(),
479  'class' => 'client-nojs',
480  ];
481  }
482 
490  function addToBodyAttributes( $out, &$bodyAttrs ) {
491  // does nothing by default
492  }
493 
498  function getLogo() {
499  return $this->getConfig()->get( 'Logo' );
500  }
501 
511  public function shouldPreloadLogo() {
512  return false;
513  }
514 
518  function getCategoryLinks() {
519  $out = $this->getOutput();
520  $allCats = $out->getCategoryLinks();
521  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
522 
523  if ( $allCats === [] ) {
524  return '';
525  }
526 
527  $embed = "<li>";
528  $pop = "</li>";
529 
530  $s = '';
531  $colon = $this->msg( 'colon-separator' )->escaped();
532 
533  if ( !empty( $allCats['normal'] ) ) {
534  $t = $embed . implode( $pop . $embed, $allCats['normal'] ) . $pop;
535 
536  $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) );
537  $linkPage = $this->msg( 'pagecategorieslink' )->inContentLanguage()->text();
538  $title = Title::newFromText( $linkPage );
539  $link = $title ? $linkRenderer->makeLink( $title, $msg->text() ) : $msg->escaped();
540  $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
541  $link . $colon . '<ul>' . $t . '</ul></div>';
542  }
543 
544  # Hidden categories
545  if ( isset( $allCats['hidden'] ) ) {
546  if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
547  $class = ' mw-hidden-cats-user-shown';
548  } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
549  $class = ' mw-hidden-cats-ns-shown';
550  } else {
551  $class = ' mw-hidden-cats-hidden';
552  }
553 
554  $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
555  $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
556  $colon . '<ul>' . $embed . implode( $pop . $embed, $allCats['hidden'] ) . $pop . '</ul>' .
557  '</div>';
558  }
559 
560  # optional 'dmoz-like' category browser. Will be shown under the list
561  # of categories an article belong to
562  if ( $this->getConfig()->get( 'UseCategoryBrowser' ) ) {
563  $s .= '<br /><hr />';
564 
565  # get a big array of the parents tree
566  $parenttree = $this->getTitle()->getParentCategoryTree();
567  # Skin object passed by reference cause it can not be
568  # accessed under the method subfunction drawCategoryBrowser
569  $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree ) );
570  # Clean out bogus first entry and sort them
571  unset( $tempout[0] );
572  asort( $tempout );
573  # Output one per line
574  $s .= implode( "<br />\n", $tempout );
575  }
576 
577  return $s;
578  }
579 
585  function drawCategoryBrowser( $tree ) {
586  $return = '';
587  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
588 
589  foreach ( $tree as $element => $parent ) {
590  if ( empty( $parent ) ) {
591  # element start a new list
592  $return .= "\n";
593  } else {
594  # grab the others elements
595  $return .= $this->drawCategoryBrowser( $parent ) . ' &gt; ';
596  }
597 
598  # add our current element to the list
599  $eltitle = Title::newFromText( $element );
600  $return .= $linkRenderer->makeLink( $eltitle, $eltitle->getText() );
601  }
602 
603  return $return;
604  }
605 
609  function getCategories() {
610  $out = $this->getOutput();
611  $catlinks = $this->getCategoryLinks();
612 
613  // Check what we're showing
614  $allCats = $out->getCategoryLinks();
615  $showHidden = $this->getUser()->getBoolOption( 'showhiddencats' ) ||
616  $this->getTitle()->getNamespace() == NS_CATEGORY;
617 
618  $classes = [ 'catlinks' ];
619  if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
620  $classes[] = 'catlinks-allhidden';
621  }
622 
623  return Html::rawElement(
624  'div',
625  [ 'id' => 'catlinks', 'class' => $classes, 'data-mw' => 'interface' ],
626  $catlinks
627  );
628  }
629 
644  protected function afterContentHook() {
645  $data = '';
646 
647  if ( Hooks::run( 'SkinAfterContent', [ &$data, $this ] ) ) {
648  // adding just some spaces shouldn't toggle the output
649  // of the whole <div/>, so we use trim() here
650  if ( trim( $data ) != '' ) {
651  // Doing this here instead of in the skins to
652  // ensure that the div has the same ID in all
653  // skins
654  $data = "<div id='mw-data-after-content'>\n" .
655  "\t$data\n" .
656  "</div>\n";
657  }
658  } else {
659  wfDebug( "Hook SkinAfterContent changed output processing.\n" );
660  }
661 
662  return $data;
663  }
664 
670  protected function generateDebugHTML() {
671  return MWDebug::getHTMLDebugLog();
672  }
673 
679  function bottomScripts() {
680  // TODO and the suckage continues. This function is really just a wrapper around
681  // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
682  // up at some point
683  $chunks = [ $this->getOutput()->getBottomScripts() ];
684 
685  // Keep the hook appendage separate to preserve WrappedString objects.
686  // This enables BaseTemplate::getTrail() to merge them where possible.
687  $extraHtml = '';
688  Hooks::run( 'SkinAfterBottomScripts', [ $this, &$extraHtml ] );
689  if ( $extraHtml !== '' ) {
690  $chunks[] = $extraHtml;
691  }
692  return WrappedString::join( "\n", $chunks );
693  }
694 
701  function printSource() {
702  $oldid = $this->getRevisionId();
703  if ( $oldid ) {
704  $canonicalUrl = $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid );
705  $url = htmlspecialchars( wfExpandIRI( $canonicalUrl ) );
706  } else {
707  // oldid not available for non existing pages
708  $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
709  }
710 
711  return $this->msg( 'retrievedfrom' )
712  ->rawParams( '<a dir="ltr" href="' . $url . '">' . $url . '</a>' )
713  ->parse();
714  }
715 
719  function getUndeleteLink() {
720  $action = $this->getRequest()->getVal( 'action', 'view' );
721  $title = $this->getTitle();
722  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
723 
724  if ( ( !$title->exists() || $action == 'history' ) &&
725  $title->quickUserCan( 'deletedhistory', $this->getUser() )
726  ) {
727  $n = $title->isDeleted();
728 
729  if ( $n ) {
730  if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
731  $msg = 'thisisdeleted';
732  } else {
733  $msg = 'viewdeleted';
734  }
735 
736  return $this->msg( $msg )->rawParams(
737  $linkRenderer->makeKnownLink(
738  SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
739  $this->msg( 'restorelink' )->numParams( $n )->text() )
740  )->escaped();
741  }
742  }
743 
744  return '';
745  }
746 
751  function subPageSubtitle( $out = null ) {
752  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
753  if ( $out === null ) {
754  $out = $this->getOutput();
755  }
756  $title = $out->getTitle();
757  $subpages = '';
758 
759  if ( !Hooks::run( 'SkinSubPageSubtitle', [ &$subpages, $this, $out ] ) ) {
760  return $subpages;
761  }
762 
763  if (
764  $out->isArticle() && MediaWikiServices::getInstance()->getNamespaceInfo()->
765  hasSubpages( $title->getNamespace() )
766  ) {
767  $ptext = $title->getPrefixedText();
768  if ( strpos( $ptext, '/' ) !== false ) {
769  $links = explode( '/', $ptext );
770  array_pop( $links );
771  $c = 0;
772  $growinglink = '';
773  $display = '';
774  $lang = $this->getLanguage();
775 
776  foreach ( $links as $link ) {
777  $growinglink .= $link;
778  $display .= $link;
779  $linkObj = Title::newFromText( $growinglink );
780 
781  if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
782  $getlink = $linkRenderer->makeKnownLink(
783  $linkObj, $display
784  );
785 
786  $c++;
787 
788  if ( $c > 1 ) {
789  $subpages .= $lang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
790  } else {
791  $subpages .= '&lt; ';
792  }
793 
794  $subpages .= $getlink;
795  $display = '';
796  } else {
797  $display .= '/';
798  }
799  $growinglink .= '/';
800  }
801  }
802  }
803 
804  return $subpages;
805  }
806 
810  function getSearchLink() {
812  return $searchPage->getLocalURL();
813  }
814 
819  function escapeSearchLink() {
820  wfDeprecated( __METHOD__, '1.34' );
821  return htmlspecialchars( $this->getSearchLink() );
822  }
823 
828  function getCopyright( $type = 'detect' ) {
829  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
830  if ( $type == 'detect' ) {
831  if ( !$this->isRevisionCurrent()
832  && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
833  ) {
834  $type = 'history';
835  } else {
836  $type = 'normal';
837  }
838  }
839 
840  if ( $type == 'history' ) {
841  $msg = 'history_copyright';
842  } else {
843  $msg = 'copyright';
844  }
845 
846  $config = $this->getConfig();
847 
848  if ( $config->get( 'RightsPage' ) ) {
849  $title = Title::newFromText( $config->get( 'RightsPage' ) );
850  $link = $linkRenderer->makeKnownLink(
851  $title, new HtmlArmor( $config->get( 'RightsText' ) )
852  );
853  } elseif ( $config->get( 'RightsUrl' ) ) {
854  $link = Linker::makeExternalLink( $config->get( 'RightsUrl' ), $config->get( 'RightsText' ) );
855  } elseif ( $config->get( 'RightsText' ) ) {
856  $link = $config->get( 'RightsText' );
857  } else {
858  # Give up now
859  return '';
860  }
861 
862  // Allow for site and per-namespace customization of copyright notice.
863  // @todo Remove deprecated $forContent param from hook handlers and then remove here.
864  $forContent = true;
865 
866  Hooks::run(
867  'SkinCopyrightFooter',
868  [ $this->getTitle(), $type, &$msg, &$link, &$forContent ]
869  );
870 
871  return $this->msg( $msg )->rawParams( $link )->text();
872  }
873 
877  function getCopyrightIcon() {
878  $out = '';
879  $config = $this->getConfig();
880 
881  $footerIcons = $config->get( 'FooterIcons' );
882  if ( $footerIcons['copyright']['copyright'] ) {
883  $out = $footerIcons['copyright']['copyright'];
884  } elseif ( $config->get( 'RightsIcon' ) ) {
885  $icon = htmlspecialchars( $config->get( 'RightsIcon' ) );
886  $url = $config->get( 'RightsUrl' );
887 
888  if ( $url ) {
889  $out .= '<a href="' . htmlspecialchars( $url ) . '">';
890  }
891 
892  $text = htmlspecialchars( $config->get( 'RightsText' ) );
893  $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
894 
895  if ( $url ) {
896  $out .= '</a>';
897  }
898  }
899 
900  return $out;
901  }
902 
907  function getPoweredBy() {
908  $resourceBasePath = $this->getConfig()->get( 'ResourceBasePath' );
909  $url1 = htmlspecialchars(
910  "$resourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
911  );
912  $url1_5 = htmlspecialchars(
913  "$resourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
914  );
915  $url2 = htmlspecialchars(
916  "$resourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
917  );
918  $text = '<a href="https://www.mediawiki.org/"><img src="' . $url1
919  . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
920  . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
921  Hooks::run( 'SkinGetPoweredBy', [ &$text, $this ] );
922  return $text;
923  }
924 
930  protected function lastModified() {
931  $timestamp = $this->getOutput()->getRevisionTimestamp();
932 
933  # No cached timestamp, load it from the database
934  if ( $timestamp === null ) {
935  $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
936  }
937 
938  if ( $timestamp ) {
939  $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() );
940  $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() );
941  $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse();
942  } else {
943  $s = '';
944  }
945 
946  if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) {
947  $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
948  }
949 
950  return $s;
951  }
952 
957  function logoText( $align = '' ) {
958  if ( $align != '' ) {
959  $a = " style='float: {$align};'";
960  } else {
961  $a = '';
962  }
963 
964  $mp = $this->msg( 'mainpage' )->escaped();
965  $mptitle = Title::newMainPage();
966  $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
967 
968  $logourl = $this->getLogo();
969  $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
970 
971  return $s;
972  }
973 
982  function makeFooterIcon( $icon, $withImage = 'withImage' ) {
983  if ( is_string( $icon ) ) {
984  $html = $icon;
985  } else { // Assuming array
986  $url = $icon["url"] ?? null;
987  unset( $icon["url"] );
988  if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
989  // do this the lazy way, just pass icon data as an attribute array
990  $html = Html::element( 'img', $icon );
991  } else {
992  $html = htmlspecialchars( $icon["alt"] );
993  }
994  if ( $url ) {
995  $html = Html::rawElement( 'a',
996  [ "href" => $url, "target" => $this->getConfig()->get( 'ExternalLinkTarget' ) ],
997  $html );
998  }
999  }
1000  return $html;
1001  }
1002 
1007  function mainPageLink() {
1008  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1009  $s = $linkRenderer->makeKnownLink(
1011  $this->msg( 'mainpage' )->text()
1012  );
1013 
1014  return $s;
1015  }
1016 
1023  public function footerLink( $desc, $page ) {
1024  $title = $this->footerLinkTitle( $desc, $page );
1025  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1026  if ( !$title ) {
1027  return '';
1028  }
1029 
1030  return $linkRenderer->makeKnownLink(
1031  $title,
1032  $this->msg( $desc )->text()
1033  );
1034  }
1035 
1041  private function footerLinkTitle( $desc, $page ) {
1042  // If the link description has been set to "-" in the default language,
1043  if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
1044  // then it is disabled, for all languages.
1045  return null;
1046  }
1047  // Otherwise, we display the link for the user, described in their
1048  // language (which may or may not be the same as the default language),
1049  // but we make the link target be the one site-wide page.
1050  $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
1051 
1052  return $title ?: null;
1053  }
1054 
1059  function privacyLink() {
1060  return $this->footerLink( 'privacy', 'privacypage' );
1061  }
1062 
1067  function aboutLink() {
1068  return $this->footerLink( 'aboutsite', 'aboutpage' );
1069  }
1070 
1075  function disclaimerLink() {
1076  return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1077  }
1078 
1086  function editUrlOptions() {
1087  $options = [ 'action' => 'edit' ];
1088 
1089  if ( !$this->isRevisionCurrent() ) {
1090  $options['oldid'] = intval( $this->getRevisionId() );
1091  }
1092 
1093  return $options;
1094  }
1095 
1100  function showEmailUser( $id ) {
1101  if ( $id instanceof User ) {
1102  $targetUser = $id;
1103  } else {
1104  $targetUser = User::newFromId( $id );
1105  }
1106 
1107  # The sending user must have a confirmed email address and the receiving
1108  # user must accept emails from the sender.
1109  return $this->getUser()->canSendEmail()
1110  && SpecialEmailUser::validateTarget( $targetUser, $this->getUser() ) === '';
1111  }
1112 
1124  function getSkinStylePath( $name ) {
1125  if ( $this->stylename === null ) {
1126  $class = static::class;
1127  throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
1128  }
1129 
1130  return $this->getConfig()->get( 'StylePath' ) . "/{$this->stylename}/$name";
1131  }
1132 
1133  /* these are used extensively in SkinTemplate, but also some other places */
1134 
1139  static function makeMainPageUrl( $urlaction = '' ) {
1141  self::checkTitle( $title, '' );
1142 
1143  return $title->getLinkURL( $urlaction );
1144  }
1145 
1157  static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
1159  if ( is_null( $proto ) ) {
1160  return $title->getLocalURL( $urlaction );
1161  } else {
1162  return $title->getFullURL( $urlaction, false, $proto );
1163  }
1164  }
1165 
1172  static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1173  $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1174  return $title->getLocalURL( $urlaction );
1175  }
1176 
1182  static function makeI18nUrl( $name, $urlaction = '' ) {
1183  $title = Title::newFromText( wfMessage( $name )->inContentLanguage()->text() );
1184  self::checkTitle( $title, $name );
1185  return $title->getLocalURL( $urlaction );
1186  }
1187 
1193  static function makeUrl( $name, $urlaction = '' ) {
1195  self::checkTitle( $title, $name );
1196 
1197  return $title->getLocalURL( $urlaction );
1198  }
1199 
1206  static function makeInternalOrExternalUrl( $name ) {
1207  if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $name ) ) {
1208  return $name;
1209  } else {
1210  return self::makeUrl( $name );
1211  }
1212  }
1213 
1221  static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1222  $title = Title::makeTitleSafe( $namespace, $name );
1223  self::checkTitle( $title, $name );
1224 
1225  return $title->getLocalURL( $urlaction );
1226  }
1227 
1234  static function makeUrlDetails( $name, $urlaction = '' ) {
1236  self::checkTitle( $title, $name );
1237 
1238  return [
1239  'href' => $title->getLocalURL( $urlaction ),
1240  'exists' => $title->isKnown(),
1241  ];
1242  }
1243 
1250  static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1252  self::checkTitle( $title, $name );
1253 
1254  return [
1255  'href' => $title->getLocalURL( $urlaction ),
1256  'exists' => true
1257  ];
1258  }
1259 
1266  static function checkTitle( &$title, $name ) {
1267  if ( !is_object( $title ) ) {
1269  if ( !is_object( $title ) ) {
1270  $title = Title::newFromText( '--error: link target missing--' );
1271  }
1272  }
1273  }
1274 
1296  public function buildSidebar() {
1297  $callback = function ( $old = null, &$ttl = null ) {
1298  $bar = [];
1299  $this->addToSidebar( $bar, 'sidebar' );
1300  Hooks::run( 'SkinBuildSidebar', [ $this, &$bar ] );
1301  if ( MessageCache::singleton()->isDisabled() ) {
1302  $ttl = WANObjectCache::TTL_UNCACHEABLE; // bug T133069
1303  }
1304 
1305  return $bar;
1306  };
1307 
1308  $msgCache = MessageCache::singleton();
1309  $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
1310  $config = $this->getConfig();
1311 
1312  $sidebar = $config->get( 'EnableSidebarCache' )
1313  ? $wanCache->getWithSetCallback(
1314  $wanCache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
1315  $config->get( 'SidebarCacheExpiry' ),
1316  $callback,
1317  [
1318  'checkKeys' => [
1319  // Unless there is both no exact $code override nor an i18n definition
1320  // in the software, the only MediaWiki page to check is for $code.
1321  $msgCache->getCheckKey( $this->getLanguage()->getCode() )
1322  ],
1323  'lockTSE' => 30
1324  ]
1325  )
1326  : $callback();
1327 
1328  // Apply post-processing to the cached value
1329  Hooks::run( 'SidebarBeforeOutput', [ $this, &$sidebar ] );
1330 
1331  return $sidebar;
1332  }
1333 
1343  public function addToSidebar( &$bar, $message ) {
1344  $this->addToSidebarPlain( $bar, $this->msg( $message )->inContentLanguage()->plain() );
1345  }
1346 
1354  function addToSidebarPlain( &$bar, $text ) {
1355  $lines = explode( "\n", $text );
1356 
1357  $heading = '';
1358  $config = $this->getConfig();
1359  $messageTitle = $config->get( 'EnableSidebarCache' )
1360  ? Title::newMainPage() : $this->getTitle();
1361 
1362  foreach ( $lines as $line ) {
1363  if ( strpos( $line, '*' ) !== 0 ) {
1364  continue;
1365  }
1366  $line = rtrim( $line, "\r" ); // for Windows compat
1367 
1368  if ( strpos( $line, '**' ) !== 0 ) {
1369  $heading = trim( $line, '* ' );
1370  if ( !array_key_exists( $heading, $bar ) ) {
1371  $bar[$heading] = [];
1372  }
1373  } else {
1374  $line = trim( $line, '* ' );
1375 
1376  if ( strpos( $line, '|' ) !== false ) { // sanity check
1377  $line = MessageCache::singleton()->transform( $line, false, null, $messageTitle );
1378  $line = array_map( 'trim', explode( '|', $line, 2 ) );
1379  if ( count( $line ) !== 2 ) {
1380  // Second sanity check, could be hit by people doing
1381  // funky stuff with parserfuncs... (T35321)
1382  continue;
1383  }
1384 
1385  $extraAttribs = [];
1386 
1387  $msgLink = $this->msg( $line[0] )->title( $messageTitle )->inContentLanguage();
1388  if ( $msgLink->exists() ) {
1389  $link = $msgLink->text();
1390  if ( $link == '-' ) {
1391  continue;
1392  }
1393  } else {
1394  $link = $line[0];
1395  }
1396  $msgText = $this->msg( $line[1] )->title( $messageTitle );
1397  if ( $msgText->exists() ) {
1398  $text = $msgText->text();
1399  } else {
1400  $text = $line[1];
1401  }
1402 
1403  if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
1404  $href = $link;
1405 
1406  // Parser::getExternalLinkAttribs won't work here because of the Namespace things
1407  if ( $config->get( 'NoFollowLinks' ) &&
1408  !wfMatchesDomainList( $href, $config->get( 'NoFollowDomainExceptions' ) )
1409  ) {
1410  $extraAttribs['rel'] = 'nofollow';
1411  }
1412 
1413  if ( $config->get( 'ExternalLinkTarget' ) ) {
1414  $extraAttribs['target'] = $config->get( 'ExternalLinkTarget' );
1415  }
1416  } else {
1418 
1419  if ( $title ) {
1420  $title = $title->fixSpecialName();
1421  $href = $title->getLinkURL();
1422  } else {
1423  $href = 'INVALID-TITLE';
1424  }
1425  }
1426 
1427  $bar[$heading][] = array_merge( [
1428  'text' => $text,
1429  'href' => $href,
1430  'id' => Sanitizer::escapeIdForAttribute( 'n-' . strtr( $line[1], ' ', '-' ) ),
1431  'active' => false,
1432  ], $extraAttribs );
1433  } else {
1434  continue;
1435  }
1436  }
1437  }
1438 
1439  return $bar;
1440  }
1441 
1447  function getNewtalks() {
1448  $newMessagesAlert = '';
1449  $user = $this->getUser();
1450  $newtalks = $user->getNewMessageLinks();
1451  $out = $this->getOutput();
1452  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1453 
1454  // Allow extensions to disable or modify the new messages alert
1455  if ( !Hooks::run( 'GetNewMessagesAlert', [ &$newMessagesAlert, $newtalks, $user, $out ] ) ) {
1456  return '';
1457  }
1458  if ( $newMessagesAlert ) {
1459  return $newMessagesAlert;
1460  }
1461 
1462  if ( count( $newtalks ) == 1 && WikiMap::isCurrentWikiId( $newtalks[0]['wiki'] ) ) {
1463  $uTalkTitle = $user->getTalkPage();
1464  $lastSeenRev = $newtalks[0]['rev'] ?? null;
1465  $nofAuthors = 0;
1466  if ( $lastSeenRev !== null ) {
1467  $plural = true; // Default if we have a last seen revision: if unknown, use plural
1468  $latestRev = Revision::newFromTitle( $uTalkTitle, false, Revision::READ_NORMAL );
1469  if ( $latestRev !== null ) {
1470  // Singular if only 1 unseen revision, plural if several unseen revisions.
1471  $plural = $latestRev->getParentId() !== $lastSeenRev->getId();
1472  $nofAuthors = $uTalkTitle->countAuthorsBetween(
1473  $lastSeenRev, $latestRev, 10, 'include_new' );
1474  }
1475  } else {
1476  // Singular if no revision -> diff link will show latest change only in any case
1477  $plural = false;
1478  }
1479  $plural = $plural ? 999 : 1;
1480  // 999 signifies "more than one revision". We don't know how many, and even if we did,
1481  // the number of revisions or authors is not necessarily the same as the number of
1482  // "messages".
1483  $newMessagesLink = $linkRenderer->makeKnownLink(
1484  $uTalkTitle,
1485  $this->msg( 'newmessageslinkplural' )->params( $plural )->text(),
1486  [],
1487  $uTalkTitle->isRedirect() ? [ 'redirect' => 'no' ] : []
1488  );
1489 
1490  $newMessagesDiffLink = $linkRenderer->makeKnownLink(
1491  $uTalkTitle,
1492  $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->text(),
1493  [],
1494  $lastSeenRev !== null
1495  ? [ 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' ]
1496  : [ 'diff' => 'cur' ]
1497  );
1498 
1499  if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
1500  $newMessagesAlert = $this->msg(
1501  'youhavenewmessagesfromusers',
1502  $newMessagesLink,
1503  $newMessagesDiffLink
1504  )->numParams( $nofAuthors, $plural );
1505  } else {
1506  // $nofAuthors === 11 signifies "11 or more" ("more than 10")
1507  $newMessagesAlert = $this->msg(
1508  $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
1509  $newMessagesLink,
1510  $newMessagesDiffLink
1511  )->numParams( $plural );
1512  }
1513  $newMessagesAlert = $newMessagesAlert->text();
1514  # Disable CDN cache
1515  $out->setCdnMaxage( 0 );
1516  } elseif ( count( $newtalks ) ) {
1517  $sep = $this->msg( 'newtalkseparator' )->escaped();
1518  $msgs = [];
1519 
1520  foreach ( $newtalks as $newtalk ) {
1521  $msgs[] = Xml::element(
1522  'a',
1523  [ 'href' => $newtalk['link'] ], $newtalk['wiki']
1524  );
1525  }
1526  $parts = implode( $sep, $msgs );
1527  $newMessagesAlert = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
1528  $out->setCdnMaxage( 0 );
1529  }
1530 
1531  return $newMessagesAlert;
1532  }
1533 
1541  private function getCachedNotice( $name ) {
1542  $config = $this->getConfig();
1543 
1544  if ( $name === 'default' ) {
1545  // special case
1546  $notice = $config->get( 'SiteNotice' );
1547  if ( empty( $notice ) ) {
1548  return false;
1549  }
1550  } else {
1551  $msg = $this->msg( $name )->inContentLanguage();
1552  if ( $msg->isBlank() ) {
1553  return '';
1554  } elseif ( $msg->isDisabled() ) {
1555  return false;
1556  }
1557  $notice = $msg->plain();
1558  }
1559 
1560  $services = MediaWikiServices::getInstance();
1561  $cache = $services->getMainWANObjectCache();
1562  $parsed = $cache->getWithSetCallback(
1563  // Use the extra hash appender to let eg SSL variants separately cache
1564  // Key is verified with md5 hash of unparsed wikitext
1565  $cache->makeKey( $name, $config->get( 'RenderHashAppend' ), md5( $notice ) ),
1566  // TTL in seconds
1567  600,
1568  function () use ( $notice ) {
1569  return $this->getOutput()->parseAsInterface( $notice );
1570  }
1571  );
1572 
1573  $contLang = $services->getContentLanguage();
1574  return Html::rawElement(
1575  'div',
1576  [
1577  'id' => 'localNotice',
1578  'lang' => $contLang->getHtmlCode(),
1579  'dir' => $contLang->getDir()
1580  ],
1581  $parsed
1582  );
1583  }
1584 
1590  function getSiteNotice() {
1591  $siteNotice = '';
1592 
1593  if ( Hooks::run( 'SiteNoticeBefore', [ &$siteNotice, $this ] ) ) {
1594  if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) {
1595  $siteNotice = $this->getCachedNotice( 'sitenotice' );
1596  } else {
1597  $anonNotice = $this->getCachedNotice( 'anonnotice' );
1598  if ( $anonNotice === false ) {
1599  $siteNotice = $this->getCachedNotice( 'sitenotice' );
1600  } else {
1601  $siteNotice = $anonNotice;
1602  }
1603  }
1604  if ( $siteNotice === false ) {
1605  $siteNotice = $this->getCachedNotice( 'default' );
1606  }
1607  }
1608 
1609  Hooks::run( 'SiteNoticeAfter', [ &$siteNotice, $this ] );
1610  return $siteNotice;
1611  }
1612 
1626  public function doEditSectionLink( Title $nt, $section, $tooltip, Language $lang ) {
1627  // HTML generated here should probably have userlangattributes
1628  // added to it for LTR text on RTL pages
1629 
1630  $attribs = [];
1631  if ( !is_null( $tooltip ) ) {
1632  $attribs['title'] = $this->msg( 'editsectionhint' )->rawParams( $tooltip )
1633  ->inLanguage( $lang )->text();
1634  }
1635 
1636  $links = [
1637  'editsection' => [
1638  'text' => $this->msg( 'editsection' )->inLanguage( $lang )->text(),
1639  'targetTitle' => $nt,
1640  'attribs' => $attribs,
1641  'query' => [ 'action' => 'edit', 'section' => $section ]
1642  ]
1643  ];
1644 
1645  Hooks::run( 'SkinEditSectionLinks', [ $this, $nt, $section, $tooltip, &$links, $lang ] );
1646 
1647  $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
1648 
1649  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1650  $linksHtml = [];
1651  foreach ( $links as $k => $linkDetails ) {
1652  $linksHtml[] = $linkRenderer->makeKnownLink(
1653  $linkDetails['targetTitle'],
1654  $linkDetails['text'],
1655  $linkDetails['attribs'],
1656  $linkDetails['query']
1657  );
1658  }
1659 
1660  $result .= implode(
1661  '<span class="mw-editsection-divider">'
1662  . $this->msg( 'pipe-separator' )->inLanguage( $lang )->escaped()
1663  . '</span>',
1664  $linksHtml
1665  );
1666 
1667  $result .= '<span class="mw-editsection-bracket">]</span></span>';
1668  return $result;
1669  }
1670 
1671 }
showEmailUser( $id)
Definition: Skin.php:1100
static makeUrlDetails( $name, $urlaction='')
these return an array with the &#39;href&#39; and boolean &#39;exists&#39;
Definition: Skin.php:1234
static makeI18nUrl( $name, $urlaction='')
Definition: Skin.php:1182
makeFooterIcon( $icon, $withImage='withImage')
Renders a $wgFooterIcons icon according to the method&#39;s arguments.
Definition: Skin.php:982
wfUrlProtocols( $includeProtocolRelative=true)
Returns a regular expression of url protocols.
lastModified()
Get the timestamp of the latest revision, formatted in user language.
Definition: Skin.php:930
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1983
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
footerLinkTitle( $desc, $page)
Definition: Skin.php:1041
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
static normalizeKey( $key)
Normalize a skin preference value to a form that can be loaded.
Definition: Skin.php:102
either a plain
Definition: hooks.txt:2044
static getTimestampFromId( $title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
Definition: Revision.php:1262
afterContentHook()
This runs a hook to allow extensions placing their stuff after content and article metadata (e...
Definition: Skin.php:644
setRelevantUser( $u)
Set the "relevant" user.
Definition: Skin.php:353
getPoweredBy()
Gets the powered by MediaWiki icon.
Definition: Skin.php:907
getNewtalks()
Gets new talk page messages for the current user and returns an appropriate alert message (or an empt...
Definition: Skin.php:1447
const NS_MAIN
Definition: Defines.php:60
static makeSpecialUrl( $name, $urlaction='', $proto=null)
Make a URL for a Special Page using the given query and protocol.
Definition: Skin.php:1157
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:656
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:926
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1983
buildSidebar()
Build an array that represents the sidebar(s), the navigation bar among them.
Definition: Skin.php:1296
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
privacyLink()
Gets the link to the wiki&#39;s privacy policy page.
Definition: Skin.php:1059
if(!isset( $args[0])) $lang
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
doEditSectionLink(Title $nt, $section, $tooltip, Language $lang)
Create a section edit link.
Definition: Skin.php:1626
initPage(OutputPage $out)
Definition: Skin.php:163
editUrlOptions()
Return URL options for the &#39;edit page&#39; link.
Definition: Skin.php:1086
getLogo()
URL to the logo.
Definition: Skin.php:498
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:57
getCopyrightIcon()
Definition: Skin.php:877
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static makeConfigSetScript(array $configuration)
Returns JS code which will set the MediaWiki configuration array to the given value.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getCachedNotice( $name)
Get a cached notice.
Definition: Skin.php:1541
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that&#39;s attached to a given link target...
Definition: Revision.php:137
shouldPreloadLogo()
Whether the logo should be preloaded with an HTTP link header or not.
Definition: Skin.php:511
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
getCategories()
Definition: Skin.php:609
getSiteNotice()
Get the site notice.
Definition: Skin.php:1590
static getHTMLDebugLog()
Generate debug log in HTML for displaying at the bottom of the main content area. ...
Definition: MWDebug.php:455
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\*-\*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1981
getPageClasses( $title)
TODO: document.
Definition: Skin.php:438
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3050
addToBodyAttributes( $out, &$bodyAttrs)
This will be called by OutputPage::headElement when it is creating the "<body>" tag, skins can override it if they have a need to add in any body attributes or classes of their own.
Definition: Skin.php:490
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:773
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1983
preloadExistence()
Preload the existence of three commonly-requested pages in a single query.
Definition: Skin.php:266
footerLink( $desc, $page)
Returns an HTML link for use in the footer.
Definition: Skin.php:1023
$modules
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
$mRelevantTitle
Definition: Skin.php:44
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2216
static checkTitle(&$title, $name)
make sure we have some title to operate on
Definition: Skin.php:1266
the value of this variable comes from LanguageConverter indexed by page_id indexed by prefixed DB keys on which the links will be shown can modify can modify can modify this should be populated with an alert message to that effect $newtalks
Definition: hooks.txt:1664
mainPageLink()
Gets the link to the wiki&#39;s main page.
Definition: Skin.php:1007
static escapeIdForAttribute( $id, $mode=self::ID_PRIMARY)
Given a section name or other user-generated or otherwise unsafe string, escapes it to be a valid HTM...
Definition: Sanitizer.php:1295
drawCategoryBrowser( $tree)
Render the array as a series of links.
Definition: Skin.php:585
getRelevantTitle()
Return the "relevant" title.
Definition: Skin.php:344
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
subPageSubtitle( $out=null)
Definition: Skin.php:751
getCategoryLinks()
Definition: Skin.php:518
disclaimerLink()
Gets the link to the wiki&#39;s general disclaimers page.
Definition: Skin.php:1075
$cache
Definition: mcc.php:33
getSearchLink()
Definition: Skin.php:810
$mRelevantUser
Definition: Skin.php:45
const NS_CATEGORY
Definition: Defines.php:74
static makeVariablesScript( $data, $nonce=null)
Definition: Skin.php:400
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1983
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:845
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1983
generateDebugHTML()
Generate debug data HTML for displaying at the bottom of the main content area.
Definition: Skin.php:670
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
setRelevantTitle( $t)
Set the "relevant" title.
Definition: Skin.php:330
getHtmlElementAttributes()
Return values for <html> element.
Definition: Skin.php:474
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:918
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:1418
getRelevantUser()
Return the "relevant" user.
Definition: Skin.php:365
aboutLink()
Gets the link to the wiki&#39;s about page.
Definition: Skin.php:1067
addToSidebarPlain(&$bar, $text)
Add content from plain text.
Definition: Skin.php:1354
addToSidebar(&$bar, $message)
Add content from a sidebar system message Currently only used for MediaWiki:Sidebar (but may be used ...
Definition: Skin.php:1343
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
logoText( $align='')
Definition: Skin.php:957
static makeKnownUrlDetails( $name, $urlaction='')
Make URL details where the article exists (or at least it&#39;s convenient to think so) ...
Definition: Skin.php:1250
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static makeInlineScript( $script, $nonce=null)
Returns an HTML script tag that runs given JS code after startup and base modules.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:3050
static makeUrl( $name, $urlaction='')
Definition: Skin.php:1193
getDefaultModules()
Defines the ResourceLoader modules that should be added to the skin It is recommended that skins wish...
Definition: Skin.php:177
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:620
printSource()
Text with the permalink to the source page, usually shown on the footer of a printed page...
Definition: Skin.php:701
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:559
string $stylename
Stylesheets set to use.
Definition: Skin.php:51
$fallback
Definition: MessagesAb.php:11
$lines
Definition: router.php:61
static isCurrentWikiId( $wikiId)
Definition: WikiMap.php:313
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
$parent
Definition: pageupdater.txt:71
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
wfExpandIRI( $url)
Take a URL, make sure it&#39;s expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
isRevisionCurrent()
Whether the revision displayed is the latest revision of the page.
Definition: Skin.php:320
$wgDefaultSkin
Default skin, for new users and anonymous visitors.
static makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN)
this can be passed the NS number as defined in Language.php
Definition: Skin.php:1221
$wgSkipSkins
Specify the names of skins that should not be presented in the list of available skins in user prefer...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$line
Definition: cdb.php:59
static getSkinNameMessages()
Fetch the skinname messages for available skins.
Definition: Skin.php:66
getCopyright( $type='detect')
Definition: Skin.php:828
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
$wgFallbackSkin
Fallback skin used when the skin defined by $wgDefaultSkin can&#39;t be found.
static validateTarget( $target, User $sender)
Validate target User.
getUndeleteLink()
Definition: Skin.php:719
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:277
$messages
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
Definition: Skin.php:1206
getSkinStylePath( $name)
Return a fully resolved style path URL to images or styles stored in the current skin&#39;s folder...
Definition: Skin.php:1124
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage. ...
static getDynamicStylesheetQuery()
Get the query to generate a dynamic stylesheet.
Definition: Skin.php:416
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
setupSkinUserCss(OutputPage $out)
Hook point for adding style modules to OutputPage.
Definition: Skin.php:429
static makeMainPageUrl( $urlaction='')
Definition: Skin.php:1139
$searchPage
getRevisionId()
Get the current revision ID.
Definition: Skin.php:311
outputPage()
Outputs the HTML generated by other functions.
escapeSearchLink()
Definition: Skin.php:819
getSkinName()
Definition: Skin.php:156
static getAllowedSkins()
Fetch the list of user-selectable skins in regards to $wgSkipSkins.
Definition: Skin.php:81
__construct( $skinname=null)
Definition: Skin.php:147
bottomScripts()
This gets called shortly before the "</body>" tag.
Definition: Skin.php:679
static singleton()
Get the singleton instance of this class.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1460
static makeSpecialUrlSubpage( $name, $subpage, $urlaction='')
Definition: Skin.php:1172
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
string null $skinname
Definition: Skin.php:42
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:322