Jforrester has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/295717

Change subject: Hooks: Replace deprecated APIEditBeforeSave with 
EditFilterMergedContent
......................................................................

Hooks: Replace deprecated APIEditBeforeSave with EditFilterMergedContent

Bug: T137832
Change-Id: I7b0e1d125b196379dd5bf26658ff642d32ba832a
---
M ProofreadPage.body.php
M extension.json
2 files changed, 35 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/17/295717/1

diff --git a/ProofreadPage.body.php b/ProofreadPage.body.php
index 53218ea..4109402 100644
--- a/ProofreadPage.body.php
+++ b/ProofreadPage.body.php
@@ -586,41 +586,56 @@
 
        /**
         * Make validation of the content in the edit API
-        * @param $editPage EditPage
-        * @param $text string
-        * @param $resultArr array
+        *
+        * @param $context Object implementing the IContextSource interface.
+        * @param $content Content of the edit box, as a Content object.
+        * @param $status  Status object to represent errors, etc.
+        * @param $summary  Edit summary for page
+        * @param $user  The User object representing the user whois performing 
the edit.
+        * @param $minoredit  Whether the edit was marked as minor by the user.
         * @return bool
         */
-       public static function onAPIEditBeforeSave( EditPage $editPage, $text, 
array &$resultArr ) {
-               if ( $editPage->contentModel !== CONTENT_MODEL_PROOFREAD_PAGE ) 
{
+       public static function onEditFilterMergedContent( IContextSource 
$context, Content $content,
+               Status $status, string $summary, User $user, boolean $minoredit 
) {
+
+               // If the content's model isn't ours, ignore this; there's 
nothing for us to do here.
+               if ( $content->contentModel !== CONTENT_MODEL_PROOFREAD_PAGE ) {
                        return true;
                }
 
                $contentHandler = ContentHandler::getForModelID( 
CONTENT_MODEL_PROOFREAD_PAGE );
-               $article = $editPage->getArticle();
-               $user = $article->getContext()->getUser();
-               $oldContent = $article->getPage()->getContent( 
Revision::FOR_THIS_USER, $user );
-               $newContent = $contentHandler->unserializeContent( $text, 
$editPage->contentFormat );
 
+               $oldContent = $context->getWikiPage()->getContent( 
Revision::FOR_THIS_USER, $user );
                if ( $oldContent === null ) {
                        $oldContent = $contentHandler->makeEmptyContent();
                }
-               $oldLevel = $oldContent->getLevel();
-               $newLevel = $newContent->getLevel();
 
-               if ( !$newContent->isValid() || $newLevel->getUser() === null 
&& $oldLevel->getUser() !== null ) {
-                       $resultArr['badpage'] = wfMessage( 
'proofreadpage_badpagetext' )->text();
+               $oldLevel = $oldContent->getLevel();
+               $newLevel = $content->getLevel();
+
+               // Fail if the content is invalid, or the level is being 
removed.
+               if (
+                       !$content->isValid() ||
+                       $newLevel->getUser() === null && $oldLevel->getUser() 
!== null
+               ) {
+                       $ourStatus = Status::newFatal( 
'proofreadpage_badpagetext' );
+                       $ourStatus->value = self::AS_HOOK_ERROR;
+                       $status->merge( $ourStatus );
                        return false;
                }
 
-               $oldLevel = $oldContent->getLevel();
-               $newLevel = $newContent->getLevel();
-               //if the user change the level, the change should be allowed 
and the new User should be the editing user
+               // Fail if the user changed the level, the change should be 
allowed and the new User should be the editing user
                if (
                        !$newLevel->equals( $oldLevel ) &&
-                       ( $newLevel->getUser() === null || 
$newLevel->getUser()->getName() !== $user->getName() || 
!$oldLevel->isChangeAllowed( $newLevel ) )
+                       (
+                               $newLevel->getUser() === null ||
+                               $newLevel->getUser()->getName() !== 
$user->getName() ||
+                               !$oldLevel->isChangeAllowed( $newLevel )
+                       )
                ) {
-                       $resultArr['notallowed'] = wfMessage( 
'proofreadpage_notallowedtext' )->text();
+                       $ourStatus = Status::newFatal( 
'proofreadpage_notallowedtext' );
+                       $ourStatus->value = self::AS_HOOK_ERROR;
+                       $status->merge( $ourStatus );
                        return false;
                }
 
diff --git a/extension.json b/extension.json
index d0f17c0..7769786 100644
--- a/extension.json
+++ b/extension.json
@@ -301,8 +301,8 @@
                "ContentHandlerDefaultModelFor": [
                        "ProofreadPage::onContentHandlerDefaultModelFor"
                ],
-               "APIEditBeforeSave": [
-                       "ProofreadPage::onAPIEditBeforeSave"
+               "EditFilterMergedContent": [
+                       "ProofreadPage::onEditFilterMergedContent"
                ],
                "EditFormPreloadText": [
                        "ProofreadPage::onEditFormPreloadText"

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b0e1d125b196379dd5bf26658ff642d32ba832a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>

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

Reply via email to