Replace $output->addWikiText by $output->addWikiMsg to avoid duplicated forms content.
[philipp/winterrodeln/mediawiki_extensions/wrreport.git] / wrreport_body.php
index 8889b7a96345c327e2b9259b91805b54c8b927d7..d65cf2ae752f6cb9cad4d137e6bc686c5fa0f0e1 100644 (file)
@@ -149,6 +149,7 @@ class WrServicesLibravatar extends Services_Libravatar {
        function __construct() {
                $this->setSize(32);
                $this->setDefault('monsterid');
+               $this->setHttps(true);
        }
 
 
@@ -636,7 +637,7 @@ class WrReport {
        // Parser Hook Functions
        // ---------------------
 
-       public static function ParserFirstCallInitHook(&$parser) {
+       public static function ParserFirstCallInitHook(Parser &$parser) {
                $parser->setHook('bahnberichtformular', 'WrReport::bahnberichtformularParserHook');
                $parser->setHook('bahnberichte', 'WrReport::bahnberichteParserHook');
                $parser->setHook('bahnentabelle', 'WrReport::bahnentabelleParserHook');
@@ -649,9 +650,9 @@ class WrReport {
        /// \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();
@@ -689,16 +690,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');
        }
@@ -881,7 +886,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
@@ -911,7 +916,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 {
@@ -963,7 +968,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
@@ -1074,7 +1079,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();
 
@@ -1122,7 +1127,7 @@ class SpecialWrReport extends SpecialPage {
        }
 
 
-       function LanguageGetSpecialPageAliasesHook(&$specialPageArray, $languageCode) {
+       static function LanguageGetSpecialPageAliasesHook(&$specialPageArray, $languageCode) {
                $text = wfMessage('wrreport')->text(); // 'Bahnberichte'
                $title = Title::newFromText($text); // 'Bahnberichte'
                $specialPageArray['wrreport'][] = $title->getDBKey(); // 'Bahnberichte'
@@ -1145,6 +1150,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();
@@ -1174,7 +1180,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));
                        }
                }
@@ -1244,18 +1249,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');
                        }
                }
 
@@ -1386,7 +1391,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;
@@ -1400,13 +1405,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');
                        }
 
                }