mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-23 22:44:42 +00:00
Merge "Namespace extension"
This commit is contained in:
commit
af5711bf3f
|
@ -29,7 +29,7 @@
|
|||
}
|
||||
},
|
||||
"SpecialPages": {
|
||||
"Thanks": "SpecialThanks"
|
||||
"Thanks": "MediaWiki\\Extension\\Thanks\\SpecialThanks"
|
||||
},
|
||||
"LogTypes": [
|
||||
"thanks"
|
||||
|
@ -38,10 +38,10 @@
|
|||
"thanks": true
|
||||
},
|
||||
"LogActionsHandlers": {
|
||||
"thanks/*": "ThanksLogFormatter"
|
||||
"thanks/*": "MediaWiki\\Extension\\Thanks\\ThanksLogFormatter"
|
||||
},
|
||||
"APIModules": {
|
||||
"thank": "ApiCoreThank"
|
||||
"thank": "MediaWiki\\Extension\\Thanks\\ApiCoreThank"
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"Thanks": [
|
||||
|
@ -52,15 +52,8 @@
|
|||
"ExtensionMessagesFiles": {
|
||||
"ThanksAlias": "Thanks.alias.php"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"ThanksHooks": "includes/ThanksHooks.php",
|
||||
"EchoCoreThanksPresentationModel": "includes/EchoCoreThanksPresentationModel.php",
|
||||
"EchoFlowThanksPresentationModel": "includes/EchoFlowThanksPresentationModel.php",
|
||||
"ApiThank": "includes/ApiThank.php",
|
||||
"ApiCoreThank": "includes/ApiCoreThank.php",
|
||||
"ApiFlowThank": "includes/ApiFlowThank.php",
|
||||
"ThanksLogFormatter": "includes/ThanksLogFormatter.php",
|
||||
"SpecialThanks": "includes/SpecialThanks.php"
|
||||
"AutoloadNamespaces": {
|
||||
"MediaWiki\\Extension\\Thanks\\": "includes/"
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.thanks.images": {
|
||||
|
@ -172,19 +165,19 @@
|
|||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"ApiMain::moduleManager": "ThanksHooks::onApiMainModuleManager",
|
||||
"BeforeCreateEchoEvent": "ThanksHooks::onBeforeCreateEchoEvent",
|
||||
"BeforePageDisplay": "ThanksHooks::onBeforePageDisplay",
|
||||
"BeforeSpecialMobileDiffDisplay": "ThanksHooks::onBeforeSpecialMobileDiffDisplay",
|
||||
"DiffTools": "ThanksHooks::insertThankLink",
|
||||
"DifferenceEngineViewHeader": "ThanksHooks::onDifferenceEngineViewHeader",
|
||||
"EchoGetBundleRules": "ThanksHooks::onEchoGetBundleRules",
|
||||
"EchoGetDefaultNotifiedUsers": "ThanksHooks::onEchoGetDefaultNotifiedUsers",
|
||||
"GetLogTypesOnUser": "ThanksHooks::onGetLogTypesOnUser",
|
||||
"HistoryTools": "ThanksHooks::insertThankLink",
|
||||
"LocalUserCreated": "ThanksHooks::onAccountCreated",
|
||||
"LogEventsListLineEnding": "ThanksHooks::onLogEventsListLineEnding",
|
||||
"PageHistoryBeforeList": "ThanksHooks::onPageHistoryBeforeList"
|
||||
"ApiMain::moduleManager": "MediaWiki\\Extension\\Thanks\\Hooks::onApiMainModuleManager",
|
||||
"BeforeCreateEchoEvent": "MediaWiki\\Extension\\Thanks\\Hooks::onBeforeCreateEchoEvent",
|
||||
"BeforePageDisplay": "MediaWiki\\Extension\\Thanks\\Hooks::onBeforePageDisplay",
|
||||
"BeforeSpecialMobileDiffDisplay": "MediaWiki\\Extension\\Thanks\\Hooks::onBeforeSpecialMobileDiffDisplay",
|
||||
"DiffTools": "MediaWiki\\Extension\\Thanks\\Hooks::insertThankLink",
|
||||
"DifferenceEngineViewHeader": "MediaWiki\\Extension\\Thanks\\Hooks::onDifferenceEngineViewHeader",
|
||||
"EchoGetBundleRules": "MediaWiki\\Extension\\Thanks\\Hooks::onEchoGetBundleRules",
|
||||
"EchoGetDefaultNotifiedUsers": "MediaWiki\\Extension\\Thanks\\Hooks::onEchoGetDefaultNotifiedUsers",
|
||||
"GetLogTypesOnUser": "MediaWiki\\Extension\\Thanks\\Hooks::onGetLogTypesOnUser",
|
||||
"HistoryTools": "MediaWiki\\Extension\\Thanks\\Hooks::insertThankLink",
|
||||
"LocalUserCreated": "MediaWiki\\Extension\\Thanks\\Hooks::onAccountCreated",
|
||||
"LogEventsListLineEnding": "MediaWiki\\Extension\\Thanks\\Hooks::onLogEventsListLineEnding",
|
||||
"PageHistoryBeforeList": "MediaWiki\\Extension\\Thanks\\Hooks::onPageHistoryBeforeList"
|
||||
},
|
||||
"config": {
|
||||
"ThanksSendToBots": {
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use ApiBase;
|
||||
use DatabaseLogEntry;
|
||||
use EchoDiscussionParser;
|
||||
use EchoEvent;
|
||||
use LogEntry;
|
||||
use LogicException;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* API module to send thanks notifications for revisions and log entries.
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use ApiBase;
|
||||
use EchoEvent;
|
||||
use Flow\Container;
|
||||
use Flow\Conversion\Utils;
|
||||
use Flow\Exception\FlowException;
|
||||
use Flow\Model\PostRevision;
|
||||
use Flow\Model\UUID;
|
||||
use MWException;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* API module to send Flow thanks notifications
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use ActorMigration;
|
||||
use ApiBase;
|
||||
use ExtensionRegistry;
|
||||
use ManualLogEntry;
|
||||
use MediaWiki\CheckUser\Hooks;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Base API module for Thanks
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use DatabaseLogEntry;
|
||||
use EchoEventPresentationModel;
|
||||
use Linker;
|
||||
use LogEntry;
|
||||
use LogFormatter;
|
||||
use LogPage;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use RawMessage;
|
||||
use Sanitizer;
|
||||
use SpecialPage;
|
||||
|
||||
class EchoCoreThanksPresentationModel extends EchoEventPresentationModel {
|
||||
/** @var LogEntry|bool|null */
|
||||
|
@ -91,8 +102,7 @@ class EchoCoreThanksPresentationModel extends EchoEventPresentationModel {
|
|||
$excerpt = $formatter->getPlainActionText();
|
||||
// Turn wikitext into plaintext
|
||||
$excerpt = Linker::formatComment( $excerpt );
|
||||
$excerpt = Sanitizer::stripAllTags( $excerpt );
|
||||
return $excerpt;
|
||||
return Sanitizer::stripAllTags( $excerpt );
|
||||
} else {
|
||||
// Try to get edit summary.
|
||||
$summary = $this->getRevisionEditSummary();
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
|
||||
class EchoFlowThanksPresentationModel extends Flow\Notifications\FlowPresentationModel {
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use Flow\Notifications\FlowPresentationModel;
|
||||
use RawMessage;
|
||||
use Title;
|
||||
|
||||
class EchoFlowThanksPresentationModel extends FlowPresentationModel {
|
||||
public function canRender() {
|
||||
return (bool)$this->event->getTitle();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use ApiModuleManager;
|
||||
use Article;
|
||||
use CategoryPage;
|
||||
use ConfigException;
|
||||
use DatabaseLogEntry;
|
||||
use DifferenceEngine;
|
||||
use EchoEvent;
|
||||
use ExtensionRegistry;
|
||||
use Html;
|
||||
use ImagePage;
|
||||
use LogEventsList;
|
||||
use LogPage;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MobileContext;
|
||||
use OutputPage;
|
||||
use RequestContext;
|
||||
use Skin;
|
||||
use SpecialPage;
|
||||
use Title;
|
||||
use User;
|
||||
use WikiPage;
|
||||
|
||||
/**
|
||||
* Hooks for Thanks extension
|
||||
|
@ -11,7 +33,7 @@ use MediaWiki\User\UserIdentity;
|
|||
* @file
|
||||
* @ingroup Extensions
|
||||
*/
|
||||
class ThanksHooks {
|
||||
class Hooks {
|
||||
|
||||
/**
|
||||
* Handler for HistoryTools and DiffTools hooks.
|
||||
|
@ -331,7 +353,7 @@ class ThanksHooks {
|
|||
$moduleManager->addModule(
|
||||
'flowthank',
|
||||
'action',
|
||||
'ApiFlowThank'
|
||||
ApiFlowThank::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +395,7 @@ class ThanksHooks {
|
|||
*
|
||||
* @link https://www.mediawiki.org/wiki/Manual:Hooks/LogEventsListLineEnding
|
||||
* @param LogEventsList $page The log events list.
|
||||
* @param string &$ret The lineending HTML, to modify.
|
||||
* @param string &$ret The line ending HTML, to modify.
|
||||
* @param DatabaseLogEntry $entry The log entry.
|
||||
* @param string[] &$classes CSS classes to add to the line.
|
||||
* @param string[] &$attribs HTML attributes to add to the line.
|
|
@ -1,5 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use ApiMain;
|
||||
use ApiUsageException;
|
||||
use DerivativeRequest;
|
||||
use FormSpecialPage;
|
||||
use HTMLForm;
|
||||
use Linker;
|
||||
use Status;
|
||||
use User;
|
||||
|
||||
class SpecialThanks extends FormSpecialPage {
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks;
|
||||
|
||||
use LogFormatter;
|
||||
use Message;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* This class formats log entries for thanks
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@ use MediaWiki\Revision\SlotRecord;
|
|||
/**
|
||||
* Integration tests for the Thanks API module
|
||||
*
|
||||
* @covers ApiCoreThank
|
||||
* @covers \MediaWiki\Extension\Thanks\ApiCoreThank
|
||||
*
|
||||
* @group Thanks
|
||||
* @group Database
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Block\DatabaseBlock;
|
||||
use MediaWiki\Extension\Thanks\ApiCoreThank;
|
||||
|
||||
/**
|
||||
* Unit tests for the Thanks API module
|
||||
|
@ -29,8 +30,8 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider provideDieOnBadUser
|
||||
* @covers ApiThank::dieOnBadUser
|
||||
* @covers ApiThank::dieOnSitewideBlockedUser
|
||||
* @covers \MediaWiki\Extension\Thanks\ApiThank::dieOnBadUser
|
||||
* @covers \MediaWiki\Extension\Thanks\ApiThank::dieOnSitewideBlockedUser
|
||||
*/
|
||||
public function testDieOnBadUser( $user, $dieMethod, $expectedError ) {
|
||||
$module = $this->getModule();
|
||||
|
@ -53,7 +54,7 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
$mockUser = $this->createMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->will( $this->returnValue( true ) );
|
||||
->willReturn( true );
|
||||
|
||||
$testCases[ 'anon' ] = [
|
||||
$mockUser,
|
||||
|
@ -64,10 +65,10 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
$mockUser = $this->createMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->will( $this->returnValue( false ) );
|
||||
->willReturn( false );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'pingLimiter' )
|
||||
->will( $this->returnValue( true ) );
|
||||
->willReturn( true );
|
||||
|
||||
$testCases[ 'ping' ] = [
|
||||
$mockUser,
|
||||
|
@ -78,18 +79,16 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
$mockUser = $this->createMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->will( $this->returnValue( false ) );
|
||||
->willReturn( false );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'pingLimiter' )
|
||||
->will( $this->returnValue( false ) );
|
||||
->willReturn( false );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isBlockedGlobally' )
|
||||
->will( $this->returnValue( true ) );
|
||||
->willReturn( true );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'getGlobalBlock' )
|
||||
->will( $this->returnValue(
|
||||
$this->createBlock( [] )
|
||||
) );
|
||||
->willReturn( $this->createBlock( [] ) );
|
||||
|
||||
$testCases[ 'globally blocked' ] = [
|
||||
$mockUser,
|
||||
|
@ -100,9 +99,7 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
$mockUser = $this->createMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'getBlock' )
|
||||
->will( $this->returnValue(
|
||||
$this->createBlock( [] )
|
||||
) );
|
||||
->willReturn( $this->createBlock( [] ) );
|
||||
|
||||
$testCases[ 'sitewide blocked' ] = [
|
||||
$mockUser,
|
||||
|
@ -113,11 +110,9 @@ class ApiCoreThankUnitTest extends MediaWikiTestCase {
|
|||
$mockUser = $this->createMock( 'User' );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'getBlock' )
|
||||
->will( $this->returnValue(
|
||||
$this->createBlock( [
|
||||
'sitewide' => false
|
||||
] )
|
||||
) );
|
||||
->willReturn(
|
||||
$this->createBlock( [ 'sitewide' => false ] )
|
||||
);
|
||||
|
||||
$testCases[ 'partial blocked' ] = [
|
||||
$mockUser,
|
||||
|
|
|
@ -8,7 +8,7 @@ use Flow\Model\Workflow;
|
|||
/**
|
||||
* Integration tests for the Thanks Flow api module
|
||||
*
|
||||
* @covers ApiFlowThank
|
||||
* @covers \MediaWiki\Extension\Thanks\ApiFlowThank
|
||||
*
|
||||
* @group Thanks
|
||||
* @group Database
|
||||
|
@ -67,9 +67,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
$that = $this;
|
||||
$mockLoader->expects( $this->any() )
|
||||
->method( 'getWithRoot' )
|
||||
->will( $this->returnCallback(
|
||||
// Hard to work with class variables or callbacks,
|
||||
// using anonymous function instead.
|
||||
->willReturnCallback(
|
||||
function ( $postId ) use ( $that ) {
|
||||
switch ( $postId ) {
|
||||
case $that->postByOtherUser->getPostId():
|
||||
|
@ -88,7 +86,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
return [ 'post' => null ];
|
||||
}
|
||||
}
|
||||
) );
|
||||
);
|
||||
|
||||
$mockWorkflow = $this->createMock( Workflow::class );
|
||||
$mockWorkflow->expects( $this->any() )
|
||||
|
@ -104,7 +102,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
|
||||
$mockStorage->expects( $this->any() )
|
||||
->method( 'get' )
|
||||
->will( $this->returnValue( $mockWorkflow ) );
|
||||
->willReturn( $mockWorkflow );
|
||||
|
||||
$mockTemplating = $this->getMockBuilder( 'Flow\Templating' )
|
||||
->disableOriginalConstructor()
|
||||
|
@ -112,7 +110,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
|
||||
$mockTemplating->expects( $this->any() )
|
||||
->method( 'getContent' )
|
||||
->will( $this->returnValue( 'test content' ) );
|
||||
->willReturn( 'test content' );
|
||||
|
||||
Flow\Container::reset();
|
||||
$container = Flow\Container::getContainer();
|
||||
|
@ -149,7 +147,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
public function testRequestWithInvalidId() {
|
||||
$this->expectException( ApiUsageException::class );
|
||||
$this->expectExceptionMessage( 'Post ID is not valid' );
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
$this->doApiRequestWithToken( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => UUID::create( '42' )->getAlphadecimal(),
|
||||
] );
|
||||
|
@ -158,7 +156,7 @@ class ApiFlowThankIntegrationTest extends ApiTestCase {
|
|||
public function testRequestWithOwnId() {
|
||||
$this->expectException( ApiUsageException::class );
|
||||
$this->expectExceptionMessage( 'You cannot thank yourself' );
|
||||
list( $result,, ) = $this->doApiRequestWithToken( [
|
||||
$this->doApiRequestWithToken( [
|
||||
'action' => 'flowthank',
|
||||
'postid' => $this->postByMe->getPostId()->getAlphadecimal(),
|
||||
], null, $this->meUser );
|
||||
|
|
Loading…
Reference in a new issue