8 * @copyright 2019-2020 Someone <someone@somenet.org>
12 use MediaWiki\Revision\RevisionRecord;
16 * Occurs after a new article has been created.
17 * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleInsertComplete
19 static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult){
20 if (stripos($wikiPage->getTitle()->getText(), 'FSPlenum') === false) return;
22 $text = ContentHandler::getContentText($revisionRecord->getContent(($revisionRecord->getSlotRoles())[0], RevisionRecord::RAW ));
23 preg_match_all('/^={1,4}[^=].*$/m', $text, $out);
26 foreach ($out[0] as $heading) {
27 if((stripos($heading, 'outcome') !== false))continue;
29 $heading = preg_replace('/\s*=+\s*$/', '', $heading);
30 $heading = preg_replace('/^(=+)\s*/', '\1+ ', $heading);
31 $heading = explode ('+ ', $heading, 2);
33 $post .= str_replace("=", " ", $heading[0]).'+ '.$heading[1].'\n';
36 $post = wfMessage('mmmotify-onPageContentInsertComplete')->plain().'\n'.$wikiPage->getTitle()->getFullURL().'\n\n----'.self::unindent($post);
38 self::send_curl_request('{"text": "'.str_replace('"', '\"', $post).'"}');
43 // stolen from Indentation.class.php
44 private static function lines($lines) {
45 if(is_string($lines)) $lines = explode("\n",str_replace("\r\n","\n",$lines));
49 // stolen from Indentation.class.php
50 private static function unindent($lines) {
51 $lines = self::lines($lines);
52 if(!$lines) return '';
54 $first = array_shift($lines);
57 foreach($lines as $l) { # find smallest indentation
58 $ind = strlen($l) - strlen(ltrim($l));
59 if($ind < $min)$min = $ind;
61 foreach($lines as $idx=>$l) $lines[$idx] = substr($l,$min);
62 return trim($first."\n".implode("\n",$lines));
65 private static function send_curl_request($postData) {
66 global $MMIncomingWebhookUrl;
69 curl_setopt($h, CURLOPT_URL, $MMIncomingWebhookUrl);
70 curl_setopt($h, CURLOPT_POST, 1);
71 curl_setopt($h, CURLOPT_POSTFIELDS, $postData);
72 curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($postData)));
73 curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
74 $curl_output = curl_exec($h);