MediaWiki  master
Linker.php
Go to the documentation of this file.
1 <?php
27 use Wikimedia\IPUtils;
28 
38 class Linker {
42  public const TOOL_LINKS_NOBLOCK = 1;
43  public const TOOL_LINKS_EMAIL = 2;
44 
87  public static function link(
88  $target, $html = null, $customAttribs = [], $query = [], $options = []
89  ) {
90  if ( !$target instanceof LinkTarget ) {
91  wfWarn( __METHOD__ . ': Requires $target to be a LinkTarget object.', 2 );
92  return "<!-- ERROR -->$html";
93  }
94 
95  $services = MediaWikiServices::getInstance();
96  $options = (array)$options;
97  if ( $options ) {
98  // Custom options, create new LinkRenderer
99  $linkRenderer = $services->getLinkRendererFactory()
100  ->createFromLegacyOptions( $options );
101  } else {
102  $linkRenderer = $services->getLinkRenderer();
103  }
104 
105  if ( $html !== null ) {
106  $text = new HtmlArmor( $html );
107  } else {
108  $text = null;
109  }
110 
111  if ( in_array( 'known', $options, true ) ) {
112  return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
113  }
114 
115  if ( in_array( 'broken', $options, true ) ) {
116  return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
117  }
118 
119  if ( in_array( 'noclasses', $options, true ) ) {
120  return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query );
121  }
122 
123  return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
124  }
125 
139  public static function linkKnown(
140  $target, $html = null, $customAttribs = [],
141  $query = [], $options = [ 'known' ]
142  ) {
143  return self::link( $target, $html, $customAttribs, $query, $options );
144  }
145 
161  public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
162  $nt = Title::newFromLinkTarget( $nt );
163  $ret = "<a class=\"mw-selflink selflink\">{$prefix}{$html}</a>{$trail}";
164  if ( !Hooks::runner()->onSelfLinkBegin( $nt, $html, $trail, $prefix, $ret ) ) {
165  return $ret;
166  }
167 
168  if ( $html == '' ) {
169  $html = htmlspecialchars( $nt->getPrefixedText() );
170  }
171  list( $inside, $trail ) = self::splitTrail( $trail );
172  return "<a class=\"mw-selflink selflink\">{$prefix}{$html}{$inside}</a>{$trail}";
173  }
174 
185  public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
186  // First we check whether the namespace exists or not.
187  if ( MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $namespace ) ) {
188  if ( $namespace == NS_MAIN ) {
189  $name = $context->msg( 'blanknamespace' )->text();
190  } else {
191  $name = MediaWikiServices::getInstance()->getContentLanguage()->
192  getFormattedNsText( $namespace );
193  }
194  return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
195  }
196 
197  return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
198  }
199 
206  public static function normaliseSpecialPage( LinkTarget $target ) {
207  wfDeprecated( __METHOD__, '1.35' );
208  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
209  return $linkRenderer->normalizeTarget( $target );
210  }
211 
220  private static function fnamePart( $url ) {
221  $basename = strrchr( $url, '/' );
222  if ( $basename === false ) {
223  $basename = $url;
224  } else {
225  $basename = substr( $basename, 1 );
226  }
227  return $basename;
228  }
229 
240  public static function makeExternalImage( $url, $alt = '' ) {
241  if ( $alt == '' ) {
242  $alt = self::fnamePart( $url );
243  }
244  $img = '';
245  $success = Hooks::runner()->onLinkerMakeExternalImage( $url, $alt, $img );
246  if ( !$success ) {
247  wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
248  . "with url {$url} and alt text {$alt} to {$img}" );
249  return $img;
250  }
251  return Html::element( 'img',
252  [
253  'src' => $url,
254  'alt' => $alt
255  ]
256  );
257  }
258 
296  public static function makeImageLink( Parser $parser, LinkTarget $title,
297  $file, $frameParams = [], $handlerParams = [], $time = false,
298  $query = "", $widthOption = null
299  ) {
301  $res = null;
302  $dummy = new DummyLinker;
303  if ( !Hooks::runner()->onImageBeforeProduceHTML( $dummy, $title,
304  $file, $frameParams, $handlerParams, $time, $res,
305  $parser, $query, $widthOption )
306  ) {
307  return $res;
308  }
309 
310  if ( $file && !$file->allowInlineDisplay() ) {
311  wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display" );
312  return self::link( $title );
313  }
314 
315  // Clean up parameters
316  $page = $handlerParams['page'] ?? false;
317  if ( !isset( $frameParams['align'] ) ) {
318  $frameParams['align'] = '';
319  }
320  if ( !isset( $frameParams['alt'] ) ) {
321  $frameParams['alt'] = '';
322  }
323  if ( !isset( $frameParams['title'] ) ) {
324  $frameParams['title'] = '';
325  }
326  if ( !isset( $frameParams['class'] ) ) {
327  $frameParams['class'] = '';
328  }
329 
330  $services = MediaWikiServices::getInstance();
331  $enableLegacyMediaDOM = $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' );
332 
333  $classes = [];
334  if ( !isset( $handlerParams['width'] ) ) {
335  $classes[] = 'mw-default-size';
336  }
337 
338  $prefix = $postfix = '';
339 
340  if ( $enableLegacyMediaDOM ) {
341  if ( $frameParams['align'] == 'center' ) {
342  $prefix = '<div class="center">';
343  $postfix = '</div>';
344  $frameParams['align'] = 'none';
345  }
346  }
347 
348  if ( $file && !isset( $handlerParams['width'] ) ) {
349  if ( isset( $handlerParams['height'] ) && $file->isVectorized() ) {
350  // If its a vector image, and user only specifies height
351  // we don't want it to be limited by its "normal" width.
352  global $wgSVGMaxSize;
353  $handlerParams['width'] = $wgSVGMaxSize;
354  } else {
355  $handlerParams['width'] = $file->getWidth( $page );
356  }
357 
358  if ( isset( $frameParams['thumbnail'] )
359  || isset( $frameParams['manualthumb'] )
360  || isset( $frameParams['framed'] )
361  || isset( $frameParams['frameless'] )
362  || !$handlerParams['width']
363  ) {
365 
366  if ( $widthOption === null || !isset( $wgThumbLimits[$widthOption] ) ) {
367  $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
368  $widthOption = $userOptionsLookup->getDefaultOption( 'thumbsize' );
369  }
370 
371  // Reduce width for upright images when parameter 'upright' is used
372  if ( isset( $frameParams['upright'] ) && $frameParams['upright'] == 0 ) {
373  $frameParams['upright'] = $wgThumbUpright;
374  }
375 
376  // For caching health: If width scaled down due to upright
377  // parameter, round to full __0 pixel to avoid the creation of a
378  // lot of odd thumbs.
379  $prefWidth = isset( $frameParams['upright'] ) ?
380  round( $wgThumbLimits[$widthOption] * $frameParams['upright'], -1 ) :
381  $wgThumbLimits[$widthOption];
382 
383  // Use width which is smaller: real image width or user preference width
384  // Unless image is scalable vector.
385  if ( !isset( $handlerParams['height'] ) && ( $handlerParams['width'] <= 0 ||
386  $prefWidth < $handlerParams['width'] || $file->isVectorized() ) ) {
387  $handlerParams['width'] = $prefWidth;
388  }
389  }
390  }
391 
392  if ( isset( $frameParams['thumbnail'] ) || isset( $frameParams['manualthumb'] )
393  || isset( $frameParams['framed'] )
394  ) {
395  if ( $enableLegacyMediaDOM ) {
396  // This is no longer needed in our new media output, since the
397  // default styling in content.media.less takes care of it;
398  // see T269704.
399 
400  # Create a thumbnail. Alignment depends on the writing direction of
401  # the page content language (right-aligned for LTR languages,
402  # left-aligned for RTL languages)
403  # If a thumbnail width has not been provided, it is set
404  # to the default user option as specified in Language*.php
405  if ( $frameParams['align'] == '' ) {
406  $frameParams['align'] = $parser->getTargetLanguage()->alignEnd();
407  }
408  }
409  return $prefix .
410  self::makeThumbLink2( $title, $file, $frameParams, $handlerParams, $time, $query, $classes ) .
411  $postfix;
412  }
413 
414  switch ( $file ? $file->getMediaType() : '' ) {
415  case 'AUDIO':
416  $rdfaType = 'mw:Audio';
417  break;
418  case 'VIDEO':
419  $rdfaType = 'mw:Video';
420  break;
421  default:
422  $rdfaType = 'mw:Image';
423  }
424 
425  if ( $file && isset( $frameParams['frameless'] ) ) {
426  $rdfaType .= '/Frameless';
427  $srcWidth = $file->getWidth( $page );
428  # For "frameless" option: do not present an image bigger than the
429  # source (for bitmap-style images). This is the same behavior as the
430  # "thumb" option does it already.
431  if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) {
432  $handlerParams['width'] = $srcWidth;
433  }
434  }
435 
436  if ( $file && isset( $handlerParams['width'] ) ) {
437  # Create a resized image, without the additional thumbnail features
438  $thumb = $file->transform( $handlerParams );
439  } else {
440  $thumb = false;
441  }
442 
443  if ( !$thumb ) {
444  $rdfaType = 'mw:Error ' . $rdfaType;
445  $label = '';
446  if ( $enableLegacyMediaDOM ) {
447  // This is the information for tooltips for inline images which
448  // Parsoid stores in data-mw. See T273014
449  $label = $frameParams['title'];
450  }
452  $title, $label, '', '', '', (bool)$time, $handlerParams
453  );
454  } else {
455  self::processResponsiveImages( $file, $thumb, $handlerParams );
456  $params = [
457  'alt' => $frameParams['alt'],
458  'title' => $frameParams['title'],
459  ];
460  if ( $enableLegacyMediaDOM ) {
461  $params += [
462  'valign' => $frameParams['valign'] ?? false,
463  'img-class' => $frameParams['class'],
464  ];
465  if ( isset( $frameParams['border'] ) ) {
466  $params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
467  }
468  }
469  $params = self::getImageLinkMTOParams( $frameParams, $query, $parser ) + $params;
470  $s = $thumb->toHtml( $params );
471  }
472 
473  if ( $enableLegacyMediaDOM ) {
474  if ( $frameParams['align'] != '' ) {
476  'div',
477  [ 'class' => 'float' . $frameParams['align'] ],
478  $s
479  );
480  }
481  return str_replace( "\n", ' ', $prefix . $s . $postfix );
482  }
483 
484  $wrapper = 'span';
485  $caption = '';
486 
487  if ( $frameParams['align'] != '' ) {
488  $wrapper = 'figure';
489  // Possible values: mw-halign-left mw-halign-center mw-halign-right mw-halign-none
490  $classes[] = "mw-halign-{$frameParams['align']}";
491  $caption = Html::rawElement(
492  'figcaption', [], $frameParams['caption'] ?? ''
493  );
494  } elseif ( isset( $frameParams['valign'] ) ) {
495  // Possible values: mw-valign-middle mw-valign-baseline mw-valign-sub
496  // mw-valign-super mw-valign-top mw-valign-text-top mw-valign-bottom
497  // mw-valign-text-bottom
498  $classes[] = "mw-valign-{$frameParams['valign']}";
499  }
500 
501  if ( isset( $frameParams['border'] ) ) {
502  $classes[] = 'mw-image-border';
503  }
504 
505  if ( isset( $frameParams['class'] ) ) {
506  $classes[] = $frameParams['class'];
507  }
508 
509  $attribs = [
510  'class' => $classes,
511  'typeof' => $rdfaType,
512  ];
513 
514  $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
515 
516  return str_replace( "\n", ' ', $s );
517  }
518 
527  private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
528  $mtoParams = [];
529  if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
530  $mtoParams['custom-url-link'] = $frameParams['link-url'];
531  if ( isset( $frameParams['link-target'] ) ) {
532  $mtoParams['custom-target-link'] = $frameParams['link-target'];
533  }
534  if ( $parser ) {
535  $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
536  foreach ( $extLinkAttrs as $name => $val ) {
537  // Currently could include 'rel' and 'target'
538  $mtoParams['parser-extlink-' . $name] = $val;
539  }
540  }
541  } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
542  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
543  $mtoParams['custom-title-link'] = Title::newFromLinkTarget(
544  $linkRenderer->normalizeTarget( $frameParams['link-title'] )
545  );
546  } elseif ( !empty( $frameParams['no-link'] ) ) {
547  // No link
548  } else {
549  $mtoParams['desc-link'] = true;
550  $mtoParams['desc-query'] = $query;
551  }
552  return $mtoParams;
553  }
554 
567  public static function makeThumbLinkObj(
568  LinkTarget $title, $file, $label = '', $alt = '', $align = null,
569  $params = [], $framed = false, $manualthumb = ""
570  ) {
571  $frameParams = [
572  'alt' => $alt,
573  'caption' => $label,
574  'align' => $align
575  ];
576  if ( $framed ) {
577  $frameParams['framed'] = true;
578  }
579  if ( $manualthumb ) {
580  $frameParams['manualthumb'] = $manualthumb;
581  }
582  $classes = [ 'mw-default-size' ];
583  return self::makeThumbLink2(
584  $title, $file, $frameParams, $params, false, '', $classes
585  );
586  }
587 
598  public static function makeThumbLink2(
599  LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
600  $time = false, $query = "", array $classes = []
601  ) {
602  $exists = $file && $file->exists();
603 
604  $services = MediaWikiServices::getInstance();
605  $enableLegacyMediaDOM = $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' );
606 
607  $page = $handlerParams['page'] ?? false;
608  if ( !isset( $frameParams['align'] ) ) {
609  $frameParams['align'] = '';
610  if ( $enableLegacyMediaDOM ) {
611  $frameParams['align'] = 'right';
612  }
613  }
614  if ( !isset( $frameParams['alt'] ) ) {
615  $frameParams['alt'] = '';
616  }
617  if ( !isset( $frameParams['title'] ) ) {
618  $frameParams['title'] = '';
619  }
620  if ( !isset( $frameParams['caption'] ) ) {
621  $frameParams['caption'] = '';
622  }
623 
624  if ( empty( $handlerParams['width'] ) ) {
625  // Reduce width for upright images when parameter 'upright' is used
626  $handlerParams['width'] = isset( $frameParams['upright'] ) ? 130 : 180;
627  }
628 
629  $thumb = false;
630  $noscale = false;
631  $manualthumb = false;
632  $rdfaType = null;
633 
634  if ( !$exists ) {
635  $outerWidth = $handlerParams['width'] + 2;
636  } else {
637  if ( isset( $frameParams['manualthumb'] ) ) {
638  # Use manually specified thumbnail
639  $manual_title = Title::makeTitleSafe( NS_FILE, $frameParams['manualthumb'] );
640  if ( $manual_title ) {
641  $manual_img = $services->getRepoGroup()
642  ->findFile( $manual_title );
643  if ( $manual_img ) {
644  $thumb = $manual_img->getUnscaledThumb( $handlerParams );
645  $manualthumb = true;
646  } else {
647  $exists = false;
648  }
649  }
650  } elseif ( isset( $frameParams['framed'] ) ) {
651  // Use image dimensions, don't scale
652  $thumb = $file->getUnscaledThumb( $handlerParams );
653  $noscale = true;
654  $rdfaType = '/Frame';
655  } else {
656  # Do not present an image bigger than the source, for bitmap-style images
657  # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
658  $srcWidth = $file->getWidth( $page );
659  if ( $srcWidth && !$file->mustRender() && $handlerParams['width'] > $srcWidth ) {
660  $handlerParams['width'] = $srcWidth;
661  }
662  $thumb = $file->transform( $handlerParams );
663  }
664 
665  if ( $thumb ) {
666  $outerWidth = $thumb->getWidth() + 2;
667  } else {
668  $outerWidth = $handlerParams['width'] + 2;
669  }
670  }
671 
672  $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
673 
674  if ( $enableLegacyMediaDOM && $page ) {
675  # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
676  # So we don't need to pass it here in $query. However, the URL for the
677  # zoom icon still needs it, so we make a unique query for it. See T16771
678  $url = wfAppendQuery( $url, [ 'page' => $page ] );
679  }
680 
681  if ( $manualthumb
682  && !isset( $frameParams['link-title'] )
683  && !isset( $frameParams['link-url'] )
684  && !isset( $frameParams['no-link'] ) ) {
685  $frameParams['link-url'] = $url;
686  }
687 
688  if ( $frameParams['align'] != '' ) {
689  // Possible values: mw-halign-left mw-halign-center mw-halign-right mw-halign-none
690  $classes[] = "mw-halign-{$frameParams['align']}";
691  }
692 
693  if ( isset( $frameParams['class'] ) ) {
694  $classes[] = $frameParams['class'];
695  }
696 
697  $s = '';
698 
699  if ( $enableLegacyMediaDOM ) {
700  $s .= "<div class=\"thumb t{$frameParams['align']}\">"
701  . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
702  }
703 
704  if ( !$exists ) {
705  $label = '';
706  if ( $enableLegacyMediaDOM ) {
707  // This is the information for tooltips for inline images which
708  // Parsoid stores in data-mw. See T273014
709  $label = $frameParams['title'];
710  }
712  $title, $label, '', '', '', (bool)$time, $handlerParams
713  );
714  $zoomIcon = '';
715  } elseif ( !$thumb ) {
716  // FIXME(T169975): Add "mw:Error"?
717  $s .= wfMessage( 'thumbnail_error', '' )->escaped();
718  $zoomIcon = '';
719  } else {
720  if ( !$noscale && !$manualthumb ) {
721  self::processResponsiveImages( $file, $thumb, $handlerParams );
722  }
723  $params = [
724  'alt' => $frameParams['alt'],
725  'title' => $frameParams['title'],
726  ];
727  if ( $enableLegacyMediaDOM ) {
728  $params += [
729  'img-class' => ( isset( $frameParams['class'] ) && $frameParams['class'] !== ''
730  ? $frameParams['class'] . ' '
731  : '' ) . 'thumbimage'
732  ];
733  }
734  $params = self::getImageLinkMTOParams( $frameParams, $query ) + $params;
735  $s .= $thumb->toHtml( $params );
736  if ( isset( $frameParams['framed'] ) ) {
737  $zoomIcon = "";
738  } else {
739  $zoomIcon = Html::rawElement( 'div', [ 'class' => 'magnify' ],
740  Html::rawElement( 'a', [
741  'href' => $url,
742  'class' => 'internal',
743  'title' => wfMessage( 'thumbnail-more' )->text() ],
744  "" ) );
745  }
746  }
747 
748  if ( $enableLegacyMediaDOM ) {
749  $s .= ' <div class="thumbcaption">' . $zoomIcon . $frameParams['caption'] . "</div></div></div>";
750  return str_replace( "\n", ' ', $s );
751  }
752 
753  $s .= Html::rawElement(
754  'figcaption', [], $frameParams['caption'] ?? ''
755  );
756 
757  $rdfaType = $rdfaType ?: '/Thumb';
758 
759  switch ( $file ? $file->getMediaType() : '' ) {
760  case 'AUDIO':
761  $rdfaType = 'mw:Audio' . $rdfaType;
762  break;
763  case 'VIDEO':
764  $rdfaType = 'mw:Video' . $rdfaType;
765  break;
766  default:
767  $rdfaType = 'mw:Image' . $rdfaType;
768  }
769 
770  if ( !$exists ) {
771  $rdfaType = 'mw:Error ' . $rdfaType;
772  }
773 
774  $attribs = [
775  'class' => $classes,
776  'typeof' => $rdfaType,
777  ];
778 
779  $s = Html::rawElement( 'figure', $attribs, $s );
780 
781  return str_replace( "\n", ' ', $s );
782  }
783 
792  public static function processResponsiveImages( $file, $thumb, $hp ) {
793  global $wgResponsiveImages;
794  if ( $wgResponsiveImages && $thumb && !$thumb->isError() ) {
795  $hp15 = $hp;
796  $hp15['width'] = round( $hp['width'] * 1.5 );
797  $hp20 = $hp;
798  $hp20['width'] = $hp['width'] * 2;
799  if ( isset( $hp['height'] ) ) {
800  $hp15['height'] = round( $hp['height'] * 1.5 );
801  $hp20['height'] = $hp['height'] * 2;
802  }
803 
804  $thumb15 = $file->transform( $hp15 );
805  $thumb20 = $file->transform( $hp20 );
806  if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
807  $thumb->responsiveUrls['1.5'] = $thumb15->getUrl();
808  }
809  if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
810  $thumb->responsiveUrls['2'] = $thumb20->getUrl();
811  }
812  }
813  }
814 
828  public static function makeBrokenImageLinkObj(
829  $title, $label = '', $query = '', $unused1 = '', $unused2 = '',
830  $time = false, array $handlerParams = []
831  ) {
832  if ( !$title instanceof LinkTarget ) {
833  wfWarn( __METHOD__ . ': Requires $title to be a LinkTarget object.' );
834  return "<!-- ERROR -->" . htmlspecialchars( $label );
835  }
836 
838 
840  if ( $label == '' ) {
841  $label = $title->getPrefixedText();
842  }
843 
844  $html = Html::element( 'span', [
845  // These data attributes are used to dynamically size the span, see T273013
846  'data-width' => $handlerParams['width'] ?? null,
847  'data-height' => $handlerParams['height'] ?? null,
848  ], $label );
849 
850  $services = MediaWikiServices::getInstance();
851  if ( $services->getMainConfig()->get( 'ParserEnableLegacyMediaDOM' ) ) {
852  $html = htmlspecialchars( $label );
853  }
854 
855  $repoGroup = $services->getRepoGroup();
856  $currentExists = $time
857  && $repoGroup->findFile( $title ) !== false;
858 
860  && !$currentExists
861  ) {
862  if ( $repoGroup->getLocalRepo()->checkRedirect( $title ) ) {
863  // We already know it's a redirect, so mark it accordingly
864  return self::link(
865  $title,
866  $html,
867  [ 'class' => 'mw-redirect' ],
868  wfCgiToArray( $query ),
869  [ 'known', 'noclasses' ]
870  );
871  }
872  return Html::rawElement( 'a', [
873  'href' => self::getUploadUrl( $title, $query ),
874  'class' => 'new',
875  'title' => $title->getPrefixedText()
876  ], $html );
877  }
878  return self::link(
879  $title,
880  $html,
881  [],
882  wfCgiToArray( $query ),
883  [ 'known', 'noclasses' ]
884  );
885  }
886 
895  protected static function getUploadUrl( $destFile, $query = '' ) {
897  $q = 'wpDestFile=' . Title::castFromLinkTarget( $destFile )->getPartialURL();
898  if ( $query != '' ) {
899  $q .= '&' . $query;
900  }
901 
902  if ( $wgUploadMissingFileUrl ) {
904  }
905 
906  if ( $wgUploadNavigationUrl ) {
908  }
909 
910  $upload = SpecialPage::getTitleFor( 'Upload' );
911 
912  return $upload->getLocalURL( $q );
913  }
914 
924  public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
925  $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
926  $title, [ 'time' => $time ]
927  );
928  return self::makeMediaLinkFile( $title, $img, $html );
929  }
930 
943  public static function makeMediaLinkFile( LinkTarget $title, $file, $html = '' ) {
944  if ( $file && $file->exists() ) {
945  $url = $file->getUrl();
946  $class = 'internal';
947  } else {
948  $url = self::getUploadUrl( $title );
949  $class = 'new';
950  }
951 
952  $alt = $title->getText();
953  if ( $html == '' ) {
954  $html = $alt;
955  }
956 
957  $ret = '';
958  $attribs = [
959  'href' => $url,
960  'class' => $class,
961  'title' => $alt
962  ];
963 
964  if ( !Hooks::runner()->onLinkerMakeMediaLinkFile(
965  Title::castFromLinkTarget( $title ), $file, $html, $attribs, $ret )
966  ) {
967  wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
968  . "with url {$url} and text {$html} to {$ret}" );
969  return $ret;
970  }
971 
972  return Html::rawElement( 'a', $attribs, $html );
973  }
974 
985  public static function specialLink( $name, $key = '' ) {
986  if ( $key == '' ) {
987  $key = strtolower( $name );
988  }
989 
990  return self::linkKnown( SpecialPage::getTitleFor( $name ), wfMessage( $key )->escaped() );
991  }
992 
1011  public static function makeExternalLink( $url, $text, $escape = true,
1012  $linktype = '', $attribs = [], $title = null
1013  ) {
1014  global $wgTitle;
1015  $class = "external";
1016  if ( $linktype ) {
1017  $class .= " $linktype";
1018  }
1019  if ( isset( $attribs['class'] ) && $attribs['class'] ) {
1020  $class .= " {$attribs['class']}";
1021  }
1022  $attribs['class'] = $class;
1023 
1024  if ( $escape ) {
1025  $text = htmlspecialchars( $text );
1026  }
1027 
1028  if ( !$title ) {
1029  $title = $wgTitle;
1030  }
1031  $newRel = Parser::getExternalLinkRel( $url, $title );
1032  if ( !isset( $attribs['rel'] ) || $attribs['rel'] === '' ) {
1033  $attribs['rel'] = $newRel;
1034  } elseif ( $newRel !== '' ) {
1035  // Merge the rel attributes.
1036  $newRels = explode( ' ', $newRel );
1037  $oldRels = explode( ' ', $attribs['rel'] );
1038  $combined = array_unique( array_merge( $newRels, $oldRels ) );
1039  $attribs['rel'] = implode( ' ', $combined );
1040  }
1041  $link = '';
1042  $success = Hooks::runner()->onLinkerMakeExternalLink(
1043  $url, $text, $link, $attribs, $linktype );
1044  if ( !$success ) {
1045  wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
1046  . "with url {$url} and text {$text} to {$link}" );
1047  return $link;
1048  }
1049  $attribs['href'] = $url;
1050  return Html::rawElement( 'a', $attribs, $text );
1051  }
1052 
1064  public static function userLink( $userId, $userName, $altUserName = false ) {
1065  if ( $userName === '' || $userName === false || $userName === null ) {
1066  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1067  'that need to be fixed?' );
1068  return wfMessage( 'empty-username' )->parse();
1069  }
1070 
1071  $classes = 'mw-userlink';
1072  $page = null;
1073  if ( $userId == 0 ) {
1074  $page = ExternalUserNames::getUserLinkTitle( $userName );
1075 
1076  if ( ExternalUserNames::isExternal( $userName ) ) {
1077  $classes .= ' mw-extuserlink';
1078  } elseif ( $altUserName === false ) {
1079  $altUserName = IPUtils::prettifyIP( $userName );
1080  }
1081  $classes .= ' mw-anonuserlink'; // Separate link class for anons (T45179)
1082  } else {
1083  $page = TitleValue::tryNew( NS_USER, strtr( $userName, ' ', '_' ) );
1084  }
1085 
1086  // Wrap the output with <bdi> tags for directionality isolation
1087  $linkText =
1088  '<bdi>' . htmlspecialchars( $altUserName !== false ? $altUserName : $userName ) . '</bdi>';
1089 
1090  return $page
1091  ? self::link( $page, $linkText, [ 'class' => $classes ] )
1092  : Html::rawElement( 'span', [ 'class' => $classes ], $linkText );
1093  }
1094 
1109  public static function userToolLinks(
1110  $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null,
1111  $useParentheses = true
1112  ) {
1113  if ( $userText === '' ) {
1114  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1115  'that need to be fixed?' );
1116  return ' ' . wfMessage( 'empty-username' )->parse();
1117  }
1118 
1119  global $wgDisableAnonTalk, $wgLang;
1120  $talkable = !( $wgDisableAnonTalk && $userId == 0 );
1121  $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
1122  $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1123 
1124  if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1125  // No tools for an external user
1126  return '';
1127  }
1128 
1129  $items = [];
1130  if ( $talkable ) {
1131  $items[] = self::userTalkLink( $userId, $userText );
1132  }
1133  if ( $userId ) {
1134  // check if the user has an edit
1135  $attribs = [];
1136  $attribs['class'] = 'mw-usertoollinks-contribs';
1137  if ( $redContribsWhenNoEdits ) {
1138  if ( intval( $edits ) === 0 && $edits !== 0 ) {
1139  $user = User::newFromId( $userId );
1140  $edits = $user->getEditCount();
1141  }
1142  if ( $edits === 0 ) {
1143  $attribs['class'] .= ' new';
1144  }
1145  }
1146  $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
1147 
1148  $items[] = self::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
1149  }
1150  $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed( 'block' );
1151  if ( $blockable && $userCanBlock ) {
1152  $items[] = self::blockLink( $userId, $userText );
1153  }
1154 
1155  $user = RequestContext::getMain()->getUser();
1156  if ( $addEmailLink && $user->canSendEmail() ) {
1157  $items[] = self::emailLink( $userId, $userText );
1158  }
1159 
1160  Hooks::runner()->onUserToolLinksEdit( $userId, $userText, $items );
1161 
1162  if ( !$items ) {
1163  return '';
1164  }
1165 
1166  if ( $useParentheses ) {
1167  return wfMessage( 'word-separator' )->escaped()
1168  . '<span class="mw-usertoollinks">'
1169  . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1170  . '</span>';
1171  }
1172 
1173  $tools = [];
1174  foreach ( $items as $tool ) {
1175  $tools[] = Html::rawElement( 'span', [], $tool );
1176  }
1177  return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1178  implode( ' ', $tools ) . '</span>';
1179  }
1180 
1190  public static function userToolLinksRedContribs(
1191  $userId, $userText, $edits = null, $useParentheses = true
1192  ) {
1193  return self::userToolLinks( $userId, $userText, true, 0, $edits, $useParentheses );
1194  }
1195 
1202  public static function userTalkLink( $userId, $userText ) {
1203  if ( $userText === '' ) {
1204  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1205  'that need to be fixed?' );
1206  return wfMessage( 'empty-username' )->parse();
1207  }
1208 
1209  $userTalkPage = TitleValue::tryNew( NS_USER_TALK, strtr( $userText, ' ', '_' ) );
1210  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-talk' ];
1211  $linkText = wfMessage( 'talkpagelinktext' )->escaped();
1212 
1213  return $userTalkPage
1214  ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1215  : Html::rawElement( 'span', $moreLinkAttribs, $linkText );
1216  }
1217 
1224  public static function blockLink( $userId, $userText ) {
1225  if ( $userText === '' ) {
1226  wfDebug( __METHOD__ . ' received an empty username. Are there database errors ' .
1227  'that need to be fixed?' );
1228  return wfMessage( 'empty-username' )->parse();
1229  }
1230 
1231  $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
1232  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-block' ];
1233 
1234  return self::link( $blockPage,
1235  wfMessage( 'blocklink' )->escaped(),
1236  $moreLinkAttribs
1237  );
1238  }
1239 
1245  public static function emailLink( $userId, $userText ) {
1246  if ( $userText === '' ) {
1247  wfLogWarning( __METHOD__ . ' received an empty username. Are there database errors ' .
1248  'that need to be fixed?' );
1249  return wfMessage( 'empty-username' )->parse();
1250  }
1251 
1252  $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
1253  $moreLinkAttribs = [ 'class' => 'mw-usertoollinks-mail' ];
1254  return self::link( $emailPage,
1255  wfMessage( 'emaillink' )->escaped(),
1256  $moreLinkAttribs
1257  );
1258  }
1259 
1271  public static function revUserLink( RevisionRecord $revRecord, $isPublic = false ) {
1272  // TODO inject authority
1273  $authority = RequestContext::getMain()->getAuthority();
1274 
1275  if ( $revRecord->isDeleted( RevisionRecord::DELETED_USER ) && $isPublic ) {
1276  $link = wfMessage( 'rev-deleted-user' )->escaped();
1277  } elseif ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) ) {
1278  $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority );
1279  $link = self::userLink(
1280  $revUser ? $revUser->getId() : 0,
1281  $revUser ? $revUser->getName() : ''
1282  );
1283  } else {
1284  $link = wfMessage( 'rev-deleted-user' )->escaped();
1285  }
1286  if ( $revRecord->isDeleted( RevisionRecord::DELETED_USER ) ) {
1287  $class = self::getRevisionDeletedClass( $revRecord );
1288  return '<span class="' . $class . '">' . $link . '</span>';
1289  }
1290  return $link;
1291  }
1292 
1299  public static function getRevisionDeletedClass( RevisionRecord $revisionRecord ): string {
1300  $class = 'history-deleted';
1301  if ( $revisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1302  $class .= ' mw-history-suppressed';
1303  }
1304  return $class;
1305  }
1306 
1319  public static function revUserTools(
1320  RevisionRecord $revRecord,
1321  $isPublic = false,
1322  $useParentheses = true
1323  ) {
1324  // TODO inject authority
1325  $authority = RequestContext::getMain()->getAuthority();
1326 
1327  if ( $revRecord->userCan( RevisionRecord::DELETED_USER, $authority ) &&
1328  ( !$revRecord->isDeleted( RevisionRecord::DELETED_USER ) || !$isPublic )
1329  ) {
1330  $revUser = $revRecord->getUser( RevisionRecord::FOR_THIS_USER, $authority );
1331  $userId = $revUser ? $revUser->getId() : 0;
1332  $userText = $revUser ? $revUser->getName() : '';
1333 
1334  if ( $userId || $userText !== '' ) {
1335  $link = self::userLink( $userId, $userText )
1336  . self::userToolLinks( $userId, $userText, false, 0, null,
1337  $useParentheses );
1338  }
1339  }
1340 
1341  if ( !isset( $link ) ) {
1342  $link = wfMessage( 'rev-deleted-user' )->escaped();
1343  }
1344 
1345  if ( $revRecord->isDeleted( RevisionRecord::DELETED_USER ) ) {
1346  $class = self::getRevisionDeletedClass( $revRecord );
1347  return ' <span class="' . $class . ' mw-userlink">' . $link . '</span>';
1348  }
1349  return $link;
1350  }
1351 
1372  public static function formatComment(
1373  $comment, $title = null, $local = false, $wikiId = null
1374  ) {
1375  $formatter = MediaWikiServices::getInstance()->getCommentFormatter();
1376  return $formatter->format( $comment, $title, $local, $wikiId );
1377  }
1378 
1398  public static function formatLinksInComment(
1399  $comment, $title = null, $local = false, $wikiId = null
1400  ) {
1401  $formatter = MediaWikiServices::getInstance()->getCommentFormatter();
1402  return $formatter->formatLinksUnsafe( $comment, $title, $local, $wikiId );
1403  }
1404 
1411  public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1412  # Valid link forms:
1413  # Foobar -- normal
1414  # :Foobar -- override special treatment of prefix (images, language links)
1415  # /Foobar -- convert to CurrentPage/Foobar
1416  # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1417  # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1418  # ../Foobar -- convert to CurrentPage/Foobar,
1419  # (from CurrentPage/CurrentSubPage)
1420  # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1421  # (from CurrentPage/CurrentSubPage)
1422 
1423  $ret = $target; # default return value is no change
1424 
1425  # Some namespaces don't allow subpages,
1426  # so only perform processing if subpages are allowed
1427  if (
1428  $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1429  hasSubpages( $contextTitle->getNamespace() )
1430  ) {
1431  $hash = strpos( $target, '#' );
1432  if ( $hash !== false ) {
1433  $suffix = substr( $target, $hash );
1434  $target = substr( $target, 0, $hash );
1435  } else {
1436  $suffix = '';
1437  }
1438  # T9425
1439  $target = trim( $target );
1440  $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1441  getPrefixedText( $contextTitle );
1442  # Look at the first character
1443  if ( $target != '' && $target[0] === '/' ) {
1444  # / at end means we don't want the slash to be shown
1445  $m = [];
1446  $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1447  if ( $trailingSlashes ) {
1448  $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1449  } else {
1450  $noslash = substr( $target, 1 );
1451  }
1452 
1453  $ret = $contextPrefixedText . '/' . trim( $noslash ) . $suffix;
1454  if ( $text === '' ) {
1455  $text = $target . $suffix;
1456  } # this might be changed for ugliness reasons
1457  } else {
1458  # check for .. subpage backlinks
1459  $dotdotcount = 0;
1460  $nodotdot = $target;
1461  while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1462  ++$dotdotcount;
1463  $nodotdot = substr( $nodotdot, 3 );
1464  }
1465  if ( $dotdotcount > 0 ) {
1466  $exploded = explode( '/', $contextPrefixedText );
1467  if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1468  $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1469  # / at the end means don't show full path
1470  if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1471  $nodotdot = rtrim( $nodotdot, '/' );
1472  if ( $text === '' ) {
1473  $text = $nodotdot . $suffix;
1474  }
1475  }
1476  $nodotdot = trim( $nodotdot );
1477  if ( $nodotdot != '' ) {
1478  $ret .= '/' . $nodotdot;
1479  }
1480  $ret .= $suffix;
1481  }
1482  }
1483  }
1484  }
1485 
1486  return $ret;
1487  }
1488 
1508  public static function commentBlock(
1509  $comment, $title = null, $local = false, $wikiId = null, $useParentheses = true
1510  ) {
1511  return MediaWikiServices::getInstance()->getCommentFormatter()
1512  ->formatBlock( $comment, $title, $local, $wikiId, $useParentheses );
1513  }
1514 
1530  public static function revComment(
1531  RevisionRecord $revRecord,
1532  $local = false,
1533  $isPublic = false,
1534  $useParentheses = true
1535  ) {
1536  $authority = RequestContext::getMain()->getAuthority();
1537  $formatter = MediaWikiServices::getInstance()->getCommentFormatter();
1538  return $formatter->formatRevision( $revRecord, $authority, $local, $isPublic, $useParentheses );
1539  }
1540 
1546  public static function formatRevisionSize( $size ) {
1547  if ( $size == 0 ) {
1548  $stxt = wfMessage( 'historyempty' )->escaped();
1549  } else {
1550  $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1551  }
1552  return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1553  }
1554 
1561  public static function tocIndent() {
1562  return "\n<ul>\n";
1563  }
1564 
1572  public static function tocUnindent( $level ) {
1573  return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
1574  }
1575 
1587  public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1588  $classes = "toclevel-$level";
1589  if ( $sectionIndex !== false ) {
1590  $classes .= " tocsection-$sectionIndex";
1591  }
1592 
1593  // <li class="$classes"><a href="#$anchor"><span class="tocnumber">
1594  // $tocnumber</span> <span class="toctext">$tocline</span></a>
1595  return Html::openElement( 'li', [ 'class' => $classes ] )
1596  . Html::rawElement( 'a',
1597  [ 'href' => "#$anchor" ],
1598  Html::element( 'span', [ 'class' => 'tocnumber' ], $tocnumber )
1599  . ' '
1600  . Html::rawElement( 'span', [ 'class' => 'toctext' ], $tocline )
1601  );
1602  }
1603 
1611  public static function tocLineEnd() {
1612  return "</li>\n";
1613  }
1614 
1623  public static function tocList( $toc, Language $lang = null ) {
1624  $lang = $lang ?? RequestContext::getMain()->getLanguage();
1625 
1626  $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1627 
1628  return '<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading">'
1629  . Html::element( 'input', [
1630  'type' => 'checkbox',
1631  'role' => 'button',
1632  'id' => 'toctogglecheckbox',
1633  'class' => 'toctogglecheckbox',
1634  'style' => 'display:none',
1635  ] )
1636  . Html::openElement( 'div', [
1637  'class' => 'toctitle',
1638  'lang' => $lang->getHtmlCode(),
1639  'dir' => $lang->getDir(),
1640  ] )
1641  . '<h2 id="mw-toc-heading">' . $title . '</h2>'
1642  . '<span class="toctogglespan">'
1643  . Html::label( '', 'toctogglecheckbox', [
1644  'class' => 'toctogglelabel',
1645  ] )
1646  . '</span>'
1647  . "</div>\n"
1648  . $toc
1649  . "</ul>\n</div>\n";
1650  }
1651 
1660  public static function generateTOC( $tree, Language $lang = null ) {
1661  $toc = '';
1662  $lastLevel = 0;
1663  foreach ( $tree as $section ) {
1664  if ( $section['toclevel'] > $lastLevel ) {
1665  $toc .= self::tocIndent();
1666  } elseif ( $section['toclevel'] < $lastLevel ) {
1667  $toc .= self::tocUnindent(
1668  $lastLevel - $section['toclevel'] );
1669  } else {
1670  $toc .= self::tocLineEnd();
1671  }
1672 
1673  $toc .= self::tocLine( $section['anchor'],
1674  $section['line'], $section['number'],
1675  $section['toclevel'], $section['index'] );
1676  $lastLevel = $section['toclevel'];
1677  }
1678  $toc .= self::tocLineEnd();
1679  return self::tocList( $toc, $lang );
1680  }
1681 
1698  public static function makeHeadline( $level, $attribs, $anchor, $html,
1699  $link, $fallbackAnchor = false
1700  ) {
1701  $anchorEscaped = htmlspecialchars( $anchor );
1702  $fallback = '';
1703  if ( $fallbackAnchor !== false && $fallbackAnchor !== $anchor ) {
1704  $fallbackAnchor = htmlspecialchars( $fallbackAnchor );
1705  $fallback = "<span id=\"$fallbackAnchor\"></span>";
1706  }
1707  return "<h$level$attribs"
1708  . "$fallback<span class=\"mw-headline\" id=\"$anchorEscaped\">$html</span>"
1709  . $link
1710  . "</h$level>";
1711  }
1712 
1719  public static function splitTrail( $trail ) {
1720  $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1721  $inside = '';
1722  if ( $trail !== '' && preg_match( $regex, $trail, $m ) ) {
1723  list( , $inside, $trail ) = $m;
1724  }
1725  return [ $inside, $trail ];
1726  }
1727 
1757  public static function generateRollback(
1758  RevisionRecord $revRecord,
1759  IContextSource $context = null,
1760  $options = [ 'verify' ]
1761  ) {
1762  if ( $context === null ) {
1763  $context = RequestContext::getMain();
1764  }
1765 
1766  $editCount = false;
1767  if ( in_array( 'verify', $options, true ) ) {
1768  $editCount = self::getRollbackEditCount( $revRecord, true );
1769  if ( $editCount === false ) {
1770  return '';
1771  }
1772  }
1773 
1774  $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1775 
1776  // Allow extensions to modify the rollback link.
1777  // Abort further execution if the extension wants full control over the link.
1778  if ( !Hooks::runner()->onLinkerGenerateRollbackLink(
1779  $revRecord, $context, $options, $inner ) ) {
1780  return $inner;
1781  }
1782 
1783  if ( !in_array( 'noBrackets', $options, true ) ) {
1784  $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
1785  }
1786 
1787  if ( MediaWikiServices::getInstance()->getUserOptionsLookup()
1788  ->getBoolOption( $context->getUser(), 'showrollbackconfirmation' )
1789  ) {
1790  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1791  $stats->increment( 'rollbackconfirmation.event.load' );
1792  $context->getOutput()->addModules( 'mediawiki.misc-authed-curate' );
1793  }
1794 
1795  return '<span class="mw-rollback-link">' . $inner . '</span>';
1796  }
1797 
1816  public static function getRollbackEditCount( RevisionRecord $revRecord, $verify ) {
1817  global $wgShowRollbackEditCount;
1818 
1819  if ( !is_int( $wgShowRollbackEditCount ) || !$wgShowRollbackEditCount > 0 ) {
1820  // Nothing has happened, indicate this by returning 'null'
1821  return null;
1822  }
1823 
1824  $dbr = wfGetDB( DB_REPLICA );
1825 
1826  // Up to the value of $wgShowRollbackEditCount revisions are counted
1827  $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
1828  // T270033 Index renaming
1829  $revIndex = $dbr->indexExists( 'revision', 'page_timestamp', __METHOD__ )
1830  ? 'page_timestamp'
1831  : 'rev_page_timestamp';
1832  $res = $dbr->select(
1833  $revQuery['tables'],
1834  [ 'rev_user_text' => $revQuery['fields']['rev_user_text'], 'rev_deleted' ],
1835  [ 'rev_page' => $revRecord->getPageId() ],
1836  __METHOD__,
1837  [
1838  'USE INDEX' => [ 'revision' => $revIndex ],
1839  'ORDER BY' => 'rev_timestamp DESC',
1840  'LIMIT' => $wgShowRollbackEditCount + 1
1841  ],
1842  $revQuery['joins']
1843  );
1844 
1845  $revUser = $revRecord->getUser( RevisionRecord::RAW );
1846  $revUserText = $revUser ? $revUser->getName() : '';
1847 
1848  $editCount = 0;
1849  $moreRevs = false;
1850  foreach ( $res as $row ) {
1851  if ( $row->rev_user_text != $revUserText ) {
1852  if ( $verify &&
1853  ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1854  || $row->rev_deleted & RevisionRecord::DELETED_USER
1855  ) ) {
1856  // If the user or the text of the revision we might rollback
1857  // to is deleted in some way we can't rollback. Similar to
1858  // the sanity checks in WikiPage::commitRollback.
1859  return false;
1860  }
1861  $moreRevs = true;
1862  break;
1863  }
1864  $editCount++;
1865  }
1866 
1867  if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1868  // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1869  // and there weren't any other revisions. That means that the current user is the only
1870  // editor, so we can't rollback
1871  return false;
1872  }
1873  return $editCount;
1874  }
1875 
1890  public static function buildRollbackLink(
1891  RevisionRecord $revRecord,
1892  IContextSource $context = null,
1893  $editCount = false
1894  ) {
1896 
1897  // To config which pages are affected by miser mode
1898  $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
1899 
1900  if ( $context === null ) {
1901  $context = RequestContext::getMain();
1902  }
1903 
1904  $title = $revRecord->getPageAsLinkTarget();
1905  $revUser = $revRecord->getUser();
1906  $revUserText = $revUser ? $revUser->getName() : '';
1907 
1908  $query = [
1909  'action' => 'rollback',
1910  'from' => $revUserText,
1911  'token' => $context->getUser()->getEditToken( 'rollback' ),
1912  ];
1913 
1914  $attrs = [
1915  'data-mw' => 'interface',
1916  'title' => $context->msg( 'tooltip-rollback' )->text()
1917  ];
1918 
1919  $options = [ 'known', 'noclasses' ];
1920 
1921  if ( $context->getRequest()->getBool( 'bot' ) ) {
1922  // T17999
1923  $query['hidediff'] = '1';
1924  $query['bot'] = '1';
1925  }
1926 
1927  $disableRollbackEditCount = false;
1928  if ( $wgMiserMode ) {
1929  foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1930  if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1931  $disableRollbackEditCount = true;
1932  break;
1933  }
1934  }
1935  }
1936 
1937  if ( !$disableRollbackEditCount
1938  && is_int( $wgShowRollbackEditCount )
1940  ) {
1941  if ( !is_numeric( $editCount ) ) {
1942  $editCount = self::getRollbackEditCount( $revRecord, false );
1943  }
1944 
1945  if ( $editCount > $wgShowRollbackEditCount ) {
1946  $html = $context->msg( 'rollbacklinkcount-morethan' )
1947  ->numParams( $wgShowRollbackEditCount )->parse();
1948  } else {
1949  $html = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1950  }
1951 
1952  return self::link( $title, $html, $attrs, $query, $options );
1953  }
1954 
1955  $html = $context->msg( 'rollbacklink' )->escaped();
1956  return self::link( $title, $html, $attrs, $query, $options );
1957  }
1958 
1967  public static function formatHiddenCategories( $hiddencats ) {
1968  $outText = '';
1969  if ( count( $hiddencats ) > 0 ) {
1970  # Construct the HTML
1971  $outText = '<div class="mw-hiddenCategoriesExplanation">';
1972  $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1973  $outText .= "</div><ul>\n";
1974 
1975  foreach ( $hiddencats as $titleObj ) {
1976  # If it's hidden, it must exist - no need to check with a LinkBatch
1977  $outText .= '<li>'
1978  . self::link( $titleObj, null, [], [], 'known' )
1979  . "</li>\n";
1980  }
1981  $outText .= '</ul>';
1982  }
1983  return $outText;
1984  }
1985 
2002  public static function titleAttrib( $name, $options = null, array $msgParams = [] ) {
2003  $message = wfMessage( "tooltip-$name", $msgParams );
2004  if ( !$message->exists() ) {
2005  $tooltip = false;
2006  } else {
2007  $tooltip = $message->text();
2008  # Compatibility: formerly some tooltips had [alt-.] hardcoded
2009  $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2010  # Message equal to '-' means suppress it.
2011  if ( $tooltip == '-' ) {
2012  $tooltip = false;
2013  }
2014  }
2015 
2016  $options = (array)$options;
2017 
2018  if ( in_array( 'nonexisting', $options ) ) {
2019  $tooltip = wfMessage( 'red-link-title', $tooltip ?: '' )->text();
2020  }
2021  if ( in_array( 'withaccess', $options ) ) {
2022  $accesskey = self::accesskey( $name );
2023  if ( $accesskey !== false ) {
2024  // Should be build the same as in jquery.accessKeyLabel.js
2025  if ( $tooltip === false || $tooltip === '' ) {
2026  $tooltip = wfMessage( 'brackets', $accesskey )->text();
2027  } else {
2028  $tooltip .= wfMessage( 'word-separator' )->text();
2029  $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2030  }
2031  }
2032  }
2033 
2034  return $tooltip;
2035  }
2036 
2037  public static $accesskeycache;
2038 
2050  public static function accesskey( $name ) {
2051  if ( isset( self::$accesskeycache[$name] ) ) {
2052  return self::$accesskeycache[$name];
2053  }
2054 
2055  $message = wfMessage( "accesskey-$name" );
2056 
2057  if ( !$message->exists() ) {
2058  $accesskey = false;
2059  } else {
2060  $accesskey = $message->plain();
2061  if ( $accesskey === '' || $accesskey === '-' ) {
2062  # Per standard MW behavior, a value of '-' means to suppress the
2063  # attribute. It is thus forbidden to use this as an access key.
2064  $accesskey = false;
2065  }
2066  }
2067 
2068  self::$accesskeycache[$name] = $accesskey;
2069  return self::$accesskeycache[$name];
2070  }
2071 
2086  public static function getRevDeleteLink(
2087  Authority $performer,
2088  RevisionRecord $revRecord,
2090  ) {
2091  $canHide = $performer->isAllowed( 'deleterevision' );
2092  $canHideHistory = $performer->isAllowed( 'deletedhistory' );
2093  if ( !$canHide && !( $revRecord->getVisibility() && $canHideHistory ) ) {
2094  return '';
2095  }
2096 
2097  if ( !$revRecord->userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
2098  return self::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2099  }
2100  $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
2101  getPrefixedDBkey( $title );
2102  if ( $revRecord->getId() ) {
2103  // RevDelete links using revision ID are stable across
2104  // page deletion and undeletion; use when possible.
2105  $query = [
2106  'type' => 'revision',
2107  'target' => $prefixedDbKey,
2108  'ids' => $revRecord->getId()
2109  ];
2110  } else {
2111  // Older deleted entries didn't save a revision ID.
2112  // We have to refer to these by timestamp, ick!
2113  $query = [
2114  'type' => 'archive',
2115  'target' => $prefixedDbKey,
2116  'ids' => $revRecord->getTimestamp()
2117  ];
2118  }
2119  return self::revDeleteLink(
2120  $query,
2121  $revRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ),
2122  $canHide
2123  );
2124  }
2125 
2138  public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) {
2139  $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
2140  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2141  $html = wfMessage( $msgKey )->escaped();
2142  $tag = $restricted ? 'strong' : 'span';
2143  $link = self::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] );
2144  return Xml::tags(
2145  $tag,
2146  [ 'class' => 'mw-revdelundel-link' ],
2147  wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2148  );
2149  }
2150 
2162  public static function revDeleteLinkDisabled( $delete = true ) {
2163  $msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
2164  $html = wfMessage( $msgKey )->escaped();
2165  $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2166  return Xml::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses );
2167  }
2168 
2181  public static function tooltipAndAccesskeyAttribs(
2182  $name,
2183  array $msgParams = [],
2184  $options = null
2185  ) {
2186  $options = (array)$options;
2187  $options[] = 'withaccess';
2188  $tooltipTitle = $name;
2189 
2190  // @since 1.35 - add a WatchlistExpiry feature flag to show new watchstar tooltip message
2191  $skin = RequestContext::getMain()->getSkin();
2192  $isWatchlistExpiryEnabled = $skin->getConfig()->get( 'WatchlistExpiry' );
2193  if ( $name === 'ca-unwatch' && $isWatchlistExpiryEnabled ) {
2194  $watchStore = MediaWikiServices::getInstance()->getWatchedItemStore();
2195  $watchedItem = $watchStore->getWatchedItem( $skin->getUser(),
2196  $skin->getRelevantTitle() );
2197  if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
2198  $diffInDays = $watchedItem->getExpiryInDays();
2199 
2200  if ( $diffInDays ) {
2201  $msgParams = [ $diffInDays ];
2202  // Resolves to tooltip-ca-unwatch-expiring message
2203  $tooltipTitle = 'ca-unwatch-expiring';
2204  } else { // Resolves to tooltip-ca-unwatch-expiring-hours message
2205  $tooltipTitle = 'ca-unwatch-expiring-hours';
2206  }
2207 
2208  }
2209  }
2210 
2211  $attribs = [
2212  'title' => self::titleAttrib( $tooltipTitle, $options, $msgParams ),
2213  'accesskey' => self::accesskey( $name )
2214  ];
2215  if ( $attribs['title'] === false ) {
2216  unset( $attribs['title'] );
2217  }
2218  if ( $attribs['accesskey'] === false ) {
2219  unset( $attribs['accesskey'] );
2220  }
2221  return $attribs;
2222  }
2223 
2231  public static function tooltip( $name, $options = null ) {
2232  $tooltip = self::titleAttrib( $name, $options );
2233  if ( $tooltip === false ) {
2234  return '';
2235  }
2236  return Xml::expandAttributes( [
2237  'title' => $tooltip
2238  ] );
2239  }
2240 
2241 }
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:527
MediaWiki\Revision\RevisionRecord\getUser
getUser( $audience=self::FOR_PUBLIC, Authority $performer=null)
Fetch revision's author's user identity, if it's available to the specified audience.
Definition: RevisionRecord.php:389
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:647
Linker\makeThumbLinkObj
static makeThumbLinkObj(LinkTarget $title, $file, $label='', $alt='', $align=null, $params=[], $framed=false, $manualthumb="")
Make HTML for a thumbnail including image, border and caption.
Definition: Linker.php:567
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
$wgThumbLimits
$wgThumbLimits
Adjust thumbnails on image pages according to a user setting.
Definition: DefaultSettings.php:1652
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:1398
Linker
Some internal bits split of from Skin.php.
Definition: Linker.php:38
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
Linker\TOOL_LINKS_NOBLOCK
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
Definition: Linker.php:42
Linker\userTalkLink
static userTalkLink( $userId, $userText)
Definition: Linker.php:1202
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:1245
Linker\generateTOC
static generateTOC( $tree, Language $lang=null)
Generate a table of contents from a section tree.
Definition: Linker.php:1660
$wgResponsiveImages
$wgResponsiveImages
Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
Definition: DefaultSettings.php:1770
Linker\makeBrokenImageLinkObj
static makeBrokenImageLinkObj( $title, $label='', $query='', $unused1='', $unused2='', $time=false, array $handlerParams=[])
Make a "broken" link to an image.
Definition: Linker.php:828
Linker\revUserTools
static revUserTools(RevisionRecord $revRecord, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
Definition: Linker.php:1319
Linker\userLink
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:1064
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
Linker\makeThumbLink2
static makeThumbLink2(LinkTarget $title, $file, $frameParams=[], $handlerParams=[], $time=false, $query="", array $classes=[])
Definition: Linker.php:598
Linker\makeSelfLinkObj
static makeSelfLinkObj( $nt, $html='', $query='', $trail='', $prefix='')
Make appropriate markup for a link to the current article.
Definition: Linker.php:161
Linker\getUploadUrl
static getUploadUrl( $destFile, $query='')
Get the URL to upload a certain file.
Definition: Linker.php:895
Linker\tocIndent
static tocIndent()
Add another level to the Table of Contents.
Definition: Linker.php:1561
$fallback
$fallback
Definition: MessagesAb.php:11
$wgSVGMaxSize
$wgSVGMaxSize
Don't scale a SVG larger than this.
Definition: DefaultSettings.php:1378
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:1109
Linker\fnamePart
static fnamePart( $url)
Returns the filename part of an url.
Definition: Linker.php:220
MediaWiki\Revision\RevisionRecord\getPageId
getPageId( $wikiId=self::LOCAL)
Get the page ID.
Definition: RevisionRecord.php:335
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:985
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Parser\getTargetLanguage
getTargetLanguage()
Get the target language for the content being parsed.
Definition: Parser.php:1159
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:139
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1175
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:107
Linker\processResponsiveImages
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:792
Linker\revUserLink
static revUserLink(RevisionRecord $revRecord, $isPublic=false)
Generate a user link if the current user is allowed to view it.
Definition: Linker.php:1271
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1048
$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:185
Parser\getExternalLinkRel
static getExternalLinkRel( $url=false, LinkTarget $title=null)
Get the rel attribute for a particular external link.
Definition: Parser.php:2221
$res
$res
Definition: testCompression.php:57
$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:1587
$wgLang
$wgLang
Definition: Setup.php:834
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:1623
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:1967
Linker\tooltipAndAccesskeyAttribs
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2181
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
$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:422
WatchedItem\getExpiry
getExpiry(?int $style=TS_MW)
When the watched item will expire.
Definition: WatchedItem.php:150
Linker\$accesskeycache
static $accesskeycache
Definition: Linker.php:2037
Linker\makeMediaLinkObj
static makeMediaLinkObj( $title, $html='', $time=false)
Create a direct link to a given uploaded file.
Definition: Linker.php:924
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:989
MessageLocalizer\msg
msg( $key,... $params)
This is the method for getting translated interface messages.
Linker\buildRollbackLink
static buildRollbackLink(RevisionRecord $revRecord, IContextSource $context=null, $editCount=false)
Build a raw rollback link, useful for collections of "tool" links.
Definition: Linker.php:1890
TitleValue\tryNew
static tryNew( $namespace, $title, $fragment='', $interwiki='')
Constructs a TitleValue, or returns null if the parameters are not valid.
Definition: TitleValue.php:94
Linker\getRevisionDeletedClass
static getRevisionDeletedClass(RevisionRecord $revisionRecord)
Returns css class of a deleted revision.
Definition: Linker.php:1299
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2192
Linker\getRollbackEditCount
static getRollbackEditCount(RevisionRecord $revRecord, $verify)
This function will return the number of revisions which a rollback would revert and,...
Definition: Linker.php:1816
Linker\makeHeadline
static makeHeadline( $level, $attribs, $anchor, $html, $link, $fallbackAnchor=false)
Create a headline for content.
Definition: Linker.php:1698
Linker\tocLineEnd
static tocLineEnd()
End a Table Of Contents line.
Definition: Linker.php:1611
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:375
Linker\revDeleteLinkDisabled
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2162
$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:1011
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Html\label
static label( $label, $id, array $attribs=[])
Convenience function for generating a label for inputs.
Definition: Html.php:815
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:886
$wgTitle
$wgTitle
Definition: Setup.php:852
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:1719
Linker\generateRollback
static generateRollback(RevisionRecord $revRecord, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1757
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
$wgShowRollbackEditCount
$wgShowRollbackEditCount
The $wgShowRollbackEditCount variable is used to show how many edits can be rolled back.
Definition: DefaultSettings.php:3975
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:676
Linker\revComment
static revComment(RevisionRecord $revRecord, $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:1530
Linker\blockLink
static blockLink( $userId, $userText)
Definition: Linker.php:1224
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
Linker\normaliseSpecialPage
static normaliseSpecialPage(LinkTarget $target)
Definition: Linker.php:206
ExternalUserNames\getUserLinkTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
Definition: ExternalUserNames.php:63
Linker\TOOL_LINKS_EMAIL
const TOOL_LINKS_EMAIL
Definition: Linker.php:43
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:1508
Linker\userToolLinksRedContribs
static userToolLinksRedContribs( $userId, $userText, $edits=null, $useParentheses=true)
Alias for userToolLinks( $userId, $userText, true );.
Definition: Linker.php:1190
MediaWiki\Revision\RevisionRecord\getPageAsLinkTarget
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Definition: RevisionRecord.php:355
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:173
Linker\link
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:87
WatchedItem
Representation of a pair of user and title for watchlist entries.
Definition: WatchedItem.php:36
Linker\formatRevisionSize
static formatRevisionSize( $size)
Definition: Linker.php:1546
NS_USER
const NS_USER
Definition: Defines.php:66
Parser
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:92
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
DummyLinker
Definition: DummyLinker.php:9
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:294
Linker\makeMediaLinkFile
static makeMediaLinkFile(LinkTarget $title, $file, $html='')
Create a direct link to a given uploaded file.
Definition: Linker.php:943
$wgUploadNavigationUrl
$wgUploadNavigationUrl
Point the upload navigation link to an external URL Useful if you want to use a shared repository by ...
Definition: DefaultSettings.php:1058
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:2002
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
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:1372
$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: ApiWatchlistTrait.php:33
Linker\tooltip
static tooltip( $name, $options=null)
Returns raw bits of HTML, use titleAttrib()
Definition: Linker.php:2231
MediaWiki\Permissions\Authority\isAllowed
isAllowed(string $permission)
Checks whether this authority has the given permission in general.
$wgMiserMode
$wgMiserMode
Disable database-intensive features.
Definition: DefaultSettings.php:2624
MediaWiki\Revision\RevisionRecord\getId
getId( $wikiId=self::LOCAL)
Get revision ID.
Definition: RevisionRecord.php:279
MediaWiki\Revision\RevisionRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaced Revision::isDeleted.
Definition: RevisionRecord.php:437
$wgThumbUpright
$wgThumbUpright
Adjust width of upright images when parameter 'upright' is used This allows a nicer look for upright ...
Definition: DefaultSettings.php:1757
Linker\tocUnindent
static tocUnindent( $level)
Finish one or more sublevels on the Table of Contents.
Definition: Linker.php:1572
MediaWiki\Revision\RevisionRecord\userCan
userCan( $field, Authority $performer)
Determine if the give authority is allowed to view a particular field of this revision,...
Definition: RevisionRecord.php:509
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:296
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:252
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
Linker\revDeleteLink
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
Definition: Linker.php:2138
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:67
MediaWiki\Revision\RevisionRecord\getTimestamp
getTimestamp()
MCR migration note: this replaced Revision::getTimestamp.
Definition: RevisionRecord.php:459
$wgEnableUploads
$wgEnableUploads
Allow users to upload files.
Definition: DefaultSettings.php:517
Linker\normalizeSubpageLink
static normalizeSubpageLink( $contextTitle, $target, &$text)
Definition: Linker.php:1411
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:1035
Title\castFromLinkTarget
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
Definition: Title.php:318
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
$wgUploadMissingFileUrl
$wgUploadMissingFileUrl
Point the upload link for missing files to an external URL, as with $wgUploadNavigationUrl.
Definition: DefaultSettings.php:1065
NS_FILE
const NS_FILE
Definition: Defines.php:70
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:2050
Linker\getRevDeleteLink
static getRevDeleteLink(Authority $performer, RevisionRecord $revRecord, LinkTarget $title)
Get a revision-deletion link, or disabled link, or nothing, depending on user permissions & the setti...
Definition: Linker.php:2086
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:149
Linker\makeExternalImage
static makeExternalImage( $url, $alt='')
Return the code for images which were added via external links, via Parser::maybeMakeExternalImage().
Definition: Linker.php:240
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:42
MediaWiki\Revision\RevisionRecord\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: RevisionRecord.php:448
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:8186