Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | global $wgOut; |
58 | 58 | $output = $wgOut; |
59 | 59 | } |
60 | | - $output->addModules( 'jquery' ); |
| 60 | + $output->addModules( 'ext.pageschemas.main' ); |
61 | 61 | } |
62 | 62 | |
63 | 63 | public static function titleString( $title ) { |
— | — | @@ -98,43 +98,59 @@ |
99 | 99 | return $xml_success; |
100 | 100 | } |
101 | 101 | |
102 | | - static function tableRowHTML($css_class, $data_type, $value = null) { |
103 | | - $data_type = htmlspecialchars($data_type); |
104 | | - if ( is_null( $value ) ) { |
| 102 | + static function tableRowHTML( $css_class, $data_type, $value = null, $bgColor = null ) { |
| 103 | + $data_type = htmlspecialchars( $data_type ); |
| 104 | + if ( !is_null( $bgColor ) ) { |
| 105 | + // We don't actually use the passed-in background color, except as an indicator |
| 106 | + // that this is a header row for extension data, and thus should have special |
| 107 | + // display. |
| 108 | + // In the future, the background color may get used, though. |
| 109 | + $data_type = HTML::element( 'span', array( 'style' => "color: #993333;" ), $data_type ); |
| 110 | + } |
| 111 | + if ( $value == '' ) { |
105 | 112 | $content = $data_type; |
106 | 113 | } else { |
107 | | - $content = "$data_type: " . HTML::element('span', array('class' => 'rowValue'), $value); |
| 114 | + $content = "$data_type: " . HTML::element( 'span', array( 'class' => 'rowValue' ), $value ); |
108 | 115 | } |
109 | | - $cell = HTML::rawElement('td', array('colspan' => 2, 'class' => $css_class), $content); |
110 | | - $text = HTML::rawElement('tr', null, $cell); |
| 116 | + $cellAttrs = array( 'colspan' => 2, 'class' => $css_class ); |
| 117 | + $cell = HTML::rawElement( 'td', $cellAttrs, $content ); |
| 118 | + //$cell = "<td colspan=2><span style=\"background: white; min-width; 20px;\">.</span><span style=\"background: $bgColor;\">$content</span></td>"; |
| 119 | + $text = HTML::rawElement( 'tr', array( 'style' => 'border: 1px black solid; margin: 10px;' ), $cell ); |
111 | 120 | $text .= "\n"; |
112 | 121 | return $text; |
113 | 122 | } |
114 | 123 | |
115 | | - static function tableMessageRowHTML( $css_class, $name, $value ) { |
116 | | - $cell1 = HTML::element('td', array('class' => $css_class), $name); |
117 | | - $cell2 = HTML::element('td', array('class' => 'msg'), $value); |
118 | | - $text = HTML::rawElement('tr', null, $cell1 . "\n" . $cell2); |
| 124 | + static function attrRowHTML( $cssClass, $fieldName, $value ) { |
| 125 | + $fieldNameAttrs = array( 'class' => $cssClass, 'style' => 'font-weight: normal;' ); |
| 126 | + $fieldNameCell = HTML::rawElement( 'td', $fieldNameAttrs, $fieldName ); |
| 127 | + $valueCell = HTML::element( 'td', array( 'class' => 'msg', 'style' => 'font-weight: bold;' ), $value ); |
| 128 | + $text = HTML::rawElement( 'tr', null, $fieldNameCell . "\n" . $valueCell ); |
119 | 129 | $text .= "\n"; |
120 | 130 | return $text; |
121 | 131 | } |
122 | 132 | |
123 | | - static function parsePageSchemas($class_schema_xml) { |
| 133 | + static function displaySchema($schema_xml) { |
124 | 134 | global $wgTitle; |
125 | 135 | |
126 | 136 | if ( $wgTitle->getNamespace() == NS_CATEGORY ) { |
127 | | - $text = Html::element( 'p', null, wfMsg( 'ps-schema-description' ) ) . "\n"; |
128 | | - $text .= "<table class=\"pageSchema\">\n"; |
129 | | - $name = $class_schema_xml->attributes()->name; |
130 | | - $text .= self::tableRowHTML('paramGroup', 'PageSchema', $name); |
131 | | - foreach ( $class_schema_xml->children() as $tag => $child ) { |
132 | | - // TODO - need a hook call right here |
133 | | - if ( $tag == 'semanticforms_Form' ) { |
134 | | - $text .= self::parseFormElem($child); |
135 | | - } elseif ($tag == 'Template') { |
136 | | - $text .= self::parseTemplate($child); |
| 137 | + //$text = Html::element( 'p', null, wfMsg( 'ps-schema-description' ) ) . "\n"; |
| 138 | + $text = "<table class=\"pageSchema mw-collapsible mw-collapsed\">\n"; |
| 139 | + $name = $schema_xml->attributes()->name; |
| 140 | + $text .= self::tableRowHTML( 'pageSchemaHeader', 'Page schema' ); |
| 141 | + $displayInfoFromExtensions = array(); |
| 142 | + wfRunHooks( 'PageSchemasGetSchemaDisplayInfo', array( $schema_xml, &$displayInfoFromExtensions ) ); |
| 143 | + foreach( $displayInfoFromExtensions as $displayInfo ) { |
| 144 | + list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 145 | + $text .= self::tableRowHTML( 'schemaExtensionRow', $label, $elementName, $bgColor ); |
| 146 | + foreach ( $values as $fieldName => $value ) { |
| 147 | + $text .= self::attrRowHTML( 'schemaAttrRow', $fieldName, $value ); |
137 | 148 | } |
138 | 149 | } |
| 150 | + foreach ( $schema_xml->children() as $tag => $child ) { |
| 151 | + if ( $tag == 'Template') { |
| 152 | + $text .= self::displayTemplate($child); |
| 153 | + } |
| 154 | + } |
139 | 155 | $text .= "</table>\n"; |
140 | 156 | } else { |
141 | 157 | $text = ""; |
— | — | @@ -142,34 +158,52 @@ |
143 | 159 | return $text; |
144 | 160 | } |
145 | 161 | |
146 | | - /** |
147 | | - * @TODO - this should move into Semantic Forms, via a hook |
148 | | - */ |
149 | | - static function parseFormElem( $form_xml ) { |
150 | | - $name = $form_xml->attributes()->name; |
151 | | - $text = self::tableRowHTML('param', 'Form', $name); |
152 | | - foreach ($form_xml->children() as $key => $value ) { |
153 | | - $text .= self::tableMessageRowHTML( "paramAttrMsg", (string)$key, (string)$value ); |
| 162 | + static function displayTemplate ( $templateXML ) { |
| 163 | + $name = $templateXML->attributes()->name; |
| 164 | + $text = self::tableRowHTML( 'templateRow', 'Template', $name ); |
| 165 | + $multiple = $templateXML->attributes()->multiple; |
| 166 | + if ( $multiple == 'multiple' ) { |
| 167 | + $text .= self::attrRowHTML( 'schemaAttrRow', 'multiple', null ); |
154 | 168 | } |
| 169 | + $displayInfoFromExtensions = array(); |
| 170 | + wfRunHooks( 'PageSchemasGetTemplateDisplayInfo', array( $templateXML, &$displayInfoFromExtensions ) ); |
| 171 | + foreach( $displayInfoFromExtensions as $displayInfo ) { |
| 172 | + list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 173 | + $text .= self::tableRowHTML( 'fieldExtensionRow', $label, $elementName, $bgColor ); |
| 174 | + foreach ( $values as $fieldName => $value ) { |
| 175 | + $text .= self::attrRowHTML( 'fieldAttrRow', $fieldName, $value ); |
| 176 | + } |
| 177 | + } |
| 178 | + foreach ( $templateXML->children() as $child ) { |
| 179 | + $text .= self::displayField( $child ); |
| 180 | + } |
155 | 181 | return $text; |
156 | 182 | } |
157 | 183 | |
158 | | - static function parseTemplate ( $template_xml ) { |
159 | | - $name = $template_xml->attributes()->name; |
160 | | - $text = self::tableRowHTML( 'param', 'Template', $name ); |
161 | | - foreach ( $template_xml->children() as $child ) { |
162 | | - $text .= self::parseField( $child ); |
| 184 | + static function displayField ( $fieldXML ) { |
| 185 | + $name = $fieldXML->attributes()->name; |
| 186 | + $text = self::tableRowHTML( 'fieldRow', 'Field', $name ); |
| 187 | + |
| 188 | + if( ((string) $fieldXML->attributes()->list) == "list" ) { |
| 189 | + $text .= self::attrRowHTML( 'fieldAttrRow', 'List', null ); |
163 | 190 | } |
164 | | - return $text; |
165 | | - } |
166 | | - static function parseField ( $field_xml ) { |
167 | | - $name = $field_xml->attributes()->name; |
168 | | - $text = self::tableRowHTML( 'paramAttr', 'Field', $name ); |
169 | | - $text_object = array(); //different extensions will fill the html parsed text in this array via hooks |
170 | | - wfRunHooks( 'PSParseFieldElements', array( $field_xml, &$text_object ) ); |
171 | | - foreach( $text_object as $key => $value ) { |
172 | | - $text .= $value; |
| 191 | + foreach ( $fieldXML->children() as $tag => $child ) { |
| 192 | + if ( $tag == 'Label' ) { |
| 193 | + $text .= self::attrRowHTML( 'fieldAttrRow', 'Label', $child ); |
| 194 | + } |
173 | 195 | } |
| 196 | + |
| 197 | + // Let extensions that store data within the Page Schemas XML each |
| 198 | + // handle displaying their data, by adding to this array. |
| 199 | + $displayInfoFromExtensions = array(); |
| 200 | + wfRunHooks( 'PageSchemasGetFieldDisplayInfo', array( $fieldXML, &$displayInfoFromExtensions ) ); |
| 201 | + foreach( $displayInfoFromExtensions as $displayInfo ) { |
| 202 | + list( $label, $elementName, $bgColor, $values ) = $displayInfo; |
| 203 | + $text .= self::tableRowHTML( 'fieldExtensionRow', $label, $elementName, $bgColor ); |
| 204 | + foreach ( $values as $fieldName => $value ) { |
| 205 | + $text .= self::attrRowHTML( 'fieldAttrRow', $fieldName, $value ); |
| 206 | + } |
| 207 | + } |
174 | 208 | return $text; |
175 | 209 | } |
176 | 210 | } |
— | — | @@ -213,7 +247,7 @@ |
214 | 248 | $this->pageXML = simplexml_load_string ( $pageXMLstr ); |
215 | 249 | /* index for template objects */ |
216 | 250 | $i = 0; |
217 | | - $inherited_templates = null ; |
| 251 | + $inherited_templates = array(); |
218 | 252 | foreach ( $this->pageXML->children() as $tag => $child ) { |
219 | 253 | if ( $tag == 'InheritsFrom ' ) { |
220 | 254 | $schema_to_inherit = (string) $child->attributes()->schema; |
— | — | @@ -266,13 +300,13 @@ |
267 | 301 | return $this->categoryName; |
268 | 302 | } |
269 | 303 | } |
| 304 | + |
270 | 305 | class PSTemplate { |
271 | 306 | /* Stores the field objects */ |
272 | 307 | public $PSFields = array(); |
273 | 308 | public $templateName =""; |
274 | 309 | public $templateXML = null; |
275 | 310 | public $multiple_allowed = false; |
276 | | - private $label_name = null; |
277 | 311 | |
278 | 312 | function __construct( $template_xml ) { |
279 | 313 | $this->templateXML = $template_xml; |
— | — | @@ -296,15 +330,13 @@ |
297 | 331 | } |
298 | 332 | } |
299 | 333 | } |
300 | | - } elseif ( $child->getName() == "Label" ) { //@TODO Label => sf:Label |
301 | | - $this->label_name = (string)$child; |
302 | 334 | } elseif ( $child->getName() == "Field" ) { |
303 | 335 | $ignore = (string) $child->attributes()->ignore; |
304 | 336 | if ( count($child->children()) > 0 ) { //@TODO :Can be dealt more efficiently |
305 | 337 | $fieldObj = new PSTemplateField($child); |
306 | 338 | $this->PSFields[$i++]= $fieldObj; |
307 | 339 | } elseif ( $ignore != "true" ) { |
308 | | - //Code to Add Templates from Inherited templates |
| 340 | + // Code to add fields from inherited templates |
309 | 341 | $field_name = (string) $child->attributes()->name; |
310 | 342 | foreach( $inherited_fields as $inherited_field ) { |
311 | 343 | if( $field_name == $inherited_field->getName() ){ |
— | — | @@ -324,8 +356,10 @@ |
325 | 357 | return $this->multiple_allowed; |
326 | 358 | } |
327 | 359 | |
328 | | - public function getLabel() { |
329 | | - return $this->label_name; |
| 360 | + function getObject( $objectName ) { |
| 361 | + $object = array(); |
| 362 | + wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->templateXML, &$object ) ); |
| 363 | + return $object; |
330 | 364 | } |
331 | 365 | |
332 | 366 | function getFields() { |
Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -11,104 +11,6 @@ |
12 | 12 | parent::__construct( 'EditSchema' ); |
13 | 13 | } |
14 | 14 | |
15 | | - public static function addJavascript() { |
16 | | - global $wgOut; |
17 | | - |
18 | | - PageSchemas::addJavascriptAndCSS(); |
19 | | - |
20 | | - // TODO - this should be in a JS file |
21 | | - $template_name_error_str = wfMsg( 'sf_blank_error' ); |
22 | | - $jsText =<<<END |
23 | | -<script type="text/javascript"> |
24 | | -var fieldNum = 0; |
25 | | -var templateNum = 0; |
26 | | -// TODO - this function should be a jQuery 'fn' instead |
27 | | -function psAddField(template_num) { |
28 | | - fieldNum++; |
29 | | - newField = jQuery('#starterField').clone().css('display', '').removeAttr('id'); |
30 | | - newHTML = newField.html().replace(/fnum/g, fieldNum); |
31 | | - newField.html(newHTML); |
32 | | - newField.find(".deleteField").click( function() { |
33 | | - // Remove the encompassing div for this instance. |
34 | | - jQuery(this).closest(".fieldBox") |
35 | | - .fadeOut('fast', function() { jQuery(this).remove(); }); |
36 | | - }); |
37 | | - jQuery('#fieldsList_'+template_num).append(newField); |
38 | | - addjQueryToCheckboxes(); |
39 | | -} |
40 | | - |
41 | | -function psAddTemplate() { |
42 | | - templateNum++; |
43 | | - newField = jQuery('#starterTemplate').clone().css('display', '').removeAttr('id'); |
44 | | - newHTML = newField.html().replace(/tnum/g, templateNum); |
45 | | - newField.html(newHTML); |
46 | | - newField.find(".deleteTemplate").click( function() { |
47 | | - // Remove the encompassing div for this instance. |
48 | | - jQuery(this).closest(".templateBox") |
49 | | - .fadeOut('fast', function() { jQuery(this).remove(); }); |
50 | | - }); |
51 | | - jQuery('#templatesList').append(newField); |
52 | | -} |
53 | | - |
54 | | -function updateFieldNum(field_num) { |
55 | | - fieldNum = field_num; |
56 | | -} |
57 | | - |
58 | | -function addjQueryToCheckboxes() { |
59 | | - jQuery('.isListCheckbox').each(function() { |
60 | | - if (jQuery(this).is(":checked")) { |
61 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
62 | | - } else { |
63 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
64 | | - } |
65 | | - }); |
66 | | - jQuery('.isListCheckbox').click(function() { |
67 | | - if (jQuery(this).is(":checked")) { |
68 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
69 | | - } else { |
70 | | - jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
71 | | - } |
72 | | - }); |
73 | | - jQuery('.sectionCheckbox').each(function() { |
74 | | - if (jQuery(this).is(":checked")) { |
75 | | - jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display', '').removeClass('hiddenSection'); |
76 | | - } else { |
77 | | - jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display', 'none').addClass('hiddenSection'); |
78 | | - } |
79 | | - }); |
80 | | - jQuery('.sectionCheckbox').click(function() { |
81 | | - if (jQuery(this).is(":checked")) { |
82 | | - jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display', '').removeClass('hiddenSection'); |
83 | | - } else { |
84 | | - jQuery(this).closest('.sectionBox').find('.extensionInputs').css('display', 'none').addClass('hiddenSection'); |
85 | | - } |
86 | | - }); |
87 | | -} |
88 | | - |
89 | | -jQuery(document).ready(function() { |
90 | | - jQuery(".deleteField").click( function() { |
91 | | - // Remove the encompassing div for this instance. |
92 | | - jQuery(this).closest(".fieldBox") |
93 | | - .fadeOut('fast', function() { jQuery(this).remove(); }); |
94 | | - }); |
95 | | - jQuery(".deleteTemplate").click( function() { |
96 | | - // Remove the encompassing div for this instance. |
97 | | - jQuery(this).closest(".templateBox") |
98 | | - .fadeOut('fast', function() { jQuery(this).remove(); }); |
99 | | - }); |
100 | | - addjQueryToCheckboxes(); |
101 | | - jQuery('#editPageSchemaForm').submit( function() { |
102 | | - jQuery('#starterTemplate').find("input, select, textarea").attr('disabled', 'disabled'); |
103 | | - jQuery('.hiddenSection').find("input, select, textarea").attr('disabled', 'disabled'); |
104 | | - return true; |
105 | | - } ); |
106 | | -}); |
107 | | -</script> |
108 | | - |
109 | | -END; |
110 | | - $wgOut->addScript( $jsText ); |
111 | | - } |
112 | | - |
113 | 15 | /** |
114 | 16 | * Returns a nicely-formatted version of the XML passed in. |
115 | 17 | * |
— | — | @@ -132,8 +34,7 @@ |
133 | 35 | static function pageSchemaXMLFromRequest() { |
134 | 36 | global $wgRequest; |
135 | 37 | |
136 | | - //Generate the XML from the Form elements |
137 | | - //$s_name = $wgRequest->getText('s_name'); |
| 38 | + // Generate the XML from the form elements. |
138 | 39 | $psXML = '<PageSchema>'; |
139 | 40 | $additionalXML = $wgRequest->getText( 'ps_add_xml' ); |
140 | 41 | $psXML .= $additionalXML; |
— | — | @@ -142,17 +43,17 @@ |
143 | 44 | $templateNum = -1; |
144 | 45 | // Arrays to store the extension-specific XML entered in the form |
145 | 46 | $schemaXMLFromExtensions = array(); |
| 47 | + $templateXMLFromExtensions = array(); |
146 | 48 | $fieldXMLFromExtensions = array(); |
147 | 49 | wfRunHooks( 'PageSchemasGetSchemaXML', array( $wgRequest, &$schemaXMLFromExtensions )); |
| 50 | + wfRunHooks( 'PageSchemasGetTemplateXML', array( $wgRequest, &$templateXMLFromExtensions )); |
148 | 51 | wfRunHooks( 'PageSchemasGetFieldXML', array( $wgRequest, &$fieldXMLFromExtensions )); |
149 | 52 | foreach ( $schemaXMLFromExtensions as $extensionName => $xml ) { |
150 | 53 | if ( !empty( $xml ) ) { |
151 | 54 | $psXML .= $xml; |
152 | 55 | } |
153 | 56 | } |
154 | | - $indexGlobalField = 0 ; //this variable is use to index the array returned by extensions for XML. |
155 | 57 | foreach ( $wgRequest->getValues() as $var => $val ) { |
156 | | - $suffix = substr( $var, -3 ); |
157 | 58 | // Ignore fields from the hidden/starter div |
158 | 59 | if ( substr( $var, 0, 7 ) == 't_name_' ) { |
159 | 60 | $templateNum = substr( $var, 7 ); |
— | — | @@ -161,6 +62,13 @@ |
162 | 63 | } else { |
163 | 64 | $psXML .= '<Template name="'.$val.'">'; |
164 | 65 | } |
| 66 | + |
| 67 | + // Get XML created by extensions for this template |
| 68 | + foreach ( $templateXMLFromExtensions as $extensionName => $xmlPerTemplate ) { |
| 69 | + if ( !empty( $xmlPerTemplate[$templateNum] ) ) { |
| 70 | + $psXML .= $xmlPerTemplate[$templateNum]; |
| 71 | + } |
| 72 | + } |
165 | 73 | } elseif ( substr( $var, 0, 7 ) == 'f_name_' ) { |
166 | 74 | $fieldNum = substr( $var, 7 ); |
167 | 75 | $fieldName = $val; |
— | — | @@ -179,13 +87,12 @@ |
180 | 88 | $psXML .= '<Label>' . $val . '</Label>'; |
181 | 89 | } |
182 | 90 | |
183 | | - // Get XML created by extensions |
| 91 | + // Get XML created by extensions for this field |
184 | 92 | foreach ( $fieldXMLFromExtensions as $extensionName => $xmlPerField ) { |
185 | | - if ( !empty( $xmlPerField[$indexGlobalField] ) ) { |
186 | | - $psXML .= $xmlPerField[$indexGlobalField]; |
| 93 | + if ( !empty( $xmlPerField[$fieldNum] ) ) { |
| 94 | + $psXML .= $xmlPerField[$fieldNum]; |
187 | 95 | } |
188 | 96 | } |
189 | | - $indexGlobalField++ ; |
190 | 97 | } elseif ( substr( $var, 0, 10 ) == 'f_add_xml_' ) { |
191 | 98 | $psXML .= $val; |
192 | 99 | $psXML .= '</Field>'; |
— | — | @@ -220,16 +127,23 @@ |
221 | 128 | ) |
222 | 129 | ); |
223 | 130 | $editSchemaPage = SpecialPage::getTitleFor( 'EditSchema' ); |
| 131 | + $text .= "<ul>\n"; |
224 | 132 | while ( $row = $dbr->fetchRow( $res ) ) { |
225 | | - if ( $row[2] != null ) { |
226 | | - $page_id_cat = $row[0]; |
227 | | - if ( Title::newFromId( $page_id_cat )->getNamespace() == NS_CATEGORY ) { |
228 | | - $cat_text = Title::newFromId( $page_id_cat )->getText(); |
229 | | - $url = $editSchemaPage ->getFullURL() . '/' . $cat_text; |
230 | | - $text .= Html::element( 'a', array( 'href' => $url ), $cat_text ) . '<br />'; |
231 | | - } |
| 133 | + if ( $row[2] == null ) { |
| 134 | + continue; |
232 | 135 | } |
| 136 | + $catTitle = Title::newFromID( $row[0] ); |
| 137 | + if ( $catTitle->getNamespace() !== NS_CATEGORY ) { |
| 138 | + continue; |
| 139 | + } |
| 140 | + $catName = $catTitle->getText(); |
| 141 | + $url = $catTitle->getFullURL( 'action=editschema' ); |
| 142 | + $text .= Html::rawElement( 'li', |
| 143 | + null, |
| 144 | + Html::element( 'a', array( 'href' => $url ), $catName ) |
| 145 | + ); |
233 | 146 | } |
| 147 | + $text .= "</ul>\n"; |
234 | 148 | $dbr->freeResult( $res ); |
235 | 149 | return $text; |
236 | 150 | } |
— | — | @@ -237,19 +151,28 @@ |
238 | 152 | /* |
239 | 153 | * Returns the HTML for one section of the EditSchema form. |
240 | 154 | */ |
241 | | - static function printFormSection( $label, $topColor, $html, $bgColor = 'white', $isCollapsible = false, $hasExistingValues = true ) { |
242 | | - $className = $isCollapsible ? 'sectionBox' : ''; |
243 | | - $text = "<div class=\"$className\" style=\"background: $bgColor; border: 1px #999 solid; padding: 0px; margin-bottom: 10px; margin-top: 10px;\">\n"; |
244 | | - $text .= "<div style=\"font-weight: bold; background: $topColor; padding: 4px 7px; border-bottom: 1px #bbb solid;\">"; |
245 | | - if ( $isCollapsible ) { |
| 155 | + static function printFormSection( $label, $headerColor, $mainHTML, $sectionClass, $hasExistingValues = true ) { |
| 156 | + // Section header |
| 157 | + $headerContents = ''; |
| 158 | + if ( empty( $sectionClass ) ) { |
246 | 159 | $checkboxAttrs = array( 'class' => 'sectionCheckbox' ); |
247 | 160 | if ( $hasExistingValues ) { |
248 | 161 | $checkboxAttrs['checked'] = true; |
249 | 162 | } |
250 | | - $text .= " " . Html::input( 'show_section', null, 'checkbox', $checkboxAttrs ); |
| 163 | + $headerContents .= "\n\t\t" . Html::input( 'show_section', null, 'checkbox', $checkboxAttrs ) . ' '; |
251 | 164 | } |
252 | | - $className = $isCollapsible ? 'extensionInputs' : ''; |
253 | | - $text .= "$label</div>" . "<div class=\"$className\" style=\"padding: 5px 15px;\">$html</div>\n" . "</div>\n"; |
| 165 | + $headerContents .= $label . "\n"; |
| 166 | + $sectionHTML = "\n\t\t\t\t\t" . Html::rawElement( 'div', array( |
| 167 | + 'class' => 'sectionHeader', |
| 168 | + 'style' => "background: $headerColor;" |
| 169 | + ), $headerContents ); |
| 170 | + |
| 171 | + // Body of section, with all the inputs. |
| 172 | + $sectionHTML .= "\n\t" . Html::rawElement( 'div', array( 'class' => 'sectionBody' ), "\n" . $mainHTML ); |
| 173 | + |
| 174 | + // Wrapper around the whole thing. |
| 175 | + $className = "editSchemaSection $sectionClass"; |
| 176 | + $text = "\n\t\t\t\t" . Html::rawElement( 'div', array( 'class' => $className ), $sectionHTML ) . "\n"; |
254 | 177 | return $text; |
255 | 178 | } |
256 | 179 | |
— | — | @@ -258,23 +181,32 @@ |
259 | 182 | */ |
260 | 183 | static function printFieldHTMLForExtension( $valuesFromExtension ) { |
261 | 184 | list( $label, $color, $html, $hasExistingValues ) = $valuesFromExtension; |
262 | | - return self::printFormSection( $label, $color, $html, 'white', true, $hasExistingValues ); |
| 185 | + return self::printFormSection( $label, $color, $html, null, $hasExistingValues ); |
263 | 186 | } |
264 | 187 | |
265 | 188 | /** |
266 | 189 | * Returns the HTML for a section of the form comprising one |
267 | 190 | * template field. |
268 | 191 | */ |
269 | | - static function printFieldSection( $field_xml = null, $pageSchemaField = null, $field_count = 'fnum' ) { |
| 192 | + static function printFieldSection( $field_xml = null, $pageSchemaField = null ) { |
| 193 | + if ( is_null( $field_xml ) ) { |
| 194 | + $fieldNum = 'fnum'; |
| 195 | + } else { |
| 196 | + global $wgPageSchemasFieldNum; |
| 197 | + $fieldNum = $wgPageSchemasFieldNum; |
| 198 | + $wgPageSchemasFieldNum++; |
| 199 | + } |
| 200 | + |
270 | 201 | $fieldName = ''; |
271 | 202 | $delimiter = ''; |
272 | 203 | $fieldLabel = ''; |
273 | 204 | $isListAttrs = array( 'class' => 'isListCheckbox' ); |
274 | 205 | $delimiterAttrs = array( 'class' => 'delimiterInput' ); |
| 206 | + $text = "\n\t\t\t"; |
275 | 207 | if ( is_null( $field_xml ) ) { |
276 | | - $text = '<div class="fieldBox" id="starterField" style="display: none" >'; |
| 208 | + $text .= '<div class="fieldBox" id="starterField" style="display: none" >'; |
277 | 209 | } else { |
278 | | - $text = '<div class="fieldBox" >'; |
| 210 | + $text .= '<div class="fieldBox" >'; |
279 | 211 | $fieldName = (string)$field_xml->attributes()->name; |
280 | 212 | if ( ((string)$field_xml->attributes()->delimiter) != null || ((string)$field_xml->attributes()->delimiter) != '' ) { |
281 | 213 | $delimiter = (string)$field_xml->attributes()->delimiter; |
— | — | @@ -288,15 +220,15 @@ |
289 | 221 | $isListAttrs['checked'] = 'checked'; |
290 | 222 | } |
291 | 223 | } |
292 | | - $fieldHTML = '<p>Field name: '; |
293 | | - $fieldHTML .= Html::input( 'f_name_' . $field_count, $fieldName, 'text', array( 'size' => 15 ) ) . ' '; |
| 224 | + $fieldHTML = wfMsg( 'ps-namelabel' ) . ' '; |
| 225 | + $fieldHTML .= Html::input( 'f_name_' . $fieldNum, $fieldName, 'text', array( 'size' => 15 ) ) . ' '; |
294 | 226 | $fieldHTML .= wfMsg( 'ps-displaylabel' ) . ' '; |
295 | | - $fieldHTML .= Html::input( 'f_label_' . $field_count, $fieldLabel, 'text', array( 'size' => 15 ) ); |
296 | | - $fieldHTML .= "\t\t</p>\n"; |
297 | | - $fieldIsListInput = Html::input( 'f_is_list_' . $field_count, null, 'checkbox', $isListAttrs ); |
| 227 | + $fieldHTML .= Html::input( 'f_label_' . $fieldNum, $fieldLabel, 'text', array( 'size' => 15 ) ); |
| 228 | + $fieldHTML = Html::rawElement( 'p', null, $fieldHTML ) . "\n"; |
| 229 | + $fieldIsListInput = Html::input( 'f_is_list_' . $fieldNum, null, 'checkbox', $isListAttrs ); |
298 | 230 | $fieldHTML .= Html::rawElement( 'p', null, $fieldIsListInput . ' ' . wfMsg( 'ps-field-list-label' ) ); |
299 | | - $fieldDelimiterInput = Html::input ( 'f_delimiter_' . $field_count, $delimiter, 'text', array( 'size' => 3 ) ); |
300 | | - $fieldHTML .= Html::rawElement( 'p', $delimiterAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
| 231 | + $fieldDelimiterInput = Html::input ( 'f_delimiter_' . $fieldNum, $delimiter, 'text', array( 'size' => 3 ) ); |
| 232 | + $fieldHTML .= "\n" . Html::rawElement( 'p', $delimiterAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
301 | 233 | |
302 | 234 | // Insert HTML text from extensions |
303 | 235 | $htmlFromExtensions = array(); |
— | — | @@ -308,20 +240,17 @@ |
309 | 241 | // their number set via Javascript) and field names from |
310 | 242 | // other extensions (which get their number set via PHP). |
311 | 243 | // Is this important to do? Probably not. |
312 | | - $fieldHTML .= str_replace( 'num', $field_count, $html ); |
| 244 | + $fieldHTML .= str_replace( 'num', $fieldNum, $html ); |
313 | 245 | } |
314 | 246 | |
315 | | - $add_xml_label = wfMsg('ps-add-xml-label'); |
316 | | - $fieldHTML .= <<<END |
317 | | - <p>$add_xml_label |
318 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_$field_count"></textarea> |
319 | | - </p> |
320 | | - |
321 | | -END; |
| 247 | + // TODO - this needs to get set. |
| 248 | + $field_add_xml = null; |
| 249 | + $additionalXMLInput = "\n\t\t\t\t" . Html::textarea( "f_add_xml_$fieldNum", $field_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) ); |
| 250 | + $fieldHTML .= "<p>" . wfMsg('ps-add-xml-label') . $additionalXMLInput . "</p>\n"; |
322 | 251 | $fieldHTML .= Html::input( 'remove-field', wfMsg( 'ps-remove-field' ), 'button', |
323 | 252 | array( 'class' => 'deleteField' ) |
324 | 253 | ); |
325 | | - $text .= self::printFormSection( wfMsg( 'ps-field' ), '#AAA', $fieldHTML, '#CCC' ); |
| 254 | + $text .= "\n" . self::printFormSection( wfMsg( 'ps-field' ), '#AAA', $fieldHTML, 'editSchemaFieldSection' ); |
326 | 255 | $text .= "\t</div><!-- fieldBox -->\n"; |
327 | 256 | return $text; |
328 | 257 | } |
— | — | @@ -336,63 +265,72 @@ |
337 | 266 | $pageSchemaTemplateFields = $pageSchemaTemplate->getFields(); |
338 | 267 | } |
339 | 268 | $attrs = array(); |
| 269 | + $templateXMLElements = array(); |
| 270 | + $text = "\t"; |
340 | 271 | if ( is_null( $template_xml ) ) { |
341 | | - $text = '<div class="templateBox" id="starterTemplate" style="display: none">'; |
| 272 | + $text .= '<div class="templateBox" id="starterTemplate" style="display: none">' . "\n"; |
342 | 273 | $templateName = ''; |
343 | | - $fields_xml_array = array( null ); |
344 | 274 | } else { |
345 | | - $text = '<div class="templateBox" >'; |
| 275 | + $text .= '<div class="templateBox" >' . "\n"; |
346 | 276 | $templateName = (string) $template_xml->attributes()->name; |
347 | 277 | if ( ( (string)$template_xml->attributes()->multiple ) == "multiple" ) { |
348 | 278 | $attrs['checked'] = 'checked'; |
349 | 279 | } |
350 | | - $fields_xml_array = $template_xml->children(); |
| 280 | + $templateXMLElements = $template_xml->children(); |
351 | 281 | } |
352 | | - $templateNameInput = Html::input( 't_name_' . $template_num, $templateName, 'text' ); |
353 | | - $templateHTML = '<p>Name: ' . $templateNameInput . '</p> '; |
| 282 | + $templateNameInput = wfMsg( 'ps-namelabel' ) . ' '; |
| 283 | + $templateNameInput .= Html::input( 't_name_' . $template_num, $templateName, 'text' ); |
| 284 | + $templateHTML = "\t\t" . Html::rawElement( 'p', null, $templateNameInput ) . "\n"; |
354 | 285 | $templateIsMultipleInput = Html::input( 'is_multiple_' . $template_num, null, 'checkbox', $attrs ); |
355 | | - $templateHTML .= Html::rawElement( 'p', null, $templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) ); |
| 286 | + $templateHTML .= "\t\t" . Html::rawElement( 'p', null, $templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) ); |
356 | 287 | $template_add_xml = ""; |
357 | | - foreach ( $fields_xml_array as $field_xml ) { |
358 | | - if ( !empty( $field_xml ) && $field_xml->getName() != 'Field' ) { |
359 | | - $template_add_xml .= (string)$field_xml->asXML(); |
| 288 | + // TODO - set this correctly. |
| 289 | + /* |
| 290 | + foreach ( $templateXMLElements as $templateXMLElement ) { |
| 291 | + if ( !empty( $templateXMLElement ) && $templateXMLElement->getName() != 'Field' ) { |
| 292 | + $template_add_xml .= (string)$templateXMLElement->asXML(); |
360 | 293 | } |
361 | 294 | } |
362 | | - $templateHTML .= '<div id="fieldsList_'.$template_num.'">'; |
363 | | - $field_count = 0; |
364 | | - foreach ( $fields_xml_array as $field_xml ) { |
365 | | - if ( empty( $field_xml ) ) { |
366 | | - $templateHTML .= self::printFieldSection(); |
367 | | - } elseif ( $field_xml->getName() == "Field" ) { |
368 | | - $pageSchemaField = $pageSchemaTemplateFields[$field_count]; |
369 | | - $templateHTML .= self::printFieldSection( $field_xml, $pageSchemaField, $field_count ); |
370 | | - $field_count++; |
| 295 | + */ |
| 296 | + |
| 297 | + $htmlForTemplate = array(); |
| 298 | + wfRunHooks( 'PageSchemasGetTemplateHTML', array( $pageSchemaTemplate, &$htmlForTemplate ) ); |
| 299 | + foreach ( $htmlForTemplate as $valuesFromExtension ) { |
| 300 | + $html = self::printFieldHTMLForExtension( $valuesFromExtension ); |
| 301 | + $templateHTML .= str_replace( 'num', $template_num, $html ); |
| 302 | + } |
| 303 | + |
| 304 | + $templateHTML .= "\n\t\t" . '<div class="fieldsList">'; |
| 305 | + $fieldNumInTemplate = 0; |
| 306 | + // If this is a "starter" template, create the starter |
| 307 | + // field HTML. |
| 308 | + if ( is_null( $pageSchemaTemplate ) ) { |
| 309 | + $templateHTML .= self::printFieldSection(); |
| 310 | + } |
| 311 | + foreach ( $templateXMLElements as $templateXMLElement ) { |
| 312 | + if ( empty( $templateXMLElement ) ) { |
| 313 | + // Do nothing (?) |
| 314 | + } elseif ( $templateXMLElement->getName() == "Field" ) { |
| 315 | + $pageSchemaField = $pageSchemaTemplateFields[$fieldNumInTemplate]; |
| 316 | + $templateHTML .= self::printFieldSection( $templateXMLElement, $pageSchemaField ); |
| 317 | + $fieldNumInTemplate++; |
371 | 318 | } |
372 | 319 | } |
373 | 320 | $templateHTML .= "\t</div><!-- fieldsList -->\n"; |
374 | | - $templateHTML .=<<<END |
375 | | -<script type="text/javascript"> |
376 | | - $(document).ready(function() { |
377 | | - updateFieldNum($field_count); |
378 | | - }); |
379 | | -</script> |
380 | | - |
381 | | -END; |
382 | 321 | $add_field_button = Xml::element( 'input', |
383 | 322 | array( |
384 | 323 | 'type' => 'button', |
| 324 | + 'class' => 'editSchemaAddField', |
385 | 325 | 'value' => wfMsg( 'ps-add-field' ), |
386 | | - 'onclick' => "psAddField($template_num)" |
387 | 326 | ) |
388 | 327 | ); |
389 | 328 | $templateHTML .= Xml::tags( 'p', null, $add_field_button ) . "\n"; |
390 | | - $templateHTML .= '<hr /> |
391 | | - <p>'. wfMsg('ps-add-xml-label') .' |
392 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_'.$template_num.'">'.$template_add_xml.'</textarea> |
393 | | - </p>'; |
| 329 | + $templateHTML .= "<hr />\n"; |
| 330 | + $additionalXMLInput = "\n\t\t\t\t" . Html::textarea( "t_add_xml_$template_num", $template_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) ); |
| 331 | + $templateHTML .= "\n<p>" . wfMsg('ps-add-xml-label') . "\n\t\t\t\t" . $additionalXMLInput . "\n\t\t\t</p>"; |
394 | 332 | $templateHTML .= '<p>' . Html::input( 'remove-template', 'Remove template', 'button', array( 'class' => 'deleteTemplate' ) ) . "</p>\n"; |
395 | | - $text .= self::printFormSection( wfMsg( 'ps-template' ), '#CCC', $templateHTML, '#EEE' ); |
396 | | - $text .= " </div><!-- templateBox-->"; |
| 333 | + $text .= self::printFormSection( wfMsg( 'ps-template' ), '#CCC', $templateHTML, 'editSchemaTemplateSection' ); |
| 334 | + $text .= "\t</div><!-- templateBox-->\n"; |
397 | 335 | return $text; |
398 | 336 | } |
399 | 337 | |
— | — | @@ -416,22 +354,24 @@ |
417 | 355 | } |
418 | 356 | |
419 | 357 | $ps_add_xml = ''; |
| 358 | + // TODO - set this correctly. |
| 359 | + /* |
420 | 360 | foreach ( $pageXMLChildren as $template_xml ) { |
421 | | - if ( ( $template_xml->getName() != 'Template') && ( $template_xml->getName() != 'semanticforms_Form' ) ) { |
| 361 | + if ( $template_xml->getName() != 'Template') { |
422 | 362 | $ps_add_xml .= (string)$template_xml->asXML(); |
423 | 363 | } |
424 | 364 | } |
| 365 | + */ |
425 | 366 | |
426 | | - $text = '<form id="editPageSchemaForm" action="" method="post">' . "\n"; |
427 | | - $text .= '<p>' . wfMsg('ps-add-xml-label') . ' |
428 | | - <textarea rows=4 style="width: 100%" name="ps_add_xml" >' . $ps_add_xml . '</textarea> |
429 | | - </p> '; |
| 367 | + $text = '<form id="editSchemaForm" action="" method="post">' . "\n"; |
| 368 | + $additionalXMLInput = "\n\t\t\t\t" . Html::textarea( 'ps_add_xml', $ps_add_xml, array( 'rows' => 4, 'style' => 'width: 100%;' ) ); |
| 369 | + $text .= '<p>' . wfMsg('ps-add-xml-label') . $additionalXMLInput . "\n</p>"; |
430 | 370 | |
431 | 371 | foreach ( $htmlForSchema as $valuesFromExtension ) { |
432 | 372 | $text .= self::printFieldHTMLForExtension( $valuesFromExtension ); |
433 | 373 | } |
434 | 374 | |
435 | | - $text .= '<div id="templatesList">'; |
| 375 | + $text .= '<div id="templatesList">' . "\n"; |
436 | 376 | |
437 | 377 | $template_num = 0; |
438 | 378 | |
— | — | @@ -448,8 +388,8 @@ |
449 | 389 | $add_template_button = Xml::element( 'input', |
450 | 390 | array( |
451 | 391 | 'type' => 'button', |
| 392 | + 'class' => 'editSchemaAddTemplate', |
452 | 393 | 'value' => wfMsg( 'ps-add-template' ), |
453 | | - 'onclick' => "psAddTemplate()" |
454 | 394 | ) |
455 | 395 | ); |
456 | 396 | $text .= "\t</div><!-- templatesList -->\n"; |
— | — | @@ -482,7 +422,7 @@ |
483 | 423 | |
484 | 424 | $this->setHeaders(); |
485 | 425 | $text = '<p>' . wfMsg( 'ps-page-desc-edit-schema' ) . '</p>'; |
486 | | - self::addJavascript(); |
| 426 | + PageSchemas::addJavascriptAndCSS(); |
487 | 427 | |
488 | 428 | $save_page = $wgRequest->getCheck( 'wpSave' ); |
489 | 429 | if ( $save_page ) { |
Index: trunk/extensions/PageSchemas/PageSchemas.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | 'path' => __FILE__, |
26 | 26 | 'name' => 'Page Schemas', |
27 | 27 | 'author' => array( 'Ankit Garg', 'Yaron Koren' ), |
28 | | - 'version' => '0.1', |
| 28 | + 'version' => '0.2-alpha', |
29 | 29 | 'url' => 'http://www.mediawiki.org/wiki/Extension:PageSchemas', |
30 | 30 | 'descriptionmsg' => 'ps-desc', |
31 | 31 | ); |
— | — | @@ -36,10 +36,9 @@ |
37 | 37 | $wgExtensionMessagesFiles['PageSchemas'] = $dir . 'PageSchemas.i18n.php'; |
38 | 38 | |
39 | 39 | //Job classes |
40 | | -$wgJobClasses['createPage'] = 'PSCreatePageJob'; |
| 40 | +$wgJobClasses['pageSchemasCreatePage'] = 'PSCreatePageJob'; |
41 | 41 | $wgAutoloadClasses['PSCreatePageJob'] = $dir . 'PS_CreatePageJob.php'; |
42 | 42 | |
43 | | - |
44 | 43 | // Register auto load for the special page class |
45 | 44 | $wgAutoloadClasses['PageSchemasHooks'] = $dir . 'PageSchemas.hooks.php'; |
46 | 45 | $wgAutoloadClasses['PageSchemas'] = $dir . 'PageSchemas.classes.php'; |
— | — | @@ -62,3 +61,25 @@ |
63 | 62 | $wgHooks['UnknownAction'][] = 'PSTabs::onUnknownAction'; |
64 | 63 | $wgHooks['SkinTemplateTabs'][] = 'PSTabs::displayTabs'; |
65 | 64 | $wgHooks['SkinTemplateNavigation'][] = 'PSTabs::displayTabs2'; |
| 65 | + |
| 66 | +// Register client-side modules |
| 67 | +$pageSchemasResourceTemplate = array( |
| 68 | + 'localBasePath' => $dir, |
| 69 | + 'remoteExtPath' => 'PageSchemas' |
| 70 | +); |
| 71 | +$wgResourceModules += array( |
| 72 | + 'ext.pageschemas.main' => $pageSchemasResourceTemplate + array( |
| 73 | + 'scripts' => array( |
| 74 | + 'PageSchemas.js', |
| 75 | + ), |
| 76 | + 'styles' => array( |
| 77 | + 'PageSchemas.css', |
| 78 | + ), |
| 79 | + 'dependencies' => array( |
| 80 | + 'jquery', |
| 81 | + ), |
| 82 | + ), |
| 83 | +); |
| 84 | + |
| 85 | +// Page Schemas global variables |
| 86 | +$wgPageSchemasFieldNum = 0; |
Index: trunk/extensions/PageSchemas/PageSchemas.css |
— | — | @@ -1,4 +1,11 @@ |
2 | | -.pageSchema td { |
| 2 | +/** |
| 3 | + * Used to display page schema information directly on the category page. |
| 4 | + */ |
| 5 | +table.pageSchema { |
| 6 | + border: 1px solid #ccc; |
| 7 | +} |
| 8 | + |
| 9 | +table.pageSchema td { |
3 | 10 | padding-right: 5px; |
4 | 11 | } |
5 | 12 | |
— | — | @@ -7,96 +14,92 @@ |
8 | 15 | padding-left: 5px; |
9 | 16 | } |
10 | 17 | |
11 | | -.pageSchema .paramGroup { |
12 | | - background: #bbaa88; |
| 18 | +table.pageSchema .pageSchemaHeader { |
13 | 19 | padding-left: 5px; |
14 | 20 | } |
15 | 21 | |
16 | | -body.rtl .pageSchema .paramGroup { |
| 22 | +body.rtl .pageSchema .pageSchemaHeader { |
17 | 23 | padding-left: auto; |
18 | 24 | padding-right: 5px; |
19 | 25 | } |
20 | 26 | |
21 | | -.pageSchema .paramGroup span.rowValue { |
| 27 | +table.pageSchema .pageSchemaHeader span.rowValue { |
22 | 28 | font-weight: bold; |
23 | 29 | } |
24 | 30 | |
25 | | -.pageSchema .param { |
26 | | - background: #d3c2a0; |
27 | | - padding-left: 20px; |
| 31 | +.pageSchema .schemaExtensionRow { |
| 32 | + padding-left: 5px; |
28 | 33 | } |
29 | 34 | |
30 | | -body.rtl .pageSchema .param { |
| 35 | +body.rtl .pageSchema .schemaExtensionRow { |
31 | 36 | padding-left: auto; |
32 | | - padding-right: 20px; |
| 37 | + padding-right: 5px; |
33 | 38 | } |
34 | 39 | |
35 | | -.pageSchema .param span.rowValue { |
| 40 | +.pageSchema .schemaAttrRow { |
| 41 | + padding-left: 25px; |
| 42 | + background: white; |
36 | 43 | font-weight: bold; |
37 | 44 | } |
38 | 45 | |
39 | | -.pageSchema .paramAttr { |
40 | | - background: #eeddbb; |
41 | | - padding-left: 35px; |
42 | | -} |
43 | | - |
44 | | -body.rtl .pageSchema .paramAttr { |
| 46 | +body.rtl .pageSchema .schemaAttrRow { |
45 | 47 | padding-left: auto; |
46 | | - padding-right: 35px; |
| 48 | + padding-left: 25px; |
47 | 49 | } |
48 | 50 | |
49 | | -.pageSchema .paramAttrMsg { |
50 | | - background: #ffeecc; |
51 | | - padding-left: 50px; |
| 51 | +table.pageSchema .templateRow { |
| 52 | + background: #d3c2a0; |
| 53 | + padding-left: 5px; |
52 | 54 | } |
53 | 55 | |
54 | | -body.rtl .pageSchema .paramAttrMsg { |
| 56 | +body.rtl .pageSchema .templaterow { |
55 | 57 | padding-left: auto; |
56 | | - padding-right: 50px; |
| 58 | + padding-right: 5px; |
57 | 59 | } |
58 | 60 | |
59 | | -.pageSchema .paramOptions { |
60 | | - padding-left: 20px; |
61 | | - background: #ffff77; |
| 61 | +.pageSchema span.rowValue { |
| 62 | + font-weight: bold; |
62 | 63 | } |
63 | 64 | |
64 | | -body.rtl .pageSchema .paramOptions { |
| 65 | +.pageSchema .fieldRow { |
| 66 | + background: #eeddbb; |
| 67 | + padding-left: 25px; |
| 68 | +} |
| 69 | + |
| 70 | +body.rtl .pageSchema .fieldRow { |
65 | 71 | padding-left: auto; |
66 | | - padding-right: 20px; |
| 72 | + padding-right: 25px; |
67 | 73 | } |
68 | 74 | |
69 | | -.pageSchema .paramOption { |
70 | | - padding-left: 35px; |
71 | | - background: #ffff99; |
| 75 | +.pageSchema .fieldExtensionRow { |
| 76 | + padding-left: 26px; |
| 77 | + border-top: 1px solid #ddd; |
72 | 78 | } |
73 | 79 | |
74 | | -body.rtl .pageSchema .paramOption { |
| 80 | +body.rtl .pageSchema .fieldExtensionRow { |
75 | 81 | padding-left: auto; |
76 | | - padding-right: 35px; |
| 82 | + padding-right: 26px; |
77 | 83 | } |
78 | 84 | |
79 | | -.pageSchema .paramOption span.rowValue { |
| 85 | +.pageSchema .fieldAttrRow { |
| 86 | + padding-left: 45px; |
| 87 | + background: white; |
80 | 88 | font-weight: bold; |
81 | 89 | } |
82 | 90 | |
83 | | -.pageSchema .paramOptionMsg { |
84 | | - padding-left: 50px; |
85 | | - background: #ffffbb; |
86 | | -} |
87 | | - |
88 | | -body.rtl .pageSchema .paramOptionMsg { |
| 91 | +body.rtl .pageSchema .fieldAttrRow { |
89 | 92 | padding-left: auto; |
90 | | - padding-right: 50px; |
| 93 | + padding-left: 45px; |
91 | 94 | } |
92 | 95 | |
93 | 96 | .pageSchema .paramData { |
94 | | - padding-left: 20px; |
| 97 | + padding-left: 5px; |
95 | 98 | background: #77dd77; |
96 | 99 | } |
97 | 100 | |
98 | 101 | body.rtl .pageSchema .paramData { |
99 | 102 | padding-left: auto; |
100 | | - padding-right: 20px; |
| 103 | + padding-right: 5px; |
101 | 104 | } |
102 | 105 | |
103 | 106 | .pageSchema .paramData span.rowValue { |
— | — | @@ -122,3 +125,28 @@ |
123 | 126 | padding-left: auto; |
124 | 127 | padding-right: 5px; |
125 | 128 | } |
| 129 | + |
| 130 | +/** |
| 131 | + * Used in Special:EditSchema |
| 132 | + */ |
| 133 | +div.editSchemaSection { |
| 134 | + border: 1px #999 solid; |
| 135 | + background: white; |
| 136 | + padding: 0px; |
| 137 | + margin-bottom: 10px; |
| 138 | + margin-top: 10px; |
| 139 | +} |
| 140 | +div.editSchemaTemplateSection { |
| 141 | + background: #EEE; |
| 142 | +} |
| 143 | +div.editSchemaFieldSection { |
| 144 | + background: #CCC; |
| 145 | +} |
| 146 | +div.editSchemaSection .sectionHeader { |
| 147 | + font-weight: bold; |
| 148 | + padding: 4px 7px; |
| 149 | + border-bottom: 1px #bbb solid; |
| 150 | +} |
| 151 | +div.editSchemaSection .sectionBody { |
| 152 | + padding: 5px 15px; |
| 153 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.hooks.php |
— | — | @@ -10,17 +10,16 @@ |
11 | 11 | |
12 | 12 | // Initialization |
13 | 13 | public static function register( &$parser ) { |
14 | | - global $wgOut, $wgScriptPath; |
15 | | - |
16 | 14 | // Register the hook with the parser |
17 | 15 | $parser->setHook( 'PageSchema', array( 'PageSchemasHooks', 'render' ) ); |
18 | | - // add the CSS |
19 | | - $wgOut->addStyle( $wgScriptPath . '/extensions/PageSchemas/PageSchemas.css' ); |
20 | 16 | return true; |
21 | 17 | } |
22 | 18 | |
23 | 19 | // Render the displayed XML, if any |
24 | 20 | public static function render( $input, $args, $parser, $frame ) { |
| 21 | + // Disable cache so that CSS will get loaded |
| 22 | + $parser->disableCache(); |
| 23 | + |
25 | 24 | // If this call is contained in a transcluded page or template, |
26 | 25 | // or if the input is empty, display nothing. |
27 | 26 | if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) { |
— | — | @@ -38,7 +37,10 @@ |
39 | 38 | if ( $xml_object = PageSchemas::validateXML( $input, $error_msg ) ) { |
40 | 39 | // Store the XML in the page_props table |
41 | 40 | $parser->getOutput()->setProperty( 'PageSchema', $input ); |
42 | | - $text = PageSchemas::parsePageSchemas( $xml_object ); |
| 41 | + // Display the schema on the screen |
| 42 | + global $wgOut, $wgScriptPath; |
| 43 | + $wgOut->addStyle( $wgScriptPath . '/extensions/PageSchemas/PageSchemas.css' ); |
| 44 | + $text = PageSchemas::displaySchema( $xml_object ); |
43 | 45 | } else { |
44 | 46 | // Store error message in the page_props table |
45 | 47 | $parser->getOutput()->setProperty( 'PageSchema', $error_msg ); |
Index: trunk/extensions/PageSchemas/PageSchemas.js |
— | — | @@ -0,0 +1,106 @@ |
| 2 | +/** |
| 3 | + * Javascript for the Page Schemas extension. |
| 4 | + * |
| 5 | + * @author Ankit Garg |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
| 8 | + |
| 9 | + |
| 10 | +var fieldNum = jQuery('.fieldBox:visible').length; |
| 11 | +var templateNum = jQuery('.templateBox:visible').length; |
| 12 | + |
| 13 | +jQuery.fn.editSchemaMakeTemplateDeleter = function() { |
| 14 | + jQuery(this).click( function() { |
| 15 | + // Remove the encompassing div for this instance. |
| 16 | + jQuery(this).closest(".templateBox") |
| 17 | + .fadeOut('fast', function() { jQuery(this).remove(); }); |
| 18 | + }); |
| 19 | +} |
| 20 | + |
| 21 | +jQuery.fn.editSchemaMakeFieldDeleter = function() { |
| 22 | + jQuery(this).click( function() { |
| 23 | + // Remove the encompassing div for this instance. |
| 24 | + jQuery(this).closest(".fieldBox") |
| 25 | + .fadeOut('fast', function() { jQuery(this).remove(); }); |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +jQuery.fn.editSchemaMakeFieldAdder = function() { |
| 30 | + jQuery(this).click( function() { |
| 31 | + newField = jQuery('#starterField').clone().css('display', '').removeAttr('id'); |
| 32 | + newHTML = newField.html().replace(/fnum/g, fieldNum); |
| 33 | + newField.html(newHTML); |
| 34 | + newField.find(".deleteField").editSchemaMakeFieldDeleter(); |
| 35 | + jQuery(this).closest('.templateBox').find('.fieldsList').append(newField); |
| 36 | + // TODO - have this apply only to the added field, instead of all fields. |
| 37 | + jQuery(".deleteField").editSchemaMakeFieldDeleter(); |
| 38 | + jQuery('.sectionCheckbox').click(function() { |
| 39 | + jQuery(this).editSchemaToggleSectionDisplay(); |
| 40 | + }); |
| 41 | + jQuery('.isListCheckbox').click(function() { |
| 42 | + jQuery(this).editSchemaToggleDelimiterInput(); |
| 43 | + }); |
| 44 | + fieldNum++; |
| 45 | + } ); |
| 46 | +} |
| 47 | + |
| 48 | +jQuery.fn.editSchemaMakeTemplateAdder = function() { |
| 49 | + jQuery(this).click( function() { |
| 50 | + newField = jQuery('#starterTemplate').clone().css('display', '').remove('#starterField').removeAttr('id'); |
| 51 | + newHTML = newField.html().replace(/tnum/g, templateNum); |
| 52 | + newField.html(newHTML); |
| 53 | + newField.find(".deleteTemplate").editSchemaMakeTemplateDeleter(); |
| 54 | + jQuery('#templatesList').append(newField); |
| 55 | + // TODO - have this apply only to the added template, instead of all templates. |
| 56 | + jQuery(".editSchemaAddField").editSchemaMakeFieldAdder(); |
| 57 | + jQuery('.sectionCheckbox').click(function() { |
| 58 | + jQuery(this).editSchemaToggleSectionDisplay(); |
| 59 | + }); |
| 60 | + jQuery('.isListCheckbox').click(function() { |
| 61 | + jQuery(this).editSchemaToggleDelimiterInput(); |
| 62 | + }); |
| 63 | + templateNum++; |
| 64 | + } ); |
| 65 | +} |
| 66 | + |
| 67 | +jQuery.fn.editSchemaToggleDelimiterInput = function() { |
| 68 | + if (this.is(":checked")) { |
| 69 | + this.closest('.fieldBox').find('.delimiterInput').css('display', ''); |
| 70 | + } else { |
| 71 | + this.closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +jQuery.fn.editSchemaToggleSectionDisplay = function() { |
| 76 | + if (this.is(":checked")) { |
| 77 | + this.closest('.editSchemaSection').find('.sectionBody').css('display', '').removeClass('hiddenSection'); |
| 78 | + } else { |
| 79 | + this.closest('.editSchemaSection').find('.sectionBody').css('display', 'none').addClass('hiddenSection'); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +jQuery(document).ready(function() { |
| 84 | + // Add and delete buttons |
| 85 | + jQuery(".deleteTemplate").editSchemaMakeTemplateDeleter(); |
| 86 | + jQuery(".editSchemaAddTemplate").editSchemaMakeTemplateAdder(); |
| 87 | + jQuery(".deleteField").editSchemaMakeFieldDeleter(); |
| 88 | + jQuery(".editSchemaAddField").editSchemaMakeFieldAdder(); |
| 89 | + |
| 90 | + // Checkboxes |
| 91 | + jQuery('.isListCheckbox').each(function() { |
| 92 | + jQuery(this).editSchemaToggleDelimiterInput(); |
| 93 | + }); |
| 94 | + jQuery('.isListCheckbox').click(function() { |
| 95 | + jQuery(this).editSchemaToggleDelimiterInput(); |
| 96 | + }); |
| 97 | + jQuery('.sectionCheckbox').each(function() { |
| 98 | + jQuery(this).editSchemaToggleSectionDisplay(); |
| 99 | + }); |
| 100 | + jQuery('.sectionCheckbox').click(function() { |
| 101 | + jQuery(this).editSchemaToggleSectionDisplay(); |
| 102 | + }); |
| 103 | + jQuery('#editSchemaForm').submit( function() { |
| 104 | + jQuery(':hidden').find("input, select, textarea").attr('disabled', 'disabled'); |
| 105 | + return true; |
| 106 | + } ); |
| 107 | +}); |