Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 591ef8746e | |||
| 6c2e30deab | |||
| ce780adf10 | |||
| 680040e823 | |||
| 8fa8dce03d | |||
| c3bdbecee5 | |||
| 6ccca7b823 | |||
| 03d612a3f7 | |||
| 9830df7e97 | |||
| cecb90dffc | |||
| 9034275470 | |||
| 3f1e1e784b | |||
| 78d66e5e31 | |||
| f0cf5a741d | |||
| c193c24be2 | |||
| 4b46212f49 | |||
| d6d0f22c01 | |||
| 0cf579aa6a | |||
| ac38da8529 |
+2
-1
@@ -1,2 +1,3 @@
|
||||
/vendor/
|
||||
debug.log
|
||||
debug.log
|
||||
.DS_Store
|
||||
@@ -45,8 +45,10 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
|
||||
| `$wgDiscordNoMinor` | bool | Do not send notifications that are for [minor edits](https://meta.wikimedia.org/wiki/Help:Minor_edit) | `false`
|
||||
| `$wgDiscordNoNull` | bool | Do not send notifications for [null edits](https://www.mediawiki.org/wiki/Manual:Purge#Null_edits) | `true`
|
||||
| `$wgDiscordSuppressPreviews` | bool | Force previews for links in Discord messages to be suppressed | `true`
|
||||
| `$wgDiscordMaxChars` | int | Maximum amount of characters for user-generated text (e.g summaries, reasons). Set to `null` to disable truncation | `null`
|
||||
| `$wgDiscordDisabledHooks` | array | List of hooks to disable sending webhooks for (see [below](#hooks-used)) | `[]`
|
||||
| `$wgDiscordDisabledNS` | array | List of namespaces to disable sending webhooks for (see [below](#hooks-used)) | `[]`
|
||||
| `$wgDiscordDisabledNS` | array | List of namespaces to disable sending webhooks for | `[]`
|
||||
| `$wgDiscordDisabledUsers` | array | List of users whose performed actions shouldn't send webhooks | `[]`
|
||||
|
||||
## Hooks used
|
||||
- `PageContentSaveComplete` - New edits to pages and page creations
|
||||
|
||||
+4
-2
@@ -4,7 +4,7 @@
|
||||
"[https://github.com/jaydenkieran Jayden Bailey]"
|
||||
],
|
||||
"url": "https://github.com/jaydenkieran/mw-discord",
|
||||
"version": "1.0",
|
||||
"version": "1.0.5",
|
||||
"descriptionmsg": "discord-desc",
|
||||
"license-name": "MIT",
|
||||
"manifest_version": 1,
|
||||
@@ -14,8 +14,10 @@
|
||||
"DiscordNoMinor": false,
|
||||
"DiscordNoNull": true,
|
||||
"DiscordSuppressPreviews": true,
|
||||
"DiscordMaxChars": null,
|
||||
"DiscordDisabledHooks": [],
|
||||
"DiscordDisabledNS": []
|
||||
"DiscordDisabledNS": [],
|
||||
"DiscordDisabledUsers": []
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"DiscordHooks": "src/DiscordHooks.php",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"discord-minor": "(m)",
|
||||
"discord-size": "($1)",
|
||||
"discord-edit": "$1 edited $2 $3 $4",
|
||||
"discord-create": "$1 created $2 $3 $4",
|
||||
"discord-articledelete": "$1 deleted $2 $3 ($4 revisions deleted)",
|
||||
"discord-undeleterev": "revisions for",
|
||||
"discord-articleundelete": "$1 undeleted $2 $3 $4",
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"@metadata": {
|
||||
"authors": [
|
||||
"Railfail536"
|
||||
]
|
||||
},
|
||||
"discord-desc": "Wysyła wiadomości o dokonywanych akcjach na serwer Discord",
|
||||
"discord-userlinks": "$1 ($2|$3)",
|
||||
"discord-revisionlinks": "($1) $2 $3",
|
||||
"discord-talk": "d",
|
||||
"discord-contribs": "w",
|
||||
"discord-diff": "różn.",
|
||||
"discord-minor": "(m)",
|
||||
"discord-size": "($1)",
|
||||
"discord-edit": "$1 edytował $2 $3 $4",
|
||||
"discord-articledelete": "$1 usunął $2 $3 ($4 wersje usunięte)",
|
||||
"discord-undeleterev": "wersje",
|
||||
"discord-articleundelete": "$1 odtworzył $2 $3 $4",
|
||||
"discord-revvisibility": "$1 zmienił widoczność $2 wersji $3",
|
||||
"discord-articleprotect": "$1 zmienił poziom zabezpoeczenia strony $2 $2 $3 ($4)",
|
||||
"discord-titlemove": "$1 przeniósł $2 na $3 $4 $5",
|
||||
"discord-localusercreated": "$1 założył konto",
|
||||
"discord-blocktimeformat": "d F Y H:i",
|
||||
"discord-blockipcomplete": "$1 zablokował $2 $3 ($4)",
|
||||
"discord-unblockusercomplete": "$1 zdjął blokadę z $2",
|
||||
"discord-usergroupschanged": "$1 zmienił uprawnienia użytkownika $2 $3 ($4) ($5)",
|
||||
"discord-uploadnewver": "nową wersję",
|
||||
"discord-uploadcomplete": "$1 przesłał $2 $3 $4 ($5, $6x$7, $8)",
|
||||
"discord-filedeletecomplete": "$1 usunął wersję pliku $2 $3",
|
||||
"discord-fileundeletecomplete": "$1 odtworzył wersje pliku $2 $3"
|
||||
}
|
||||
+2
-1
@@ -7,7 +7,8 @@
|
||||
"discord-diff": "Used as the text for $1 in discord-revisionlinks",
|
||||
"discord-minor": "Used as the text for $2 in discord-revisionlinks",
|
||||
"discord-size": "Used as the text for $3 in discord-revisionlinks. Parameters\n* $1 - Calculated revision size diff",
|
||||
"discord-edit": "Message sent to Discord for when a page edit/creation is made. Parameters:\n* $1 - discord-userlinks\n* $2 - Page link\n* $3 - discord-revisionlinks\n* $4 - Summary (always surrounded in tildes)",
|
||||
"discord-edit": "Message sent to Discord for when a page edit is made. Parameters:\n* $1 - discord-userlinks\n* $2 - Page link\n* $3 - discord-revisionlinks\n* $4 - Summary (always surrounded in tildes)",
|
||||
"discord-create": "Message sent to Discord for when a page creation is made. Parameters:\n* $1 - discord-userlinks\n* $2 - Page link\n* $3 - discord-revisionlinks\n* $4 - Summary (always surrounded in tildes)",
|
||||
"discord-articledelete": "Message sent to Discord when a page is deleted. Parameters:\n* $1 - discord-userlinks\n* $2 - Page link\n* $3 - Reason (always surrounded in tildes)\n* $4 - Number of revisions deleted",
|
||||
"discord-undeleterev": "Used as the text for $2 in discord-articleundelete if revisions are being undeleted rather than a page",
|
||||
"discord-articleundelete": "Message sent to Discord when pages/revisions are undeleted. Parameters:\n* $1 - discord-userlinks\n* $2 - discord-undeleterev\n* $3 - Page link\n* $4 - Comment (always surrounded in tildes)",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<phpunit colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Utils tests">
|
||||
<file>tests/UtilsTests.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
+78
-39
@@ -13,7 +13,7 @@ class DiscordHooks {
|
||||
public static function onPageContentSaveComplete( &$wikiPage, &$user, $content, $summary, $isMinor, $isWatch, $section, &$flags, $revision, &$status, $baseRevId, $undidRevId ) {
|
||||
global $wgDiscordNoBots, $wgDiscordNoMinor, $wgDiscordNoNull;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'PageContentSaveComplete', $wikiPage->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'PageContentSaveComplete', $wikiPage->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,15 +32,22 @@ class DiscordHooks {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wikiPage->getTitle()->inNamespace( NS_FILE ) ) {
|
||||
// Don't continue, it's a file which onUploadComplete will handle instead
|
||||
if ( $wikiPage->getTitle()->inNamespace( NS_FILE ) && is_null( $revision->getPrevious() ) ) {
|
||||
// Don't continue, it's a new file which onUploadComplete will handle instead
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-edit', DiscordUtils::createUserLinks( $user ),
|
||||
$msgKey = 'discord-edit';
|
||||
|
||||
$isNew = $status->value['new'];
|
||||
if ($isNew == 1) { // is a new page
|
||||
$msgKey = 'discord-create';
|
||||
}
|
||||
|
||||
$msg = wfMessage( $msgKey, DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $wikiPage->getTitle(), $wikiPage->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createRevisionText( $revision ),
|
||||
( $summary ? ('`' . $summary . '`' ) : '' ) )->text();
|
||||
( $summary ? ('`' . DiscordUtils::truncateText( $summary ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -50,9 +57,9 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDeleteComplete
|
||||
*/
|
||||
public static function onArticleDeleteComplete( &$article, User &$user, $reason, $id, $content, LogEntry $logEntry, $archivedRevisionCount ) {
|
||||
global $wgDiscordNoBots, $wgDiscordNoMinor, $wgDiscordNoNull;
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleDeleteComplete', $article->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleDeleteComplete', $article->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -63,8 +70,8 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-articledelete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
$archivedRevisionCount)->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
$archivedRevisionCount)->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -74,16 +81,21 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleUndelete
|
||||
*/
|
||||
public static function onArticleUndelete( Title $title, $create, $comment, $oldPageId, $restoredPages ) {
|
||||
global $wgUser;
|
||||
global $wgDiscordNoBots, $wgUser;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleUndelete', $title->getNamespace(), $wgUser ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-articleundelete', DiscordUtils::createUserLinks( $wgUser ),
|
||||
($create ? '' : wfMessage( 'discord-undeleterev' )->text() ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $comment ? ('`' . $comment . '`' ) : '' ))->text();
|
||||
( $comment ? ('`' . DiscordUtils::truncateText( $comment ) . '`' ) : '' ))->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -93,15 +105,20 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleRevisionVisibilitySet
|
||||
*/
|
||||
public static function onArticleRevisionVisibilitySet( &$title, $ids, $visibilityChangeMap ) {
|
||||
global $wgUser;
|
||||
global $wgDiscordNoBots, $wgUser;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleRevisionVisibilitySet', $title->getNamespace(), $wgUser ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $wgUser->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-revvisibility', DiscordUtils::createUserLinks( $wgUser ),
|
||||
count($visibilityChangeMap),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ) )->text();
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -113,7 +130,7 @@ class DiscordHooks {
|
||||
public static function onArticleProtectComplete( &$article, &$user, $protect, $reason ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'ArticleProtectComplete', $article->getTitle()->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'ArticleProtectComplete', $article->getTitle()->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -124,8 +141,8 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-articleprotect', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
implode(", ", $protect) )->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
implode(", ", $protect) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -137,7 +154,7 @@ class DiscordHooks {
|
||||
public static function onTitleMoveComplete( Title &$title, Title &$newTitle, User $user, $oldid, $newid, $reason, Revision $revision ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'TitleMoveComplete', $title->getNamespace() ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'TitleMoveComplete', $title->getNamespace(), $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -149,8 +166,8 @@ class DiscordHooks {
|
||||
$msg = wfMessage( 'discord-titlemove', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createMarkdownLink( $newTitle, $newTitle->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
DiscordUtils::createRevisionText( $revision ) )->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
DiscordUtils::createRevisionText( $revision ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -160,11 +177,11 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
|
||||
*/
|
||||
public static function onLocalUserCreated( $user, $autocreated ) {
|
||||
if ( DiscordUtils::isDisabled( 'LocalUserCreated', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'LocalUserCreated', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-localusercreated', DiscordUtils::createUserLinks( $user ) )->text();
|
||||
$msg = wfMessage( 'discord-localusercreated', DiscordUtils::createUserLinks( $user ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -174,7 +191,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/BlockIpComplete
|
||||
*/
|
||||
public static function onBlockIpComplete( Block $block, User $user ) {
|
||||
if ( DiscordUtils::isDisabled( 'BlockIpComplete', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'BlockIpComplete', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -186,8 +203,8 @@ class DiscordHooks {
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTarget() ),
|
||||
( $block->mReason ? ('`' . $block->mReason . '`' ) : '' ),
|
||||
$expiryMsg )->text();
|
||||
( $block->mReason ? ('`' . DiscordUtils::truncateText( $block->mReason ) . '`' ) : '' ),
|
||||
$expiryMsg )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -197,7 +214,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UnblockUserComplete
|
||||
*/
|
||||
public static function onUnblockUserComplete( Block $block, User $user ) {
|
||||
if ( DiscordUtils::isDisabled( 'UnblockUserComplete', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'UnblockUserComplete', NULL, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -211,7 +228,7 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGroupsChanged
|
||||
*/
|
||||
public static function onUserGroupsChanged( User $user, array $added, array $removed, $performer, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'UserGroupsChanged', NULL ) ) {
|
||||
if ( DiscordUtils::isDisabled( 'UserGroupsChanged', NULL, $performer ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -222,9 +239,9 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-usergroupschanged', DiscordUtils::createUserLinks( $performer ),
|
||||
DiscordUtils::createUserLinks( $user ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
( ( count($added) > 0 ) ? ( '+ ' . join(', ', $added) ) : ''),
|
||||
( ( count($removed) > 0 ) ? ( '- ' . join(', ', $removed) ) : '' ) )->text();
|
||||
( ( count($removed) > 0 ) ? ( '- ' . join(', ', $removed) ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -234,23 +251,31 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete
|
||||
*/
|
||||
public static function onUploadComplete( &$image ) {
|
||||
if ( DiscordUtils::isDisabled( 'UploadComplete', NS_FILE ) ) {
|
||||
return true;
|
||||
}
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
$lf = $image->getLocalFile();
|
||||
$user = $lf->getUser( $type = 'object' ); // only supported in MW 1.31+
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'UploadComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$comment = $lf->getDescription();
|
||||
$isNewRevision = count($lf->getHistory()) > 0;
|
||||
|
||||
$msg = wfMessage( 'discord-uploadcomplete', DiscordUtils::createUserLinks( $user ),
|
||||
( $isNewRevision ? wfMessage( 'discord-uploadnewver' )->text() : '' ),
|
||||
DiscordUtils::createMarkdownLink( $lf->getName(), $lf->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $comment ? ('`' . $comment . '`' ) : '' ),
|
||||
( $comment ? ('`' . DiscordUtils::truncateText( $comment ) . '`' ) : '' ),
|
||||
DiscordUtils::formatBytes($lf->getSize()),
|
||||
$lf->getWidth(),
|
||||
$lf->getHeight(),
|
||||
$lf->getMimeType() )->text();
|
||||
$lf->getMimeType() )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -260,7 +285,14 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileDeleteComplete
|
||||
*/
|
||||
public static function onFileDeleteComplete( $file, $oldimage, $article, $user, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileDeleteComplete', NS_FILE ) ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'FileDeleteComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -271,7 +303,7 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-filedeletecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $file->getName(), $file->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ) )->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -281,13 +313,20 @@ class DiscordHooks {
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/FileUndeleteComplete
|
||||
*/
|
||||
public static function onFileUndeleteComplete( $title, $fileVersions, $user, $reason ) {
|
||||
if ( DiscordUtils::isDisabled( 'FileUndeleteComplete', NS_FILE ) ) {
|
||||
global $wgDiscordNoBots;
|
||||
|
||||
if ( DiscordUtils::isDisabled( 'FileUndeleteComplete', NS_FILE, $user ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $wgDiscordNoBots && $user->isBot() ) {
|
||||
// Don't continue, this is a bot change
|
||||
return true;
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-fileundeletecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ) )->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->plain();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
+42
-8
@@ -4,8 +4,8 @@ class DiscordUtils {
|
||||
/**
|
||||
* Checks if criteria is met for this action to be cancelled
|
||||
*/
|
||||
public static function isDisabled ( $hook, $ns ) {
|
||||
global $wgDiscordDisabledHooks, $wgDiscordDisabledNS;
|
||||
public static function isDisabled ( $hook, $ns, $user ) {
|
||||
global $wgDiscordDisabledHooks, $wgDiscordDisabledNS, $wgDiscordDisabledUsers;
|
||||
|
||||
if ( is_array( $wgDiscordDisabledHooks ) ) {
|
||||
if ( in_array( strtolower( $hook ), array_map( 'strtolower', $wgDiscordDisabledHooks ) ) ) {
|
||||
@@ -26,6 +26,18 @@ class DiscordUtils {
|
||||
} else {
|
||||
wfDebugLog( 'discord', 'The value of $wgDiscordDisabledNS is not valid and therefore all namespaces are enabled.' );
|
||||
}
|
||||
if ( is_array( $wgDiscordDisabledUsers ) ) {
|
||||
if ( !is_null( $user ) ) {
|
||||
if ( $user instanceof User ) {
|
||||
if ( in_array( $user->getName(), $wgDiscordDisabledUsers ) ) {
|
||||
// User shouldn't trigger a message, return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wfDebugLog( 'discord', 'The value of $wgDiscordDisabledUsers is not valid and therefore all users can trigger messages.' );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -75,7 +87,6 @@ class DiscordUtils {
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_TIMEOUT, 20 ); // Do not allow cURL to run for a long time
|
||||
curl_setopt( $c_handlers[$value], CURLOPT_USERAGENT, 'mw-discord/1.0 (github.com/jaydenkieran)' ); // Add a unique user agent
|
||||
curl_multi_add_handle( $mh, $c_handlers[$value] );
|
||||
$response = curl_exec( $ch );
|
||||
}
|
||||
|
||||
$running = null;
|
||||
@@ -108,10 +119,16 @@ class DiscordUtils {
|
||||
* Creates links for a specific MediaWiki User object
|
||||
*/
|
||||
public static function createUserLinks ($user) {
|
||||
$userPage = DiscordUtils::createMarkdownLink( $user, $user->getUserPage()->getFullUrl( '', '', $proto = PROTO_HTTP ) );
|
||||
$userTalk = DiscordUtils::createMarkdownLink( wfMessage( 'discord-talk' )->text(), $user->getTalkPage()->getFullUrl( '', '', $proto = PROTO_HTTP ) );
|
||||
$userContribs = DiscordUtils::createMarkdownLink( wfMessage( 'discord-contribs' )->text(), Title::newFromText("Special:Contributions/" . $user)->getFullURL( '', '', $proto = PROTO_HTTP ) );
|
||||
$text = wfMessage( 'discord-userlinks', $userPage, $userTalk, $userContribs )->text();
|
||||
if ( $user instanceof User ) {
|
||||
$userPage = DiscordUtils::createMarkdownLink( $user, $user->getUserPage()->getFullUrl( '', '', $proto = PROTO_HTTP ) );
|
||||
$userTalk = DiscordUtils::createMarkdownLink( wfMessage( 'discord-talk' )->text(), $user->getTalkPage()->getFullUrl( '', '', $proto = PROTO_HTTP ) );
|
||||
$userContribs = DiscordUtils::createMarkdownLink( wfMessage( 'discord-contribs' )->text(), Title::newFromText("Special:Contributions/" . $user)->getFullURL( '', '', $proto = PROTO_HTTP ) );
|
||||
$text = wfMessage( 'discord-userlinks', $userPage, $userTalk, $userContribs )->text();
|
||||
} else {
|
||||
// If it's a string, which can be likely (for example when range blocking a user)
|
||||
// We need to handle this differently.
|
||||
$text = wfMessage( 'discord-userlinks', $user, 'n/a', 'n/a' )->text();
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
@@ -135,6 +152,9 @@ class DiscordUtils {
|
||||
$size .= wfMessage( 'discord-size', sprintf( "%+d", $revision->getSize() - $previous->getSize() ) )->text();
|
||||
}
|
||||
}
|
||||
if ( $size == '' ) {
|
||||
$size .= wfMessage( 'discord-size', sprintf( "%d", $revision->getSize() ) )->text();
|
||||
}
|
||||
$text = wfMessage( 'discord-revisionlinks', $diff, $minor, $size )->text();
|
||||
return $text;
|
||||
}
|
||||
@@ -162,7 +182,21 @@ class DiscordUtils {
|
||||
$bytes /= (1 << (10 * $pow));
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$pow];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate text to maximum allowed characters
|
||||
*/
|
||||
public static function truncateText($text) {
|
||||
global $wgDiscordMaxChars;
|
||||
if ($wgDiscordMaxChars) {
|
||||
if (strlen($text) > $wgDiscordMaxChars) {
|
||||
$text = substr($text, 0, $wgDiscordMaxChars);
|
||||
$text = $text.'...';
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
require "src/Utils.php";
|
||||
|
||||
class UtilsTests extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testCreateMarkdownLink()
|
||||
{
|
||||
$link = DiscordUtils::CreateMarkdownLink("Link", "https://example.com");
|
||||
$this->assertEquals("[Link](https://example.com)", $link);
|
||||
}
|
||||
|
||||
public function testRemoveMultipleSlashes()
|
||||
{
|
||||
$url = DiscordUtils::RemoveMultipleSlashes("https://example.com/page/page2//page3/page4//page5//");
|
||||
$this->assertEquals("https://example.com/page/page2/page3/page4/page5/", $url);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user