53 public function format( array $templates, $type =
false, $more =
null ) {
59 # Do a batch existence check
60 $batch = $this->linkBatchFactory->newLinkBatch( $templates );
61 $batch->setCaller( __METHOD__ );
65 $outText = Html::openElement(
'div', [
'class' =>
'mw-templatesUsedExplanation' ] );
66 $count = count( $templates );
67 if ( $type ===
'preview' ) {
68 $outText .= $this->context->msg(
'templatesusedpreview' )->numParams( $count )
70 } elseif ( $type ===
'section' ) {
71 $outText .= $this->context->msg(
'templatesusedsection' )->numParams( $count )
74 $outText .= $this->context->msg(
'templatesused' )->numParams( $count )
77 $outText .= Html::closeElement(
'div' ) . Html::openElement(
'ul' ) .
"\n";
79 usort( $templates, Title::compare( ... ) );
80 foreach ( $templates as $template ) {
81 $outText .= $this->formatTemplate( $template );
85 $outText .= Html::rawElement(
'li', [],
86 $this->linkRenderer->makeLink(
88 $this->context->msg(
'moredotdotdot' )->text()
93 $outText .= Html::rawElement(
'li', [], $more );
96 $outText .= Html::closeElement(
'ul' );
108 private function formatTemplate(
PageIdentity $target ) {
110 return Html::rawElement(
'li', [], $this->linkRenderer->makeLink( $target ) );
113 $protected = $this->getRestrictionsText(
114 $this->restrictionStore->getRestrictions( $target,
'edit' )
116 $editLink = $this->buildEditLink( $target );
117 return Html::rawElement(
'li', [], $this->linkRenderer->makeLink( $target )
118 . $this->context->msg(
'word-separator' )->escaped()
119 . $this->context->msg(
'parentheses' )->rawParams( $editLink )->escaped()
120 . $this->context->msg(
'word-separator' )->escaped()
132 private function getRestrictionsText( array $restrictions ) {
134 if ( !$restrictions ) {
141 foreach ( $restrictions as $r ) {
142 $msgs[] = $this->context->msg(
"restriction-level-$r" );
147 if ( $restrictions === [
'sysop' ] ) {
148 $msg = $this->context->msg(
'template-protected' );
149 } elseif ( $restrictions === [
'autoconfirmed' ] ) {
150 $msg = $this->context->msg(
'template-semiprotected' );
152 if ( !$msg || $msg->isDisabled() ) {
154 $msg = $this->context->msg(
'parentheses' );
167 private function buildEditLink( PageIdentity $page ) {
168 if ( $this->context->getAuthority()->probablyCan(
'edit', $page ) ) {
169 $linkMsg =
'editlink';
171 $linkMsg =
'viewsourcelink';
174 return $this->linkRenderer->makeLink(
176 $this->context->msg( $linkMsg )->text(),
178 [
'action' =>
'edit' ]