Skip to content

Commit

Permalink
Initial Whitelist Support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmallardi committed Feb 19, 2019
1 parent e84353e commit b426037
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ You can exclude notifications from certain namespaces / articles by adding them
$wgSlackExcludeNotificationsFrom = ["User:", "Weirdgroup"];
```

### Enable notifications from certain pages / namespaces

You can whitelist notifications from certain namespaces / articles by adding them into this array. Note: This targets all pages starting with the name. ALL Other notifications will be discarded, When active, the previously listed exclusion array will further limit this whitelist.

```php
// Actions (add, edit, modify) will be notified to Slack room from articles starting with these names
$wgSlackIncludeNotificationsFrom = ["IT:", "Specialgroup"];
```

### Actions to notify of

MediaWiki actions that will be sent notifications of into Slack. Set desired options to false to disable notifications of those actions.
Expand Down
31 changes: 31 additions & 0 deletions SlackNotificationsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ static function slack_article_saved(WikiPage $article, $user, $content, $summary
}
}

// Discard notifications from non-included pages
global $wgSlackIncludeNotificationsFrom;
if (count($wgSlackIncludeNotificationsFrom) > 0) {
foreach ($wgSlackIncludeNotificationsFrom as &$currentInclude) {
if (0 !== strpos($article->getTitle(), $currentInclude)) return;
}
}

// Skip new articles that have view count below 1. Adding new articles is already handled in article_added function and
// calling it also here would trigger two notifications!
$isNew = $status->value['new']; // This is 1 if article is new
Expand Down Expand Up @@ -161,6 +169,14 @@ static function slack_article_inserted(WikiPage $article, $user, $text, $summary
}
}

// Discard notifications from non-included pages
global $wgSlackIncludeNotificationsFrom;
if (count($wgSlackIncludeNotificationsFrom) > 0) {
foreach ($wgSlackIncludeNotificationsFrom as &$currentInclude) {
if (0 !== strpos($article->getTitle(), $currentInclude)) return;
}
}

// Do not announce newly added file uploads as articles...
if ($article->getTitle()->getNsText() == "File") return true;

Expand Down Expand Up @@ -195,6 +211,13 @@ static function slack_article_deleted(WikiPage $article, $user, $reason, $id)
if (0 === strpos($article->getTitle(), $currentExclude)) return;
}
}
// Discard notifications from non-included pages
global $wgSlackIncludeNotificationsFrom;
if (count($wgSlackIncludeNotificationsFrom) > 0) {
foreach ($wgSlackIncludeNotificationsFrom as &$currentInclude) {
if (0 !== strpos($article->getTitle(), $currentInclude)) return;
}
}

$message = sprintf(
"%s has deleted article %s Reason: %s",
Expand Down Expand Up @@ -222,6 +245,14 @@ static function slack_article_moved($title, $newtitle, $user, $oldid, $newid, $r
if (0 === strpos($newtitle, $currentExclude)) return;
}
}
// Discard notifications from non-included pages
global $wgSlackIncludeNotificationsFrom;
if (count($wgSlackIncludeNotificationsFrom) > 0) {
foreach ($wgSlackIncludeNotificationsFrom as &$currentInclude) {
if (0 !== strpos($title, $currentInclude)) return;
if (0 !== strpos($newtitle, $currentInclude)) return;
}
}

$message = sprintf(
"%s has moved article %s to %s. Reason: %s",
Expand Down
1 change: 1 addition & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"SlackIgnoreMinorEdits": false,
"ExcludedPermission": "",
"SlackExcludeNotificationsFrom": [],
"SlackIncludeNotificationsFrom": [],
"WikiUrl": "",
"WikiUrlEnding": "index.php?title=",
"WikiUrlEndingUserRights": "Special%3AUserRights&user=",
Expand Down

0 comments on commit b426037

Please sign in to comment.