setHeaders(); list( $limit, $offset ) = $this->getRequest()->getLimitOffset(); $rep = new TemplatesPage(); $rep->execute( $query ); } protected function getGroupName() { return 'pages'; } } /** * @ingroup PFSpecialPages */ class TemplatesPage extends QueryPage { public function __construct( $name = 'Templates' ) { parent::__construct( $name ); } function getName() { return "Templates"; } function isExpensive() { return false; } function isSyndicated() { return false; } function getPageHeader() { $header = Html::element( 'p', null, wfMessage( 'pf_templates_docu' )->text() ); return $header; } function getPageFooter() { } function getQueryInfo() { return array( 'tables' => array( 'page' ), 'fields' => array( 'page_title AS title', 'page_title AS value' ), 'conds' => array( 'page_namespace' => NS_TEMPLATE ) ); } function sortDescending() { return false; } function getCategoryDefinedByTemplate( $templateTitle ) { global $wgContLang; $templateText = PFUtils::getPageText( $templateTitle ); $cat_ns_name = $wgContLang->getNsText( NS_CATEGORY ); if ( preg_match_all( "/\[\[(Category|$cat_ns_name):([^\]]*)\]\]/", $templateText, $matches ) ) { // Get the last match - if there's more than one // category tag, there's a good chance that the last // one will be the relevant one - the others are // probably part of inline queries. $categoryName = trim( end( $matches[2] ) ); // If there's a pipe, remove it and anything after it. $locationOfPipe = strpos( $categoryName, '|' ); if ( $locationOfPipe !== false ) { $categoryName = substr( $categoryName, 0, $locationOfPipe ); } return $categoryName; } return ""; } function formatResult( $skin, $result ) { $title = Title::makeTitle( NS_TEMPLATE, $result->value ); if ( method_exists( $this, 'getLinkRenderer' ) ) { $linkRenderer = $this->getLinkRenderer(); } else { $linkRenderer = null; } $text = PFUtils::makeLink( $linkRenderer, $title, htmlspecialchars( $title->getText() ) ); $category = $this->getCategoryDefinedByTemplate( $title ); if ( $category !== '' ) { $text .= ' ' . wfMessage( 'pf_templates_definescat', PFUtils::linkText( NS_CATEGORY, $category ) )->parse(); } return $text; } }