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 $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  $user = RequestContext::getMain()->getUser();
986  $userCanBlock = MediaWikiServices::getInstance()->getPermissionManager()
987  ->userHasRight( $user, 'block' );
988  if ( $blockable && $userCanBlock ) {
989  $items[] = self::blockLink( $userId, $userText );
990  }
991 
992  if ( $addEmailLink && $user->canSendEmail() ) {
993  $items[] = self::emailLink( $userId, $userText );
994  }
995 
996  Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] );
997 
998  if ( !$items ) {
999  return '';
1000  }
1001 
1002  if ( $useParentheses ) {
1003  return wfMessage( 'word-separator' )->escaped()
1004  . '<span class="mw-usertoollinks">'
1005  . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1006  . '</span>';
1007  }
1008 
1009  $tools = [];
1010  foreach ( $items as $tool ) {
1011  $tools[] = Html::rawElement( 'span', [], $tool );
1012  }
1013  return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1014  implode( ' ', $tools ) . '</span>';
1015  }
1016 
1026  public static function userToolLinksRedContribs(
1027  $userId, $userText, $edits = null, $useParentheses = true
1028  ) {
1029  return self::userToolLinks( $userId, $userText, true, 0, $edits, $useParentheses );
1030  }
1031 
1038  public static function userTalkLink( $userId, $userText ) {
1039  if ( $userText === '' ) {
1040  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1041  'that need to be fixed?' );
1042  return wfMessage( 'empty-username' )->parse();
1043  }
1044 
1045  $userTalkPage = TitleValue::tryNew( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
1046  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-talk' ];
1047  $linkText = wfMessage( 'talkpagelinktext' )->escaped();
1048 
1049  return $userTalkPage
1050  ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1051  : Html::rawElement( 'span', $moreLinkAttribs, $linkText );
1052  }
1053 
1060  public static function blockLink( $userId, $userText ) {
1061  if ( $userText === '' ) {
1062  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1063  'that need to be fixed?' );
1064  return wfMessage( 'empty-username' )->parse();
1065  }
1066 
1067  $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
1068  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-block' ];
1069 
1070  return self::link( $blockPage,
1071  wfMessage( 'blocklink' )->escaped(),
1072  $moreLinkAttribs
1073  );
1074  }
1075 
1081  public static function emailLink( $userId, $userText ) {
1082  if ( $userText === '' ) {
1083  wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
1084  'that need to be fixed?' );
1085  return wfMessage( 'empty-username' )->parse();
1086  }
1087 
1088  $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
1089  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-mail' ];
1090  return self::link( $emailPage,
1091  wfMessage( 'emaillink' )->escaped(),
1092  $moreLinkAttribs
1093  );
1094  }
1095 
1103  public static function revUserLink( $rev, $isPublic = false ) {
1104  // TODO inject a user
1105  $user = RequestContext::getMain()->getUser();
1106 
1107  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) && $isPublic ) {
1108  $link = wfMessage( 'rev-deleted-user' )->escaped();
1109  } elseif ( RevisionRecord::userCanBitfield(
1110  $rev->getVisibility(),
1111  RevisionRecord::DELETED_USER,
1112  $user
1113  ) ) {
1114  $link = self::userLink(
1115  $rev->getUser( RevisionRecord::FOR_THIS_USER, $user ),
1116  $rev->getUserText( RevisionRecord::FOR_THIS_USER, $user )
1117  );
1118  } else {
1119  $link = wfMessage( 'rev-deleted-user' )->escaped();
1120  }
1121  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1122  return '<span class="history-deleted">' . $link . '</span>';
1123  }
1124  return $link;
1125  }
1126 
1135  public static function revUserTools( $rev, $isPublic = false, $useParentheses = true ) {
1136  // TODO inject a user
1137  $user = RequestContext::getMain()->getUser();
1138 
1139  if ( RevisionRecord::userCanBitfield(
1140  $rev->getVisibility(),
1141  RevisionRecord::DELETED_USER,
1142  $user
1143  ) &&
1144  ( !$rev->isDeleted( RevisionRecord::DELETED_USER ) || !$isPublic )
1145  ) {
1146  $userId = $rev->getUser( RevisionRecord::FOR_THIS_USER, $user );
1147  $userText = $rev->getUserText( RevisionRecord::FOR_THIS_USER, $user );
1148  if ( $userId || (string)$userText !== '' ) {
1149  $link = self::userLink( $userId, $userText )
1150  . self::userToolLinks( $userId, $userText, false, 0, null,
1151  $useParentheses );
1152  }
1153  }
1154 
1155  if ( !isset( $link ) ) {
1156  $link = wfMessage( 'rev-deleted-user' )->escaped();
1157  }
1158 
1159  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1160  return ' <span class="history-deleted mw-userlink">' . $link . '</span>';
1161  }
1162  return $link;
1163  }
1164 
1183  public static function formatComment(
1184  $comment, $title = null, $local = false, $wikiId = null
1185  ) {
1186  # Sanitize text a bit:
1187  $comment = str_replace( "\n", " ", $comment );
1188  # Allow HTML entities (for T15815)
1189  $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
1190 
1191  # Render autocomments and make links:
1192  $comment = self::formatAutocomments( $comment, $title, $local, $wikiId );
1193  return self::formatLinksInComment( $comment, $title, $local, $wikiId );
1194  }
1195 
1213  private static function formatAutocomments(
1214  $comment, $title = null, $local = false, $wikiId = null
1215  ) {
1216  // @todo $append here is something of a hack to preserve the status
1217  // quo. Someone who knows more about bidi and such should decide
1218  // (1) what sane rendering even *is* for an LTR edit summary on an RTL
1219  // wiki, both when autocomments exist and when they don't, and
1220  // (2) what markup will make that actually happen.
1221  $append = '';
1222  $comment = preg_replace_callback(
1223  // To detect the presence of content before or after the
1224  // auto-comment, we use capturing groups inside optional zero-width
1225  // assertions. But older versions of PCRE can't directly make
1226  // zero-width assertions optional, so wrap them in a non-capturing
1227  // group.
1228  '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
1229  function ( $match ) use ( $title, $local, $wikiId, &$append ) {
1230  global $wgLang;
1231 
1232  // Ensure all match positions are defined
1233  $match += [ '', '', '', '' ];
1234 
1235  $pre = $match[1] !== '';
1236  $auto = $match[2];
1237  $post = $match[3] !== '';
1238  $comment = null;
1239 
1240  Hooks::run(
1241  'FormatAutocomments',
1242  [ &$comment, $pre, $auto, $post, Title::castFromLinkTarget( $title ), $local,
1243  $wikiId ]
1244  );
1245 
1246  if ( $comment === null ) {
1247  if ( $title ) {
1248  $section = $auto;
1249  # Remove links that a user may have manually put in the autosummary
1250  # This could be improved by copying as much of Parser::stripSectionName as desired.
1251  $section = str_replace( [
1252  '[[:',
1253  '[[',
1254  ']]'
1255  ], '', $section );
1256 
1257  // We don't want any links in the auto text to be linked, but we still
1258  // want to show any [[ ]]
1259  $sectionText = str_replace( '[[', '&#91;[', $auto );
1260 
1261  $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
1262  if ( $section !== '' ) {
1263  if ( $local ) {
1264  $sectionTitle = new TitleValue( NS_MAIN, '', $section );
1265  } else {
1266  $sectionTitle = $title->createFragmentTarget( $section );
1267  }
1268  $auto = Linker::makeCommentLink(
1269  $sectionTitle,
1270  $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText,
1271  $wikiId,
1272  'noclasses'
1273  );
1274  }
1275  }
1276  if ( $pre ) {
1277  # written summary $presep autocomment (summary /* section */)
1278  $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1279  }
1280  if ( $post ) {
1281  # autocomment $postsep written summary (/* section */ summary)
1282  $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1283  }
1284  if ( $auto ) {
1285  $auto = '<span dir="auto"><span class="autocomment">' . $auto . '</span>';
1286  $append .= '</span>';
1287  }
1288  $comment = $pre . $auto;
1289  }
1290  return $comment;
1291  },
1292  $comment
1293  );
1294  return $comment . $append;
1295  }
1296 
1316  public static function formatLinksInComment(
1317  $comment, $title = null, $local = false, $wikiId = null
1318  ) {
1319  return preg_replace_callback(
1320  '/
1321  \[\[
1322  \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking
1323  :? # ignore optional leading colon
1324  ([^\]|]+) # 1. link target; page names cannot include ] or |
1325  (?:\|
1326  # 2. link text
1327  # Stop matching at ]] without relying on backtracking.
1328  ((?:]?[^\]])*+)
1329  )?
1330  \]\]
1331  ([^[]*) # 3. link trail (the text up until the next link)
1332  /x',
1333  function ( $match ) use ( $title, $local, $wikiId ) {
1334  $services = MediaWikiServices::getInstance();
1335 
1336  $medians = '(?:';
1337  $medians .= preg_quote(
1338  $services->getNamespaceInfo()->getCanonicalName( NS_MEDIA ), '/' );
1339  $medians .= '|';
1340  $medians .= preg_quote(
1341  $services->getContentLanguage()->getNsText( NS_MEDIA ),
1342  '/'
1343  ) . '):';
1344 
1345  $comment = $match[0];
1346 
1347  # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1348  if ( strpos( $match[1], '%' ) !== false ) {
1349  $match[1] = strtr(
1350  rawurldecode( $match[1] ),
1351  [ '<' => '&lt;', '>' => '&gt;' ]
1352  );
1353  }
1354 
1355  # Handle link renaming [[foo|text]] will show link as "text"
1356  if ( $match[2] != "" ) {
1357  $text = $match[2];
1358  } else {
1359  $text = $match[1];
1360  }
1361  $submatch = [];
1362  $thelink = null;
1363  if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1364  # Media link; trail not supported.
1365  $linkRegexp = '/\[\[(.*?)\]\]/';
1366  $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1367  if ( $title ) {
1368  $thelink = Linker::makeMediaLinkObj( $title, $text );
1369  }
1370  } else {
1371  # Other kind of link
1372  # Make sure its target is non-empty
1373  if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1374  $match[1] = substr( $match[1], 1 );
1375  }
1376  if ( $match[1] !== false && $match[1] !== '' ) {
1377  if ( preg_match(
1378  $services->getContentLanguage()->linkTrail(),
1379  $match[3],
1380  $submatch
1381  ) ) {
1382  $trail = $submatch[1];
1383  } else {
1384  $trail = "";
1385  }
1386  $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1387  list( $inside, $trail ) = Linker::splitTrail( $trail );
1388 
1389  $linkText = $text;
1390  $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText );
1391 
1392  Title::newFromText( $linkTarget );
1393  try {
1394  $target = $services->getTitleParser()->
1395  parseTitle( $linkTarget );
1396 
1397  if ( $target->getText() == '' && !$target->isExternal()
1398  && !$local && $title
1399  ) {
1400  $target = $title->createFragmentTarget( $target->getFragment() );
1401  }
1402 
1403  $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
1404  } catch ( MalformedTitleException $e ) {
1405  // Fall through
1406  }
1407  }
1408  }
1409  if ( $thelink ) {
1410  // If the link is still valid, go ahead and replace it in!
1411  $comment = preg_replace(
1412  $linkRegexp,
1414  $comment,
1415  1
1416  );
1417  }
1418 
1419  return $comment;
1420  },
1421  $comment
1422  );
1423  }
1424 
1438  public static function makeCommentLink(
1439  LinkTarget $linkTarget, $text, $wikiId = null, $options = []
1440  ) {
1441  if ( $wikiId !== null && !$linkTarget->isExternal() ) {
1442  $link = self::makeExternalLink(
1444  $wikiId,
1445  $linkTarget->getNamespace() === 0
1446  ? $linkTarget->getDBkey()
1447  : MediaWikiServices::getInstance()->getNamespaceInfo()->
1448  getCanonicalName( $linkTarget->getNamespace() ) .
1449  ':' . $linkTarget->getDBkey(),
1450  $linkTarget->getFragment()
1451  ),
1452  $text,
1453  /* escape = */ false // Already escaped
1454  );
1455  } else {
1456  $link = self::link( $linkTarget, $text, [], [], $options );
1457  }
1458 
1459  return $link;
1460  }
1461 
1468  public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1469  # Valid link forms:
1470  # Foobar -- normal
1471  # :Foobar -- override special treatment of prefix (images, language links)
1472  # /Foobar -- convert to CurrentPage/Foobar
1473  # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1474  # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1475  # ../Foobar -- convert to CurrentPage/Foobar,
1476  # (from CurrentPage/CurrentSubPage)
1477  # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1478  # (from CurrentPage/CurrentSubPage)
1479 
1480  $ret = $target; # default return value is no change
1481 
1482  # Some namespaces don't allow subpages,
1483  # so only perform processing if subpages are allowed
1484  if (
1485  $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1486  hasSubpages( $contextTitle->getNamespace() )
1487  ) {
1488  $hash = strpos( $target, '#' );
1489  if ( $hash !== false ) {
1490  $suffix = substr( $target, $hash );
1491  $target = substr( $target, 0, $hash );
1492  } else {
1493  $suffix = '';
1494  }
1495  # T9425
1496  $target = trim( $target );
1497  $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1498  getPrefixedText( $contextTitle );
1499  # Look at the first character
1500  if ( $target != '' && $target[0] === '/' ) {
1501  # / at end means we don't want the slash to be shown
1502  $m = [];
1503  $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1504  if ( $trailingSlashes ) {
1505  $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1506  } else {
1507  $noslash = substr( $target, 1 );
1508  }
1509 
1510  $ret = $contextPrefixedText . '/' . trim( $noslash ) . $suffix;
1511  if ( $text === '' ) {
1512  $text = $target . $suffix;
1513  } # this might be changed for ugliness reasons
1514  } else {
1515  # check for .. subpage backlinks
1516  $dotdotcount = 0;
1517  $nodotdot = $target;
1518  while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1519  ++$dotdotcount;
1520  $nodotdot = substr( $nodotdot, 3 );
1521  }
1522  if ( $dotdotcount > 0 ) {
1523  $exploded = explode( '/', $contextPrefixedText );
1524  if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1525  $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1526  # / at the end means don't show full path
1527  if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1528  $nodotdot = rtrim( $nodotdot, '/' );
1529  if ( $text === '' ) {
1530  $text = $nodotdot . $suffix;
1531  }
1532  }
1533  $nodotdot = trim( $nodotdot );
1534  if ( $nodotdot != '' ) {
1535  $ret .= '/' . $nodotdot;
1536  }
1537  $ret .= $suffix;
1538  }
1539  }
1540  }
1541  }
1542 
1543  return $ret;
1544  }
1545 
1561  public static function commentBlock(
1562  $comment, $title = null, $local = false, $wikiId = null, $useParentheses = true
1563  ) {
1564  // '*' used to be the comment inserted by the software way back
1565  // in antiquity in case none was provided, here for backwards
1566  // compatibility, acc. to brion -√¶var
1567  if ( $comment == '' || $comment == '*' ) {
1568  return '';
1569  }
1570  $formatted = self::formatComment( $comment, $title, $local, $wikiId );
1571  if ( $useParentheses ) {
1572  $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1573  $classNames = 'comment';
1574  } else {
1575  $classNames = 'comment comment--without-parentheses';
1576  }
1577  return " <span class=\"$classNames\">$formatted</span>";
1578  }
1579 
1591  public static function revComment( Revision $rev, $local = false, $isPublic = false,
1592  $useParentheses = true
1593  ) {
1594  // TODO inject a user
1595  $user = RequestContext::getMain()->getUser();
1596 
1597  if ( $rev->getComment( RevisionRecord::RAW ) == "" ) {
1598  return "";
1599  }
1600  if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) && $isPublic ) {
1601  $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1602  } elseif ( RevisionRecord::userCanBitfield(
1603  $rev->getVisibility(),
1604  RevisionRecord::DELETED_COMMENT,
1605  $user
1606  ) ) {
1607  $block = self::commentBlock(
1608  $rev->getComment( RevisionRecord::FOR_THIS_USER, $user ),
1609  $rev->getTitle(), $local, null, $useParentheses
1610  );
1611  } else {
1612  $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1613  }
1614  if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
1615  return " <span class=\"history-deleted comment\">$block</span>";
1616  }
1617  return $block;
1618  }
1619 
1625  public static function formatRevisionSize( $size ) {
1626  if ( $size == 0 ) {
1627  $stxt = wfMessage( 'historyempty' )->escaped();
1628  } else {
1629  $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1630  }
1631  return "<span class=\"history-size mw-diff-bytes\">$stxt</span>";
1632  }
1633 
1640  public static function tocIndent() {
1641  return "\n<ul>\n";
1642  }
1643 
1651  public static function tocUnindent( $level ) {
1652  return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
1653  }
1654 
1666  public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1667  $classes = "toclevel-$level";
1668  if ( $sectionIndex !== false ) {
1669  $classes .= " tocsection-$sectionIndex";
1670  }
1671 
1672  // <li class="$classes"><a href="#$anchor"><span class="tocnumber">
1673  // $tocnumber</span> <span class="toctext">$tocline</span></a>
1674  return Html::openElement( 'li', [ 'class' => $classes ] )
1675  . Html::rawElement( 'a',
1676  [ 'href' => "#$anchor" ],
1677  Html::element( 'span', [ 'class' => 'tocnumber' ], $tocnumber )
1678  . ' '
1679  . Html::rawElement( 'span', [ 'class' => 'toctext' ], $tocline )
1680  );
1681  }
1682 
1690  public static function tocLineEnd() {
1691  return "</li>\n";
1692  }
1693 
1702  public static function tocList( $toc, Language $lang = null ) {
1703  $lang = $lang ?? RequestContext::getMain()->getLanguage();
1704 
1705  $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1706 
1707  return '<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading">'
1708  . Html::element( 'input', [
1709  'type' => 'checkbox',
1710  'role' => 'button',
1711  'id' => 'toctogglecheckbox',
1712  'class' => 'toctogglecheckbox',
1713  'style' => 'display:none',
1714  ] )
1715  . Html::openElement( 'div', [
1716  'class' => 'toctitle',
1717  'lang' => $lang->getHtmlCode(),
1718  'dir' => $lang->getDir(),
1719  ] )
1720  . '<h2 id="mw-toc-heading">' . $title . '</h2>'
1721  . '<span class="toctogglespan">'
1722  . Html::label( '', 'toctogglecheckbox', [
1723  'class' => 'toctogglelabel',
1724  ] )
1725  . '</span>'
1726  . "</div>\n"
1727  . $toc
1728  . "</ul>\n</div>\n";
1729  }
1730 
1739  public static function generateTOC( $tree, Language $lang = null ) {
1740  $toc = '';
1741  $lastLevel = 0;
1742  foreach ( $tree as $section ) {
1743  if ( $section['toclevel'] > $lastLevel ) {
1744  $toc .= self::tocIndent();
1745  } elseif ( $section['toclevel'] < $lastLevel ) {
1746  $toc .= self::tocUnindent(
1747  $lastLevel - $section['toclevel'] );
1748  } else {
1749  $toc .= self::tocLineEnd();
1750  }
1751 
1752  $toc .= self::tocLine( $section['anchor'],
1753  $section['line'], $section['number'],
1754  $section['toclevel'], $section['index'] );
1755  $lastLevel = $section['toclevel'];
1756  }
1757  $toc .= self::tocLineEnd();
1758  return self::tocList( $toc, $lang );
1759  }
1760 
1777  public static function makeHeadline( $level, $attribs, $anchor, $html,
1778  $link, $fallbackAnchor = false
1779  ) {
1780  $anchorEscaped = htmlspecialchars( $anchor );
1781  $fallback = '';
1782  if ( $fallbackAnchor !== false && $fallbackAnchor !== $anchor ) {
1783  $fallbackAnchor = htmlspecialchars( $fallbackAnchor );
1784  $fallback = "<span id=\"$fallbackAnchor\"></span>";
1785  }
1786  return "<h$level$attribs"
1787  . "$fallback<span class=\"mw-headline\" id=\"$anchorEscaped\">$html</span>"
1788  . $link
1789  . "</h$level>";
1790  }
1791 
1798  public static function splitTrail( $trail ) {
1799  $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1800  $inside = '';
1801  if ( $trail !== '' && preg_match( $regex, $trail, $m ) ) {
1802  list( , $inside, $trail ) = $m;
1803  }
1804  return [ $inside, $trail ];
1805  }
1806 
1834  public static function generateRollback( $rev, IContextSource $context = null,
1835  $options = [ 'verify' ]
1836  ) {
1837  if ( $context === null ) {
1839  }
1840 
1841  $editCount = false;
1842  if ( in_array( 'verify', $options, true ) ) {
1843  $editCount = self::getRollbackEditCount( $rev, true );
1844  if ( $editCount === false ) {
1845  return '';
1846  }
1847  }
1848 
1849  $inner = self::buildRollbackLink( $rev, $context, $editCount );
1850 
1851  if ( !in_array( 'noBrackets', $options, true ) ) {
1852  $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
1853  }
1854 
1855  if ( $context->getUser()->getBoolOption( 'showrollbackconfirmation' ) ) {
1856  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1857  $stats->increment( 'rollbackconfirmation.event.load' );
1858  $context->getOutput()->addModules( 'mediawiki.page.rollback.confirmation' );
1859  }
1860 
1861  return '<span class="mw-rollback-link">' . $inner . '</span>';
1862  }
1863 
1879  public static function getRollbackEditCount( $rev, $verify ) {
1880  global $wgShowRollbackEditCount;
1881  if ( !is_int( $wgShowRollbackEditCount ) || !$wgShowRollbackEditCount > 0 ) {
1882  // Nothing has happened, indicate this by returning 'null'
1883  return null;
1884  }
1885 
1886  $dbr = wfGetDB( DB_REPLICA );
1887 
1888  // Up to the value of $wgShowRollbackEditCount revisions are counted
1889  $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
1890  $res = $dbr->select(
1891  $revQuery['tables'],
1892  [ 'rev_user_text' => $revQuery['fields']['rev_user_text'], 'rev_deleted' ],
1893  // $rev->getPage() returns null sometimes
1894  [ 'rev_page' => $rev->getTitle()->getArticleID() ],
1895  __METHOD__,
1896  [
1897  'USE INDEX' => [ 'revision' => 'page_timestamp' ],
1898  'ORDER BY' => 'rev_timestamp DESC',
1899  'LIMIT' => $wgShowRollbackEditCount + 1
1900  ],
1901  $revQuery['joins']
1902  );
1903 
1904  $editCount = 0;
1905  $moreRevs = false;
1906  foreach ( $res as $row ) {
1907  if ( $rev->getUserText( RevisionRecord::RAW ) != $row->rev_user_text ) {
1908  if ( $verify &&
1909  ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1910  || $row->rev_deleted & RevisionRecord::DELETED_USER
1911  ) ) {
1912  // If the user or the text of the revision we might rollback
1913  // to is deleted in some way we can't rollback. Similar to
1914  // the sanity checks in WikiPage::commitRollback.
1915  return false;
1916  }
1917  $moreRevs = true;
1918  break;
1919  }
1920  $editCount++;
1921  }
1922 
1923  if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1924  // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1925  // and there weren't any other revisions. That means that the current user is the only
1926  // editor, so we can't rollback
1927  return false;
1928  }
1929  return $editCount;
1930  }
1931 
1941  public static function buildRollbackLink( $rev, IContextSource $context = null,
1942  $editCount = false
1943  ) {
1945 
1946  // To config which pages are affected by miser mode
1947  $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
1948 
1949  if ( $context === null ) {
1951  }
1952 
1953  $title = $rev->getTitle();
1954 
1955  $query = [
1956  'action' => 'rollback',
1957  'from' => $rev->getUserText(),
1958  'token' => $context->getUser()->getEditToken( 'rollback' ),
1959  ];
1960 
1961  $attrs = [
1962  'data-mw' => 'interface',
1963  'title' => $context->msg( 'tooltip-rollback' )->text()
1964  ];
1965 
1966  $options = [ 'known', 'noclasses' ];
1967 
1968  if ( $context->getRequest()->getBool( 'bot' ) ) {
1969  //T17999
1970  $query['hidediff'] = '1';
1971  $query['bot'] = '1';
1972  }
1973 
1974  $disableRollbackEditCount = false;
1975  if ( $wgMiserMode ) {
1976  foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1977  if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1978  $disableRollbackEditCount = true;
1979  break;
1980  }
1981  }
1982  }
1983 
1984  if ( !$disableRollbackEditCount
1985  && is_int( $wgShowRollbackEditCount )
1987  ) {
1988  if ( !is_numeric( $editCount ) ) {
1989  $editCount = self::getRollbackEditCount( $rev, false );
1990  }
1991 
1992  if ( $editCount > $wgShowRollbackEditCount ) {
1993  $html = $context->msg( 'rollbacklinkcount-morethan' )
1994  ->numParams( $wgShowRollbackEditCount )->parse();
1995  } else {
1996  $html = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1997  }
1998 
1999  return self::link( $title, $html, $attrs, $query, $options );
2000  }
2001 
2002  $html = $context->msg( 'rollbacklink' )->escaped();
2003  return self::link( $title, $html, $attrs, $query, $options );
2004  }
2005 
2014  public static function formatHiddenCategories( $hiddencats ) {
2015  $outText = '';
2016  if ( count( $hiddencats ) > 0 ) {
2017  # Construct the HTML
2018  $outText = '<div class="mw-hiddenCategoriesExplanation">';
2019  $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
2020  $outText .= "</div><ul>\n";
2021 
2022  foreach ( $hiddencats as $titleObj ) {
2023  # If it's hidden, it must exist - no need to check with a LinkBatch
2024  $outText .= '<li>'
2025  . self::link( $titleObj, null, [], [], 'known' )
2026  . "</li>\n";
2027  }
2028  $outText .= '</ul>';
2029  }
2030  return $outText;
2031  }
2032 
2049  public static function titleAttrib( $name, $options = null, array $msgParams = [] ) {
2050  $message = wfMessage( "tooltip-$name", $msgParams );
2051  if ( !$message->exists() ) {
2052  $tooltip = false;
2053  } else {
2054  $tooltip = $message->text();
2055  # Compatibility: formerly some tooltips had [alt-.] hardcoded
2056  $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2057  # Message equal to '-' means suppress it.
2058  if ( $tooltip == '-' ) {
2059  $tooltip = false;
2060  }
2061  }
2062 
2063  $options = (array)$options;
2064 
2065  if ( in_array( 'nonexisting', $options ) ) {
2066  $tooltip = wfMessage( 'red-link-title', $tooltip ?: '' )->text();
2067  }
2068  if ( in_array( 'withaccess', $options ) ) {
2069  $accesskey = self::accesskey( $name );
2070  if ( $accesskey !== false ) {
2071  // Should be build the same as in jquery.accessKeyLabel.js
2072  if ( $tooltip === false || $tooltip === '' ) {
2073  $tooltip = wfMessage( 'brackets', $accesskey )->text();
2074  } else {
2075  $tooltip .= wfMessage( 'word-separator' )->text();
2076  $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2077  }
2078  }
2079  }
2080 
2081  return $tooltip;
2082  }
2083 
2084  public static $accesskeycache;
2085 
2097  public static function accesskey( $name ) {
2098  if ( isset( self::$accesskeycache[$name] ) ) {
2099  return self::$accesskeycache[$name];
2100  }
2101 
2102  $message = wfMessage( "accesskey-$name" );
2103 
2104  if ( !$message->exists() ) {
2105  $accesskey = false;
2106  } else {
2107  $accesskey = $message->plain();
2108  if ( $accesskey === '' || $accesskey === '-' ) {
2109  # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2110  # attribute, but this is broken for accesskey: that might be a useful
2111  # value.
2112  $accesskey = false;
2113  }
2114  }
2115 
2116  self::$accesskeycache[$name] = $accesskey;
2117  return self::$accesskeycache[$name];
2118  }
2119 
2133  public static function getRevDeleteLink( User $user, Revision $rev, LinkTarget $title ) {
2134  $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2135  $canHide = $permissionManager->userHasRight( $user, 'deleterevision' );
2136  $canHideHistory = $permissionManager->userHasRight( $user, 'deletedhistory' );
2137  if ( !$canHide && !( $rev->getVisibility() && $canHideHistory ) ) {
2138  return '';
2139  }
2140 
2141  if ( !RevisionRecord::userCanBitfield(
2142  $rev->getVisibility(),
2143  RevisionRecord::DELETED_RESTRICTED,
2144  $user
2145  ) ) {
2146  return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2147  }
2148  $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
2149  getPrefixedDBkey( $title );
2150  if ( $rev->getId() ) {
2151  // RevDelete links using revision ID are stable across
2152  // page deletion and undeletion; use when possible.
2153  $query = [
2154  'type' => 'revision',
2155  'target' => $prefixedDbKey,
2156  'ids' => $rev->getId()
2157  ];
2158  } else {
2159  // Older deleted entries didn't save a revision ID.
2160  // We have to refer to these by timestamp, ick!
2161  $query = [
2162  'type' => 'archive',
2163  'target' => $prefixedDbKey,
2164  'ids' => $rev->getTimestamp()
2165  ];
2166  }
2167  return self::revDeleteLink( $query,
2168  $rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ), $canHide );
2169  }
2170 
2181  public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) {
2182  $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
2183  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2184  $html = wfMessage( $msgKey )->escaped();
2185  $tag = $restricted ? 'strong' : 'span';
2186  $link = self::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] );
2187  return Xml::tags(
2188  $tag,
2189  [ 'class' => 'mw-revdelundel-link' ],
2190  wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2191  );
2192  }
2193 
2203  public static function revDeleteLinkDisabled( $delete = true ) {
2204  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2205  $html = wfMessage( $msgKey )->escaped();
2206  $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2207  return Xml::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses );
2208  }
2209 
2222  public static function tooltipAndAccesskeyAttribs(
2223  $name,
2224  array $msgParams = [],
2225  $options = null
2226  ) {
2227  $options = (array)$options;
2228  $options[] = 'withaccess';
2229 
2230  $attribs = [
2231  'title' => self::titleAttrib( $name, $options, $msgParams ),
2232  'accesskey' => self::accesskey( $name )
2233  ];
2234  if ( $attribs['title'] === false ) {
2235  unset( $attribs['title'] );
2236  }
2237  if ( $attribs['accesskey'] === false ) {
2238  unset( $attribs['accesskey'] );
2239  }
2240  return $attribs;
2241  }
2242 
2250  public static function tooltip( $name, $options = null ) {
2251  $tooltip = self::titleAttrib( $name, $options );
2252  if ( $tooltip === false ) {
2253  return '';
2254  }
2255  return Xml::expandAttributes( [
2256  'title' => $tooltip
2257  ] );
2258  }
2259 
2260 }
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1656
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:832
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:559
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:332
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:1506
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:1316
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:1038
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:1081
Linker\generateTOC
static generateTOC( $tree, Language $lang=null)
Generate a table of contents from a section tree.
Definition: Linker.php:1739
$wgResponsiveImages
$wgResponsiveImages
Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
Definition: DefaultSettings.php:1625
Linker\revUserLink
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1103
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:137
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
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:1640
$fallback
$fallback
Definition: MessagesAb.php:11
$wgSVGMaxSize
$wgSVGMaxSize
Don't scale a SVG larger than this.
Definition: DefaultSettings.php:1245
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:312
NS_FILE
const NS_FILE
Definition: Defines.php:75
$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:1591
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:1201
$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:1067
$wgTitle
if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
Definition: api.php:59
$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:57
Revision\getId
getId()
Get revision ID.
Definition: Revision.php:441
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:56
Linker\tocLine
static tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex=false)
parameter level defines if we are on an indentation level
Definition: Linker.php:1666
Linker\tocList
static tocList( $toc, Language $lang=null)
Wraps the TOC in a div with ARIA navigation role and provides the hide/collapse JavaScript.
Definition: Linker.php:1702
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:2014
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:2222
$dbr
$dbr
Definition: testCompression.php:54
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:69
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
Linker\$accesskeycache
static $accesskeycache
Definition: Linker.php:2084
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
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:1834
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:1213
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2500
Linker\getRollbackEditCount
static getRollbackEditCount( $rev, $verify)
This function will return the number of revisions which a rollback would revert and,...
Definition: Linker.php:1879
$wgLang
$wgLang
Definition: Setup.php:776
Linker\makeHeadline
static makeHeadline( $level, $attribs, $anchor, $html, $link, $fallbackAnchor=false)
Create a headline for content.
Definition: Linker.php:1777
Linker\tocLineEnd
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1690
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:2203
$title
$title
Definition: testCompression.php:38
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:1135
Linker\makeCommentLink
static makeCommentLink(LinkTarget $linkTarget, $text, $wikiId=null, $options=[])
Generates a link to the given LinkTarget.
Definition: Linker.php:1438
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:1798
Revision\getTitle
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:565
$wgShowRollbackEditCount
$wgShowRollbackEditCount
The $wgShowRollbackEditCount variable is used to show how many edits can be rolled back.
Definition: DefaultSettings.php:3567
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:621
Linker\blockLink
static blockLink( $userId, $userText)
Definition: Linker.php:1060
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:72
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:1561
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:57
Linker\userToolLinksRedContribs
static userToolLinksRedContribs( $userId, $userText, $edits=null, $useParentheses=true)
Alias for userToolLinks( $userId, $userText, true );.
Definition: Linker.php:1026
Revision\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:723
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:2133
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:714
Linker\formatRevisionSize
static formatRevisionSize( $size)
Definition: Linker.php:1625
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:451
DummyLinker
Definition: DummyLinker.php:6
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:284
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:915
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:2049
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
$context
$context
Definition: load.php:43
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:1183
Linker\tooltip
static tooltip( $name, $options=null)
Returns raw bits of HTML, use titleAttrib()
Definition: Linker.php:2250
$wgMiserMode
$wgMiserMode
Disable database-intensive features.
Definition: DefaultSettings.php:2292
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:1612
Linker\tocUnindent
static tocUnindent( $level)
Finish one or more sublevels on the Table of Contents.
Definition: Linker.php:1651
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:2181
$wgEnableUploads
$wgEnableUploads
Allow users to upload files.
Definition: DefaultSettings.php:429
NS_USER
const NS_USER
Definition: Defines.php:71
Revision\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Definition: Revision.php:663
Linker\normalizeSubpageLink
static normalizeSubpageLink( $contextTitle, $target, &$text)
Definition: Linker.php:1468
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:1054
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:308
$wgUploadMissingFileUrl
$wgUploadMissingFileUrl
Point the upload link for missing files to an external URL, as with $wgUploadNavigationUrl.
Definition: DefaultSettings.php:922
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:2097
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
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:1941
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 See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
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
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:7303
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:37