Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.php |
— | — | @@ -98,7 +98,14 @@ |
99 | 99 | $this->setTypeAndPossibleValues(); |
100 | 100 | } |
101 | 101 | |
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 ) { |
103 | 110 | $template_header = wfMsgForContent( 'sf_template_docu', $template_name ); |
104 | 111 | $text = <<<END |
105 | 112 | <noinclude> |
— | — | @@ -119,31 +126,46 @@ |
120 | 127 | </noinclude><includeonly> |
121 | 128 | |
122 | 129 | 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 |
124 | 139 | 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 |
128 | 144 | {| 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;" |
129 | 145 | ! style="text-align: center; background-color:#ccccff;" colspan="2" |<big>{{PAGENAME}}</big> |
130 | 146 | |- |
131 | 147 | |
132 | 148 | END; |
133 | 149 | } else { |
134 | | - $text .= '{| class="wikitable"' . "\n"; |
| 150 | + $tableText .= '{| class="wikitable"' . "\n"; |
135 | 151 | } |
136 | 152 | |
137 | 153 | foreach ( $template_fields as $i => $field ) { |
138 | 154 | if ( $i > 0 ) { |
139 | | - $text .= "|-\n"; |
| 155 | + $tableText .= "|-\n"; |
140 | 156 | } |
141 | | - $text .= "! " . $field->label . "\n"; |
| 157 | + $tableText .= "! " . $field->label . "\n"; |
142 | 158 | if ( $field->semantic_property == null || $field->semantic_property == '' ) { |
143 | | - $text .= "| {{{" . $field->field_name . "|}}}\n"; |
| 159 | + $tableText .= "| {{{" . $field->field_name . "|}}}\n"; |
144 | 160 | // if this field is meant to contain a list, |
145 | 161 | // add on an 'arraymap' function, that will |
146 | 162 | // call this semantic markup tag on every |
147 | 163 | // 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 | + } |
148 | 170 | } elseif ( $field->is_list ) { |
149 | 171 | // find a string that's not in the semantic |
150 | 172 | // field call, to be used as the variable |
— | — | @@ -157,25 +179,31 @@ |
158 | 180 | } |
159 | 181 | } |
160 | 182 | } |
161 | | - $text .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n"; |
| 183 | + $tableText .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n"; |
162 | 184 | } else { |
163 | | - $text .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n"; |
| 185 | + $tableText .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n"; |
164 | 186 | } |
165 | 187 | } |
166 | 188 | |
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. |
169 | 191 | if ( $aggregating_property != '' ) { |
170 | 192 | if ( count( $template_fields ) > 0 ) { |
171 | | - $text .= "|-\n"; |
| 193 | + $tableText .= "|-\n"; |
172 | 194 | } |
173 | | - $text .= <<<END |
| 195 | + $tableText .= <<<END |
174 | 196 | ! $aggregating_label |
175 | 197 | | {{#ask:[[$aggregating_property::{{SUBJECTPAGENAME}}]]|format=list}} |
176 | 198 | |
177 | 199 | END; |
178 | 200 | } |
179 | | - $text .= "|}\n"; |
| 201 | + $tableText .= "|}\n"; |
| 202 | + if ( !is_null( $setInternalText ) ) { |
| 203 | + $setInternalText .= "}}\n"; |
| 204 | + $text .= $setInternalText; |
| 205 | + } |
| 206 | + |
| 207 | + $text .= $tableText; |
180 | 208 | if ( $category != '' ) { |
181 | 209 | global $wgContLang; |
182 | 210 | $namespace_labels = $wgContLang->getNamespaces(); |