Index: trunk/extensions/PageSchemas/PS_ExtensionHandler.php |
— | — | @@ -0,0 +1,106 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Yaron Koren |
| 5 | + * @file |
| 6 | + * @ingroup SF |
| 7 | + */ |
| 8 | + |
| 9 | +class PSExtensionHandler { |
| 10 | + |
| 11 | + public static function getDisplayColor() { |
| 12 | + return 'white'; |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Creates an object to hold form-wide information, based on an XML |
| 17 | + * object from the Page Schemas extension. |
| 18 | + */ |
| 19 | + public static function createPageSchemasObject( $tagName, $xml ) { |
| 20 | + return array(); |
| 21 | + } |
| 22 | + |
| 23 | + public static function getSchemaDisplayValues( $schemaXML ) { |
| 24 | + return null; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Displays form details for one template in the Page Schemas XML. |
| 29 | + */ |
| 30 | + public static function getTemplateDisplayValues( $templateXML ) { |
| 31 | + return null; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Displays data on a single form input in the Page Schemas XML. |
| 36 | + */ |
| 37 | + public static function getFieldDisplayValues( $fieldXML ) { |
| 38 | + return null; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Creates Page Schemas XML for form-wide information. |
| 43 | + */ |
| 44 | + public static function getSchemaXML() { |
| 45 | + return null; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Creates Page Schemas XML for form information on templates. |
| 50 | + */ |
| 51 | + public static function getTemplateXML() { |
| 52 | + return null; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Creates Page Schemas XML for form fields. |
| 57 | + */ |
| 58 | + public static function getFieldXML() { |
| 59 | + return null; |
| 60 | + } |
| 61 | + |
| 62 | + public static function getSchemaDisplayString() { |
| 63 | + return null; |
| 64 | + } |
| 65 | + |
| 66 | + public static function getSchemaEditingHTML( $pageSchema ) { |
| 67 | + return null; |
| 68 | + } |
| 69 | + |
| 70 | + public static function getTemplateDisplayString() { |
| 71 | + return null; |
| 72 | + } |
| 73 | + |
| 74 | + public static function getTemplateEditingHTML( $psTemplate ) { |
| 75 | + return null; |
| 76 | + } |
| 77 | + |
| 78 | + public static function getFieldDisplayString() { |
| 79 | + return null; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Returns the HTML for inputs to define a single form field, |
| 84 | + * within the Page Schemas 'edit schema' page. |
| 85 | + */ |
| 86 | + public static function getFieldEditingHTML( $psField ) { |
| 87 | + return null; |
| 88 | + } |
| 89 | + |
| 90 | + public static function getFieldInfo( $psTemplate ) { |
| 91 | + return null; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Return the list of pages that Semantic Forms could generate from |
| 96 | + * the current Page Schemas schema. |
| 97 | + */ |
| 98 | + public static function getPagesToGenerate( $psSchemaObj ) { |
| 99 | + return array(); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Generate pages (form and templates) specified in the list. |
| 104 | + */ |
| 105 | + public static function generatePages( $psSchemaObj, $selectedPages ) { |
| 106 | + } |
| 107 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | // TODO - this should be a non-static method of the PSSchema class, |
136 | 136 | // instead of taking in XML. |
137 | 137 | static function displaySchema( $schemaXML ) { |
138 | | - global $wgTitle; |
| 138 | + global $wgTitle, $wgPageSchemasHandlerClasses; |
139 | 139 | |
140 | 140 | if ( $wgTitle->getNamespace() != NS_CATEGORY ) { |
141 | 141 | return ''; |
— | — | @@ -143,10 +143,13 @@ |
144 | 144 | $name = $schemaXML->attributes()->name; |
145 | 145 | $text .= self::tableRowHTML( 'pageSchemaHeader', 'Page schema' ); |
146 | 146 | |
147 | | - $displayInfoFromExtensions = array(); |
148 | | - wfRunHooks( 'PageSchemasGetSchemaDisplayInfo', array( $schemaXML, &$displayInfoFromExtensions ) ); |
149 | | - foreach ( $displayInfoFromExtensions as $displayInfo ) { |
150 | | - list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 147 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 148 | + list( $elementName, $values ) = call_user_func( array( $psHandlerClass, 'getSchemaDisplayValues' ), $schemaXML ); |
| 149 | + if ( is_null( $elementName ) ) { |
| 150 | + continue; |
| 151 | + } |
| 152 | + $label = call_user_func( array( $psHandlerClass, 'getSchemaDisplayString' ) ); |
| 153 | + $bgColor = call_user_func( array( $psHandlerClass, 'getDisplayColor' ) ); |
151 | 154 | $text .= self::tableRowHTML( 'schemaExtensionRow', $label, $elementName, $bgColor ); |
152 | 155 | foreach ( $values as $fieldName => $value ) { |
153 | 156 | $text .= self::attrRowHTML( 'schemaAttrRow', $fieldName, $value ); |
— | — | @@ -162,6 +165,8 @@ |
163 | 166 | } |
164 | 167 | |
165 | 168 | static function displayTemplate ( $templateXML ) { |
| 169 | + global $wgPageSchemasHandlerClasses; |
| 170 | + |
166 | 171 | $name = $templateXML->attributes()->name; |
167 | 172 | $text = self::tableRowHTML( 'templateRow', 'Template', $name ); |
168 | 173 | $multiple = $templateXML->attributes()->multiple; |
— | — | @@ -169,10 +174,13 @@ |
170 | 175 | $text .= self::attrRowHTML( 'schemaAttrRow', 'multiple', null ); |
171 | 176 | } |
172 | 177 | |
173 | | - $displayInfoFromExtensions = array(); |
174 | | - wfRunHooks( 'PageSchemasGetTemplateDisplayInfo', array( $templateXML, &$displayInfoFromExtensions ) ); |
175 | | - foreach( $displayInfoFromExtensions as $displayInfo ) { |
176 | | - list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 178 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 179 | + list( $elementName, $values ) = call_user_func( array( $psHandlerClass, 'getTemplateDisplayValues' ), $templateXML ); |
| 180 | + if ( is_null( $elementName ) ) { |
| 181 | + continue; |
| 182 | + } |
| 183 | + $label = call_user_func( array( $psHandlerClass, 'getTemplateDisplayString' ) ); |
| 184 | + $bgColor = call_user_func( array( $psHandlerClass, 'getDisplayColor' ) ); |
177 | 185 | $text .= self::tableRowHTML( 'fieldExtensionRow', $label, $elementName, $bgColor ); |
178 | 186 | foreach ( $values as $fieldName => $value ) { |
179 | 187 | $text .= self::attrRowHTML( 'fieldAttrRow', $fieldName, $value ); |
— | — | @@ -185,6 +193,8 @@ |
186 | 194 | } |
187 | 195 | |
188 | 196 | static function displayField ( $fieldXML ) { |
| 197 | + global $wgPageSchemasHandlerClasses; |
| 198 | + |
189 | 199 | $name = $fieldXML->attributes()->name; |
190 | 200 | $text = self::tableRowHTML( 'fieldRow', 'Field', $name ); |
191 | 201 | |
— | — | @@ -197,12 +207,15 @@ |
198 | 208 | } |
199 | 209 | } |
200 | 210 | |
201 | | - // Let extensions that store data within the Page Schemas XML each |
202 | | - // handle displaying their data, by adding to this array. |
203 | | - $displayInfoFromExtensions = array(); |
204 | | - wfRunHooks( 'PageSchemasGetFieldDisplayInfo', array( $fieldXML, &$displayInfoFromExtensions ) ); |
205 | | - foreach( $displayInfoFromExtensions as $displayInfo ) { |
206 | | - list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 211 | + // Let extensions that store data within the Page Schemas XML |
| 212 | + // each handle displaying their data, by adding to this array. |
| 213 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 214 | + list( $elementName, $values ) = call_user_func( array( $psHandlerClass, 'getFieldDisplayValues' ), $fieldXML ); |
| 215 | + if ( is_null( $elementName ) ) { |
| 216 | + continue; |
| 217 | + } |
| 218 | + $label = call_user_func( array( $psHandlerClass, 'getFieldDisplayString' ) ); |
| 219 | + $bgColor = call_user_func( array( $psHandlerClass, 'getDisplayColor' ) ); |
207 | 220 | $text .= self::tableRowHTML( 'fieldExtensionRow', $label, $elementName, $bgColor ); |
208 | 221 | foreach ( $values as $fieldName => $value ) { |
209 | 222 | $text .= self::attrRowHTML( 'fieldAttrRow', $fieldName, $value ); |
— | — | @@ -210,6 +223,15 @@ |
211 | 224 | } |
212 | 225 | return $text; |
213 | 226 | } |
| 227 | + |
| 228 | + public static function getValueFromObject( $object, $key ) { |
| 229 | + if ( is_null( $object ) ) { |
| 230 | + return null; |
| 231 | + } elseif ( !array_key_exists( $key, $object ) ) { |
| 232 | + return null; |
| 233 | + } |
| 234 | + return $object[$key]; |
| 235 | + } |
214 | 236 | } |
215 | 237 | |
216 | 238 | /** |
— | — | @@ -245,7 +267,7 @@ |
246 | 268 | // retrieve the third attribute, which is pp_value |
247 | 269 | $pageXMLstr = $row[2]; |
248 | 270 | $this->mPageXML = simplexml_load_string ( $pageXMLstr ); |
249 | | - /* index for template objects */ |
| 271 | + // index for template objects |
250 | 272 | $i = 0; |
251 | 273 | $inherited_templates = array(); |
252 | 274 | foreach ( $this->mPageXML->children() as $tag => $child ) { |
— | — | @@ -279,7 +301,10 @@ |
280 | 302 | * Generates all pages selected by the user, based on the Page Schemas XML. |
281 | 303 | */ |
282 | 304 | public function generateAllPages ( $selectedPageList ) { |
283 | | - wfRunHooks( 'PageSchemasGeneratePages', array( $this, $selectedPageList )); |
| 305 | + global $wgPageSchemasHandlerClasses; |
| 306 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 307 | + call_user_func( array( $psHandlerClass, 'generatePages' ), $this, $selectedPageList ); |
| 308 | + } |
284 | 309 | } |
285 | 310 | |
286 | 311 | public function getCategoryName() { |
— | — | @@ -302,9 +327,14 @@ |
303 | 328 | } |
304 | 329 | |
305 | 330 | public function getObject( $objectName ) { |
306 | | - $object = array(); |
307 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->mPageXML, &$object ) ); |
308 | | - return $object; |
| 331 | + global $wgPageSchemasHandlerClasses; |
| 332 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 333 | + $object = call_user_func( array( $psHandlerClass, 'createPageSchemasObject' ), $objectName, $this->mPageXML ); |
| 334 | + if ( !is_null( $object ) ) { |
| 335 | + return $object; |
| 336 | + } |
| 337 | + } |
| 338 | + return null; |
309 | 339 | } |
310 | 340 | } |
311 | 341 | |
— | — | @@ -320,14 +350,14 @@ |
321 | 351 | if( ((string) $templateXML->attributes()->multiple) == "multiple" ) { |
322 | 352 | $this->mMultipleAllowed = true; |
323 | 353 | } |
324 | | - /*index for template objects */ |
| 354 | + // Index for template objects |
325 | 355 | $i = 0 ; |
326 | 356 | $inherited_fields = array(); |
327 | 357 | foreach ($templateXML->children() as $child) { |
328 | 358 | if ( $child->getName() == 'InheritsFrom' ) { |
329 | 359 | $schema_to_inherit = (string) $child->attributes()->schema; |
330 | 360 | $template_to_inherit = (string) $child->attributes()->template; |
331 | | - if( $schema_to_inherit !=null && $template_to_inherit != null ) { |
| 361 | + if ( $schema_to_inherit != null && $template_to_inherit != null ) { |
332 | 362 | $inheritedSchemaObj = new PSSchema( $schema_to_inherit ); |
333 | 363 | $inherited_templates = $inheritedSchemaObj->getTemplates(); |
334 | 364 | foreach( $inherited_templates as $inherited_template ) { |
— | — | @@ -339,13 +369,13 @@ |
340 | 370 | } elseif ( $child->getName() == "Field" ) { |
341 | 371 | $ignore = (string) $child->attributes()->ignore; |
342 | 372 | if ( count($child->children()) > 0 ) { //@TODO :Can be dealt more efficiently |
343 | | - $fieldObj = new PSTemplateField($child); |
| 373 | + $fieldObj = new PSTemplateField( $child ); |
344 | 374 | $this->mFields[$i++]= $fieldObj; |
345 | 375 | } elseif ( $ignore != "true" ) { |
346 | 376 | // Code to add fields from inherited templates |
347 | 377 | $field_name = (string) $child->attributes()->name; |
348 | | - foreach( $inherited_fields as $inherited_field ) { |
349 | | - if( $field_name == $inherited_field->getName() ){ |
| 378 | + foreach ( $inherited_fields as $inherited_field ) { |
| 379 | + if ( $field_name == $inherited_field->getName() ) { |
350 | 380 | $this->mFields[$i++]= $inherited_field; |
351 | 381 | } |
352 | 382 | } |
— | — | @@ -354,25 +384,30 @@ |
355 | 385 | } |
356 | 386 | } |
357 | 387 | |
358 | | - function getName() { |
| 388 | + public function getName() { |
359 | 389 | return $this->mTemplateName; |
360 | 390 | } |
361 | 391 | |
362 | | - function getXML() { |
| 392 | + public function getXML() { |
363 | 393 | return $this->mTemplateXML; |
364 | 394 | } |
365 | 395 | |
366 | | - function isMultiple() { |
| 396 | + public function isMultiple() { |
367 | 397 | return $this->mMultipleAllowed; |
368 | 398 | } |
369 | 399 | |
370 | | - function getObject( $objectName ) { |
371 | | - $object = array(); |
372 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->mTemplateXML, &$object ) ); |
373 | | - return $object; |
| 400 | + public function getObject( $objectName ) { |
| 401 | + global $wgPageSchemasHandlerClasses; |
| 402 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 403 | + $object = call_user_func( array( $psHandlerClass, 'createPageSchemasObject' ), $objectName, $this->mTemplateXML ); |
| 404 | + if ( !empty( $object ) ) { |
| 405 | + return $object; |
| 406 | + } |
| 407 | + } |
| 408 | + return null; |
374 | 409 | } |
375 | 410 | |
376 | | - function getFields() { |
| 411 | + public function getFields() { |
377 | 412 | return $this->mFields; |
378 | 413 | } |
379 | 414 | } |
— | — | @@ -400,25 +435,31 @@ |
401 | 436 | } |
402 | 437 | } |
403 | 438 | |
404 | | - public function getDelimiter(){ |
| 439 | + public function getDelimiter() { |
405 | 440 | return $this->mDelimiter; |
406 | 441 | } |
407 | 442 | |
408 | | - public function getName(){ |
| 443 | + public function getName() { |
409 | 444 | return $this->mFieldName; |
410 | 445 | } |
411 | 446 | |
412 | | - public function getLabel(){ |
| 447 | + public function getLabel() { |
413 | 448 | return $this->mFieldLabel; |
414 | 449 | } |
415 | 450 | |
416 | | - public function isList(){ |
| 451 | + public function isList() { |
417 | 452 | return $this->mIsList; |
418 | 453 | } |
419 | 454 | |
420 | 455 | public function getObject( $objectName ) { |
421 | | - $object = array(); |
422 | | - wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->mFieldXML, &$object ) ); |
423 | | - return $object; |
| 456 | + global $wgPageSchemasHandlerClasses; |
| 457 | + |
| 458 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 459 | + $object = call_user_func( array( $psHandlerClass, 'createPageSchemasObject' ), $objectName, $this->mFieldXML ); |
| 460 | + if ( !is_null( $object ) ) { |
| 461 | + return $object; |
| 462 | + } |
| 463 | + } |
| 464 | + return null; |
424 | 465 | } |
425 | 466 | } |
Index: trunk/extensions/PageSchemas/specials/PS_GeneratePages.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | function execute( $category ) { |
18 | | - global $wgRequest, $wgOut; |
| 18 | + global $wgRequest, $wgOut, $wgPageSchemasHandlerClasses; |
19 | 19 | |
20 | 20 | $this->setHeaders(); |
21 | 21 | $param = $wgRequest->getText('param'); |
— | — | @@ -48,7 +48,12 @@ |
49 | 49 | // This hook will set an array of strings, with each value |
50 | 50 | // as a title of a page to be created. |
51 | 51 | $pageList = array(); |
52 | | - wfRunHooks( 'PageSchemasGetPageList', array( $pageSchemaObj, &$pageList ) ); |
| 52 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 53 | + $pagesFromHandler = call_user_func( array( $psHandlerClass, "getPagesToGenerate" ), $pageSchemaObj ); |
| 54 | + foreach ( $pagesFromHandler as $page ) { |
| 55 | + $pageList[] = $page; |
| 56 | + } |
| 57 | + } |
53 | 58 | // SpecialPage::getSkin() was added in MW 1.18 |
54 | 59 | if ( is_callable( $this, 'getSkin' ) ) { |
55 | 60 | $skin = $this->getSkin(); |
— | — | @@ -72,9 +77,9 @@ |
73 | 78 | /** |
74 | 79 | * Creates all the pages that the user specified. |
75 | 80 | */ |
76 | | - function generatePages( $categoryName, $toGenPageList ) { |
| 81 | + function generatePages( $categoryName, $selectedPageList ) { |
77 | 82 | $pageSchema = new PSSchema( $categoryName ); |
78 | | - $pageSchema->generateAllPages( $toGenPageList ); |
| 83 | + $pageSchema->generateAllPages( $selectedPageList ); |
79 | 84 | } |
80 | 85 | |
81 | 86 | /** |
Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -33,6 +33,7 @@ |
34 | 34 | */ |
35 | 35 | static function pageSchemaXMLFromRequest() { |
36 | 36 | global $wgRequest; |
| 37 | + global $wgPageSchemasHandlerClasses; |
37 | 38 | |
38 | 39 | // Generate the XML from the form elements. |
39 | 40 | $psXML = '<PageSchema>'; |
— | — | @@ -45,10 +46,12 @@ |
46 | 47 | $schemaXMLFromExtensions = array(); |
47 | 48 | $templateXMLFromExtensions = array(); |
48 | 49 | $fieldXMLFromExtensions = array(); |
49 | | - wfRunHooks( 'PageSchemasGetSchemaXML', array( $wgRequest, &$schemaXMLFromExtensions )); |
50 | | - wfRunHooks( 'PageSchemasGetTemplateXML', array( $wgRequest, &$templateXMLFromExtensions )); |
51 | | - wfRunHooks( 'PageSchemasGetFieldXML', array( $wgRequest, &$fieldXMLFromExtensions )); |
52 | | - foreach ( $schemaXMLFromExtensions as $extensionName => $xml ) { |
| 50 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 51 | + $schemaXMLFromExtensions[] = call_user_func( array( $psHandlerClass, 'getSchemaXML' ) ); |
| 52 | + $templateXMLFromExtensions[] = call_user_func( array( $psHandlerClass, 'getTemplateXML' ) ); |
| 53 | + $fieldXMLFromExtensions[] = call_user_func( array( $psHandlerClass, 'getFieldXML' ) ); |
| 54 | + } |
| 55 | + foreach ( $schemaXMLFromExtensions as $xml ) { |
53 | 56 | if ( !empty( $xml ) ) { |
54 | 57 | $psXML .= $xml; |
55 | 58 | } |
— | — | @@ -102,8 +105,7 @@ |
103 | 106 | } |
104 | 107 | } |
105 | 108 | $psXML .= '</PageSchema>'; |
106 | | - $psXML = self::prettyPrintXML( $psXML ); |
107 | | - return $psXML; |
| 109 | + return self::prettyPrintXML( $psXML ); |
108 | 110 | } |
109 | 111 | |
110 | 112 | /** |
— | — | @@ -179,8 +181,8 @@ |
180 | 182 | /* |
181 | 183 | * Returns the HTML for a form section coming from a specific extension. |
182 | 184 | */ |
183 | | - static function printFieldHTMLForExtension( $valuesFromExtension ) { |
184 | | - list( $label, $color, $html, $hasExistingValues ) = $valuesFromExtension; |
| 185 | + static function printFieldHTMLForExtension( $valuesFromExtension, $label, $color ) { |
| 186 | + list( $html, $hasExistingValues ) = $valuesFromExtension; |
185 | 187 | return self::printFormSection( $label, $color, $html, null, $hasExistingValues ); |
186 | 188 | } |
187 | 189 | |
— | — | @@ -188,7 +190,9 @@ |
189 | 191 | * Returns the HTML for a section of the form comprising one |
190 | 192 | * template field. |
191 | 193 | */ |
192 | | - static function printFieldSection( $field_xml = null, $pageSchemaField = null ) { |
| 194 | + static function printFieldSection( $field_xml = null, $psField = null ) { |
| 195 | + global $wgPageSchemasHandlerClasses; |
| 196 | + |
193 | 197 | if ( is_null( $field_xml ) ) { |
194 | 198 | $fieldNum = 'fnum'; |
195 | 199 | } else { |
— | — | @@ -221,9 +225,9 @@ |
222 | 226 | } |
223 | 227 | } |
224 | 228 | $fieldHTML = wfMsg( 'ps-namelabel' ) . ' '; |
225 | | - $fieldHTML .= Html::input( 'f_name_' . $fieldNum, $fieldName, 'text', array( 'size' => 15 ) ) . ' '; |
| 229 | + $fieldHTML .= Html::input( 'f_name_' . $fieldNum, $fieldName, 'text', array( 'size' => 25 ) ) . ' '; |
226 | 230 | $fieldHTML .= wfMsg( 'ps-displaylabel' ) . ' '; |
227 | | - $fieldHTML .= Html::input( 'f_label_' . $fieldNum, $fieldLabel, 'text', array( 'size' => 15 ) ); |
| 231 | + $fieldHTML .= Html::input( 'f_label_' . $fieldNum, $fieldLabel, 'text', array( 'size' => 25 ) ); |
228 | 232 | $fieldHTML = Html::rawElement( 'p', null, $fieldHTML ) . "\n"; |
229 | 233 | $fieldIsListInput = Html::input( 'f_is_list_' . $fieldNum, null, 'checkbox', $isListAttrs ); |
230 | 234 | $fieldHTML .= Html::rawElement( 'p', null, $fieldIsListInput . ' ' . wfMsg( 'ps-field-list-label' ) ); |
— | — | @@ -231,10 +235,14 @@ |
232 | 236 | $fieldHTML .= "\n" . Html::rawElement( 'p', $delimiterAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
233 | 237 | |
234 | 238 | // Insert HTML text from extensions |
235 | | - $htmlFromExtensions = array(); |
236 | | - wfRunHooks( 'PageSchemasGetFieldHTML', array( $pageSchemaField, &$htmlFromExtensions ) ); |
237 | | - foreach ( $htmlFromExtensions as $valuesFromExtension ) { |
238 | | - $html = self::printFieldHTMLForExtension( $valuesFromExtension ); |
| 239 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 240 | + $valuesFromExtension = call_user_func( array( $psHandlerClass, "getFieldEditingHTML" ), $psField ); |
| 241 | + if ( is_null( $valuesFromExtension ) ) { |
| 242 | + continue; |
| 243 | + } |
| 244 | + $label = call_user_func( array( $psHandlerClass, "getFieldDisplayString" ) ); |
| 245 | + $color = call_user_func( array( $psHandlerClass, "getDisplayColor" ) ); |
| 246 | + $html = self::printFieldHTMLForExtension( $valuesFromExtension, $label, $color ); |
239 | 247 | // We use 'num' here, instead of 'fnum', to distinguish |
240 | 248 | // between field names from Page Schemas (which get |
241 | 249 | // their number set via Javascript) and field names from |
— | — | @@ -259,6 +267,8 @@ |
260 | 268 | * Returns the HTML for a section of the form comprising one template. |
261 | 269 | */ |
262 | 270 | static function printTemplateSection( $template_num = 'tnum', $templateXML = null, $psTemplate = null ) { |
| 271 | + global $wgPageSchemasHandlerClasses; |
| 272 | + |
263 | 273 | if ( is_null( $psTemplate ) ) { |
264 | 274 | $psTemplateFields = array(); |
265 | 275 | } else { |
— | — | @@ -293,10 +303,14 @@ |
294 | 304 | } |
295 | 305 | */ |
296 | 306 | |
297 | | - $htmlForTemplate = array(); |
298 | | - wfRunHooks( 'PageSchemasGetTemplateHTML', array( $psTemplate, &$htmlForTemplate ) ); |
299 | | - foreach ( $htmlForTemplate as $valuesFromExtension ) { |
300 | | - $html = self::printFieldHTMLForExtension( $valuesFromExtension ); |
| 307 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 308 | + $valuesFromExtension = call_user_func( array( $psHandlerClass, "getTemplateEditingHTML" ), $psTemplate ); |
| 309 | + if ( is_null( $valuesFromExtension ) ) { |
| 310 | + continue; |
| 311 | + } |
| 312 | + $label = call_user_func( array( $psHandlerClass, "getTemplateDisplayString" ) ); |
| 313 | + $color = call_user_func( array( $psHandlerClass, "getDisplayColor" ) ); |
| 314 | + $html = self::printFieldHTMLForExtension( $valuesFromExtension, $label, $color ); |
301 | 315 | $templateHTML .= str_replace( 'num', $template_num, $html ); |
302 | 316 | } |
303 | 317 | |
— | — | @@ -338,8 +352,7 @@ |
339 | 353 | * Returns the HTML to display an entire form. |
340 | 354 | */ |
341 | 355 | static function printForm( $pageSchemaObj = null, $pageXML = null ) { |
342 | | - $htmlForSchema = array(); |
343 | | - wfRunHooks( 'PageSchemasGetSchemaHTML', array( $pageSchemaObj, &$htmlForSchema ) ); |
| 356 | + global $wgPageSchemasHandlerClasses; |
344 | 357 | |
345 | 358 | if ( is_null( $pageSchemaObj ) ) { |
346 | 359 | $psTemplates = array(); |
— | — | @@ -367,8 +380,15 @@ |
368 | 381 | $additionalXMLInput = "\n\t\t\t\t" . Html::textarea( 'ps_add_xml', $ps_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) ); |
369 | 382 | $text .= '<p>' . wfMsg('ps-add-xml-label') . $additionalXMLInput . "\n</p>"; |
370 | 383 | |
371 | | - foreach ( $htmlForSchema as $valuesFromExtension ) { |
372 | | - $text .= self::printFieldHTMLForExtension( $valuesFromExtension ); |
| 384 | + foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) { |
| 385 | + $valuesFromExtension = call_user_func( array( $psHandlerClass, "getSchemaEditingHTML" ), $pageSchemaObj ); |
| 386 | + if ( is_null( $valuesFromExtension ) ) { |
| 387 | + continue; |
| 388 | + } |
| 389 | + $label = call_user_func( array( $psHandlerClass, "getSchemaDisplayString" ) ); |
| 390 | + $color = call_user_func( array( $psHandlerClass, "getDisplayColor" ) ); |
| 391 | + $html = self::printFieldHTMLForExtension( $valuesFromExtension, $label, $color ); |
| 392 | + $text .= str_replace( 'num', $fieldNum, $html ); |
373 | 393 | } |
374 | 394 | |
375 | 395 | $text .= '<div id="templatesList">' . "\n"; |
Index: trunk/extensions/PageSchemas/PageSchemas.php |
— | — | @@ -35,11 +35,11 @@ |
36 | 36 | // Internationalization |
37 | 37 | $wgExtensionMessagesFiles['PageSchemas'] = $dir . 'PageSchemas.i18n.php'; |
38 | 38 | |
39 | | -//Job classes |
| 39 | +// Job classes |
40 | 40 | $wgJobClasses['pageSchemasCreatePage'] = 'PSCreatePageJob'; |
41 | 41 | $wgAutoloadClasses['PSCreatePageJob'] = $dir . 'PS_CreatePageJob.php'; |
42 | 42 | |
43 | | -// Register auto load for the special page class |
| 43 | +// Register page classes |
44 | 44 | $wgAutoloadClasses['PageSchemasHooks'] = $dir . 'PageSchemas.hooks.php'; |
45 | 45 | $wgAutoloadClasses['PageSchemas'] = $dir . 'PageSchemas.classes.php'; |
46 | 46 | $wgAutoloadClasses['PSSchema'] = $dir . 'PageSchemas.classes.php'; |
— | — | @@ -47,7 +47,9 @@ |
48 | 48 | $wgAutoloadClasses['PSGeneratePages'] = $dir . 'specials/PS_GeneratePages.php'; |
49 | 49 | $wgAutoloadClasses['PSEditSchema'] = $dir . 'specials/PS_EditSchema.php'; |
50 | 50 | $wgAutoloadClasses['PSTabs'] = $dir . 'PS_Tabs.php'; |
51 | | -// registering Special page |
| 51 | +$wgAutoloadClasses['PSExtensionHandler'] = $dir . 'PS_ExtensionHandler.php'; |
| 52 | + |
| 53 | +// Register special pages |
52 | 54 | $wgSpecialPages['GeneratePages'] = 'PSGeneratePages'; |
53 | 55 | $wgSpecialPages['EditSchema'] = 'PSEditSchema'; |
54 | 56 | $wgSpecialPageGroups['GeneratePages'] = 'other'; |
— | — | @@ -83,3 +85,4 @@ |
84 | 86 | |
85 | 87 | // Page Schemas global variables |
86 | 88 | $wgPageSchemasFieldNum = 0; |
| 89 | +$wgPageSchemasHandlerClasses = array(); |