r84151 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84150‎ | r84151 | r84152 >
Date:05:28, 17 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Modified createTemplateText() to be able to place semantic markup in the template it creates within a #set_internal call, if the Semantic Internal Objects extension is installed.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.php
@@ -98,7 +98,14 @@
9999 $this->setTypeAndPossibleValues();
100100 }
101101
102 - public static function createTemplateText( $template_name, $template_fields, $category, $aggregating_property, $aggregating_label, $template_format ) {
 102+ /**
 103+ * Creates the text of a template, when called from either
 104+ * Special:CreateTemplate or Special:CreateClass.
 105+ *
 106+ * @TODO: There's really no good reason why this method is contained
 107+ * within this class.
 108+ */
 109+ public static function createTemplateText( $template_name, $template_fields, $internal_obj_property, $category, $aggregating_property, $aggregating_label, $template_format ) {
103110 $template_header = wfMsgForContent( 'sf_template_docu', $template_name );
104111 $text = <<<END
105112 <noinclude>
@@ -119,31 +126,46 @@
120127 </noinclude><includeonly>
121128
122129 END;
123 - // topmost part depends on format
 130+ // Only add a call to #set_internal if the Semantic Internal
 131+ // Objects extension is also installed.
 132+ if ( !empty( $internal_obj_property) && class_exists( 'SIOInternalObject' ) ) {
 133+ $setInternalText = '{{#set_internal:' . $internal_obj_property;
 134+ } else {
 135+ $setInternalText = null;
 136+ }
 137+
 138+ // Topmost part of table depends on format
124139 if ( $template_format == 'infobox' ) {
125 - // CSS style can't be used, unfortunately, since most MediaWiki
126 - // setups don't have an 'infobox' or comparable CSS class
127 - $text .= <<<END
 140+ // A CSS style can't be used, unfortunately, since most
 141+ // MediaWiki setups don't have an 'infobox' or
 142+ // comparable CSS class.
 143+ $tableText .= <<<END
128144 {| style="width: 30em; font-size: 90%; border: 1px solid #aaaaaa; background-color: #f9f9f9; color: black; margin-bottom: 0.5em; margin-left: 1em; padding: 0.2em; float: right; clear: right; text-align:left;"
129145 ! style="text-align: center; background-color:#ccccff;" colspan="2" |<big>{{PAGENAME}}</big>
130146 |-
131147
132148 END;
133149 } else {
134 - $text .= '{| class="wikitable"' . "\n";
 150+ $tableText .= '{| class="wikitable"' . "\n";
135151 }
136152
137153 foreach ( $template_fields as $i => $field ) {
138154 if ( $i > 0 ) {
139 - $text .= "|-\n";
 155+ $tableText .= "|-\n";
140156 }
141 - $text .= "! " . $field->label . "\n";
 157+ $tableText .= "! " . $field->label . "\n";
142158 if ( $field->semantic_property == null || $field->semantic_property == '' ) {
143 - $text .= "| {{{" . $field->field_name . "|}}}\n";
 159+ $tableText .= "| {{{" . $field->field_name . "|}}}\n";
144160 // if this field is meant to contain a list,
145161 // add on an 'arraymap' function, that will
146162 // call this semantic markup tag on every
147163 // element in the list
 164+ } elseif ( !is_null( $setInternalText ) ) {
 165+ if ( $field->is_list ) {
 166+ $setInternalText .= '|' . $field->semantic_property . '#list={{{' . $field->field_name . '|}}}';
 167+ } else {
 168+ $setInternalText .= '|' . $field->semantic_property . '={{{' . $field->field_name . '|}}}';
 169+ }
148170 } elseif ( $field->is_list ) {
149171 // find a string that's not in the semantic
150172 // field call, to be used as the variable
@@ -157,25 +179,31 @@
158180 }
159181 }
160182 }
161 - $text .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n";
 183+ $tableText .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n";
162184 } else {
163 - $text .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n";
 185+ $tableText .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n";
164186 }
165187 }
166188
167 - // add a row with an inline query to this table, for aggregation, if
168 - // a property was specified
 189+ // Add a row with an inline query to this table, for
 190+ // aggregation, if a property was specified.
169191 if ( $aggregating_property != '' ) {
170192 if ( count( $template_fields ) > 0 ) {
171 - $text .= "|-\n";
 193+ $tableText .= "|-\n";
172194 }
173 - $text .= <<<END
 195+ $tableText .= <<<END
174196 ! $aggregating_label
175197 | {{#ask:[[$aggregating_property::{{SUBJECTPAGENAME}}]]|format=list}}
176198
177199 END;
178200 }
179 - $text .= "|}\n";
 201+ $tableText .= "|}\n";
 202+ if ( !is_null( $setInternalText ) ) {
 203+ $setInternalText .= "}}\n";
 204+ $text .= $setInternalText;
 205+ }
 206+
 207+ $text .= $tableText;
180208 if ( $category != '' ) {
181209 global $wgContLang;
182210 $namespace_labels = $wgContLang->getNamespaces();