2018-01-27 01:48:19 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* A handle for managing updates for derived page data on edit, import, purge, etc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Storage;
|
|
|
|
|
|
|
|
|
|
use CategoryMembershipChangeJob;
|
|
|
|
|
use Content;
|
|
|
|
|
use ContentHandler;
|
2018-03-09 22:05:47 +00:00
|
|
|
use DeferrableUpdate;
|
2018-01-27 01:48:19 +00:00
|
|
|
use DeferredUpdates;
|
|
|
|
|
use IDBAccessObject;
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
use JobQueueGroup;
|
|
|
|
|
use Language;
|
|
|
|
|
use LinksUpdate;
|
|
|
|
|
use LogicException;
|
2020-01-18 20:25:04 +00:00
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2021-07-21 01:03:59 +00:00
|
|
|
use MediaWiki\Content\Transform\ContentTransformer;
|
2018-01-27 01:48:19 +00:00
|
|
|
use MediaWiki\Edit\PreparedEdit;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2021-06-05 21:10:29 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\MutableRevisionRecord;
|
2018-08-07 16:52:40 +00:00
|
|
|
use MediaWiki\Revision\RenderedRevision;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2018-08-07 16:52:40 +00:00
|
|
|
use MediaWiki\Revision\RevisionRenderer;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionSlots;
|
|
|
|
|
use MediaWiki\Revision\RevisionStore;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2020-01-10 00:00:51 +00:00
|
|
|
use MediaWiki\Revision\SlotRoleRegistry;
|
2021-06-05 21:10:29 +00:00
|
|
|
use MediaWiki\User\TalkPageNotificationManager;
|
2018-01-27 01:48:19 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2021-04-12 14:45:26 +00:00
|
|
|
use MediaWiki\User\UserNameUtils;
|
2018-01-27 01:48:19 +00:00
|
|
|
use MessageCache;
|
2020-04-02 20:00:24 +00:00
|
|
|
use MWTimestamp;
|
2020-01-18 20:25:04 +00:00
|
|
|
use MWUnknownContentModelException;
|
2018-01-27 01:48:19 +00:00
|
|
|
use ParserCache;
|
|
|
|
|
use ParserOptions;
|
|
|
|
|
use ParserOutput;
|
2019-04-19 01:36:40 +00:00
|
|
|
use Psr\Log\LoggerAwareInterface;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
use Psr\Log\NullLogger;
|
2019-03-19 16:03:36 +00:00
|
|
|
use RefreshSecondaryDataUpdate;
|
2018-01-27 01:48:19 +00:00
|
|
|
use ResourceLoaderWikiModule;
|
2020-07-06 11:47:22 +00:00
|
|
|
use RevertedTagUpdateJob;
|
2018-01-27 01:48:19 +00:00
|
|
|
use SearchUpdate;
|
|
|
|
|
use SiteStatsUpdate;
|
|
|
|
|
use Title;
|
|
|
|
|
use User;
|
2021-06-05 21:10:29 +00:00
|
|
|
use WANObjectCache;
|
2018-01-27 01:48:19 +00:00
|
|
|
use Wikimedia\Assert\Assert;
|
2019-06-07 14:22:48 +00:00
|
|
|
use Wikimedia\Rdbms\ILBFactory;
|
2018-01-27 01:48:19 +00:00
|
|
|
use WikiPage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A handle for managing updates for derived page data on edit, import, purge, etc.
|
|
|
|
|
*
|
|
|
|
|
* @note Avoid direct usage of DerivedPageDataUpdater.
|
|
|
|
|
*
|
|
|
|
|
* @todo Define interfaces for the different use cases of DerivedPageDataUpdater, particularly
|
|
|
|
|
* providing access to post-PST content and ParserOutput to callbacks during revision creation,
|
|
|
|
|
* which currently use WikiPage::prepareContentForEdit, and allowing updates to be triggered on
|
|
|
|
|
* purge, import, and undeletion, which currently use WikiPage::doEditUpdates() and
|
|
|
|
|
* Content::getSecondaryDataUpdates().
|
|
|
|
|
*
|
|
|
|
|
* DerivedPageDataUpdater instances are designed to be cached inside a WikiPage instance,
|
|
|
|
|
* and re-used by callback code over the course of an update operation. It's a stepping stone
|
2019-07-11 05:59:56 +00:00
|
|
|
* on the way to a more complete refactoring of WikiPage.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* When using a DerivedPageDataUpdater, the following life cycle must be observed:
|
|
|
|
|
* grabCurrentRevision (optional), prepareContent (optional), prepareUpdate (required
|
|
|
|
|
* for doUpdates). getCanonicalParserOutput, getSlots, and getSecondaryDataUpdates
|
|
|
|
|
* require prepareContent or prepareUpdate to have been called first, to initialize the
|
|
|
|
|
* DerivedPageDataUpdater.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for more information.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* MCR migration note: this replaces the relevant methods in WikiPage, and covers the use cases
|
|
|
|
|
* of PreparedEdit.
|
|
|
|
|
*
|
|
|
|
|
* @internal
|
|
|
|
|
*
|
|
|
|
|
* @since 1.32
|
|
|
|
|
* @ingroup Page
|
|
|
|
|
*/
|
2019-04-19 01:36:40 +00:00
|
|
|
class DerivedPageDataUpdater implements IDBAccessObject, LoggerAwareInterface {
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var UserIdentity|null
|
|
|
|
|
*/
|
|
|
|
|
private $user = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var WikiPage
|
|
|
|
|
*/
|
|
|
|
|
private $wikiPage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var ParserCache
|
|
|
|
|
*/
|
|
|
|
|
private $parserCache;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var RevisionStore
|
|
|
|
|
*/
|
|
|
|
|
private $revisionStore;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Language
|
|
|
|
|
*/
|
2018-07-29 12:24:54 +00:00
|
|
|
private $contLang;
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var JobQueueGroup
|
|
|
|
|
*/
|
|
|
|
|
private $jobQueueGroup;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var MessageCache
|
|
|
|
|
*/
|
|
|
|
|
private $messageCache;
|
|
|
|
|
|
2018-08-28 15:34:25 +00:00
|
|
|
/**
|
2019-06-07 14:22:48 +00:00
|
|
|
* @var ILBFactory
|
2018-08-28 15:34:25 +00:00
|
|
|
*/
|
|
|
|
|
private $loadbalancerFactory;
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
/**
|
|
|
|
|
* @var HookRunner
|
|
|
|
|
*/
|
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
2019-04-19 01:36:40 +00:00
|
|
|
/**
|
|
|
|
|
* @var LoggerInterface
|
|
|
|
|
*/
|
|
|
|
|
private $logger;
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @var string see $wgArticleCountMethod
|
|
|
|
|
*/
|
|
|
|
|
private $articleCountMethod;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-10-28 19:44:09 +00:00
|
|
|
* @var bool see $wgRCWatchCategoryMembership
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
private $rcWatchCategoryMembership = false;
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-28 15:34:25 +00:00
|
|
|
* Stores (most of) the $options parameter of prepareUpdate().
|
|
|
|
|
* @see prepareUpdate()
|
2020-07-06 11:47:22 +00:00
|
|
|
*
|
2021-04-04 19:18:22 +00:00
|
|
|
* @phpcs:ignore Generic.Files.LineLength
|
2020-07-06 11:47:22 +00:00
|
|
|
* @phan-var array{changed:bool,created:bool,moved:bool,restored:bool,oldrevision:null|RevisionRecord,triggeringUser:null|UserIdentity,oldredirect:bool|null|string,oldcountable:bool|null|string,causeAction:null|string,causeAgent:null|string,editResult:null|EditResult,approved:bool}
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
private $options = [
|
|
|
|
|
'changed' => true,
|
2018-11-24 15:59:58 +00:00
|
|
|
// newrev is true if prepareUpdate is handling the creation of a new revision,
|
|
|
|
|
// as opposed to a null edit or a forced update.
|
|
|
|
|
'newrev' => false,
|
2018-01-27 01:48:19 +00:00
|
|
|
'created' => false,
|
|
|
|
|
'moved' => false,
|
|
|
|
|
'restored' => false,
|
2018-08-28 15:34:25 +00:00
|
|
|
'oldrevision' => null,
|
2018-01-27 01:48:19 +00:00
|
|
|
'oldcountable' => null,
|
|
|
|
|
'oldredirect' => null,
|
2018-08-28 15:34:25 +00:00
|
|
|
'triggeringUser' => null,
|
|
|
|
|
// causeAction/causeAgent default to 'unknown' but that's handled where it's read,
|
|
|
|
|
// to make the life of prepareUpdate() callers easier.
|
|
|
|
|
'causeAction' => null,
|
|
|
|
|
'causeAgent' => null,
|
2020-07-06 11:47:22 +00:00
|
|
|
'editResult' => null,
|
|
|
|
|
'approved' => false,
|
2018-01-27 01:48:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The state of the relevant row in page table before the edit.
|
|
|
|
|
* This is determined by the first call to grabCurrentRevision, prepareContent,
|
2018-08-01 12:22:37 +00:00
|
|
|
* or prepareUpdate (so it is only accessible in 'knows-current' or a later stage).
|
2018-01-27 01:48:19 +00:00
|
|
|
* If pageState was not initialized when prepareUpdate() is called, prepareUpdate() will
|
|
|
|
|
* attempt to emulate the state of the page table before the edit.
|
|
|
|
|
*
|
2018-08-01 12:22:37 +00:00
|
|
|
* Contains the following fields:
|
|
|
|
|
* - oldRevision (RevisionRecord|null): the revision that was current before the change
|
2018-03-09 22:05:47 +00:00
|
|
|
* associated with this update. Might not be set, use getParentRevision().
|
2018-08-01 12:22:37 +00:00
|
|
|
* - oldId (int|null): the id of the above revision. 0 if there is no such revision (the change
|
|
|
|
|
* was about creating a new page); null if not known (that should not happen).
|
|
|
|
|
* - oldIsRedirect (bool|null): whether the page was a redirect before the change. Lazy-loaded,
|
|
|
|
|
* can be null; use wasRedirect() instead of direct access.
|
|
|
|
|
* - oldCountable (bool|null): whether the page was countable before the change (or null
|
|
|
|
|
* if we don't have that information)
|
|
|
|
|
*
|
2018-01-27 01:48:19 +00:00
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private $pageState = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var RevisionSlotsUpdate|null
|
|
|
|
|
*/
|
|
|
|
|
private $slotsUpdate = null;
|
|
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
/**
|
|
|
|
|
* @var RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
private $parentRevision = null;
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
2018-08-07 16:52:40 +00:00
|
|
|
* @var RevisionRecord|null
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2018-08-07 16:52:40 +00:00
|
|
|
private $revision = null;
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-08-07 16:52:40 +00:00
|
|
|
* @var RenderedRevision
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2018-08-07 16:52:40 +00:00
|
|
|
private $renderedRevision = null;
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-08-07 16:52:40 +00:00
|
|
|
* @var RevisionRenderer
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2018-08-07 16:52:40 +00:00
|
|
|
private $revisionRenderer;
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2018-11-19 11:39:56 +00:00
|
|
|
/** @var SlotRoleRegistry */
|
|
|
|
|
private $slotRoleRegistry;
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* A stage identifier for managing the life cycle of this instance.
|
|
|
|
|
* Possible stages are 'new', 'knows-current', 'has-content', 'has-revision', and 'done'.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for documentation of the life cycle.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $stage = 'new';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transition table for managing the life cycle of DerivedPageDateUpdater instances.
|
|
|
|
|
*
|
|
|
|
|
* XXX: Overkill. This is a linear order, we could just count. Names are nice though,
|
|
|
|
|
* and constants are also overkill...
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for documentation of the life cycle.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @var array[]
|
|
|
|
|
*/
|
2019-10-16 01:24:50 +00:00
|
|
|
private const TRANSITIONS = [
|
2018-01-27 01:48:19 +00:00
|
|
|
'new' => [
|
|
|
|
|
'new' => true,
|
|
|
|
|
'knows-current' => true,
|
|
|
|
|
'has-content' => true,
|
|
|
|
|
'has-revision' => true,
|
|
|
|
|
],
|
|
|
|
|
'knows-current' => [
|
|
|
|
|
'knows-current' => true,
|
|
|
|
|
'has-content' => true,
|
|
|
|
|
'has-revision' => true,
|
|
|
|
|
],
|
|
|
|
|
'has-content' => [
|
|
|
|
|
'has-content' => true,
|
|
|
|
|
'has-revision' => true,
|
|
|
|
|
],
|
|
|
|
|
'has-revision' => [
|
|
|
|
|
'has-revision' => true,
|
|
|
|
|
'done' => true,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2020-07-06 11:47:22 +00:00
|
|
|
/** @var IContentHandlerFactory */
|
2020-01-18 20:25:04 +00:00
|
|
|
private $contentHandlerFactory;
|
|
|
|
|
|
2020-07-06 11:47:22 +00:00
|
|
|
/** @var EditResultCache */
|
|
|
|
|
private $editResultCache;
|
|
|
|
|
|
2021-04-12 14:45:26 +00:00
|
|
|
/** @var UserNameUtils */
|
|
|
|
|
private $userNameUtils;
|
|
|
|
|
|
2021-07-21 01:03:59 +00:00
|
|
|
/** @var ContentTransformer */
|
|
|
|
|
private $contentTransformer;
|
|
|
|
|
|
2021-06-05 21:10:29 +00:00
|
|
|
/** @var PageEditStash */
|
|
|
|
|
private $pageEditStash;
|
|
|
|
|
|
|
|
|
|
/** @var TalkPageNotificationManager */
|
|
|
|
|
private $talkPageNotificationManager;
|
|
|
|
|
|
|
|
|
|
/** @var WANObjectCache */
|
|
|
|
|
private $mainWANObjectCache;
|
|
|
|
|
|
|
|
|
|
/** @var PermissionManager */
|
|
|
|
|
private $permissionManager;
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
2021-11-04 21:32:39 +00:00
|
|
|
* @param WikiPage $wikiPage
|
2018-01-27 01:48:19 +00:00
|
|
|
* @param RevisionStore $revisionStore
|
2018-08-07 16:52:40 +00:00
|
|
|
* @param RevisionRenderer $revisionRenderer
|
2018-11-19 11:39:56 +00:00
|
|
|
* @param SlotRoleRegistry $slotRoleRegistry
|
2018-01-27 01:48:19 +00:00
|
|
|
* @param ParserCache $parserCache
|
|
|
|
|
* @param JobQueueGroup $jobQueueGroup
|
|
|
|
|
* @param MessageCache $messageCache
|
2018-07-29 12:24:54 +00:00
|
|
|
* @param Language $contLang
|
2019-06-07 14:22:48 +00:00
|
|
|
* @param ILBFactory $loadbalancerFactory
|
2020-01-18 20:25:04 +00:00
|
|
|
* @param IContentHandlerFactory $contentHandlerFactory
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
* @param HookContainer $hookContainer
|
2020-07-06 11:47:22 +00:00
|
|
|
* @param EditResultCache $editResultCache
|
2021-04-12 14:45:26 +00:00
|
|
|
* @param UserNameUtils $userNameUtils
|
2021-07-21 01:03:59 +00:00
|
|
|
* @param ContentTransformer $contentTransformer
|
2021-06-05 21:10:29 +00:00
|
|
|
* @param PageEditStash $pageEditStash
|
|
|
|
|
* @param TalkPageNotificationManager $talkPageNotificationManager
|
|
|
|
|
* @param WANObjectCache $mainWANObjectCache
|
|
|
|
|
* @param PermissionManager $permissionManager
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
WikiPage $wikiPage,
|
|
|
|
|
RevisionStore $revisionStore,
|
2018-08-07 16:52:40 +00:00
|
|
|
RevisionRenderer $revisionRenderer,
|
2018-11-19 11:39:56 +00:00
|
|
|
SlotRoleRegistry $slotRoleRegistry,
|
2018-01-27 01:48:19 +00:00
|
|
|
ParserCache $parserCache,
|
|
|
|
|
JobQueueGroup $jobQueueGroup,
|
|
|
|
|
MessageCache $messageCache,
|
2018-08-28 15:34:25 +00:00
|
|
|
Language $contLang,
|
2020-01-18 20:25:04 +00:00
|
|
|
ILBFactory $loadbalancerFactory,
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
IContentHandlerFactory $contentHandlerFactory,
|
2020-07-06 11:47:22 +00:00
|
|
|
HookContainer $hookContainer,
|
2021-04-12 14:45:26 +00:00
|
|
|
EditResultCache $editResultCache,
|
2021-07-21 01:03:59 +00:00
|
|
|
UserNameUtils $userNameUtils,
|
2021-06-05 21:10:29 +00:00
|
|
|
ContentTransformer $contentTransformer,
|
|
|
|
|
PageEditStash $pageEditStash,
|
|
|
|
|
TalkPageNotificationManager $talkPageNotificationManager,
|
|
|
|
|
WANObjectCache $mainWANObjectCache,
|
|
|
|
|
PermissionManager $permissionManager
|
2018-01-27 01:48:19 +00:00
|
|
|
) {
|
|
|
|
|
$this->wikiPage = $wikiPage;
|
|
|
|
|
|
|
|
|
|
$this->parserCache = $parserCache;
|
|
|
|
|
$this->revisionStore = $revisionStore;
|
2018-08-07 16:52:40 +00:00
|
|
|
$this->revisionRenderer = $revisionRenderer;
|
2018-11-19 11:39:56 +00:00
|
|
|
$this->slotRoleRegistry = $slotRoleRegistry;
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->jobQueueGroup = $jobQueueGroup;
|
|
|
|
|
$this->messageCache = $messageCache;
|
2018-07-29 12:24:54 +00:00
|
|
|
$this->contLang = $contLang;
|
2018-10-31 17:36:48 +00:00
|
|
|
// XXX only needed for waiting for replicas to catch up; there should be a narrower
|
2018-08-28 15:34:25 +00:00
|
|
|
// interface for that.
|
|
|
|
|
$this->loadbalancerFactory = $loadbalancerFactory;
|
2020-01-18 20:25:04 +00:00
|
|
|
$this->contentHandlerFactory = $contentHandlerFactory;
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookRunner = new HookRunner( $hookContainer );
|
2020-07-06 11:47:22 +00:00
|
|
|
$this->editResultCache = $editResultCache;
|
2021-04-12 14:45:26 +00:00
|
|
|
$this->userNameUtils = $userNameUtils;
|
2021-07-21 01:03:59 +00:00
|
|
|
$this->contentTransformer = $contentTransformer;
|
2021-06-05 21:10:29 +00:00
|
|
|
$this->pageEditStash = $pageEditStash;
|
|
|
|
|
$this->talkPageNotificationManager = $talkPageNotificationManager;
|
|
|
|
|
$this->mainWANObjectCache = $mainWANObjectCache;
|
|
|
|
|
$this->permissionManager = $permissionManager;
|
2020-01-18 20:25:04 +00:00
|
|
|
|
2019-04-19 01:36:40 +00:00
|
|
|
$this->logger = new NullLogger();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setLogger( LoggerInterface $logger ) {
|
|
|
|
|
$this->logger = $logger;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transition function for managing the life cycle of this instances.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for documentation of the life cycle.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @param string $newStage the new stage
|
|
|
|
|
* @return string the previous stage
|
|
|
|
|
*
|
|
|
|
|
* @throws LogicException If a transition to the given stage is not possible in the current
|
|
|
|
|
* stage.
|
|
|
|
|
*/
|
|
|
|
|
private function doTransition( $newStage ) {
|
|
|
|
|
$this->assertTransition( $newStage );
|
|
|
|
|
|
|
|
|
|
$oldStage = $this->stage;
|
|
|
|
|
$this->stage = $newStage;
|
|
|
|
|
|
|
|
|
|
return $oldStage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asserts that a transition to the given stage is possible, without performing it.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for documentation of the life cycle.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @param string $newStage the new stage
|
|
|
|
|
*
|
|
|
|
|
* @throws LogicException If this instance is not in the expected stage
|
|
|
|
|
*/
|
|
|
|
|
private function assertTransition( $newStage ) {
|
2019-10-16 01:24:50 +00:00
|
|
|
if ( empty( self::TRANSITIONS[$this->stage][$newStage] ) ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
throw new LogicException( "Cannot transition from {$this->stage} to $newStage" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether this DerivedPageDataUpdater can be re-used for running updates targeting
|
2018-08-09 08:21:56 +00:00
|
|
|
* the given revision.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @param UserIdentity|null $user The user creating the revision in question
|
|
|
|
|
* @param RevisionRecord|null $revision New revision (after save, if already saved)
|
|
|
|
|
* @param RevisionSlotsUpdate|null $slotsUpdate New content (before PST)
|
|
|
|
|
* @param null|int $parentId Parent revision of the edit (use 0 for page creation)
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isReusableFor(
|
|
|
|
|
UserIdentity $user = null,
|
|
|
|
|
RevisionRecord $revision = null,
|
|
|
|
|
RevisionSlotsUpdate $slotsUpdate = null,
|
|
|
|
|
$parentId = null
|
|
|
|
|
) {
|
|
|
|
|
if ( $revision
|
|
|
|
|
&& $parentId
|
|
|
|
|
&& $revision->getParentId() !== $parentId
|
|
|
|
|
) {
|
|
|
|
|
throw new InvalidArgumentException( '$parentId should match the parent of $revision' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 14:49:23 +00:00
|
|
|
// NOTE: For null revisions, $user may be different from $this->revision->getUser
|
|
|
|
|
// and also from $revision->getUser.
|
|
|
|
|
// But $user should always match $this->user.
|
2018-01-27 01:48:19 +00:00
|
|
|
if ( $user && $this->user && $user->getName() !== $this->user->getName() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $revision && $this->revision && $this->revision->getId()
|
|
|
|
|
&& $this->revision->getId() !== $revision->getId()
|
|
|
|
|
) {
|
2018-01-27 01:48:19 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->pageState
|
|
|
|
|
&& $revision
|
|
|
|
|
&& $revision->getParentId() !== null
|
|
|
|
|
&& $this->pageState['oldId'] !== $revision->getParentId()
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->pageState
|
|
|
|
|
&& $parentId !== null
|
|
|
|
|
&& $this->pageState['oldId'] !== $parentId
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: this check is the primary reason for having the $this->slotsUpdate field!
|
|
|
|
|
if ( $this->slotsUpdate
|
|
|
|
|
&& $slotsUpdate
|
|
|
|
|
&& !$this->slotsUpdate->hasSameUpdates( $slotsUpdate )
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $revision
|
|
|
|
|
&& $this->revision
|
|
|
|
|
&& !$this->revision->getSlots()->hasSameContent( $revision->getSlots() )
|
2018-01-27 01:48:19 +00:00
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $articleCountMethod "any" or "link".
|
|
|
|
|
* @see $wgArticleCountMethod
|
|
|
|
|
*/
|
|
|
|
|
public function setArticleCountMethod( $articleCountMethod ) {
|
|
|
|
|
$this->articleCountMethod = $articleCountMethod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bool $rcWatchCategoryMembership
|
|
|
|
|
* @see $wgRCWatchCategoryMembership
|
|
|
|
|
*/
|
|
|
|
|
public function setRcWatchCategoryMembership( $rcWatchCategoryMembership ) {
|
|
|
|
|
$this->rcWatchCategoryMembership = $rcWatchCategoryMembership;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
private function getTitle() {
|
|
|
|
|
// NOTE: eventually, we won't get a WikiPage passed into the constructor any more
|
|
|
|
|
return $this->wikiPage->getTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return WikiPage
|
|
|
|
|
*/
|
|
|
|
|
private function getWikiPage() {
|
|
|
|
|
// NOTE: eventually, we won't get a WikiPage passed into the constructor any more
|
|
|
|
|
return $this->wikiPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines whether the page being edited already existed.
|
|
|
|
|
* Only defined after calling grabCurrentRevision() or prepareContent() or prepareUpdate()!
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
* @throws LogicException if called before grabCurrentRevision
|
|
|
|
|
*/
|
|
|
|
|
public function pageExisted() {
|
|
|
|
|
$this->assertHasPageState( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
return $this->pageState['oldId'] > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-09 22:05:47 +00:00
|
|
|
* Returns the parent revision of the new revision wrapped by this update.
|
|
|
|
|
* If the update is a null-edit, this will return the parent of the current (and new) revision.
|
|
|
|
|
* This will return null if the revision wrapped by this update created the page.
|
|
|
|
|
* Only defined after calling prepareContent() or prepareUpdate()!
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
2018-03-09 22:05:47 +00:00
|
|
|
* @return RevisionRecord|null the parent revision of the new revision, or null if
|
|
|
|
|
* the update created the page.
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2018-03-09 22:05:47 +00:00
|
|
|
private function getParentRevision() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
if ( $this->parentRevision ) {
|
|
|
|
|
return $this->parentRevision;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
if ( !$this->pageState['oldId'] ) {
|
|
|
|
|
// If there was no current revision, there is no parent revision,
|
|
|
|
|
// since the page didn't exist.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$oldId = $this->revision->getParentId();
|
2021-09-02 23:10:56 +00:00
|
|
|
$flags = $this->usePrimary() ? RevisionStore::READ_LATEST : 0;
|
2018-03-09 22:05:47 +00:00
|
|
|
$this->parentRevision = $oldId
|
|
|
|
|
? $this->revisionStore->getRevisionById( $oldId, $flags )
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
return $this->parentRevision;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the revision that was the page's current revision when grabCurrentRevision()
|
|
|
|
|
* was first called.
|
|
|
|
|
*
|
|
|
|
|
* During an edit, that revision will act as the logical parent of the new revision.
|
|
|
|
|
*
|
|
|
|
|
* Some updates are performed based on the difference between the database state at the
|
|
|
|
|
* moment this method is first called, and the state after the edit.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for more information on when thie method can and should be called.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @note After prepareUpdate() was called, grabCurrentRevision() will throw an exception
|
|
|
|
|
* to avoid confusion, since the page's current revision is then the new revision after
|
|
|
|
|
* the edit, which was presumably passed to prepareUpdate() as the $revision parameter.
|
2018-03-09 22:05:47 +00:00
|
|
|
* Use getParentRevision() instead to access the revision that is the parent of the
|
|
|
|
|
* new revision.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @return RevisionRecord|null the page's current revision, or null if the page does not
|
|
|
|
|
* yet exist.
|
|
|
|
|
*/
|
|
|
|
|
public function grabCurrentRevision() {
|
|
|
|
|
if ( $this->pageState ) {
|
|
|
|
|
return $this->pageState['oldRevision'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertTransition( 'knows-current' );
|
|
|
|
|
|
|
|
|
|
// NOTE: eventually, we won't get a WikiPage passed into the constructor any more
|
|
|
|
|
$wikiPage = $this->getWikiPage();
|
|
|
|
|
|
|
|
|
|
// Do not call WikiPage::clear(), since the caller may already have caused page data
|
|
|
|
|
// to be loaded with SELECT FOR UPDATE. Just assert it's loaded now.
|
|
|
|
|
$wikiPage->loadPageData( self::READ_LATEST );
|
2020-04-18 02:39:58 +00:00
|
|
|
$current = $wikiPage->getRevisionRecord();
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->pageState = [
|
|
|
|
|
'oldRevision' => $current,
|
2020-04-18 02:39:58 +00:00
|
|
|
'oldId' => $current ? $current->getId() : 0,
|
2018-01-27 01:48:19 +00:00
|
|
|
'oldIsRedirect' => $wikiPage->isRedirect(), // NOTE: uses page table
|
|
|
|
|
'oldCountable' => $wikiPage->isCountable(), // NOTE: uses pagelinks table
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->doTransition( 'knows-current' );
|
|
|
|
|
|
|
|
|
|
return $this->pageState['oldRevision'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether prepareUpdate() or prepareContent() have been called on this instance.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isContentPrepared() {
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->revision !== null;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether prepareUpdate() has been called on this instance.
|
|
|
|
|
*
|
2018-08-07 16:52:40 +00:00
|
|
|
* @note will also return null in case of a null-edit!
|
|
|
|
|
*
|
2018-01-27 01:48:19 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isUpdatePrepared() {
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->revision !== null && $this->revision->getId() !== null;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
private function getPageId() {
|
|
|
|
|
// NOTE: eventually, we won't get a WikiPage passed into the constructor any more
|
|
|
|
|
return $this->wikiPage->getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-07 16:52:40 +00:00
|
|
|
* Whether the content is deleted and thus not visible to the public.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2018-08-07 16:52:40 +00:00
|
|
|
public function isContentDeleted() {
|
2018-01-27 01:48:19 +00:00
|
|
|
if ( $this->revision ) {
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->revision->isDeleted( RevisionRecord::DELETED_TEXT );
|
2018-01-27 01:48:19 +00:00
|
|
|
} else {
|
2018-08-07 16:52:40 +00:00
|
|
|
// If the content has not been saved yet, it cannot have been deleted yet.
|
|
|
|
|
return false;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the slot, modified or inherited, after PST, with no audience checks applied.
|
|
|
|
|
*
|
|
|
|
|
* @param string $role slot role name
|
|
|
|
|
*
|
|
|
|
|
* @throws PageUpdateException If the slot is neither set for update nor inherited from the
|
|
|
|
|
* parent revision.
|
|
|
|
|
* @return SlotRecord
|
|
|
|
|
*/
|
|
|
|
|
public function getRawSlot( $role ) {
|
|
|
|
|
return $this->getSlots()->getSlot( $role );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the content of the given slot, with no audience checks.
|
|
|
|
|
*
|
|
|
|
|
* @throws PageUpdateException If the slot is neither set for update nor inherited from the
|
|
|
|
|
* parent revision.
|
|
|
|
|
* @param string $role slot role name
|
|
|
|
|
* @return Content
|
|
|
|
|
*/
|
|
|
|
|
public function getRawContent( $role ) {
|
|
|
|
|
return $this->getRawSlot( $role )->getContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the content model of the given slot
|
|
|
|
|
*
|
|
|
|
|
* @param string $role slot role name
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getContentModel( $role ) {
|
|
|
|
|
return $this->getRawSlot( $role )->getModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $role slot role name
|
|
|
|
|
* @return ContentHandler
|
2020-01-18 20:25:04 +00:00
|
|
|
* @throws MWUnknownContentModelException
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
2020-01-18 20:25:04 +00:00
|
|
|
private function getContentHandler( $role ): ContentHandler {
|
|
|
|
|
return $this->contentHandlerFactory
|
|
|
|
|
->getContentHandler( $this->getContentModel( $role ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-02 23:10:56 +00:00
|
|
|
private function usePrimary() {
|
2018-01-27 01:48:19 +00:00
|
|
|
// TODO: can we just set a flag to true in prepareContent()?
|
|
|
|
|
return $this->wikiPage->wasLoadedFrom( self::READ_LATEST );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isCountable() {
|
|
|
|
|
// NOTE: Keep in sync with WikiPage::isCountable.
|
|
|
|
|
|
|
|
|
|
if ( !$this->getTitle()->isContentPage() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $this->isContentDeleted() ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
// This should be irrelevant: countability only applies to the current revision,
|
|
|
|
|
// and the current revision is never suppressed.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->isRedirect() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hasLinks = null;
|
|
|
|
|
|
|
|
|
|
if ( $this->articleCountMethod === 'link' ) {
|
2018-11-19 11:39:56 +00:00
|
|
|
// NOTE: it would be more appropriate to determine for each slot separately
|
|
|
|
|
// whether it has links, and use that information with that slot's
|
|
|
|
|
// isCountable() method. However, that would break parity with
|
|
|
|
|
// WikiPage::isCountable, which uses the pagelinks table to determine
|
|
|
|
|
// whether the current revision has links.
|
2018-01-27 01:48:19 +00:00
|
|
|
$hasLinks = (bool)count( $this->getCanonicalParserOutput()->getLinks() );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 21:52:39 +00:00
|
|
|
foreach ( $this->getSlots()->getSlotRoles() as $role ) {
|
2018-11-19 11:39:56 +00:00
|
|
|
$roleHandler = $this->slotRoleRegistry->getRoleHandler( $role );
|
|
|
|
|
if ( $roleHandler->supportsArticleCount() ) {
|
|
|
|
|
$content = $this->getRawContent( $role );
|
|
|
|
|
|
|
|
|
|
if ( $content->isCountable( $hasLinks ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isRedirect() {
|
|
|
|
|
// NOTE: main slot determines redirect status
|
2018-11-19 11:39:56 +00:00
|
|
|
// TODO: MCR: this should be controlled by a PageTypeHandler
|
2018-09-24 21:10:08 +00:00
|
|
|
$mainContent = $this->getRawContent( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
return $mainContent->isRedirect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param RevisionRecord $rev
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function revisionIsRedirect( RevisionRecord $rev ) {
|
|
|
|
|
// NOTE: main slot determines redirect status
|
2018-09-24 21:10:08 +00:00
|
|
|
$mainContent = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
return $mainContent->isRedirect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare updates based on an update which has not yet been saved.
|
|
|
|
|
*
|
|
|
|
|
* This may be used to create derived data that is needed when creating a new revision;
|
|
|
|
|
* particularly, this makes available the slots of the new revision via the getSlots()
|
|
|
|
|
* method, after applying PST and slot inheritance.
|
|
|
|
|
*
|
|
|
|
|
* The derived data prepared for revision creation may then later be re-used by doUpdates(),
|
|
|
|
|
* without the need to re-calculate.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for more information on when thie method can and should be called.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
2018-07-26 16:31:49 +00:00
|
|
|
* @note Calling this method more than once with the same $slotsUpdate
|
2018-01-27 01:48:19 +00:00
|
|
|
* has no effect. Calling this method multiple times with different content will cause
|
|
|
|
|
* an exception.
|
|
|
|
|
*
|
2018-07-26 16:31:49 +00:00
|
|
|
* @note Calling this method after prepareUpdate() has been called will cause an exception.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
2021-02-23 14:51:23 +00:00
|
|
|
* @param UserIdentity $user The user to act as context for pre-save transformation (PST).
|
2018-01-27 01:48:19 +00:00
|
|
|
* Type hint should be reduced to UserIdentity at some point.
|
|
|
|
|
* @param RevisionSlotsUpdate $slotsUpdate The new content of the slots to be updated
|
|
|
|
|
* by this edit, before PST.
|
|
|
|
|
* @param bool $useStash Whether to use stashed ParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function prepareContent(
|
2021-02-23 14:51:23 +00:00
|
|
|
UserIdentity $user,
|
2018-01-27 01:48:19 +00:00
|
|
|
RevisionSlotsUpdate $slotsUpdate,
|
|
|
|
|
$useStash = true
|
|
|
|
|
) {
|
|
|
|
|
if ( $this->slotsUpdate ) {
|
|
|
|
|
if ( !$this->user ) {
|
|
|
|
|
throw new LogicException(
|
|
|
|
|
'Unexpected state: $this->slotsUpdate was initialized, '
|
|
|
|
|
. 'but $this->user was not.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->user->getName() !== $user->getName() ) {
|
|
|
|
|
throw new LogicException( 'Can\'t call prepareContent() again for different user! '
|
|
|
|
|
. 'Expected ' . $this->user->getName() . ', got ' . $user->getName()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$this->slotsUpdate->hasSameUpdates( $slotsUpdate ) ) {
|
|
|
|
|
throw new LogicException(
|
|
|
|
|
'Can\'t call prepareContent() again with different slot content!'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return; // prepareContent() already done, nothing to do
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertTransition( 'has-content' );
|
|
|
|
|
|
|
|
|
|
$wikiPage = $this->getWikiPage(); // TODO: use only for legacy hooks!
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
|
|
|
|
|
$parentRevision = $this->grabCurrentRevision();
|
|
|
|
|
|
|
|
|
|
// The edit may have already been prepared via api.php?action=stashedit
|
|
|
|
|
$stashedEdit = false;
|
|
|
|
|
|
|
|
|
|
// TODO: MCR: allow output for all slots to be stashed.
|
2018-09-24 21:10:08 +00:00
|
|
|
if ( $useStash && $slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) ) {
|
2021-06-05 21:10:29 +00:00
|
|
|
$stashedEdit = $this->pageEditStash->checkCache(
|
2019-04-13 04:38:55 +00:00
|
|
|
$title,
|
|
|
|
|
$slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent(),
|
2021-10-15 14:12:55 +00:00
|
|
|
$user
|
2019-04-13 04:38:55 +00:00
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 03:34:24 +00:00
|
|
|
$userPopts = ParserOptions::newFromUserAndLang( $user, $this->contLang );
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->hookRunner->onArticlePrepareTextForEdit( $wikiPage, $userPopts );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->user = $user;
|
|
|
|
|
$this->slotsUpdate = $slotsUpdate;
|
|
|
|
|
|
|
|
|
|
if ( $parentRevision ) {
|
2018-08-07 16:52:40 +00:00
|
|
|
$this->revision = MutableRevisionRecord::newFromParentRevision( $parentRevision );
|
2018-01-27 01:48:19 +00:00
|
|
|
} else {
|
2018-08-07 16:52:40 +00:00
|
|
|
$this->revision = new MutableRevisionRecord( $title );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-05 18:03:15 +00:00
|
|
|
// NOTE: user and timestamp must be set, so they can be used for
|
|
|
|
|
// {{subst:REVISIONUSER}} and {{subst:REVISIONTIMESTAMP}} in PST!
|
2020-04-02 20:00:24 +00:00
|
|
|
$this->revision->setTimestamp( MWTimestamp::now( TS_MW ) );
|
2018-09-05 18:03:15 +00:00
|
|
|
$this->revision->setUser( $user );
|
|
|
|
|
|
|
|
|
|
// Set up ParserOptions to operate on the new revision
|
2020-06-03 03:48:42 +00:00
|
|
|
$oldCallback = $userPopts->getCurrentRevisionRecordCallback();
|
|
|
|
|
$userPopts->setCurrentRevisionRecordCallback(
|
|
|
|
|
function ( Title $parserTitle, $parser = null ) use ( $title, $oldCallback ) {
|
2018-09-05 18:03:15 +00:00
|
|
|
if ( $parserTitle->equals( $title ) ) {
|
2020-06-03 03:48:42 +00:00
|
|
|
return $this->revision;
|
2018-09-05 18:03:15 +00:00
|
|
|
} else {
|
|
|
|
|
return call_user_func( $oldCallback, $parserTitle, $parser );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
$pstContentSlots = $this->revision->getSlots();
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
foreach ( $slotsUpdate->getModifiedRoles() as $role ) {
|
|
|
|
|
$slot = $slotsUpdate->getModifiedSlot( $role );
|
|
|
|
|
|
|
|
|
|
if ( $slot->isInherited() ) {
|
|
|
|
|
// No PST for inherited slots! Note that "modified" slots may still be inherited
|
|
|
|
|
// from an earlier version, e.g. for rollbacks.
|
|
|
|
|
$pstSlot = $slot;
|
2018-09-24 21:10:08 +00:00
|
|
|
} elseif ( $role === SlotRecord::MAIN && $stashedEdit ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
// TODO: MCR: allow PST content for all slots to be stashed.
|
|
|
|
|
$pstSlot = SlotRecord::newUnsaved( $role, $stashedEdit->pstContent );
|
|
|
|
|
} else {
|
2021-07-21 01:03:59 +00:00
|
|
|
$pstContent = $this->contentTransformer->preSaveTransform(
|
|
|
|
|
$slot->getContent(),
|
|
|
|
|
$title,
|
|
|
|
|
$user,
|
|
|
|
|
$userPopts
|
|
|
|
|
);
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$pstSlot = SlotRecord::newUnsaved( $role, $pstContent );
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
$pstContentSlots->setSlot( $pstSlot );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $slotsUpdate->getRemovedRoles() as $role ) {
|
2018-08-07 16:52:40 +00:00
|
|
|
$pstContentSlots->removeSlot( $role );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->options['created'] = ( $parentRevision === null );
|
|
|
|
|
$this->options['changed'] = ( $parentRevision === null
|
2018-08-07 16:52:40 +00:00
|
|
|
|| !$pstContentSlots->hasSameContent( $parentRevision->getSlots() ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->doTransition( 'has-content' );
|
2018-08-07 16:52:40 +00:00
|
|
|
|
|
|
|
|
if ( !$this->options['changed'] ) {
|
|
|
|
|
// null-edit!
|
|
|
|
|
|
|
|
|
|
// TODO: move this into MutableRevisionRecord
|
|
|
|
|
// TODO: This needs to behave differently for a forced dummy edit!
|
|
|
|
|
$this->revision->setId( $parentRevision->getId() );
|
|
|
|
|
$this->revision->setTimestamp( $parentRevision->getTimestamp() );
|
|
|
|
|
$this->revision->setPageId( $parentRevision->getPageId() );
|
|
|
|
|
$this->revision->setParentId( $parentRevision->getParentId() );
|
|
|
|
|
$this->revision->setUser( $parentRevision->getUser( RevisionRecord::RAW ) );
|
|
|
|
|
$this->revision->setComment( $parentRevision->getComment( RevisionRecord::RAW ) );
|
|
|
|
|
$this->revision->setMinorEdit( $parentRevision->isMinor() );
|
|
|
|
|
$this->revision->setVisibility( $parentRevision->getVisibility() );
|
|
|
|
|
|
|
|
|
|
// prepareUpdate() is redundant for null-edits
|
|
|
|
|
$this->doTransition( 'has-revision' );
|
2018-03-09 22:05:47 +00:00
|
|
|
} else {
|
|
|
|
|
$this->parentRevision = $parentRevision;
|
2018-08-07 16:52:40 +00:00
|
|
|
}
|
2018-11-15 16:40:53 +00:00
|
|
|
|
2021-09-02 23:10:56 +00:00
|
|
|
$renderHints = [ 'use-master' => $this->usePrimary(), 'audience' => RevisionRecord::RAW ];
|
2018-11-15 16:40:53 +00:00
|
|
|
|
|
|
|
|
if ( $stashedEdit ) {
|
|
|
|
|
/** @var ParserOutput $output */
|
|
|
|
|
$output = $stashedEdit->output;
|
|
|
|
|
// TODO: this should happen when stashing the ParserOutput, not now!
|
|
|
|
|
$output->setCacheTime( $stashedEdit->timestamp );
|
|
|
|
|
|
|
|
|
|
$renderHints['known-revision-output'] = $output;
|
2019-04-19 01:36:40 +00:00
|
|
|
|
|
|
|
|
$this->logger->debug( __METHOD__ . ': using stashed edit output...' );
|
2018-11-15 16:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
$renderHints['generate-html'] = $this->shouldGenerateHTMLOnEdit();
|
|
|
|
|
|
2018-11-15 16:40:53 +00:00
|
|
|
// NOTE: we want a canonical rendering, so don't pass $this->user or ParserOptions
|
|
|
|
|
// NOTE: the revision is either new or current, so we can bypass audience checks.
|
|
|
|
|
$this->renderedRevision = $this->revisionRenderer->getRenderedRevision(
|
|
|
|
|
$this->revision,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
$renderHints
|
|
|
|
|
);
|
2018-08-07 16:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the update's target revision - that is, the revision that will be the current
|
|
|
|
|
* revision after the update.
|
|
|
|
|
*
|
|
|
|
|
* @note Callers must treat the returned RevisionRecord's content as immutable, even
|
|
|
|
|
* if it is a MutableRevisionRecord instance. Other aspects of a MutableRevisionRecord
|
|
|
|
|
* returned from here, such as the user or the comment, may be changed, but may not
|
|
|
|
|
* be reflected in ParserOutput until after prepareUpdate() has been called.
|
|
|
|
|
*
|
|
|
|
|
* @todo This is currently used by PageUpdater::makeNewRevision() to construct an unsaved
|
|
|
|
|
* MutableRevisionRecord instance. Introduce something like an UnsavedRevisionFactory service
|
|
|
|
|
* for that purpose instead!
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionRecord
|
|
|
|
|
*/
|
|
|
|
|
public function getRevision() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
|
|
|
|
return $this->revision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return RenderedRevision
|
|
|
|
|
*/
|
|
|
|
|
public function getRenderedRevision() {
|
2018-11-15 16:40:53 +00:00
|
|
|
$this->assertPrepared( __METHOD__ );
|
2018-08-07 16:52:40 +00:00
|
|
|
|
|
|
|
|
return $this->renderedRevision;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertHasPageState( $method ) {
|
|
|
|
|
if ( !$this->pageState ) {
|
|
|
|
|
throw new LogicException(
|
|
|
|
|
'Must call grabCurrentRevision() or prepareContent() '
|
|
|
|
|
. 'or prepareUpdate() before calling ' . $method
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function assertPrepared( $method ) {
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( !$this->revision ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
throw new LogicException(
|
|
|
|
|
'Must call prepareContent() or prepareUpdate() before calling ' . $method
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-28 15:34:25 +00:00
|
|
|
private function assertHasRevision( $method ) {
|
|
|
|
|
if ( !$this->revision->getId() ) {
|
|
|
|
|
throw new LogicException(
|
|
|
|
|
'Must call prepareUpdate() before calling ' . $method
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the edit creates the page.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isCreation() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
|
|
|
|
return $this->options['created'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the edit created, or should create, a new revision (that is, it's not a null-edit).
|
|
|
|
|
*
|
2018-07-26 16:31:49 +00:00
|
|
|
* @warning at present, "null-revisions" that do not change content but do have a revision
|
2018-01-27 01:48:19 +00:00
|
|
|
* record would return false after prepareContent(), but true after prepareUpdate()!
|
|
|
|
|
* This should probably be fixed.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isChange() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
|
|
|
|
return $this->options['changed'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the page was a redirect before the edit.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function wasRedirect() {
|
|
|
|
|
$this->assertHasPageState( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
if ( $this->pageState['oldIsRedirect'] === null ) {
|
|
|
|
|
/** @var RevisionRecord $rev */
|
|
|
|
|
$rev = $this->pageState['oldRevision'];
|
|
|
|
|
if ( $rev ) {
|
|
|
|
|
$this->pageState['oldIsRedirect'] = $this->revisionIsRedirect( $rev );
|
|
|
|
|
} else {
|
|
|
|
|
$this->pageState['oldIsRedirect'] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->pageState['oldIsRedirect'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the slots of the target revision, after PST.
|
|
|
|
|
*
|
2018-08-07 16:52:40 +00:00
|
|
|
* @note Callers must treat the returned RevisionSlots instance as immutable, even
|
|
|
|
|
* if it is a MutableRevisionSlots instance.
|
|
|
|
|
*
|
2018-01-27 01:48:19 +00:00
|
|
|
* @return RevisionSlots
|
|
|
|
|
*/
|
|
|
|
|
public function getSlots() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->revision->getSlots();
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the RevisionSlotsUpdate for this updater.
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionSlotsUpdate
|
|
|
|
|
*/
|
|
|
|
|
private function getRevisionSlotsUpdate() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
if ( !$this->slotsUpdate ) {
|
2018-03-09 22:05:47 +00:00
|
|
|
$old = $this->getParentRevision();
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->slotsUpdate = RevisionSlotsUpdate::newFromRevisionSlots(
|
|
|
|
|
$this->revision->getSlots(),
|
|
|
|
|
$old ? $old->getSlots() : null
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $this->slotsUpdate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the role names of the slots touched by the new revision,
|
|
|
|
|
* including removed roles.
|
|
|
|
|
*
|
|
|
|
|
* @return string[]
|
|
|
|
|
*/
|
|
|
|
|
public function getTouchedSlotRoles() {
|
|
|
|
|
return $this->getRevisionSlotsUpdate()->getTouchedRoles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the role names of the slots modified by the new revision,
|
|
|
|
|
* not including removed roles.
|
|
|
|
|
*
|
|
|
|
|
* @return string[]
|
|
|
|
|
*/
|
|
|
|
|
public function getModifiedSlotRoles() {
|
|
|
|
|
return $this->getRevisionSlotsUpdate()->getModifiedRoles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the role names of the slots removed by the new revision.
|
|
|
|
|
*
|
|
|
|
|
* @return string[]
|
|
|
|
|
*/
|
|
|
|
|
public function getRemovedSlotRoles() {
|
|
|
|
|
return $this->getRevisionSlotsUpdate()->getRemovedRoles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-02 23:55:07 +00:00
|
|
|
* Prepare derived data updates targeting the given RevisionRecord.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
|
|
|
|
* Calling this method requires the given revision to be present in the database.
|
|
|
|
|
* This may be right after a new revision has been created, or when re-generating
|
|
|
|
|
* derived data e.g. in ApiPurge, RefreshLinksJob, and the refreshLinks
|
|
|
|
|
* script.
|
|
|
|
|
*
|
2020-01-05 22:22:48 +00:00
|
|
|
* @see docs/pageupdater.md for more information on when thie method can and should be called.
|
2018-01-27 01:48:19 +00:00
|
|
|
*
|
2018-07-26 16:31:49 +00:00
|
|
|
* @note Calling this method more than once with the same revision has no effect.
|
2018-01-27 01:48:19 +00:00
|
|
|
* $options are only used for the first call. Calling this method multiple times with
|
|
|
|
|
* different revisions will cause an exception.
|
|
|
|
|
*
|
2018-07-26 16:31:49 +00:00
|
|
|
* @note If grabCurrentRevision() (or prepareContent()) has been called before
|
2018-01-27 01:48:19 +00:00
|
|
|
* calling this method, $revision->getParentRevision() has to refer to the revision that
|
|
|
|
|
* was the current revision at the time grabCurrentRevision() was called.
|
|
|
|
|
*
|
|
|
|
|
* @param RevisionRecord $revision
|
|
|
|
|
* @param array $options Array of options, following indexes are used:
|
|
|
|
|
* - changed: bool, whether the revision changed the content (default true)
|
|
|
|
|
* - created: bool, whether the revision created the page (default false)
|
|
|
|
|
* - moved: bool, whether the page was moved (default false)
|
|
|
|
|
* - restored: bool, whether the page was undeleted (default false)
|
2020-06-20 09:47:39 +00:00
|
|
|
* - oldrevision: RevisionRecord object for the pre-update revision (default null)
|
2018-08-28 15:34:25 +00:00
|
|
|
* - triggeringUser: The user triggering the update (UserIdentity, defaults to the
|
|
|
|
|
* user who created the revision)
|
2018-01-27 01:48:19 +00:00
|
|
|
* - oldredirect: bool, null, or string 'no-change' (default null):
|
|
|
|
|
* - bool: whether the page was counted as a redirect before that
|
|
|
|
|
* revision, only used in changed is true and created is false
|
|
|
|
|
* - null or 'no-change': don't update the redirect status.
|
|
|
|
|
* - oldcountable: bool, null, or string 'no-change' (default null):
|
|
|
|
|
* - bool: whether the page was counted as an article before that
|
|
|
|
|
* revision, only used in changed is true and created is false
|
|
|
|
|
* - null: if created is false, don't update the article count; if created
|
|
|
|
|
* is true, do update the article count
|
|
|
|
|
* - 'no-change': don't update the article count, ever
|
2018-08-01 12:22:37 +00:00
|
|
|
* When set to null, pageState['oldCountable'] will be used instead if available.
|
2018-08-28 15:34:25 +00:00
|
|
|
* - causeAction: an arbitrary string identifying the reason for the update.
|
|
|
|
|
* See DataUpdate::getCauseAction(). (default 'unknown')
|
|
|
|
|
* - causeAgent: name of the user who caused the update. See DataUpdate::getCauseAgent().
|
|
|
|
|
* (string, default 'unknown')
|
2019-04-02 08:25:48 +00:00
|
|
|
* - known-revision-output: a combined canonical ParserOutput for the revision, perhaps
|
|
|
|
|
* from some cache. The caller is responsible for ensuring that the ParserOutput indeed
|
|
|
|
|
* matched the $rev and $options. This mechanism is intended as a temporary stop-gap,
|
|
|
|
|
* for the time until caches have been changed to store RenderedRevision states instead
|
|
|
|
|
* of ParserOutput objects. (default: null) (since 1.33)
|
2020-07-06 11:47:22 +00:00
|
|
|
* - editResult: EditResult object created during the update. Required to perform reverted
|
|
|
|
|
* tag update using RevertedTagUpdateJob. (default: null) (since 1.36)
|
|
|
|
|
* - approved: whether the edit is somehow "approved" and the RevertedTagUpdateJob should
|
|
|
|
|
* be scheduled right away. Required only if EditResult::isRevert() is true. (boolean,
|
|
|
|
|
* default: false) (since 1.36)
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
public function prepareUpdate( RevisionRecord $revision, array $options = [] ) {
|
|
|
|
|
Assert::parameter(
|
|
|
|
|
!isset( $options['oldrevision'] )
|
|
|
|
|
|| $options['oldrevision'] instanceof RevisionRecord,
|
|
|
|
|
'$options["oldrevision"]',
|
2021-05-02 02:44:33 +00:00
|
|
|
'must be a RevisionRecord'
|
2018-01-27 01:48:19 +00:00
|
|
|
);
|
|
|
|
|
Assert::parameter(
|
2018-08-28 15:34:25 +00:00
|
|
|
!isset( $options['triggeringUser'] )
|
|
|
|
|
|| $options['triggeringUser'] instanceof UserIdentity,
|
|
|
|
|
'$options["triggeringUser"]',
|
2018-01-27 01:48:19 +00:00
|
|
|
'must be a UserIdentity'
|
|
|
|
|
);
|
2020-07-06 11:47:22 +00:00
|
|
|
Assert::parameter(
|
|
|
|
|
!isset( $options['editResult'] )
|
|
|
|
|
|| $options['editResult'] instanceof EditResult,
|
|
|
|
|
'$options["editResult"]',
|
|
|
|
|
'must be an EditResult'
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
if ( !$revision->getId() ) {
|
|
|
|
|
throw new InvalidArgumentException(
|
|
|
|
|
'Revision must have an ID set for it to be used with prepareUpdate()!'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $this->revision && $this->revision->getId() ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
if ( $this->revision->getId() === $revision->getId() ) {
|
|
|
|
|
return; // nothing to do!
|
|
|
|
|
} else {
|
|
|
|
|
throw new LogicException(
|
|
|
|
|
'Trying to re-use DerivedPageDataUpdater with revision '
|
2018-09-07 17:01:32 +00:00
|
|
|
. $revision->getId()
|
2018-01-27 01:48:19 +00:00
|
|
|
. ', but it\'s already bound to revision '
|
|
|
|
|
. $this->revision->getId()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $this->revision
|
|
|
|
|
&& !$this->revision->getSlots()->hasSameContent( $revision->getSlots() )
|
2018-01-27 01:48:19 +00:00
|
|
|
) {
|
|
|
|
|
throw new LogicException(
|
2021-05-02 23:55:07 +00:00
|
|
|
'The revision provided has mismatching content!'
|
2018-01-27 01:48:19 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override fields defined in $this->options with values from $options.
|
|
|
|
|
$this->options = array_intersect_key( $options, $this->options ) + $this->options;
|
|
|
|
|
|
2018-11-24 15:59:58 +00:00
|
|
|
if ( $this->revision ) {
|
|
|
|
|
$oldId = $this->pageState['oldId'] ?? 0;
|
|
|
|
|
$this->options['newrev'] = ( $revision->getId() !== $oldId );
|
2018-01-27 01:48:19 +00:00
|
|
|
} elseif ( isset( $this->options['oldrevision'] ) ) {
|
2020-06-20 09:47:39 +00:00
|
|
|
/** @var RevisionRecord $oldRev */
|
2018-01-27 01:48:19 +00:00
|
|
|
$oldRev = $this->options['oldrevision'];
|
|
|
|
|
$oldId = $oldRev->getId();
|
2018-11-24 15:59:58 +00:00
|
|
|
$this->options['newrev'] = ( $revision->getId() !== $oldId );
|
2018-01-27 01:48:19 +00:00
|
|
|
} else {
|
|
|
|
|
$oldId = $revision->getParentId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $oldId !== null ) {
|
|
|
|
|
// XXX: what if $options['changed'] disagrees?
|
|
|
|
|
// MovePage creates a dummy revision with changed = false!
|
|
|
|
|
// We may want to explicitly distinguish between "no new revision" (null-edit)
|
|
|
|
|
// and "new revision without new content" (dummy revision).
|
|
|
|
|
|
|
|
|
|
if ( $oldId === $revision->getParentId() ) {
|
|
|
|
|
// NOTE: this may still be a NullRevision!
|
|
|
|
|
// New revision!
|
|
|
|
|
$this->options['changed'] = true;
|
|
|
|
|
} elseif ( $oldId === $revision->getId() ) {
|
|
|
|
|
// Null-edit!
|
|
|
|
|
$this->options['changed'] = false;
|
|
|
|
|
} else {
|
2021-05-02 23:55:07 +00:00
|
|
|
// This indicates that calling code has given us the wrong RevisionRecord object
|
2018-01-27 01:48:19 +00:00
|
|
|
throw new LogicException(
|
2021-05-02 23:55:07 +00:00
|
|
|
'The RevisionRecord mismatches old revision ID: '
|
2018-01-27 01:48:19 +00:00
|
|
|
. 'Old ID is ' . $oldId
|
|
|
|
|
. ', parent ID is ' . $revision->getParentId()
|
|
|
|
|
. ', revision ID is ' . $revision->getId()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If prepareContent() was used to generate the PST content (which is indicated by
|
|
|
|
|
// $this->slotsUpdate being set), and this is not a null-edit, then the given
|
|
|
|
|
// revision must have the acting user as the revision author. Otherwise, user
|
|
|
|
|
// signatures generated by PST would mismatch the user in the revision record.
|
|
|
|
|
if ( $this->user !== null && $this->options['changed'] && $this->slotsUpdate ) {
|
|
|
|
|
$user = $revision->getUser();
|
|
|
|
|
if ( !$this->user->equals( $user ) ) {
|
|
|
|
|
throw new LogicException(
|
2021-05-02 23:55:07 +00:00
|
|
|
'The RevisionRecord provided has a mismatching actor: expected '
|
2018-09-07 17:01:32 +00:00
|
|
|
. $this->user->getName()
|
2018-01-27 01:48:19 +00:00
|
|
|
. ', got '
|
|
|
|
|
. $user->getName()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If $this->pageState was not yet initialized by grabCurrentRevision or prepareContent,
|
|
|
|
|
// emulate the state of the page table before the edit, as good as we can.
|
|
|
|
|
if ( !$this->pageState ) {
|
|
|
|
|
$this->pageState = [
|
|
|
|
|
'oldIsRedirect' => isset( $this->options['oldredirect'] )
|
|
|
|
|
&& is_bool( $this->options['oldredirect'] )
|
|
|
|
|
? $this->options['oldredirect']
|
|
|
|
|
: null,
|
|
|
|
|
'oldCountable' => isset( $this->options['oldcountable'] )
|
|
|
|
|
&& is_bool( $this->options['oldcountable'] )
|
|
|
|
|
? $this->options['oldcountable']
|
|
|
|
|
: null,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ( $this->options['changed'] ) {
|
|
|
|
|
// The edit created a new revision
|
|
|
|
|
$this->pageState['oldId'] = $revision->getParentId();
|
|
|
|
|
|
|
|
|
|
if ( isset( $this->options['oldrevision'] ) ) {
|
|
|
|
|
$rev = $this->options['oldrevision'];
|
2020-06-20 09:47:39 +00:00
|
|
|
$this->pageState['oldRevision'] = $rev;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// This is a null-edit, so the old revision IS the new revision!
|
|
|
|
|
$this->pageState['oldId'] = $revision->getId();
|
|
|
|
|
$this->pageState['oldRevision'] = $revision;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "created" is forced here
|
2019-05-09 00:56:15 +00:00
|
|
|
$this->options['created'] = ( $this->options['created'] ||
|
|
|
|
|
( $this->pageState['oldId'] === 0 ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->revision = $revision;
|
|
|
|
|
|
|
|
|
|
$this->doTransition( 'has-revision' );
|
|
|
|
|
|
|
|
|
|
// NOTE: in case we have a User object, don't override with a UserIdentity.
|
|
|
|
|
// We already checked that $revision->getUser() mathces $this->user;
|
|
|
|
|
if ( !$this->user ) {
|
|
|
|
|
$this->user = $revision->getUser( RevisionRecord::RAW );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prune any output that depends on the revision ID.
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( $this->renderedRevision ) {
|
|
|
|
|
$this->renderedRevision->updateRevision( $revision );
|
2018-11-15 16:40:53 +00:00
|
|
|
} else {
|
|
|
|
|
// NOTE: we want a canonical rendering, so don't pass $this->user or ParserOptions
|
|
|
|
|
// NOTE: the revision is either new or current, so we can bypass audience checks.
|
|
|
|
|
$this->renderedRevision = $this->revisionRenderer->getRenderedRevision(
|
|
|
|
|
$this->revision,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
2019-04-02 08:25:48 +00:00
|
|
|
[
|
2021-09-02 23:10:56 +00:00
|
|
|
'use-master' => $this->usePrimary(),
|
2019-04-02 08:25:48 +00:00
|
|
|
'audience' => RevisionRecord::RAW,
|
|
|
|
|
'known-revision-output' => $options['known-revision-output'] ?? null
|
|
|
|
|
]
|
2018-11-15 16:40:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// XXX: Since we presumably are dealing with the current revision,
|
|
|
|
|
// we could try to get the ParserOutput from the parser cache.
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: optionally get ParserOutput from the ParserCache here.
|
|
|
|
|
// Move the logic used by RefreshLinksJob here!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated This only exists for B/C, use the getters on DerivedPageDataUpdater directly!
|
|
|
|
|
* @return PreparedEdit
|
|
|
|
|
*/
|
|
|
|
|
public function getPreparedEdit() {
|
|
|
|
|
$this->assertPrepared( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$slotsUpdate = $this->getRevisionSlotsUpdate();
|
|
|
|
|
$preparedEdit = new PreparedEdit();
|
|
|
|
|
|
|
|
|
|
$preparedEdit->popts = $this->getCanonicalParserOptions();
|
2018-10-26 22:42:26 +00:00
|
|
|
$preparedEdit->parserOutputCallback = [ $this, 'getCanonicalParserOutput' ];
|
2018-09-24 21:10:08 +00:00
|
|
|
$preparedEdit->pstContent = $this->revision->getContent( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
$preparedEdit->newContent =
|
2018-09-24 21:10:08 +00:00
|
|
|
$slotsUpdate->isModifiedSlot( SlotRecord::MAIN )
|
|
|
|
|
? $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent()
|
|
|
|
|
: $this->revision->getContent( SlotRecord::MAIN ); // XXX: can we just remove this?
|
2018-01-27 01:48:19 +00:00
|
|
|
$preparedEdit->oldContent = null; // unused. // XXX: could get this from the parent revision
|
|
|
|
|
$preparedEdit->revid = $this->revision ? $this->revision->getId() : null;
|
|
|
|
|
$preparedEdit->timestamp = $preparedEdit->output->getCacheTime();
|
|
|
|
|
$preparedEdit->format = $preparedEdit->pstContent->getDefaultFormat();
|
|
|
|
|
|
|
|
|
|
return $preparedEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $role
|
|
|
|
|
* @param bool $generateHtml
|
|
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function getSlotParserOutput( $role, $generateHtml = true ) {
|
2018-08-13 20:33:31 +00:00
|
|
|
return $this->getRenderedRevision()->getSlotParserOutput(
|
|
|
|
|
$role,
|
|
|
|
|
[ 'generate-html' => $generateHtml ]
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function getParserOutputForMetaData(): ParserOutput {
|
|
|
|
|
return $this->getRenderedRevision()->getRevisionParserOutput( [ 'generate-html' => false ] );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @return ParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function getCanonicalParserOutput() {
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->getRenderedRevision()->getRevisionParserOutput();
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return ParserOptions
|
|
|
|
|
*/
|
|
|
|
|
public function getCanonicalParserOptions() {
|
2018-08-07 16:52:40 +00:00
|
|
|
return $this->getRenderedRevision()->getOptions();
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bool $recursive
|
|
|
|
|
*
|
2018-03-09 22:05:47 +00:00
|
|
|
* @return DeferrableUpdate[]
|
2018-01-27 01:48:19 +00:00
|
|
|
*/
|
|
|
|
|
public function getSecondaryDataUpdates( $recursive = false ) {
|
2018-03-09 22:05:47 +00:00
|
|
|
if ( $this->isContentDeleted() ) {
|
|
|
|
|
// This shouldn't happen, since the current content is always public,
|
|
|
|
|
// and DataUpates are only needed for current content.
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 21:54:08 +00:00
|
|
|
$wikiPage = $this->getWikiPage();
|
|
|
|
|
$wikiPage->loadPageData( WikiPage::READ_LATEST );
|
|
|
|
|
if ( !$wikiPage->exists() ) {
|
|
|
|
|
// page deleted while defering the update
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = $wikiPage->getTitle();
|
2021-08-16 14:34:58 +00:00
|
|
|
$allUpdates = [];
|
|
|
|
|
$parserOutput = $this->shouldGenerateHTMLOnEdit() ?
|
|
|
|
|
$this->getCanonicalParserOutput() : $this->getParserOutputForMetaData();
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
// Construct a LinksUpdate for the combined canonical output.
|
|
|
|
|
$linksUpdate = new LinksUpdate(
|
2021-02-17 21:54:08 +00:00
|
|
|
$title,
|
2021-08-16 14:34:58 +00:00
|
|
|
$parserOutput,
|
2018-03-09 22:05:47 +00:00
|
|
|
$recursive
|
2018-01-27 01:48:19 +00:00
|
|
|
);
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
$allUpdates[] = $linksUpdate;
|
2018-03-09 22:05:47 +00:00
|
|
|
// NOTE: Run updates for all slots, not just the modified slots! Otherwise,
|
|
|
|
|
// info for an inherited slot may end up being removed. This is also needed
|
|
|
|
|
// to ensure that purges are effective.
|
|
|
|
|
$renderedRevision = $this->getRenderedRevision();
|
2021-08-16 14:34:58 +00:00
|
|
|
|
2018-03-09 22:05:47 +00:00
|
|
|
foreach ( $this->getSlots()->getSlotRoles() as $role ) {
|
|
|
|
|
$slot = $this->getRawSlot( $role );
|
|
|
|
|
$content = $slot->getContent();
|
|
|
|
|
$handler = $content->getContentHandler();
|
|
|
|
|
|
|
|
|
|
$updates = $handler->getSecondaryDataUpdates(
|
2021-02-17 21:54:08 +00:00
|
|
|
$title,
|
2018-03-09 22:05:47 +00:00
|
|
|
$content,
|
|
|
|
|
$role,
|
|
|
|
|
$renderedRevision
|
|
|
|
|
);
|
|
|
|
|
|
2021-07-22 09:56:07 +00:00
|
|
|
$allUpdates = array_merge( $allUpdates, $updates );
|
2018-03-09 22:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX: if a slot was removed by an earlier edit, but deletion updates failed to run at
|
|
|
|
|
// that time, we don't know for which slots to run deletion updates when purging a page.
|
|
|
|
|
// We'd have to examine the entire history of the page to determine that. Perhaps there
|
|
|
|
|
// could be a "try extra hard" mode for that case that would run a DB query to find all
|
|
|
|
|
// roles/models ever used on the page. On the other hand, removing slots should be quite
|
|
|
|
|
// rare, so perhaps this isn't worth the trouble.
|
|
|
|
|
|
|
|
|
|
// TODO: consolidate with similar logic in WikiPage::getDeletionUpdates()
|
|
|
|
|
$parentRevision = $this->getParentRevision();
|
|
|
|
|
foreach ( $this->getRemovedSlotRoles() as $role ) {
|
|
|
|
|
// HACK: we should get the content model of the removed slot from a SlotRoleHandler!
|
|
|
|
|
// For now, find the slot in the parent revision - if the slot was removed, it should
|
|
|
|
|
// always exist in the parent revision.
|
|
|
|
|
$parentSlot = $parentRevision->getSlot( $role, RevisionRecord::RAW );
|
|
|
|
|
$content = $parentSlot->getContent();
|
|
|
|
|
$handler = $content->getContentHandler();
|
|
|
|
|
|
|
|
|
|
$updates = $handler->getDeletionUpdates(
|
2021-02-17 21:54:08 +00:00
|
|
|
$title,
|
2018-03-09 22:05:47 +00:00
|
|
|
$role
|
|
|
|
|
);
|
|
|
|
|
|
2021-07-21 11:28:35 +00:00
|
|
|
$allUpdates = array_merge( $allUpdates, $updates );
|
2018-03-09 22:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: hard deprecate SecondaryDataUpdates in favor of RevisionDataUpdates in 1.33!
|
2021-02-17 21:54:08 +00:00
|
|
|
$this->hookRunner->onRevisionDataUpdates( $title, $renderedRevision, $allUpdates );
|
2018-03-09 22:05:47 +00:00
|
|
|
|
|
|
|
|
return $allUpdates;
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool true if at least one of slots require rendering HTML on edit, false otherwise.
|
|
|
|
|
* This is needed for example in populating ParserCache.
|
|
|
|
|
*/
|
|
|
|
|
private function shouldGenerateHTMLOnEdit(): bool {
|
|
|
|
|
foreach ( $this->getSlots()->getSlotRoles() as $role ) {
|
|
|
|
|
$slot = $this->getRawSlot( $role );
|
|
|
|
|
$contentHandler = $this->contentHandlerFactory->getContentHandler( $slot->getModel() );
|
|
|
|
|
if ( $contentHandler->generateHTMLOnEdit() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* Do standard updates after page edit, purge, or import.
|
|
|
|
|
* Update links tables, site stats, search index, title cache, message cache, etc.
|
|
|
|
|
* Purges pages that depend on this page when appropriate.
|
|
|
|
|
* With a 10% chance, triggers pruning the recent changes table.
|
|
|
|
|
*
|
|
|
|
|
* @note prepareUpdate() must be called before calling this method!
|
|
|
|
|
*
|
|
|
|
|
* MCR migration note: this replaces WikiPage::doEditUpdates.
|
|
|
|
|
*/
|
|
|
|
|
public function doUpdates() {
|
|
|
|
|
$this->assertTransition( 'done' );
|
|
|
|
|
|
|
|
|
|
// TODO: move logic into a PageEventEmitter service
|
|
|
|
|
|
|
|
|
|
$wikiPage = $this->getWikiPage(); // TODO: use only for legacy hooks!
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
if ( $this->shouldGenerateHTMLOnEdit() ) {
|
|
|
|
|
$this->triggerParserCacheUpdate();
|
2018-10-26 22:42:26 +00:00
|
|
|
}
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2019-03-19 16:03:36 +00:00
|
|
|
$this->doSecondaryDataUpdates( [
|
|
|
|
|
// T52785 do not update any other pages on a null edit
|
|
|
|
|
'recursive' => $this->options['changed'],
|
|
|
|
|
// Defer the getCannonicalParserOutput() call made by getSecondaryDataUpdates()
|
|
|
|
|
'defer' => DeferredUpdates::POSTSEND
|
|
|
|
|
] );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: MCR: check if *any* changed slot supports categories!
|
|
|
|
|
if ( $this->rcWatchCategoryMembership
|
2018-09-24 21:10:08 +00:00
|
|
|
&& $this->getContentHandler( SlotRecord::MAIN )->supportsCategories() === true
|
2018-01-27 01:48:19 +00:00
|
|
|
&& ( $this->options['changed'] || $this->options['created'] )
|
|
|
|
|
&& !$this->options['restored']
|
|
|
|
|
) {
|
|
|
|
|
// Note: jobs are pushed after deferred updates, so the job should be able to see
|
|
|
|
|
// the recent change entry (also done via deferred updates) and carry over any
|
|
|
|
|
// bot/deletion/IP flags, ect.
|
|
|
|
|
$this->jobQueueGroup->lazyPush(
|
2018-11-14 17:07:20 +00:00
|
|
|
CategoryMembershipChangeJob::newSpec(
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->getTitle(),
|
2018-11-14 17:07:20 +00:00
|
|
|
$this->revision->getTimestamp()
|
2018-01-27 01:48:19 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = $this->getPageId();
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
$shortTitle = $title->getDBkey();
|
|
|
|
|
|
|
|
|
|
if ( !$title->exists() ) {
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __METHOD__ . ": Page doesn't exist any more, bailing out" );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->doTransition( 'done' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 00:05:40 +00:00
|
|
|
DeferredUpdates::addCallableUpdate( function () {
|
|
|
|
|
if (
|
|
|
|
|
$this->options['oldcountable'] === 'no-change' ||
|
|
|
|
|
( !$this->options['changed'] && !$this->options['moved'] )
|
|
|
|
|
) {
|
|
|
|
|
$good = 0;
|
|
|
|
|
} elseif ( $this->options['created'] ) {
|
|
|
|
|
$good = (int)$this->isCountable();
|
|
|
|
|
} elseif ( $this->options['oldcountable'] !== null ) {
|
|
|
|
|
$good = (int)$this->isCountable()
|
|
|
|
|
- (int)$this->options['oldcountable'];
|
|
|
|
|
} elseif ( isset( $this->pageState['oldCountable'] ) ) {
|
|
|
|
|
$good = (int)$this->isCountable()
|
|
|
|
|
- (int)$this->pageState['oldCountable'];
|
|
|
|
|
} else {
|
|
|
|
|
$good = 0;
|
|
|
|
|
}
|
|
|
|
|
$edits = $this->options['changed'] ? 1 : 0;
|
|
|
|
|
$pages = $this->options['created'] ? 1 : 0;
|
2018-01-27 01:48:19 +00:00
|
|
|
|
2019-04-20 00:05:40 +00:00
|
|
|
DeferredUpdates::addUpdate( SiteStatsUpdate::factory(
|
|
|
|
|
[ 'edits' => $edits, 'articles' => $good, 'pages' => $pages ]
|
|
|
|
|
) );
|
|
|
|
|
} );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: make search infrastructure aware of slots!
|
2018-09-24 21:10:08 +00:00
|
|
|
$mainSlot = $this->revision->getSlot( SlotRecord::MAIN );
|
2018-08-07 16:52:40 +00:00
|
|
|
if ( !$mainSlot->isInherited() && !$this->isContentDeleted() ) {
|
2019-08-01 10:13:45 +00:00
|
|
|
DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $mainSlot->getContent() ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If this is another user's talk page, update newtalk.
|
|
|
|
|
// Don't do this if $options['changed'] = false (null-edits) nor if
|
|
|
|
|
// it's a minor edit and the user making the edit doesn't generate notifications for those.
|
2021-02-23 14:51:23 +00:00
|
|
|
// TODO: the permission check should be performed by the callers, see T276181.
|
2018-01-27 01:48:19 +00:00
|
|
|
if ( $this->options['changed']
|
2020-07-22 17:29:48 +00:00
|
|
|
&& $title->getNamespace() === NS_USER_TALK
|
2021-10-15 14:12:55 +00:00
|
|
|
&& $title->getText() != $this->user->getName()
|
2021-06-05 21:10:29 +00:00
|
|
|
&& !( $this->revision->isMinor() && $this->permissionManager
|
2021-05-22 03:34:24 +00:00
|
|
|
->userHasRight( $this->user, 'nominornewtalk' )
|
|
|
|
|
)
|
2018-01-27 01:48:19 +00:00
|
|
|
) {
|
|
|
|
|
$recipient = User::newFromName( $shortTitle, false );
|
|
|
|
|
if ( !$recipient ) {
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __METHOD__ . ": invalid username" );
|
2018-01-27 01:48:19 +00:00
|
|
|
} else {
|
|
|
|
|
// Allow extensions to prevent user notification
|
|
|
|
|
// when a new message is added to their talk page
|
|
|
|
|
// TODO: replace legacy hook! Use a listener on PageEventEmitter instead!
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
if ( $this->hookRunner->onArticleEditUpdateNewTalk( $wikiPage, $recipient ) ) {
|
2020-04-08 18:09:11 +00:00
|
|
|
$revRecord = $this->revision;
|
2021-04-12 14:45:26 +00:00
|
|
|
if ( $this->userNameUtils->isIP( $shortTitle ) ) {
|
2018-01-27 01:48:19 +00:00
|
|
|
// An anonymous user
|
2021-06-05 21:10:29 +00:00
|
|
|
$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
|
2020-12-17 23:10:11 +00:00
|
|
|
} elseif ( $recipient->isRegistered() ) {
|
2021-06-05 21:10:29 +00:00
|
|
|
$this->talkPageNotificationManager->setUserHasNewMessages( $recipient, $revRecord );
|
2018-01-27 01:48:19 +00:00
|
|
|
} else {
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( __METHOD__ . ": don't need to notify a nonexistent user" );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 17:29:48 +00:00
|
|
|
if ( $title->getNamespace() === NS_MEDIAWIKI
|
2018-09-24 21:10:08 +00:00
|
|
|
&& $this->getRevisionSlotsUpdate()->isModifiedSlot( SlotRecord::MAIN )
|
2018-01-27 01:48:19 +00:00
|
|
|
) {
|
2018-09-24 21:10:08 +00:00
|
|
|
$mainContent = $this->isContentDeleted() ? null : $this->getRawContent( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->messageCache->updateMessageOverride( $title, $mainContent );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: move onArticleCreate and onArticle into a PageEventEmitter service
|
|
|
|
|
if ( $this->options['created'] ) {
|
|
|
|
|
WikiPage::onArticleCreate( $title );
|
|
|
|
|
} elseif ( $this->options['changed'] ) { // T52785
|
2020-04-10 06:12:41 +00:00
|
|
|
WikiPage::onArticleEdit( $title, $this->revision, $this->getTouchedSlotRoles() );
|
2019-11-21 15:21:41 +00:00
|
|
|
} elseif ( $this->options['restored'] ) {
|
2021-06-05 21:10:29 +00:00
|
|
|
$this->mainWANObjectCache->touchCheckKey(
|
2019-11-21 15:21:41 +00:00
|
|
|
"DerivedPageDataUpdater:restore:page:$id"
|
|
|
|
|
);
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-08 18:09:11 +00:00
|
|
|
$oldRevisionRecord = $this->getParentRevision();
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: In the wiring, register a listener for this on the new PageEventEmitter
|
|
|
|
|
ResourceLoaderWikiModule::invalidateModuleCache(
|
2019-07-04 07:31:06 +00:00
|
|
|
$title,
|
2020-04-08 18:09:11 +00:00
|
|
|
$oldRevisionRecord,
|
|
|
|
|
$this->revision,
|
2019-07-04 07:31:06 +00:00
|
|
|
$this->loadbalancerFactory->getLocalDomainID()
|
2018-01-27 01:48:19 +00:00
|
|
|
);
|
|
|
|
|
|
2020-07-06 11:47:22 +00:00
|
|
|
// Schedule a deferred update for marking reverted edits if applicable.
|
|
|
|
|
$this->maybeEnqueueRevertedTagUpdateJob();
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->doTransition( 'done' );
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:34:58 +00:00
|
|
|
private function triggerParserCacheUpdate() {
|
|
|
|
|
$userParserOptions = ParserOptions::newFromUser( $this->user );
|
|
|
|
|
// Decide whether to save the final canonical parser output based on the fact that
|
|
|
|
|
// users are typically redirected to viewing pages right after they edit those pages.
|
|
|
|
|
// Due to vary-revision-id, getting/saving that output here might require a reparse.
|
|
|
|
|
if ( $userParserOptions->matchesForCacheKey( $this->getCanonicalParserOptions() ) ) {
|
|
|
|
|
// Whether getting the final output requires a reparse or not, the user will
|
|
|
|
|
// need canonical output anyway, since that is what their parser options use.
|
|
|
|
|
// A reparse now at least has the benefit of various warm process caches.
|
|
|
|
|
$this->doParserCacheUpdate();
|
|
|
|
|
} else {
|
|
|
|
|
// If the user does not have canonical parse options, then don't risk another parse
|
|
|
|
|
// to make output they cannot use on the page refresh that typically occurs after
|
|
|
|
|
// editing. Doing the parser output save post-send will still benefit *other* users.
|
|
|
|
|
DeferredUpdates::addCallableUpdate( function () {
|
|
|
|
|
$this->doParserCacheUpdate();
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 11:47:22 +00:00
|
|
|
/**
|
|
|
|
|
* If the edit was a revert and it is considered "approved", enqueues the
|
|
|
|
|
* RevertedTagUpdateJob for it. If the edit is not yet approved, the EditResult is
|
|
|
|
|
* persisted in cache for later use.
|
|
|
|
|
*/
|
|
|
|
|
private function maybeEnqueueRevertedTagUpdateJob() {
|
|
|
|
|
if ( $this->options['editResult'] === null ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$editResult = $this->options['editResult'];
|
|
|
|
|
if ( !$editResult->isRevert() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->options['approved'] ) {
|
|
|
|
|
// Enqueue the job
|
|
|
|
|
$this->jobQueueGroup->lazyPush(
|
|
|
|
|
RevertedTagUpdateJob::newSpec(
|
|
|
|
|
$this->revision->getId(),
|
|
|
|
|
$this->options['editResult']
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Cache EditResult for later use
|
|
|
|
|
$this->editResultCache->set(
|
|
|
|
|
$this->revision->getId(),
|
|
|
|
|
$this->options['editResult']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-28 15:34:25 +00:00
|
|
|
/**
|
2019-03-19 16:03:36 +00:00
|
|
|
* Do secondary data updates (e.g. updating link tables) or schedule them as deferred updates
|
2018-08-28 15:34:25 +00:00
|
|
|
*
|
|
|
|
|
* MCR note: this method is temporarily exposed via WikiPage::doSecondaryDataUpdates.
|
|
|
|
|
*
|
|
|
|
|
* @param array $options
|
|
|
|
|
* - recursive: make the update recursive, i.e. also update pages which transclude the
|
|
|
|
|
* current page or otherwise depend on it (default: false)
|
|
|
|
|
* - defer: one of the DeferredUpdates constants, or false to run immediately after waiting
|
|
|
|
|
* for replication of the changes from the SecondaryDataUpdates hooks (default: false)
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
public function doSecondaryDataUpdates( array $options = [] ) {
|
|
|
|
|
$this->assertHasRevision( __METHOD__ );
|
2019-05-29 21:07:03 +00:00
|
|
|
$options += [ 'recursive' => false, 'defer' => false ];
|
2018-08-28 15:34:25 +00:00
|
|
|
$deferValues = [ false, DeferredUpdates::PRESEND, DeferredUpdates::POSTSEND ];
|
|
|
|
|
if ( !in_array( $options['defer'], $deferValues, true ) ) {
|
2019-05-24 21:01:17 +00:00
|
|
|
throw new InvalidArgumentException( 'Invalid value for defer: ' . $options['defer'] );
|
2018-08-28 15:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$triggeringUser = $this->options['triggeringUser'] ?? $this->user;
|
|
|
|
|
$causeAction = $this->options['causeAction'] ?? 'unknown';
|
|
|
|
|
$causeAgent = $this->options['causeAgent'] ?? 'unknown';
|
|
|
|
|
|
2019-03-19 16:03:36 +00:00
|
|
|
// Bundle all of the data updates into a single deferred update wrapper so that
|
|
|
|
|
// any failure will cause at most one refreshLinks job to be enqueued by
|
|
|
|
|
// DeferredUpdates::doUpdates(). This is hard to do when there are many separate
|
|
|
|
|
// updates that are not defined as being related.
|
|
|
|
|
$update = new RefreshSecondaryDataUpdate(
|
|
|
|
|
$this->loadbalancerFactory,
|
|
|
|
|
$triggeringUser,
|
|
|
|
|
$this->wikiPage,
|
|
|
|
|
$this->revision,
|
|
|
|
|
$this,
|
|
|
|
|
[ 'recursive' => $options['recursive'] ]
|
|
|
|
|
);
|
|
|
|
|
$update->setCause( $causeAction, $causeAgent );
|
2019-03-29 01:06:59 +00:00
|
|
|
|
2019-05-29 21:07:03 +00:00
|
|
|
if ( $options['defer'] === false ) {
|
2019-03-19 16:03:36 +00:00
|
|
|
DeferredUpdates::attemptUpdate( $update, $this->loadbalancerFactory );
|
2019-05-29 21:07:03 +00:00
|
|
|
} else {
|
2019-03-19 16:03:36 +00:00
|
|
|
DeferredUpdates::addUpdate( $update, $options['defer'] );
|
2018-08-28 15:34:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doParserCacheUpdate() {
|
|
|
|
|
$this->assertHasRevision( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$wikiPage = $this->getWikiPage(); // TODO: ParserCache should accept a RevisionRecord instead
|
|
|
|
|
|
|
|
|
|
// NOTE: this may trigger the first parsing of the new content after an edit (when not
|
|
|
|
|
// using pre-generated stashed output).
|
|
|
|
|
// XXX: we may want to use the PoolCounter here. This would perhaps allow the initial parse
|
|
|
|
|
// to be performed post-send. The client could already follow a HTTP redirect to the
|
|
|
|
|
// page view, but would then have to wait for a response until rendering is complete.
|
|
|
|
|
$output = $this->getCanonicalParserOutput();
|
|
|
|
|
|
|
|
|
|
// Save it to the parser cache. Use the revision timestamp in the case of a
|
|
|
|
|
// freshly saved edit, as that matches page_touched and a mismatch would trigger an
|
|
|
|
|
// unnecessary reparse.
|
2018-11-24 15:59:58 +00:00
|
|
|
$timestamp = $this->options['newrev'] ? $this->revision->getTimestamp()
|
|
|
|
|
: $output->getCacheTime();
|
2018-08-28 15:34:25 +00:00
|
|
|
$this->parserCache->save(
|
|
|
|
|
$output, $wikiPage, $this->getCanonicalParserOptions(),
|
|
|
|
|
$timestamp, $this->revision->getId()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|