Index: trunk/extensions/TemplateInfo/TemplateInfo.hooks.php |
— | — | @@ -8,6 +8,8 @@ |
9 | 9 | |
10 | 10 | class TemplateInfoHooks { |
11 | 11 | |
| 12 | + static $tab = " "; |
| 13 | + |
12 | 14 | /* Functions */ |
13 | 15 | |
14 | 16 | // Initialization |
— | — | @@ -24,7 +26,7 @@ |
25 | 27 | <?xml version="1.0" encoding="utf-8"?> |
26 | 28 | <!DOCTYPE template [ |
27 | 29 | <!ELEMENT template (description?,params?,data*)> |
28 | | -<!ELEMENT params (param|group)*> |
| 30 | +<!ELEMENT templateinfo (param|group)*> |
29 | 31 | <!ELEMENT param (label?,description?,options?,type?,data*)> |
30 | 32 | <!ATTLIST param id ID #REQUIRED> |
31 | 33 | <!ELEMENT group (label?,description?,param*,data*)> |
— | — | @@ -52,10 +54,125 @@ |
53 | 55 | $errors = libxml_get_errors(); |
54 | 56 | $message = $errors[0]->message; |
55 | 57 | //$line = $errors[0]->line; |
56 | | - $error_msg = "ERROR: $message"; |
| 58 | + $error_msg = "$message"; |
57 | 59 | return $xml_success; |
58 | 60 | } |
59 | 61 | |
| 62 | + static function parseTemplateInfo($template_info_xml) { |
| 63 | + $text = "<p>Template description:</p>\n"; |
| 64 | + $text .= "<table>\n"; |
| 65 | + foreach ($template_info_xml->children() as $tag => $child) { |
| 66 | + if ($tag == 'group') { |
| 67 | + $text .= self::parseParamGroup($child); |
| 68 | + } elseif ($tag == 'param') { |
| 69 | + $text .= self::parseParam($child); |
| 70 | + } |
| 71 | + } |
| 72 | + $text .= "</table>\n"; |
| 73 | + return $text; |
| 74 | + } |
| 75 | + |
| 76 | + static function parseParamGroup($param_group_xml) { |
| 77 | + $text = "<tr>\n"; |
| 78 | + $text .= "<td colspan=\"2\" style=\"background: #bbaa88\">"; |
| 79 | + $id = $param_group_xml->attributes()->id; |
| 80 | + $text .= " Group: <strong>$id</strong></td>"; |
| 81 | + $text .= "</tr>\n"; |
| 82 | + foreach ($param_group_xml->children() as $child) { |
| 83 | + $text .= self::parseParam($child); |
| 84 | + } |
| 85 | + return $text; |
| 86 | + } |
| 87 | + |
| 88 | + static function parseParam($param_xml) { |
| 89 | + $id = $param_xml->attributes()->id; |
| 90 | + $text = "<tr><td colspan=\"2\" style=\"background: #d3c2a0\">" . self::$tab . "Parameter: <strong>$id</strong></td></tr>\n"; |
| 91 | + foreach ($param_xml->children() as $tag_name => $child) { |
| 92 | + if ($tag_name == 'label') { |
| 93 | + $text .= self::parseParamLabel($child); |
| 94 | + } elseif ($tag_name == 'description') { |
| 95 | + $text .= self::parseParamDescription($child); |
| 96 | + } elseif ($tag_name == 'options') { |
| 97 | + $text .= self::parseParamOptions($child); |
| 98 | + } elseif ($tag_name == 'data') { |
| 99 | + $text .= self::parseParamData($child); |
| 100 | + } |
| 101 | + } |
| 102 | + return $text; |
| 103 | + } |
| 104 | + |
| 105 | + static function parseParamLabel($param_label_xml) { |
| 106 | + if (count($param_label_xml->children()) == 0) { |
| 107 | + $text .= "<tr><td colspan=\"2\" style=\"background: #eeddbb\">" . self::$tab . self::$tab . "Label: $param_label_xml</td></tr>\n"; |
| 108 | + } else { |
| 109 | + $text .= "<tr><td colspan=\"2\" style=\"background: #eeddbb\">" . self::$tab . self::$tab . "Label</td></tr>\n"; |
| 110 | + foreach ($param_label_xml->children() as $child) { |
| 111 | + $text .= self::parseMsg($child); |
| 112 | + } |
| 113 | + } |
| 114 | + return $text; |
| 115 | + } |
| 116 | + |
| 117 | + static function parseParamDescription($param_desc_xml) { |
| 118 | + if (count($param_desc_xml->children()) == 0) { |
| 119 | + $text = "<tr><td colspan=\"2\" style=\"background: #eeddbb\">" . self::$tab . self::$tab . "Description: $param_desc_xml</td></tr>\n"; |
| 120 | + } else { |
| 121 | + $text = "<tr><td colspan=\"2\" style=\"background: #eeddbb\">" . self::$tab . self::$tab . "Description</td></tr>\n"; |
| 122 | + foreach ($param_desc_xml->children() as $child) { |
| 123 | + $text .= self::parseMsg($child); |
| 124 | + } |
| 125 | + } |
| 126 | + return $text; |
| 127 | + } |
| 128 | + |
| 129 | + static function parseParamOptions($param_options_xml) { |
| 130 | + $text = "<tr><td colspan=\"2\" style=\"background: #ffff77\">" . self::$tab . self::$tab . "Options</td></tr>\n"; |
| 131 | + foreach ($param_options_xml->children() as $child) { |
| 132 | + $text .= self::parseParamOption($child); |
| 133 | + } |
| 134 | + return $text; |
| 135 | + } |
| 136 | + |
| 137 | + static function parseParamOption($param_option_xml) { |
| 138 | + $name = $param_option_xml->attributes()->name; |
| 139 | + $text = "<tr><td colspan=\"2\" style=\"background: #ffff99\">" . self::$tab . self::$tab . self::$tab . "Option: <strong>$name</strong></td></tr>\n"; |
| 140 | + if (count($param_option_xml->children()) == 0) { |
| 141 | + $text .= "<tr><td colspan=\"2\" style=\"background: #ffffbb\">" . self::$tab . self::$tab . self::$tab . self::$tab . "$param_option_xml</td></tr>\n"; |
| 142 | + } else { |
| 143 | + foreach ($param_option_xml->children() as $child) { |
| 144 | + $text .= self::parseOptionMsg($child); |
| 145 | + } |
| 146 | + } |
| 147 | + return $text; |
| 148 | + } |
| 149 | + |
| 150 | + static function parseMsg($msg_xml) { |
| 151 | + $language = $msg_xml->attributes()->language; |
| 152 | + $text = "<tr><td style=\"background: #ffeecc\">" . self::$tab . self::$tab . self::$tab . "$language</td><td style=\"background: white\">$msg_xml</td></tr>\n"; |
| 153 | + return $text; |
| 154 | + } |
| 155 | + |
| 156 | + static function parseOptionMsg($msg_xml) { |
| 157 | + $language = $msg_xml->attributes()->language; |
| 158 | + $text = "<tr><td style=\"background: #ffffbb\">" . self::$tab . self::$tab . self::$tab . self::$tab . "$language</td><td style=\"background: white\">$msg_xml</td></tr>\n"; |
| 159 | + return $text; |
| 160 | + } |
| 161 | + |
| 162 | + static function parseParamData($param_data_xml) { |
| 163 | + $app = $param_data_xml->attributes()->app; |
| 164 | + $text = "<tr><td colspan=\"2\" style=\"background: #77dd77\">" . self::$tab . self::$tab . "Data for app: <strong>$app</strong></td></tr>\n"; |
| 165 | + foreach ($param_data_xml->children() as $child) { |
| 166 | + $text .= self::parseField($child); |
| 167 | + } |
| 168 | + return $text; |
| 169 | + } |
| 170 | + |
| 171 | + static function parseField($field_xml) { |
| 172 | + $name = $field_xml->attributes()->name; |
| 173 | + $text = "<tr><td style=\"background: #99ff99\">" . self::$tab . self::$tab . self::$tab . "$name</td><td style=\"background: white\">$field_xml</td></tr>\n"; |
| 174 | + return $text; |
| 175 | + } |
| 176 | + |
60 | 177 | // Render the displayed XML, if any |
61 | 178 | public static function render( $input, $args, $parser, $frame ) { |
62 | 179 | // if this call is contained in a transcluded page or template, |
— | — | @@ -66,14 +183,17 @@ |
67 | 184 | // Store XML in the page_props table |
68 | 185 | // TODO: Do processing here, like parse to an array |
69 | 186 | $error_msg = null; |
70 | | - if ( TemplateInfoHooks::validateXML( $input, $error_msg ) ) |
| 187 | + $input = "<templateinfo>$input</templateinfo>\n"; |
| 188 | + if ( $xml_object = TemplateInfoHooks::validateXML( $input, $error_msg ) ) { |
71 | 189 | $parser->getOutput()->setProperty( 'templateinfo', $input ); |
72 | | - else |
| 190 | + $text = self::parseTemplateInfo($xml_object); |
| 191 | + } else { |
73 | 192 | $parser->getOutput()->setProperty( 'templateinfo', $error_msg ); |
| 193 | + $text = "<p>The (incorrect) XML definition for this template is:</p>\n"; |
| 194 | + $text .= htmlspecialchars( $input, ENT_QUOTES ); |
| 195 | + } |
74 | 196 | |
75 | | - // Return output |
76 | | - $text = "<p>" . wfMsg( 'templateinfo-header' ) . "</p>\n"; |
77 | | - $text .= htmlspecialchars( $input, ENT_QUOTES ); |
| 197 | + // return output |
78 | 198 | return $text; |
79 | 199 | } |
80 | 200 | } |