33use Wikimedia\Assert\Assert;
36use Wikimedia\RemexHtml\Serializer\SerializerNode;
95 public static function link(
96 $target, $html =
null, $customAttribs = [], $query = [], $options = []
99 wfWarn( __METHOD__ .
': Requires $target to be a LinkTarget object.', 2 );
100 return "<!-- ERROR -->$html";
104 $options = (array)$options;
107 $linkRenderer = $services->getLinkRendererFactory()
108 ->createFromLegacyOptions( $options );
110 $linkRenderer = $services->getLinkRenderer();
113 if ( $html !==
null ) {
119 if ( in_array(
'known', $options,
true ) ) {
120 return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
123 if ( in_array(
'broken', $options,
true ) ) {
124 return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
127 if ( in_array(
'noclasses', $options,
true ) ) {
128 return $linkRenderer->makePreloadedLink( $target, $text,
'', $customAttribs, $query );
131 return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
154 $target, $html =
null, $customAttribs = [],
155 $query = [], $options = [
'known' ]
157 return self::link( $target, $html, $customAttribs, $query, $options );
177 public static function makeSelfLinkObj( $nt, $html =
'', $query =
'', $trail =
'', $prefix =
'', $hash =
'' ) {
178 $nt = Title::newFromLinkTarget( $nt );
181 $attrs[
'class'] =
'mw-selflink-fragment';
182 $attrs[
'href'] =
'#' . $hash;
185 $attrs[
'class'] =
'mw-selflink selflink';
187 $ret = Html::rawElement(
'a', $attrs, $prefix . $html ) . $trail;
189 if ( !$hookRunner->onSelfLinkBegin( $nt, $html, $trail, $prefix, $ret ) ) {
194 $html = htmlspecialchars( $nt->getPrefixedText() );
197 return Html::rawElement(
'a', $attrs, $prefix . $html . $inside ) . $trail;
214 $name = $context->
msg(
'blanknamespace' )->text();
217 getFormattedNsText( $namespace );
219 return $context->
msg(
'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
222 return $context->
msg(
'invalidtitle-unknownnamespace', $namespace, $title )->text();
233 private static function fnamePart(
$url ) {
234 $basename = strrchr(
$url,
'/' );
235 if ( $basename ===
false ) {
238 $basename = substr( $basename, 1 );
255 $alt = self::fnamePart(
$url );
259 ->onLinkerMakeExternalImage(
$url, $alt, $img );
261 wfDebug(
"Hook LinkerMakeExternalImage changed the output of external image "
262 .
"with url {$url} and alt text {$alt} to {$img}" );
312 $file, $frameParams = [], $handlerParams = [], $time =
false,
313 $query =
'', $widthOption =
null
315 $title = Title::newFromLinkTarget( $title );
318 if ( !$hookRunner->onImageBeforeProduceHTML(
null, $title,
320 $file, $frameParams, $handlerParams, $time, $res,
322 $parser, $query, $widthOption )
327 if ( $file && !$file->allowInlineDisplay() ) {
328 wfDebug( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
' does not allow inline display' );
333 $page = $handlerParams[
'page'] ??
false;
334 if ( !isset( $frameParams[
'align'] ) ) {
335 $frameParams[
'align'] =
'';
337 if ( !isset( $frameParams[
'title'] ) ) {
338 $frameParams[
'title'] =
'';
340 if ( !isset( $frameParams[
'class'] ) ) {
341 $frameParams[
'class'] =
'';
345 $config = $services->getMainConfig();
349 !isset( $handlerParams[
'width'] ) &&
350 !isset( $frameParams[
'manualthumb'] ) &&
351 !isset( $frameParams[
'framed'] )
353 $classes[] =
'mw-default-size';
356 $prefix = $postfix =
'';
358 if ( $file && !isset( $handlerParams[
'width'] ) ) {
359 if ( isset( $handlerParams[
'height'] ) && $file->isVectorized() ) {
363 $handlerParams[
'width'] = $svgMaxSize;
365 $handlerParams[
'width'] = $file->getWidth( $page );
368 if ( isset( $frameParams[
'thumbnail'] )
369 || isset( $frameParams[
'manualthumb'] )
370 || isset( $frameParams[
'framed'] )
371 || isset( $frameParams[
'frameless'] )
372 || !$handlerParams[
'width']
376 if ( $widthOption ===
null || !isset( $thumbLimits[$widthOption] ) ) {
377 $userOptionsLookup = $services->getUserOptionsLookup();
382 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
383 $frameParams[
'upright'] = $thumbUpright;
389 $prefWidth = isset( $frameParams[
'upright'] ) ?
390 round( $thumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
391 $thumbLimits[$widthOption];
395 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
396 $prefWidth < $handlerParams[
'width'] || $file->isVectorized() ) ) {
397 $handlerParams[
'width'] = $prefWidth;
403 $hasVisibleCaption = isset( $frameParams[
'thumbnail'] ) ||
404 isset( $frameParams[
'manualthumb'] ) ||
405 isset( $frameParams[
'framed'] );
407 if ( $hasVisibleCaption ) {
409 $title, $file, $frameParams, $handlerParams, $time, $query,
414 $rdfaType =
'mw:File';
416 if ( isset( $frameParams[
'frameless'] ) ) {
417 $rdfaType .=
'/Frameless';
419 $srcWidth = $file->getWidth( $page );
420 # For "frameless" option: do not present an image bigger than the
421 # source (for bitmap-style images). This is the same behavior as the
422 # "thumb" option does it already.
423 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
424 $handlerParams[
'width'] = $srcWidth;
429 if ( $file && isset( $handlerParams[
'width'] ) ) {
430 # Create a resized image, without the additional thumbnail features
431 $thumb = $file->transform( $handlerParams );
436 $isBadFile = $file && $thumb &&
439 if ( !$thumb || $thumb->isError() || $isBadFile ) {
440 $rdfaType =
'mw:Error ' . $rdfaType;
441 $currentExists = $file && $file->exists();
442 if ( $currentExists && !$thumb ) {
443 $label =
wfMessage(
'thumbnail_error',
'' )->text();
444 } elseif ( $thumb && $thumb->isError() ) {
447 'Unknown MediaTransformOutput: ' . get_class( $thumb )
449 $label = $thumb->toText();
451 $label = $frameParams[
'alt'] ??
'';
454 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams, $currentExists
462 if ( isset( $frameParams[
'alt'] ) ) {
463 $params[
'alt'] = $frameParams[
'alt'];
465 $params[
'title'] = $frameParams[
'title'];
467 'img-class' =>
'mw-file-element',
470 $s = $thumb->toHtml( $params );
476 if ( $frameParams[
'align'] !=
'' ) {
479 $classes[] =
"mw-halign-{$frameParams['align']}";
480 $caption = Html::rawElement(
481 'figcaption', [], $frameParams[
'caption'] ??
''
483 } elseif ( isset( $frameParams[
'valign'] ) ) {
487 $classes[] =
"mw-valign-{$frameParams['valign']}";
490 if ( isset( $frameParams[
'border'] ) ) {
491 $classes[] =
'mw-image-border';
494 if ( isset( $frameParams[
'class'] ) ) {
495 $classes[] = $frameParams[
'class'];
500 'typeof' => $rdfaType,
503 $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
505 return str_replace(
"\n",
' ', $s );
518 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
519 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
520 if ( isset( $frameParams[
'link-target'] ) ) {
521 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
524 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
525 foreach ( $extLinkAttrs as $name => $val ) {
527 $mtoParams[
'parser-extlink-' . $name] = $val;
530 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
532 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
533 $linkRenderer->normalizeTarget( $frameParams[
'link-title'] )
535 if ( isset( $frameParams[
'link-title-query'] ) ) {
536 $mtoParams[
'custom-title-link-query'] = $frameParams[
'link-title-query'];
538 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
541 $mtoParams[
'desc-link'] =
true;
542 $mtoParams[
'desc-query'] = $query;
560 LinkTarget $title, $file, $label =
'', $alt =
'', $align =
null,
561 $params = [], $framed =
false, $manualthumb =
''
569 if ( $manualthumb ) {
570 $frameParams[
'manualthumb'] = $manualthumb;
571 } elseif ( $framed ) {
572 $frameParams[
'framed'] =
true;
573 } elseif ( !isset( $params[
'width'] ) ) {
574 $classes[] =
'mw-default-size';
577 $title, $file, $frameParams, $params,
false,
'', $classes
593 LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
594 $time =
false, $query =
'', array $classes = [], ?
Parser $parser =
null
596 $exists = $file && $file->exists();
599 $page = $handlerParams[
'page'] ??
false;
600 $lang = $handlerParams[
'lang'] ??
false;
602 if ( !isset( $frameParams[
'align'] ) ) {
603 $frameParams[
'align'] =
'';
605 if ( !isset( $frameParams[
'caption'] ) ) {
606 $frameParams[
'caption'] =
'';
609 if ( empty( $handlerParams[
'width'] ) ) {
611 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
616 $manualthumb =
false;
618 $rdfaType =
'mw:File/Thumb';
622 if ( !isset( $frameParams[
'manualthumb'] ) && isset( $frameParams[
'framed'] ) ) {
623 $rdfaType =
'mw:File/Frame';
625 $outerWidth = $handlerParams[
'width'] + 2;
627 if ( isset( $frameParams[
'manualthumb'] ) ) {
628 # Use manually specified thumbnail
629 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
630 if ( $manual_title ) {
631 $manual_img = $services->getRepoGroup()
632 ->findFile( $manual_title );
634 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
639 $srcWidth = $file->getWidth( $page );
640 if ( isset( $frameParams[
'framed'] ) ) {
641 $rdfaType =
'mw:File/Frame';
642 if ( !$file->isVectorized() ) {
648 $handlerParams[
'width'] = $srcWidth;
654 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
655 $handlerParams[
'width'] = $srcWidth;
659 ? $file->getUnscaledThumb( $handlerParams )
660 : $file->transform( $handlerParams );
664 $outerWidth = $thumb->getWidth() + 2;
666 $outerWidth = $handlerParams[
'width'] + 2;
670 if ( $parser && $rdfaType ===
'mw:File/Thumb' ) {
671 $parser->getOutput()->addModules( [
'mediawiki.page.media' ] );
674 $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
675 $linkTitleQuery = [];
676 if ( $page || $lang ) {
678 $linkTitleQuery[
'page'] = $page;
681 $linkTitleQuery[
'lang'] = $lang;
683 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
684 # So we don't need to pass it here in $query. However, the URL for the
685 # zoom icon still needs it, so we make a unique query for it. See T16771
690 && !isset( $frameParams[
'link-title'] )
691 && !isset( $frameParams[
'link-url'] )
692 && !isset( $frameParams[
'no-link'] ) ) {
693 $frameParams[
'link-title'] = $title;
694 $frameParams[
'link-title-query'] = $linkTitleQuery;
697 if ( $frameParams[
'align'] !=
'' ) {
699 $classes[] =
"mw-halign-{$frameParams['align']}";
702 if ( isset( $frameParams[
'class'] ) ) {
703 $classes[] = $frameParams[
'class'];
708 $isBadFile = $exists && $thumb && $parser &&
709 $parser->getBadFileLookup()->isBadFile(
710 $manualthumb ? $manual_title->getDBkey() : $title->
getDBkey(),
715 $rdfaType =
'mw:Error ' . $rdfaType;
716 $label = $frameParams[
'alt'] ??
'';
718 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
false
721 } elseif ( !$thumb || $thumb->isError() || $isBadFile ) {
722 $rdfaType =
'mw:Error ' . $rdfaType;
723 if ( $thumb && $thumb->isError() ) {
726 'Unknown MediaTransformOutput: ' . get_class( $thumb )
728 $label = $thumb->toText();
729 } elseif ( !$thumb ) {
730 $label =
wfMessage(
'thumbnail_error',
'' )->text();
735 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
true
739 if ( !$noscale && !$manualthumb ) {
746 if ( isset( $frameParams[
'alt'] ) ) {
747 $params[
'alt'] = $frameParams[
'alt'];
750 'img-class' =>
'mw-file-element',
753 if ( $rdfaType ===
'mw:File/Thumb' ) {
754 $params[
'magnify-resource'] =
$url;
757 $s .= $thumb->toHtml( $params );
758 if ( isset( $frameParams[
'framed'] ) ) {
761 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
762 Html::rawElement(
'a', [
764 'class' =>
'internal',
765 'title' =>
wfMessage(
'thumbnail-more' )->text(),
771 $s .= Html::rawElement(
772 'figcaption', [], $frameParams[
'caption'] ??
''
777 'typeof' => $rdfaType,
780 $s = Html::rawElement(
'figure', $attribs, $s );
782 return str_replace(
"\n",
' ', $s );
795 if ( $responsiveImages && $thumb && !$thumb->isError() ) {
797 $hp15[
'width'] = round( $hp[
'width'] * 1.5 );
799 $hp20[
'width'] = $hp[
'width'] * 2;
800 if ( isset( $hp[
'height'] ) ) {
801 $hp15[
'height'] = round( $hp[
'height'] * 1.5 );
802 $hp20[
'height'] = $hp[
'height'] * 2;
805 $thumb15 = $file->transform( $hp15 );
806 $thumb20 = $file->transform( $hp20 );
807 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
808 $thumb->responsiveUrls[
'1.5'] = $thumb15->getUrl();
810 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
811 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
831 $title, $label =
'', $query =
'', $unused1 =
'', $unused2 =
'',
832 $time =
false, array $handlerParams = [],
bool $currentExists =
false
835 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
836 return "<!-- ERROR -->" . htmlspecialchars( $label );
839 $title = Title::newFromLinkTarget( $title );
841 $mainConfig = $services->getMainConfig();
845 if ( $label ==
'' ) {
846 $label = $title->getPrefixedText();
850 'class' =>
'mw-file-element mw-broken-media',
852 'data-width' => $handlerParams[
'width'] ??
null,
853 'data-height' => $handlerParams[
'height'] ??
null,
856 $repoGroup = $services->getRepoGroup();
857 $currentExists = $currentExists ||
858 ( $time && $repoGroup->findFile( $title ) !== false );
860 if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
864 $title->inNamespace(
NS_FILE ) &&
865 $repoGroup->getLocalRepo()->checkRedirect( $title )
871 [
'class' =>
'mw-redirect' ],
873 [
'known',
'noclasses' ]
876 return Html::rawElement(
'a', [
877 'href' => self::getUploadUrl( $title, $query ),
879 'title' => $title->getPrefixedText()
887 [
'known',
'noclasses' ]
903 $q =
'wpDestFile=' . Title::newFromLinkTarget( $destFile )->getPartialURL();
904 if ( $query !=
'' ) {
908 if ( $uploadMissingFileUrl ) {
912 if ( $uploadNavigationUrl ) {
918 return $upload->getLocalURL( $q );
932 $title, [
'time' => $time ]
950 if ( $file && $file->exists() ) {
951 $url = $file->getUrl();
971 Title::newFromLinkTarget( $title ), $file, $html, $attribs, $ret )
973 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
974 .
"with url {$url} and text {$html} to {$ret}" );
978 return Html::rawElement(
'a', $attribs, $html );
992 $queryPos = strpos( $name,
'?' );
993 if ( $queryPos !==
false ) {
994 $getParams =
wfCgiToArray( substr( $name, $queryPos + 1 ) );
995 $name = substr( $name, 0, $queryPos );
1000 $slashPos = strpos( $name,
'/' );
1001 if ( $slashPos !==
false ) {
1002 $subpage = substr( $name, $slashPos + 1 );
1003 $name = substr( $name, 0, $slashPos );
1009 $key = strtolower( $name );
1041 $linktype =
'', $attribs = [], $title =
null
1046 return $linkRenderer->makeExternalLink(
1048 $escape ? $text :
new HtmlArmor( $text ),
1072 $altUserName =
false,
1075 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
1076 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1077 'that need to be fixed?' );
1078 return wfMessage(
'empty-username' )->parse();
1084 RequestContext::getMain(),
1085 $altUserName ===
false ?
null : (string)$altUserName,
1109 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null
1113 $talkable = !( $disableAnonTalk && $userId == 0 );
1115 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1117 if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1129 $attribs[
'class'] =
'mw-usertoollinks-contribs';
1130 if ( $redContribsWhenNoEdits ) {
1131 if ( $edits ===
null ) {
1132 $user = UserIdentityValue::newRegistered( $userId, $userText );
1133 $edits = $services->getUserEditTracker()->getUserEditCount( $user );
1135 if ( $edits === 0 ) {
1138 $attribs[
'class'] .=
' mw-usertoollinks-contribs-no-edits';
1145 $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed(
'block' );
1146 if ( $blockable && $userCanBlock ) {
1153 ->newEmailUser( RequestContext::getMain()->
getAuthority() )
1160 (
new HookRunner( $services->getHookContainer() ) )->onUserToolLinksEdit( $userId, $userText, $items );
1179 if ( $useParentheses ) {
1180 return wfMessage(
'word-separator' )->escaped()
1181 .
'<span class="mw-usertoollinks">'
1182 .
wfMessage(
'parentheses' )->rawParams(
$wgLang->pipeList( $items ) )->escaped()
1187 foreach ( $items as $tool ) {
1188 $tools[] = Html::rawElement(
'span', [], $tool );
1190 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1191 implode(
' ', $tools ) .
'</span>';
1209 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
1210 $useParentheses =
true
1212 if ( $userText ===
'' ) {
1213 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1214 'that need to be fixed?' );
1215 return ' ' .
wfMessage(
'empty-username' )->parse();
1218 $items = self::userToolLinkArray( $userId, $userText, $redContribsWhenNoEdits, $flags, $edits );
1219 return self::renderUserToolLinksArray( $items, $useParentheses );
1232 $userId, $userText, $edits =
null, $useParentheses =
true
1234 return self::userToolLinks( $userId, $userText,
true, 0, $edits, $useParentheses );
1244 if ( $userText ===
'' ) {
1245 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1246 'that need to be fixed?' );
1247 return wfMessage(
'empty-username' )->parse();
1250 $userTalkPage = TitleValue::tryNew(
NS_USER_TALK, strtr( $userText,
' ',
'_' ) );
1251 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1252 $linkText =
wfMessage(
'talkpagelinktext' )->escaped();
1254 return $userTalkPage
1255 ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1256 : Html::rawElement(
'span', $moreLinkAttribs, $linkText );
1266 if ( $userText ===
'' ) {
1267 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1268 'that need to be fixed?' );
1269 return wfMessage(
'empty-username' )->parse();
1272 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1273 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1275 return self::link( $blockPage,
1287 if ( $userText ===
'' ) {
1288 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1289 'that need to be fixed?' );
1290 return wfMessage(
'empty-username' )->parse();
1293 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1294 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1295 return self::link( $emailPage,
1314 $authority = RequestContext::getMain()->getAuthority();
1316 $revUser = $revRecord->
getUser(
1317 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1321 $link = self::userLink( $revUser->getId(), $revUser->getName() );
1324 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1327 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1328 $class = self::getRevisionDeletedClass( $revRecord );
1329 return '<span class="' . $class .
'">' . $link .
'</span>';
1341 $class =
'history-deleted';
1342 if ( $revisionRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1343 $class .=
' mw-history-suppressed';
1363 $useParentheses =
true
1366 $authority = RequestContext::getMain()->getAuthority();
1368 $revUser = $revRecord->
getUser(
1369 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1373 $link = self::userLink(
1375 $revUser->getName(),
1377 [
'data-mw-revid' => $revRecord->
getId() ]
1378 ) . self::userToolLinks(
1380 $revUser->getName(),
1388 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1391 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1392 $class = self::getRevisionDeletedClass( $revRecord );
1393 return ' <span class="' . $class .
' mw-userlink">' . $link .
'</span>';
1409 return HtmlHelper::modifyElements(
1411 static function ( SerializerNode $node ):
bool {
1412 return $node->name ===
'a' && isset( $node->attrs[
'href'] );
1414 static function ( SerializerNode $node ): SerializerNode {
1415 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
1416 $node->attrs[
'href'] =
1417 $urlUtils->expand( $node->attrs[
'href'],
PROTO_RELATIVE ) ??
false;
1432 # :Foobar -- override special treatment of prefix (images, language links)
1433 # /Foobar -- convert to CurrentPage/Foobar
1434 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1435 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1436 # ../Foobar -- convert to CurrentPage/Foobar,
1437 # (from CurrentPage/CurrentSubPage)
1438 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1439 # (from CurrentPage/CurrentSubPage)
1441 $ret = $target; #
default return value is no change
1443 # Some namespaces don't allow subpages,
1444 # so only perform processing if subpages are allowed
1446 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1447 hasSubpages( $contextTitle->getNamespace() )
1449 $hash = strpos( $target,
'#' );
1450 if ( $hash !==
false ) {
1451 $suffix = substr( $target, $hash );
1452 $target = substr( $target, 0, $hash );
1457 $target = trim( $target );
1458 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1459 getPrefixedText( $contextTitle );
1460 # Look at the first character
1461 if ( $target !=
'' && $target[0] ===
'/' ) {
1462 # / at end means we don't want the slash to be shown
1464 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1465 if ( $trailingSlashes ) {
1466 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1468 $noslash = substr( $target, 1 );
1471 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1472 if ( $text ===
'' ) {
1473 $text = $target . $suffix;
1474 } #
this might be changed
for ugliness reasons
1476 # check for .. subpage backlinks
1478 $nodotdot = $target;
1479 while ( str_starts_with( $nodotdot,
'../' ) ) {
1481 $nodotdot = substr( $nodotdot, 3 );
1483 if ( $dotdotcount > 0 ) {
1484 $exploded = explode(
'/', $contextPrefixedText );
1485 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1486 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1487 # / at the end means don't show full path
1488 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1489 $nodotdot = rtrim( $nodotdot,
'/' );
1490 if ( $text ===
'' ) {
1491 $text = $nodotdot . $suffix;
1494 $nodotdot = trim( $nodotdot );
1495 if ( $nodotdot !=
'' ) {
1496 $ret .=
'/' . $nodotdot;
1514 $stxt =
wfMessage(
'historyempty' )->escaped();
1516 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1518 return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1528 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1530 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1531 [ , $inside, $trail ] = $m;
1533 return [ $inside, $trail ];
1571 $context ??= RequestContext::getMain();
1573 $editCount = self::getRollbackEditCount( $revRecord );
1574 if ( $editCount ===
false ) {
1578 $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1580 $services = MediaWikiServices::getInstance();
1583 if ( !(
new HookRunner( $services->getHookContainer() ) )->onLinkerGenerateRollbackLink(
1584 $revRecord, $context, $options, $inner ) ) {
1588 if ( !in_array(
'noBrackets', $options,
true ) ) {
1589 $inner = $context->msg(
'brackets' )->rawParams( $inner )->escaped();
1592 if ( $services->getUserOptionsLookup()
1593 ->getBoolOption( $context->getUser(),
'showrollbackconfirmation' )
1595 $context->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1598 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1620 if ( func_num_args() > 1 ) {
1621 wfDeprecated( __METHOD__ .
' with $verify parameter',
'1.40' );
1623 $showRollbackEditCount = MediaWikiServices::getInstance()->getMainConfig()
1624 ->get( MainConfigNames::ShowRollbackEditCount );
1626 if ( !is_int( $showRollbackEditCount ) || !$showRollbackEditCount > 0 ) {
1631 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
1634 $queryBuilder = MediaWikiServices::getInstance()->getRevisionStore()->newSelectQueryBuilder( $dbr );
1635 $res = $queryBuilder->where( [
'rev_page' => $revRecord->
getPageId() ] )
1636 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
1637 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
1638 ->limit( $showRollbackEditCount + 1 )
1639 ->caller( __METHOD__ )->fetchResultSet();
1641 $revUser = $revRecord->
getUser( RevisionRecord::RAW );
1642 $revUserText = $revUser ? $revUser->getName() :
'';
1646 foreach ( $res as $row ) {
1647 if ( $row->rev_user_text != $revUserText ) {
1648 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1649 || $row->rev_deleted & RevisionRecord::DELETED_USER
1662 if ( $editCount <= $showRollbackEditCount && !$moreRevs ) {
1690 $config = MediaWikiServices::getInstance()->getMainConfig();
1691 $showRollbackEditCount = $config->get( MainConfigNames::ShowRollbackEditCount );
1692 $miserMode = $config->get( MainConfigNames::MiserMode );
1694 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1696 $context ??= RequestContext::getMain();
1699 $revUser = $revRecord->
getUser();
1700 $revUserText = $revUser ? $revUser->getName() :
'';
1703 'action' =>
'rollback',
1704 'from' => $revUserText,
1705 'token' => $context->getUser()->getEditToken(
'rollback' ),
1709 'data-mw' =>
'interface',
1710 'title' => $context->msg(
'tooltip-rollback' )->text()
1713 $options = [
'known',
'noclasses' ];
1715 if ( $context->getRequest()->getBool(
'bot' ) ) {
1717 $query[
'hidediff'] =
'1';
1718 $query[
'bot'] =
'1';
1722 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1723 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1724 $showRollbackEditCount =
false;
1731 $msg = [
'rollbacklink' ];
1732 if ( is_int( $showRollbackEditCount ) && $showRollbackEditCount > 0 ) {
1733 if ( !is_numeric( $editCount ) ) {
1734 $editCount = self::getRollbackEditCount( $revRecord );
1737 if ( $editCount > $showRollbackEditCount ) {
1738 $msg = [
'rollbacklinkcount-morethan', Message::numParam( $showRollbackEditCount ) ];
1739 } elseif ( $editCount ) {
1740 $msg = [
'rollbacklinkcount', Message::numParam( $editCount ) ];
1744 $html = $context->msg( ...$msg )->parse();
1745 return self::link( $title, $html, $attrs, $query, $options );
1758 if ( count( $hiddencats ) > 0 ) {
1759 # Construct the HTML
1760 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1761 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1762 $outText .=
"</div><ul>\n";
1764 foreach ( $hiddencats as $titleObj ) {
1765 # If it's hidden, it must exist - no need to check with a LinkBatch
1767 . self::link( $titleObj,
null, [], [],
'known' )
1770 $outText .=
'</ul>';
1778 private static function getContextFromMain() {
1779 $context = RequestContext::getMain();
1801 public static function titleAttrib( $name, $options =
null, array $msgParams = [], $localizer =
null ) {
1802 if ( !$localizer ) {
1803 $localizer = self::getContextFromMain();
1805 $message = $localizer->msg(
"tooltip-$name", $msgParams );
1808 if ( !$message->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1809 $message = $localizer->msg(
'tooltip-ca-nstab' );
1812 if ( $message->isDisabled() ) {
1815 $tooltip = $message->text();
1816 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1817 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
1820 $options = (array)$options;
1822 if ( in_array(
'nonexisting', $options ) ) {
1823 $tooltip = $localizer->msg(
'red-link-title', $tooltip ?:
'' )->text();
1825 if ( in_array(
'withaccess', $options ) ) {
1826 $accesskey = self::accesskey( $name, $localizer );
1827 if ( $accesskey !==
false ) {
1829 if ( $tooltip ===
false || $tooltip ===
'' ) {
1830 $tooltip = $localizer->msg(
'brackets', $accesskey )->text();
1832 $tooltip .= $localizer->msg(
'word-separator' )->text();
1833 $tooltip .= $localizer->msg(
'brackets', $accesskey )->text();
1856 public static function accesskey( $name, $localizer =
null ) {
1857 if ( !isset( self::$accesskeycache[$name] ) ) {
1858 if ( !$localizer ) {
1859 $localizer = self::getContextFromMain();
1861 $msg = $localizer->msg(
"accesskey-$name" );
1864 if ( !$msg->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1865 $msg = $localizer->msg(
'accesskey-ca-nstab' );
1867 self::$accesskeycache[$name] = $msg->isDisabled() ? false : $msg->plain();
1869 return self::$accesskeycache[$name];
1891 $canHide = $performer->
isAllowed(
'deleterevision' );
1892 $canHideHistory = $performer->
isAllowed(
'deletedhistory' );
1893 if ( !$canHide && !( $revRecord->
getVisibility() && $canHideHistory ) ) {
1897 if ( !$revRecord->
userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
1898 return self::revDeleteLinkDisabled( $canHide );
1900 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
1901 getPrefixedDBkey( $title );
1902 if ( $revRecord->
getId() ) {
1906 'type' =>
'revision',
1907 'target' => $prefixedDbKey,
1908 'ids' => $revRecord->
getId()
1914 'type' =>
'archive',
1915 'target' => $prefixedDbKey,
1919 return self::revDeleteLink(
1921 $revRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ),
1938 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
1939 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
1940 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1941 $html =
wfMessage( $msgKey )->escaped();
1942 $tag = $restricted ?
'strong' :
'span';
1943 $link = self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
1944 return Html::rawElement(
1946 [
'class' =>
'mw-revdelundel-link' ],
1947 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
1963 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1964 $html =
wfMessage( $msgKey )->escaped();
1965 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
1966 return Html::rawElement(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
1984 array $msgParams = [],
1988 $options = (array)$options;
1989 $options[] =
'withaccess';
1992 if ( !$localizer ) {
1993 $localizer = self::getContextFromMain();
1997 'title' => self::titleAttrib( $name, $options, $msgParams, $localizer ),
1998 'accesskey' => self::accesskey( $name, $localizer )
2000 if ( $attribs[
'title'] ===
false ) {
2001 unset( $attribs[
'title'] );
2003 if ( $attribs[
'accesskey'] ===
false ) {
2004 unset( $attribs[
'accesskey'] );
2016 public static function tooltip( $name, $options =
null ) {
2017 $tooltip = self::titleAttrib( $name, $options );
2018 if ( $tooltip ===
false ) {
2021 return Html::expandAttributes( [
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
An IContextSource implementation which will inherit context from another source but allow individual ...
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
const UploadNavigationUrl
Name constant for the UploadNavigationUrl setting, for use with Config::get()
const ThumbUpright
Name constant for the ThumbUpright setting, for use with Config::get()
const EnableUploads
Name constant for the EnableUploads setting, for use with Config::get()
const SVGMaxSize
Name constant for the SVGMaxSize setting, for use with Config::get()
const ResponsiveImages
Name constant for the ResponsiveImages setting, for use with Config::get()
const DisableAnonTalk
Name constant for the DisableAnonTalk setting, for use with Config::get()
const ThumbLimits
Name constant for the ThumbLimits setting, for use with Config::get()
const UploadMissingFileUrl
Name constant for the UploadMissingFileUrl setting, for use with Config::get()
Parent class for all special pages.
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,...
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.
msg( $key,... $params)
This is the method for getting translated interface messages.