Coder Social home page Coder Social logo

kulttuuri / slacknotifications Goto Github PK

View Code? Open in Web Editor NEW
27.0 6.0 15.0 114 KB

Slack Mediawiki - Integrate Slack with Mediawiki. Sends notifications into your Slack room when certain actions are being performed in your wiki (for example when article is being edited, new article was added...)

Home Page: https://www.mediawiki.org/wiki/Extension:SlackNotifications

License: MIT License

PHP 100.00%
slack mediawiki mediawiki-extension slack-extension

slacknotifications's People

Contributors

cdhowie avatar harshkhandeparkar avatar jacksga avatar kulttuuri avatar mdmallardi avatar meneth avatar paladox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

slacknotifications's Issues

Suggested javascript encode \ in the curl post

Excellent work on this guys. One suggestion / fix which worked for us.

With the JSON preparation not using a library there is room for some encoding issues which apparently I am the first to experience this one...

On our system, running on windows, we use windows authentication, so user names are of the format domain\bob and the ** caused slack to return invalid_payload error (which are not handled by the extension - not complaining).

So with domain\bob in javascript the \b is not a valid escape character and that is where the error is, so below this on line ~372:

$message = str_replace('"', "'", $message);

We added this:

//Ensure a random \ is not read as the beginning of an escape character. Windows users may be authenticated with a username containing domain\user, so to ensure \ is encoded as \\...
$message = str_replace('\\', "\\\\", $message);

Notification came in html format

Hy Guys,

I just connect the extension with our slack channel and all the notification are coming as it should.

But the way the message is shown on the screen is very bad. See below. Am I missing some configuration? Maybe on slack?

<index.php?title=User:emailOfTheUser|emailOfTheUser> has edited article <index.php?title=Main_Page|Main Page> (<index.php?title=Main_Page&action=edit|edit> | <index.php?title=Main_Page&action=delete|delete> | <index.php?title=Main_Page&action=history|history> | <index.php?title=Main_Page&diff=prev&oldid=10|diff>)\n (+0 bytes)

Get rid of the "SlackNotifications" directory

Having your code in a subdirectory makes it impossible to clone the repo and use it directly from Mediawiki. The repo should be named "SlackNotifications" and the files should be in the root directory!

Alternatively, you could make all the path references in your code relative instead of hard-coded against $IP/extensions.

Protecting page will throw exception

In MediaWiki 1.31 (PHP 7.2), when we try to protect a page, it will throw exception:

Backtrace:

#0 /srv/wiki.plurk.info/public/includes/Hooks.php(177): SlackNotifications::slack_article_protected(WikiPage, User, array, string)
#1 /srv/wiki.plurk.info/public/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#2 /srv/wiki.plurk.info/public/includes/page/WikiPage.php(2521): Hooks::run(string, array)
#3 /srv/wiki.plurk.info/public/includes/page/Article.php(2593): WikiPage->doUpdateRestrictions(array, array, boolean, string, User)
#4 /srv/wiki.plurk.info/public/includes/ProtectionForm.php(312): Article->doUpdateRestrictions(array, array, boolean, string, User)
#5 /srv/wiki.plurk.info/public/includes/ProtectionForm.php(187): ProtectionForm->save()
#6 /srv/wiki.plurk.info/public/includes/page/Article.php(1544): ProtectionForm->execute()
#7 /srv/wiki.plurk.info/public/includes/actions/ProtectAction.php(52): Article->protect()
#8 /srv/wiki.plurk.info/public/includes/MediaWiki.php(500): ProtectAction->show()
#9 /srv/wiki.plurk.info/public/includes/MediaWiki.php(294): MediaWiki->performAction(Article, Title)
#10 /srv/wiki.plurk.info/public/includes/MediaWiki.php(861): MediaWiki->performRequest()
#11 /srv/wiki.plurk.info/public/includes/MediaWiki.php(524): MediaWiki->main()
#12 /srv/wiki.plurk.info/public/index.php(42): MediaWiki->run()
#13 {main}

Broken wiki links with spaces

Hi,
We started using this extension, which is really nice, but in our case the links to the pages, displayed in the slack channel, are broken. The problem is with how the spaces are encoded, eg: page with title: "Work Tracking" were encoded in the link into: index.php?title=Work%2520tracking which means that space was encoded into %20 and then % sign was encoded into %25. I've checked a code of your extension, and it is not broken, as the link is created properly in the "<a href" tag, but the onclick action added by slack was messing up the rest. So I've done a quick patch, to get rid of spaces from URL. Wiki is using underscore sign for spaces, so a simple change like below resolves the problem, maybe you would like to be interested into incorporating this change.
Line 38 in SlackNotificationsCore.php:
Change from:
$prefix = "<".$wgWikiUrl.$wgWikiUrlEnding.$article->getTitle()->getFullText();
to:
$prefix = "<".$wgWikiUrl.$wgWikiUrlEnding.str_replace(" ", "_", $article->getTitle()->getFullText());
Regards
Adam

ExcludedPermission causes PHP fatal

When we tried installing another extension after having installed SlackNotifications on MediaWiki 1.34 we got the following error. The usage of ExcludedPermission seems to be interfering with other extensions

PHP Fatal error:  Uncaught Exception: Unable to open file /srv/mediawiki/w/extensions/RegexFunctions/extension.json: filemtime(): stat failed for /srv/mediawiki/w/extensions/RegexFunctions/extension.json in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php:136
Stack trace:
#0 /srv/mediawiki/w/includes/GlobalFunctions.php(52): ExtensionRegistry->queue('/srv/mediawiki/...')
#1 /srv/mediawiki/config/LocalExtensions.php(1131): wfLoadExtension('RegexFunctions')
#2 /srv/mediawiki/config/LocalSettings.php(3319): require_once('/srv/mediawiki/...')
#3 /srv/mediawiki/w/includes/Setup.php(124): require_once('/srv/mediawiki/...')
#4 /srv/mediawiki/w/maintenance/doMaintenance.php(83): require_once('/srv/mediawiki/...')
#5 /srv/mediawiki/w/extensions/ManageWiki/maintenance/toggleExtension.php(62): require_once('/srv/mediawiki/...')
#6 {main}
  thrown in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php on line 136

Fatal error: Uncaught Exception: Unable to open file /srv/mediawiki/w/extensions/RegexFunctions/extension.json: filemtime(): stat failed for /srv/mediawiki/w/extensions/RegexFunctions/extension.json in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php:136
Stack trace:
#0 /srv/mediawiki/w/includes/GlobalFunctions.php(52): ExtensionRegistry->queue('/srv/mediawiki/...')
#1 /srv/mediawiki/config/LocalExtensions.php(1131): wfLoadExtension('RegexFunctions')
#2 /srv/mediawiki/config/LocalSettings.php(3319): require_once('/srv/mediawiki/...')
#3 /srv/mediawiki/w/includes/Setup.php(124): require_once('/srv/mediawiki/...')
#4 /srv/mediawiki/w/maintenance/doMaintenance.php(83): require_once('/srv/mediawiki/...')
#5 /srv/mediawiki/w/extensions/ManageWiki/maintenance/toggleExtension.php(62): require_once('/srv/mediawiki/...')
#6 {main}
  thrown in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php on line 136
zppix@mw4:/srv/mediawiki/w/extensions/ManageWiki/maintenance$ sudo -u www-data php toggleExtension.php --disable  regexfunctions --wiki testwiki
PHP Fatal error:  Uncaught Exception: Unable to open file /srv/mediawiki/w/extensions/RegexFunctions/extension.json: filemtime(): stat failed for /srv/mediawiki/w/extensions/RegexFunctions/extension.json in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php:136
Stack trace:
#0 /srv/mediawiki/w/includes/GlobalFunctions.php(52): ExtensionRegistry->queue('/srv/mediawiki/...')
#1 /srv/mediawiki/config/LocalExtensions.php(1131): wfLoadExtension('RegexFunctions')
#2 /srv/mediawiki/config/LocalSettings.php(3319): require_once('/srv/mediawiki/...')
#3 /srv/mediawiki/w/includes/Setup.php(124): require_once('/srv/mediawiki/...')
#4 /srv/mediawiki/w/maintenance/doMaintenance.php(83): require_once('/srv/mediawiki/...')
#5 /srv/mediawiki/w/extensions/ManageWiki/maintenance/toggleExtension.php(62): require_once('/srv/mediawiki/...')
#6 {main}
  thrown in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php on line 136

Fatal error: Uncaught Exception: Unable to open file /srv/mediawiki/w/extensions/RegexFunctions/extension.json: filemtime(): stat failed for /srv/mediawiki/w/extensions/RegexFunctions/extension.json in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php:136
Stack trace:
#0 /srv/mediawiki/w/includes/GlobalFunctions.php(52): ExtensionRegistry->queue('/srv/mediawiki/...')
#1 /srv/mediawiki/config/LocalExtensions.php(1131): wfLoadExtension('RegexFunctions')
#2 /srv/mediawiki/config/LocalSettings.php(3319): require_once('/srv/mediawiki/...')
#3 /srv/mediawiki/w/includes/Setup.php(124): require_once('/srv/mediawiki/...')
#4 /srv/mediawiki/w/maintenance/doMaintenance.php(83): require_once('/srv/mediawiki/...')
#5 /srv/mediawiki/w/extensions/ManageWiki/maintenance/toggleExtension.php(62): require_once('/srv/mediawiki/...')
#6 {main}
  thrown in /srv/mediawiki/w/includes/registration/ExtensionRegistry.php on line 136

Thank you

I just installed this extension on my Wiki and it works great. Just wanted to give you props for your efforts 👍

Enable/disable notifications by namespace

I'd like to disable notifications for the User: namespace, or to enable it just for the main namespace.

Rationale: people can be shy and avoid a wiki because they know that everyone else on the team will jump on their drafts immediately and start discussions prematurely. So I'd like to offer them a usage pattern where they write a draft in User:Username/Draft first and move it over to the main namespace when it's finished.

Change $wgSlackFromName default to $wgSitename

Could you make the default value for $wgSlackFromName =$wgSitename? We're probably going to install it on the @miraheze wiki farm, and that would make default config a little easier. And it seems like a sane enough value.

I'm the security reviewer over at Miraheze, and it looks like a pretty good extension to me. Thanks.

Tag current release

We'd like to pin to 1.14 (to avoid any accidental breakage during future development) but the last release tagged was 1.12. So we're having to pin to the commit SHA which isn't ideal.

Works also with Mattermost

I just want to give the information, that this extension also works perfectly with Mattermost (Slack alternative). Thanks for the great work.

Notifications configuration

Hi,
First of all thanks for a great extension.
I´m having some issues to use the configuration of the notifications.
I have set everything to false except "AddedArticle" but it´s still posting changes, removals etc, and added the settings in the bottom of LocalSettings.php
Dose anyone have any idea abot what might be the issue?

$wgSlackNotificationNewUser = false;
$wgSlackNotificationBlockedUser = false;
$wgSlackNotificationAddedArticle = true;
$wgSlackNotificationRemovedArticle = false;
$wgSlackNotificationMovedArticle = false;
$wgSlackNotificationEditedArticle = false;
$wgSlackNotificationFileUpload = false;

Thanks

badcachekey No cached serialization found with that key

Hi
I use this extension with VisualEditor, but error occurred when saving page.

My MediaWiki version: 1.31.0
Following is api.php reponses:

  1. {"visualeditoredit":{"result":"success","cachekey":"f60552e9de0a8b27ef1a0c7c853c35d2"}}

  2. {"error":{"code":"badcachekey","info":"No cached serialization found with that key","*":"See https://wiki.skymirror.com.tw/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."}}

Support for Discord

Hi, Do you have plans to adapt this to support Discord servers? Discord supports per-channel/per-server webhooks but I assume the method is slightly different, I tried my luck and put Discord webhook details in the config but no luck :)

Thanks in advance for reading!

Utilize slack attachments

Format all that diff and links etc. to come inside slack attachments. That could improve readability of the message. Slack seems to have added nice way to actually create formatted messages in web interface for testing them before actually implementing.

Would be great to first make suggestion of how the message would look like in that slack message builder interface and paste here url for that for discussion.

curl_init() failure

I'm a huge fan of this extension; it's a major part of my workflow.

Updated basically everything on the server (Ubuntu 16.06, PHP 7, and MediaWiki 1.28) this morning, though, and ran into a problem. Installed curl sudo apt-get install php-curl and restarted the server; error remains the same.

So… any guesses what I'm doing wrong?

Thanks for creating such an awesome extension!

[4f1546bd9c53f8d999378587] /index.php?title=KENDALL_C._GEDNEY,_LTJG,_USN&action=submit Error from line 357 of /var/www/html/extensions/SlackNotifications/SlackNotificationsCore.php: Call to undefined function curl_init()

Backtrace:

#0 /var/www/html/extensions/SlackNotifications/SlackNotificationsCore.php(135): SlackNotifications::push_slack_notify(string, string, User)
#1 /var/www/html/includes/Hooks.php(195): SlackNotifications::slack_article_saved(WikiPage, User, WikitextContent, string, integer, NULL, NULL, integer, Revision, Status, boolean)
#2 /var/www/html/includes/page/WikiPage.php(1912): Hooks::run(string, array)
#3 /var/www/html/includes/libs/rdbms/database/Database.php(2682): WikiPage->{closure}(DatabaseMysqli, string)
#4 /var/www/html/includes/deferred/AtomicSectionUpdate.php(33): Database->doAtomicSection(string, Closure)
#5 /var/www/html/includes/deferred/DeferredUpdates.php(263): AtomicSectionUpdate->doUpdate()
#6 /var/www/html/includes/deferred/DeferredUpdates.php(225): DeferredUpdates::runUpdate(AtomicSectionUpdate, LBFactorySimple, integer)
#7 /var/www/html/includes/deferred/DeferredUpdates.php(129): DeferredUpdates::execute(array, string, integer)
#8 /var/www/html/includes/MediaWiki.php(592): DeferredUpdates::doUpdates(string, integer)
#9 /var/www/html/includes/MediaWiki.php(561): MediaWiki::preOutputCommit(RequestContext, Closure)
#10 /var/www/html/includes/MediaWiki.php(867): MediaWiki->doPreOutputCommit(Closure)
#11 /var/www/html/includes/MediaWiki.php(512): MediaWiki->main()
#12 /var/www/html/index.php(43): MediaWiki->run()
#13 {main}

Allow users to invoke a MediaWiki page from within Slack

Allow users to invoke a MediaWiki page from within Slack.
Example: it reads the message content (What's the API rate limit), and looks it up on the MediaWiki install. It then returns a list of candidates that can be replied back to the Slack user.

Ability to set emoji for the bot

In slack the icon of the bot can be customized with either slack emoji or something from url. that icon_emoji parameter is explained here. Could be a new variable added to extension parameters so users can customize this.

Plugin usage with proxy

I couldnt get the plugin to work. I managed to fix it myself in SlackNotificationsCore.php

...
global $wgSlackIncomingWebhookUrl, $wgSlackFromName, $wgSlackRoomName, $wgSlackSendMethod, $wgExcludedPermission, $wgSitename, $wgSlackEmoji, $wgHTTPProxy;
...
curl_setopt($h, CURLOPT_PROXY, $wgHTTPProxy);

Rename slack_notifications.php

Could you rename slack_notifications.php to SlackNotifications.php to meet the common practice in MediaWiki extensions naming?

$wgExcludedPermission doesn't seem to work

Tried $wgExcludedPermission = "Administrators"; and still get every notification pushed.

I'm probably doing something wrong… any guesses what it might be?

(Thanks for this extension, btw. Love it!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.