43 private $linkRenderer;
48 private $linkBatchFactory;
53 private $restrictionStore;
67 $this->context = $context;
68 $this->linkRenderer = $linkRenderer;
69 $this->linkBatchFactory = $linkBatchFactory;
70 $this->restrictionStore = $restrictionStore;
84 public function format( array $templates,
$type =
false, $more =
null ) {
90 # Do a batch existence check
91 $batch = $this->linkBatchFactory->newLinkBatch( $templates );
92 $batch->setCaller( __METHOD__ );
96 $outText = Html::openElement(
'div', [
'class' =>
'mw-templatesUsedExplanation' ] );
97 $count = count( $templates );
98 if (
$type ===
'preview' ) {
99 $outText .= $this->context->msg(
'templatesusedpreview' )->numParams( $count )
101 } elseif (
$type ===
'section' ) {
102 $outText .= $this->context->msg(
'templatesusedsection' )->numParams( $count )
105 $outText .= $this->context->msg(
'templatesused' )->numParams( $count )
108 $outText .= Html::closeElement(
'div' ) . Html::openElement(
'ul' ) .
"\n";
110 usort( $templates, [ Title::class,
'compare' ] );
111 foreach ( $templates as $template ) {
112 $outText .= $this->formatTemplate( $template );
116 $outText .= Html::rawElement(
'li', [],
117 $this->linkRenderer->makeLink(
119 $this->context->msg(
'moredotdotdot' )->text()
124 $outText .= Html::rawElement(
'li', [], $more );
127 $outText .= Html::closeElement(
'ul' );
137 private function formatTemplate(
PageIdentity $target ) {
138 $protected = $this->getRestrictionsText(
139 $this->restrictionStore->getRestrictions( $target,
'edit' )
141 $editLink = $this->buildEditLink( $target );
142 return Html::rawElement(
'li', [], $this->linkRenderer->makeLink( $target )
143 . $this->context->msg(
'word-separator' )->escaped()
144 . $this->context->msg(
'parentheses' )->rawParams( $editLink )->escaped()
145 . $this->context->msg(
'word-separator' )->escaped()
157 private function getRestrictionsText( array $restrictions ) {
159 if ( !$restrictions ) {
165 if ( $restrictions === [
'sysop' ] ) {
166 $msg = $this->context->msg(
'template-protected' );
167 } elseif ( $restrictions === [
'autoconfirmed' ] ) {
168 $msg = $this->context->msg(
'template-semiprotected' );
170 if ( $msg && !$msg->isDisabled() ) {
171 $protected = $msg->parse();
176 foreach ( $restrictions as $r ) {
177 $msgs[] = $this->context->msg(
"restriction-level-$r" )->parse();
179 $protected = $this->context->msg(
'parentheses' )
180 ->rawParams( $this->context->getLanguage()->commaList( $msgs ) )->escaped();
194 if ( $this->context->getAuthority()->probablyCan(
'edit', $page ) ) {
195 $linkMsg =
'editlink';
197 $linkMsg =
'viewsourcelink';
200 return $this->linkRenderer->makeLink(
202 $this->context->msg( $linkMsg )->text(),
204 [
'action' =>
'edit' ]
Interface for objects which can provide a MediaWiki context on request.