r91390 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91389‎ | r91390 | r91391 >
Date:03:21, 4 July 2011
Author:yaron
Status:deferred
Tags:
Comment:
Cleaned up some of the code, improved formatting
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_Templates.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_Templates.php
@@ -39,9 +39,10 @@
4040 * @ingroup SFSpecialPages
4141 */
4242 class TemplatesPage extends QueryPage {
 43+
4344 public function __construct( $name = 'Templates' ) {
4445 // For MW <= 1.17
45 - if ( $this instanceof SpecialPage ) {
 46+ if ( $this instanceof SpecialPage ) {
4647 parent::__construct( $name );
4748 }
4849 }
@@ -95,28 +96,30 @@
9697 return false;
9798 }
9899
99 - function getCategoryDefinedByTemplate( $template_article ) {
 100+ function getCategoryDefinedByTemplate( $templateTitle ) {
100101 global $wgContLang;
101102
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
106108 // category tag, there's a good chance that the last
107109 // one will be the relevant one - the others are
108 - // probably part of inline queries
 110+ // probably part of inline queries.
109111 return trim( end( $matches[2] ) );
110112 }
111113 return "";
112114 }
113115
114116 function formatResult( $skin, $result ) {
115 - SFUtils::loadMessages();
116117 $title = Title::makeTitle( NS_TEMPLATE, $result->value );
117118 $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();
120122 $text .= ' ' . wfMsg( 'sf_templates_definescat' ) . ' ' . SFUtils::linkText( NS_CATEGORY, $category );
 123+ }
121124 return $text;
122125 }
123126 }