MediaWiki  master
Linker.php
Go to the documentation of this file.
1 <?php
25 use Wikimedia\IPUtils;
26 
36 class Linker {
40  const TOOL_LINKS_NOBLOCK = 1;
41  const TOOL_LINKS_EMAIL = 2;
42 
86  public static function link(
87  $target, $html = null, $customAttribs = [], $query = [], $options = []
88  ) {
89  if ( !$target instanceof LinkTarget ) {
90  wfWarn( __METHOD__ . ': Requires $target to be a LinkTarget object.', 2 );
91  return "<!-- ERROR -->$html";
92  }
93 
94  $services = MediaWikiServices::getInstance();
95  $options = (array)$options;
96  if ( $options ) {
97  // Custom options, create new LinkRenderer
98  if ( !isset( $options['stubThreshold'] ) ) {
99  $defaultLinkRenderer = $services->getLinkRenderer();
100  $options['stubThreshold'] = $defaultLinkRenderer->getStubThreshold();
101  }
102  $linkRenderer = $services->getLinkRendererFactory()
103  ->createFromLegacyOptions( $options );
104  } else {
105  $linkRenderer = $services->getLinkRenderer();
106  }
107 
108  if ( $html !== null ) {
109  $text = new HtmlArmor( $html );
110  } else {
111  $text = null;
112  }
113 
114  if ( in_array( 'known', $options, true ) ) {
115  return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
116  }
117 
118  if ( in_array( 'broken', $options, true ) ) {
119  return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
120  }
121 
122  if ( in_array( 'noclasses', $options, true ) ) {
123  return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query );
124  }
125 
126  return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
127  }
128 
142  public static function linkKnown(
143  $target, $html = null, $customAttribs = [],
144  $query = [], $options = [ 'known' ]
145  ) {
146  return self::link( $target, $html, $customAttribs, $query, $options );
147  }
148 
164  public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
165  $nt = Title::newFromLinkTarget( $nt );
166  $ret = "<a class=\"mw-selflink selflink\">{$prefix}{$html}</a>{$trail}";
167  if ( !Hooks::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
168  return $ret;
169  }
170 
171  if ( $html == '' ) {
172  $html = htmlspecialchars( $nt->getPrefixedText() );
173  }
174  list( $inside, $trail ) = self::splitTrail( $trail );
175  return "<a class=\"mw-selflink selflink\">{$prefix}{$html}{$inside}</a>{$trail}";
176  }
177 
188  public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
189  // First we check whether the namespace exists or not.
190  if ( MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $namespace ) ) {
191  if ( $namespace == NS_MAIN ) {
192  $name = $context->msg( 'blanknamespace' )->text();
193  } else {
194  $name = MediaWikiServices::getInstance()->getContentLanguage()->
195  getFormattedNsText( $namespace );
196  }
197  return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
198  }
199 
200  return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
201  }
202 
208  public static function normaliseSpecialPage( LinkTarget $target ) {
209  if ( $target->getNamespace() == NS_SPECIAL && !$target->isExternal() ) {
210  list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
211  resolveAlias( $target->getDBkey() );
212  if ( $name ) {
213  return SpecialPage::getTitleValueFor( $name, $subpage, $target->getFragment() );
214  }
215  }
216 
217  return $target;
218  }
219 
228  private static function fnamePart( $url ) {
229  $basename = strrchr( $url, '/' );
230  if ( $basename === false ) {
231  $basename = $url;
232  } else {
233  $basename = substr( $basename, 1 );
234  }
235  return $basename;
236  }
237 
248  public static function makeExternalImage( $url, $alt = '' ) {
249  if ( $alt == '' ) {
250  $alt = self::fnamePart( $url );
251  }
252  $img = '';
253  $success = Hooks::run( 'LinkerMakeExternalImage', [ &$url, &$alt, &$img ] );
254  if ( !$success ) {
255  wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
256  . "with url {$url} and alt text {$alt} to {$img}\n", true );
257  return $img;
258  }
259  return Html::element( 'img',
260  [
261  'src' => $url,
262  'alt' => $alt
263  ]
264  );
265  }
266 
304  public static function makeImageLink( Parser $parser, LinkTarget $title,
305  $file, $frameParams = [], $handlerParams = [], $time = false,
306  $query = "", $widthOption = null
307  ) {
309  $res = null;
310  $dummy = new DummyLinker;
311  if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title,
312  &$file, &$frameParams, &$handlerParams, &$time, &$res,
313  $parser, &$query, &$widthOption
314  ] ) ) {
315  return $res;
316  }
317 
318  if ( $file && !$file->allowInlineDisplay() ) {
319  wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
320  return self::link( $title );
321  }
322 
323  // Clean up parameters
324  $page = $handlerParams['page'] ?? false;
325  if ( !isset( $frameParams['align'] ) ) {
326  $frameParams['align'] = '';
327  }
328  if ( !isset( $frameParams['alt'] ) ) {
329  $frameParams['alt'] = '';
330  }
331  if ( !isset( $frameParams['title'] ) ) {
332  $frameParams['title'] = '';
333  }
334  if ( !isset( $frameParams['class'] ) ) {
335  $frameParams['class'] = '';
336  }
337 
338  $prefix = $postfix = '';
339 
340  if ( $frameParams['align'] == 'center' ) {
341  $prefix = '<div class="center">';
342  $postfix = '</div>';
343  $frameParams['align'] = 'none';
344  }
345  if ( $file && !isset( $handlerParams['width'] ) ) {
346  if ( isset( $handlerParams['height'] ) && $file->isVectorized() ) {
347  // If its a vector image, and user only specifies height
348  // we don't want it to be limited by its "normal" width.
349  global $wgSVGMaxSize;
350  $handlerParams['width'] = $wgSVGMaxSize;
351  } else {
352  $handlerParams['width'] = $file->getWidth( $page );
353  }
354 
355  if ( isset( $frameParams['thumbnail'] )
356  || isset( $frameParams['manualthumb'] )
357  || isset( $frameParams['framed'] )
358  || isset( $frameParams['frameless'] )
359  || !$handlerParams['width']
360  ) {
362 
363  if ( $widthOption === null || !isset( $wgThumbLimits[$widthOption] ) ) {
364  $widthOption = User::getDefaultOption( 'thumbsize' );
365  }
366 
367  // Reduce width for upright images when parameter 'upright' is used
368  if ( isset( $frameParams['upright'] ) && $frameParams['upright'] == 0 ) {
369  $frameParams['upright'] = $wgThumbUpright;
370  }
371 
372  // For caching health: If width scaled down due to upright
373  // parameter, round to full __0 pixel to avoid the creation of a
374  // lot of odd thumbs.
375  $prefWidth = isset( $frameParams['upright'] ) ?
376  round( $wgThumbLimits[$widthOption] * $frameParams['upright'], -1 ) :
377  $wgThumbLimits[$widthOption];
378 
379  // Use width which is smaller: real image width or user preference width
380  // Unless image is scalable vector.
381  if ( !isset( $handlerParams['height'] ) && ( $handlerParams['width'] <= 0 ||
382  $prefWidth < $handlerParams['width'] || $file->isVectorized() ) ) {
383  $handlerParams['width'] = $prefWidth;
384  }
385  }
386  }
387 
388  if ( isset( $frameParams['thumbnail'] ) || isset( $frameParams['manualthumb'] )
389  || isset( $frameParams['framed'] )
390  ) {
391  # Create a thumbnail. Alignment depends on the writing direction of
392  # the page content language (right-aligned for LTR languages,
393  # left-aligned for RTL languages)
394  # If a thumbnail width has not been provided, it is set
395  # to the default user option as specified in Language*.php
396  if ( $frameParams['align'] == '' ) {
397  $frameParams['align'] = $parser->getTargetLanguage()->alignEnd();
398  }
399  return $prefix .
400  self::makeThumbLink2( $title, $file, $frameParams, $handlerParams, $time, $query ) .
401  $postfix;
402  }
403 
404  if ( $file && isset( $frameParams['frameless'] ) ) {
405  $srcWidth = $file->getWidth( $page );
406  # For "frameless" option: do not present an image bigger than the
407  # source (for bitmap-style images). This is the same behavior as the
408  # "thumb" option does it already.
409  if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) {
410  $handlerParams['width'] = $srcWidth;
411  }
412  }
413 
414  if ( $file && isset( $handlerParams['width'] ) ) {
415  # Create a resized image, without the additional thumbnail features
416  $thumb = $file->transform( $handlerParams );
417  } else {
418  $thumb = false;
419  }
420 
421  if ( !$thumb ) {
422  $s = self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true );
423  } else {
424  self::processResponsiveImages( $file, $thumb, $handlerParams );
425  $params = [
426  'alt' => $frameParams['alt'],
427  'title' => $frameParams['title'],
428  'valign' => $frameParams['valign'] ?? false,
429  'img-class' => $frameParams['class'] ];
430  if ( isset( $frameParams['border'] ) ) {
431  $params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
432  }
433  $params = self::getImageLinkMTOParams( $frameParams, $query, $parser ) + $params;
434 
435  $s = $thumb->toHtml( $params );
436  }
437  if ( $frameParams['align'] != '' ) {
438  $s = Html::rawElement(
439  'div',
440  [ 'class' => 'float' . $frameParams['align'] ],
441  $s
442  );
443  }
444  return str_replace( "\n", ' ', $prefix . $s . $postfix );
445  }
446 
455  private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
456  $mtoParams = [];
457  if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
458  $mtoParams['custom-url-link'] = $frameParams['link-url'];
459  if ( isset( $frameParams['link-target'] ) ) {
460  $mtoParams['custom-target-link'] = $frameParams['link-target'];
461  }
462  if ( $parser ) {
463  $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
464  foreach ( $extLinkAttrs as $name => $val ) {
465  // Currently could include 'rel' and 'target'
466  $mtoParams['parser-extlink-' . $name] = $val;
467  }
468  }
469  } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
470  $mtoParams['custom-title-link'] = Title::newFromLinkTarget(
471  self::normaliseSpecialPage( $frameParams['link-title'] )
472  );
473  } elseif ( !empty( $frameParams['no-link'] ) ) {
474  // No link
475  } else {
476  $mtoParams['desc-link'] = true;
477  $mtoParams['desc-query'] = $query;
478  }
479  return $mtoParams;
480  }
481 
494  public static function makeThumbLinkObj( LinkTarget $title, $file, $label = '', $alt = '',
495  $align = 'right', $params = [], $framed = false, $manualthumb = ""
496  ) {
497  $frameParams = [
498  'alt' => $alt,
499  'caption' => $label,
500  'align' => $align
501  ];
502  if ( $framed ) {
503  $frameParams['framed'] = true;
504  }
505  if ( $manualthumb ) {
506  $frameParams['manualthumb'] = $manualthumb;
507  }
508  return self::makeThumbLink2( $title, $file, $frameParams, $params );
509  }
510 
520  public static function makeThumbLink2( LinkTarget $title, $file, $frameParams = [],
521  $handlerParams = [], $time = false, $query = ""
522  ) {
523  $exists = $file && $file->exists();
524 
525  $page = $handlerParams['page'] ?? false;
526  if ( !isset( $frameParams['align'] ) ) {
527  $frameParams['align'] = 'right';
528  }
529  if ( !isset( $frameParams['alt'] ) ) {
530  $frameParams['alt'] = '';
531  }
532  if ( !isset( $frameParams['title'] ) ) {
533  $frameParams['title'] = '';
534  }
535  if ( !isset( $frameParams['caption'] ) ) {
536  $frameParams['caption'] = '';
537  }
538 
539  if ( empty( $handlerParams['width'] ) ) {
540  // Reduce width for upright images when parameter 'upright' is used
541  $handlerParams['width'] = isset( $frameParams['upright'] ) ? 130 : 180;
542  }
543  $thumb = false;
544  $noscale = false;
545  $manualthumb = false;
546 
547  if ( !$exists ) {
548  $outerWidth = $handlerParams['width'] + 2;
549  } else {
550  if ( isset( $frameParams['manualthumb'] ) ) {
551  # Use manually specified thumbnail
552  $manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] );
553  if ( $manual_title ) {
554  $manual_img = MediaWikiServices::getInstance()->getRepoGroup()
555  ->findFile( $manual_title );
556  if ( $manual_img ) {
557  $thumb = $manual_img->getUnscaledThumb( $handlerParams );
558  $manualthumb = true;
559  } else {
560  $exists = false;
561  }
562  }
563  } elseif ( isset( $frameParams['framed'] ) ) {
564  // Use image dimensions, don't scale
565  $thumb = $file->getUnscaledThumb( $handlerParams );
566  $noscale = true;
567  } else {
568  # Do not present an image bigger than the source, for bitmap-style images
569  # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
570  $srcWidth = $file->getWidth( $page );
571  if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) {
572  $handlerParams['width'] = $srcWidth;
573  }
574  $thumb = $file->transform( $handlerParams );
575  }
576 
577  if ( $thumb ) {
578  $outerWidth = $thumb->getWidth() + 2;
579  } else {
580  $outerWidth = $handlerParams['width'] + 2;
581  }
582  }
583 
584  # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
585  # So we don't need to pass it here in $query. However, the URL for the
586  # zoom icon still needs it, so we make a unique query for it. See T16771
587  $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
588  if ( $page ) {
589  $url = wfAppendQuery( $url, [ 'page' => $page ] );
590  }
591  if ( $manualthumb
592  && !isset( $frameParams['link-title'] )
593  && !isset( $frameParams['link-url'] )
594  && !isset( $frameParams['no-link'] ) ) {
595  $frameParams['link-url'] = $url;
596  }
597 
598  $s = "<div class=\"thumb t{$frameParams['align']}\">"
599  . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
600 
601  if ( !$exists ) {
602  $s .= self::makeBrokenImageLinkObj( $title, $frameParams['title'], '', '', '', $time == true );
603  $zoomIcon = '';
604  } elseif ( !$thumb ) {
605  $s .= wfMessage( 'thumbnail_error', '' )->escaped();
606  $zoomIcon = '';
607  } else {
608  if ( !$noscale && !$manualthumb ) {
609  self::processResponsiveImages( $file, $thumb, $handlerParams );
610  }
611  $params = [
612  'alt' => $frameParams['alt'],
613  'title' => $frameParams['title'],
614  'img-class' => ( isset( $frameParams['class'] ) && $frameParams['class'] !== ''
615  ? $frameParams['class'] . ' '
616  : '' ) . 'thumbimage'
617  ];
618  $params = self::getImageLinkMTOParams( $frameParams, $query ) + $params;
619  $s .= $thumb->toHtml( $params );
620  if ( isset( $frameParams['framed'] ) ) {
621  $zoomIcon = "";
622  } else {
623  $zoomIcon = Html::rawElement( 'div', [ 'class' => 'magnify' ],
624  Html::rawElement( 'a', [
625  'href' => $url,
626  'class' => 'internal',
627  'title' => wfMessage( 'thumbnail-more' )->text() ],
628  "" ) );
629  }
630  }
631  $s .= ' <div class="thumbcaption">' . $zoomIcon . $frameParams['caption'] . "</div></div></div>";
632  return str_replace( "\n", ' ', $s );
633  }
634 
643  public static function processResponsiveImages( $file, $thumb, $hp ) {
644  global $wgResponsiveImages;
645  if ( $wgResponsiveImages && $thumb && !$thumb->isError() ) {
646  $hp15 = $hp;
647  $hp15['width'] = round( $hp['width'] * 1.5 );
648  $hp20 = $hp;
649  $hp20['width'] = $hp['width'] * 2;
650  if ( isset( $hp['height'] ) ) {
651  $hp15['height'] = round( $hp['height'] * 1.5 );
652  $hp20['height'] = $hp['height'] * 2;
653  }
654 
655  $thumb15 = $file->transform( $hp15 );
656  $thumb20 = $file->transform( $hp20 );
657  if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
658  $thumb->responsiveUrls['1.5'] = $thumb15->getUrl();
659  }
660  if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
661  $thumb->responsiveUrls['2'] = $thumb20->getUrl();
662  }
663  }
664  }
665 
678  public static function makeBrokenImageLinkObj( $title, $label = '',
679  $query = '', $unused1 = '', $unused2 = '', $time = false
680  ) {
681  if ( !$title instanceof LinkTarget ) {
682  wfWarn( __METHOD__ . ': Requires $title to be a LinkTarget object.' );
683  return "<!-- ERROR -->" . htmlspecialchars( $label );
684  }
685 
687 
689  if ( $label == '' ) {
690  $label = $title->getPrefixedText();
691  }
692  $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
693  $currentExists = $time
694  && $repoGroup->findFile( $title ) !== false;
695 
697  && !$currentExists
698  ) {
699  if ( $repoGroup->getLocalRepo()->checkRedirect( $title ) ) {
700  // We already know it's a redirect, so mark it accordingly
701  return self::link(
702  $title,
703  htmlspecialchars( $label ),
704  [ 'class' => 'mw-redirect' ],
705  wfCgiToArray( $query ),
706  [ 'known', 'noclasses' ]
707  );
708  }
709 
710  return Html::element( 'a', [
711  'href' => self::getUploadUrl( $title, $query ),
712  'class' => 'new',
713  'title' => $title->getPrefixedText()
714  ], $label );
715  }
716 
717  return self::link(
718  $title,
719  htmlspecialchars( $label ),
720  [],
721  wfCgiToArray( $query ),
722  [ 'known', 'noclasses' ]
723  );
724  }
725 
734  protected static function getUploadUrl( $destFile, $query = '' ) {
736  $q = 'wpDestFile=' . Title::castFromLinkTarget( $destFile )->getPartialURL();
737  if ( $query != '' ) {
738  $q .= '&' . $query;
739  }
740 
741  if ( $wgUploadMissingFileUrl ) {
743  }
744 
745  if ( $wgUploadNavigationUrl ) {
747  }
748 
749  $upload = SpecialPage::getTitleFor( 'Upload' );
750 
751  return $upload->getLocalURL( $q );
752  }
753 
763  public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
764  $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
765  $title, [ 'time' => $time ]
766  );
767  return self::makeMediaLinkFile( $title, $img, $html );
768  }
769 
782  public static function makeMediaLinkFile( LinkTarget $title, $file, $html = '' ) {
783  if ( $file && $file->exists() ) {
784  $url = $file->getUrl();
785  $class = 'internal';
786  } else {
787  $url = self::getUploadUrl( $title );
788  $class = 'new';
789  }
790 
791  $alt = $title->getText();
792  if ( $html == '' ) {
793  $html = $alt;
794  }
795 
796  $ret = '';
797  $attribs = [
798  'href' => $url,
799  'class' => $class,
800  'title' => $alt
801  ];
802 
803  if ( !Hooks::run( 'LinkerMakeMediaLinkFile',
804  [ Title::castFromLinkTarget( $title ), $file, &$html, &$attribs, &$ret ] ) ) {
805  wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
806  . "with url {$url} and text {$html} to {$ret}\n", true );
807  return $ret;
808  }
809 
810  return Html::rawElement( 'a', $attribs, $html );
811  }
812 
823  public static function specialLink( $name, $key = '' ) {
824  if ( $key == '' ) {
825  $key = strtolower( $name );
826  }
827 
828  return self::linkKnown( SpecialPage::getTitleFor( $name ), wfMessage( $key )->escaped() );
829  }
830 
849  public static function makeExternalLink( $url, $text, $escape = true,
850  $linktype = '', $attribs = [], $title = null
851  ) {
852  global $wgTitle;
853  $class = "external";
854  if ( $linktype ) {
855  $class .= " $linktype";
856  }
857  if ( isset( $attribs['class'] ) && $attribs['class'] ) {
858  $class .= " {$attribs['class']}";
859  }
860  $attribs['class'] = $class;
861 
862  if ( $escape ) {
863  $text = htmlspecialchars( $text );
864  }
865 
866  if ( !$title ) {
867  $title = $wgTitle;
868  }
869  $newRel = Parser::getExternalLinkRel( $url, $title );
870  if ( !isset( $attribs['rel'] ) || $attribs['rel'] === '' ) {
871  $attribs['rel'] = $newRel;
872  } elseif ( $newRel !== '' ) {
873  // Merge the rel attributes.
874  $newRels = explode( ' ', $newRel );
875  $oldRels = explode( ' ', $attribs['rel'] );
876  $combined = array_unique( array_merge( $newRels, $oldRels ) );
877  $attribs['rel'] = implode( ' ', $combined );
878  }
879  $link = '';
880  $success = Hooks::run( 'LinkerMakeExternalLink',
881  [ &$url, &$text, &$link, &$attribs, $linktype ] );
882  if ( !$success ) {
883  wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
884  . "with url {$url} and text {$text} to {$link}\n", true );
885  return $link;
886  }
887  $attribs['href'] = $url;
888  return Html::rawElement( 'a', $attribs, $text );
889  }
890 
899  public static function userLink( $userId, $userName, $altUserName = false ) {
900  if ( $userName === '' || $userName === false || $userName === null ) {
901  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
902  'that need to be fixed?' );
903  return wfMessage( 'empty-username' )->parse();
904  }
905 
906  $classes = 'mw-userlink';
907  $page = null;
908  if ( $userId == 0 ) {
909  $page = ExternalUserNames::getUserLinkTitle( $userName );
910 
911  if ( ExternalUserNames::isExternal( $userName ) ) {
912  $classes .= ' mw-extuserlink';
913  } elseif ( $altUserName === false ) {
914  $altUserName = IPUtils::prettifyIP( $userName );
915  }
916  $classes .= ' mw-anonuserlink'; // Separate link class for anons (T45179)
917  } else {
918  $page = TitleValue::tryNew( NS_USER, strtr( $userName, ' ', '_' ) );
919  }
920 
921  // Wrap the output with <bdi> tags for directionality isolation
922  $linkText =
923  '<bdi>' . htmlspecialchars( $altUserName !== false ? $altUserName : $userName ) . '</bdi>';
924 
925  return $page
926  ? self::link( $page, $linkText, [ 'class' => $classes ] )
927  : Html::rawElement( 'span', [ 'class' => $classes ], $linkText );
928  }
929 
944  public static function userToolLinks(
945  $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null,
946  $useParentheses = true
947  ) {
948  if ( $userText === '' ) {
949  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
950  'that need to be fixed?' );
951  return ' ' . wfMessage( 'empty-username' )->parse();
952  }
953 
954  global $wgUser, $wgDisableAnonTalk, $wgLang;
955  $talkable = !( $wgDisableAnonTalk && $userId == 0 );
956  $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
957  $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
958 
959  if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
960  // No tools for an external user
961  return '';
962  }
963 
964  $items = [];
965  if ( $talkable ) {
966  $items[] = self::userTalkLink( $userId, $userText );
967  }
968  if ( $userId ) {
969  // check if the user has an edit
970  $attribs = [];
971  $attribs['class'] = 'mw-usertoollinks-contribs';
972  if ( $redContribsWhenNoEdits ) {
973  if ( intval( $edits ) === 0 && $edits !== 0 ) {
974  $user = User::newFromId( $userId );
975  $edits = $user->getEditCount();
976  }
977  if ( $edits === 0 ) {
978  $attribs['class'] .= ' new';
979  }
980  }
981  $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
982 
983  $items[] = self::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
984  }
985  $userCanBlock = MediaWikiServices::getInstance()->getPermissionManager()
986  ->userHasRight( $wgUser, 'block' );
987  if ( $blockable && $userCanBlock ) {
988  $items[] = self::blockLink( $userId, $userText );
989  }
990 
991  if ( $addEmailLink && $wgUser->canSendEmail() ) {
992  $items[] = self::emailLink( $userId, $userText );
993  }
994 
995  Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] );
996 
997  if ( !$items ) {
998  return '';
999  }
1000 
1001  if ( $useParentheses ) {
1002  return wfMessage( 'word-separator' )->escaped()
1003  . '<span class="mw-usertoollinks">'
1004  . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1005  . '</span>';
1006  }
1007 
1008  $tools = [];
1009  foreach ( $items as $tool ) {
1010  $tools[] = Html::rawElement( 'span', [], $tool );
1011  }
1012  return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1013  implode( ' ', $tools ) . '</span>';
1014  }
1015 
1025  public static function userToolLinksRedContribs(
1026  $userId, $userText, $edits = null, $useParentheses = true
1027  ) {
1028  return self::userToolLinks( $userId, $userText, true, 0, $edits, $useParentheses );
1029  }
1030 
1037  public static function userTalkLink( $userId, $userText ) {
1038  if ( $userText === '' ) {
1039  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1040  'that need to be fixed?' );
1041  return wfMessage( 'empty-username' )->parse();
1042  }
1043 
1044  $userTalkPage = TitleValue::tryNew( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
1045  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-talk' ];
1046  $linkText = wfMessage( 'talkpagelinktext' )->escaped();
1047 
1048  return $userTalkPage
1049  ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1050  : Html::rawElement( 'span', $moreLinkAttribs, $linkText );
1051  }
1052 
1059  public static function blockLink( $userId, $userText ) {
1060  if ( $userText === '' ) {
1061  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1062  'that need to be fixed?' );
1063  return wfMessage( 'empty-username' )->parse();
1064  }
1065 
1066  $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
1067  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-block' ];
1068 
1069  return self::link( $blockPage,
1070  wfMessage( 'blocklink' )->escaped(),
1071  $moreLinkAttribs
1072  );
1073  }
1074 
1080  public static function emailLink( $userId, $userText ) {
1081  if ( $userText === '' ) {
1082  wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
1083  'that need to be fixed?' );
1084  return wfMessage( 'empty-username' )->parse();
1085  }
1086 
1087  $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
1088  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-mail' ];
1089  return self::link( $emailPage,
1090  wfMessage( 'emaillink' )->escaped(),
1091  $moreLinkAttribs
1092  );
1093  }
1094 
1102  public static function revUserLink( $rev, $isPublic = false ) {
1103  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) && $isPublic ) {
1104  $link = wfMessage( 'rev-deleted-user' )->escaped();
1105  } elseif ( $rev->userCan( RevisionRecord::DELETED_USER ) ) {
1106  $link = self::userLink( $rev->getUser( RevisionRecord::FOR_THIS_USER ),
1107  $rev->getUserText( RevisionRecord::FOR_THIS_USER ) );
1108  } else {
1109  $link = wfMessage( 'rev-deleted-user' )->escaped();
1110  }
1111  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1112  return '<span class="history-deleted">' . $link . '</span>';
1113  }
1114  return $link;
1115  }
1116 
1125  public static function revUserTools( $rev, $isPublic = false, $useParentheses = true ) {
1126  if ( $rev->userCan( RevisionRecord::DELETED_USER ) &&
1127  ( !$rev->isDeleted( RevisionRecord::DELETED_USER ) || !$isPublic )
1128  ) {
1129  $userId = $rev->getUser( RevisionRecord::FOR_THIS_USER );
1130  $userText = $rev->getUserText( RevisionRecord::FOR_THIS_USER );
1131  if ( $userId || (string)$userText !== '' ) {
1132  $link = self::userLink( $userId, $userText )
1133  . self::userToolLinks( $userId, $userText, false, 0, null,
1134  $useParentheses );
1135  }
1136  }
1137 
1138  if ( !isset( $link ) ) {
1139  $link = wfMessage( 'rev-deleted-user' )->escaped();
1140  }
1141 
1142  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1143  return ' <span class="history-deleted mw-userlink">' . $link . '</span>';
1144  }
1145  return $link;
1146  }
1147 
1166  public static function formatComment(
1167  $comment, $title = null, $local = false, $wikiId = null
1168  ) {
1169  # Sanitize text a bit:
1170  $comment = str_replace( "\n", " ", $comment );
1171  # Allow HTML entities (for T15815)
1172  $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
1173 
1174  # Render autocomments and make links:
1175  $comment = self::formatAutocomments( $comment, $title, $local, $wikiId );
1176  return self::formatLinksInComment( $comment, $title, $local, $wikiId );
1177  }
1178 
1196  private static function formatAutocomments(
1197  $comment, $title = null, $local = false, $wikiId = null
1198  ) {
1199  // @todo $append here is something of a hack to preserve the status
1200  // quo. Someone who knows more about bidi and such should decide
1201  // (1) what sane rendering even *is* for an LTR edit summary on an RTL
1202  // wiki, both when autocomments exist and when they don't, and
1203  // (2) what markup will make that actually happen.
1204  $append = '';
1205  $comment = preg_replace_callback(
1206  // To detect the presence of content before or after the
1207  // auto-comment, we use capturing groups inside optional zero-width
1208  // assertions. But older versions of PCRE can't directly make
1209  // zero-width assertions optional, so wrap them in a non-capturing
1210  // group.
1211  '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
1212  function ( $match ) use ( $title, $local, $wikiId, &$append ) {
1213  global $wgLang;
1214 
1215  // Ensure all match positions are defined
1216  $match += [ '', '', '', '' ];
1217 
1218  $pre = $match[1] !== '';
1219  $auto = $match[2];
1220  $post = $match[3] !== '';
1221  $comment = null;
1222 
1223  Hooks::run(
1224  'FormatAutocomments',
1225  [ &$comment, $pre, $auto, $post, Title::castFromLinkTarget( $title ), $local,
1226  $wikiId ]
1227  );
1228 
1229  if ( $comment === null ) {
1230  if ( $title ) {
1231  $section = $auto;
1232  # Remove links that a user may have manually put in the autosummary
1233  # This could be improved by copying as much of Parser::stripSectionName as desired.
1234  $section = str_replace( [
1235  '[[:',
1236  '[[',
1237  ']]'
1238  ], '', $section );
1239 
1240  // We don't want any links in the auto text to be linked, but we still
1241  // want to show any [[ ]]
1242  $sectionText = str_replace( '[[', '&#91;[', $auto );
1243 
1244  $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
1245  if ( $section !== '' ) {
1246  if ( $local ) {
1247  $sectionTitle = new TitleValue( NS_MAIN, '', $section );
1248  } else {
1249  $sectionTitle = $title->createFragmentTarget( $section );
1250  }
1251  $auto = Linker::makeCommentLink(
1252  $sectionTitle,
1253  $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText,
1254  $wikiId,
1255  'noclasses'
1256  );
1257  }
1258  }
1259  if ( $pre ) {
1260  # written summary $presep autocomment (summary /* section */)
1261  $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1262  }
1263  if ( $post ) {
1264  # autocomment $postsep written summary (/* section */ summary)
1265  $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1266  }
1267  if ( $auto ) {
1268  $auto = '<span dir="auto"><span class="autocomment">' . $auto . '</span>';
1269  $append .= '</span>';
1270  }
1271  $comment = $pre . $auto;
1272  }
1273  return $comment;
1274  },
1275  $comment
1276  );
1277  return $comment . $append;
1278  }
1279 
1299  public static function formatLinksInComment(
1300  $comment, $title = null, $local = false, $wikiId = null
1301  ) {
1302  return preg_replace_callback(
1303  '/
1304  \[\[
1305  \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking
1306  :? # ignore optional leading colon
1307  ([^\]|]+) # 1. link target; page names cannot include ] or |
1308  (?:\|
1309  # 2. link text
1310  # Stop matching at ]] without relying on backtracking.
1311  ((?:]?[^\]])*+)
1312  )?
1313  \]\]
1314  ([^[]*) # 3. link trail (the text up until the next link)
1315  /x',
1316  function ( $match ) use ( $title, $local, $wikiId ) {
1317  $services = MediaWikiServices::getInstance();
1318 
1319  $medians = '(?:';
1320  $medians .= preg_quote(
1321  $services->getNamespaceInfo()->getCanonicalName( NS_MEDIA ), '/' );
1322  $medians .= '|';
1323  $medians .= preg_quote(
1324  $services->getContentLanguage()->getNsText( NS_MEDIA ),
1325  '/'
1326  ) . '):';
1327 
1328  $comment = $match[0];
1329 
1330  # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1331  if ( strpos( $match[1], '%' ) !== false ) {
1332  $match[1] = strtr(
1333  rawurldecode( $match[1] ),
1334  [ '<' => '&lt;', '>' => '&gt;' ]
1335  );
1336  }
1337 
1338  # Handle link renaming [[foo|text]] will show link as "text"
1339  if ( $match[2] != "" ) {
1340  $text = $match[2];
1341  } else {
1342  $text = $match[1];
1343  }
1344  $submatch = [];
1345  $thelink = null;
1346  if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1347  # Media link; trail not supported.
1348  $linkRegexp = '/\[\[(.*?)\]\]/';
1349  $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1350  if ( $title ) {
1351  $thelink = Linker::makeMediaLinkObj( $title, $text );
1352  }
1353  } else {
1354  # Other kind of link
1355  # Make sure its target is non-empty
1356  if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1357  $match[1] = substr( $match[1], 1 );
1358  }
1359  if ( $match[1] !== false && $match[1] !== '' ) {
1360  if ( preg_match(
1361  $services->getContentLanguage()->linkTrail(),
1362  $match[3],
1363  $submatch
1364  ) ) {
1365  $trail = $submatch[1];
1366  } else {
1367  $trail = "";
1368  }
1369  $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1370  list( $inside, $trail ) = Linker::splitTrail( $trail );
1371 
1372  $linkText = $text;
1373  $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText );
1374 
1375  Title::newFromText( $linkTarget );
1376  try {
1377  $target = $services->getTitleParser()->
1378  parseTitle( $linkTarget );
1379 
1380  if ( $target->getText() == '' && !$target->isExternal()
1381  && !$local && $title
1382  ) {
1383  $target = $title->createFragmentTarget( $target->getFragment() );
1384  }
1385 
1386  $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
1387  } catch ( MalformedTitleException $e ) {
1388  // Fall through
1389  }
1390  }
1391  }
1392  if ( $thelink ) {
1393  // If the link is still valid, go ahead and replace it in!
1394  $comment = preg_replace(
1395  $linkRegexp,
1397  $comment,
1398  1
1399  );
1400  }
1401 
1402  return $comment;
1403  },
1404  $comment
1405  );
1406  }
1407 
1421  public static function makeCommentLink(
1422  LinkTarget $linkTarget, $text, $wikiId = null, $options = []
1423  ) {
1424  if ( $wikiId !== null && !$linkTarget->isExternal() ) {
1425  $link = self::makeExternalLink(
1427  $wikiId,
1428  $linkTarget->getNamespace() === 0
1429  ? $linkTarget->getDBkey()
1430  : MediaWikiServices::getInstance()->getNamespaceInfo()->
1431  getCanonicalName( $linkTarget->getNamespace() ) .
1432  ':' . $linkTarget->getDBkey(),
1433  $linkTarget->getFragment()
1434  ),
1435  $text,
1436  /* escape = */ false // Already escaped
1437  );
1438  } else {
1439  $link = self::link( $linkTarget, $text, [], [], $options );
1440  }
1441 
1442  return $link;
1443  }
1444 
1451  public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1452  # Valid link forms:
1453  # Foobar -- normal
1454  # :Foobar -- override special treatment of prefix (images, language links)
1455  # /Foobar -- convert to CurrentPage/Foobar
1456  # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1457  # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1458  # ../Foobar -- convert to CurrentPage/Foobar,
1459  # (from CurrentPage/CurrentSubPage)
1460  # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1461  # (from CurrentPage/CurrentSubPage)
1462 
1463  $ret = $target; # default return value is no change
1464 
1465  # Some namespaces don't allow subpages,
1466  # so only perform processing if subpages are allowed
1467  if (
1468  $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1469  hasSubpages( $contextTitle->getNamespace() )
1470  ) {
1471  $hash = strpos( $target, '#' );
1472  if ( $hash !== false ) {
1473  $suffix = substr( $target, $hash );
1474  $target = substr( $target, 0, $hash );
1475  } else {
1476  $suffix = '';
1477  }
1478  # T9425
1479  $target = trim( $target );
1480  $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1481  getPrefixedText( $contextTitle );
1482  # Look at the first character
1483  if ( $target != '' && $target[0] === '/' ) {
1484  # / at end means we don't want the slash to be shown
1485  $m = [];
1486  $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1487  if ( $trailingSlashes ) {
1488  $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1489  } else {
1490  $noslash = substr( $target, 1 );
1491  }
1492 
1493  $ret = $contextPrefixedText . '/' . trim( $noslash ) . $suffix;
1494  if ( $text === '' ) {
1495  $text = $target . $suffix;
1496  } # this might be changed for ugliness reasons
1497  } else {
1498  # check for .. subpage backlinks
1499  $dotdotcount = 0;
1500  $nodotdot = $target;
1501  while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1502  ++$dotdotcount;
1503  $nodotdot = substr( $nodotdot, 3 );
1504  }
1505  if ( $dotdotcount > 0 ) {
1506  $exploded = explode( '/', $contextPrefixedText );
1507  if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1508  $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1509  # / at the end means don't show full path
1510  if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1511  $nodotdot = rtrim( $nodotdot, '/' );
1512  if ( $text === '' ) {
1513  $text = $nodotdot . $suffix;
1514  }
1515  }
1516  $nodotdot = trim( $nodotdot );
1517  if ( $nodotdot != '' ) {
1518  $ret .= '/' . $nodotdot;
1519  }
1520  $ret .= $suffix;
1521  }
1522  }
1523  }
1524  }
1525 
1526  return $ret;
1527  }
1528 
1544  public static function commentBlock(
1545  $comment, $title = null, $local = false, $wikiId = null, $useParentheses = true
1546  ) {
1547  // '*' used to be the comment inserted by the software way back
1548  // in antiquity in case none was provided, here for backwards
1549  // compatibility, acc. to brion -√¶var
1550  if ( $comment == '' || $comment == '*' ) {
1551  return '';
1552  }
1553  $formatted = self::formatComment( $comment, $title, $local, $wikiId );
1554  if ( $useParentheses ) {
1555  $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1556  $classNames = 'comment';
1557  } else {
1558  $classNames = 'comment comment--without-parentheses';
1559  }
1560  return " <span class=\"$classNames\">$formatted</span>";
1561  }
1562 
1574  public static function revComment( Revision $rev, $local = false, $isPublic = false,
1575  $useParentheses = true
1576  ) {
1577  if ( $rev->getComment( RevisionRecord::RAW ) == "" ) {
1578  return "";
1579  }
1580  if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) && $isPublic ) {
1581  $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1582  } elseif ( $rev->userCan( RevisionRecord::DELETED_COMMENT ) ) {
1583  $block = self::commentBlock( $rev->getComment( RevisionRecord::FOR_THIS_USER ),
1584  $rev->getTitle(), $local, null, $useParentheses );
1585  } else {
1586  $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1587  }
1588  if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
1589  return " <span class=\"history-deleted comment\">$block</span>";
1590  }
1591  return $block;
1592  }
1593 
1599  public static function formatRevisionSize( $size ) {
1600  if ( $size == 0 ) {
1601  $stxt = wfMessage( 'historyempty' )->escaped();
1602  } else {
1603  $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1604  }
1605  return "<span class=\"history-size mw-diff-bytes\">$stxt</span>";
1606  }
1607 
1614  public static function tocIndent() {
1615  return "\n<ul>\n";
1616  }
1617 
1625  public static function tocUnindent( $level ) {
1626  return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
1627  }
1628 
1640  public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1641  $classes = "toclevel-$level";
1642  if ( $sectionIndex !== false ) {
1643  $classes .= " tocsection-$sectionIndex";
1644  }
1645 
1646  // <li class="$classes"><a href="#$anchor"><span class="tocnumber">
1647  // $tocnumber</span> <span class="toctext">$tocline</span></a>
1648  return Html::openElement( 'li', [ 'class' => $classes ] )
1649  . Html::rawElement( 'a',
1650  [ 'href' => "#$anchor" ],
1651  Html::element( 'span', [ 'class' => 'tocnumber' ], $tocnumber )
1652  . ' '
1653  . Html::rawElement( 'span', [ 'class' => 'toctext' ], $tocline )
1654  );
1655  }
1656 
1664  public static function tocLineEnd() {
1665  return "</li>\n";
1666  }
1667 
1676  public static function tocList( $toc, Language $lang = null ) {
1677  $lang = $lang ?? RequestContext::getMain()->getLanguage();
1678 
1679  $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1680 
1681  return '<div id="toc" class="toc">'
1682  . Html::element( 'input', [
1683  'type' => 'checkbox',
1684  'role' => 'button',
1685  'id' => 'toctogglecheckbox',
1686  'class' => 'toctogglecheckbox',
1687  'style' => 'display:none',
1688  ] )
1689  . Html::openElement( 'div', [
1690  'class' => 'toctitle',
1691  'lang' => $lang->getHtmlCode(),
1692  'dir' => $lang->getDir(),
1693  ] )
1694  . "<h2>$title</h2>"
1695  . '<span class="toctogglespan">'
1696  . Html::label( '', 'toctogglecheckbox', [
1697  'class' => 'toctogglelabel',
1698  ] )
1699  . '</span>'
1700  . "</div>\n"
1701  . $toc
1702  . "</ul>\n</div>\n";
1703  }
1704 
1713  public static function generateTOC( $tree, Language $lang = null ) {
1714  $toc = '';
1715  $lastLevel = 0;
1716  foreach ( $tree as $section ) {
1717  if ( $section['toclevel'] > $lastLevel ) {
1718  $toc .= self::tocIndent();
1719  } elseif ( $section['toclevel'] < $lastLevel ) {
1720  $toc .= self::tocUnindent(
1721  $lastLevel - $section['toclevel'] );
1722  } else {
1723  $toc .= self::tocLineEnd();
1724  }
1725 
1726  $toc .= self::tocLine( $section['anchor'],
1727  $section['line'], $section['number'],
1728  $section['toclevel'], $section['index'] );
1729  $lastLevel = $section['toclevel'];
1730  }
1731  $toc .= self::tocLineEnd();
1732  return self::tocList( $toc, $lang );
1733  }
1734 
1751  public static function makeHeadline( $level, $attribs, $anchor, $html,
1752  $link, $fallbackAnchor = false
1753  ) {
1754  $anchorEscaped = htmlspecialchars( $anchor );
1755  $fallback = '';
1756  if ( $fallbackAnchor !== false && $fallbackAnchor !== $anchor ) {
1757  $fallbackAnchor = htmlspecialchars( $fallbackAnchor );
1758  $fallback = "<span id=\"$fallbackAnchor\"></span>";
1759  }
1760  return "<h$level$attribs"
1761  . "$fallback<span class=\"mw-headline\" id=\"$anchorEscaped\">$html</span>"
1762  . $link
1763  . "</h$level>";
1764  }
1765 
1772  public static function splitTrail( $trail ) {
1773  $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1774  $inside = '';
1775  if ( $trail !== '' && preg_match( $regex, $trail, $m ) ) {
1776  list( , $inside, $trail ) = $m;
1777  }
1778  return [ $inside, $trail ];
1779  }
1780 
1808  public static function generateRollback( $rev, IContextSource $context = null,
1809  $options = [ 'verify' ]
1810  ) {
1811  if ( $context === null ) {
1813  }
1814 
1815  $editCount = false;
1816  if ( in_array( 'verify', $options, true ) ) {
1817  $editCount = self::getRollbackEditCount( $rev, true );
1818  if ( $editCount === false ) {
1819  return '';
1820  }
1821  }
1822 
1823  $inner = self::buildRollbackLink( $rev, $context, $editCount );
1824 
1825  if ( !in_array( 'noBrackets', $options, true ) ) {
1826  $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
1827  }
1828 
1829  if ( $context->getUser()->getBoolOption( 'showrollbackconfirmation' ) ) {
1830  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1831  $stats->increment( 'rollbackconfirmation.event.load' );
1832  $context->getOutput()->addModules( 'mediawiki.page.rollback.confirmation' );
1833  }
1834 
1835  return '<span class="mw-rollback-link">' . $inner . '</span>';
1836  }
1837 
1853  public static function getRollbackEditCount( $rev, $verify ) {
1854  global $wgShowRollbackEditCount;
1855  if ( !is_int( $wgShowRollbackEditCount ) || !$wgShowRollbackEditCount > 0 ) {
1856  // Nothing has happened, indicate this by returning 'null'
1857  return null;
1858  }
1859 
1860  $dbr = wfGetDB( DB_REPLICA );
1861 
1862  // Up to the value of $wgShowRollbackEditCount revisions are counted
1864  $res = $dbr->select(
1865  $revQuery['tables'],
1866  [ 'rev_user_text' => $revQuery['fields']['rev_user_text'], 'rev_deleted' ],
1867  // $rev->getPage() returns null sometimes
1868  [ 'rev_page' => $rev->getTitle()->getArticleID() ],
1869  __METHOD__,
1870  [
1871  'USE INDEX' => [ 'revision' => 'page_timestamp' ],
1872  'ORDER BY' => 'rev_timestamp DESC',
1873  'LIMIT' => $wgShowRollbackEditCount + 1
1874  ],
1875  $revQuery['joins']
1876  );
1877 
1878  $editCount = 0;
1879  $moreRevs = false;
1880  foreach ( $res as $row ) {
1881  if ( $rev->getUserText( RevisionRecord::RAW ) != $row->rev_user_text ) {
1882  if ( $verify &&
1883  ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1884  || $row->rev_deleted & RevisionRecord::DELETED_USER
1885  ) ) {
1886  // If the user or the text of the revision we might rollback
1887  // to is deleted in some way we can't rollback. Similar to
1888  // the sanity checks in WikiPage::commitRollback.
1889  return false;
1890  }
1891  $moreRevs = true;
1892  break;
1893  }
1894  $editCount++;
1895  }
1896 
1897  if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1898  // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1899  // and there weren't any other revisions. That means that the current user is the only
1900  // editor, so we can't rollback
1901  return false;
1902  }
1903  return $editCount;
1904  }
1905 
1915  public static function buildRollbackLink( $rev, IContextSource $context = null,
1916  $editCount = false
1917  ) {
1919 
1920  // To config which pages are affected by miser mode
1921  $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
1922 
1923  if ( $context === null ) {
1925  }
1926 
1927  $title = $rev->getTitle();
1928 
1929  $query = [
1930  'action' => 'rollback',
1931  'from' => $rev->getUserText(),
1932  'token' => $context->getUser()->getEditToken( 'rollback' ),
1933  ];
1934 
1935  $attrs = [
1936  'data-mw' => 'interface',
1937  'title' => $context->msg( 'tooltip-rollback' )->text()
1938  ];
1939 
1940  $options = [ 'known', 'noclasses' ];
1941 
1942  if ( $context->getRequest()->getBool( 'bot' ) ) {
1943  //T17999
1944  $query['hidediff'] = '1';
1945  $query['bot'] = '1';
1946  }
1947 
1948  $disableRollbackEditCount = false;
1949  if ( $wgMiserMode ) {
1950  foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1951  if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1952  $disableRollbackEditCount = true;
1953  break;
1954  }
1955  }
1956  }
1957 
1958  if ( !$disableRollbackEditCount
1959  && is_int( $wgShowRollbackEditCount )
1961  ) {
1962  if ( !is_numeric( $editCount ) ) {
1963  $editCount = self::getRollbackEditCount( $rev, false );
1964  }
1965 
1966  if ( $editCount > $wgShowRollbackEditCount ) {
1967  $html = $context->msg( 'rollbacklinkcount-morethan' )
1968  ->numParams( $wgShowRollbackEditCount )->parse();
1969  } else {
1970  $html = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1971  }
1972 
1973  return self::link( $title, $html, $attrs, $query, $options );
1974  }
1975 
1976  $html = $context->msg( 'rollbacklink' )->escaped();
1977  return self::link( $title, $html, $attrs, $query, $options );
1978  }
1979 
1988  public static function formatHiddenCategories( $hiddencats ) {
1989  $outText = '';
1990  if ( count( $hiddencats ) > 0 ) {
1991  # Construct the HTML
1992  $outText = '<div class="mw-hiddenCategoriesExplanation">';
1993  $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1994  $outText .= "</div><ul>\n";
1995 
1996  foreach ( $hiddencats as $titleObj ) {
1997  # If it's hidden, it must exist - no need to check with a LinkBatch
1998  $outText .= '<li>'
1999  . self::link( $titleObj, null, [], [], 'known' )
2000  . "</li>\n";
2001  }
2002  $outText .= '</ul>';
2003  }
2004  return $outText;
2005  }
2006 
2023  public static function titleAttrib( $name, $options = null, array $msgParams = [] ) {
2024  $message = wfMessage( "tooltip-$name", $msgParams );
2025  if ( !$message->exists() ) {
2026  $tooltip = false;
2027  } else {
2028  $tooltip = $message->text();
2029  # Compatibility: formerly some tooltips had [alt-.] hardcoded
2030  $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2031  # Message equal to '-' means suppress it.
2032  if ( $tooltip == '-' ) {
2033  $tooltip = false;
2034  }
2035  }
2036 
2037  $options = (array)$options;
2038 
2039  if ( in_array( 'nonexisting', $options ) ) {
2040  $tooltip = wfMessage( 'red-link-title', $tooltip ?: '' )->text();
2041  }
2042  if ( in_array( 'withaccess', $options ) ) {
2043  $accesskey = self::accesskey( $name );
2044  if ( $accesskey !== false ) {
2045  // Should be build the same as in jquery.accessKeyLabel.js
2046  if ( $tooltip === false || $tooltip === '' ) {
2047  $tooltip = wfMessage( 'brackets', $accesskey )->text();
2048  } else {
2049  $tooltip .= wfMessage( 'word-separator' )->text();
2050  $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2051  }
2052  }
2053  }
2054 
2055  return $tooltip;
2056  }
2057 
2058  public static $accesskeycache;
2059 
2071  public static function accesskey( $name ) {
2072  if ( isset( self::$accesskeycache[$name] ) ) {
2073  return self::$accesskeycache[$name];
2074  }
2075 
2076  $message = wfMessage( "accesskey-$name" );
2077 
2078  if ( !$message->exists() ) {
2079  $accesskey = false;
2080  } else {
2081  $accesskey = $message->plain();
2082  if ( $accesskey === '' || $accesskey === '-' ) {
2083  # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2084  # attribute, but this is broken for accesskey: that might be a useful
2085  # value.
2086  $accesskey = false;
2087  }
2088  }
2089 
2090  self::$accesskeycache[$name] = $accesskey;
2091  return self::$accesskeycache[$name];
2092  }
2093 
2107  public static function getRevDeleteLink( User $user, Revision $rev, LinkTarget $title ) {
2108  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2109  $canHide = $permissionManager->userHasRight( $user, 'deleterevision' );
2110  $canHideHistory = $permissionManager->userHasRight( $user, 'deletedhistory' );
2111  if ( !$canHide && !( $rev->getVisibility() && $canHideHistory ) ) {
2112  return '';
2113  }
2114 
2115  if ( !$rev->userCan( RevisionRecord::DELETED_RESTRICTED, $user ) ) {
2116  return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2117  }
2118  $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
2119  getPrefixedDBkey( $title );
2120  if ( $rev->getId() ) {
2121  // RevDelete links using revision ID are stable across
2122  // page deletion and undeletion; use when possible.
2123  $query = [
2124  'type' => 'revision',
2125  'target' => $prefixedDbKey,
2126  'ids' => $rev->getId()
2127  ];
2128  } else {
2129  // Older deleted entries didn't save a revision ID.
2130  // We have to refer to these by timestamp, ick!
2131  $query = [
2132  'type' => 'archive',
2133  'target' => $prefixedDbKey,
2134  'ids' => $rev->getTimestamp()
2135  ];
2136  }
2137  return self::revDeleteLink( $query,
2138  $rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ), $canHide );
2139  }
2140 
2151  public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) {
2152  $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
2153  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2154  $html = wfMessage( $msgKey )->escaped();
2155  $tag = $restricted ? 'strong' : 'span';
2156  $link = self::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] );
2157  return Xml::tags(
2158  $tag,
2159  [ 'class' => 'mw-revdelundel-link' ],
2160  wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2161  );
2162  }
2163 
2173  public static function revDeleteLinkDisabled( $delete = true ) {
2174  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2175  $html = wfMessage( $msgKey )->escaped();
2176  $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2177  return Xml::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses );
2178  }
2179 
2192  public static function tooltipAndAccesskeyAttribs(
2193  $name,
2194  array $msgParams = [],
2195  $options = null
2196  ) {
2197  $options = (array)$options;
2198  $options[] = 'withaccess';
2199 
2200  $attribs = [
2201  'title' => self::titleAttrib( $name, $options, $msgParams ),
2202  'accesskey' => self::accesskey( $name )
2203  ];
2204  if ( $attribs['title'] === false ) {
2205  unset( $attribs['title'] );
2206  }
2207  if ( $attribs['accesskey'] === false ) {
2208  unset( $attribs['accesskey'] );
2209  }
2210  return $attribs;
2211  }
2212 
2220  public static function tooltip( $name, $options = null ) {
2221  $tooltip = self::titleAttrib( $name, $options );
2222  if ( $tooltip === false ) {
2223  return '';
2224  }
2225  return Xml::expandAttributes( [
2226  'title' => $tooltip
2227  ] );
2228  }
2229 
2230 }
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1748
Linker\getImageLinkMTOParams
static getImageLinkMTOParams( $frameParams, $query='', $parser=null)
Get the link parameters for MediaTransformOutput::toHtml() from given frame parameters supplied by th...
Definition: Linker.php:455
Revision\getTimestamp
getTimestamp()
Definition: Revision.php:798
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:561
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:317
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
$wgThumbLimits
$wgThumbLimits
Adjust thumbnails on image pages according to a user setting.
Definition: DefaultSettings.php:1474
Linker\formatLinksInComment
static formatLinksInComment( $comment, $title=null, $local=false, $wikiId=null)
Formats wiki links and media links in text; all other wiki formatting is ignored.
Definition: Linker.php:1299
Linker
Some internal bits split of from Skin.php.
Definition: Linker.php:36
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
Linker\TOOL_LINKS_NOBLOCK
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
Definition: Linker.php:40
Linker\userTalkLink
static userTalkLink( $userId, $userText)
Definition: Linker.php:1037
Xml\expandAttributes
static expandAttributes( $attribs)
Given an array of ('attributename' => 'value'), it generates the code to set the XML attributes : att...
Definition: Xml.php:67
Linker\emailLink
static emailLink( $userId, $userText)
Definition: Linker.php:1080
Linker\generateTOC
static generateTOC( $tree, Language $lang=null)
Generate a table of contents from a section tree.
Definition: Linker.php:1713
$wgResponsiveImages
$wgResponsiveImages
Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
Definition: DefaultSettings.php:1593
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1102
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:899
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:130
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
Linker\makeSelfLinkObj
static makeSelfLinkObj( $nt, $html='', $query='', $trail='', $prefix='')
Make appropriate markup for a link to the current article.
Definition: Linker.php:164
Linker\getUploadUrl
static getUploadUrl( $destFile, $query='')
Get the URL to upload a certain file.
Definition: Linker.php:734
Linker\tocIndent
static tocIndent()
Add another level to the Table of Contents.
Definition: Linker.php:1614
$fallback
$fallback
Definition: MessagesAb.php:11
$wgSVGMaxSize
$wgSVGMaxSize
Don't scale a SVG larger than this.
Definition: DefaultSettings.php:1218
Linker\userToolLinks
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:944
WikiMap\getForeignURL
static getForeignURL( $wikiID, $page, $fragmentId=null)
Convenience to get a url to a page on a foreign wiki.
Definition: WikiMap.php:171
Linker\fnamePart
static fnamePart( $url)
Returns the filename part of an url.
Definition: Linker.php:228
Linker\specialLink
static specialLink( $name, $key='')
Make a link to a special page given its name and, optionally, a message key from the link text.
Definition: Linker.php:823
StringUtils\escapeRegexReplacement
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Definition: StringUtils.php:343
NS_FILE
const NS_FILE
Definition: Defines.php:66
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Linker\revComment
static revComment(Revision $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision's comment block, if the current user is allowed to view it.
Definition: Linker.php:1574
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:142
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1263
$s
$s
Definition: mergeMessageFileList.php:185
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:83
Linker\processResponsiveImages
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:643
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1078
$wgTitle
if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
Definition: api.php:53
$success
$success
Definition: NoLocalSettings.php:42
Linker\getInvalidTitleDescription
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
Definition: Linker.php:188
MediaWiki\Linker\LinkTarget\isExternal
isExternal()
Whether this LinkTarget has an interwiki component.
$res
$res
Definition: testCompression.php:54
Revision\getId
getId()
Get revision ID.
Definition: Revision.php:442
Linker\makeThumbLinkObj
static makeThumbLinkObj(LinkTarget $title, $file, $label='', $alt='', $align='right', $params=[], $framed=false, $manualthumb="")
Make HTML for a thumbnail including image, border and caption.
Definition: Linker.php:494
$revQuery
$revQuery
Definition: testCompression.php:53
Linker\tocLine
static tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex=false)
parameter level defines if we are on an indentation level
Definition: Linker.php:1640
Linker\tocList
static tocList( $toc, Language $lang=null)
Wraps the TOC in a table and provides the hide/collapse javascript.
Definition: Linker.php:1676
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:1988
Linker\makeThumbLink2
static makeThumbLink2(LinkTarget $title, $file, $frameParams=[], $handlerParams=[], $time=false, $query="")
Definition: Linker.php:520
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2192
$dbr
$dbr
Definition: testCompression.php:52
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:439
Revision
Definition: Revision.php:40
NS_MAIN
const NS_MAIN
Definition: Defines.php:60
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:49
Linker\$accesskeycache
static $accesskeycache
Definition: Linker.php:2058
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:315
Linker\makeMediaLinkObj
static makeMediaLinkObj( $title, $html='', $time=false)
Create a direct link to a given uploaded file.
Definition: Linker.php:763
Linker\generateRollback
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1808
TitleValue\tryNew
static tryNew( $namespace, $title, $fragment='', $interwiki='')
Constructs a TitleValue, or returns null if the parameters are not valid.
Definition: TitleValue.php:91
SpecialPage\getTitleValueFor
static getTitleValueFor( $name, $subpage=false, $fragment='')
Get a localised TitleValue object for a specified special page name.
Definition: SpecialPage.php:98
Linker\formatAutocomments
static formatAutocomments( $comment, $title=null, $local=false, $wikiId=null)
Converts autogenerated comments in edit summaries into section links.
Definition: Linker.php:1196
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2562
Linker\getRollbackEditCount
static getRollbackEditCount( $rev, $verify)
This function will return the number of revisions which a rollback would revert and,...
Definition: Linker.php:1853
$wgLang
$wgLang
Definition: Setup.php:842
Linker\makeHeadline
static makeHeadline( $level, $attribs, $anchor, $html, $link, $fallbackAnchor=false)
Create a headline for content.
Definition: Linker.php:1751
Linker\tocLineEnd
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1664
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:392
Linker\revDeleteLinkDisabled
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2173
$title
$title
Definition: testCompression.php:36
Linker\makeExternalLink
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:849
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Linker\revUserTools
static revUserTools( $rev, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1125
Linker\makeCommentLink
static makeCommentLink(LinkTarget $linkTarget, $text, $wikiId=null, $options=[])
Generates a link to the given LinkTarget.
Definition: Linker.php:1421
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:913
Linker\splitTrail
static splitTrail( $trail)
Split a link trail, return the "inside" portion and the remainder of the trail as a two-element array...
Definition: Linker.php:1772
Revision\getTitle
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:559
$wgShowRollbackEditCount
$wgShowRollbackEditCount
The $wgShowRollbackEditCount variable is used to show how many edits can be rolled back.
Definition: DefaultSettings.php:3541
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:610
Linker\blockLink
static blockLink( $userId, $userText)
Definition: Linker.php:1059
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:63
Linker\normaliseSpecialPage
static normaliseSpecialPage(LinkTarget $target)
Definition: Linker.php:208
ExternalUserNames\getUserLinkTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
Definition: ExternalUserNames.php:62
Linker\TOOL_LINKS_EMAIL
const TOOL_LINKS_EMAIL
Definition: Linker.php:41
Linker\commentBlock
static commentBlock( $comment, $title=null, $local=false, $wikiId=null, $useParentheses=true)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
Definition: Linker.php:1544
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:48
Linker\userToolLinksRedContribs
static userToolLinksRedContribs( $userId, $userText, $edits=null, $useParentheses=true)
Alias for userToolLinks( $userId, $userText, true );.
Definition: Linker.php:1025
Revision\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:701
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
Linker\getRevDeleteLink
static getRevDeleteLink(User $user, Revision $rev, LinkTarget $title)
Get a revision-deletion link, or disabled link, or nothing, depending on user permissions & the setti...
Definition: Linker.php:2107
Linker\link
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:86
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
Revision\isDeleted
isDeleted( $field)
Definition: Revision.php:692
Linker\formatRevisionSize
static formatRevisionSize( $size)
Definition: Linker.php:1599
MediaWiki\Linker\LinkTarget\getFragment
getFragment()
Get the link fragment (i.e.
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:447
DummyLinker
Definition: DummyLinker.php:6
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Linker\makeMediaLinkFile
static makeMediaLinkFile(LinkTarget $title, $file, $html='')
Create a direct link to a given uploaded file.
Definition: Linker.php:782
$wgUploadNavigationUrl
$wgUploadNavigationUrl
Point the upload navigation link to an external URL Useful if you want to use a shared repository by ...
Definition: DefaultSettings.php:888
Linker\titleAttrib
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
Definition: Linker.php:2023
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
$context
$context
Definition: load.php:40
Linker\formatComment
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1166
Linker\tooltip
static tooltip( $name, $options=null)
Returns raw bits of HTML, use titleAttrib()
Definition: Linker.php:2220
$wgMiserMode
$wgMiserMode
Disable database-intensive features.
Definition: DefaultSettings.php:2260
MalformedTitleException
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
Definition: MalformedTitleException.php:25
$wgThumbUpright
$wgThumbUpright
Adjust width of upright images when parameter 'upright' is used This allows a nicer look for upright ...
Definition: DefaultSettings.php:1580
Linker\tocUnindent
static tocUnindent( $level)
Finish one or more sublevels on the Table of Contents.
Definition: Linker.php:1625
Linker\makeImageLink
static makeImageLink(Parser $parser, LinkTarget $title, $file, $frameParams=[], $handlerParams=[], $time=false, $query="", $widthOption=null)
Given parameters derived from [[Image:Foo|options...]], generate the HTML that that syntax inserts in...
Definition: Linker.php:304
Linker\revDeleteLink
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2151
$wgEnableUploads
$wgEnableUploads
Allow users to upload files.
Definition: DefaultSettings.php:402
NS_USER
const NS_USER
Definition: Defines.php:62
Revision\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: Revision.php:649
Linker\normalizeSubpageLink
static normalizeSubpageLink( $contextTitle, $target, &$text)
Definition: Linker.php:1451
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1065
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:293
$wgUploadMissingFileUrl
$wgUploadMissingFileUrl
Point the upload link for missing files to an external URL, as with $wgUploadNavigationUrl.
Definition: DefaultSettings.php:895
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Linker\accesskey
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
Definition: Linker.php:2071
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:52
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
Linker\buildRollbackLink
static buildRollbackLink( $rev, IContextSource $context=null, $editCount=false)
Build a raw rollback link, useful for collections of "tool" links.
Definition: Linker.php:1915
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:137
Linker\makeExternalImage
static makeExternalImage( $url, $alt='')
Return the code for images which were added via external links, via Parser::maybeMakeExternalImage().
Definition: Linker.php:248
Language
Internationalisation code.
Definition: Language.php:39
Linker\makeBrokenImageLinkObj
static makeBrokenImageLinkObj( $title, $label='', $query='', $unused1='', $unused2='', $time=false)
Make a "broken" link to an image.
Definition: Linker.php:678
Revision\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1022
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:7022
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:37