jenkins-bot has submitted this change and it was merged. Change subject: New-topic recentchanges must use the board title ......................................................................
New-topic recentchanges must use the board title Currently watchlisting a board does not give you entries for new topics on that board, they are being inserted against the topic. The patch adds a new option, 'rc_title', that allows the action configuration to toggle between using the owner or article title as the recent change source. Change-Id: Id60c6d7b05650ac12567626083814bf6526575c1 --- M FlowActions.php M autoload.php M container.php M includes/Data/RecentChanges/HeaderRecentChanges.php M includes/Data/RecentChanges/PostRevisionRecentChanges.php M includes/Data/RecentChanges/PostSummaryRecentChanges.php A includes/Data/RecentChanges/RecentChangeFactory.php M includes/Data/RecentChanges/RecentChanges.php A tests/phpunit/Data/RecentChanges/RecentChangesTest.php 9 files changed, 158 insertions(+), 10 deletions(-) Approvals: Matthias Mullie: Looks good to me, approved jenkins-bot: Verified diff --git a/FlowActions.php b/FlowActions.php index 012009d..8b7a45a 100644 --- a/FlowActions.php +++ b/FlowActions.php @@ -29,6 +29,11 @@ * * bundle: array with, again, all of the above information if multiple types * should be bundled (then the bundle i18n & class will be used to generate * the list-item; clicking on it will reveal the individual history entries) + * * watch: Used by the WatchTopicListener to auto-subscribe users to topics. Only + * value value currently is immediate. + * * immediate: watchlist the title in the current process + * * rc_title: Either 'article' or 'owner' to select between Workflow::getArticleTitle + * or Workflow::getOwnerTitle being used as the related recentchanges entry on insert */ $wgFlowActions = array( 'create-header' => array( @@ -150,6 +155,7 @@ 'performs-writes' => true, 'log_type' => false, 'rc_insert' => true, + 'rc_title' => 'owner', 'permissions' => array( PostRevision::MODERATED_NONE => '', ), diff --git a/autoload.php b/autoload.php index 35a6e09..836b397 100644 --- a/autoload.php +++ b/autoload.php @@ -97,6 +97,7 @@ $wgAutoloadClasses['Flow\\Data\\RecentChanges\\HeaderRecentChanges'] = __DIR__ . '/includes/Data/RecentChanges/HeaderRecentChanges.php'; $wgAutoloadClasses['Flow\\Data\\RecentChanges\\PostRevisionRecentChanges'] = __DIR__ . '/includes/Data/RecentChanges/PostRevisionRecentChanges.php'; $wgAutoloadClasses['Flow\\Data\\RecentChanges\\PostSummaryRecentChanges'] = __DIR__ . '/includes/Data/RecentChanges/PostSummaryRecentChanges.php'; +$wgAutoloadClasses['Flow\\Data\\RecentChanges\\RecentChangeFactory'] = __DIR__ . '/includes/Data/RecentChanges/RecentChangeFactory.php'; $wgAutoloadClasses['Flow\\Data\\RecentChanges\\RecentChanges'] = __DIR__ . '/includes/Data/RecentChanges/RecentChanges.php'; $wgAutoloadClasses['Flow\\Data\\Storage\\BasicDbStorage'] = __DIR__ . '/includes/Data/Storage/BasicDbStorage.php'; $wgAutoloadClasses['Flow\\Data\\Storage\\BoardHistoryStorage'] = __DIR__ . '/includes/Data/Storage/BoardHistoryStorage.php'; @@ -227,9 +228,13 @@ $wgAutoloadClasses['Flow\\Tests\\Data\\FlowNothingTest'] = __DIR__ . '/tests/phpunit/Data/NothingTest.php'; $wgAutoloadClasses['Flow\\Tests\\Data\\IndexTest'] = __DIR__ . '/tests/phpunit/Data/IndexTest.php'; $wgAutoloadClasses['Flow\\Tests\\Data\\ObjectLocatorTest'] = __DIR__ . '/tests/phpunit/Data/ObjectLocatorTest.php'; +$wgAutoloadClasses['Flow\\Tests\\Data\\Pager\\PagerTest'] = __DIR__ . '/tests/phpunit/Data/Pager/PagerTest.php'; +$wgAutoloadClasses['Flow\\Tests\\Data\\RecentChanges\\RecentChangesMock'] = __DIR__ . '/tests/phpunit/Data/RecentChanges/RecentChangesTest.php'; +$wgAutoloadClasses['Flow\\Tests\\Data\\RecentChanges\\RecentChangesTest'] = __DIR__ . '/tests/phpunit/Data/RecentChanges/RecentChangesTest.php'; $wgAutoloadClasses['Flow\\Tests\\Data\\RevisionStorageTest'] = __DIR__ . '/tests/phpunit/Data/RevisionStorageTest.php'; $wgAutoloadClasses['Flow\\Tests\\Data\\UserNameBatchTest'] = __DIR__ . '/tests/phpunit/Data/UserNameBatchTest.php'; $wgAutoloadClasses['Flow\\Tests\\Data\\UserNameListenerTest'] = __DIR__ . '/tests/phpunit/Data/UserNameListenerTest.php'; +$wgAutoloadClasses['Flow\\Tests\\FlowActionsTest'] = __DIR__ . '/tests/phpunit/FlowActionsTest.php'; $wgAutoloadClasses['Flow\\Tests\\FlowTestCase'] = __DIR__ . '/tests/phpunit/FlowTestCase.php'; $wgAutoloadClasses['Flow\\Tests\\Formatter\\FormatterTest'] = __DIR__ . '/tests/phpunit/Formatter/FormatterTest.php'; $wgAutoloadClasses['Flow\\Tests\\HookTest'] = __DIR__ . '/tests/phpunit/HookTest.php'; diff --git a/container.php b/container.php index 861ae2c..23050fa 100644 --- a/container.php +++ b/container.php @@ -237,6 +237,7 @@ new Flow\Data\RecentChanges\HeaderRecentChanges( $c['flow_actions'], $c['repository.username'], + new Flow\Data\RecentChanges\RecentChangeFactory, $wgContLang ) ), @@ -301,6 +302,7 @@ new Flow\Data\RecentChanges\PostSummaryRecentChanges( $c['flow_actions'], $c['repository.username'], + new Flow\Data\RecentChanges\RecentChangeFactory, $wgContLang ) ), @@ -409,6 +411,7 @@ new Flow\Data\RecentChanges\PostRevisionRecentChanges( $c['flow_actions'], $c['repository.username'], + new Flow\Data\RecentChanges\RecentChangeFactory, $wgContLang ) ), @@ -596,7 +599,6 @@ $wgFlowDefaultWorkflow ); } ); - // Initialized in FlowHooks to faciliate only loading the flow container // when flow is specifically requested to run. Extension initialization // must always happen before calling flow code. diff --git a/includes/Data/RecentChanges/HeaderRecentChanges.php b/includes/Data/RecentChanges/HeaderRecentChanges.php index 5a0aee4..dbda7bf 100644 --- a/includes/Data/RecentChanges/HeaderRecentChanges.php +++ b/includes/Data/RecentChanges/HeaderRecentChanges.php @@ -18,8 +18,13 @@ */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { - parent::__construct( $actions, $usernames ); + public function __construct( + FlowActions $actions, + UserNameBatch $usernames, + RecentChangeFactory $rcFactory, + Language $contLang + ) { + parent::__construct( $actions, $usernames, $rcFactory ); $this->contLang = $contLang; } diff --git a/includes/Data/RecentChanges/PostRevisionRecentChanges.php b/includes/Data/RecentChanges/PostRevisionRecentChanges.php index 4af3fde..c03e2b6 100644 --- a/includes/Data/RecentChanges/PostRevisionRecentChanges.php +++ b/includes/Data/RecentChanges/PostRevisionRecentChanges.php @@ -17,8 +17,13 @@ */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { - parent::__construct( $actions, $usernames ); + public function __construct( + FlowActions $actions, + UserNameBatch $usernames, + RecentChangeFactory $rcFactory, + Language $contLang + ) { + parent::__construct( $actions, $usernames, $rcFactory ); $this->contLang = $contLang; } diff --git a/includes/Data/RecentChanges/PostSummaryRecentChanges.php b/includes/Data/RecentChanges/PostSummaryRecentChanges.php index a27c2f1..cff4517 100644 --- a/includes/Data/RecentChanges/PostSummaryRecentChanges.php +++ b/includes/Data/RecentChanges/PostSummaryRecentChanges.php @@ -17,8 +17,13 @@ */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { - parent::__construct( $actions, $usernames ); + public function __construct( + FlowActions $actions, + UserNameBatch $usernames, + RecentChangeFactory $rcFactory, + Language $contLang + ) { + parent::__construct( $actions, $usernames, $rcFactory ); $this->contLang = $contLang; } diff --git a/includes/Data/RecentChanges/RecentChangeFactory.php b/includes/Data/RecentChanges/RecentChangeFactory.php new file mode 100644 index 0000000..3c09451 --- /dev/null +++ b/includes/Data/RecentChanges/RecentChangeFactory.php @@ -0,0 +1,13 @@ +<?php + +namespace Flow\Data\RecentChanges; + +/** + * Provides access to static methods of RecentChange so they + * can be swapped out during tests + */ +class RecentChangeFactory { + public function newFromRow( $obj ) { + return \RecentChange::newFromRow( $obj ); + } +} diff --git a/includes/Data/RecentChanges/RecentChanges.php b/includes/Data/RecentChanges/RecentChanges.php index 2278d67..313826b 100644 --- a/includes/Data/RecentChanges/RecentChanges.php +++ b/includes/Data/RecentChanges/RecentChanges.php @@ -39,10 +39,12 @@ /** * @param FlowActions $actions * @param UserNameBatch $usernames + * @param RecentChangeFactory $rcFactory Creates mw RecentChange instances */ - public function __construct( FlowActions $actions, UserNameBatch $usernames ) { + public function __construct( FlowActions $actions, UserNameBatch $usernames, RecentChangeFactory $rcFactory ) { $this->actions = $actions; $this->usernames = $usernames; + $this->rcFactory = $rcFactory; } public function onAfterUpdate( $object, array $old, array $new, array $metadata ) { @@ -76,7 +78,8 @@ return; } - $title = $workflow->getArticleTitle(); + $title = $this->getRcTitle( $workflow, $revision->getChangeType() ); + $collection = $revision->getCollection(); // get content of both this & the current revision @@ -120,7 +123,7 @@ 'rc_deleted' => 0, ); - $rc = RecentChange::newFromRow( (object)$attribs ); + $rc = $this->rcFactory->newFromRow( (object)$attribs ); $rc->save( /* $noudp = */ true ); // Insert into db $feeds = $wgRCFeeds; // Override the IRC formatter with our own formatter @@ -131,6 +134,14 @@ $rc->notifyRCFeeds( $feeds ); } + public function getRcTitle( Workflow $workflow, $action ) { + if ( $this->actions->getValue( $action, 'rc_title' ) === 'owner' ) { + return $workflow->getOwnerTitle(); + } else { + return $workflow->getArticleTitle(); + } + } + /** * @param AbstractRevision $revision * @param string $action diff --git a/tests/phpunit/Data/RecentChanges/RecentChangesTest.php b/tests/phpunit/Data/RecentChanges/RecentChangesTest.php new file mode 100644 index 0000000..713d94b --- /dev/null +++ b/tests/phpunit/Data/RecentChanges/RecentChangesTest.php @@ -0,0 +1,96 @@ +<?php + +namespace Flow\Tests\Data\RecentChanges; + +use Flow\Container; +use Flow\Data\RecentChanges\RecentChanges; +use Flow\Model\PostRevision; +use Flow\Model\Workflow; +use Title; +use User; + +class RecentChangesTest extends \MediaWikiTestCase { + + public function somethingProvider() { + return array( + array( + 'Newly created topic inserts as board', + // expect + NS_MAIN, + // something + function( $workflow ) { + return PostRevision::create( $workflow, 'blah blah' ); + } + ), + + array( + 'Replies go to the topic', + NS_TOPIC, + function( $workflow ) { + $first = PostRevision::create( $workflow, 'blah blah' ); + $user = $workflow->getUserTuple()->createUser(); + return $first->reply( $workflow, $user, 'fofofo' ); + }, + ), + ); + } + + /** + * @dataProvider somethingProvider + */ + public function testSomething( $message, $expect, $init ) { + $actions = Container::get( 'flow_actions' ); + $usernames = $this->getMockBuilder( 'Flow\Repository\UserNameBatch' ) + ->disableOriginalConstructor() + ->getMock(); + $rcFactory = $this->getMockBuilder( 'Flow\Data\RecentChanges\RecentChangeFactory' ) + ->disableOriginalConstructor() + ->getMock(); + + $rc = new RecentChangesMock( $actions, $usernames, $rcFactory ); + $change = $this->getMock( 'RecentChange' ); + $rcFactory->expects( $this->once() ) + ->method( 'newFromRow' ) + ->will( $this->returnCallback( function( $obj ) use ( &$ref, $change ) { + $ref = $obj; + return $change; + } ) ); + + $title = Title::newMainPage(); + $user = User::newFromName( '127.0.0.1', false ); + $workflow = Workflow::create( 'topic', $user, $title ); + + $revision = $init( $workflow ); + + $rc->onAfterInsert( $revision, array(), array( + 'workflow' => $workflow, + ) ); + $this->assertNotNull( $ref ); + $this->assertEquals( $expect, $ref->rc_namespace, $message ); + } +} + +class RecentChangesMock extends RecentChanges { + // Mock abuses metadata parameter to test parent class + public function onAfterInsert( $object, array $new, array $metadata ) { + $metadata += array( + 'block' => null, + 'revisionType' => null, + 'row' => array(), + 'workflow' => null, // @todo real workflow is required + 'changes' => array() + ); + + $this->insert( + $object, + $metadata['block'], + $metadata['revisionType'], + $metadata['row'] + array( + 'rev_user_id' => 0, + 'rev_user_ip' => '127.0.0.1', + ), + $metadata['workflow'], + $metadata['changes'] + ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/165316 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id60c6d7b05650ac12567626083814bf6526575c1 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: SG <shah...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits