Add PageSaveComplete hook to replace PageContent(Insert|Save)Complete

Bug: T250566
Change-Id: I8e515ad9d344cb31e59bcfc87a717ca2b93feee2
This commit is contained in:
DannyS712 2020-06-01 01:31:00 +00:00
parent 4e2897575a
commit 0e915c0b63
8 changed files with 77 additions and 7 deletions

View file

@ -1022,6 +1022,8 @@ because of Phabricator reports.
* WikiPage::$mLastRevision was changed from protected to private.
* The RevisionInsertComplete hook, soft deprecated in 1.31, now emits
deprecation warnings.
* The PageContentInsertComplete and PageContentSaveComplete hooks were
deprecated in favor of the new PageSaveComplete hook.
* RecentChange::markPatrolled was deprecated. Use ::doMarkPatrolled instead.
* The JobRunner class has been converted to a service class.
Direct construction is deprecated, use MediaWikiServices::getJobRunner.

View file

@ -2450,7 +2450,8 @@ $categories: associative array, keys are category names, values are category
[&]$out: OutputPage instance (object)
$parserOutput: parserOutput instance being added in $out
'PageContentInsertComplete': After a new article is created.
'PageContentInsertComplete': DEPRECATED since 1.35, use PageSaveComplete instead.
After a new article is created.
[&]$wikiPage: WikiPage created
[&]$user: User creating the article
$content: New content as a Content object
@ -2483,7 +2484,8 @@ $section: Previously the section number being edited. Currently unused, always n
[&]$status: StatusValue object for the hook handlers resulting status. Either set $status->fatal() or
return false to abort the save action.
'PageContentSaveComplete': After an article has been updated.
'PageContentSaveComplete': DEPRECATED since 1.35, use PageSaveComplete instead.
After an article has been updated.
[&]$wikiPage: WikiPage modified
[&]$user: User performing the modification
$content: New content, as a Content object

View file

@ -50,7 +50,9 @@ class DeprecatedHooks {
'LinkBegin' => [ 'deprecatedVersion' => '1.28' ],
'LinkEnd' => [ 'deprecatedVersion' => '1.28' ],
'NewRevisionFromEditComplete' => [ 'deprecatedVersion' => '1.35' ],
'PageContentInsertComplete' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
'PageContentSave' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
'PageContentSaveComplete' => [ 'deprecatedVersion' => '1.35', 'silent' => true ],
'ParserBeforeTidy' => [ 'deprecatedVersion' => '1.35' ],
'ParserFetchTemplate' => [ 'deprecatedVersion' => '1.35' ],
'ParserGetVariableValueVarCache' => [ 'deprecatedVersion' => '1.35' ],

View file

@ -525,6 +525,7 @@ class HookRunner implements
\MediaWiki\Storage\Hook\PageContentInsertCompleteHook,
\MediaWiki\Storage\Hook\PageContentSaveCompleteHook,
\MediaWiki\Storage\Hook\PageContentSaveHook,
\MediaWiki\Storage\Hook\PageSaveCompleteHook,
\MediaWiki\Storage\Hook\ParserOutputStashForEditHook,
\MediaWiki\Storage\Hook\RevisionDataUpdatesHook,
\MediaWiki\User\Hook\ConfirmEmailCompleteHook,
@ -2808,6 +2809,16 @@ class HookRunner implements
);
}
public function onPageSaveComplete( $wikiPage, $user, $summary, $flags,
$revisionRecord, $originalRevId, $undidRevId
) {
return $this->container->run(
'PageSaveComplete',
[ $wikiPage, $user, $summary, $flags, $revisionRecord,
$originalRevId, $undidRevId ]
);
}
public function onPageViewUpdates( $wikipage, $user ) {
return $this->container->run(
'PageViewUpdates',

View file

@ -8,7 +8,7 @@ use User;
use WikiPage;
/**
* @stable for implementation
* @deprecated since 1.35, use PageSaveComplete
* @ingroup Hooks
*/
interface PageContentInsertCompleteHook {

View file

@ -9,7 +9,7 @@ use User;
use WikiPage;
/**
* @stable for implementation
* @deprecated since 1.35, use PageSaveComplete
* @ingroup Hooks
*/
interface PageContentSaveCompleteHook {

View file

@ -0,0 +1,40 @@
<?php
namespace MediaWiki\Storage\Hook;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\User\UserIdentity;
use WikiPage;
/**
* @stable for implementation
* @ingroup Hooks
*/
interface PageSaveCompleteHook {
/**
* This hook is called after an article has been updated.
*
* @since 1.35
*
* @param WikiPage $wikiPage WikiPage modified
* @param UserIdentity $user User performing the modification
* @param string $summary Edit summary/comment
* @param int $flags Flags passed to WikiPage::doEditContent()
* @param RevisionRecord $revisionRecord New RevisionRecord of the article
* @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 $baseRevId.)
* @param int $undidRevId Rev ID (or 0) this edit undid
* @return bool|void True or no return value to continue or false to stop other hook handlers
* from being called; save cannot be aborted
*/
public function onPageSaveComplete(
$wikiPage,
$user,
$summary,
$flags,
$revisionRecord,
$originalRevId,
$undidRevId
);
}

View file

@ -1286,16 +1286,29 @@ class PageUpdater {
$hints['causeAction'] = 'edit-page';
$hints['causeAgent'] = $user->getName();
$newLegacyRevision = new Revision( $newRevisionRecord );
$mainContent = $newRevisionRecord->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
// Update links tables, site stats, etc.
$this->derivedDataUpdater->prepareUpdate( $newRevisionRecord, $hints );
$this->derivedDataUpdater->doUpdates();
// TODO: replace legacy hook!
$created = $hints['created'] ?? false;
$flags |= ( $created ? EDIT_NEW : EDIT_UPDATE );
if ( $hints['created'] ?? false ) {
// PageSaveComplete replaces the other two since 1.35
$this->hookRunner->onPageSaveComplete(
$wikiPage,
$user,
$summary->text,
$flags,
$newRevisionRecord,
$this->getOriginalRevisionId(),
$this->undidRevId
);
// Deprecated since 1.35
$newLegacyRevision = new Revision( $newRevisionRecord );
if ( $created ) {
// Trigger post-create hook
$this->hookRunner->onPageContentInsertComplete( $wikiPage, $user,
$mainContent, $summary->text, $flags & EDIT_MINOR,