/** * Returns HTML for the "templates used on this page" list. * * @param $templates Array of templates from Article::getUsedTemplate * or similar * @param $preview Boolean: whether this is for a preview * @param $section Boolean: whether this is for a section edit * @return String: HTML output */ public static function formatTemplates($templates, $preview = false, $section = false) { wfProfileIn(__METHOD__); $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 .= wfMsgExt('templatesusedpreview', array('parse'), count($templates)); } elseif ($section) { $outText .= wfMsgExt('templatesusedsection', array('parse'), count($templates)); } else { $outText .= wfMsgExt('templatesused', array('parse'), count($templates)); } $outText .= "</div><ul>\n"; // Wikia change - begin - @author: wladek // preload restrictions $titleBatch = new TitleBatch($templates); $titleBatch->loadRestrictions(); // Wikia change - end usort($templates, array('Title', 'compare')); foreach ($templates as $titleObj) { $r = $titleObj->getRestrictions('edit'); if (in_array('sysop', $r)) { $protected = wfMsgExt('template-protected', array('parseinline')); } elseif (in_array('autoconfirmed', $r)) { $protected = wfMsgExt('template-semiprotected', array('parseinline')); } else { $protected = ''; } if ($titleObj->quickUserCan('edit')) { $editLink = self::link($titleObj, wfMsg('editlink'), array(), array('action' => 'edit')); } else { $editLink = self::link($titleObj, wfMsg('viewsourcelink'), array(), array('action' => 'edit')); } $outText .= '<li>' . self::link($titleObj) . ' (' . $editLink . ') ' . $protected . '</li>'; } $outText .= '</ul>'; } wfProfileOut(__METHOD__); return $outText; }