Index: trunk/extensions/PageSchemas/PageSchemas.classes.php |
— | — | @@ -0,0 +1,201 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Classes for PageSchemas extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class PageSchemas { |
| 11 | + |
| 12 | + /* Functions */ |
| 13 | + |
| 14 | + |
| 15 | + public static function validateXML( $xml, &$error_msg ) { |
| 16 | + |
| 17 | + |
| 18 | + $xmlDTD =<<<END |
| 19 | +<?xml version="1.0" encoding="utf-8"?> |
| 20 | +<!DOCTYPE PageSchema [ |
| 21 | +<!ELEMENT PageSchema (Template*)> |
| 22 | +<!ATTLIST PageSchema name CDATA #REQUIRED> |
| 23 | +<!ELEMENT Template (Field*)> |
| 24 | +<!ATTLIST Template name CDATA #REQUIRED> |
| 25 | +<!ATTLIST Field name CDATA #REQUIRED> |
| 26 | +]> |
| 27 | + |
| 28 | +END; |
| 29 | + // we are using the SimpleXML library to do the XML validation |
| 30 | + // for now - this may change later |
| 31 | + // hide parsing warnings |
| 32 | + libxml_use_internal_errors(true); |
| 33 | + $xml_success = simplexml_load_string($xmlDTD . $xml); |
| 34 | + $errors = libxml_get_errors(); |
| 35 | + $error_msg = $errors[0]->message; |
| 36 | + return $xml_success; |
| 37 | + } |
| 38 | + |
| 39 | + static function tableRowHTML($css_class, $data_type, $value = null) { |
| 40 | + $data_type = htmlspecialchars($data_type); |
| 41 | + if (is_null($value)) { |
| 42 | + $content = $data_type; |
| 43 | + } else { |
| 44 | + $content = "$data_type: " . HTML::element('span', array('class' => 'rowValue'), $value); |
| 45 | + } |
| 46 | + $cell = HTML::rawElement('td', array('colspan' => 2, 'class' => $css_class), $content); |
| 47 | + $text = HTML::rawElement('tr', null, $cell); |
| 48 | + $text .= "\n"; |
| 49 | + return $text; |
| 50 | + } |
| 51 | + |
| 52 | + static function tableMessageRowHTML( $css_class, $name, $value ) { |
| 53 | + $cell1 = HTML::element('td', array('class' => $css_class), $name); |
| 54 | + $cell2 = HTML::element('td', array('class' => 'msg'), $value); |
| 55 | + $text = HTML::rawElement('tr', null, $cell1 . "\n" . $cell2); |
| 56 | + $text .= "\n"; |
| 57 | + return $text; |
| 58 | + } |
| 59 | + |
| 60 | + static function parsePageSchemas($class_schema_xml) { |
| 61 | + |
| 62 | + global $wgTitle; |
| 63 | + |
| 64 | + if($wgTitle->getNamespace() == NS_CATEGORY){ |
| 65 | + $text = "<p>Schema description:</p>\n"; |
| 66 | + $text .= "<table class=\"pageSchema\">\n"; |
| 67 | + $name = $class_schema_xml->attributes()->name; |
| 68 | + $text = self::tableRowHTML('template_class', 'PageSchema', $name); |
| 69 | + foreach ( $class_schema_xml->children() as $tag => $child ) { |
| 70 | + if ($tag == 'Template') { |
| 71 | + $text .= self::parseTemplate($child); |
| 72 | + } else{ |
| 73 | + echo "Code to be added by other extension\n"; |
| 74 | + } |
| 75 | + } |
| 76 | + $text .= "</table>\n"; |
| 77 | + }else{ |
| 78 | + $text = ""; |
| 79 | + } |
| 80 | + return $text; |
| 81 | + } |
| 82 | + |
| 83 | + static function parseTemplate ( $template_xml ) { |
| 84 | + $name = $template_xml->attributes()->name; |
| 85 | + $text = self::tableRowHTML('template_class', 'Template', $name); |
| 86 | + foreach ($template_xml->children() as $child) { |
| 87 | + $text .= self::parseField($child); |
| 88 | + } |
| 89 | + return $text; |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + static function parseField ( $field_xml ) { |
| 95 | + $name = $field_xml->attributes()->name; |
| 96 | + $text = self::tableMessageRowHTML('paramDataField', $name, $field_xml); |
| 97 | + return $text; |
| 98 | + } |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | +/*class holds the PageScheme tag equivalent object */ |
| 103 | + |
| 104 | +class PageSchema { |
| 105 | + |
| 106 | + $categoryName = ""; |
| 107 | + $pageId=0; |
| 108 | + $pageXml=""; |
| 109 | + $pageName=""; |
| 110 | + |
| 111 | + /* Stores the templte objects */ |
| 112 | + $PSTemplates = array(); |
| 113 | + |
| 114 | + function __construct ( $category_name ) { |
| 115 | + |
| 116 | + $pageName = $pageXml->attributes()->name; |
| 117 | + $this->categoryName = $category_name; |
| 118 | + $title = Title::newFromText( $categoryName, NS_CATEGORY ); |
| 119 | + $pageId = $title->getArticleID(); |
| 120 | + /* get the database instance */ |
| 121 | + $dbr = wfGetDB( DB_SLAVE ); |
| 122 | + /*get the result set, query : slect page_props*/ |
| 123 | + $res = $dbr->select( 'page_props', |
| 124 | + array( |
| 125 | + 'pp_page', |
| 126 | + 'pp_propname', |
| 127 | + 'pp_value' |
| 128 | + ), |
| 129 | + array( |
| 130 | + 'pp_page' => $pageId, |
| 131 | + 'pp_propname' => 'PageSchema' |
| 132 | + ) |
| 133 | + ); |
| 134 | + |
| 135 | + /*first row of the result set */ |
| 136 | + $row = $dbr->fetchRow( $res ); |
| 137 | + |
| 138 | + /* retrievimg the third attribute which is pp_value */ |
| 139 | + $pageXml = $row[2]; |
| 140 | + |
| 141 | + /* index for template objects */ |
| 142 | + $i = 0 ; |
| 143 | + foreach ( $pageXml->children() as $tag => $child ) { |
| 144 | + if ( $tag == 'Template' ) { |
| 145 | + $templateObj = new PSTemplate($child); |
| 146 | + $PSTemplates[$i++]= $templateObj; |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | + /*return an array of PSTemplate Objects */ |
| 153 | + static function getTemplates () { |
| 154 | + return PSTemplates; |
| 155 | + } |
| 156 | + |
| 157 | + /*returns the name of the PageSchema object */ |
| 158 | + function getName(){ |
| 159 | + return $pageName; |
| 160 | + } |
| 161 | +} |
| 162 | +class PSTemplate { |
| 163 | + /* Stores the field objects */ |
| 164 | + $PSFields = array(); |
| 165 | + $templateName =""; |
| 166 | + $templateXml =""; |
| 167 | + function __construct( $template_xml ) { |
| 168 | + $templateXml = $template_xml; |
| 169 | + $templateName = $templateXml->attributes()->name; |
| 170 | + /* index for template objects */ |
| 171 | + $i = 0 ; |
| 172 | + foreach ($templateXml->children() as $child) { |
| 173 | + $fieldObj = new PSTemplateField($child); |
| 174 | + $PSFields[$i++]= $fieldObj; |
| 175 | + } |
| 176 | + } |
| 177 | + function getName(){ |
| 178 | + return $templateName; |
| 179 | + } |
| 180 | + static function getFields(){ |
| 181 | + return $PSFields; |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +class PSTemplateField { |
| 186 | + |
| 187 | + $fieldName =""; |
| 188 | + $fieldXml= ""; |
| 189 | + |
| 190 | + function __construct( $field_xml ) { |
| 191 | + $fieldXml = $field_xml; |
| 192 | + $fieldXml = $templateXml->attributes()->name; |
| 193 | + } |
| 194 | + function getName(){ |
| 195 | + return $fieldName; |
| 196 | + } |
| 197 | + public function getObject( $objectName ) { |
| 198 | + $object = null; |
| 199 | + wfRunHooks( 'PageSchemasGetObject', array( $objectName, $this->fieldXml, $object ) ); |
| 200 | + return $object; |
| 201 | + } |
| 202 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.i18n.php |
— | — | @@ -0,0 +1,394 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Messages file for the PageSchemas extension |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * Get all extension messages |
| 13 | + * |
| 14 | + * @return array |
| 15 | + */ |
| 16 | +$messages = array(); |
| 17 | + |
| 18 | +$messages['en'] = array( |
| 19 | + 'pageschemas-desc' => 'Supports templates defining their data structure via XML markup', |
| 20 | + 'pageschemas-header' => 'The XML definition for this template is:', |
| 21 | +); |
| 22 | + |
| 23 | +/** Message documentation (Message documentation) |
| 24 | + * @author The Evil IP address |
| 25 | + * @author Ankit Garg |
| 26 | + */ |
| 27 | +$messages['qqq'] = array( |
| 28 | + 'pageschemas-desc' => '{{desc}}', |
| 29 | + 'pageschemas-header' => 'Header to display XML definition in template page', |
| 30 | +); |
| 31 | + |
| 32 | +/** Afrikaans (Afrikaans) |
| 33 | + * @author Naudefj |
| 34 | + */ |
| 35 | +$messages['af'] = array( |
| 36 | + 'pageschemas-desc' => 'Ondersteun sjablone waarvoor die datastruktuur via XML gedefinieer is', |
| 37 | + 'pageschemas-header' => 'Die XML-definisie vir die sjabloon is:', |
| 38 | +); |
| 39 | + |
| 40 | +/** Arabic (العربية) |
| 41 | + * @author Meno25 |
| 42 | + */ |
| 43 | +$messages['ar'] = array( |
| 44 | + 'pageschemas-desc' => 'يدعم القوالب التي تعرف هيكل بياناتها من خلال علامات XML', |
| 45 | + 'pageschemas-header' => 'تعريف XML لهذا القالب هو:', |
| 46 | +); |
| 47 | + |
| 48 | +/** Egyptian Spoken Arabic (مصرى) |
| 49 | + * @author Dudi |
| 50 | + * @author Ghaly |
| 51 | + */ |
| 52 | +$messages['arz'] = array( |
| 53 | + 'pageschemas-desc' => 'بيدعم القوالب اللى بتعرّف هيكل الداتا بتاعتها عن طريق علامات XML', |
| 54 | + 'pageschemas-header' => 'تعريف XML للقالب ده هو:', |
| 55 | +); |
| 56 | + |
| 57 | +/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
| 58 | + * @author EugeneZelenko |
| 59 | + * @author Jim-by |
| 60 | + */ |
| 61 | +$messages['be-tarask'] = array( |
| 62 | + 'pageschemas-desc' => 'Падтрымлівае шаблёны вызначаючы іх будову зьвестак праз меткі XML', |
| 63 | + 'pageschemas-header' => 'XML-вызначэньне гэтага шаблёну:', |
| 64 | +); |
| 65 | + |
| 66 | +/** Breton (Brezhoneg) |
| 67 | + * @author Fulup |
| 68 | + */ |
| 69 | +$messages['br'] = array( |
| 70 | + 'pageschemas-desc' => 'Skorañ a ra ar patromoù dre dermeniñ o framm roadennoù gant balizennoù XML', |
| 71 | + 'pageschemas-header' => 'Setu an termenadur XML evit ar patrom-mañ :', |
| 72 | +); |
| 73 | + |
| 74 | +/** Bosnian (Bosanski) |
| 75 | + * @author CERminator |
| 76 | + */ |
| 77 | +$messages['bs'] = array( |
| 78 | + 'pageschemas-desc' => 'Podržava šablone koji definiraju svoju strukturu podataka preko XML opisnog jezika', |
| 79 | + 'pageschemas-header' => 'XML definicija za ovaj šablon je:', |
| 80 | +); |
| 81 | + |
| 82 | +/** German (Deutsch) |
| 83 | + * @author Imre |
| 84 | + */ |
| 85 | +$messages['de'] = array( |
| 86 | + 'pageschemas-desc' => 'Unterstützt Vorlagen, die ihre Datenstruktur über XML auszeichnen', |
| 87 | + 'pageschemas-header' => 'Die XML-Definition für diese Vorlage ist:', |
| 88 | +); |
| 89 | + |
| 90 | +/** Lower Sorbian (Dolnoserbski) |
| 91 | + * @author Michawiki |
| 92 | + */ |
| 93 | +$messages['dsb'] = array( |
| 94 | + 'pageschemas-desc' => 'Pódpěra pśedłogi, kótarež definěruju datowu strukturu pśez XML-wobznamjenjenja', |
| 95 | + 'pageschemas-header' => 'XML-definicija za toś tu pśedłogu jo:', |
| 96 | +); |
| 97 | + |
| 98 | +/** Greek (Ελληνικά) |
| 99 | + * @author Περίεργος |
| 100 | + */ |
| 101 | +$messages['el'] = array( |
| 102 | + 'pageschemas-desc' => 'Υποστηρίζει πρότυπα που καθορίζουν τη δομή των δεδομένων τους μέσω της σήμανσης XML', |
| 103 | + 'pageschemas-header' => 'Ο προσδιορισμός XML για αυτό το πρότυπο είναι:', |
| 104 | +); |
| 105 | + |
| 106 | +/** Spanish (Español) |
| 107 | + * @author Translationista |
| 108 | + */ |
| 109 | +$messages['es'] = array( |
| 110 | + 'pageschemas-desc' => 'Admite plantillas que definen su estructura de datos a través de XML', |
| 111 | + 'pageschemas-header' => 'La definición XML para esta plantilla es:', |
| 112 | +); |
| 113 | + |
| 114 | +/** Finnish (Suomi) |
| 115 | + * @author Crt |
| 116 | + */ |
| 117 | +$messages['fi'] = array( |
| 118 | + 'pageschemas-desc' => 'Tukee mallineiden tietorakenteiden määrittelyä XML-merkkauskielen kautta.', |
| 119 | + 'pageschemas-header' => 'XML-määritelmä tälle mallineelle on:', |
| 120 | +); |
| 121 | + |
| 122 | +/** French (Français) |
| 123 | + * @author PieRRoMaN |
| 124 | + */ |
| 125 | +$messages['fr'] = array( |
| 126 | + 'pageschemas-desc' => 'Supporte les modèle en définissant leur structure de données via des balises XML', |
| 127 | + 'pageschemas-header' => 'La définition XML pour ce modèle est :', |
| 128 | +); |
| 129 | + |
| 130 | +/** Franco-Provençal (Arpetan) |
| 131 | + * @author ChrisPtDe |
| 132 | + */ |
| 133 | +$messages['frp'] = array( |
| 134 | + 'pageschemas-desc' => 'Recognêt los modèlos en dèfenéssent lor structura de balyês avouéc des balises XML.', |
| 135 | + 'pageschemas-header' => 'La dèfinicion XML por ceti modèlo est :', |
| 136 | +); |
| 137 | + |
| 138 | +/** Galician (Galego) |
| 139 | + * @author Toliño |
| 140 | + */ |
| 141 | +$messages['gl'] = array( |
| 142 | + 'pageschemas-desc' => 'Soporta modelos que definen a súa estrutura de datos a través do formato XML', |
| 143 | + 'pageschemas-header' => 'A definición XML para este modelo é:', |
| 144 | +); |
| 145 | + |
| 146 | +/** Swiss German (Alemannisch) |
| 147 | + * @author Als-Holder |
| 148 | + */ |
| 149 | +$messages['gsw'] = array( |
| 150 | + 'pageschemas-desc' => 'Unterstitzt Vorlage, wu ihri Datestruktur iber XML-Markup definiere', |
| 151 | + 'pageschemas-header' => 'D XML-Definition fir die Vorlag isch:', |
| 152 | +); |
| 153 | + |
| 154 | +/** Hebrew (עברית) |
| 155 | + * @author YaronSh |
| 156 | + */ |
| 157 | +$messages['he'] = array( |
| 158 | + 'pageschemas-desc' => 'תומכת בתבניות המגדירות את מבנה הנתונים שלהן באמצעות תחביר XML', |
| 159 | + 'pageschemas-header' => 'הגדרת ה־XML עבור תבנית זו היא:', |
| 160 | +); |
| 161 | + |
| 162 | +/** Upper Sorbian (Hornjoserbsce) |
| 163 | + * @author Michawiki |
| 164 | + */ |
| 165 | +$messages['hsb'] = array( |
| 166 | + 'pageschemas-desc' => 'Podpěruje předłohi, kotrež datowu strukturu přez XML-woznamjenjenja definuja', |
| 167 | + 'pageschemas-header' => 'XML-definicija za tutu předłohu je:', |
| 168 | +); |
| 169 | + |
| 170 | +/** Hungarian (Magyar) |
| 171 | + * @author Dani |
| 172 | + */ |
| 173 | +$messages['hu'] = array( |
| 174 | + 'pageschemas-desc' => 'Lehetővé teszi, hogy a sablonok XML-jelölőnyelv segítségével definiálják az adatstruktúrájukat', |
| 175 | + 'pageschemas-header' => 'A sablon XML-definíciója:', |
| 176 | +); |
| 177 | + |
| 178 | +/** Interlingua (Interlingua) |
| 179 | + * @author McDutchie |
| 180 | + */ |
| 181 | +$messages['ia'] = array( |
| 182 | + 'pageschemas-desc' => 'Supporta patronos que defini lor structura de datos per medio del notation XML', |
| 183 | + 'pageschemas-header' => 'Le definition XML pro iste patrono es:', |
| 184 | +); |
| 185 | + |
| 186 | +/** Indonesian (Bahasa Indonesia) |
| 187 | + * @author IvanLanin |
| 188 | + */ |
| 189 | +$messages['id'] = array( |
| 190 | + 'pageschemas-desc' => 'Mendukung templat untuk dapat mendefinisikan struktur data mereka melalui markah XML', |
| 191 | + 'pageschemas-header' => 'Definisi XML untuk templat ini adalah:', |
| 192 | +); |
| 193 | + |
| 194 | +/** Igbo (Igbo) |
| 195 | + * @author Ukabia |
| 196 | + */ |
| 197 | +$messages['ig'] = array( |
| 198 | + 'pageschemas-desc' => 'Në nyé ike maka mkpurụ ihü, në nyé úchè maka ázú omárí ha nke shi édé XML', |
| 199 | + 'pageschemas-header' => 'Úchè XML maka mkpurụ ihü nka bu:', |
| 200 | +); |
| 201 | + |
| 202 | +/** Italian (Italiano) |
| 203 | + * @author Beta16 |
| 204 | + */ |
| 205 | +$messages['it'] = array( |
| 206 | + 'pageschemas-header' => 'La definizione XML per questo template è:', |
| 207 | +); |
| 208 | + |
| 209 | +/** Japanese (日本語) |
| 210 | + * @author Fryed-peach |
| 211 | + */ |
| 212 | +$messages['ja'] = array( |
| 213 | + 'pageschemas-desc' => '自身のデータ構造を XML マークアップで定義するテンプレートをサポートする', |
| 214 | + 'pageschemas-header' => 'このテンプレートの XML 定義は以下のようになっています:', |
| 215 | +); |
| 216 | + |
| 217 | +/** Colognian (Ripoarisch) |
| 218 | + * @author Purodha |
| 219 | + */ |
| 220 | +$messages['ksh'] = array( |
| 221 | + 'pageschemas-desc' => 'Ongerschtöz, dat mer de Dateschtruktur vun Schablone övver en <i lang="en">XML</i> Fommaat beschrieve kann.', |
| 222 | + 'pageschemas-header' => 'Di Schablon met <i lang="en">XML</i> beschrevve:', |
| 223 | +); |
| 224 | + |
| 225 | +/** Luxembourgish (Lëtzebuergesch) |
| 226 | + * @author Robby |
| 227 | + */ |
| 228 | +$messages['lb'] = array( |
| 229 | + 'pageschemas-desc' => "Ënnerstëtzt d'Schablounen déi hir Datestruktur iwwer XML-Tagen definéieren", |
| 230 | + 'pageschemas-header' => "D'XML-Definitioun fir dës Schabloun ass:", |
| 231 | +); |
| 232 | + |
| 233 | +/** Macedonian (Македонски) |
| 234 | + * @author Bjankuloski06 |
| 235 | + */ |
| 236 | +$messages['mk'] = array( |
| 237 | + 'pageschemas-desc' => 'Поддржува шаблони кои ја определуваат нивната податочна структура по пат на XML ознаки', |
| 238 | + 'pageschemas-header' => 'XML-определбата за овој шаблон е:', |
| 239 | +); |
| 240 | + |
| 241 | +/** Dutch (Nederlands) |
| 242 | + * @author Siebrand |
| 243 | + */ |
| 244 | +$messages['nl'] = array( |
| 245 | + 'pageschemas-desc' => 'Ondersteunt sjablonen waarvoor de gegevensstructuur is gedefinieerd via XML', |
| 246 | + 'pageschemas-header' => 'De XML-definitie voor dit sjabloon luidt als volgt:', |
| 247 | +); |
| 248 | + |
| 249 | +/** Norwegian Nynorsk (Norsk (nynorsk)) |
| 250 | + * @author Harald Khan |
| 251 | + */ |
| 252 | +$messages['nn'] = array( |
| 253 | + 'pageschemas-desc' => 'Støttar malar som definerer datastrukturen sin gjennom XML-markering.', |
| 254 | + 'pageschemas-header' => 'XML-definisjonen til denne malen er:', |
| 255 | +); |
| 256 | + |
| 257 | +/** Norwegian (bokmål) (Norsk (bokmål)) |
| 258 | + * @author Nghtwlkr |
| 259 | + */ |
| 260 | +$messages['no'] = array( |
| 261 | + 'pageschemas-desc' => 'Støtter maler som definerer datastrukturen sin gjennom XML-markering', |
| 262 | + 'pageschemas-header' => 'XML-definisjonen for denne malen er:', |
| 263 | +); |
| 264 | + |
| 265 | +/** Occitan (Occitan) |
| 266 | + * @author Cedric31 |
| 267 | + */ |
| 268 | +$messages['oc'] = array( |
| 269 | + 'pageschemas-desc' => 'Supòrta los modèls en definissent lor estructura de donadas via de balisas XML', |
| 270 | + 'pageschemas-header' => 'La definicion XML per aqueste modèl es :', |
| 271 | +); |
| 272 | + |
| 273 | +/** Polish (Polski) |
| 274 | + * @author Sp5uhe |
| 275 | + */ |
| 276 | +$messages['pl'] = array( |
| 277 | + 'pageschemas-desc' => 'Obsługa definiowania struktury szablonów z wykorzystaniem znaczników XML', |
| 278 | + 'pageschemas-header' => 'Definicja XML dla tego szablonu:', |
| 279 | +); |
| 280 | + |
| 281 | +/** Piedmontese (Piemontèis) |
| 282 | + * @author Borichèt |
| 283 | + * @author Dragonòt |
| 284 | + */ |
| 285 | +$messages['pms'] = array( |
| 286 | + 'pageschemas-desc' => "A manten jë stamp ch'a definisso soa strutura dij dat via markup XML", |
| 287 | + 'pageschemas-header' => "La definission XML për sto stamp-sì a l'é:", |
| 288 | +); |
| 289 | + |
| 290 | +/** Portuguese (Português) |
| 291 | + * @author Hamilton Abreu |
| 292 | + */ |
| 293 | +$messages['pt'] = array( |
| 294 | + 'pageschemas-desc' => 'Define a estrutura de dados das predefinições em XML', |
| 295 | + 'pageschemas-header' => 'A definição XML para esta predefinição é:', |
| 296 | +); |
| 297 | + |
| 298 | +/** Brazilian Portuguese (Português do Brasil) |
| 299 | + * @author Daemorris |
| 300 | + */ |
| 301 | +$messages['pt-br'] = array( |
| 302 | + 'pageschemas-desc' => 'Suporta predefinições definindo suas estruturas de dados via marcação XML', |
| 303 | + 'pageschemas-header' => 'A definição XML para esta predefinição é:', |
| 304 | +); |
| 305 | + |
| 306 | +/** Tarandíne (Tarandíne) |
| 307 | + * @author Joetaras |
| 308 | + */ |
| 309 | +$messages['roa-tara'] = array( |
| 310 | + 'pageschemas-desc' => "Le template de supporte definiscene 'a struttura lore ausanne l'XML", |
| 311 | + 'pageschemas-header' => "'A definizione XML pe st'esembie jè:", |
| 312 | +); |
| 313 | + |
| 314 | +/** Russian (Русский) |
| 315 | + * @author Александр Сигачёв |
| 316 | + */ |
| 317 | +$messages['ru'] = array( |
| 318 | + 'pageschemas-desc' => 'Поддерживает шаблоны с определением их структуры данных постредством XML-разметки', |
| 319 | + 'pageschemas-header' => 'XML-определение этого шаблона:', |
| 320 | +); |
| 321 | + |
| 322 | +/** Slovenian (Slovenščina) |
| 323 | + * @author Dbc334 |
| 324 | + */ |
| 325 | +$messages['sl'] = array( |
| 326 | + 'pageschemas-desc' => 'Podpira predloge, ki opredelujejo svojo zgradbo podatkov preko označevanja XML', |
| 327 | + 'pageschemas-header' => 'Opredelitev XML predloge je:', |
| 328 | +); |
| 329 | + |
| 330 | +/** Serbian Cyrillic ekavian (Српски (ћирилица)) |
| 331 | + * @author Rancher |
| 332 | + */ |
| 333 | +$messages['sr-ec'] = array( |
| 334 | + 'pageschemas-desc' => 'Подршка шаблонима који дефинишу структуру података преко XML означавања', |
| 335 | + 'pageschemas-header' => 'XML дефиниција овог шаблона:', |
| 336 | +); |
| 337 | + |
| 338 | +/** Swedish (Svenska) |
| 339 | + * @author Per |
| 340 | + */ |
| 341 | +$messages['sv'] = array( |
| 342 | + 'pageschemas-desc' => 'Stödjer mallar som definierar datastrukturen med XML-markering', |
| 343 | + 'pageschemas-header' => 'XML-definitionen för denna mall är:', |
| 344 | +); |
| 345 | + |
| 346 | +/** Tagalog (Tagalog) |
| 347 | + * @author AnakngAraw |
| 348 | + */ |
| 349 | +$messages['tl'] = array( |
| 350 | + 'pageschemas-desc' => 'Tumatangkilik sa mga suleras na nagbibigay kahulugan sa kanilang kayarian ng dato sa pamamagitan ng pagmarkang XML', |
| 351 | + 'pageschemas-header' => 'Ang kahulugang XML para sa suleras na ito ay:', |
| 352 | +); |
| 353 | + |
| 354 | +/** Turkish (Türkçe) |
| 355 | + * @author Vito Genovese |
| 356 | + */ |
| 357 | +$messages['tr'] = array( |
| 358 | + 'pageschemas-desc' => 'XML işaretlemesi ile veri yapılarını tanımlayan şablonları destekler', |
| 359 | + 'pageschemas-header' => 'Bu şablon için XML tanımı şu şekilde:', |
| 360 | +); |
| 361 | + |
| 362 | +/** Ukrainian (Українська) |
| 363 | + * @author NickK |
| 364 | + * @author Prima klasy4na |
| 365 | + * @author Тест |
| 366 | + */ |
| 367 | +$messages['uk'] = array( |
| 368 | + 'pageschemas-desc' => 'Підтримує визначення структури даних шаблонів за допомогою розмітки XML', |
| 369 | + 'pageschemas-header' => 'XML-визначення для цього шаблону:', |
| 370 | +); |
| 371 | + |
| 372 | +/** Vietnamese (Tiếng Việt) |
| 373 | + * @author Minh Nguyen |
| 374 | + */ |
| 375 | +$messages['vi'] = array( |
| 376 | + 'pageschemas-desc' => 'Cho phép định nghĩa cấu trúc dữ liệu của bản mẫu dùng mã XML', |
| 377 | + 'pageschemas-header' => 'Định nghĩa XML của bản mẫu này là:', |
| 378 | +); |
| 379 | + |
| 380 | +/** Simplified Chinese (中文(简体)) |
| 381 | + * @author Chenxiaoqino |
| 382 | + */ |
| 383 | +$messages['zh-hans'] = array( |
| 384 | + 'pageschemas-desc' => '支持的模版已将其数据结构用XML代码声明。', |
| 385 | + 'pageschemas-header' => '此模版的XML定义是:', |
| 386 | +); |
| 387 | + |
| 388 | +/** Traditional Chinese (中文(繁體)) |
| 389 | + * @author Mark85296341 |
| 390 | + */ |
| 391 | +$messages['zh-hant'] = array( |
| 392 | + 'pageschemas-desc' => '支援的模版已將其資料結構用 XML 代碼聲明。', |
| 393 | + 'pageschemas-header' => '此模版的 XML 定義是:', |
| 394 | +); |
| 395 | + |
Index: trunk/extensions/PageSchemas/ApiQueryPageSchemas.php |
— | — | @@ -0,0 +1,89 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Adds the 'PageSchema' action to the MediaWiki API. |
| 5 | + * |
| 6 | + * @author Ankit Garg |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * Protect against register_globals vulnerabilities. |
| 11 | + * This line must be present before any global variable is referenced. |
| 12 | + */ |
| 13 | +if (!defined('MEDIAWIKI')) die(); |
| 14 | + |
| 15 | +/** |
| 16 | + * @ingroup API |
| 17 | + */ |
| 18 | +class APIQueryPageSchemas extends ApiQueryBase { |
| 19 | + |
| 20 | + public function __construct( $query, $moduleName ) { |
| 21 | + parent :: __construct( $query, $moduleName, 'ti' ); |
| 22 | + } |
| 23 | + |
| 24 | + public function execute() { |
| 25 | + $params = $this->extractRequestParams(); |
| 26 | + $titles = $this->getPageSet()->getGoodTitles(); |
| 27 | + if (count($titles) == 0) |
| 28 | + return; |
| 29 | + |
| 30 | + $this->addTables( 'page_props' ); |
| 31 | + $this->addFields( array( 'pp_page', 'pp_value' ) ); |
| 32 | + $this->addWhere( array( |
| 33 | + 'pp_page' => array_keys( $titles ), |
| 34 | + 'pp_propname' => 'PageSchema' |
| 35 | + ) ); |
| 36 | + if ( !is_null( $params['continue'] ) ) |
| 37 | + { |
| 38 | + $fromid = intval( $params['continue'] ); |
| 39 | + $this->addWhere( "pp_page >= $fromid" ); |
| 40 | + } |
| 41 | + $this->addOption( 'ORDER BY', 'pp_page' ); |
| 42 | + |
| 43 | + $res = $this->select(__METHOD__); |
| 44 | + while ( $row = $this->getDB()->fetchObject( $res ) ) { |
| 45 | + $vals = array( ); |
| 46 | + $template_info = $row->pp_value; |
| 47 | + // determine whether this is actual XML or an error |
| 48 | + // message by checking whether the first character |
| 49 | + // is '<' - this is an interim solution until there's |
| 50 | + // a better storage format in place |
| 51 | + if (substr($template_info, 0, 1) == '<') |
| 52 | + ApiResult::setContent( $vals, $row->pp_value ); |
| 53 | + else |
| 54 | + // add error message as an "error=" attribute |
| 55 | + $vals['error'] = $row->pp_value; |
| 56 | + $fit = $this->addPageSubItems( $row->pp_page, $vals ); |
| 57 | + if( !$fit ) { |
| 58 | + $this->setContinueEnumParameter( 'continue', $row->pp_page ); |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + public function getAllowedParams() { |
| 65 | + return array ( |
| 66 | + 'continue' => null, |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + public function getParamDescription() { |
| 71 | + return array ( |
| 72 | + 'continue' => 'When more results are available, use this to continue', |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public function getDescription() { |
| 77 | + return 'Template information, defined by the Template Info extension (http://www.mediawiki.org/Extension:Template_Info)'; |
| 78 | + } |
| 79 | + |
| 80 | + protected function getExamples() { |
| 81 | + return array ( |
| 82 | + 'api.php?action=query&prop=PageSchema&titles=Template:Foo|Template:Bar', |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + public function getVersion() { |
| 87 | + return __CLASS__ . ': $Id$'; |
| 88 | + } |
| 89 | + |
| 90 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * PageSchemas extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * This file contains the main include file for the PageSchemas extension of |
| 10 | + * MediaWiki. |
| 11 | + * |
| 12 | + * Usage: Add the following line in LocalSettings.php: |
| 13 | + * require_once( "$IP/extensions/PageSchemas/PageSchemas.php" ); |
| 14 | + * |
| 15 | + * @version 0.0.1 |
| 16 | + */ |
| 17 | + |
| 18 | +// Check environment |
| 19 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 20 | + echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); |
| 21 | + die( -1 ); |
| 22 | +} |
| 23 | + |
| 24 | +/* Configuration */ |
| 25 | + |
| 26 | +// Credits |
| 27 | +$wgExtensionCredits['parserhook'][] = array( |
| 28 | + 'path' => __FILE__, |
| 29 | + 'name' => 'Page Schemas', |
| 30 | + 'author' => array( 'Ankit Garg' ), |
| 31 | + 'version' => '0.0.1', |
| 32 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:PageSchemas', |
| 33 | + 'descriptionmsg' => 'PageSchema-desc', |
| 34 | +); |
| 35 | + |
| 36 | +// Shortcut to this extension directory |
| 37 | +$dir = dirname( __FILE__ ) . '/'; |
| 38 | + |
| 39 | +// Internationalization |
| 40 | +$wgExtensionMessagesFiles['PageSchemas'] = $dir . 'PageSchemas.i18n.php'; |
| 41 | + |
| 42 | +// Register auto load for the special page class |
| 43 | +$wgAutoloadClasses['PageSchemasHooks'] = $dir . 'PageSchemas.hooks.php'; |
| 44 | +$wgAutoloadClasses['PageSchemas'] = $dir . 'PageSchemas.classes.php'; |
| 45 | +$wgAutoloadClasses['ApiQueryPageSchemas'] = $dir . 'ApiQueryPageSchemas.php'; |
| 46 | + |
| 47 | +// Register parser hook |
| 48 | +$wgHooks['ParserFirstCallInit'][] = 'PageSchemasHooks::register'; |
| 49 | + |
| 50 | +// Register API action |
| 51 | +$wgAPIPropModules['PageSchema'] = 'ApiQueryPageSchemas'; |
| 52 | + |
| 53 | +// Register page_props usage |
| 54 | +$wgPageProps['PageSchema'] = 'Content of <PageSchema> tag'; |
Index: trunk/extensions/PageSchemas/PageSchemas.css |
— | — | @@ -0,0 +1,124 @@ |
| 2 | +.pageSchema td { |
| 3 | + padding-right: 5px; |
| 4 | +} |
| 5 | + |
| 6 | +body.rtl .pageSchema td { |
| 7 | + padding-right: auto; |
| 8 | + padding-left: 5px; |
| 9 | +} |
| 10 | + |
| 11 | +.pageSchema .template_class { |
| 12 | + background: #bbaa88; |
| 13 | + padding-left: 5px; |
| 14 | +} |
| 15 | + |
| 16 | +body.rtl .pageSchema .template_class { |
| 17 | + padding-left: auto; |
| 18 | + padding-right: 5px; |
| 19 | +} |
| 20 | + |
| 21 | +.pageSchema .template_class span.rowValue { |
| 22 | + font-weight: bold; |
| 23 | +} |
| 24 | + |
| 25 | +.pageSchema .param { |
| 26 | + background: #d3c2a0; |
| 27 | + padding-left: 20px; |
| 28 | +} |
| 29 | + |
| 30 | +body.rtl .pageSchema .param { |
| 31 | + padding-left: auto; |
| 32 | + padding-right: 20px; |
| 33 | +} |
| 34 | + |
| 35 | +.pageSchema .param span.rowValue { |
| 36 | + font-weight: bold; |
| 37 | +} |
| 38 | + |
| 39 | +.pageSchema .paramAttr { |
| 40 | + background: #eeddbb; |
| 41 | + padding-left: 35px; |
| 42 | +} |
| 43 | + |
| 44 | +body.rtl .pageSchema .paramAttr { |
| 45 | + padding-left: auto; |
| 46 | + padding-right: 35px; |
| 47 | +} |
| 48 | + |
| 49 | +.pageSchema .paramAttrMsg { |
| 50 | + background: #ffeecc; |
| 51 | + padding-left: 50px; |
| 52 | +} |
| 53 | + |
| 54 | +body.rtl .pageSchema .paramAttrMsg { |
| 55 | + padding-left: auto; |
| 56 | + padding-right: 50px; |
| 57 | +} |
| 58 | + |
| 59 | +.pageSchema .paramOptions { |
| 60 | + padding-left: 20px; |
| 61 | + background: #ffff77; |
| 62 | +} |
| 63 | + |
| 64 | +body.rtl .pageSchema .paramOptions { |
| 65 | + padding-left: auto; |
| 66 | + padding-right: 20px; |
| 67 | +} |
| 68 | + |
| 69 | +.pageSchema .paramOption { |
| 70 | + padding-left: 35px; |
| 71 | + background: #ffff99; |
| 72 | +} |
| 73 | + |
| 74 | +body.rtl .pageSchema .paramOption { |
| 75 | + padding-left: auto; |
| 76 | + padding-right: 35px; |
| 77 | +} |
| 78 | + |
| 79 | +.pageSchema .paramOption span.rowValue { |
| 80 | + font-weight: bold; |
| 81 | +} |
| 82 | + |
| 83 | +.pageSchema .paramOptionMsg { |
| 84 | + padding-left: 50px; |
| 85 | + background: #ffffbb; |
| 86 | +} |
| 87 | + |
| 88 | +body.rtl .pageSchema .paramOptionMsg { |
| 89 | + padding-left: auto; |
| 90 | + padding-right: 50px; |
| 91 | +} |
| 92 | + |
| 93 | +.pageSchema .paramData { |
| 94 | + padding-left: 20px; |
| 95 | + background: #77dd77; |
| 96 | +} |
| 97 | + |
| 98 | +body.rtl .pageSchema .paramData { |
| 99 | + padding-left: auto; |
| 100 | + padding-right: 20px; |
| 101 | +} |
| 102 | + |
| 103 | +.pageSchema .paramData span.rowValue { |
| 104 | + font-weight: bold; |
| 105 | +} |
| 106 | + |
| 107 | +.pageSchema .paramDataField { |
| 108 | + background: #99ff99; |
| 109 | + padding-left: 35px; |
| 110 | +} |
| 111 | + |
| 112 | +body.rtl .pageSchema .paramDataField { |
| 113 | + padding-left: auto; |
| 114 | + padding-right: 35px; |
| 115 | +} |
| 116 | + |
| 117 | +.pageSchema .msg { |
| 118 | + padding-left: 5px; |
| 119 | + background: white; |
| 120 | +} |
| 121 | + |
| 122 | +body.rtl .pageSchema .msg { |
| 123 | + padding-left: auto; |
| 124 | + padding-right: 5px; |
| 125 | +} |
Index: trunk/extensions/PageSchemas/PageSchemas.hooks.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for PageSchemas extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class PageSchemasHooks { |
| 11 | + |
| 12 | + /* Functions */ |
| 13 | + |
| 14 | + // Initialization |
| 15 | + public static function register( &$parser ) { |
| 16 | + // Register the hook with the parser |
| 17 | + $parser->setHook( 'PageSchema', array( 'PageSchemasHooks', 'render' ) ); |
| 18 | + // add the CSS |
| 19 | + global $wgOut, $wgScriptPath; |
| 20 | + $wgOut->addStyle($wgScriptPath . '/extensions/PageSchemas/PageSchemas.css'); |
| 21 | + |
| 22 | + // Continue |
| 23 | + return true; |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | + // Render the displayed XML, if any |
| 28 | + public static function render( $input, $args, $parser, $frame ) { |
| 29 | + // if this call is contained in a transcluded page or template, |
| 30 | + // or if the input is empty, display nothing |
| 31 | + if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) |
| 32 | + return; |
| 33 | + |
| 34 | + |
| 35 | + // TODO: Do processing here, like parse to an array |
| 36 | + $error_msg = null; |
| 37 | + |
| 38 | + // recreate the top-level <PageSchema> tag, with whatever |
| 39 | + // attributes it contained, because that was actually a tag- |
| 40 | + // function call, as opposed to a real XML tag |
| 41 | + $input = Xml::tags('PageSchema', $args, $input); |
| 42 | + |
| 43 | + // if 'type=' was specified, and it wasn't set to one of the |
| 44 | + // allowed values (currently just 'auto'), don't validate - |
| 45 | + // just display the XML |
| 46 | + if (array_key_exists('type', $args) && $args['type'] != 'auto') { |
| 47 | + // Store XML in the page_props table - the Javascript |
| 48 | + // can figure out on its own whether or not to handle it |
| 49 | + $parser->getOutput()->setProperty( 'PageSchema', $input ); |
| 50 | + // TODO - a hook should be called here, to allow other |
| 51 | + // XML handlers to parse and display this |
| 52 | + $text = Html::element('p', null, "The (unhandled) XML definition for this Schema is:") . "\n"; |
| 53 | + $text .= Html::element('pre', null, $input); |
| 54 | + return $text; |
| 55 | + } |
| 56 | + |
| 57 | + if ( $xml_object = PageSchemas::validateXML( $input, $error_msg ) ) { |
| 58 | + // Store XML in the page_props table |
| 59 | + $parser->getOutput()->setProperty( 'PageSchema', $input ); |
| 60 | + $text = PageSchemas::parsePageSchemas($xml_object); |
| 61 | + } else { |
| 62 | + // Store error message in the page_props table |
| 63 | + $parser->getOutput()->setProperty( 'PageSchema', $error_msg ); |
| 64 | + $text = Html::element('p', null, "The (incorrect) XML definition for this template is:") . "\n"; |
| 65 | + $text .= Html::element('pre', null, $input); |
| 66 | + } |
| 67 | + |
| 68 | + // return output |
| 69 | + return $text; |
| 70 | + } |
| 71 | +} |