From 7adaaa1d0377b83e9f92e72cf2a909919bae4ee4 Mon Sep 17 00:00:00 2001 From: Someone Date: Tue, 21 May 2019 22:12:22 +0200 Subject: [PATCH] MM-Notify-extension gitified. --- LICENSE | 9 +++++++++ MMNotify.php | 28 ++++++++++++++++++++++++++++ MMNotifyCore.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ extension.json | 27 +++++++++++++++++++++++++++ i18n/de.json | 8 ++++++++ i18n/en.json | 8 ++++++++ 6 files changed, 126 insertions(+) create mode 100644 LICENSE create mode 100644 MMNotify.php create mode 100644 MMNotifyCore.php create mode 100644 extension.json create mode 100644 i18n/de.json create mode 100644 i18n/en.json diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..09f0df8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT license + +Copyright (C) 2019 Someone + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/MMNotify.php b/MMNotify.php new file mode 100644 index 0000000..e633f3a --- /dev/null +++ b/MMNotify.php @@ -0,0 +1,28 @@ + + * @license MIT + */ + +if ( function_exists( 'wfLoadExtension' ) ) { + wfLoadExtension( 'MMNotify' ); + // Keep i18n globals so mergeMessageFileList.php doesn't break + $wgMessagesDirs['MMNotify'] = __DIR__ . '/i18n'; + $wgExtensionMessagesFiles['MMNotify'] = __DIR__ . '/MMNotify.alias.php'; + wfWarn( + 'Deprecated PHP entry point used for the MMNotify extension. ' . + 'Please use wfLoadExtension instead, ' . + 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' + ); + return; +} else { + die( 'This version of the MMNotify extension requires MediaWiki 1.29+' ); +} diff --git a/MMNotifyCore.php b/MMNotifyCore.php new file mode 100644 index 0000000..5b90428 --- /dev/null +++ b/MMNotifyCore.php @@ -0,0 +1,46 @@ + + * @license MIT + */ + +class MMNotify{ + /** + * Occurs after a new article has been created. + * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleInsertComplete + */ + 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)); + preg_match_all('/^={1,2}[^=].*$/m', $text, $out); + + foreach ($out[0] as $heading) { + $post .= $heading.'\n'; + } + + self::send_curl_request('{"text": "'.str_replace('"', '\"', $post).'"}'); + return true; + } + + + private static function send_curl_request($postData) { + global $MMIncomingWebhookUrl; + + $h = curl_init(); + curl_setopt($h, CURLOPT_URL, $MMIncomingWebhookUrl); + curl_setopt($h, CURLOPT_POST, 1); + curl_setopt($h, CURLOPT_POSTFIELDS, $postData); + curl_setopt($h, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($postData))); + curl_setopt($h, CURLOPT_RETURNTRANSFER, true); + $curl_output = curl_exec($h); + curl_close($h); + } +} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..386fe89 --- /dev/null +++ b/extension.json @@ -0,0 +1,27 @@ +{ + "name": "Mattermost Notify", + "version": "1.0.0", + "author": "Someone ", + "url": "https://git.somenet.org/pub/jan/mw_mm_webhook_extension.git", + "description": "Notify Mattermost of wiki changes.", + "type": "other", + "AutoloadClasses": { + "MMNotify": "MMNotifyCore.php" + }, + "MessagesDirs": { + "MMNotify": [ + "i18n" + ] + }, + "Hooks": { + "PageContentInsertComplete": [ + [ + "MMNotify::onPageContentInsertComplete" + ] + ] + }, + "config": { + "MMIncomingWebhookUrl": "" + }, + "manifest_version": 1 +} diff --git a/i18n/de.json b/i18n/de.json new file mode 100644 index 0000000..d0eee9f --- /dev/null +++ b/i18n/de.json @@ -0,0 +1,8 @@ +{ + "@metadata": { + "authors": [ + "Someone " + ] + }, + "mmmotify-onPageContentInsertComplete": "## #FSS-``Protokoll ist online`` :tada:" +} diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000..419a1b8 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,8 @@ +{ + "@metadata": { + "authors": [ + "Someone " + ] + }, + "mmmotify-onPageContentInsertComplete": "## #FSS-``Protokoll is online`` :tada:" +} -- 2.43.0