jenkins-bot has submitted this change and it was merged.

Change subject: Provide better URLs to IRC rcfeed
......................................................................


Provide better URLs to IRC rcfeed

Bug: 60559
Change-Id: Ieee69baa0c094603547e3bcee4c879d29f9fe4e2
---
M Flow.php
M Hooks.php
M container.php
M includes/Data/RecentChanges.php
A includes/Formatter/IRCLineUrlFormatter.php
M includes/Formatter/RevisionFormatter.php
A tests/HookTest.php
7 files changed, 280 insertions(+), 9 deletions(-)

Approvals:
  Bsitu: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Flow.php b/Flow.php
index 7758034..0e692c5 100755
--- a/Flow.php
+++ b/Flow.php
@@ -171,6 +171,7 @@
 $wgAutoloadClasses['Flow\Formatter\RecentChanges'] = $dir . 
'includes/Formatter/RecentChanges.php';
 $wgAutoloadClasses['Flow\Formatter\RecentChangesQuery'] = $dir . 
'includes/Formatter/RecentChangesQuery.php';
 $wgAutoloadClasses['Flow\Formatter\RecentChangesRow'] = $dir . 
'includes/Formatter/RecentChangesQuery.php';
+$wgAutoloadClasses['Flow\Formatter\IRCLineUrlFormatter'] = $dir . 
'includes/Formatter/IRCLineUrlFormatter.php';
 
 // Convert model instances into array of user-visible data
 $wgAutoloadClasses['Flow\Formatter\RevisionFormatter'] = $dir . 
'includes/Formatter/RevisionFormatter.php';
@@ -244,6 +245,7 @@
 $wgHooks['MakeGlobalVariablesScript'][] = 
'FlowHooks::onMakeGlobalVariablesScript';
 $wgHooks['CheckUserInsertForRecentChange'][] = 
'FlowHooks::onCheckUserInsertForRecentChange';
 $wgHooks['SkinMinervaDefaultModules'][] = 
'FlowHooks::onSkinMinervaDefaultModules';
+$wgHooks['IRCLineURL'][] = 'FlowHooks::onIRCLineURL';
 
 // Extension initialization
 $wgExtensionFunctions[] = 'FlowHooks::initFlowExtension';
diff --git a/Hooks.php b/Hooks.php
index daeaaa0..510650f 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -21,7 +21,7 @@
 
        /**
         * Initialized during extension initialization rather than
-        * in container so that non-flow pages don't  load the container.
+        * in container so that non-flow pages don't load the container.
         *
         * @return OccupationController
         */
@@ -40,7 +40,7 @@
 
        /**
         * Initialized during extension initialization rather than
-        * in container so that non-flow pages don't  load the container.
+        * in container so that non-flow pages don't load the container.
         *
         * @return AbuseFilter|null when disabled
         */
@@ -395,8 +395,8 @@
 
        /**
         * Adds Flow entries to watchlists
-        * @param  array &$types Type array to modify
-        * @return boolean       true
+        * @param array &$types Type array to modify
+        * @return boolean true
         */
        public static function onSpecialWatchlistGetNonRevisionTypes( &$types ) 
{
                $types[] = RC_FLOW;
@@ -609,4 +609,25 @@
 
                return true;
        }
+
+       public static function onIRCLineURL( &$url, &$query, RecentChange $rc ) 
{
+               if ( $rc->getAttribute( 'rc_source' ) !== 
Flow\Data\RecentChanges::SRC_FLOW ) {
+                       return true;
+               }
+
+               $result = null;
+               try {
+                       $result = Container::get( 'formatter.irclineurl' 
)->format( $rc );
+               } catch ( FlowException $e ) {
+                       wfDebugLog( 'Flow', __METHOD__ . ': Failed formatting 
rc ' . $rc->getAttribute( 'rc_id' ) );
+                       \MWExceptionHandler::logException( $e );
+               }
+
+               if ( $result !== null ) {
+                       $url = $result;
+                       $query = '';
+               }
+
+               return true;
+       }
 }
diff --git a/container.php b/container.php
index c4507e1..ce1e5b8 100644
--- a/container.php
+++ b/container.php
@@ -594,6 +594,14 @@
                $c['repository.tree']
        );
 } );
+
+$c['formatter.irclineurl'] = $c->share( function( $c ) {
+       return new Flow\Formatter\IRCLineUrlFormatter(
+               $c['permissions'],
+               $c['templating']
+       );
+} );
+
 $c['formatter.checkuser'] = $c->share( function( $c ) {
        return new Flow\Formatter\CheckUser(
                $c['permissions'],
diff --git a/includes/Data/RecentChanges.php b/includes/Data/RecentChanges.php
index 04fe8d7..62189d2 100644
--- a/includes/Data/RecentChanges.php
+++ b/includes/Data/RecentChanges.php
@@ -100,6 +100,9 @@
                                        'revision' => $revisionId,
                                        'workflow' => 
$workflow->getId()->getAlphadecimal(),
                                        'definition' => 
$workflow->getDefinitionId()->getAlphadecimal(),
+                                       'prev_revision' => 
$revision->isFirstRevision()
+                                               ? null
+                                               : 
$revision->getPrevRevision()->getAlphadecimal()
                                ) + $changes,
                        ) ),
                        'rc_cur_id' => 0,
diff --git a/includes/Formatter/IRCLineUrlFormatter.php 
b/includes/Formatter/IRCLineUrlFormatter.php
new file mode 100644
index 0000000..ba3328c
--- /dev/null
+++ b/includes/Formatter/IRCLineUrlFormatter.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Flow\Formatter;
+
+use Flow\Model\PostRevision;
+use Flow\Model\UUID;
+use Flow\Model\Workflow;
+use RecentChange;
+
+/**
+ * Generates URL's to be inserted into the IRC
+ * recent changes feed.
+ */
+class IRCLineUrlFormatter extends AbstractFormatter {
+
+       /**
+        * @param RecentChange $rc
+        * @return string|null
+        */
+       public function format( RecentChange $rc ) {
+
+               $encoded = $rc->getAttribute( 'rc_params' );
+               if ( !$encoded ) {
+                       wfDebugLog( 'Flow', __METHOD__ . 'Something something' 
);
+                       die( 'no rc_params' );
+                       return null;
+               }
+               $params = unserialize( $encoded );
+               if ( !isset( $params['flow-workflow-change'] ) ) {
+                       wfDebugLog( 'Flow', __METHOD__ . 'Something something' 
);
+                       die( 'no flow-workflow-change' );
+                       return null;
+               }
+               $change = $params['flow-workflow-change'];
+
+               // The rc has all data necessary to render the links
+               // we need, fetching the data models would be more
+               // work than necessary. We suppress/restore the warnings
+               // since we arn't creating the real full data models
+               $row = new FormatterRow;
+               wfSuppressWarnings();
+               $row->revision = $this->mockRevision( $rc, $change );
+               $row->currentRevision = $row->revision;
+               $row->workflow = $this->mockWorkflow( $rc, $change );
+               wfRestoreWarnings();
+               $links = $this->serializer->buildActionLinks( $row );
+
+               // Listed in order of preference
+               $accept = array(
+                       'diff',
+                       'post-history', 'topic-history', 'board-history',
+                       'post', 'topic',
+                       'workflow'
+               );
+
+               foreach ( $accept as $key ) {
+                       if ( isset( $links[$key] ) ) {
+                               return $links[$key][0];
+                       }
+               }
+
+               var_dump( $links );die( 'no links generated' );
+
+               wfDebugLog( 'Flow', __METHOD__
+                               . ': No url generated for action ' . 
$change['action']
+                               . ' on revision ' . $change['revision']
+               );
+               return null;
+       }
+
+       protected function mockRevision( RecentChange $rc, array $change ) {
+               // the exact revision type doesn't currently matter
+               // but when it does
+               switch( $change['revision_type'] ) {
+               case 'PostRevision':
+                       $class = 'Flow\\Model\\PostRevision';
+                       $row = array(
+                               'rev_type_id' => $change['post'],
+                               'tree_rev_id' => $change['revision'],
+                       );
+                       break;
+
+               case 'Header':
+                       $class = 'Flow\\Model\\Header';
+                       $row = array( 'rev_type_id' => $change['workflow'] );
+                       break;
+
+               case 'Summary':
+                       $class = 'Flow\\Model\\Summary';
+                       $row = array( 'rev_type_id' => $change['something'] );
+                       break;
+
+               default:
+                       throw new FlowException( 'Unknown revision type in 
recent change row ' . $rc->getAttribute( 'rc_id' ) );
+               }
+
+               return $class::fromStorageRow( $row + array(
+                       'rev_id' => $change['revision'],
+                       'rev_change_type' => $change['action'],
+                       'rev_parent_id' => $change['prev_revision'],
+               ) );
+       }
+
+       protected function mockWorkflow( RecentChange $rc, array $change ) {
+               return Workflow::fromStorageRow( array(
+                       'workflow_id' => $change['workflow'],
+                       'workflow_title_text' => $rc->getAttribute( 'rc_title' 
),
+                       'workflow_namespace' => $rc->getAttribute( 
'rc_namespace' ),
+                       'workflow_wiki' => wfWikiId(),
+               ) );
+       }
+}
diff --git a/includes/Formatter/RevisionFormatter.php 
b/includes/Formatter/RevisionFormatter.php
index 098a986..26ce19f 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -274,7 +274,6 @@
                                                        array(
                                                                'workflow' => 
$workflowId->getAlphadecimal(),
                                                                
'header_newRevision' => $revId->getAlphadecimal(),
-                                                               
'header_oldRevision' => $row->revision->getPrevRevisionId()->getAlphadecimal(),
                                                        )
                                                ),
                                                wfMessage( 'diff' )
@@ -302,11 +301,11 @@
                                        $links['diff-cur'] = array(
                                                $this->urlGenerator->buildUrl(
                                                        $title,
-                                                       
'compare-post-revisions',
+                                                       
'compare-header-revisions',
                                                        array(
                                                                'workflow' => 
$workflowId->getAlphadecimal(),
-                                                               
'topic_newRevision' => $cur->getRevisionId()->getAlphadecimal(),
-                                                               
'topic_oldRevision' => $revId->getAlphadecimal(),
+                                                               
'header_newRevision' => $cur->getRevisionId()->getAlphadecimal(),
+                                                               
'header_oldRevision' => $revId->getAlphadecimal(),
                                                        )
                                                ),
                                                wfMessage( 'cur' )
@@ -331,7 +330,6 @@
                                                        array(
                                                                'workflow' => 
$workflowId->getAlphadecimal(),
                                                                
'topic_newRevision' => $revId->getAlphadecimal(),
-                                                               
'topic_oldRevision' => $row->revision->getPrevRevisionId()->getAlphadecimal(),
                                                        )
                                                ),
                                                wfMessage( 'diff' )
diff --git a/tests/HookTest.php b/tests/HookTest.php
new file mode 100644
index 0000000..1a6a204
--- /dev/null
+++ b/tests/HookTest.php
@@ -0,0 +1,127 @@
+<?php
+
+namespace Flow\Tests;
+
+use FlowHooks;
+use Flow\Model\UUID;
+use RecentChange;
+
+class HookTest extends \MediaWikiTestCase {
+       static public function onIRCLineURLProvider() {
+               // specific uuid's dont mean anything, just repeatability
+               $workflowAlpha = 'rs2l7n89pmch81qy';
+               $postAlpha = 'rs2l7n8ctv7rwf6i';
+               $topicAlpha = 'rs2l7n8dra7r9a22';
+               $revisionAlpha = 'rs2l7n89ab7rdd0f';
+               $prevRevisionAlpha = 'rs2l7k73abd02ee2';
+
+               $basicPost = array(
+                       'block' => 'topic',
+                       'revision_type' => 'PostRevision',
+                       'revision' => $revisionAlpha,
+                       'prev_revision' => $prevRevisionAlpha,
+                       'workflow' => $workflowAlpha,
+                       'post' => $postAlpha,
+                       'topic' => $topicAlpha,
+               );
+
+               $basicHeader = array(
+                       'block' => 'header',
+                       'revision_type' => 'Header',
+                       'revision' => $revisionAlpha,
+                       'prev_revision' => $prevRevisionAlpha,
+                       'workflow' => $workflowAlpha,
+                       'content' => 'foo bar baz...',
+               );
+
+               return array(
+                       array(
+                               // test message
+                               'Freshly created topic',
+                               // flow-workflow-change attribute within 
rc_params
+                               $basicPost + array(
+                                       'action' => 'new-post',
+                               ),
+                               // expected url
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&action=history',
+                               // expected query
+                               ''
+                       ),
+
+                       array(
+                               'Reply to topic',
+                               $basicPost + array(
+                                       'action' => 'reply',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&action=history',
+                               '',
+                       ),
+
+                       array(
+                               'Edit topic title',
+                               $basicPost + array(
+                                       'action' => 'edit-title',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&topic_newRevision=rs2l7n89ab7rdd0f&action=compare-post-revisions',
+                               '',
+                       ),
+
+                       array(
+                               'Edit post',
+                               $basicPost + array(
+                                       'action' => 'edit-post',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&topic_newRevision=rs2l7n89ab7rdd0f&action=compare-post-revisions',
+                               '',
+                       ),
+
+                       array(
+                               'Edit board header',
+                               $basicHeader + array(
+                                       'action' => 'edit-header',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&header_newRevision=rs2l7n89ab7rdd0f&action=compare-header-revisions',
+                               '',
+                       ),
+
+                       array(
+                               'Moderate a post',
+                               $basicPost + array(
+                                       'action' => 'delete-post',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&topic_postId=rs2l7n8ctv7rwf6i&action=history',
+                               '',
+                       ),
+
+                       array(
+                               'Moderate a topic',
+                               $basicPost + array(
+                                       'action' => 'hide-topic',
+                               ),
+                               
'?title=Main_Page&workflow=rs2l7n89pmch81qy&topic_postId=rs2l7n8ctv7rwf6i&action=history',
+                               '',
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider onIRCLineUrlProvider
+        */
+       public function testOnIRCLineUrl( $message, array $change, 
$expectedUrl, $expectedQuery ) {
+               $rc = new RecentChange;
+               $rc->mAttribs = array(
+                       'rc_namespace' => 0,
+                       'rc_title' => 'Main Page',
+                       'rc_source' => \Flow\Data\RecentChanges::SRC_FLOW,
+                       'rc_params' => serialize( array(
+                               'flow-workflow-change' => $change
+                       ) ),
+               );
+               $url = 'unset';
+               $query = 'unset';
+               $this->assertTrue( FlowHooks::onIRCLineURL( $url, $query, $rc ) 
);
+
+               $this->assertStringEndsWith( $expectedUrl, $url, $message );
+               $this->assertEquals( $expectedQuery, $query, $message );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/123114
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieee69baa0c094603547e3bcee4c879d29f9fe4e2
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Werdna <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to