Kaldari has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376773 )

Change subject: Switch from AlternateEdit hook to CustomEditor hook
......................................................................

Switch from AlternateEdit hook to CustomEditor hook

Bug: T173605
Change-Id: I4991a1cb88d64bd4e63fa932fb01d6b15cb3b0ee
---
M extension.json
M includes/Hooks.php
M includes/Workflow.php
M tests/phpunit/WorkflowTest.php
4 files changed, 16 insertions(+), 16 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleCreationWorkflow 
refs/changes/73/376773/1

diff --git a/extension.json b/extension.json
index 8309ffa..77506ea 100644
--- a/extension.json
+++ b/extension.json
@@ -10,7 +10,7 @@
                "MediaWiki": ">= 1.30.0-alpha"
        },
        "Hooks": {
-               "AlternateEdit": 
"ArticleCreationWorkflow\\Hooks::onAlternateEdit",
+               "CustomEditor": 
"ArticleCreationWorkflow\\Hooks::onCustomEditor",
                "ShowMissingArticle": 
"ArticleCreationWorkflow\\Hooks::onShowMissingArticle"
        },
        "AutoloadClasses": {
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 08e8b2d..60cc649 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -11,25 +11,26 @@
  */
 class Hooks {
        /**
-        * AlternateEdit hook handler
+        * CustomEditor hook handler
         * Redirects users attempting to create pages to the landing page, 
based on configuration
         *
-        * @see https://www.mediawiki.org/wiki/Manual:Hooks/AlternateEdit
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/CustomEditor
         *
-        * @param EditPage $editPage
+        * @param WikiPage|Article|Page $article The requested page
+        * @param User $user The user trying to load the editor
         * @return bool
         */
-       public static function onAlternateEdit( EditPage $editPage ) {
+       public static function onCustomEditor( $article, $user ) {
                $config = MediaWikiServices::getInstance()
                        ->getConfigFactory()
                        ->makeConfig( 'ArticleCreationWorkflow' );
                $workflow = new Workflow( $config );
 
-               if ( $workflow->shouldInterceptEditPage( $editPage ) ) {
-                       $title = $editPage->getTitle();
+               if ( $workflow->shouldInterceptEditPage( $article, $user ) ) {
+                       $title = $article->getTitle();
                        // If the landing page didn't exist, we wouldn't have 
intercepted.
                        $redirTo = $workflow->getLandingPageTitle();
-                       $output = $editPage->getContext()->getOutput();
+                       $output = $article->getContext()->getOutput();
                        $output->redirect( $redirTo->getFullURL(
                                [ 'page' => $title->getPrefixedText(), 'wprov' 
=> 'acww1' ]
                        ) );
diff --git a/includes/Workflow.php b/includes/Workflow.php
index c3b5365..9d2a3fc 100644
--- a/includes/Workflow.php
+++ b/includes/Workflow.php
@@ -34,12 +34,12 @@
        /**
         * Checks whether an attempt to edit a page should be intercepted and 
redirected to our workflow
         *
-        * @param EditPage $editPage
+        * @param WikiPage|Article|Page $article The requested page
+        * @param User $user The user trying to load the editor
         * @return bool
         */
-       public function shouldInterceptEditPage( EditPage $editPage ) {
-               $title = $editPage->getTitle();
-               $user = $editPage->getContext()->getUser();
+       public function shouldInterceptEditPage( $article, $user ) {
+               $title = $article->getTitle();
 
                $conditions = $this->config->get( 'ArticleCreationWorkflows' );
 
diff --git a/tests/phpunit/WorkflowTest.php b/tests/phpunit/WorkflowTest.php
index 6534373..e1c48ac 100644
--- a/tests/phpunit/WorkflowTest.php
+++ b/tests/phpunit/WorkflowTest.php
@@ -34,7 +34,6 @@
 
                $article = new Article( $title );
                $article->setContext( $context );
-               $editPage = new EditPage( $article );
                $config = new HashConfig( [ 'ArticleCreationWorkflows' => 
$settings ] );
 
                $landingPage = $this->getMock( Title::class, [ 'exists' ] );
@@ -42,7 +41,7 @@
                $workflow = $this->getMock( Workflow::class, [ 
'getLandingPageTitle' ], [ $config ] );
                $workflow->method( 'getLandingPageTitle' )->willReturn( 
$landingPage );
 
-               self::assertEquals( $expected, 
$workflow->shouldInterceptEditPage( $editPage ) );
+               self::assertEquals( $expected, 
$workflow->shouldInterceptEditPage( $article, $user ) );
        }
 
        public function provideShouldInterceptEditPage() {
@@ -84,7 +83,7 @@
 
        public function testLandingPageExistence() {
                $article = new Article( Title::newFromText( 'Test page' ) );
-               $editPage = new EditPage( $article );
+               $user = $this->getMock( 'User' );
                $config = new HashConfig( [
                        'ArticleCreationWorkflows' => [
                                [
@@ -99,7 +98,7 @@
                $workflow->method( 'getLandingPageTitle' )->willReturn( null );
 
                // Check that it doesn't intercept if the message is empty
-               self::assertEquals( false, $workflow->shouldInterceptEditPage( 
$editPage ) );
+               self::assertEquals( false, $workflow->shouldInterceptEditPage( 
$article, $user ) );
        }
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4991a1cb88d64bd4e63fa932fb01d6b15cb3b0ee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleCreationWorkflow
Gerrit-Branch: master
Gerrit-Owner: Kaldari <rkald...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to