- global $wgLang;
-
- $outText = '';
- if ( count( $templates ) > 0 ) {
- # Do a batch existence check
- $batch = new LinkBatch;
- foreach ( $templates as $title ) {
- $batch->addObj( $title );
- }
- $batch->execute();
-
- # Construct the HTML
- $outText = '<div class="mw-templatesUsedExplanation">';
- if ( $preview ) {
- $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) )
- ->parseAsBlock();
- } elseif ( $section ) {
- $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) )
- ->parseAsBlock();
- } else {
- $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) )
- ->parseAsBlock();
- }
- $outText .= "</div><ul>\n";
-
- usort( $templates, 'Title::compare' );
- foreach ( $templates as $titleObj ) {
- $protected = '';
- $restrictions = $titleObj->getRestrictions( 'edit' );
- if ( $restrictions ) {
- // Check backwards-compatible messages
- $msg = null;
- if ( $restrictions === [ 'sysop' ] ) {
- $msg = wfMessage( 'template-protected' );
- } elseif ( $restrictions === [ 'autoconfirmed' ] ) {
- $msg = wfMessage( 'template-semiprotected' );
- }
- if ( $msg && !$msg->isDisabled() ) {
- $protected = $msg->parse();
- } else {
- // Construct the message from restriction-level-*
- // e.g. restriction-level-sysop, restriction-level-autoconfirmed
- $msgs = [];
- foreach ( $restrictions as $r ) {
- $msgs[] = wfMessage( "restriction-level-$r" )->parse();
- }
- $protected = wfMessage( 'parentheses' )
- ->rawParams( $wgLang->commaList( $msgs ) )->escaped();
- }
- }
- if ( $titleObj->quickUserCan( 'edit' ) ) {
- $editLink = self::link(
- $titleObj,
- wfMessage( 'editlink' )->escaped(),
- [],
- [ 'action' => 'edit' ]
- );
- } else {
- $editLink = self::link(
- $titleObj,
- wfMessage( 'viewsourcelink' )->escaped(),
- [],
- [ 'action' => 'edit' ]
- );
- }
- $outText .= '<li>' . self::link( $titleObj )
- . wfMessage( 'word-separator' )->escaped()
- . wfMessage( 'parentheses' )->rawParams( $editLink )->escaped()
- . wfMessage( 'word-separator' )->escaped()
- . $protected . '</li>';
- }