Created basic structure for parsing <rodelbahntabelle>.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 15 Jan 2014 20:24:39 +0000 (20:24 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 15 Jan 2014 20:24:39 +0000 (20:24 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrreport/trunk@1877 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php
wrreport.i18n.php
wrreport.php

index 6b1fa4cbfeb641a56b2b862618bab2e1601c0dee..5b1eb43ab162db2deaae567302b563182b0fb560 100644 (file)
@@ -875,6 +875,95 @@ class WrReport {
        }
 
 
+       /// \brief Is called when the tag <rodelbahntabelle/> is encountered.
+       ///
+       /// Description: See description of wrreport.php
+       public static function rodelbahntabelleParserHook($input, $args, $parser) {
+               $parser->getOutput()->addModules('ext.wrreport');
+               $dbr = wfGetDB(DB_SLAVE);
+
+               try {
+                       libxml_use_internal_errors(true); // without that, we get PHP Warnings if the $input is not well-formed
+                       $xml = new SimpleXMLElement('<rodelbahntabelle>' . $input . '</rodelbahntabelle>'); // input
+                       $whitespace = (string) $xml; // everything between <rodelbahntabelle> and </rodelbahntabelle> that's not a sub-element
+                       if (strlen($whitespace) > 0 && !ctype_space($whitespace)) // there must not be anythin except sub-elements or whitespace
+                               throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-textbetweenelements', trim($xml))->text());
+
+                       // page_ids of sledrun titles that that are going to be returned
+                       $page_ids = array();
+                       foreach ($xml as $entry) { // entry is <rodelbahn>, <region> or <rodelbahnen>
+                               $tagname = $entry->getName();
+                               $attributes = array();
+                               foreach ($entry->attributes() as $key => $value) $attributes[] = $key;
+
+                               // is the element known?
+                               if (!in_array($tagname, array('rodelbahn', 'region', 'rodelbahnen')))
+                                       throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+
+                               // parse operation attribute
+                               $operation = '+'; // '+' (append) or '-' (subtract)
+                               if (array_key_exists('operation', $attributes)) {
+                                       $operation = $attributes['operation'];
+                                       if (!in_array($operation, array('+', '-')))
+                                               throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-value', $tagname, 'operation', $operation)->text());
+                                       unset($attributes['operation']);
+                               }
+
+                               // parse in_arbeit attribute
+                               $unter_construction = false;
+                               if (array_key_exists('in_arbeit', $attributes)) {
+                                       if (!in_array($attributes['in_arbeit'], array('ja', 'nein', '*')))
+                                               throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-value', $tagname, 'operation', $operation)->text());
+                                       if (in_array($attributes['in_arbeit'] === 'nein')) $under_construction = false;
+                                       elseif (in_array($attributes['*'] === '*')) $under_construction = null;
+                                       unset($attributes['in_arbeit']);
+                               }
+
+                               // any attributes left that are not handled yet?
+                               if (count($attributes) > 0)
+                                       throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-name', $tagname, array_keys($attributes)[0])->text());
+
+                               // <rodelbahn>
+                               if ($tagname == 'rodelbahn') {
+                               }
+
+                               // <region>
+                               elseif ($tagname == 'region') {
+                                       // get titles that are in the region
+                                       // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
+                                       // $res = $dbr->select('wrsledruncache', 'page_id', array('CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))', 'NOT under_construction'), __METHOD__, 'page_title');
+                                       $res = $dbr->select(array('wrsledruncache', 'wrregioncache'), array('page_id' => 'wrregioncache.page_id'), array('wrregioncache.region_id' => $region_id, 'wrregioncache.page_id=wrsledruncache.page_id', 'NOT under_construction'), __METHOD__, 'page_title');
+                                       foreach ($res as $row) {
+                                               $page_titles[] = Title::newFromId($row->page_id);
+                                       }
+                                       $dbr->freeResult($res);
+                               }
+
+                               // <rodelbahnen>
+                               elseif ($tagname == 'rodelbahnen') {
+                               }
+
+                               else throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+
+                       }
+
+                       // page_titles that are going to be returned
+                       $page_titles = array();
+                       foreach ($page_id as $page_ids) {
+                               $page_titles[] = Title::newFromId($page_id);
+                       }
+                       $html = WrReport::createBahnentabelle($page_titles);
+
+               } catch (WrReportException $e) {
+                       $doc = new WrDOMDocument();
+                       $doc->appendElement('span', array('class' => 'error'))->appendText(wfMessage('wrreport-rodelbahntabelle-error', $e->getMessage())->text());
+                       $html = $doc->saveHTML($doc->firstChild);
+               }
+
+               return array($html, 'noparse' => true, 'isHTML' => true);
+       }
+
+
        /// \brief Is called when the tag <avatar>username</avatar> is encountered.
        public static function avatarParserHook($input, $args, $parser, $frame) {
                $doc = new WrDOMDocument();
index 4c2a497e6277640e6b9f57d9206e6862486cc828..08cfdb459574adfe7ffe40ce167415d1a6ef8ccb 100644 (file)
@@ -86,6 +86,10 @@ $messages['qqq'] = array(
        'wrreport-bahnenregiontabelle-noregionname' => 'Text. Error message saying that the specified region name was not found in the database (table wrregion)',
        'wrreport-bahnenregiontabelle-invalidargument' => 'Text. Error message saying that the argument (given by $1) of <bahnenregiontabelle> is invalid',
        'wrreport-bahnenregiontabelle-error' => 'Text. Text describing that an error in paring/using the <bahnenregiontabelle> tag occurred. $1 gives details.',
+       'wrreport-rodelbahntabelle-textbetweenelements' => 'Text. Error message describing that invalid text is found between elements. $1 gives the complete XML.',
+       'wrreport-rodelbahntabelle-invalid-element' => 'Text. Error message describing that the element given as $1 is not known.',
+       'wrreport-rodelbahntabelle-invalid-attribute-name' => 'Text. Error message describing that the attribute given as $2 of the elment given as $1 is not known.',
+       'wrreport-rodelbahntabelle-invalid-attribute-value' => 'Text. Error message describing that the value $3 of the attribut given as $2 of the element given as $1 is not known.',
        'wrreport-icon-sledrental' => 'Text',
        'wrreport-icon-nightlight' => 'Text',
        'wrreport-icon-lift' => 'Text',
@@ -183,6 +187,10 @@ $messages['en'] = array(
        'wrreport-bahnenregiontabelle-noregionname' => 'The specified region name was not found in the region table of the database.',
        'wrreport-bahnenregiontabelle-invalidargument' => 'The argument $1 is not allowed.',
        'wrreport-bahnenregiontabelle-error' => 'The following error occurred at the <bahnenregiontabelle> tag: $1',
+       'wrreport-rodelbahntabelle-textbetweenelements' => 'Unknown text was found between the subelements: $1',
+       'wrreport-rodelbahntabelle-invalid-element' => 'The element $1 is not known.',
+       'wrreport-rodelbahntabelle-invalid-attribute-name' => 'The attribute $2 of element $1 is not known.',
+       'wrreport-rodelbahntabelle-invalid-attribute-value' => 'The value $3 of attribute $2 of element $1 is not known.',
        'wrreport-icon-sledrental' => 'Sled Rental',
        'wrreport-icon-nightlight' => 'Light at Night',
        'wrreport-icon-lift' => 'Help me get up',
index f74738c924789981bae6497e4db85ccaaada5fcd..f114af97a5b799109eb0fea06ca59437da53bbd0 100644 (file)
@@ -118,6 +118,7 @@ function WrReportParserFirstCallInitHook(&$parser) {
        $parser->setHook('bahnberichte', 'WrReport::bahnberichteParserHook');
        $parser->setHook('bahnentabelle', 'WrReport::bahnentabelleParserHook');
        $parser->setHook('bahnenregiontabelle', 'WrReport::bahnenregiontabelleParserHook');
+       $parser->setHook('rodelbahntabelle', 'WrReport::rodelbahntabelleParserHook');
        $parser->setHook('avatar', 'WrReport::avatarParserHook');
        return true;
 }