Style delete button.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 403f29a2aa78158dae0a482a4c2a7eef488fdf1f..4e60a3b5ff2821404d66121c8e5e8cdc43a195bf 100644 (file)
@@ -1,6 +1,74 @@
 <?php
 // File encoding: utf-8
-// Classes for the wrreport extension.
+// This extension does not depend on other extensions.
+//
+// Variables that can be changed in LocalSettings.php:
+//     $wgWrReportMode = 'allow'; // 'summer', 'allow', 'loggedin', 'deny'
+//     $wgWrReportBlackListAll = array(); // array of page names where reports disallowed for all users. Example: array('Birgitzer Alm (vom Adelshof)');
+//     $wgWrReportBlackListStrangers = array(); // array of page names where reports are disallowed for not logged in users
+//     $wgWrReportDeleteMode = 'loggedin'; // 'allow', 'loggedin', 'deny'
+//     $wgWrReportFeedRoot = 'http://www.winterrodeln.org/feed'; // root URL of the Winterrodeln feed without trailing slash
+//
+//
+// The following tags are supported:
+// <bahnentabelle/>
+//     Creates an overview table of all sledruns specified (one per line) in the tag.
+//
+// <bahnenregiontabelle/>
+//     Like <bahnentabelle> but includes all sledruns that are in the region of the current page
+//     or in the region specified by one of the following parameters:
+//         <bahnenregiontabelle wiki="Innsbruck" /> (refers to region represented by the MediaWiki Title name)
+//         <bahnenregiontabelle region_id="3" /> (refers to id in the wrregion table)
+//         <bahnenregiontabelle region_name="Innsbruck" /> (refers to name in the wrregion table)
+//     This tag does not accept any contents.
+//
+// <bahnberichte/>
+//     Shows an overview of the sledrun reports of the current page.
+//
+// <bahnberichtformular/>
+//     Creates the form that is used to enter sledrun reports.
+//
+// <rodelbahntabelle/>
+//     Generates a list of sledrun entries in a flexible way.
+//     Each line (entry) either add sledruns or removes sledruns.
+//     Without entries, the table contains no sledruns.
+//
+//     Examples:
+//     Empty list:
+//         <rodelbahntabelle/>
+//
+//     Sledrun "Rumer Alm" and sledrun "Juifenalm"
+//         <rodelbahntabelle>
+//             <rodelbahn>Juifenalm</rodelbahn>
+//             <rodelbahn>Rumer Alm</rodelbahn>
+//         </rodelbahntabelle>
+//
+//     All sledruns in region Innsbruck thats entries are not "under construction".
+//     The name of the region has to correspond to a name (column name)
+//     in the table wrregion.
+//         <rodelbahntabelle>
+//             <region>Innsbruck</region>
+//         </rodelbahntabelle>
+//
+//     Same as above but excluding the sledrun "Rumer Alm":
+//         <rodelbahntabelle>
+//             <region>Innsbruck</region>
+//             <rodelbahn operation="-">Rumer Alm</rodelbahn>
+//         </rodelbahntabelle>
+//
+//     All sledruns thats entries are "under construction"
+//         <rodelbahntabelle>
+//             <rodelbahnen in_arbeit="ja"/>
+//         </rodelbahntabelle>
+//
+//     Attributes:
+//         * in_arbeit: values "ja", "nein" (default for <region> and <rodelbahnen>), "*" (default for <rodelbahn>)
+//             Just include the sledrun(s) if the condition is fulfilled.
+//         * operation: values "+" (add the sledrun(s) to the set, default), "-" (subtract the sledrun(s) from the set)
+//     Attributes that may be implemented later
+//         * beleuchtungstage: values "0", "unknown" (is null), ">0" (excludes null), "7", "*" (includes null)
+//             Just include the sledrun(s) if the condition is fulfilled.
+//
 
 
 // Constants
@@ -81,6 +149,7 @@ class WrServicesLibravatar extends Services_Libravatar {
        function __construct() {
                $this->setSize(32);
                $this->setDefault('monsterid');
+               $this->setHttps(true);
        }
 
 
@@ -246,7 +315,7 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-condition')->text());
        $td = $tr->appendElement('td');
-       $select = $td->appendElement('select', array('name' => 'condition'));
+       $select = $td->appendElement('select', array('name' => 'condition', 'required' => 'required'));
        $option = $select->appendElement('option', array('value' => '0'));
        $option->appendText(wfMessage('wrreport-condition-select')->text());
        foreach (WrReport::$wrConditions as $condition_num => $condition_text) {
@@ -261,7 +330,7 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        // description
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-description')->text());
-       $tr->appendElement('td')->appendElement('textarea', array('name' => 'description', 'class' => 'fullwidth', 'rows' => '7'))->appendText($description);
+       $tr->appendElement('td')->appendElement('textarea', array('name' => 'description', 'class' => 'fullwidth', 'rows' => '7', 'required' => 'required'))->appendText($description);
 
        // author
        $tr = $table->appendElement('tr');
@@ -278,13 +347,11 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-newreport-submit')->text());
        $td = $tr->appendElement('td');
-       $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit'));
-       if ($hide_save_button)
-               $input->setAttribute('value', wfMessage('wrreport-newreport-preview')->text() . ' & ' . wfMessage('wrreport-newreport-save')->text());
-       else {
-               $input->setAttribute('value', wfMessage('wrreport-newreport-preview')->text());
-
-               $td->appendElement('input', array('name' => 'store', 'type' => 'submit', 'value' => wfMessage('wrreport-newreport-save')->text()));
+       if ($hide_save_button) {
+               $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-progressive', 'value' => wfMessage('wrreport-newreport-next')->text()));
+       } else {
+               $input = $td->appendElement('input', array('name' => 'preview', 'type' => 'submit', 'class' => 'mw-ui-button', 'value' => wfMessage('wrreport-newreport-preview')->text()));
+               $td->appendElement('input', array('name' => 'store', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-constructive', 'value' => wfMessage('wrreport-newreport-save')->text()));
        }
 
        return $doc->saveHTML($form);
@@ -328,8 +395,8 @@ function wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason
        $tr = $table->appendElement('tr');
        $tr->appendElement('th')->appendText(wfMessage('wrreport-reports-action')->text());
        $td = $tr->appendElement('td');
-       $td->appendElement('input', array('name' => 'deletepreview', 'type' => 'submit', 'value' => wfMessage('wrreport-newreport-preview')->text()));
-       $td->appendElement('input', array('name' => 'delete', 'type' => 'submit', 'value' => wfMessage('wrreport-deletereport-delete')->text()));
+       $td->appendElement('input', array('name' => 'deletepreview', 'type' => 'submit', 'class' => 'mw-ui-button', 'value' => wfMessage('wrreport-newreport-preview')->text()));
+       $td->appendElement('input', array('name' => 'delete', 'type' => 'submit', 'class' => 'mw-ui-button mw-ui-destructive', 'value' => wfMessage('wrreport-deletereport-delete')->text()));
 
        // hidden field
        $input = $td->appendElement('input', array('name' => 'reportid', 'type' => 'hidden', 'value' => (string) $reportid));
@@ -568,12 +635,22 @@ class WrReport {
        // Parser Hook Functions
        // ---------------------
 
+       public static function ParserFirstCallInitHook(Parser &$parser) {
+               $parser->setHook('bahnberichtformular', 'WrReport::bahnberichtformularParserHook');
+               $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;
+       }
+
        /// \brief Is called when the tag <bahnberichtformular/> is encountered.
        ///
        /// The current page name is taken.
-       public static function bahnberichtformularParserHook($input, $args, $parser) {
+       public static function bahnberichtformularParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                // Username
-               global $wgUser;
+               $wgUser = $parser->getUser();
                $author_name = NULL;
                if ($wgUser->isLoggedIn()) {
                        $author_name = $wgUser->getRealName();
@@ -611,16 +688,20 @@ class WrReport {
        /// \brief Is called when the tag <bahnberichte/> is encountered.
        ///
        /// The current page name is taken.
-       public static function bahnberichteParserHook($input, $args, $parser) {
+       public static function bahnberichteParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport'); // getOutput() returns class ParserOutput
                $title = $parser->getTitle();
+               $page_id = $title->getArticleID();
 
-               global $wgOut; // class OutputPage
-               global $wgWrReportFeedRoot;
-               $wgOut->addFeedLink('atom', $wgWrReportFeedRoot . '/berichte/bahn/' . strtolower($title->getPartialURL()));
+               $rows = array();
+               if ($page_id > 0) {
+                       global $wgOut; // class OutputPage
+                       global $wgWrReportFeedRoot;
+                       $wgOut->addFeedLink('atom', $wgWrReportFeedRoot . '/berichte/bahn/' . strtolower($title->getPartialURL()));
 
-               $conditions = array('page_title' => $title->getText(), 'date_invalid > now()');
-               $rows = wrReportGetReports($conditions);
+                       $conditions = array('page_id' => $page_id, 'date_invalid > now()');
+                       $rows = wrReportGetReports($conditions);
+               }
                if (count($rows) == 0) return wfMessage('wrreport-reports-none')->text();
                return array(wrReportTableRender($rows, WRREPORT_COMPACT, wrReportUserMayDelete(), $parser), 'markerType' => 'nowiki');
        }
@@ -803,7 +884,7 @@ class WrReport {
        /// Kemater Alm
        /// Axamer Lizum
        /// </bahnentabelle>
-       public static function bahnentabelleParserHook($input, $args, $parser) {
+       public static function bahnentabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                // Add feed
@@ -833,7 +914,7 @@ class WrReport {
        /// <bahnenregiontabelle wiki="Innsbruck" /> (refers to region represented by the MediaWiki Title name)
        /// <bahnenregiontabelle region_id="3" /> (refers to id in the wrregion table)
        /// <bahnenregiontabelle region_name="Innsbruck" /> (refers to name in the wrregion table)
-       public static function bahnenregiontabelleParserHook($input, $args, $parser) {
+       public static function bahnenregiontabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                try {
@@ -885,7 +966,7 @@ class WrReport {
        /// \brief Is called when the tag <rodelbahntabelle/> is encountered.
        ///
        /// Description: See description of wrreport.php
-       public static function rodelbahntabelleParserHook($input, $args, $parser) {
+       public static function rodelbahntabelleParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $parser->getOutput()->addModules('ext.wrreport');
 
                // Add feed
@@ -996,7 +1077,7 @@ class WrReport {
 
 
        /// \brief Is called when the tag <avatar>username</avatar> is encountered.
-       public static function avatarParserHook($input, $args, $parser, $frame) {
+       public static function avatarParserHook($input, array $args, Parser $parser, PPFrame $frame) {
                $doc = new WrDOMDocument();
                $sla = new WrServicesLibravatar();
 
@@ -1028,6 +1109,32 @@ class WrReport {
        }
 
 
+       public static function MobileMenuHook($name, \MobileFrontend\MenuBuilder &$menu) {
+               if ($name === 'discovery') {
+                       // delete "Random page". As a removeEntry function is missing,
+                       // a new menu is built here without the random page.
+                       $new_menu = new MobileFrontend\MenuBuilder();
+                       foreach ($menu->getEntries() as $menuEntryRepresentation) {
+                               $new_entry_name = $menuEntryRepresentation['name'];
+                               if ($new_entry_name == 'random') continue;
+                               $new_entry_components = $menuEntryRepresentation['components'];
+                               $new_entry_isjsonly = isset($menuEntryRepresentation['class']) and $menuEntryRepresentation['class'] === 'jsonly';
+                               $new_entry = $new_menu->insert($new_entry_name, $new_entry_isjsonly);
+                               foreach ($new_entry_components as $new_entry_component) {
+                                       $label = $new_entry_component['text'];
+                                       $url = $new_entry_component['href'];
+                                       $className = $new_entry_component['class'];
+                                       $new_entry->addComponent($label, $url, $className, $new_entry_components);
+                               }
+                       }
+                       $menu = $new_menu;
+
+                       // add region menu entry
+                       $icon = MobileUI::iconClass('random', 'before');
+                       $title = Title::newFromText('Region', NS_CATEGORY);
+                       $menu->insert('region')->addComponent('Regionen', $title->getLocalURL(), $icon, array('id' => 'regionButton', 'data-event-name' => 'region'));
+               }
+       }
 
 }
 WrReport::initWrConditions();
@@ -1044,6 +1151,15 @@ class SpecialWrReport extends SpecialPage {
        }
 
 
+       static function LanguageGetSpecialPageAliasesHook(&$specialPageArray, $languageCode) {
+               $text = wfMessage('wrreport')->text(); // 'Bahnberichte'
+               $title = Title::newFromText($text); // 'Bahnberichte'
+               $specialPageArray['wrreport'][] = $title->getDBKey(); // 'Bahnberichte'
+               return true;
+       }
+
+
+
        /// \param $par Possibilities:
        /// - action == 'view' (default)
        /// - action == 'preview': Preview new report
@@ -1058,6 +1174,7 @@ class SpecialWrReport extends SpecialPage {
                $output = $this->getOutput();
        
                global $wgParser;
+               $output->addWikiText(''); // this is necessary because otherwise $wgParser is not properly initialized
 
                $output->addModules('ext.wrreport');
                $this->setHeaders();
@@ -1087,7 +1204,6 @@ class SpecialWrReport extends SpecialPage {
                        $rows = wrReportGetReports($conditions);
                        if (count($rows) == 0) $output->addHTML(wfMessage('wrreport-reports-none')->text());
                        else {
-                               $output->addWikiText(''); // this is necessary because otherwise $wgParser is not properly initialized but $wgParser is needed in the next line
                                $output->addHTML(wrReportTableRender($rows, WRREPORT_DETAIL, wrReportUserMayDelete(), $wgParser));
                        }
                }
@@ -1157,18 +1273,18 @@ class SpecialWrReport extends SpecialPage {
                                $output->addWikiText(wfMessage('wrreport-deletereport-success', '[[' . $row['page_title'] . '#' . wfMessage('wrreport-reports-sectionname')->text() . '|' . $row['page_title'] . ']]')->text());
                        }
                        if ($action == 'deletepreview') {
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-before')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-before');
                                $format = WRREPORT_COMPACT_PAGE;
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-after')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-after');
                                $row['delete_date'] = date('c');
                                $row['delete_reason_public'] = $delete_reason_public;
                                $row['delete_person_name'] = $delete_person_name;
                                $row['delete_invisible'] = $delete_invisible;
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-form')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-form');
                                $output->addHTML(wrDeleteReportFormRender($reportid, $delete_person_name, $delete_reason_public, $delete_invisible));
-                               $output->addWikiText(wfMessage('wrreport-deletereport-preview-bottom')->text());
+                               $output->addWikiMsg('wrreport-deletereport-preview-bottom');
                        }
                }
 
@@ -1299,7 +1415,7 @@ class SpecialWrReport extends SpecialPage {
                                // $output->redirect($title->getFullURL() . '#' . wfMessage('wrreport-reports-sectionname')->text());
                        }
                        if ($action == 'preview') {
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-top')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-top');
                                $format = WRREPORT_COMPACT_PAGE;
                                $row = array_fill_keys(wrReportGetColumnNames(), NULL);
                                $row['page_id'] = $page_id;
@@ -1313,13 +1429,13 @@ class SpecialWrReport extends SpecialPage {
                                $row['author_username'] = $author_username;
 
                                $output->addHTML(wrReportTableRender(array($row), $format, FALSE, $wgParser));
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-middle')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-middle');
                                $output->addHTML(wrReportFormRender(FALSE, $page_title, $date_report, $time_report, $condition, $description, $author_name));
-                               $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom')->text());
-                               if ($author_userid)
-                                       $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom-loggedin')->text());
+                               $output->addWikiMsg('wrreport-newreport-preview-bottom');
+                               if ($wgUser->isLoggedIn())
+                                       $output->addWikiMsg('wrreport-newreport-preview-bottom-loggedin');
                                else
-                                       $output->addWikiText(wfMessage('wrreport-newreport-preview-bottom-anonymous')->text());
+                                       $output->addWikiMsg('wrreport-newreport-preview-bottom-anonymous');
                        }
 
                }