Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cf579aa6a | |||
| ac38da8529 |
+2
-1
@@ -1,2 +1,3 @@
|
||||
/vendor/
|
||||
debug.log
|
||||
debug.log
|
||||
.DS_Store
|
||||
@@ -45,8 +45,9 @@ 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 | `[]`
|
||||
|
||||
## Hooks used
|
||||
- `PageContentSaveComplete` - New edits to pages and page creations
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@
|
||||
"[https://github.com/jaydenkieran Jayden Bailey]"
|
||||
],
|
||||
"url": "https://github.com/jaydenkieran/mw-discord",
|
||||
"version": "1.0",
|
||||
"version": "1.0.1",
|
||||
"descriptionmsg": "discord-desc",
|
||||
"license-name": "MIT",
|
||||
"manifest_version": 1,
|
||||
@@ -14,6 +14,7 @@
|
||||
"DiscordNoMinor": false,
|
||||
"DiscordNoNull": true,
|
||||
"DiscordSuppressPreviews": true,
|
||||
"DiscordMaxChars": null,
|
||||
"DiscordDisabledHooks": [],
|
||||
"DiscordDisabledNS": []
|
||||
},
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<phpunit colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Utils tests">
|
||||
<file>tests/UtilsTests.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
+10
-10
@@ -40,7 +40,7 @@ class DiscordHooks {
|
||||
$msg = wfMessage( 'discord-edit', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $wikiPage->getTitle(), $wikiPage->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
DiscordUtils::createRevisionText( $revision ),
|
||||
( $summary ? ('`' . $summary . '`' ) : '' ) )->text();
|
||||
( $summary ? ('`' . DiscordUtils::truncateText( $summary ) . '`' ) : '' ) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-articledelete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
$archivedRevisionCount)->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
@@ -83,7 +83,7 @@ class DiscordHooks {
|
||||
$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 ) . '`' ) : '' ))->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-articleprotect', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $article->getTitle(), $article->getTitle()->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
implode(", ", $protect) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
@@ -149,7 +149,7 @@ 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 . '`' ) : '' ),
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ),
|
||||
DiscordUtils::createRevisionText( $revision ) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
@@ -186,7 +186,7 @@ class DiscordHooks {
|
||||
}
|
||||
|
||||
$msg = wfMessage( 'discord-blockipcomplete', DiscordUtils::createUserLinks( $user ), DiscordUtils::createUserLinks( $block->getTarget() ),
|
||||
( $block->mReason ? ('`' . $block->mReason . '`' ) : '' ),
|
||||
( $block->mReason ? ('`' . DiscordUtils::truncateText( $block->mReason ) . '`' ) : '' ),
|
||||
$expiryMsg )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
@@ -222,7 +222,7 @@ 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();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
@@ -246,7 +246,7 @@ class DiscordHooks {
|
||||
$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(),
|
||||
@@ -271,7 +271,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 ) . '`' ) : '' ) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ class DiscordHooks {
|
||||
|
||||
$msg = wfMessage( 'discord-fileundeletecomplete', DiscordUtils::createUserLinks( $user ),
|
||||
DiscordUtils::createMarkdownLink( $title, $title->getFullUrl( '', '', $proto = PROTO_HTTP ) ),
|
||||
( $reason ? ('`' . $reason . '`' ) : '' ) )->text();
|
||||
( $reason ? ('`' . DiscordUtils::truncateText( $reason ) . '`' ) : '' ) )->text();
|
||||
DiscordUtils::handleDiscord($msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
+15
-1
@@ -162,7 +162,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