Index: trunk/extensions/SemanticForms/specials/SF_Templates.php |
— | — | @@ -39,9 +39,10 @@ |
40 | 40 | * @ingroup SFSpecialPages |
41 | 41 | */ |
42 | 42 | class TemplatesPage extends QueryPage { |
| 43 | + |
43 | 44 | public function __construct( $name = 'Templates' ) { |
44 | 45 | // For MW <= 1.17 |
45 | | - if ( $this instanceof SpecialPage ) { |
| 46 | + if ( $this instanceof SpecialPage ) { |
46 | 47 | parent::__construct( $name ); |
47 | 48 | } |
48 | 49 | } |
— | — | @@ -95,28 +96,30 @@ |
96 | 97 | return false; |
97 | 98 | } |
98 | 99 | |
99 | | - function getCategoryDefinedByTemplate( $template_article ) { |
| 100 | + function getCategoryDefinedByTemplate( $templateTitle ) { |
100 | 101 | global $wgContLang; |
101 | 102 | |
102 | | - $template_text = $template_article->getContent(); |
103 | | - $cat_ns_name = $wgContLang->getNsText( 14 ); |
104 | | - if ( preg_match_all( "/\[\[(Category|$cat_ns_name):([^\]]*)\]\]/", $template_text, $matches ) ) { |
105 | | - // get the last match - if there's more than one |
| 103 | + $templateArticle = new Article( $templateTitle ); |
| 104 | + $templateText = $templateArticle->getContent(); |
| 105 | + $cat_ns_name = $wgContLang->getNsText( NS_TEMPLATE ); |
| 106 | + if ( preg_match_all( "/\[\[(Category|$cat_ns_name):([^\]]*)\]\]/", $templateText, $matches ) ) { |
| 107 | + // Get the last match - if there's more than one |
106 | 108 | // category tag, there's a good chance that the last |
107 | 109 | // one will be the relevant one - the others are |
108 | | - // probably part of inline queries |
| 110 | + // probably part of inline queries. |
109 | 111 | return trim( end( $matches[2] ) ); |
110 | 112 | } |
111 | 113 | return ""; |
112 | 114 | } |
113 | 115 | |
114 | 116 | function formatResult( $skin, $result ) { |
115 | | - SFUtils::loadMessages(); |
116 | 117 | $title = Title::makeTitle( NS_TEMPLATE, $result->value ); |
117 | 118 | $text = $skin->makeLinkObj( $title, htmlspecialchars( $title->getText() ) ); |
118 | | - $category = $this->getCategoryDefinedByTemplate( new Article( $title ) ); |
119 | | - if ( $category != '' ) |
| 119 | + $category = $this->getCategoryDefinedByTemplate( $title ); |
| 120 | + if ( $category != '' ) { |
| 121 | + SFUtils::loadMessages(); |
120 | 122 | $text .= ' ' . wfMsg( 'sf_templates_definescat' ) . ' ' . SFUtils::linkText( NS_CATEGORY, $category ); |
| 123 | + } |
121 | 124 | return $text; |
122 | 125 | } |
123 | 126 | } |