85 public static function link(
86 $target, $html =
null, $customAttribs = [], $query = [], $options = []
89 wfWarn( __METHOD__ .
': Requires $target to be a LinkTarget object.', 2 );
90 return "<!-- ERROR -->$html";
93 $services = MediaWikiServices::getInstance();
94 $options = (array)$options;
97 if ( !isset( $options[
'stubThreshold'] ) ) {
98 $defaultLinkRenderer = $services->getLinkRenderer();
99 $options[
'stubThreshold'] = $defaultLinkRenderer->getStubThreshold();
101 $linkRenderer = $services->getLinkRendererFactory()
102 ->createFromLegacyOptions( $options );
104 $linkRenderer = $services->getLinkRenderer();
107 if ( $html !==
null ) {
113 if ( in_array(
'known', $options,
true ) ) {
114 return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
117 if ( in_array(
'broken', $options,
true ) ) {
118 return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
121 if ( in_array(
'noclasses', $options,
true ) ) {
122 return $linkRenderer->makePreloadedLink( $target, $text,
'', $customAttribs, $query );
125 return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
142 $target, $html =
null, $customAttribs = [],
143 $query = [], $options = [
'known' ]
145 return self::link( $target, $html, $customAttribs, $query, $options );
163 public static function makeSelfLinkObj( $nt, $html =
'', $query =
'', $trail =
'', $prefix =
'' ) {
164 $nt = Title::newFromLinkTarget( $nt );
165 $ret =
"<a class=\"mw-selflink selflink\">{$prefix}{$html}</a>{$trail}";
166 if ( !Hooks::run(
'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
171 $html = htmlspecialchars( $nt->getPrefixedText() );
174 return "<a class=\"mw-selflink selflink\">{$prefix}{$html}{$inside}</a>{$trail}";
189 if ( MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $namespace ) ) {
191 $name =
$context->msg(
'blanknamespace' )->text();
193 $name = MediaWikiServices::getInstance()->getContentLanguage()->
194 getFormattedNsText( $namespace );
196 return $context->msg(
'invalidtitle-knownnamespace', $namespace, $name,
$title )->text();
199 return $context->msg(
'invalidtitle-unknownnamespace', $namespace,
$title )->text();
209 list( $name, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
210 resolveAlias( $target->
getDBkey() );
212 return SpecialPage::getTitleValueFor( $name, $subpage, $target->
getFragment() );
228 $basename = strrchr( $url,
'/' );
229 if ( $basename ===
false ) {
232 $basename = substr( $basename, 1 );
252 $success = Hooks::run(
'LinkerMakeExternalImage', [ &$url, &$alt, &$img ] );
254 wfDebug(
"Hook LinkerMakeExternalImage changed the output of external image "
255 .
"with url {$url} and alt text {$alt} to {$img}\n",
true );
258 return Html::element(
'img',
304 $file, $frameParams = [], $handlerParams = [], $time =
false,
305 $query =
"", $widthOption =
null
310 if ( !Hooks::run(
'ImageBeforeProduceHTML', [ &$dummy, &
$title,
311 &
$file, &$frameParams, &$handlerParams, &$time, &
$res,
312 $parser, &$query, &$widthOption
317 if (
$file && !
$file->allowInlineDisplay() ) {
318 wfDebug( __METHOD__ .
': ' .
$title->getPrefixedDBkey() .
" does not allow inline display\n" );
323 $page = $handlerParams[
'page'] ??
false;
324 if ( !isset( $frameParams[
'align'] ) ) {
325 $frameParams[
'align'] =
'';
327 if ( !isset( $frameParams[
'alt'] ) ) {
328 $frameParams[
'alt'] =
'';
330 if ( !isset( $frameParams[
'title'] ) ) {
331 $frameParams[
'title'] =
'';
333 if ( !isset( $frameParams[
'class'] ) ) {
334 $frameParams[
'class'] =
'';
337 $prefix = $postfix =
'';
339 if ( $frameParams[
'align'] ==
'center' ) {
340 $prefix =
'<div class="center">';
342 $frameParams[
'align'] =
'none';
344 if (
$file && !isset( $handlerParams[
'width'] ) ) {
345 if ( isset( $handlerParams[
'height'] ) &&
$file->isVectorized() ) {
351 $handlerParams[
'width'] =
$file->getWidth( $page );
354 if ( isset( $frameParams[
'thumbnail'] )
355 || isset( $frameParams[
'manualthumb'] )
356 || isset( $frameParams[
'framed'] )
357 || isset( $frameParams[
'frameless'] )
358 || !$handlerParams[
'width']
362 if ( $widthOption ===
null || !isset(
$wgThumbLimits[$widthOption] ) ) {
363 $widthOption = User::getDefaultOption(
'thumbsize' );
367 if ( isset( $frameParams[
'upright'] ) && $frameParams[
'upright'] == 0 ) {
374 $prefWidth = isset( $frameParams[
'upright'] ) ?
375 round(
$wgThumbLimits[$widthOption] * $frameParams[
'upright'], -1 ) :
380 if ( !isset( $handlerParams[
'height'] ) && ( $handlerParams[
'width'] <= 0 ||
381 $prefWidth < $handlerParams[
'width'] ||
$file->isVectorized() ) ) {
382 $handlerParams[
'width'] = $prefWidth;
387 if ( isset( $frameParams[
'thumbnail'] ) || isset( $frameParams[
'manualthumb'] )
388 || isset( $frameParams[
'framed'] )
390 # Create a thumbnail. Alignment depends on the writing direction of
391 # the page content language (right-aligned for LTR languages,
392 # left-aligned for RTL languages)
393 # If a thumbnail width has not been provided, it is set
394 # to the default user option as specified in Language*.php
395 if ( $frameParams[
'align'] ==
'' ) {
403 if (
$file && isset( $frameParams[
'frameless'] ) ) {
404 $srcWidth =
$file->getWidth( $page );
405 # For "frameless" option: do not present an image bigger than the
406 # source (for bitmap-style images). This is the same behavior as the
407 # "thumb" option does it already.
408 if ( $srcWidth && !
$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
409 $handlerParams[
'width'] = $srcWidth;
413 if (
$file && isset( $handlerParams[
'width'] ) ) {
414 # Create a resized image, without the additional thumbnail features
415 $thumb =
$file->transform( $handlerParams );
425 'alt' => $frameParams[
'alt'],
426 'title' => $frameParams[
'title'],
427 'valign' => $frameParams[
'valign'] ??
false,
428 'img-class' => $frameParams[
'class'] ];
429 if ( isset( $frameParams[
'border'] ) ) {
430 $params[
'img-class'] .= ( $params[
'img-class'] !==
'' ?
' ' :
'' ) .
'thumbborder';
434 $s = $thumb->toHtml( $params );
436 if ( $frameParams[
'align'] !=
'' ) {
437 $s = Html::rawElement(
439 [
'class' =>
'float' . $frameParams[
'align'] ],
443 return str_replace(
"\n",
' ', $prefix .
$s . $postfix );
456 if ( isset( $frameParams[
'link-url'] ) && $frameParams[
'link-url'] !==
'' ) {
457 $mtoParams[
'custom-url-link'] = $frameParams[
'link-url'];
458 if ( isset( $frameParams[
'link-target'] ) ) {
459 $mtoParams[
'custom-target-link'] = $frameParams[
'link-target'];
462 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams[
'link-url'] );
463 foreach ( $extLinkAttrs as $name => $val ) {
465 $mtoParams[
'parser-extlink-' . $name] = $val;
468 } elseif ( isset( $frameParams[
'link-title'] ) && $frameParams[
'link-title'] !==
'' ) {
469 $mtoParams[
'custom-title-link'] = Title::newFromLinkTarget(
470 self::normaliseSpecialPage( $frameParams[
'link-title'] )
472 } elseif ( !empty( $frameParams[
'no-link'] ) ) {
475 $mtoParams[
'desc-link'] =
true;
476 $mtoParams[
'desc-query'] = $query;
494 $align =
'right', $params = [], $framed =
false, $manualthumb =
""
502 $frameParams[
'framed'] =
true;
504 if ( $manualthumb ) {
505 $frameParams[
'manualthumb'] = $manualthumb;
520 $handlerParams = [], $time =
false, $query =
""
524 $page = $handlerParams[
'page'] ??
false;
525 if ( !isset( $frameParams[
'align'] ) ) {
526 $frameParams[
'align'] =
'right';
528 if ( !isset( $frameParams[
'alt'] ) ) {
529 $frameParams[
'alt'] =
'';
531 if ( !isset( $frameParams[
'title'] ) ) {
532 $frameParams[
'title'] =
'';
534 if ( !isset( $frameParams[
'caption'] ) ) {
535 $frameParams[
'caption'] =
'';
538 if ( empty( $handlerParams[
'width'] ) ) {
540 $handlerParams[
'width'] = isset( $frameParams[
'upright'] ) ? 130 : 180;
544 $manualthumb =
false;
547 $outerWidth = $handlerParams[
'width'] + 2;
549 if ( isset( $frameParams[
'manualthumb'] ) ) {
550 # Use manually specified thumbnail
551 $manual_title = Title::makeTitleSafe(
NS_FILE, $frameParams[
'manualthumb'] );
552 if ( $manual_title ) {
553 $manual_img = MediaWikiServices::getInstance()->getRepoGroup()
554 ->findFile( $manual_title );
556 $thumb = $manual_img->getUnscaledThumb( $handlerParams );
562 } elseif ( isset( $frameParams[
'framed'] ) ) {
564 $thumb =
$file->getUnscaledThumb( $handlerParams );
567 # Do not present an image bigger than the source, for bitmap-style images
568 # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
569 $srcWidth =
$file->getWidth( $page );
570 if ( $srcWidth && !
$file->mustRender() && $handlerParams[
'width'] > $srcWidth ) {
571 $handlerParams[
'width'] = $srcWidth;
573 $thumb =
$file->transform( $handlerParams );
577 $outerWidth = $thumb->getWidth() + 2;
579 $outerWidth = $handlerParams[
'width'] + 2;
583 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
584 # So we don't need to pass it here in $query. However, the URL for the
585 # zoom icon still needs it, so we make a unique query for it. See T16771
586 $url = Title::newFromLinkTarget(
$title )->getLocalURL( $query );
591 && !isset( $frameParams[
'link-title'] )
592 && !isset( $frameParams[
'link-url'] )
593 && !isset( $frameParams[
'no-link'] ) ) {
594 $frameParams[
'link-url'] = $url;
597 $s =
"<div class=\"thumb t{$frameParams['align']}\">"
598 .
"<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
603 } elseif ( !$thumb ) {
604 $s .=
wfMessage(
'thumbnail_error',
'' )->escaped();
607 if ( !$noscale && !$manualthumb ) {
611 'alt' => $frameParams[
'alt'],
612 'title' => $frameParams[
'title'],
613 'img-class' => ( isset( $frameParams[
'class'] ) && $frameParams[
'class'] !==
''
614 ? $frameParams[
'class'] .
' '
615 :
'' ) .
'thumbimage'
618 $s .= $thumb->toHtml( $params );
619 if ( isset( $frameParams[
'framed'] ) ) {
622 $zoomIcon = Html::rawElement(
'div', [
'class' =>
'magnify' ],
623 Html::rawElement(
'a', [
625 'class' =>
'internal',
626 'title' =>
wfMessage(
'thumbnail-more' )->text() ],
630 $s .=
' <div class="thumbcaption">' . $zoomIcon . $frameParams[
'caption'] .
"</div></div></div>";
631 return str_replace(
"\n",
' ',
$s );
646 $hp15[
'width'] = round( $hp[
'width'] * 1.5 );
648 $hp20[
'width'] = $hp[
'width'] * 2;
649 if ( isset( $hp[
'height'] ) ) {
650 $hp15[
'height'] = round( $hp[
'height'] * 1.5 );
651 $hp20[
'height'] = $hp[
'height'] * 2;
654 $thumb15 =
$file->transform( $hp15 );
655 $thumb20 =
$file->transform( $hp20 );
656 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
657 $thumb->responsiveUrls[
'1.5'] = $thumb15->getUrl();
659 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
660 $thumb->responsiveUrls[
'2'] = $thumb20->getUrl();
678 $query =
'', $unused1 =
'', $unused2 =
'', $time =
false
681 wfWarn( __METHOD__ .
': Requires $title to be a LinkTarget object.' );
682 return "<!-- ERROR -->" . htmlspecialchars( $label );
688 if ( $label ==
'' ) {
689 $label =
$title->getPrefixedText();
691 $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
692 $currentExists = $time
693 && $repoGroup->findFile(
$title ) !==
false;
698 if ( $repoGroup->getLocalRepo()->checkRedirect(
$title ) ) {
702 htmlspecialchars( $label ),
703 [
'class' =>
'mw-redirect' ],
705 [
'known',
'noclasses' ]
709 return Html::element(
'a', [
710 'href' => self::getUploadUrl(
$title, $query ),
712 'title' =>
$title->getPrefixedText()
718 htmlspecialchars( $label ),
721 [
'known',
'noclasses' ]
735 $q =
'wpDestFile=' . Title::castFromLinkTarget( $destFile )->getPartialURL();
736 if ( $query !=
'' ) {
748 $upload = SpecialPage::getTitleFor(
'Upload' );
750 return $upload->getLocalURL( $q );
763 $img = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
764 $title, [
'time' => $time ]
783 $url =
$file->getUrl();
802 if ( !Hooks::run(
'LinkerMakeMediaLinkFile',
803 [ Title::castFromLinkTarget(
$title ),
$file, &$html, &$attribs, &$ret ] ) ) {
804 wfDebug(
"Hook LinkerMakeMediaLinkFile changed the output of link "
805 .
"with url {$url} and text {$html} to {$ret}\n",
true );
809 return Html::rawElement(
'a', $attribs, $html );
824 $key = strtolower( $name );
849 $linktype =
'', $attribs = [],
$title =
null
854 $class .=
" $linktype";
856 if ( isset( $attribs[
'class'] ) && $attribs[
'class'] ) {
857 $class .=
" {$attribs['class']}";
859 $attribs[
'class'] = $class;
862 $text = htmlspecialchars( $text );
868 $newRel = Parser::getExternalLinkRel( $url,
$title );
869 if ( !isset( $attribs[
'rel'] ) || $attribs[
'rel'] ===
'' ) {
870 $attribs[
'rel'] = $newRel;
871 } elseif ( $newRel !==
'' ) {
873 $newRels = explode(
' ', $newRel );
874 $oldRels = explode(
' ', $attribs[
'rel'] );
875 $combined = array_unique( array_merge( $newRels, $oldRels ) );
876 $attribs[
'rel'] = implode(
' ', $combined );
879 $success = Hooks::run(
'LinkerMakeExternalLink',
880 [ &$url, &$text, &$link, &$attribs, $linktype ] );
882 wfDebug(
"Hook LinkerMakeExternalLink changed the output of link "
883 .
"with url {$url} and text {$text} to {$link}\n",
true );
886 $attribs[
'href'] = $url;
887 return Html::rawElement(
'a', $attribs, $text );
898 public static function userLink( $userId, $userName, $altUserName =
false ) {
899 if ( $userName ===
'' || $userName ===
false || $userName ===
null ) {
900 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
901 'that need to be fixed?' );
902 return wfMessage(
'empty-username' )->parse();
905 $classes =
'mw-userlink';
907 if ( $userId == 0 ) {
911 $classes .=
' mw-extuserlink';
912 } elseif ( $altUserName ===
false ) {
913 $altUserName = IP::prettifyIP( $userName );
915 $classes .=
' mw-anonuserlink';
922 '<bdi>' . htmlspecialchars( $altUserName !==
false ? $altUserName : $userName ) .
'</bdi>';
925 ?
self::link( $page, $linkText, [
'class' => $classes ] )
926 : Html::rawElement(
'span', [
'class' => $classes ], $linkText );
944 $userId, $userText, $redContribsWhenNoEdits =
false, $flags = 0, $edits =
null,
945 $useParentheses =
true
947 if ( $userText ===
'' ) {
948 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
949 'that need to be fixed?' );
950 return ' ' .
wfMessage(
'empty-username' )->parse();
956 $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
970 $attribs[
'class'] =
'mw-usertoollinks-contribs';
971 if ( $redContribsWhenNoEdits ) {
972 if ( intval( $edits ) === 0 && $edits !== 0 ) {
973 $user = User::newFromId( $userId );
974 $edits = $user->getEditCount();
976 if ( $edits === 0 ) {
977 $attribs[
'class'] .=
' new';
980 $contribsPage = SpecialPage::getTitleFor(
'Contributions', $userText );
984 $userCanBlock = MediaWikiServices::getInstance()->getPermissionManager()
985 ->userHasRight( $wgUser,
'block' );
986 if ( $blockable && $userCanBlock ) {
990 if ( $addEmailLink && $wgUser->canSendEmail() ) {
994 Hooks::run(
'UserToolLinksEdit', [ $userId, $userText, &$items ] );
1000 if ( $useParentheses ) {
1001 return wfMessage(
'word-separator' )->escaped()
1002 .
'<span class="mw-usertoollinks">'
1003 .
wfMessage(
'parentheses' )->rawParams(
$wgLang->pipeList( $items ) )->escaped()
1008 foreach ( $items as $tool ) {
1009 $tools[] = Html::rawElement(
'span', [], $tool );
1011 return ' <span class="mw-usertoollinks mw-changeslist-links">' .
1012 implode(
' ', $tools ) .
'</span>';
1025 $userId, $userText, $edits =
null, $useParentheses =
true
1037 if ( $userText ===
'' ) {
1038 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1039 'that need to be fixed?' );
1040 return wfMessage(
'empty-username' )->parse();
1044 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-talk' ];
1047 wfMessage(
'talkpagelinktext' )->escaped(),
1059 if ( $userText ===
'' ) {
1060 wfDebug( __METHOD__ .
' received an empty username. Are there database errors ' .
1061 'that need to be fixed?' );
1062 return wfMessage(
'empty-username' )->parse();
1065 $blockPage = SpecialPage::getTitleFor(
'Block', $userText );
1066 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-block' ];
1080 if ( $userText ===
'' ) {
1081 wfLogWarning( __METHOD__ .
' received an empty username. Are there database errors ' .
1082 'that need to be fixed?' );
1083 return wfMessage(
'empty-username' )->parse();
1086 $emailPage = SpecialPage::getTitleFor(
'Emailuser', $userText );
1087 $moreLinkAttribs = [
'class' =>
'mw-usertoollinks-mail' ];
1102 if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) && $isPublic ) {
1103 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1104 } elseif ( $rev->userCan( RevisionRecord::DELETED_USER ) ) {
1105 $link =
self::userLink( $rev->getUser( RevisionRecord::FOR_THIS_USER ),
1106 $rev->getUserText( RevisionRecord::FOR_THIS_USER ) );
1108 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1110 if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1111 return '<span class="history-deleted">' . $link .
'</span>';
1124 public static function revUserTools( $rev, $isPublic =
false, $useParentheses =
true ) {
1125 if ( $rev->userCan( RevisionRecord::DELETED_USER ) &&
1126 ( !$rev->isDeleted( RevisionRecord::DELETED_USER ) || !$isPublic )
1128 $userId = $rev->getUser( RevisionRecord::FOR_THIS_USER );
1129 $userText = $rev->getUserText( RevisionRecord::FOR_THIS_USER );
1130 if ( $userId || (
string)$userText !==
'' ) {
1137 if ( !isset( $link ) ) {
1138 $link =
wfMessage(
'rev-deleted-user' )->escaped();
1141 if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
1142 return ' <span class="history-deleted mw-userlink">' . $link .
'</span>';
1166 $comment,
$title =
null, $local =
false, $wikiId =
null
1168 # Sanitize text a bit:
1169 $comment = str_replace(
"\n",
" ", $comment );
1170 # Allow HTML entities (for T15815)
1171 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
1173 # Render autocomments and make links:
1196 $comment,
$title =
null, $local =
false, $wikiId =
null
1204 $comment = preg_replace_callback(
1210 '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
1211 function ( $match ) use (
$title, $local, $wikiId, &$append ) {
1215 $match += [
'',
'',
'',
'' ];
1217 $pre = $match[1] !==
'';
1219 $post = $match[3] !==
'';
1223 'FormatAutocomments',
1224 [ &$comment, $pre, $auto, $post, Title::castFromLinkTarget(
$title ), $local,
1228 if ( $comment ===
null ) {
1231 # Remove links that a user may have manually put in the autosummary
1232 # This could be improved by copying as much of Parser::stripSectionName as desired.
1233 $section = str_replace( [
1241 $sectionText = str_replace(
'[[',
'[[', $auto );
1243 $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
1249 if ( $section !==
'' && $section !==
false ) {
1253 $sectionTitle =
$title->createFragmentTarget( $section );
1264 # written summary $presep autocomment (summary )
1265 $pre =
wfMessage(
'autocomment-prefix' )->inContentLanguage()->escaped();
1268 # autocomment $postsep written summary ( summary)
1269 $auto .=
wfMessage(
'colon-separator' )->inContentLanguage()->escaped();
1272 $auto =
'<span dir="auto"><span class="autocomment">' . $auto .
'</span>';
1273 $append .=
'</span>';
1275 $comment = $pre . $auto;
1281 return $comment . $append;
1304 $comment,
$title =
null, $local =
false, $wikiId =
null
1306 return preg_replace_callback(
1309 \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking
1310 :? # ignore optional leading colon
1311 ([^\]|]+) # 1. link target; page names cannot include ] or |
1314 # Stop matching at ]] without relying on backtracking.
1318 ([^[]*) # 3. link trail (the text up until the next link)
1320 function ( $match ) use (
$title, $local, $wikiId ) {
1321 $services = MediaWikiServices::getInstance();
1324 $medians .= preg_quote(
1325 $services->getNamespaceInfo()->getCanonicalName(
NS_MEDIA ),
'/' );
1327 $medians .= preg_quote(
1328 $services->getContentLanguage()->getNsText(
NS_MEDIA ),
1332 $comment = $match[0];
1334 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1335 if ( strpos( $match[1],
'%' ) !==
false ) {
1337 rawurldecode( $match[1] ),
1338 [
'<' =>
'<',
'>' =>
'>' ]
1342 # Handle link renaming [[foo|text]] will show link as "text"
1343 if ( $match[2] !=
"" ) {
1350 if ( preg_match(
'/^' . $medians .
'(.*)$/i', $match[1], $submatch ) ) {
1351 # Media link; trail not supported.
1352 $linkRegexp =
'/\[\[(.*?)\]\]/';
1358 # Other kind of link
1359 # Make sure its target is non-empty
1360 if ( isset( $match[1][0] ) && $match[1][0] ==
':' ) {
1361 $match[1] = substr( $match[1], 1 );
1363 if ( $match[1] !==
false && $match[1] !==
'' ) {
1365 $services->getContentLanguage()->linkTrail(),
1369 $trail = $submatch[1];
1373 $linkRegexp =
'/\[\[(.*?)\]\]' . preg_quote( $trail,
'/' ) .
'/';
1379 Title::newFromText( $linkTarget );
1381 $target = $services->getTitleParser()->
1382 parseTitle( $linkTarget );
1384 if ( $target->getText() ==
'' && !$target->isExternal()
1387 $target =
$title->createFragmentTarget( $target->getFragment() );
1398 $comment = preg_replace(
1400 StringUtils::escapeRegexReplacement( $thelink ),
1426 LinkTarget $linkTarget, $text, $wikiId =
null, $options = []
1428 if ( $wikiId !==
null && !$linkTarget->
isExternal() ) {
1430 WikiMap::getForeignURL(
1434 : MediaWikiServices::getInstance()->getNamespaceInfo()->
1443 $link =
self::link( $linkTarget, $text, [], [], $options );
1458 # :Foobar -- override special treatment of prefix (images, language links)
1459 # /Foobar -- convert to CurrentPage/Foobar
1460 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1461 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1462 # ../Foobar -- convert to CurrentPage/Foobar,
1463 # (from CurrentPage/CurrentSubPage)
1464 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1465 # (from CurrentPage/CurrentSubPage)
1467 $ret = $target; #
default return value is no change
1469 # Some namespaces don't allow subpages,
1470 # so only perform processing if subpages are allowed
1472 $contextTitle && MediaWikiServices::getInstance()->getNamespaceInfo()->
1473 hasSubpages( $contextTitle->getNamespace() )
1475 $hash = strpos( $target,
'#' );
1476 if ( $hash !==
false ) {
1477 $suffix = substr( $target, $hash );
1478 $target = substr( $target, 0, $hash );
1483 $target = trim( $target );
1484 $contextPrefixedText = MediaWikiServices::getInstance()->getTitleFormatter()->
1485 getPrefixedText( $contextTitle );
1486 # Look at the first character
1487 if ( $target !=
'' && $target[0] ===
'/' ) {
1488 # / at end means we don't want the slash to be shown
1490 $trailingSlashes = preg_match_all(
'%(/+)$%', $target, $m );
1491 if ( $trailingSlashes ) {
1492 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1494 $noslash = substr( $target, 1 );
1497 $ret = $contextPrefixedText .
'/' . trim( $noslash ) . $suffix;
1498 if ( $text ===
'' ) {
1499 $text = $target . $suffix;
1500 } #
this might be changed
for ugliness reasons
1502 # check for .. subpage backlinks
1504 $nodotdot = $target;
1505 while ( strncmp( $nodotdot,
"../", 3 ) == 0 ) {
1507 $nodotdot = substr( $nodotdot, 3 );
1509 if ( $dotdotcount > 0 ) {
1510 $exploded = explode(
'/', $contextPrefixedText );
1511 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1512 $ret = implode(
'/', array_slice( $exploded, 0, -$dotdotcount ) );
1513 # / at the end means don't show full path
1514 if ( substr( $nodotdot, -1, 1 ) ===
'/' ) {
1515 $nodotdot = rtrim( $nodotdot,
'/' );
1516 if ( $text ===
'' ) {
1517 $text = $nodotdot . $suffix;
1520 $nodotdot = trim( $nodotdot );
1521 if ( $nodotdot !=
'' ) {
1522 $ret .=
'/' . $nodotdot;
1548 $comment,
$title =
null, $local =
false, $wikiId =
null, $useParentheses =
true
1553 if ( $comment ==
'' || $comment ==
'*' ) {
1557 if ( $useParentheses ) {
1558 $formatted =
wfMessage(
'parentheses' )->rawParams( $formatted )->escaped();
1559 $classNames =
'comment';
1561 $classNames =
'comment comment--without-parentheses';
1563 return " <span class=\"$classNames\">$formatted</span>";
1578 $useParentheses =
true
1580 if ( $rev->
getComment( RevisionRecord::RAW ) ==
"" ) {
1583 if ( $rev->
isDeleted( RevisionRecord::DELETED_COMMENT ) && $isPublic ) {
1584 $block =
" <span class=\"comment\">" .
wfMessage(
'rev-deleted-comment' )->escaped() .
"</span>";
1585 } elseif ( $rev->
userCan( RevisionRecord::DELETED_COMMENT ) ) {
1587 $rev->
getTitle(), $local,
null, $useParentheses );
1589 $block =
" <span class=\"comment\">" .
wfMessage(
'rev-deleted-comment' )->escaped() .
"</span>";
1591 if ( $rev->
isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
1592 return " <span class=\"history-deleted comment\">$block</span>";
1604 $stxt =
wfMessage(
'historyempty' )->escaped();
1606 $stxt =
wfMessage(
'nbytes' )->numParams( $size )->escaped();
1608 return "<span class=\"history-size mw-diff-bytes\">$stxt</span>";
1629 return "</li>\n" . str_repeat(
"</ul>\n</li>\n", $level > 0 ? $level : 0 );
1643 public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex =
false ) {
1644 $classes =
"toclevel-$level";
1645 if ( $sectionIndex !==
false ) {
1646 $classes .=
" tocsection-$sectionIndex";
1651 return Html::openElement(
'li', [
'class' => $classes ] )
1652 . Html::rawElement(
'a',
1653 [
'href' =>
"#$anchor" ],
1654 Html::element(
'span', [
'class' =>
'tocnumber' ], $tocnumber )
1656 . Html::rawElement(
'span', [
'class' =>
'toctext' ], $tocline )
1680 $lang =
$lang ?? RequestContext::getMain()->getLanguage();
1684 return '<div id="toc" class="toc">'
1685 . Html::element(
'input', [
1686 'type' =>
'checkbox',
1688 'id' =>
'toctogglecheckbox',
1689 'class' =>
'toctogglecheckbox',
1690 'style' =>
'display:none',
1692 . Html::openElement(
'div', [
1693 'class' =>
'toctitle',
1694 'lang' =>
$lang->getHtmlCode(),
1695 'dir' =>
$lang->getDir(),
1698 .
'<span class="toctogglespan">'
1699 . Html::label(
'',
'toctogglecheckbox', [
1700 'class' =>
'toctogglelabel',
1705 .
"</ul>\n</div>\n";
1719 foreach ( $tree as $section ) {
1720 if ( $section[
'toclevel'] > $lastLevel ) {
1722 } elseif ( $section[
'toclevel'] < $lastLevel ) {
1724 $lastLevel - $section[
'toclevel'] );
1730 $section[
'line'], $section[
'number'],
1731 $section[
'toclevel'], $section[
'index'] );
1732 $lastLevel = $section[
'toclevel'];
1755 $link, $fallbackAnchor =
false
1757 $anchorEscaped = htmlspecialchars( $anchor );
1759 if ( $fallbackAnchor !==
false && $fallbackAnchor !== $anchor ) {
1760 $fallbackAnchor = htmlspecialchars( $fallbackAnchor );
1761 $fallback =
"<span id=\"$fallbackAnchor\"></span>";
1763 return "<h$level$attribs"
1764 .
"$fallback<span class=\"mw-headline\" id=\"$anchorEscaped\">$html</span>"
1776 $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
1778 if ( $trail !==
'' && preg_match( $regex, $trail, $m ) ) {
1779 list( , $inside, $trail ) = $m;
1781 return [ $inside, $trail ];
1812 $options = [
'verify' ]
1815 $context = RequestContext::getMain();
1819 if ( in_array(
'verify', $options,
true ) ) {
1821 if ( $editCount ===
false ) {
1828 if ( !in_array(
'noBrackets', $options,
true ) ) {
1829 $inner =
$context->msg(
'brackets' )->rawParams( $inner )->escaped();
1832 if (
$context->getUser()->getBoolOption(
'showrollbackconfirmation' ) ) {
1833 $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1834 $stats->increment(
'rollbackconfirmation.event.load' );
1835 $context->getOutput()->addModules(
'mediawiki.page.rollback.confirmation' );
1838 return '<span class="mw-rollback-link">' . $inner .
'</span>';
1869 [
'rev_user_text' =>
$revQuery[
'fields'][
'rev_user_text'],
'rev_deleted' ],
1871 [
'rev_page' => $rev->getTitle()->getArticleID() ],
1874 'USE INDEX' => [
'revision' =>
'page_timestamp' ],
1875 'ORDER BY' =>
'rev_timestamp DESC',
1883 foreach (
$res as $row ) {
1884 if ( $rev->getUserText( RevisionRecord::RAW ) != $row->rev_user_text ) {
1886 ( $row->rev_deleted & RevisionRecord::DELETED_TEXT
1887 || $row->rev_deleted & RevisionRecord::DELETED_USER
1924 $disableRollbackEditCountSpecialPage = [
'Recentchanges',
'Watchlist' ];
1927 $context = RequestContext::getMain();
1930 $title = $rev->getTitle();
1933 'action' =>
'rollback',
1934 'from' => $rev->getUserText(),
1935 'token' =>
$context->getUser()->getEditToken(
'rollback' ),
1939 'data-mw' =>
'interface',
1940 'title' =>
$context->msg(
'tooltip-rollback' )->text()
1943 $options = [
'known',
'noclasses' ];
1945 if (
$context->getRequest()->getBool(
'bot' ) ) {
1947 $query[
'hidediff'] =
'1';
1948 $query[
'bot'] =
'1';
1951 $disableRollbackEditCount =
false;
1953 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1954 if (
$context->getTitle()->isSpecial( $specialPage ) ) {
1955 $disableRollbackEditCount =
true;
1961 if ( !$disableRollbackEditCount
1965 if ( !is_numeric( $editCount ) ) {
1970 $html =
$context->msg(
'rollbacklinkcount-morethan' )
1973 $html =
$context->msg(
'rollbacklinkcount' )->numParams( $editCount )->parse();
1979 $html =
$context->msg(
'rollbacklink' )->escaped();
1993 if ( count( $hiddencats ) > 0 ) {
1994 # Construct the HTML
1995 $outText =
'<div class="mw-hiddenCategoriesExplanation">';
1996 $outText .=
wfMessage(
'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
1997 $outText .=
"</div><ul>\n";
1999 foreach ( $hiddencats as $titleObj ) {
2000 # If it's hidden, it must exist - no need to check with a LinkBatch
2002 .
self::link( $titleObj,
null, [], [],
'known' )
2005 $outText .=
'</ul>';
2026 public static function titleAttrib( $name, $options =
null, array $msgParams = [] ) {
2027 $message =
wfMessage(
"tooltip-$name", $msgParams );
2028 if ( !$message->exists() ) {
2031 $tooltip = $message->text();
2032 # Compatibility: formerly some tooltips had [alt-.] hardcoded
2033 $tooltip = preg_replace(
"/ ?\[alt-.\]$/",
'', $tooltip );
2034 # Message equal to '-' means suppress it.
2035 if ( $tooltip ==
'-' ) {
2040 $options = (array)$options;
2042 if ( in_array(
'nonexisting', $options ) ) {
2043 $tooltip =
wfMessage(
'red-link-title', $tooltip ?:
'' )->text();
2045 if ( in_array(
'withaccess', $options ) ) {
2047 if ( $accesskey !==
false ) {
2049 if ( $tooltip ===
false || $tooltip ===
'' ) {
2050 $tooltip =
wfMessage(
'brackets', $accesskey )->text();
2052 $tooltip .=
wfMessage(
'word-separator' )->text();
2053 $tooltip .=
wfMessage(
'brackets', $accesskey )->text();
2075 if ( isset( self::$accesskeycache[$name] ) ) {
2076 return self::$accesskeycache[$name];
2079 $message =
wfMessage(
"accesskey-$name" );
2081 if ( !$message->exists() ) {
2084 $accesskey = $message->plain();
2085 if ( $accesskey ===
'' || $accesskey ===
'-' ) {
2086 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2087 # attribute, but this is broken for accesskey: that might be a useful
2093 self::$accesskeycache[$name] = $accesskey;
2094 return self::$accesskeycache[$name];
2111 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
2112 $canHide = $permissionManager->userHasRight( $user,
'deleterevision' );
2113 $canHideHistory = $permissionManager->userHasRight( $user,
'deletedhistory' );
2114 if ( !$canHide && !( $rev->
getVisibility() && $canHideHistory ) ) {
2118 if ( !$rev->
userCan( RevisionRecord::DELETED_RESTRICTED, $user ) ) {
2121 $prefixedDbKey = MediaWikiServices::getInstance()->getTitleFormatter()->
2122 getPrefixedDBkey(
$title );
2123 if ( $rev->
getId() ) {
2127 'type' =>
'revision',
2128 'target' => $prefixedDbKey,
2129 'ids' => $rev->
getId()
2135 'type' =>
'archive',
2136 'target' => $prefixedDbKey,
2141 $rev->
isDeleted( RevisionRecord::DELETED_RESTRICTED ), $canHide );
2154 public static function revDeleteLink( $query = [], $restricted =
false, $delete =
true ) {
2155 $sp = SpecialPage::getTitleFor(
'Revisiondelete' );
2156 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
2157 $html =
wfMessage( $msgKey )->escaped();
2158 $tag = $restricted ?
'strong' :
'span';
2159 $link =
self::link( $sp, $html, [], $query, [
'known',
'noclasses' ] );
2162 [
'class' =>
'mw-revdelundel-link' ],
2163 wfMessage(
'parentheses' )->rawParams( $link )->escaped()
2177 $msgKey = $delete ?
'rev-delundel' :
'rev-showdeleted';
2178 $html =
wfMessage( $msgKey )->escaped();
2179 $htmlParentheses =
wfMessage(
'parentheses' )->rawParams( $html )->escaped();
2180 return Xml::tags(
'span', [
'class' =>
'mw-revdelundel-link' ], $htmlParentheses );
2197 array $msgParams = [],
2200 $options = (array)$options;
2201 $options[] =
'withaccess';
2207 if ( $attribs[
'title'] ===
false ) {
2208 unset( $attribs[
'title'] );
2210 if ( $attribs[
'accesskey'] ===
false ) {
2211 unset( $attribs[
'accesskey'] );
2223 public static function tooltip( $name, $options =
null ) {
2225 if ( $tooltip ===
false ) {
2228 return Xml::expandAttributes( [
$wgThumbUpright
Adjust width of upright images when parameter 'upright' is used This allows a nicer look for upright ...
$wgThumbLimits
Adjust thumbnails on image pages according to a user setting.
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
$wgSVGMaxSize
Don't scale a SVG larger than this.
$wgShowRollbackEditCount
The $wgShowRollbackEditCount variable is used to show how many edits can be rolled back.
$wgUploadMissingFileUrl
Point the upload link for missing files to an external URL, as with $wgUploadNavigationUrl.
$wgUploadNavigationUrl
Point the upload navigation link to an external URL Useful if you want to use a shared repository by ...
$wgResponsiveImages
Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
$wgEnableUploads
Allow users to upload files.
$wgMiserMode
Disable database-intensive features.
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.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
if(! $wgRequest->checkUrlExtension()) if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
static isExternal( $username)
Tells whether the username is external or not.
Marks HTML that shouldn't be escaped.
Internationalisation code.
Some internal bits split of from Skin.php.
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
static makeMediaLinkFile(LinkTarget $title, $file, $html='')
Create a direct link to a given uploaded file.
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
static fnamePart( $url)
Returns the filename part of an url.
static tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex=false)
parameter level defines if we are on an indentation level
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
static formatAutocomments( $comment, $title=null, $local=false, $wikiId=null)
Converts autogenerated comments in edit summaries into section links.
static specialLink( $name, $key='')
Make a link to a special page given its name and, optionally, a message key from the link text.
static getRevDeleteLink(User $user, Revision $rev, LinkTarget $title)
Get a revision-deletion link, or disabled link, or nothing, depending on user permissions & the setti...
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
static makeExternalImage( $url, $alt='')
Return the code for images which were added via external links, via Parser::maybeMakeExternalImage().
static buildRollbackLink( $rev, IContextSource $context=null, $editCount=false)
Build a raw rollback link, useful for collections of "tool" links.
static makeCommentLink(LinkTarget $linkTarget, $text, $wikiId=null, $options=[])
Generates a link to the given LinkTarget.
static revComment(Revision $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision's comment block, if the current user is allowed to view it.
static processResponsiveImages( $file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
static blockLink( $userId, $userText)
static revDeleteLinkDisabled( $delete=true)
Creates a dead (show/hide) link for deleting revisions/log entries.
static getRollbackEditCount( $rev, $verify)
This function will return the number of revisions which a rollback would revert and,...
static normalizeSubpageLink( $contextTitle, $target, &$text)
const TOOL_LINKS_NOBLOCK
Flags for userToolLinks()
static makeSelfLinkObj( $nt, $html='', $query='', $trail='', $prefix='')
Make appropriate markup for a link to the current article.
static getUploadUrl( $destFile, $query='')
Get the URL to upload a certain file.
static tocIndent()
Add another level to the Table of Contents.
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...
static revUserLink( $rev, $isPublic=false)
Generate a user link if the current user is allowed to view it.
static getInvalidTitleDescription(IContextSource $context, $namespace, $title)
Get a message saying that an invalid title was encountered.
static emailLink( $userId, $userText)
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
static splitTrail( $trail)
Split a link trail, return the "inside" portion and the remainder of the trail as a two-element array...
static makeThumbLink2(LinkTarget $title, $file, $frameParams=[], $handlerParams=[], $time=false, $query="")
static generateTOC( $tree, Language $lang=null)
Generate a table of contents from a section tree.
static formatRevisionSize( $size)
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...
static tooltip( $name, $options=null)
Returns raw bits of HTML, use titleAttrib()
static revUserTools( $rev, $isPublic=false, $useParentheses=true)
Generate a user tool link cluster if the current user is allowed to view it.
static userTalkLink( $userId, $userText)
static formatLinksInComment( $comment, $title=null, $local=false, $wikiId=null)
Formats wiki links and media links in text; all other wiki formatting is ignored.
static makeMediaLinkObj( $title, $html='', $time=false)
Create a direct link to a given uploaded file.
static makeThumbLinkObj(LinkTarget $title, $file, $label='', $alt='', $align='right', $params=[], $framed=false, $manualthumb="")
Make HTML for a thumbnail including image, border and caption.
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
static normaliseSpecialPage(LinkTarget $target)
static makeHeadline( $level, $attribs, $anchor, $html, $link, $fallbackAnchor=false)
Create a headline for content.
static tocUnindent( $level)
Finish one or more sublevels on the Table of Contents.
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
static tocList( $toc, Language $lang=null)
Wraps the TOC in a table and provides the hide/collapse javascript.
static getImageLinkMTOParams( $frameParams, $query='', $parser=null)
Get the link parameters for MediaTransformOutput::toHtml() from given frame parameters supplied by th...
static revDeleteLink( $query=[], $restricted=false, $delete=true)
Creates a (show/hide) link for deleting revisions/log entries.
static tocLineEnd()
End a Table Of Contents line.
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...
static userToolLinksRedContribs( $userId, $userText, $edits=null, $useParentheses=true)
Alias for userToolLinks( $userId, $userText, true );.
static makeBrokenImageLinkObj( $title, $label='', $query='', $unused1='', $unused2='', $time=false)
Make a "broken" link to an image.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
getTargetLanguage()
Get the target language for the content being parsed.
getTitle()
Returns the title of the page associated with this entry.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
getVisibility()
Get the deletion bitfield of the revision.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Represents a page (or page fragment) title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Interface for objects which can provide a MediaWiki context on request.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!isset( $args[0])) $lang