8 * @copyright 2019-2020 Someone <someone@somenet.org>
14 * Occurs after a new article has been created.
15 * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleInsertComplete
17 static function onPageContentInsertComplete(WikiPage $wikiPage, $user, $text, $summary, $isminor, $iswatch, $section, $flags, $revision){
18 if (stripos($wikiPage->getTitle()->getText(), 'FSPlenum') === false) return;
20 $text = ContentHandler::getContentText($wikiPage->getRevision()->getContent( Revision::RAW));
21 preg_match_all('/^={1,4}[^=].*$/m', $text, $out);
24 foreach ($out[0] as $heading) {
25 if((stripos($heading, 'outcome') !== false))continue;
27 $heading = preg_replace('/\s*=+\s*$/', '', $heading);
28 $heading = preg_replace('/^(=+)\s*/', '\1+ ', $heading);
29 $heading = explode ('+ ', $heading, 2);
31 $post .= str_replace("=", " ", $heading[0]).'+ '.$heading[1].'\n';
34 $post = wfMessage('mmmotify-onPageContentInsertComplete')->plain().'\n'.$wikiPage->getTitle()->getFullURL().'\n\n----'.self::unindent($post);
36 self::send_curl_request('{"text": "'.str_replace('"', '\"', $post).'"}');
41 // stolen from Indentation.class.php
42 private static function lines($lines) {
43 if(is_string($lines)) $lines = explode("\n",str_replace("\r\n","\n",$lines));
47 // stolen from Indentation.class.php
48 private static function unindent($lines) {
49 $lines = self::lines($lines);
50 if(!$lines) return '';
52 $first = array_shift($lines);
55 foreach($lines as $l) { # find smallest indentation
56 $ind = strlen($l) - strlen(ltrim($l));
57 if($ind < $min)$min = $ind;
59 foreach($lines as $idx=>$l) $lines[$idx] = substr($l,$min);
60 return trim($first."\n".implode("\n",$lines));
63 private static function send_curl_request($postData) {
64 global $MMIncomingWebhookUrl;
67 curl_setopt($h, CURLOPT_URL, $MMIncomingWebhookUrl);
68 curl_setopt($h, CURLOPT_POST, 1);
69 curl_setopt($h, CURLOPT_POSTFIELDS, $postData);
70 curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($postData)));
71 curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
72 $curl_output = curl_exec($h);