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";
103 $options = (array)$options;
104 $linkRenderer = self::getLinkRenderer( $options );
106 if ( $html !==
null ) {
112 if ( in_array(
'known', $options,
true ) ) {
113 return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
116 if ( in_array(
'broken', $options,
true ) ) {
117 return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
120 if ( in_array(
'noclasses', $options,
true ) ) {
121 return $linkRenderer->makePreloadedLink( $target, $text,
'', $customAttribs, $query );
124 return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
147 $target, $html =
null, $customAttribs = [],
148 $query = [], $options = [
'known' ]
150 return self::link( $target, $html, $customAttribs, $query, $options );
170 public static function makeSelfLinkObj( $nt, $html =
'', $query =
'', $trail =
'', $prefix =
'', $hash =
'' ) {
171 $nt = Title::newFromLinkTarget( $nt );
174 $attrs[
'class'] =
'mw-selflink-fragment';
175 $attrs[
'href'] =
'#' . $hash;
178 $attrs[
'class'] =
'mw-selflink selflink';
180 $ret = Html::rawElement(
'a', $attrs, $prefix . $html ) . $trail;
182 if ( !$hookRunner->onSelfLinkBegin( $nt, $html, $trail, $prefix, $ret ) ) {
187 $html = htmlspecialchars( $nt->getPrefixedText() );
190 return Html::rawElement(
'a', $attrs, $prefix . $html . $inside ) . $trail;
207 $name = $context->
msg(
'blanknamespace' )->text();
210 getFormattedNsText( $namespace );
212 return $context->
msg(
'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
215 return $context->
msg(
'invalidtitle-unknownnamespace', $namespace, $title )->text();
226 private static function fnamePart(
$url ) {
227 $basename = strrchr(
$url,
'/' );
228 if ( $basename ===
false ) {
231 $basename = substr( $basename, 1 );
248 $alt = self::fnamePart(
$url );
252 ->onLinkerMakeExternalImage(
$url, $alt, $img );
254 wfDebug(
"Hook LinkerMakeExternalImage changed the output of external image "
255 .
"with url {$url} and alt text {$alt} to {$img}" );
305 $file, $frameParams = [], $handlerParams = [], $time =
false,
306 $query =
'', $widthOption =
null
308 $title = Title::newFromLinkTarget( $title );
311 if ( !$hookRunner->onImageBeforeProduceHTML(
null, $title,
313 $file, $frameParams, $handlerParams, $time, $res,
315 $parser, $query, $widthOption )
320 if ( $file && !$file->allowInlineDisplay() ) {
321 wfDebug( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
' does not allow inline display' );
326 $page = $handlerParams[
'page'] ??
false;
327 if ( !isset( $frameParams[
'align'] ) ) {
328 $frameParams[
'align'] =
'';
330 if ( !isset( $frameParams[
'title'] ) ) {
331 $frameParams[
'title'] =
'';
333 if ( !isset( $frameParams[
'class'] ) ) {
334 $frameParams[
'class'] =
'';
338 $config = $services->getMainConfig();
342 !isset( $handlerParams[
'width'] ) &&
343 !isset( $frameParams[
'manualthumb'] ) &&
344 !isset( $frameParams[
'framed'] )
346 $classes[] =
'mw-default-size';
349 $prefix = $postfix =
'';
351 if ( $file && !isset( $handlerParams[
'width'] ) ) {
352 if ( isset( $handlerParams[
'height'] ) && $file->isVectorized() ) {
356 $handlerParams[
'width'] = $svgMaxSize;
358 $handlerParams[
'width'] = $file->getWidth( $page );
361 if ( isset( $frameParams[
'thumbnail'] )
362 || isset( $frameParams[
'manualthumb'] )
363 || isset( $frameParams[
'framed'] )
364 || isset( $frameParams[
'frameless'] )
365 || !$handlerParams[
'width']
369 if ( $widthOption ===
null || !isset( $thumbLimits[$widthOption] ) ) {
370 $userOptionsLookup = $services->getUserOptionsLookup();
375 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
376 $frameParams[
'upright'] = $thumbUpright;
382 $prefWidth = isset( $frameParams[
'upright'] ) ?
383 round( $thumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
384 $thumbLimits[$widthOption];
388 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
389 $prefWidth < $handlerParams[
'width'] || $file->isVectorized() ) ) {
390 $handlerParams[
'width'] = $prefWidth;
396 $hasVisibleCaption = isset( $frameParams[
'thumbnail'] ) ||
397 isset( $frameParams[
'manualthumb'] ) ||
398 isset( $frameParams[
'framed'] );
400 if ( $hasVisibleCaption ) {
402 $title, $file, $frameParams, $handlerParams, $time, $query,
407 $rdfaType =
'mw:File';
409 if ( isset( $frameParams[
'frameless'] ) ) {
410 $rdfaType .=
'/Frameless';
412 $srcWidth = $file->getWidth( $page );
413 # For "frameless" option: do not present an image bigger than the
414 # source (for bitmap-style images). This is the same behavior as the
415 # "thumb" option does it already.
416 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
417 $handlerParams[
'width'] = $srcWidth;
422 if ( $file && isset( $handlerParams[
'width'] ) ) {
423 # Create a resized image, without the additional thumbnail features
424 $thumb = $file->transform( $handlerParams );
429 $isBadFile = $file && $thumb &&
432 if ( !$thumb || $thumb->isError() || $isBadFile ) {
433 $rdfaType =
'mw:Error ' . $rdfaType;
434 $currentExists = $file && $file->exists();
435 if ( $currentExists && !$thumb ) {
436 $label =
wfMessage(
'thumbnail_error',
'' )->text();
437 } elseif ( $thumb && $thumb->isError() ) {
440 'Unknown MediaTransformOutput: ' . get_class( $thumb )
442 $label = $thumb->toText();
444 $label = $frameParams[
'alt'] ??
'';
447 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams, $currentExists
455 if ( isset( $frameParams[
'alt'] ) ) {
456 $params[
'alt'] = $frameParams[
'alt'];
458 $params[
'title'] = $frameParams[
'title'];
460 'img-class' =>
'mw-file-element',
463 $s = $thumb->toHtml( $params );
469 if ( $frameParams[
'align'] !=
'' ) {
472 $classes[] =
"mw-halign-{$frameParams['align']}";
473 $caption = Html::rawElement(
474 'figcaption', [], $frameParams[
'caption'] ??
''
476 } elseif ( isset( $frameParams[
'valign'] ) ) {
480 $classes[] =
"mw-valign-{$frameParams['valign']}";
483 if ( isset( $frameParams[
'border'] ) ) {
484 $classes[] =
'mw-image-border';
487 if ( isset( $frameParams[
'class'] ) ) {
488 $classes[] = $frameParams[
'class'];
493 'typeof' => $rdfaType,
496 $s = Html::rawElement( $wrapper, $attribs, $s . $caption );
498 return str_replace(
"\n",
' ', $s );
511 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
512 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
513 if ( isset( $frameParams[
'link-target'] ) ) {
514 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
517 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
518 foreach ( $extLinkAttrs as $name => $val ) {
520 $mtoParams[
'parser-extlink-' . $name] = $val;
523 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
524 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
525 self::getLinkRenderer()->normalizeTarget( $frameParams[
'link-title'] )
527 if ( isset( $frameParams[
'link-title-query'] ) ) {
528 $mtoParams[
'custom-title-link-query'] = $frameParams[
'link-title-query'];
530 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
533 $mtoParams[
'desc-link'] =
true;
534 $mtoParams[
'desc-query'] = $query;
552 LinkTarget $title, $file, $label =
'', $alt =
'', $align =
null,
553 $params = [], $framed =
false, $manualthumb =
''
561 if ( $manualthumb ) {
562 $frameParams[
'manualthumb'] = $manualthumb;
563 } elseif ( $framed ) {
564 $frameParams[
'framed'] =
true;
565 } elseif ( !isset( $params[
'width'] ) ) {
566 $classes[] =
'mw-default-size';
569 $title, $file, $frameParams, $params,
false,
'', $classes
585 LinkTarget $title, $file, $frameParams = [], $handlerParams = [],
586 $time =
false, $query =
'', array $classes = [], ?
Parser $parser =
null
588 $exists = $file && $file->exists();
591 $page = $handlerParams[
'page'] ??
false;
592 $lang = $handlerParams[
'lang'] ??
false;
594 if ( !isset( $frameParams[
'align'] ) ) {
595 $frameParams[
'align'] =
'';
597 if ( !isset( $frameParams[
'caption'] ) ) {
598 $frameParams[
'caption'] =
'';
601 if ( empty( $handlerParams[
'width'] ) ) {
603 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
608 $manualthumb =
false;
610 $rdfaType =
'mw:File/Thumb';
614 if ( !isset( $frameParams[
'manualthumb'] ) && isset( $frameParams[
'framed'] ) ) {
615 $rdfaType =
'mw:File/Frame';
617 $outerWidth = $handlerParams[
'width'] + 2;
619 if ( isset( $frameParams[
'manualthumb'] ) ) {
620 # Use manually specified thumbnail
621 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
622 if ( $manual_title ) {
623 $manual_img = $services->getRepoGroup()
624 ->findFile( $manual_title );
626 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
631 $srcWidth = $file->getWidth( $page );
632 if ( isset( $frameParams[
'framed'] ) ) {
633 $rdfaType =
'mw:File/Frame';
634 if ( !$file->isVectorized() ) {
640 $handlerParams[
'width'] = $srcWidth;
646 if ( $srcWidth && !$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
647 $handlerParams[
'width'] = $srcWidth;
651 ? $file->getUnscaledThumb( $handlerParams )
652 : $file->transform( $handlerParams );
656 $outerWidth = $thumb->getWidth() + 2;
658 $outerWidth = $handlerParams[
'width'] + 2;
662 if ( $parser && $rdfaType ===
'mw:File/Thumb' ) {
663 $parser->getOutput()->addModules( [
'mediawiki.page.media' ] );
666 $url = Title::newFromLinkTarget( $title )->getLocalURL( $query );
667 $linkTitleQuery = [];
668 if ( $page || $lang ) {
670 $linkTitleQuery[
'page'] = $page;
673 $linkTitleQuery[
'lang'] = $lang;
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
682 && !isset( $frameParams[
'link-title'] )
683 && !isset( $frameParams[
'link-url'] )
684 && !isset( $frameParams[
'no-link'] ) ) {
685 $frameParams[
'link-title'] = $title;
686 $frameParams[
'link-title-query'] = $linkTitleQuery;
689 if ( $frameParams[
'align'] !=
'' ) {
691 $classes[] =
"mw-halign-{$frameParams['align']}";
694 if ( isset( $frameParams[
'class'] ) ) {
695 $classes[] = $frameParams[
'class'];
700 $isBadFile = $exists && $thumb && $parser &&
701 $parser->getBadFileLookup()->isBadFile(
702 $manualthumb ? $manual_title->getDBkey() : $title->
getDBkey(),
707 $rdfaType =
'mw:Error ' . $rdfaType;
708 $label = $frameParams[
'alt'] ??
'';
710 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
false
713 } elseif ( !$thumb || $thumb->isError() || $isBadFile ) {
714 $rdfaType =
'mw:Error ' . $rdfaType;
715 if ( $thumb && $thumb->isError() ) {
718 'Unknown MediaTransformOutput: ' . get_class( $thumb )
720 $label = $thumb->toText();
721 } elseif ( !$thumb ) {
722 $label =
wfMessage(
'thumbnail_error',
'' )->text();
727 $title, $label,
'',
'',
'', (
bool)$time, $handlerParams,
true
731 if ( !$noscale && !$manualthumb ) {
738 if ( isset( $frameParams[
'alt'] ) ) {
739 $params[
'alt'] = $frameParams[
'alt'];
742 'img-class' =>
'mw-file-element',
745 if ( $rdfaType ===
'mw:File/Thumb' ) {
746 $params[
'magnify-resource'] =
$url;
749 $s .= $thumb->toHtml( $params );
750 if ( isset( $frameParams[
'framed'] ) ) {
753 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
754 Html::rawElement(
'a', [
756 'class' =>
'internal',
757 'title' =>
wfMessage(
'thumbnail-more' )->text(),
763 $s .= Html::rawElement(
764 'figcaption', [], $frameParams[
'caption'] ??
''
769 'typeof' => $rdfaType,
772 $s = Html::rawElement(
'figure', $attribs, $s );
774 return str_replace(
"\n",
' ', $s );
787 if ( $responsiveImages && $thumb && !$thumb->isError() ) {
789 $hp15[
'width'] = round( $hp[
'width'] * 1.5 );
791 $hp20[
'width'] = $hp[
'width'] * 2;
792 if ( isset( $hp[
'height'] ) ) {
793 $hp15[
'height'] = round( $hp[
'height'] * 1.5 );
794 $hp20[
'height'] = $hp[
'height'] * 2;
797 $thumb15 = $file->transform( $hp15 );
798 $thumb20 = $file->transform( $hp20 );
799 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
800 $thumb->responsiveUrls[
'1.5'] = $thumb15->getUrl();
802 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
803 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
823 $title, $label =
'', $query =
'', $unused1 =
'', $unused2 =
'',
824 $time =
false, array $handlerParams = [],
bool $currentExists =
false
827 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
828 return "<!-- ERROR -->" . htmlspecialchars( $label );
831 $title = Title::newFromLinkTarget( $title );
833 $mainConfig = $services->getMainConfig();
837 if ( $label ==
'' ) {
838 $label = $title->getPrefixedText();
842 'class' =>
'mw-file-element mw-broken-media',
844 'data-width' => $handlerParams[
'width'] ??
null,
845 'data-height' => $handlerParams[
'height'] ??
null,
848 $repoGroup = $services->getRepoGroup();
849 $currentExists = $currentExists ||
850 ( $time && $repoGroup->findFile( $title ) !== false );
852 if ( ( $uploadMissingFileUrl || $uploadNavigationUrl || $enableUploads )
856 $title->inNamespace(
NS_FILE ) &&
857 $repoGroup->getLocalRepo()->checkRedirect( $title )
863 [
'class' =>
'mw-redirect' ],
865 [
'known',
'noclasses' ]
868 return Html::rawElement(
'a', [
869 'href' => self::getUploadUrl( $title, $query ),
871 'title' => $title->getPrefixedText()
879 [
'known',
'noclasses' ]
895 $q =
'wpDestFile=' . Title::newFromLinkTarget( $destFile )->getPartialURL();
896 if ( $query !=
'' ) {
900 if ( $uploadMissingFileUrl ) {
904 if ( $uploadNavigationUrl ) {
910 return $upload->getLocalURL( $q );
924 $title, [
'time' => $time ]
942 if ( $file && $file->exists() ) {
943 $url = $file->getUrl();
963 Title::newFromLinkTarget( $title ), $file, $html, $attribs, $ret )
965 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
966 .
"with url {$url} and text {$html} to {$ret}" );
970 return Html::rawElement(
'a', $attribs, $html );
984 $queryPos = strpos( $name,
'?' );
985 if ( $queryPos !==
false ) {
986 $getParams =
wfCgiToArray( substr( $name, $queryPos + 1 ) );
987 $name = substr( $name, 0, $queryPos );
992 $slashPos = strpos( $name,
'/' );
993 if ( $slashPos !==
false ) {
994 $subpage = substr( $name, $slashPos + 1 );
995 $name = substr( $name, 0, $slashPos );
1001 $key = strtolower( $name );
1033 $linktype =
'', $attribs = [], $title =
null
1037 return self::getLinkRenderer()->makeExternalLink(
1039 $escape ? $text :
new HtmlArmor( $text ),
1063 $altUserName =
false,
1066 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
1067 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1068 'that need to be fixed?' );
1069 return wfMessage(
'empty-username' )->parse();
1072 return self::getLinkRenderer()->makeUserLink(
1074 RequestContext::getMain(),
1075 $altUserName ===
false ?
null : (string)$altUserName,
1099 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null
1103 $talkable = !( $disableAnonTalk && $userId == 0 );
1105 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
1107 if ( $userId == 0 && ExternalUserNames::isExternal( $userText ) ) {
1120 if ( $userId && !$services->getTempUserConfig()->isTempName( $userText ) ) {
1122 $attribs[
'class'] =
'mw-usertoollinks-contribs';
1125 if ( $redContribsWhenNoEdits ) {
1126 if ( $edits ===
null ) {
1127 $user = UserIdentityValue::newRegistered( $userId, $userText );
1128 $edits = $services->getUserEditTracker()->getUserEditCount( $user );
1130 if ( $edits === 0 ) {
1133 $attribs[
'class'] .=
' mw-usertoollinks-contribs-no-edits';
1140 $userCanBlock = RequestContext::getMain()->getAuthority()->isAllowed(
'block' );
1141 if ( $blockable && $userCanBlock ) {
1148 ->newEmailUser( RequestContext::getMain()->
getAuthority() )
1155 (
new HookRunner( $services->getHookContainer() ) )->onUserToolLinksEdit( $userId, $userText, $items );
1174 if ( $useParentheses ) {
1175 return wfMessage(
'word-separator' )->escaped()
1176 .
'<span class="mw-usertoollinks">'
1177 .
wfMessage(
'parentheses' )->rawParams(
$wgLang->pipeList( $items ) )->escaped()
1182 foreach ( $items as $tool ) {
1183 $tools[] = Html::rawElement(
'span', [], $tool );
1185 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1186 implode(
' ', $tools ) .
'</span>';
1204 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
1205 $useParentheses =
true
1207 if ( $userText ===
'' ) {
1208 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1209 'that need to be fixed?' );
1210 return ' ' .
wfMessage(
'empty-username' )->parse();
1213 $items = self::userToolLinkArray( $userId, $userText, $redContribsWhenNoEdits, $flags, $edits );
1214 return self::renderUserToolLinksArray( $items, $useParentheses );
1227 $userId, $userText, $edits =
null, $useParentheses =
true
1229 return self::userToolLinks( $userId, $userText,
true, 0, $edits, $useParentheses );
1239 if ( $userText ===
'' ) {
1240 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1241 'that need to be fixed?' );
1242 return wfMessage(
'empty-username' )->parse();
1245 $userTalkPage = TitleValue::tryNew(
NS_USER_TALK, strtr( $userText,
' ',
'_' ) );
1246 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1247 $linkText =
wfMessage(
'talkpagelinktext' )->escaped();
1249 return $userTalkPage
1250 ? self::link( $userTalkPage, $linkText, $moreLinkAttribs )
1251 : Html::rawElement(
'span', $moreLinkAttribs, $linkText );
1261 if ( $userText ===
'' ) {
1262 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1263 'that need to be fixed?' );
1264 return wfMessage(
'empty-username' )->parse();
1267 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1268 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1270 return self::link( $blockPage,
1282 if ( $userText ===
'' ) {
1283 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1284 'that need to be fixed?' );
1285 return wfMessage(
'empty-username' )->parse();
1288 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1289 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1290 return self::link( $emailPage,
1309 $authority = RequestContext::getMain()->getAuthority();
1311 $revUser = $revRecord->
getUser(
1312 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1316 $link = self::userLink( $revUser->getId(), $revUser->getName() );
1319 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1322 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1323 $class = self::getRevisionDeletedClass( $revRecord );
1324 return '<span class="' . $class .
'">' . $link .
'</span>';
1336 $class =
'history-deleted';
1337 if ( $revisionRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
1338 $class .=
' mw-history-suppressed';
1358 $useParentheses =
true
1361 $authority = RequestContext::getMain()->getAuthority();
1363 $revUser = $revRecord->
getUser(
1364 $isPublic ? RevisionRecord::FOR_PUBLIC : RevisionRecord::FOR_THIS_USER,
1368 $link = self::userLink(
1370 $revUser->getName(),
1372 [
'data-mw-revid' => $revRecord->
getId() ]
1373 ) . self::userToolLinks(
1375 $revUser->getName(),
1383 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1386 if ( $revRecord->
isDeleted( RevisionRecord::DELETED_USER ) ) {
1387 $class = self::getRevisionDeletedClass( $revRecord );
1388 return ' <span class="' . $class .
' mw-userlink">' . $link .
'</span>';
1404 return HtmlHelper::modifyElements(
1406 static function ( SerializerNode $node ):
bool {
1407 return $node->name ===
'a' && isset( $node->attrs[
'href'] );
1409 static function ( SerializerNode $node ): SerializerNode {
1410 $urlUtils = MediaWikiServices::getInstance()->getUrlUtils();
1411 $node->attrs[
'href'] =
1412 $urlUtils->expand( $node->attrs[
'href'],
PROTO_RELATIVE ) ??
false;
1427 # :Foobar -- override special treatment of prefix (images, language links)
1428 # /Foobar -- convert to CurrentPage/Foobar
1429 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1430 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1431 # ../Foobar -- convert to CurrentPage/Foobar,
1432 # (from CurrentPage/CurrentSubPage)
1433 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1434 # (from CurrentPage/CurrentSubPage)
1436 $ret = $target; #
default return value is no change
1438 # Some namespaces don't allow subpages,
1439 # so only perform processing if subpages are allowed
1441 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1442 hasSubpages( $contextTitle->getNamespace() )
1444 $hash = strpos( $target,
'#' );
1445 if ( $hash !==
false ) {
1446 $suffix = substr( $target, $hash );
1447 $target = substr( $target, 0, $hash );
1452 $target = trim( $target );
1453 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1454 getPrefixedText( $contextTitle );
1455 # Look at the first character
1456 if ( $target !=
'' && $target[0] ===
'/' ) {
1457 # / at end means we don't want the slash to be shown
1459 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1460 if ( $trailingSlashes ) {
1461 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1463 $noslash = substr( $target, 1 );
1466 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1467 if ( $text ===
'' ) {
1468 $text = $target . $suffix;
1469 } #
this might be changed
for ugliness reasons
1471 # check for .. subpage backlinks
1473 $nodotdot = $target;
1474 while ( str_starts_with( $nodotdot,
'../' ) ) {
1476 $nodotdot = substr( $nodotdot, 3 );
1478 if ( $dotdotcount > 0 ) {
1479 $exploded = explode(
'/', $contextPrefixedText );
1480 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1481 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1482 # / at the end means don't show full path
1483 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1484 $nodotdot = rtrim( $nodotdot,
'/' );
1485 if ( $text ===
'' ) {
1486 $text = $nodotdot . $suffix;
1489 $nodotdot = trim( $nodotdot );
1490 if ( $nodotdot !=
'' ) {
1491 $ret .=
'/' . $nodotdot;
1509 $stxt =
wfMessage(
'historyempty' )->escaped();
1511 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1513 return "<span class=\"history-size mw-diff-bytes\" data-mw-bytes=\"$size\">$stxt</span>";
1523 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1525 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1526 [ , $inside, $trail ] = $m;
1528 return [ $inside, $trail ];
1566 $context ??= RequestContext::getMain();
1568 $editCount = self::getRollbackEditCount( $revRecord );
1569 if ( $editCount ===
false ) {
1573 $inner = self::buildRollbackLink( $revRecord, $context, $editCount );
1575 $services = MediaWikiServices::getInstance();
1578 if ( !(
new HookRunner( $services->getHookContainer() ) )->onLinkerGenerateRollbackLink(
1579 $revRecord, $context, $options, $inner ) ) {
1583 if ( !in_array(
'noBrackets', $options,
true ) ) {
1584 $inner = $context->msg(
'brackets' )->rawParams( $inner )->escaped();
1587 if ( $services->getUserOptionsLookup()
1588 ->getBoolOption( $context->getUser(),
'showrollbackconfirmation' )
1590 $context->getOutput()->addModules(
'mediawiki.misc-authed-curate' );
1593 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1615 if ( func_num_args() > 1 ) {
1616 wfDeprecated( __METHOD__ .
' with $verify parameter',
'1.40' );
1618 $showRollbackEditCount = MediaWikiServices::getInstance()->getMainConfig()
1619 ->get( MainConfigNames::ShowRollbackEditCount );
1621 if ( !is_int( $showRollbackEditCount ) || !$showRollbackEditCount > 0 ) {
1626 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
1629 $queryBuilder = MediaWikiServices::getInstance()->getRevisionStore()->newSelectQueryBuilder( $dbr );
1630 $res = $queryBuilder->where( [
'rev_page' => $revRecord->
getPageId() ] )
1631 ->useIndex( [
'revision' =>
'rev_page_timestamp' ] )
1632 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
1633 ->limit( $showRollbackEditCount + 1 )
1634 ->caller( __METHOD__ )->fetchResultSet();
1636 $revUser = $revRecord->
getUser( RevisionRecord::RAW );
1637 $revUserText = $revUser ? $revUser->getName() :
'';
1641 foreach ( $res as $row ) {
1642 if ( $row->rev_user_text != $revUserText ) {
1643 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1644 || $row->rev_deleted & RevisionRecord::DELETED_USER
1657 if ( $editCount <= $showRollbackEditCount && !$moreRevs ) {
1685 $config = MediaWikiServices::getInstance()->getMainConfig();
1686 $showRollbackEditCount = $config->get( MainConfigNames::ShowRollbackEditCount );
1687 $miserMode = $config->get( MainConfigNames::MiserMode );
1689 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1691 $context ??= RequestContext::getMain();
1694 $revUser = $revRecord->
getUser();
1695 $revUserText = $revUser ? $revUser->getName() :
'';
1698 'action' =>
'rollback',
1699 'from' => $revUserText,
1700 'token' => $context->getUser()->getEditToken(
'rollback' ),
1704 'data-mw-interface' =>
'',
1705 'title' => $context->msg(
'tooltip-rollback' )->text()
1708 $options = [
'known',
'noclasses' ];
1710 if ( $context->getRequest()->getBool(
'bot' ) ) {
1712 $query[
'hidediff'] =
'1';
1713 $query[
'bot'] =
'1';
1717 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1718 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1719 $showRollbackEditCount =
false;
1726 $msg = [
'rollbacklink' ];
1727 if ( is_int( $showRollbackEditCount ) && $showRollbackEditCount > 0 ) {
1728 if ( !is_numeric( $editCount ) ) {
1729 $editCount = self::getRollbackEditCount( $revRecord );
1732 if ( $editCount > $showRollbackEditCount ) {
1733 $msg = [
'rollbacklinkcount-morethan', Message::numParam( $showRollbackEditCount ) ];
1734 } elseif ( $editCount ) {
1735 $msg = [
'rollbacklinkcount', Message::numParam( $editCount ) ];
1739 $html = $context->msg( ...$msg )->parse();
1740 return self::link( $title, $html, $attrs, $query, $options );
1753 if ( count( $hiddencats ) > 0 ) {
1754 # Construct the HTML
1755 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1756 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1757 $outText .=
"</div><ul>\n";
1759 foreach ( $hiddencats as $titleObj ) {
1760 # If it's hidden, it must exist - no need to check with a LinkBatch
1762 . self::link( $titleObj,
null, [], [],
'known' )
1765 $outText .=
'</ul>';
1773 private static function getContextFromMain() {
1774 $context = RequestContext::getMain();
1796 public static function titleAttrib( $name, $options =
null, array $msgParams = [], $localizer =
null ) {
1797 if ( !$localizer ) {
1798 $localizer = self::getContextFromMain();
1800 $message = $localizer->msg(
"tooltip-$name", $msgParams );
1803 if ( !$message->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1804 $message = $localizer->msg(
'tooltip-ca-nstab' );
1807 if ( $message->isDisabled() ) {
1810 $tooltip = $message->text();
1811 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1812 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
1815 $options = (array)$options;
1817 if ( in_array(
'nonexisting', $options ) ) {
1818 $tooltip = $localizer->msg(
'red-link-title', $tooltip ?:
'' )->text();
1820 if ( in_array(
'withaccess', $options ) ) {
1821 $accesskey = self::accesskey( $name, $localizer );
1822 if ( $accesskey !==
false ) {
1824 if ( $tooltip ===
false || $tooltip ===
'' ) {
1825 $tooltip = $localizer->msg(
'brackets', $accesskey )->text();
1827 $tooltip .= $localizer->msg(
'word-separator' )->text();
1828 $tooltip .= $localizer->msg(
'brackets', $accesskey )->text();
1851 public static function accesskey( $name, $localizer =
null ) {
1852 if ( !isset( self::$accesskeycache[$name] ) ) {
1853 if ( !$localizer ) {
1854 $localizer = self::getContextFromMain();
1856 $msg = $localizer->msg(
"accesskey-$name" );
1859 if ( !$msg->exists() && str_starts_with( $name,
'ca-nstab-' ) ) {
1860 $msg = $localizer->msg(
'accesskey-ca-nstab' );
1862 self::$accesskeycache[$name] = $msg->isDisabled() ? false : $msg->plain();
1864 return self::$accesskeycache[$name];
1886 $canHide = $performer->
isAllowed(
'deleterevision' );
1887 $canHideHistory = $performer->
isAllowed(
'deletedhistory' );
1888 if ( !$canHide && !( $revRecord->
getVisibility() && $canHideHistory ) ) {
1892 if ( !$revRecord->
userCan( RevisionRecord::DELETED_RESTRICTED, $performer ) ) {
1893 return self::revDeleteLinkDisabled( $canHide );
1895 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
1896 getPrefixedDBkey( $title );
1897 if ( $revRecord->
getId() ) {
1901 'type' =>
'revision',
1902 'target' => $prefixedDbKey,
1903 'ids' => $revRecord->
getId()
1909 'type' =>
'archive',
1910 'target' => $prefixedDbKey,
1914 return self::revDeleteLink(
1916 $revRecord->
isDeleted( RevisionRecord::DELETED_RESTRICTED ),
1933 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
1934 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
1935 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1936 $html =
wfMessage( $msgKey )->escaped();
1937 $tag = $restricted ?
'strong' :
'span';
1938 $link = self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
1939 return Html::rawElement(
1941 [
'class' =>
'mw-revdelundel-link' ],
1942 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
1958 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
1959 $html =
wfMessage( $msgKey )->escaped();
1960 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
1961 return Html::rawElement(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
1979 array $msgParams = [],
1983 $options = (array)$options;
1984 $options[] =
'withaccess';
1987 if ( !$localizer ) {
1988 $localizer = self::getContextFromMain();
1992 'title' => self::titleAttrib( $name, $options, $msgParams, $localizer ),
1993 'accesskey' => self::accesskey( $name, $localizer )
1995 if ( $attribs[
'title'] ===
false ) {
1996 unset( $attribs[
'title'] );
1998 if ( $attribs[
'accesskey'] ===
false ) {
1999 unset( $attribs[
'accesskey'] );
2011 public static function tooltip( $name, $options =
null ) {
2012 $tooltip = self::titleAttrib( $name, $options );
2013 if ( $tooltip ===
false ) {
2016 return Html::expandAttributes( [
2025 private static function getLinkRenderer(
2026 array $legacyOptions = []
2030 if ( count( $legacyOptions ) > 0 ) {
2036 return $services->getLinkRenderer();
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.