Replace NewRevisionFromEditComplete with RevisionFromEditComplete

Bug: T250338
Change-Id: I4ef249d013d1a9bc33d1d0f380c41963635012ab
This commit is contained in:
DannyS712 2020-04-16 01:52:24 +00:00
parent 444d140e04
commit 77e2dd7169
9 changed files with 102 additions and 14 deletions

View file

@ -706,8 +706,10 @@ because of Phabricator reports.
use the RecentChange_save hook or similar instead.
* The ArticleEditUpdates hook has been deprecated. Please
use the RevisionDataUpdates hook or similar instead.
* The ArticleRevisionUndeleted has been hard deprecated. Please use the new
RevisionUndeleted hook instead.
* The ArticleRevisionUndeleted hook has been hard deprecated. Please use the
new RevisionUndeleted hook instead.
* The NewRevisionFromEditComplete hook has been soft deprecated. Please use
the new RevisionFromEditComplete hook instead.
* LinkHolderArray has been deprecated for public usage and will be
internal part of parser.
* ResourceLoaderFileModule::compileLessFile() has been deprecated, use

View file

@ -2369,8 +2369,8 @@ $row: the database row for this page (the recentchanges record and a few extras
Currently only data attributes reserved to MediaWiki are allowed
(see Sanitizer::isReservedDataAttribute).
'NewRevisionFromEditComplete': Called when a revision was inserted due to an
edit, file upload, import or page move.
'NewRevisionFromEditComplete': DEPRECATED since 1.35! Use RevisionFromEditComplete
Called when a revision was inserted due to an edit, file upload, import or page move.
$wikiPage: the WikiPage edited
$rev: the new revision
$originalRevId: if the edit restores or repeats an earlier revision (such as a
@ -2895,6 +2895,17 @@ $renderedRevision: a RenderedRevision object representing the new revision and p
to the RevisionRecord as well as ParserOutput of that revision.
&$updates: A list of DeferrableUpdate that can be manipulated by the hook handler.
'RevisionFromEditComplete': Called when a revision was inserted due to an edit,
file upload, import or page move.
$wikiPage: the WikiPage edited
$revRecord: the new RevisionRecord object
$originalRevId: if the edit restores or repeats an earlier revision (such as a
rollback or a null revision), the ID of that earlier revision. False otherwise.
(Used to be called $baseID.)
$user: UserIdentity representing the editing user
&$tags: tags to apply to the edit and recent change. This is empty, and
replacement is ignored, in the case of import or page move.
'RevisionRecordInserted': Called after a revision is inserted into the database.
$revisionRecord: the RevisionRecord that has just been inserted.

View file

@ -869,6 +869,11 @@ class MovePage {
// TODO cleanup hooks and use of $nullRevisionObj
$nullRevisionObj = new Revision( $nullRevision );
$fakeTags = [];
Hooks::run( 'RevisionFromEditComplete',
[ $newpage, $nullRevision, $nullRevision->getParentId(), $user, &$fakeTags ] );
// TODO hard deprecate hook
$nullRevisionObj = new Revision( $nullRevision );
Hooks::run( 'NewRevisionFromEditComplete',
[ $newpage, $nullRevisionObj, $nullRevision->getParentId(), $user, &$fakeTags ] );
@ -898,9 +903,17 @@ class MovePage {
$redirectRevId = $inserted->getId();
$redirectArticle->updateRevisionOn( $dbw, $inserted, 0 );
// TODO replace hook with one using RevisionRecord
$redirectRevisionObj = new Revision( $inserted );
$fakeTags = [];
Hooks::run( 'RevisionFromEditComplete', [
$redirectArticle,
$inserted,
false,
$user,
&$fakeTags
] );
// TODO hard deprecate hook
$redirectRevisionObj = new Revision( $inserted );
Hooks::run( 'NewRevisionFromEditComplete',
[ $redirectArticle, $redirectRevisionObj, false, $user, &$fakeTags ] );

View file

@ -1033,9 +1033,14 @@ class PageUpdater {
throw new PageUpdateException( "Failed to update page row to use new revision." );
}
$tags = $this->computeEffectiveTags( $flags );
Hooks::run(
'RevisionFromEditComplete',
[ $wikiPage, $newRevisionRecord, $this->getOriginalRevisionId(), $user, &$tags ]
);
// TODO: replace legacy hook!
$newLegacyRevision = new Revision( $newRevisionRecord );
$tags = $this->computeEffectiveTags( $flags );
Hooks::run(
'NewRevisionFromEditComplete',
[ $wikiPage, $newLegacyRevision, $this->getOriginalRevisionId(), $user, &$tags ]
@ -1167,9 +1172,14 @@ class PageUpdater {
throw new PageUpdateException( "Failed to update page row to use new revision." );
}
$tags = $this->computeEffectiveTags( $flags );
Hooks::run(
'RevisionFromEditComplete',
[ $wikiPage, $newRevisionRecord, false, $user, &$tags ]
);
// TODO: replace legacy hook!
$newLegacyRevision = new Revision( $newRevisionRecord );
$tags = $this->computeEffectiveTags( $flags );
Hooks::run(
'NewRevisionFromEditComplete',
[ $wikiPage, $newLegacyRevision, false, $user, &$tags ]

View file

@ -1646,7 +1646,18 @@ class LocalFile extends File {
if ( $nullRevRecord ) {
$inserted = $revStore->insertRevisionOn( $nullRevRecord, $dbw );
// TODO replace hook
Hooks::run(
'RevisionFromEditComplete',
[
$wikiPage,
$inserted,
$inserted->getParentId(),
$user,
&$tags
]
);
// TODO hard deprecate
$nullRevision = new Revision( $inserted );
Hooks::run(
'NewRevisionFromEditComplete',

View file

@ -7,7 +7,7 @@ use User;
use WikiPage;
/**
* @stable for implementation
* @deprecated since 1.35, use the RevisionFromEditComplete hook instead
* @ingroup Hooks
*/
interface NewRevisionFromEditCompleteHook {

View file

@ -0,0 +1,33 @@
<?php
namespace MediaWiki\Page\Hook;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\User\UserIdentity;
use WikiPage;
/**
* @stable for implementation
* @ingroup Hooks
*/
interface RevisionFromEditCompleteHook {
/**
* This hook is called when a revision was inserted due to an edit,
* file upload, import or page move.
*
* @since 1.35
*
* @param WikiPage $wikiPage WikiPage edited
* @param RevisionRecord $rev New revision
* @param int|bool $originalRevId If the edit restores or repeats an earlier revision (such as a
* rollback or a null revision), the ID of that earlier revision. False otherwise.
* (Used to be called $baseID.)
* @param UserIdentity $user Editing user
* @param string[] &$tags Tags to apply to the edit and recent change. This is empty, and
* replacement is ignored, in the case of import or page move.
* @return bool|void True or no return value to continue or false to abort
*/
public function onRevisionFromEditComplete( $wikiPage, $rev, $originalRevId,
$user, &$tags
);
}

View file

@ -2382,13 +2382,16 @@ class WikiPage implements Page, IDBAccessObject {
__METHOD__
);
// Avoid PHP 7.1 warning of passing $this by reference
$wikiPage = $this;
Hooks::run( 'RevisionFromEditComplete',
[ $this, $nullRevisionRecord, $latest, $user, &$tags ] );
// TODO replace hook with one using RevisionRecord
// TODO hard deprecate
$nullRevision = new Revision( $nullRevisionRecord );
Hooks::run( 'NewRevisionFromEditComplete',
[ $this, $nullRevision, $latest, $user, &$tags ] );
// Avoid PHP 7.1 warning of passing $this by reference
$wikiPage = $this;
Hooks::run( 'ArticleProtectComplete', [ &$wikiPage, &$user, $limit, $reason ] );
} else { // Protection of non-existing page (also known as "title protection")
// Cascade protection is meaningless in this case

View file

@ -152,8 +152,13 @@ class ImportReporter extends ContextSource {
// Update page record
$page->updateRevisionOn( $dbw, $inserted );
// TODO replace hook
$fakeTags = [];
Hooks::run(
'RevisionFromEditComplete',
[ $page, $inserted, $latest, $this->getUser(), &$fakeTags ]
);
// TODO hard deprecate old hook
$nullRevision = new Revision( $inserted );
Hooks::run(
'NewRevisionFromEditComplete',