Dont send out mediawiki syntax, but markdown notifications.
authorSomeone <someone@somenet.org>
Wed, 22 Apr 2020 02:27:43 +0000 (04:27 +0200)
committerSomeone <someone@somenet.org>
Wed, 22 Apr 2020 02:27:43 +0000 (04:27 +0200)
MMNotifyCore.php

index 5b90428cb74cb0e108de734649dcfc8545c3a453..ac05afa351fe1c1f8fff8bf3d2cd85cdd2bd335c 100644 (file)
@@ -5,7 +5,7 @@
  *
  * @file
  * @ingroup Extensions
  *
  * @file
  * @ingroup Extensions
- * @copyright 2019 Someone <someone@somenet.org>
+ * @copyright 2019-2020 Someone <someone@somenet.org>
  * @license MIT
  */
 
  * @license MIT
  */
 
@@ -17,20 +17,49 @@ class MMNotify{
     static function onPageContentInsertComplete(WikiPage $wikiPage, $user, $text, $summary, $isminor, $iswatch, $section, $flags, $revision){
         if (stripos($wikiPage->getTitle()->getText(), 'FSPlenum') === false) return;
 
     static function onPageContentInsertComplete(WikiPage $wikiPage, $user, $text, $summary, $isminor, $iswatch, $section, $flags, $revision){
         if (stripos($wikiPage->getTitle()->getText(), 'FSPlenum') === false) return;
 
-        $post = wfMessage('mmmotify-onPageContentInsertComplete')->plain().'\n'.$wikiPage->getTitle()->getFullURL().'\n\n----\n';
-
         $text = ContentHandler::getContentText($wikiPage->getRevision()->getContent( Revision::RAW));
         $text = ContentHandler::getContentText($wikiPage->getRevision()->getContent( Revision::RAW));
-        preg_match_all('/^={1,2}[^=].*$/m', $text, $out);
+        preg_match_all('/^={1,4}[^=].*$/m', $text, $out);
 
 
+        $post = '\n';
         foreach ($out[0] as $heading) {
         foreach ($out[0] as $heading) {
-            $post .= $heading.'\n';
+            if((stripos($heading, 'outcome') !== false))continue;
+
+            $heading = preg_replace('/\s*=+\s*$/', '', $heading);
+            $heading = preg_replace('/^(=+)\s*/', '\1+ ', $heading);
+            $heading = explode ('+ ', $heading, 2);
+
+            $post .= str_replace("=", " ", $heading[0]).'+ '.$heading[1].'\n';
         }
 
         }
 
+        $post = wfMessage('mmmotify-onPageContentInsertComplete')->plain().'\n'.$wikiPage->getTitle()->getFullURL().'\n\n----'.self::unindent($post);
+
         self::send_curl_request('{"text": "'.str_replace('"', '\"', $post).'"}');
         return true;
     }
 
 
         self::send_curl_request('{"text": "'.str_replace('"', '\"', $post).'"}');
         return true;
     }
 
 
+    // stolen from Indentation.class.php
+    private static function lines($lines) {
+        if(is_string($lines)) $lines = explode("\n",str_replace("\r\n","\n",$lines));
+        return $lines;
+    }
+
+    // stolen from Indentation.class.php
+    private static function unindent($lines) {
+        $lines = self::lines($lines);
+        if(!$lines) return '';
+
+        $first = array_shift($lines);
+        $min = PHP_INT_MAX;
+
+        foreach($lines as $l) { # find smallest indentation
+            $ind = strlen($l) - strlen(ltrim($l));
+            if($ind < $min)$min = $ind;
+         }
+        foreach($lines as $idx=>$l) $lines[$idx] = substr($l,$min);
+        return trim($first."\n".implode("\n",$lines));
+    }
+
     private static function send_curl_request($postData) {
         global $MMIncomingWebhookUrl;
 
     private static function send_curl_request($postData) {
         global $MMIncomingWebhookUrl;