public static function onPageContentSaveComplete($article, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId)
 {
     global $wgSlackWebhookURL, $wgSlackChannel, $wgSlackUserName, $wgSlackLinkUsers;
     wfDebug("Slack URL: " . $wgSlackWebhookURL . "\n");
     // Build the message we're going to post to Slack.
     $message = '*<' . SlackHooks::encodeSlackChars($article->getTitle()->getFullURL()) . '|' . SlackHooks::encodeSlackChars($article->getTitle()) . '>* ' . 'modified by *';
     if ($wgSlackLinkUsers) {
         $message .= '@';
     }
     $message .= SlackHooks::encodeSlackChars(strtolower($user->getName())) . '*: ' . SlackHooks::encodeSlackChars($summary) . '.';
     // Build the WebHook Payload.
     // NB: The Slack parser chokes if there is a trailing , at the end of the list of items
     //     in the payload. Make sure any optional items are in the middle to avoid this.
     $payload = '{"channel": "' . $wgSlackChannel . '",';
     if ($wgSlackLinkUsers) {
         $payload .= '"link_names": "1",';
     }
     $payload .= '"username": "******",' . '"text": "' . $message . '"' . '}';
     wfDebug("Slack Payload: " . $payload . "\n");
     $post = "payload=" . urlencode($payload);
     // POST it to Slack.
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $wgSlackWebhookURL);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     $result = curl_exec($ch);
     wfDebug("Slack Result: " . $result . "\n");
 }
Example #2
0
 public static function onPageContentInsertComplete($wikiPage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision)
 {
     global $wgSlackIsCreate, $wgSlackIgnoreMinor;
     // If this is a minor edit and we want to ignore minor edits, return now.
     if ($wgSlackIgnoreMinor && $isMinor) {
         return true;
     }
     // Flag this as a page creation so we don't notify it's been modified as well.
     $wgSlackIsCreate = true;
     // Build the Slack Message.
     $message = SlackHooks::buildMessage($wikiPage, $user, $summary, "created");
     // Build the Slack Payload.
     $payload = SlackHooks::buildPayload($message);
     // Send the message to Slack.
     SlackHooks::sendToSlack($payload);
     return true;
 }