2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-05-08 12:51:21 +00:00
|
|
|
* User interface for the difference engine.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
2010-08-08 11:55:47 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup DifferenceEngine
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
2022-12-11 00:33:56 +00:00
|
|
|
use MediaWiki\CommentFormatter\CommentFormatter;
|
2024-10-21 18:33:42 +00:00
|
|
|
use MediaWiki\Content\Content;
|
2020-01-18 20:25:04 +00:00
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\ContextSource;
|
|
|
|
|
use MediaWiki\Context\IContextSource;
|
2024-05-04 18:15:02 +00:00
|
|
|
use MediaWiki\Debug\DeprecationHelper;
|
2023-07-03 08:27:47 +00:00
|
|
|
use MediaWiki\Diff\TextDiffer\ManifoldTextDiffer;
|
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\HookRunner;
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2024-10-21 18:33:42 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2022-12-05 11:29:37 +00:00
|
|
|
use MediaWiki\Linker\Linker;
|
2019-09-07 09:27:30 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2022-04-25 15:19:41 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2018-11-27 17:48:18 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-06-16 18:18:23 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2022-12-18 00:22:42 +00:00
|
|
|
use MediaWiki\Page\ParserOutputAccess;
|
2020-11-11 21:36:36 +00:00
|
|
|
use MediaWiki\Page\WikiPageFactory;
|
2021-02-24 15:46:13 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2021-02-27 02:03:46 +00:00
|
|
|
use MediaWiki\Permissions\PermissionStatus;
|
2023-09-01 22:52:05 +00:00
|
|
|
use MediaWiki\Revision\ArchivedRevisionLookup;
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
use MediaWiki\Revision\BadRevisionException;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2020-03-26 22:40:22 +00:00
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2018-11-27 17:48:18 +00:00
|
|
|
use MediaWiki\Storage\NameTableAccessException;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-11-29 10:21:43 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2023-09-29 23:08:12 +00:00
|
|
|
use MediaWiki\User\UserEditTracker;
|
|
|
|
|
use MediaWiki\User\UserGroupManager;
|
2023-12-11 15:05:02 +00:00
|
|
|
use MediaWiki\User\UserGroupMembership;
|
2023-09-29 23:08:12 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
|
use MediaWiki\User\UserIdentityUtils;
|
2023-07-05 08:57:11 +00:00
|
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
2010-11-27 19:01:51 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
|
|
|
|
|
* This includes interpreting URL parameters, retrieving revision data, checking access permissions,
|
|
|
|
|
* selecting and invoking the diff generator class for the individual slots, doing post-processing
|
|
|
|
|
* on the generated diff, adding the rest of the HTML (such as headers) and writing the whole thing
|
|
|
|
|
* to OutputPage.
|
|
|
|
|
*
|
|
|
|
|
* DifferenceEngine can be subclassed by extensions, by customizing
|
|
|
|
|
* ContentHandler::createDifferenceEngine; the content handler will be selected based on the
|
|
|
|
|
* content model of the main slot (of the new revision, when the two are different).
|
|
|
|
|
* That might change after PageTypeHandler gets introduced.
|
|
|
|
|
*
|
|
|
|
|
* In the past, the class was also used for slot-level diff generation, and extensions might still
|
2021-12-26 11:24:49 +00:00
|
|
|
* subclass it and add such functionality. When that is the case (specifically, when a
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* ContentHandler returns a standard SlotDiffRenderer but a nonstandard DifferenceEngine)
|
|
|
|
|
* DifferenceEngineSlotDiffRenderer will be used to convert the old behavior into the new one.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup DifferenceEngine
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*
|
|
|
|
|
* @todo This class is huge and poorly defined. It should be split into a controller responsible
|
|
|
|
|
* for interpreting query parameters, retrieving data and checking permissions; and a HTML renderer.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2011-11-10 13:06:52 +00:00
|
|
|
class DifferenceEngine extends ContextSource {
|
2018-07-11 08:54:58 +00:00
|
|
|
|
|
|
|
|
use DeprecationHelper;
|
|
|
|
|
|
2016-07-20 21:10:02 +00:00
|
|
|
/**
|
|
|
|
|
* Constant to indicate diff cache compatibility.
|
|
|
|
|
* Bump this when changing the diff formatting in a way that
|
|
|
|
|
* fixes important bugs or such to force cached diff views to
|
|
|
|
|
* clear.
|
|
|
|
|
*/
|
2023-07-03 08:27:47 +00:00
|
|
|
private const DIFF_VERSION = '1.41';
|
2014-03-03 17:08:05 +00:00
|
|
|
|
2018-08-20 14:49:56 +00:00
|
|
|
/**
|
|
|
|
|
* Revision ID for the old revision. 0 for the revision previous to $mNewid, false
|
|
|
|
|
* if the diff does not have an old revision (e.g. 'oldid=<first revision of page>&diff=prev'),
|
|
|
|
|
* or the revision does not exist, null if the revision is unsaved.
|
|
|
|
|
* @var int|false|null
|
|
|
|
|
*/
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mOldid;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2018-08-20 14:49:56 +00:00
|
|
|
/**
|
|
|
|
|
* Revision ID for the new revision. 0 for the last revision of the current page
|
|
|
|
|
* (as defined by the request context), false if the revision does not exist, null
|
|
|
|
|
* if it is unsaved, or an alias such as 'next'.
|
|
|
|
|
* @var int|string|false|null
|
|
|
|
|
*/
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mNewid;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Old revision (left pane).
|
|
|
|
|
* Allowed to be an unsaved revision, unlikely that's ever needed though.
|
2018-08-20 14:49:56 +00:00
|
|
|
* False when the old revision does not exist; this can happen when using
|
|
|
|
|
* diff=prev on the first revision. Null when the revision should exist but
|
|
|
|
|
* doesn't (e.g. load failure); loadRevisionData() will return false in that
|
|
|
|
|
* case. Also null until lazy-loaded. Ignored completely when isContentOverridden
|
|
|
|
|
* is set.
|
2020-04-29 16:38:25 +00:00
|
|
|
* @var RevisionRecord|null|false
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
2020-04-29 16:38:25 +00:00
|
|
|
private $mOldRevisionRecord;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* New revision (right pane).
|
|
|
|
|
* Note that this might be an unsaved revision (e.g. for edit preview).
|
2018-08-20 14:49:56 +00:00
|
|
|
* Null in case of load failure; diff methods will just return an error message in that case,
|
|
|
|
|
* and loadRevisionData() will return false. Also null until lazy-loaded. Ignored completely
|
|
|
|
|
* when isContentOverridden is set.
|
2020-04-29 16:38:25 +00:00
|
|
|
* @var RevisionRecord|null
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
2020-04-29 16:38:25 +00:00
|
|
|
private $mNewRevisionRecord;
|
2011-02-19 21:44:20 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* Title of old revision or null if the old revision does not exist or does not belong to a page.
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @var Title|null
|
|
|
|
|
*/
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mOldPage;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* Title of new revision or null if the new revision does not exist or does not belong to a page.
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @var Title|null
|
|
|
|
|
*/
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mNewPage;
|
2011-02-19 21:44:20 +00:00
|
|
|
|
2018-08-20 14:49:56 +00:00
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* Change tags of old revision or null if it does not exist / is not saved.
|
2022-01-21 08:55:23 +00:00
|
|
|
* @var string|false|null
|
2018-08-20 14:49:56 +00:00
|
|
|
*/
|
|
|
|
|
private $mOldTags;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* Change tags of new revision or null if it does not exist / is not saved.
|
2022-01-21 08:55:23 +00:00
|
|
|
* @var string|null
|
2018-08-20 14:49:56 +00:00
|
|
|
*/
|
|
|
|
|
private $mNewTags;
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* @var Content|null
|
|
|
|
|
* @deprecated since 1.32, content slots are now handled by the corresponding SlotDiffRenderer.
|
|
|
|
|
* This property is set to the content of the main slot, but not actually used for the main diff.
|
|
|
|
|
*/
|
|
|
|
|
private $mOldContent;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Content|null
|
|
|
|
|
* @deprecated since 1.32, content slots are now handled by the corresponding SlotDiffRenderer.
|
|
|
|
|
* This property is set to the content of the main slot, but not actually used for the main diff.
|
|
|
|
|
*/
|
|
|
|
|
private $mNewContent;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2023-07-11 00:33:07 +00:00
|
|
|
/** @var Language */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
protected $mDiffLang;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
|
|
|
|
/** @var bool Have the revisions IDs been loaded */
|
|
|
|
|
private $mRevisionsIdsLoaded = false;
|
|
|
|
|
|
|
|
|
|
/** @var bool Have the revisions been loaded */
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mRevisionsLoaded = false;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
|
|
|
|
/** @var int How many text blobs have been loaded, 0, 1 or 2? */
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mTextLoaded = 0;
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2018-07-11 08:48:49 +00:00
|
|
|
/**
|
|
|
|
|
* Was the content overridden via setContent()?
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* If the content was overridden, most internal state (e.g. mOldid or mOldRev) should be ignored
|
|
|
|
|
* and only mOldContent and mNewContent is reliable.
|
|
|
|
|
* (Note that setRevisions() does not set this flag as in that case all properties are
|
2021-12-26 11:24:49 +00:00
|
|
|
* overridden and remain consistent with each other, so no special handling is needed.)
|
2018-07-11 08:48:49 +00:00
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $isContentOverridden = false;
|
|
|
|
|
|
2013-11-20 19:11:57 +00:00
|
|
|
/** @var bool Was the diff fetched from cache? */
|
2018-07-11 08:54:58 +00:00
|
|
|
protected $mCacheHit = false;
|
2004-04-17 07:37:55 +00:00
|
|
|
|
2023-06-10 14:32:48 +00:00
|
|
|
/** @var string|null Cache key if the diff was fetched from cache */
|
|
|
|
|
private $cacheHitKey = null;
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Set this to true to add debug info to the HTML output.
|
|
|
|
|
* Warning: this may cause RSS readers to spuriously mark articles as "new"
|
2017-02-20 22:44:19 +00:00
|
|
|
* (T22601)
|
2020-11-21 01:11:54 +00:00
|
|
|
* @var bool
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2013-10-04 13:43:09 +00:00
|
|
|
public $enableDebugComment = false;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2014-04-08 15:29:17 +00:00
|
|
|
/** @var bool If true, line X is not displayed when X is 1, for example
|
2013-11-20 19:11:57 +00:00
|
|
|
* to increase readability and conserve space with many small diffs.
|
|
|
|
|
*/
|
2013-11-11 16:35:19 +00:00
|
|
|
protected $mReducedLineNumbers = false;
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2014-02-05 11:02:29 +00:00
|
|
|
/** @var string Link to action=markpatrolled */
|
2013-11-11 16:35:19 +00:00
|
|
|
protected $mMarkPatrolledLink = null;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2013-11-20 19:11:57 +00:00
|
|
|
/** @var bool Show rev_deleted content if allowed */
|
|
|
|
|
protected $unhide = false;
|
2014-10-10 21:14:56 +00:00
|
|
|
|
|
|
|
|
/** @var bool Refresh the diff cache */
|
|
|
|
|
protected $mRefreshCache = false;
|
|
|
|
|
|
2021-09-22 20:16:51 +00:00
|
|
|
/** @var SlotDiffRenderer[]|null DifferenceEngine classes for the slots, keyed by role name. */
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
protected $slotDiffRenderers = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Temporary hack for B/C while slot diff related methods of DifferenceEngine are being
|
|
|
|
|
* deprecated. When true, we are inside a DifferenceEngineSlotDiffRenderer and
|
|
|
|
|
* $slotDiffRenderers should not be used.
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $isSlotDiffRenderer = false;
|
|
|
|
|
|
2020-07-23 09:41:58 +00:00
|
|
|
/**
|
|
|
|
|
* A set of options that will be passed to the SlotDiffRenderer upon creation
|
2019-10-29 23:30:32 +00:00
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private $slotDiffOptions = [];
|
|
|
|
|
|
2023-07-14 01:35:08 +00:00
|
|
|
/**
|
|
|
|
|
* Extra query parameters to be appended to diff page links
|
2024-09-05 19:41:19 +00:00
|
|
|
* @var array
|
2023-07-14 01:35:08 +00:00
|
|
|
*/
|
|
|
|
|
private $extraQueryParams = [];
|
|
|
|
|
|
2023-07-03 08:27:47 +00:00
|
|
|
/** @var ManifoldTextDiffer|null */
|
|
|
|
|
private $textDiffer;
|
|
|
|
|
|
2023-09-06 20:31:00 +00:00
|
|
|
protected LinkRenderer $linkRenderer;
|
|
|
|
|
private IContentHandlerFactory $contentHandlerFactory;
|
|
|
|
|
private RevisionStore $revisionStore;
|
2023-09-01 22:52:05 +00:00
|
|
|
private ArchivedRevisionLookup $archivedRevisionLookup;
|
2023-09-06 20:31:00 +00:00
|
|
|
private HookRunner $hookRunner;
|
|
|
|
|
private WikiPageFactory $wikiPageFactory;
|
|
|
|
|
private UserOptionsLookup $userOptionsLookup;
|
|
|
|
|
private CommentFormatter $commentFormatter;
|
2023-07-05 08:57:11 +00:00
|
|
|
private IConnectionProvider $dbProvider;
|
2023-09-29 23:08:12 +00:00
|
|
|
private UserGroupManager $userGroupManager;
|
|
|
|
|
private UserEditTracker $userEditTracker;
|
|
|
|
|
private UserIdentityUtils $userIdentityUtils;
|
2023-07-05 08:57:11 +00:00
|
|
|
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
/** @var Message[] */
|
|
|
|
|
private $revisionLoadErrors = [];
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param IContextSource|null $context Context to use, anything else will be ignored
|
2014-07-24 17:42:45 +00:00
|
|
|
* @param int $old Old ID we want to show and diff with.
|
|
|
|
|
* @param string|int $new Either revision ID or 'prev' or 'next'. Default: 0.
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param int $rcid Deprecated, no longer used!
|
|
|
|
|
* @param bool $refreshCache If set, refreshes the diff cache
|
|
|
|
|
* @param bool $unhide If set, allow viewing deleted revs
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
|
|
|
|
|
$refreshCache = false, $unhide = false
|
|
|
|
|
) {
|
2011-11-10 13:06:52 +00:00
|
|
|
if ( $context instanceof IContextSource ) {
|
|
|
|
|
$this->setContext( $context );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2011-11-10 13:06:52 +00:00
|
|
|
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'" );
|
2010-11-07 16:28:11 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mOldid = $old;
|
|
|
|
|
$this->mNewid = $new;
|
|
|
|
|
$this->mRefreshCache = $refreshCache;
|
2010-11-07 16:28:11 +00:00
|
|
|
$this->unhide = $unhide;
|
2020-03-26 22:40:22 +00:00
|
|
|
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->linkRenderer = $services->getLinkRenderer();
|
|
|
|
|
$this->contentHandlerFactory = $services->getContentHandlerFactory();
|
|
|
|
|
$this->revisionStore = $services->getRevisionStore();
|
2023-09-01 22:52:05 +00:00
|
|
|
$this->archivedRevisionLookup = $services->getArchivedRevisionLookup();
|
2021-04-11 20:49:08 +00:00
|
|
|
$this->hookRunner = new HookRunner( $services->getHookContainer() );
|
2020-11-11 21:36:36 +00:00
|
|
|
$this->wikiPageFactory = $services->getWikiPageFactory();
|
2022-04-22 12:21:13 +00:00
|
|
|
$this->userOptionsLookup = $services->getUserOptionsLookup();
|
2022-12-11 00:33:56 +00:00
|
|
|
$this->commentFormatter = $services->getCommentFormatter();
|
2024-01-22 21:32:48 +00:00
|
|
|
$this->dbProvider = $services->getConnectionProvider();
|
2023-09-29 23:08:12 +00:00
|
|
|
$this->userGroupManager = $services->getUserGroupManager();
|
|
|
|
|
$this->userEditTracker = $services->getUserEditTracker();
|
|
|
|
|
$this->userIdentityUtils = $services->getUserIdentityUtils();
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2011-06-01 16:27:46 +00:00
|
|
|
/**
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @return SlotDiffRenderer[] Diff renderers for each slot, keyed by role name.
|
2023-06-21 01:05:25 +00:00
|
|
|
* Includes slots only present in one of the revisions. Does not include slots
|
|
|
|
|
* for which content is identical in the two revisions.
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
|
|
|
|
protected function getSlotDiffRenderers() {
|
|
|
|
|
if ( $this->isSlotDiffRenderer ) {
|
|
|
|
|
throw new LogicException( __METHOD__ . ' called in slot diff renderer mode' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->slotDiffRenderers === null ) {
|
|
|
|
|
if ( !$this->loadRevisionData() ) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$slotContents = $this->getSlotContents();
|
2023-06-21 01:05:25 +00:00
|
|
|
$this->slotDiffRenderers = [];
|
|
|
|
|
foreach ( $slotContents as $role => $contents ) {
|
|
|
|
|
if ( $contents['new'] && $contents['old']
|
|
|
|
|
&& $contents['new']->equals( $contents['old'] )
|
|
|
|
|
) {
|
|
|
|
|
// Do not produce a diff of identical content
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-04-03 21:13:14 +00:00
|
|
|
if ( !$contents['new'] && !$contents['old'] ) {
|
|
|
|
|
// Nothing to diff (i.e both revisions are corrupted), just ignore
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-06-21 01:05:25 +00:00
|
|
|
$handler = ( $contents['new'] ?: $contents['old'] )->getContentHandler();
|
|
|
|
|
$this->slotDiffRenderers[$role] = $handler->getSlotDiffRenderer(
|
2022-01-21 08:55:23 +00:00
|
|
|
$this->getContext(),
|
2023-07-06 00:21:37 +00:00
|
|
|
$this->slotDiffOptions + [
|
2023-07-03 08:27:47 +00:00
|
|
|
'contentLanguage' => $this->getDiffLang()->getCode(),
|
|
|
|
|
'textDiffer' => $this->getTextDiffer()
|
2023-07-06 00:21:37 +00:00
|
|
|
]
|
2019-10-29 23:30:32 +00:00
|
|
|
);
|
2023-06-21 01:05:25 +00:00
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
2022-01-21 08:55:23 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return $this->slotDiffRenderers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mark this DifferenceEngine as a slot renderer (as opposed to a page renderer).
|
|
|
|
|
* This is used in legacy mode when the DifferenceEngine is wrapped in a
|
|
|
|
|
* DifferenceEngineSlotDiffRenderer.
|
|
|
|
|
* @internal For use by DifferenceEngineSlotDiffRenderer only.
|
|
|
|
|
*/
|
|
|
|
|
public function markAsSlotDiffRenderer() {
|
|
|
|
|
$this->isSlotDiffRenderer = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the old and new content objects for all slots.
|
|
|
|
|
* This method does not do any permission checks.
|
2023-06-21 01:05:25 +00:00
|
|
|
* @return (Content|null)[][] [ role => [ 'old' => Content|null, 'new' => Content|null ], ... ]
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*/
|
|
|
|
|
protected function getSlotContents() {
|
|
|
|
|
if ( $this->isContentOverridden ) {
|
|
|
|
|
return [
|
2022-01-21 08:55:23 +00:00
|
|
|
SlotRecord::MAIN => [ 'old' => $this->mOldContent, 'new' => $this->mNewContent ]
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
];
|
2018-08-20 14:49:56 +00:00
|
|
|
} elseif ( !$this->loadRevisionData() ) {
|
|
|
|
|
return [];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-07 04:41:19 +00:00
|
|
|
$newSlots = $this->mNewRevisionRecord->getPrimarySlots()->getSlots();
|
2022-01-21 08:55:23 +00:00
|
|
|
$oldSlots = $this->mOldRevisionRecord ?
|
|
|
|
|
$this->mOldRevisionRecord->getPrimarySlots()->getSlots() :
|
|
|
|
|
[];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
// The order here will determine the visual order of the diff. The current logic is
|
2018-08-20 14:49:56 +00:00
|
|
|
// slots of the new revision first in natural order, then deleted ones. This is ad hoc
|
|
|
|
|
// and should not be relied on - in the future we may want the ordering to depend
|
|
|
|
|
// on the page type.
|
2022-01-21 08:55:23 +00:00
|
|
|
$roles = array_keys( array_merge( $newSlots, $oldSlots ) );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
$slots = [];
|
|
|
|
|
foreach ( $roles as $role ) {
|
|
|
|
|
$slots[$role] = [
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
'old' => $this->loadSingleSlot(
|
|
|
|
|
$oldSlots[$role] ?? null,
|
|
|
|
|
'old'
|
|
|
|
|
),
|
|
|
|
|
'new' => $this->loadSingleSlot(
|
|
|
|
|
$newSlots[$role] ?? null,
|
|
|
|
|
'new'
|
|
|
|
|
)
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
// move main slot to front
|
2018-09-24 21:10:08 +00:00
|
|
|
if ( isset( $slots[SlotRecord::MAIN] ) ) {
|
|
|
|
|
$slots = [ SlotRecord::MAIN => $slots[SlotRecord::MAIN] ] + $slots;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
return $slots;
|
|
|
|
|
}
|
|
|
|
|
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
/**
|
|
|
|
|
* Load the content of a single slot record
|
|
|
|
|
*
|
|
|
|
|
* @param SlotRecord|null $slot
|
|
|
|
|
* @param string $which "new" or "old"
|
|
|
|
|
* @return Content|null
|
|
|
|
|
*/
|
|
|
|
|
private function loadSingleSlot( ?SlotRecord $slot, string $which ) {
|
|
|
|
|
if ( !$slot ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return $slot->getContent();
|
|
|
|
|
} catch ( BadRevisionException $e ) {
|
|
|
|
|
$this->addRevisionLoadError( $which );
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a message to show as a notice at the top of the page
|
|
|
|
|
*
|
|
|
|
|
* @param string $which "new" or "old"
|
|
|
|
|
*/
|
|
|
|
|
private function addRevisionLoadError( $which ) {
|
|
|
|
|
$this->revisionLoadErrors[] = $this->msg( $which === 'new'
|
|
|
|
|
? 'difference-bad-new-revision' : 'difference-bad-old-revision'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If errors were encountered while loading the revision contents, this
|
|
|
|
|
* will return an array of Messages describing the errors.
|
|
|
|
|
*
|
|
|
|
|
* @return Message[]
|
|
|
|
|
*/
|
|
|
|
|
public function getRevisionLoadErrors() {
|
|
|
|
|
return $this->revisionLoadErrors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine whether there was an error loading the new revision
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function hasNewRevisionLoadError() {
|
|
|
|
|
foreach ( $this->revisionLoadErrors as $error ) {
|
|
|
|
|
if ( $error->getKey() === 'difference-bad-new-revision' ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-21 01:11:54 +00:00
|
|
|
/** @inheritDoc */
|
2018-08-22 08:22:54 +00:00
|
|
|
public function getTitle() {
|
|
|
|
|
// T202454 avoid errors when there is no title
|
|
|
|
|
return parent::getTitle() ?: Title::makeTitle( NS_SPECIAL, 'BadTitle/DifferenceEngine' );
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Set reduced line numbers mode.
|
|
|
|
|
* When set, line X is not displayed when X is 1, for example to increase readability and
|
|
|
|
|
* conserve space with many small diffs.
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param bool $value
|
2011-06-01 16:27:46 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function setReducedLineNumbers( $value = true ) {
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mReducedLineNumbers = $value;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
/**
|
2023-07-11 00:33:07 +00:00
|
|
|
* Get the language in which the diff text is written
|
2018-06-19 19:37:17 +00:00
|
|
|
*
|
2023-07-11 00:33:07 +00:00
|
|
|
* @return Language
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function getDiffLang() {
|
2022-12-16 23:48:27 +00:00
|
|
|
# Default language in which the diff text is written.
|
2023-07-05 00:48:42 +00:00
|
|
|
$this->mDiffLang ??= $this->getDefaultLanguage();
|
2013-11-11 16:35:19 +00:00
|
|
|
return $this->mDiffLang;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-05 00:48:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get the language to use if none has been set by setTextLanguage().
|
|
|
|
|
* Wikibase overrides this to use the user language.
|
|
|
|
|
*
|
2023-07-11 00:33:07 +00:00
|
|
|
* @return Language
|
2023-07-05 00:48:42 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDefaultLanguage() {
|
|
|
|
|
return $this->getTitle()->getPageLanguage();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-01 16:27:46 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function wasCacheHit() {
|
2013-11-11 16:35:19 +00:00
|
|
|
return $this->mCacheHit;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2010-11-27 19:01:51 +00:00
|
|
|
|
2011-06-01 16:27:46 +00:00
|
|
|
/**
|
2018-08-20 14:49:56 +00:00
|
|
|
* Get the ID of old revision (left pane) of the diff. 0 for the revision
|
|
|
|
|
* previous to getNewid(), false if the old revision does not exist, null
|
|
|
|
|
* if it's unsaved.
|
|
|
|
|
* To get a real revision ID instead of 0, call loadRevisionData() first.
|
|
|
|
|
* @return int|false|null
|
2011-06-01 16:27:46 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function getOldid() {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$this->loadRevisionIds();
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
return $this->mOldid;
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2010-11-27 19:01:51 +00:00
|
|
|
|
2011-06-01 16:27:46 +00:00
|
|
|
/**
|
2018-08-20 14:49:56 +00:00
|
|
|
* Get the ID of new revision (right pane) of the diff. 0 for the current revision,
|
|
|
|
|
* false if the new revision does not exist, null if it's unsaved.
|
|
|
|
|
* To get a real revision ID instead of 0, call loadRevisionData() first.
|
|
|
|
|
* @return int|false|null
|
2011-06-01 16:27:46 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function getNewid() {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$this->loadRevisionIds();
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
return $this->mNewid;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2006-10-03 13:00:52 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Get the left side of the diff.
|
|
|
|
|
* Could be null when the first revision of the page is diffed to 'prev' (or in the case of
|
|
|
|
|
* load failure).
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
public function getOldRevision() {
|
2020-04-29 16:38:25 +00:00
|
|
|
return $this->mOldRevisionRecord ?: null;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the right side of the diff.
|
|
|
|
|
* Should not be null but can still happen in the case of load failure.
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
public function getNewRevision() {
|
2020-04-29 16:38:25 +00:00
|
|
|
return $this->mNewRevisionRecord;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-10 01:17:01 +00:00
|
|
|
/**
|
|
|
|
|
* Look up a special:Undelete link to the given deleted revision id,
|
|
|
|
|
* as a workaround for being unable to load deleted diffs in currently.
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param int $id Revision ID
|
|
|
|
|
*
|
2016-10-12 05:36:22 +00:00
|
|
|
* @return string|bool Link HTML or false
|
2011-05-10 01:17:01 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function deletedLink( $id ) {
|
2021-02-27 02:03:46 +00:00
|
|
|
if ( $this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
|
2023-09-01 22:52:05 +00:00
|
|
|
$revRecord = $this->archivedRevisionLookup->getArchivedRevisionRecord( null, $id );
|
|
|
|
|
if ( $revRecord ) {
|
|
|
|
|
$title = Title::newFromPageIdentity( $revRecord->getPage() );
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( [
|
2011-05-10 01:17:01 +00:00
|
|
|
'target' => $title->getPrefixedText(),
|
2020-04-01 17:47:23 +00:00
|
|
|
'timestamp' => $revRecord->getTimestamp()
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2011-05-10 01:17:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2011-05-10 01:17:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build a wikitext link toward a deleted revision, if viewable.
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param int $id Revision ID
|
|
|
|
|
*
|
|
|
|
|
* @return string Wikitext fragment
|
2011-05-10 01:17:01 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function deletedIdMarker( $id ) {
|
2011-05-10 01:17:01 +00:00
|
|
|
$link = $this->deletedLink( $id );
|
|
|
|
|
if ( $link ) {
|
|
|
|
|
return "[$link $id]";
|
|
|
|
|
} else {
|
2016-12-08 05:04:53 +00:00
|
|
|
return (string)$id;
|
2011-05-10 01:17:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
private function showMissingRevision() {
|
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$missing = [];
|
2022-01-21 08:55:23 +00:00
|
|
|
if ( $this->mOldid && ( !$this->mOldRevisionRecord || !$this->mOldContent ) ) {
|
2013-11-11 16:35:19 +00:00
|
|
|
$missing[] = $this->deletedIdMarker( $this->mOldid );
|
2012-08-20 14:55:28 +00:00
|
|
|
}
|
2022-01-21 08:55:23 +00:00
|
|
|
if ( !$this->mNewRevisionRecord || !$this->mNewContent ) {
|
2013-11-11 16:35:19 +00:00
|
|
|
$missing[] = $this->deletedIdMarker( $this->mNewid );
|
2012-08-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-10 17:25:17 +00:00
|
|
|
$out->setPageTitleMsg( $this->msg( 'errorpagetitle' ) );
|
2014-09-25 12:34:41 +00:00
|
|
|
$msg = $this->msg( 'difference-missing-revision' )
|
|
|
|
|
->params( $this->getLanguage()->listToText( $missing ) )
|
|
|
|
|
->numParams( count( $missing ) )
|
|
|
|
|
->parseAsBlock();
|
2016-03-19 00:08:06 +00:00
|
|
|
$out->addHTML( $msg );
|
2012-08-20 14:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-29 23:30:32 +00:00
|
|
|
/**
|
|
|
|
|
* Checks whether one of the given Revisions was deleted
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function hasDeletedRevision() {
|
|
|
|
|
$this->loadRevisionData();
|
2020-04-29 16:38:25 +00:00
|
|
|
return (
|
|
|
|
|
$this->mNewRevisionRecord &&
|
|
|
|
|
$this->mNewRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT )
|
|
|
|
|
) ||
|
|
|
|
|
(
|
|
|
|
|
$this->mOldRevisionRecord &&
|
|
|
|
|
$this->mOldRevisionRecord->isDeleted( RevisionRecord::DELETED_TEXT )
|
|
|
|
|
);
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the permission errors associated with the revisions for the current diff.
|
|
|
|
|
*
|
2021-02-27 02:03:46 +00:00
|
|
|
* @param Authority $performer
|
2019-10-29 23:30:32 +00:00
|
|
|
* @return array[] Array of arrays of the arguments to wfMessage to explain permissions problems.
|
|
|
|
|
*/
|
2021-02-27 02:03:46 +00:00
|
|
|
public function getPermissionErrors( Authority $performer ) {
|
2019-10-29 23:30:32 +00:00
|
|
|
$this->loadRevisionData();
|
2021-02-27 02:03:46 +00:00
|
|
|
$permStatus = PermissionStatus::newEmpty();
|
2019-10-29 23:30:32 +00:00
|
|
|
if ( $this->mNewPage ) {
|
2021-02-27 02:03:46 +00:00
|
|
|
$performer->authorizeRead( 'read', $this->mNewPage, $permStatus );
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
if ( $this->mOldPage ) {
|
2021-02-27 02:03:46 +00:00
|
|
|
$performer->authorizeRead( 'read', $this->mOldPage, $permStatus );
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
2021-02-27 02:03:46 +00:00
|
|
|
return $permStatus->toLegacyErrorArray();
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether one of the given Revisions was suppressed
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function hasSuppressedRevision() {
|
2020-04-29 16:38:25 +00:00
|
|
|
return $this->hasDeletedRevision() && (
|
|
|
|
|
( $this->mOldRevisionRecord &&
|
|
|
|
|
$this->mOldRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) ||
|
|
|
|
|
( $this->mNewRevisionRecord &&
|
|
|
|
|
$this->mNewRevisionRecord->isDeleted( RevisionRecord::DELETED_RESTRICTED ) )
|
|
|
|
|
);
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-29 23:08:12 +00:00
|
|
|
/**
|
|
|
|
|
* Renders user associated edit count
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getUserEditCount( $user ): string {
|
|
|
|
|
$editCount = $this->userEditTracker->getUserEditCount( $user );
|
|
|
|
|
if ( $editCount === null ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Html::rawElement( 'div', [
|
|
|
|
|
'class' => 'mw-diff-usereditcount',
|
|
|
|
|
],
|
|
|
|
|
$this->msg(
|
|
|
|
|
'diff-user-edits',
|
|
|
|
|
$this->getLanguage()->formatNum( $editCount )
|
|
|
|
|
)->parse()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renders user roles
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity $user
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getUserRoles( UserIdentity $user ) {
|
|
|
|
|
if ( !$this->userIdentityUtils->isNamed( $user ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$userGroups = $this->userGroupManager->getUserGroups( $user );
|
|
|
|
|
$userGroupLinks = [];
|
|
|
|
|
foreach ( $userGroups as $group ) {
|
|
|
|
|
$userGroupLinks[] = UserGroupMembership::getLinkHTML( $group, $this->getContext() );
|
|
|
|
|
}
|
|
|
|
|
return Html::rawElement( 'div', [
|
|
|
|
|
'class' => 'mw-diff-userroles',
|
|
|
|
|
], $this->getLanguage()->commaList( $userGroupLinks ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renders user associated meta data
|
|
|
|
|
*
|
|
|
|
|
* @param UserIdentity|null $user
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getUserMetaData( ?UserIdentity $user ) {
|
|
|
|
|
if ( !$user ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return Html::rawElement( 'div', [
|
|
|
|
|
'class' => 'mw-diff-usermetadata',
|
|
|
|
|
], $this->getUserRoles( $user ) . $this->getUserEditCount( $user ) );
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 23:30:32 +00:00
|
|
|
/**
|
|
|
|
|
* Checks whether the current user has permission for accessing the revisions of the diff.
|
|
|
|
|
* Note that this does not check whether the user has permission to view the page, it only
|
|
|
|
|
* checks revdelete permissions.
|
|
|
|
|
*
|
|
|
|
|
* It is the caller's responsibility to call
|
|
|
|
|
* $this->getUserPermissionErrors or similar checks.
|
|
|
|
|
*
|
2021-02-24 15:46:13 +00:00
|
|
|
* @param Authority $performer
|
2019-10-29 23:30:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-02-24 15:46:13 +00:00
|
|
|
public function isUserAllowedToSeeRevisions( Authority $performer ) {
|
2019-10-29 23:30:32 +00:00
|
|
|
$this->loadRevisionData();
|
2022-01-21 08:55:23 +00:00
|
|
|
|
|
|
|
|
if ( $this->mOldRevisionRecord && !$this->mOldRevisionRecord->userCan(
|
|
|
|
|
RevisionRecord::DELETED_TEXT,
|
|
|
|
|
$performer
|
|
|
|
|
) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 23:30:32 +00:00
|
|
|
// $this->mNewRev will only be falsy if a loading error occurred
|
|
|
|
|
// (in which case the user is allowed to see).
|
2022-01-21 08:55:23 +00:00
|
|
|
return !$this->mNewRevisionRecord || $this->mNewRevisionRecord->userCan(
|
2020-03-11 01:41:49 +00:00
|
|
|
RevisionRecord::DELETED_TEXT,
|
2021-02-24 15:46:13 +00:00
|
|
|
$performer
|
2020-03-11 01:41:49 +00:00
|
|
|
);
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the diff should be hidden from the current user
|
|
|
|
|
* This is based on whether the user is allowed to see it and has specifically asked to see it.
|
|
|
|
|
*
|
2021-03-04 20:28:38 +00:00
|
|
|
* @param Authority $performer
|
2019-10-29 23:30:32 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-03-04 20:28:38 +00:00
|
|
|
public function shouldBeHiddenFromUser( Authority $performer ) {
|
2019-10-29 23:30:32 +00:00
|
|
|
return $this->hasDeletedRevision() && ( !$this->unhide ||
|
2021-03-04 20:28:38 +00:00
|
|
|
!$this->isUserAllowedToSeeRevisions( $performer ) );
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-21 01:11:54 +00:00
|
|
|
/**
|
|
|
|
|
* @param bool $diffOnly
|
|
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function showDiffPage( $diffOnly = false ) {
|
2011-01-04 06:12:33 +00:00
|
|
|
# Allow frames except in certain special cases
|
2011-11-10 13:06:52 +00:00
|
|
|
$out = $this->getOutput();
|
2024-07-31 18:12:34 +00:00
|
|
|
$out->getMetadata()->setPreventClickjacking( false );
|
2011-11-10 13:06:52 +00:00
|
|
|
$out->setRobotPolicy( 'noindex,nofollow' );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to add any extra output here
|
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->onDifferenceEngineShowDiffPage( $out );
|
2016-07-08 16:46:20 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
if ( !$this->loadRevisionData() ) {
|
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->onDifferenceEngineShowDiffPageMaybeShowMissingRevision( $this ) ) {
|
2016-11-17 02:14:26 +00:00
|
|
|
$this->showMissingRevision();
|
|
|
|
|
}
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 13:06:52 +00:00
|
|
|
$user = $this->getUser();
|
2021-02-27 02:03:46 +00:00
|
|
|
$permErrors = $this->getPermissionErrors( $this->getAuthority() );
|
2022-01-21 08:55:23 +00:00
|
|
|
if ( $permErrors ) {
|
2011-11-06 19:59:46 +00:00
|
|
|
throw new PermissionsError( 'read', $permErrors );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$rollback = '';
|
|
|
|
|
|
2023-07-14 01:35:08 +00:00
|
|
|
$query = $this->extraQueryParams;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
# Carry over 'diffonly' param via navigation links
|
2021-03-16 21:43:21 +00:00
|
|
|
if ( $diffOnly != MediaWikiServices::getInstance()
|
|
|
|
|
->getUserOptionsLookup()->getBoolOption( $user, 'diffonly' )
|
|
|
|
|
) {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$query['diffonly'] = $diffOnly;
|
|
|
|
|
}
|
|
|
|
|
# Cascade unhide param in links for easy deletion browsing
|
|
|
|
|
if ( $this->unhide ) {
|
|
|
|
|
$query['unhide'] = 1;
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
# Check if one of the revisions is deleted/suppressed
|
2019-10-29 23:30:32 +00:00
|
|
|
$deleted = $this->hasDeletedRevision();
|
|
|
|
|
$suppressed = $this->hasSuppressedRevision();
|
2021-02-27 02:03:46 +00:00
|
|
|
$allowed = $this->isUserAllowedToSeeRevisions( $this->getAuthority() );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$revisionTools = [];
|
2023-09-29 22:37:28 +00:00
|
|
|
$breadCrumbs = '';
|
2013-03-13 15:43:27 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
# mOldRevisionRecord is false if the difference engine is called with a "vague" query for
|
2010-11-07 16:28:11 +00:00
|
|
|
# a diff between a version V and its previous version V' AND the version V
|
|
|
|
|
# is the first version of that article. In that case, V' does not exist.
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord === false ) {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( $this->mNewPage ) {
|
2023-08-10 17:25:17 +00:00
|
|
|
$out->setPageTitleMsg(
|
|
|
|
|
$this->msg( 'difference-title' )->plaintextParams( $this->mNewPage->getPrefixedText() )
|
|
|
|
|
);
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
2011-10-05 19:59:39 +00:00
|
|
|
$samePage = true;
|
|
|
|
|
$oldHeader = '';
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to change the $oldHeader variable
|
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->onDifferenceEngineOldHeaderNoOldRev( $oldHeader );
|
2011-10-05 19:59:39 +00:00
|
|
|
} else {
|
2020-06-18 13:20:49 +00:00
|
|
|
$this->hookRunner->onDifferenceEngineViewHeader( $this );
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$this->mOldPage || !$this->mNewPage ) {
|
|
|
|
|
// XXX say something to the user?
|
|
|
|
|
$samePage = false;
|
|
|
|
|
} elseif ( $this->mNewPage->equals( $this->mOldPage ) ) {
|
2023-08-10 17:25:17 +00:00
|
|
|
$out->setPageTitleMsg(
|
|
|
|
|
$this->msg( 'difference-title' )->plaintextParams( $this->mNewPage->getPrefixedText() )
|
|
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$samePage = true;
|
|
|
|
|
} else {
|
2023-08-10 17:25:17 +00:00
|
|
|
$out->setPageTitleMsg( $this->msg( 'difference-title-multipage' )->plaintextParams(
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) );
|
2011-11-10 13:06:52 +00:00
|
|
|
$out->addSubtitle( $this->msg( 'difference-multipage' ) );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$samePage = false;
|
|
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
|
2021-02-27 02:03:46 +00:00
|
|
|
if ( $samePage && $this->mNewPage &&
|
|
|
|
|
$this->getAuthority()->probablyCan( 'edit', $this->mNewPage )
|
|
|
|
|
) {
|
|
|
|
|
if ( $this->mNewRevisionRecord->isCurrent() &&
|
|
|
|
|
$this->getAuthority()->probablyCan( 'rollback', $this->mNewPage )
|
|
|
|
|
) {
|
2020-04-18 00:21:26 +00:00
|
|
|
$rollbackLink = Linker::generateRollback(
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewRevisionRecord,
|
2020-04-18 00:21:26 +00:00
|
|
|
$this->getContext(),
|
|
|
|
|
[ 'noBrackets' ]
|
|
|
|
|
);
|
2012-11-01 20:04:12 +00:00
|
|
|
if ( $rollbackLink ) {
|
2024-07-31 18:12:34 +00:00
|
|
|
$out->getMetadata()->setPreventClickjacking( true );
|
2016-12-27 21:14:16 +00:00
|
|
|
$rollback = "\u{00A0}\u{00A0}\u{00A0}" . $rollbackLink;
|
2012-11-01 20:04:12 +00:00
|
|
|
}
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
2013-10-04 13:43:09 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->userCanEdit( $this->mOldRevisionRecord ) &&
|
|
|
|
|
$this->userCanEdit( $this->mNewRevisionRecord )
|
2013-10-04 13:43:09 +00:00
|
|
|
) {
|
2021-02-12 11:35:32 +00:00
|
|
|
$undoLink = $this->linkRenderer->makeKnownLink(
|
|
|
|
|
$this->mNewPage,
|
|
|
|
|
$this->msg( 'editundo' )->text(),
|
|
|
|
|
[ 'title' => Linker::titleAttrib( 'undo' ) ],
|
|
|
|
|
[
|
|
|
|
|
'action' => 'edit',
|
|
|
|
|
'undoafter' => $this->mOldid,
|
|
|
|
|
'undo' => $this->mNewid
|
|
|
|
|
]
|
2013-03-07 02:38:00 +00:00
|
|
|
);
|
2014-07-05 17:57:37 +00:00
|
|
|
$revisionTools['mw-diff-undo'] = $undoLink;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# Make "previous revision link"
|
2020-04-29 16:38:25 +00:00
|
|
|
$hasPrevious = $samePage && $this->mOldPage &&
|
|
|
|
|
$this->revisionStore->getPreviousRevision( $this->mOldRevisionRecord );
|
|
|
|
|
if ( $hasPrevious ) {
|
2023-09-29 22:37:28 +00:00
|
|
|
$prevlinkQuery = [ 'diff' => 'prev', 'oldid' => $this->mOldid ] + $query;
|
2019-09-07 09:27:30 +00:00
|
|
|
$prevlink = $this->linkRenderer->makeKnownLink(
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mOldPage,
|
2019-09-07 09:27:30 +00:00
|
|
|
$this->msg( 'previousdiff' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'differences-prevlink' ],
|
2023-09-29 22:37:28 +00:00
|
|
|
$prevlinkQuery
|
|
|
|
|
);
|
|
|
|
|
$breadCrumbs .= $this->linkRenderer->makeKnownLink(
|
|
|
|
|
$this->mOldPage,
|
|
|
|
|
$this->msg( 'previousdiff' )->text(),
|
|
|
|
|
[
|
|
|
|
|
'class' => 'mw-diff-revision-history-link-previous'
|
|
|
|
|
],
|
|
|
|
|
$prevlinkQuery
|
2010-11-07 16:28:11 +00:00
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
} else {
|
2016-12-27 21:14:16 +00:00
|
|
|
$prevlink = "\u{00A0}";
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord->isMinor() ) {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$oldminor = ChangesList::flag( 'minor' );
|
2010-11-07 16:28:11 +00:00
|
|
|
} else {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$oldminor = '';
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$oldRevRecord = $this->mOldRevisionRecord;
|
2020-04-27 18:47:50 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$ldel = $this->revisionDeleteLink( $oldRevRecord );
|
2020-04-27 18:47:50 +00:00
|
|
|
$oldRevisionHeader = $this->getRevisionHeader( $oldRevRecord, 'complete' );
|
2016-01-29 13:03:41 +00:00
|
|
|
$oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff', $this->getContext() );
|
2022-12-11 00:33:56 +00:00
|
|
|
$oldRevComment = $this->commentFormatter
|
2023-10-04 18:04:10 +00:00
|
|
|
->formatRevision(
|
|
|
|
|
$oldRevRecord, $user, !$diffOnly, !$this->unhide, /** disable parentheseses */ false
|
|
|
|
|
);
|
2022-01-07 07:05:28 +00:00
|
|
|
|
|
|
|
|
if ( $oldRevComment === '' ) {
|
|
|
|
|
$defaultComment = $this->msg( 'changeslist-nocomment' )->escaped();
|
|
|
|
|
$oldRevComment = "<span class=\"comment mw-comment-none\">$defaultComment</span>";
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
|
|
|
|
|
'<div id="mw-diff-otitle2">' .
|
2023-09-29 23:08:12 +00:00
|
|
|
Linker::revUserTools( $oldRevRecord, !$this->unhide ) .
|
|
|
|
|
$this->getUserMetaData( $oldRevRecord->getUser() ) .
|
|
|
|
|
'</div>' .
|
2022-01-07 07:05:28 +00:00
|
|
|
'<div id="mw-diff-otitle3">' . $oldminor . $oldRevComment . $ldel . '</div>' .
|
2013-07-06 20:53:27 +00:00
|
|
|
'<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
'<div id="mw-diff-otitle4">' . $prevlink . '</div>';
|
|
|
|
|
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to change the $oldHeader variable
|
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->onDifferenceEngineOldHeader(
|
|
|
|
|
$this, $oldHeader, $prevlink, $oldminor, $diffOnly, $ldel, $this->unhide );
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2017-07-17 20:19:33 +00:00
|
|
|
$out->addJsConfigVars( [
|
|
|
|
|
'wgDiffOldId' => $this->mOldid,
|
|
|
|
|
'wgDiffNewId' => $this->mNewid,
|
|
|
|
|
] );
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
# Make "next revision link"
|
|
|
|
|
# Skip next link on the top revision
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $samePage && $this->mNewPage && !$this->mNewRevisionRecord->isCurrent() ) {
|
2023-09-29 22:37:28 +00:00
|
|
|
$nextlinkQuery = [ 'diff' => 'next', 'oldid' => $this->mNewid ] + $query;
|
2019-09-07 09:27:30 +00:00
|
|
|
$nextlink = $this->linkRenderer->makeKnownLink(
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mNewPage,
|
2019-09-07 09:27:30 +00:00
|
|
|
$this->msg( 'nextdiff' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'differences-nextlink' ],
|
2023-09-29 22:37:28 +00:00
|
|
|
$nextlinkQuery
|
|
|
|
|
);
|
|
|
|
|
$breadCrumbs .= $this->linkRenderer->makeKnownLink(
|
|
|
|
|
$this->mNewPage,
|
|
|
|
|
$this->msg( 'nextdiff' )->text(),
|
|
|
|
|
[
|
|
|
|
|
'class' => 'mw-diff-revision-history-link-next'
|
|
|
|
|
],
|
|
|
|
|
$nextlinkQuery
|
2010-11-07 16:28:11 +00:00
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
} else {
|
2016-12-27 21:14:16 +00:00
|
|
|
$nextlink = "\u{00A0}";
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mNewRevisionRecord->isMinor() ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$newminor = ChangesList::flag( 'minor' );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
} else {
|
|
|
|
|
$newminor = '';
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
# Handle RevisionDelete links...
|
2020-04-29 16:38:25 +00:00
|
|
|
$rdel = $this->revisionDeleteLink( $this->mNewRevisionRecord );
|
2013-03-07 02:38:00 +00:00
|
|
|
|
|
|
|
|
# Allow extensions to define their own revision tools
|
2020-06-15 21:19:04 +00:00
|
|
|
$this->hookRunner->onDiffTools(
|
|
|
|
|
$this->mNewRevisionRecord,
|
2020-06-24 22:05:35 +00:00
|
|
|
$revisionTools,
|
2020-06-25 01:19:47 +00:00
|
|
|
$this->mOldRevisionRecord ?: null,
|
2020-06-15 21:19:04 +00:00
|
|
|
$user
|
|
|
|
|
);
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formattedRevisionTools = [];
|
2013-03-07 02:38:00 +00:00
|
|
|
// Put each one in parentheses (poor man's button)
|
2014-07-05 17:57:37 +00:00
|
|
|
foreach ( $revisionTools as $key => $tool ) {
|
|
|
|
|
$toolClass = is_string( $key ) ? $key : 'mw-diff-tool';
|
|
|
|
|
$element = Html::rawElement(
|
|
|
|
|
'span',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => $toolClass ],
|
2023-10-13 17:41:34 +00:00
|
|
|
$tool
|
2014-07-05 17:57:37 +00:00
|
|
|
);
|
|
|
|
|
$formattedRevisionTools[] = $element;
|
2013-03-07 02:38:00 +00:00
|
|
|
}
|
2020-04-27 18:47:50 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$newRevRecord = $this->mNewRevisionRecord;
|
2020-04-27 18:47:50 +00:00
|
|
|
|
|
|
|
|
$newRevisionHeader = $this->getRevisionHeader( $newRevRecord, 'complete' ) .
|
2013-10-04 13:43:09 +00:00
|
|
|
' ' . implode( ' ', $formattedRevisionTools );
|
2016-01-29 13:03:41 +00:00
|
|
|
$newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff', $this->getContext() );
|
2023-10-04 18:04:10 +00:00
|
|
|
$newRevComment = $this->commentFormatter->formatRevision(
|
|
|
|
|
$newRevRecord, $user, !$diffOnly, !$this->unhide, /** disable parentheseses */ false
|
|
|
|
|
);
|
2022-01-07 07:05:28 +00:00
|
|
|
|
|
|
|
|
if ( $newRevComment === '' ) {
|
|
|
|
|
$defaultComment = $this->msg( 'changeslist-nocomment' )->escaped();
|
|
|
|
|
$newRevComment = "<span class=\"comment mw-comment-none\">$defaultComment</span>";
|
|
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
|
2020-04-18 00:21:26 +00:00
|
|
|
'<div id="mw-diff-ntitle2">' . Linker::revUserTools( $newRevRecord, !$this->unhide ) .
|
2023-09-29 23:08:12 +00:00
|
|
|
$rollback .
|
|
|
|
|
$this->getUserMetaData( $newRevRecord->getUser() ) .
|
|
|
|
|
'</div>' .
|
2022-01-07 07:05:28 +00:00
|
|
|
'<div id="mw-diff-ntitle3">' . $newminor . $newRevComment . $rdel . '</div>' .
|
2013-07-06 20:53:27 +00:00
|
|
|
'<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
|
2024-02-23 00:08:45 +00:00
|
|
|
'<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
|
2010-11-07 16:28:11 +00:00
|
|
|
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to change the $newHeader variable
|
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->onDifferenceEngineNewHeader( $this, $newHeader,
|
|
|
|
|
$formattedRevisionTools, $nextlink, $rollback, $newminor, $diffOnly,
|
|
|
|
|
$rdel, $this->unhide );
|
2016-07-08 16:46:20 +00:00
|
|
|
|
2023-09-29 22:37:28 +00:00
|
|
|
$out->addHTML(
|
|
|
|
|
Html::rawElement( 'div', [
|
|
|
|
|
'class' => 'mw-diff-revision-history-links'
|
|
|
|
|
], $breadCrumbs )
|
|
|
|
|
);
|
2010-11-07 16:28:11 +00:00
|
|
|
# If the diff cannot be shown due to a deleted revision, then output
|
|
|
|
|
# the diff header and links to unhide (if available)...
|
2021-03-04 20:28:38 +00:00
|
|
|
if ( $this->shouldBeHiddenFromUser( $this->getAuthority() ) ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$this->showDiffStyle();
|
|
|
|
|
$multi = $this->getMultiNotice();
|
2011-11-10 13:06:52 +00:00
|
|
|
$out->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) );
|
2010-11-27 19:01:51 +00:00
|
|
|
if ( !$allowed ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
# Give explanation for why revision is not visible
|
2022-01-21 08:55:23 +00:00
|
|
|
$msg = [ $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff' ];
|
2010-11-07 16:28:11 +00:00
|
|
|
} else {
|
|
|
|
|
# Give explanation and add a link to view the diff...
|
2016-01-06 23:13:31 +00:00
|
|
|
$query = $this->getRequest()->appendQueryValue( 'unhide', '1' );
|
2022-01-21 08:55:23 +00:00
|
|
|
$msg = [
|
|
|
|
|
$suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff',
|
|
|
|
|
$this->getTitle()->getFullURL( $query )
|
|
|
|
|
];
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2022-12-04 19:09:28 +00:00
|
|
|
$out->addHTML( Html::warningBox( $this->msg( ...$msg )->parse(), 'plainlinks' ) );
|
2010-11-07 16:28:11 +00:00
|
|
|
# Otherwise, output a regular diff...
|
2004-11-25 23:49:52 +00:00
|
|
|
} else {
|
2010-11-07 16:28:11 +00:00
|
|
|
# Add deletion notice if the user is viewing deleted content
|
|
|
|
|
$notice = '';
|
2010-11-27 19:01:51 +00:00
|
|
|
if ( $deleted ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
|
2022-01-21 08:55:23 +00:00
|
|
|
$notice = Html::warningBox( $this->msg( $msg )->parse(), 'plainlinks' );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
|
|
|
|
|
# Add an error if the content can't be loaded
|
|
|
|
|
$this->getSlotContents();
|
|
|
|
|
foreach ( $this->getRevisionLoadErrors() as $msg ) {
|
|
|
|
|
$notice .= Html::warningBox( $msg->parse() );
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 08:27:47 +00:00
|
|
|
// Check if inline switcher will be needed
|
|
|
|
|
if ( $this->getTextDiffer()->hasFormat( 'inline' ) ) {
|
2023-03-24 04:15:57 +00:00
|
|
|
$out->enableOOUI();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 00:08:30 +00:00
|
|
|
$this->showTablePrefixes();
|
2010-11-07 16:28:11 +00:00
|
|
|
$this->showDiff( $oldHeader, $newHeader, $notice );
|
2010-11-27 19:01:51 +00:00
|
|
|
if ( !$diffOnly ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$this->renderNewRevision();
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2024-02-12 20:15:16 +00:00
|
|
|
|
|
|
|
|
// Allow extensions to optionally not show the final patrolled link
|
|
|
|
|
if ( $this->hookRunner->onDifferenceEngineRenderRevisionShowFinalPatrolLink() ) {
|
|
|
|
|
# Add redundant patrol link on bottom...
|
2024-02-23 00:08:45 +00:00
|
|
|
$out->addHTML( $this->markPatrolledLink() );
|
2024-02-12 20:15:16 +00:00
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-11-27 19:01:51 +00:00
|
|
|
|
2023-06-15 00:08:30 +00:00
|
|
|
/**
|
|
|
|
|
* Add table prefixes
|
|
|
|
|
*/
|
|
|
|
|
private function showTablePrefixes() {
|
|
|
|
|
$parts = [];
|
|
|
|
|
foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
|
|
|
|
|
$parts += $slotDiffRenderer->getTablePrefix( $this->getContext(), $this->mNewPage );
|
|
|
|
|
}
|
|
|
|
|
ksort( $parts );
|
|
|
|
|
if ( count( array_filter( $parts ) ) > 0 ) {
|
|
|
|
|
$language = $this->getLanguage();
|
|
|
|
|
$attrs = [
|
|
|
|
|
'class' => 'mw-diff-table-prefix',
|
|
|
|
|
'dir' => $language->getDir(),
|
|
|
|
|
'lang' => $language->getCode(),
|
|
|
|
|
];
|
|
|
|
|
$this->getOutput()->addHTML(
|
|
|
|
|
Html::rawElement( 'div', $attrs, implode( '', $parts ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
/**
|
2015-12-04 17:34:49 +00:00
|
|
|
* Build a link to mark a change as patrolled.
|
|
|
|
|
*
|
|
|
|
|
* Returns empty string if there's either no revision to patrol or the user is not allowed to.
|
2020-05-23 01:30:33 +00:00
|
|
|
*
|
2012-10-03 01:33:55 +00:00
|
|
|
* Side effect: When the patrol link is build, this method will call
|
2024-07-31 18:12:34 +00:00
|
|
|
* OutputPage::getMetadata()->setPreventClickjacking(true) and load a
|
|
|
|
|
* JS module.
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
*
|
2015-12-04 17:34:49 +00:00
|
|
|
* @return string HTML or empty string
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
*/
|
2024-02-23 00:08:45 +00:00
|
|
|
public function markPatrolledLink() {
|
2015-12-04 17:34:49 +00:00
|
|
|
if ( $this->mMarkPatrolledLink === null ) {
|
|
|
|
|
$linkInfo = $this->getMarkPatrolledLinkInfo();
|
|
|
|
|
// If false, there is no patrol link needed/allowed
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$linkInfo || !$this->mNewPage ) {
|
2015-12-04 17:34:49 +00:00
|
|
|
$this->mMarkPatrolledLink = '';
|
|
|
|
|
} else {
|
2024-02-12 20:15:16 +00:00
|
|
|
$patrolLinkClass = 'patrollink';
|
|
|
|
|
$this->mMarkPatrolledLink = ' <span class="' . $patrolLinkClass . '" data-mw="interface">[' .
|
2019-09-07 09:27:30 +00:00
|
|
|
$this->linkRenderer->makeKnownLink(
|
2016-05-20 18:11:58 +00:00
|
|
|
$this->mNewPage,
|
2019-09-07 09:27:30 +00:00
|
|
|
$this->msg( 'markaspatrolleddiff' )->text(),
|
2016-05-20 18:11:58 +00:00
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'action' => 'markpatrolled',
|
|
|
|
|
'rcid' => $linkInfo['rcid'],
|
|
|
|
|
]
|
|
|
|
|
) . ']</span>';
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to change the markpatrolled link
|
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->onDifferenceEngineMarkPatrolledLink( $this,
|
|
|
|
|
$this->mMarkPatrolledLink, $linkInfo['rcid'] );
|
2015-12-04 17:34:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->mMarkPatrolledLink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an array of meta data needed to build a "mark as patrolled" link and
|
2020-05-23 01:30:33 +00:00
|
|
|
* adds a JS module to the output.
|
2015-12-04 17:34:49 +00:00
|
|
|
*
|
2016-10-26 16:14:21 +00:00
|
|
|
* @return array|false An array of meta data for a patrol link (rcid only)
|
2015-12-04 17:34:49 +00:00
|
|
|
* or false if no link is needed
|
|
|
|
|
*/
|
|
|
|
|
protected function getMarkPatrolledLinkInfo() {
|
2013-07-20 19:24:20 +00:00
|
|
|
$user = $this->getUser();
|
2018-12-31 20:13:49 +00:00
|
|
|
$config = $this->getConfig();
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2015-12-04 17:34:49 +00:00
|
|
|
// Prepare a change patrol link, if applicable
|
|
|
|
|
if (
|
|
|
|
|
// Is patrolling enabled and the user allowed to?
|
2022-04-25 15:19:41 +00:00
|
|
|
$config->get( MainConfigNames::UseRCPatrol ) &&
|
2019-08-23 23:53:15 +00:00
|
|
|
$this->mNewPage &&
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->getAuthority()->probablyCan( 'patrol', $this->mNewPage ) &&
|
2015-12-04 17:34:49 +00:00
|
|
|
// Only do this if the revision isn't more than 6 hours older
|
|
|
|
|
// than the Max RC age (6h because the RC might not be cleaned out regularly)
|
2020-04-29 16:38:25 +00:00
|
|
|
RecentChange::isInRCLifespan( $this->mNewRevisionRecord->getTimestamp(), 21600 )
|
2015-12-04 17:34:49 +00:00
|
|
|
) {
|
|
|
|
|
// Look for an unpatrolled change corresponding to this diff
|
|
|
|
|
$change = RecentChange::newFromConds(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-12-04 17:34:49 +00:00
|
|
|
'rc_this_oldid' => $this->mNewid,
|
2018-04-11 20:20:55 +00:00
|
|
|
'rc_patrolled' => RecentChange::PRC_UNPATROLLED
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-12-04 17:34:49 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2012-12-29 02:53:18 +00:00
|
|
|
|
2021-05-25 15:39:48 +00:00
|
|
|
if ( $change && !$change->getPerformerIdentity()->equals( $user ) ) {
|
2015-12-04 17:34:49 +00:00
|
|
|
$rcid = $change->getAttribute( 'rc_id' );
|
|
|
|
|
} else {
|
|
|
|
|
// None found or the page has been created by the current user.
|
|
|
|
|
// If the user could patrol this it already would be patrolled
|
|
|
|
|
$rcid = 0;
|
|
|
|
|
}
|
2016-07-08 16:46:20 +00:00
|
|
|
|
|
|
|
|
// Allow extensions to possibly change the rcid here
|
|
|
|
|
// For example the rcid might be set to zero due to the user
|
|
|
|
|
// being the same as the performer of the change but an extension
|
|
|
|
|
// might still want to show it under certain conditions
|
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->onDifferenceEngineMarkPatrolledRCID( $rcid, $this, $change, $user );
|
2016-07-08 16:46:20 +00:00
|
|
|
|
2015-12-04 17:34:49 +00:00
|
|
|
// Build the link
|
|
|
|
|
if ( $rcid ) {
|
2024-07-31 18:12:34 +00:00
|
|
|
$this->getOutput()->getMetadata()->setPreventClickjacking( true );
|
2024-02-15 20:23:23 +00:00
|
|
|
$this->getOutput()->addModules( 'mediawiki.misc-authed-curate' );
|
2012-10-03 01:33:55 +00:00
|
|
|
|
2022-01-21 08:55:23 +00:00
|
|
|
return [ 'rcid' => $rcid ];
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 17:34:49 +00:00
|
|
|
// No mark as patrolled link applicable
|
|
|
|
|
return false;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-19 21:44:20 +00:00
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* @param RevisionRecord $revRecord
|
2020-04-18 00:21:26 +00:00
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @return string
|
2011-02-19 21:44:20 +00:00
|
|
|
*/
|
2020-04-29 16:38:25 +00:00
|
|
|
private function revisionDeleteLink( RevisionRecord $revRecord ) {
|
2020-04-18 00:21:26 +00:00
|
|
|
$link = Linker::getRevDeleteLink(
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->getAuthority(),
|
2020-04-29 16:38:25 +00:00
|
|
|
$revRecord,
|
|
|
|
|
$revRecord->getPageAsLinkTarget()
|
2020-04-18 00:21:26 +00:00
|
|
|
);
|
2011-12-28 18:41:36 +00:00
|
|
|
if ( $link !== '' ) {
|
2016-12-27 21:14:16 +00:00
|
|
|
$link = "\u{00A0}\u{00A0}\u{00A0}" . $link . ' ';
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return $link;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-07 16:28:11 +00:00
|
|
|
* Show the new revision of the page.
|
2018-08-14 16:37:30 +00:00
|
|
|
*
|
|
|
|
|
* @note Not supported after calling setContent().
|
2004-04-17 07:37:55 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function renderNewRevision() {
|
2018-08-14 16:37:30 +00:00
|
|
|
if ( $this->isContentOverridden ) {
|
2021-05-02 23:55:07 +00:00
|
|
|
// The code below only works with a RevisionRecord object. We could construct a
|
|
|
|
|
// fake RevisionRecord (here or in setContent), but since this does not seem
|
|
|
|
|
// needed at the moment, we'll just fail for now.
|
2018-08-14 16:37:30 +00:00
|
|
|
throw new LogicException(
|
|
|
|
|
__METHOD__
|
|
|
|
|
. ' is not supported after calling setContent(). Use setRevisions() instead.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 13:06:52 +00:00
|
|
|
$out = $this->getOutput();
|
2020-04-29 16:38:25 +00:00
|
|
|
$revHeader = $this->getRevisionHeader( $this->mNewRevisionRecord );
|
2010-12-11 05:32:48 +00:00
|
|
|
# Add "current version as of X" title
|
2015-01-16 22:50:34 +00:00
|
|
|
$out->addHTML( "<hr class='diff-hr' id='mw-oldid' />
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
<h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
|
2010-12-11 05:32:48 +00:00
|
|
|
# Page content may be handled by a hooked call 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->onArticleContentOnDiff( $this, $out ) ) {
|
2010-12-11 05:32:48 +00:00
|
|
|
$this->loadNewText();
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$this->mNewPage ) {
|
|
|
|
|
// New revision is unsaved; bail out.
|
|
|
|
|
// TODO in theory rendering the new revision is a meaningful thing to do
|
|
|
|
|
// even if it's unsaved, but a lot of untangling is required to do it safely.
|
2018-09-10 19:02:26 +00:00
|
|
|
return;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
if ( $this->hasNewRevisionLoadError() ) {
|
|
|
|
|
// There was an error loading the new revision
|
|
|
|
|
return;
|
|
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$out->setRevisionId( $this->mNewid );
|
2022-08-06 14:40:47 +00:00
|
|
|
$out->setRevisionIsCurrent( $this->mNewRevisionRecord->isCurrent() );
|
2020-04-29 16:38:25 +00:00
|
|
|
$out->setRevisionTimestamp( $this->mNewRevisionRecord->getTimestamp() );
|
2011-11-10 13:06:52 +00:00
|
|
|
$out->setArticleFlag( true );
|
2011-02-12 04:06:22 +00:00
|
|
|
|
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->onArticleRevisionViewCustom(
|
|
|
|
|
$this->mNewRevisionRecord, $this->mNewPage, $this->mOldid, $out )
|
2018-08-14 16:37:30 +00:00
|
|
|
) {
|
|
|
|
|
// Handled by extension
|
|
|
|
|
// NOTE: sync with hooks called in Article::view()
|
2011-11-14 18:28:01 +00:00
|
|
|
} else {
|
2011-11-17 20:21:54 +00:00
|
|
|
// Normal page
|
2021-12-14 20:34:46 +00:00
|
|
|
if ( $this->getTitle()->equals( $this->mNewPage ) ) {
|
|
|
|
|
// If the Title stored in the context is the same as the one
|
|
|
|
|
// of the new revision, we can use its associated WikiPage
|
|
|
|
|
// object.
|
|
|
|
|
$wikiPage = $this->getWikiPage();
|
|
|
|
|
} else {
|
|
|
|
|
// Otherwise we need to create our own WikiPage object
|
|
|
|
|
$wikiPage = $this->wikiPageFactory->newFromTitle( $this->mNewPage );
|
|
|
|
|
}
|
2011-11-14 18:28:01 +00:00
|
|
|
|
2022-12-18 00:22:42 +00:00
|
|
|
$parserOptions = $wikiPage->makeParserOptions( $this->getContext() );
|
|
|
|
|
$parserOptions->setRenderReason( 'diff-page' );
|
2011-11-14 18:28:01 +00:00
|
|
|
|
2022-12-18 00:22:42 +00:00
|
|
|
$parserOutputAccess = MediaWikiServices::getInstance()->getParserOutputAccess();
|
|
|
|
|
$status = $parserOutputAccess->getParserOutput(
|
|
|
|
|
$wikiPage,
|
|
|
|
|
$parserOptions,
|
|
|
|
|
$this->mNewRevisionRecord,
|
|
|
|
|
// we already checked
|
2023-06-26 02:04:42 +00:00
|
|
|
ParserOutputAccess::OPT_NO_AUDIENCE_CHECK |
|
|
|
|
|
// Update cascading protection
|
|
|
|
|
ParserOutputAccess::OPT_LINKS_UPDATE
|
2022-12-18 00:22:42 +00:00
|
|
|
);
|
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
|
$parserOutput = $status->getValue();
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to change parser output here
|
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->onDifferenceEngineRenderRevisionAddParserOutput(
|
|
|
|
|
$this, $out, $parserOutput, $wikiPage )
|
2017-10-22 14:44:04 +00:00
|
|
|
) {
|
2017-11-22 20:07:51 +00:00
|
|
|
$out->addParserOutput( $parserOutput, [
|
2020-04-29 16:38:25 +00:00
|
|
|
'enableSectionEditLinks' => $this->mNewRevisionRecord->isCurrent()
|
2021-02-27 02:03:46 +00:00
|
|
|
&& $this->getAuthority()->probablyCan(
|
2019-08-23 23:53:15 +00:00
|
|
|
'edit',
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->mNewRevisionRecord->getPage()
|
2021-10-04 03:32:27 +00:00
|
|
|
),
|
|
|
|
|
'absoluteURLs' => $this->slotDiffOptions['expand-url'] ?? false
|
2017-11-22 20:07:51 +00:00
|
|
|
] );
|
2016-07-08 16:46:20 +00:00
|
|
|
}
|
2022-12-18 00:22:42 +00:00
|
|
|
} else {
|
|
|
|
|
$out->addHTML(
|
|
|
|
|
Html::errorBox(
|
|
|
|
|
$out->parseAsInterface(
|
|
|
|
|
$status->getWikiText( false, false, $this->getLanguage() )
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2011-02-12 04:06:22 +00:00
|
|
|
}
|
2010-12-11 05:32:48 +00:00
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-04-17 07:37:55 +00:00
|
|
|
/**
|
2011-11-10 13:06:52 +00:00
|
|
|
* Get the diff text, send it to the OutputPage object
|
2010-11-07 16:28:11 +00:00
|
|
|
* Returns false if the diff could not be generated, otherwise returns true
|
2011-06-01 16:27:46 +00:00
|
|
|
*
|
2020-11-21 01:11:54 +00:00
|
|
|
* @param string|false $otitle Header for old text or false
|
|
|
|
|
* @param string|false $ntitle Header for new text or false
|
2013-10-29 23:43:53 +00:00
|
|
|
* @param string $notice HTML between diff header and body
|
|
|
|
|
*
|
2011-06-01 16:27:46 +00:00
|
|
|
* @return bool
|
2004-04-17 07:37:55 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function showDiff( $otitle, $ntitle, $notice = '' ) {
|
2016-07-08 16:46:20 +00:00
|
|
|
// Allow extensions to affect the output here
|
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->onDifferenceEngineShowDiff( $this );
|
2016-07-08 16:46:20 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
$diff = $this->getDiff( $otitle, $ntitle, $notice );
|
|
|
|
|
if ( $diff === false ) {
|
2012-08-20 14:55:28 +00:00
|
|
|
$this->showMissingRevision();
|
2010-11-07 16:28:11 +00:00
|
|
|
return false;
|
2022-01-21 08:55:23 +00:00
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2022-01-21 08:55:23 +00:00
|
|
|
$this->showDiffStyle();
|
|
|
|
|
if ( $this->slotDiffOptions['expand-url'] ?? false ) {
|
|
|
|
|
$diff = Linker::expandLocalLinks( $diff );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2022-01-21 08:55:23 +00:00
|
|
|
$this->getOutput()->addHTML( $diff );
|
|
|
|
|
return true;
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
|
|
|
|
|
/**
|
2016-08-31 08:14:48 +00:00
|
|
|
* Add style sheets for diff display.
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function showDiffStyle() {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$this->isSlotDiffRenderer ) {
|
2021-06-23 13:55:13 +00:00
|
|
|
$this->getOutput()->addModules( 'mediawiki.diff' );
|
2019-01-09 00:30:18 +00:00
|
|
|
$this->getOutput()->addModuleStyles( [
|
|
|
|
|
'mediawiki.interface.helpers.styles',
|
|
|
|
|
'mediawiki.diff.styles'
|
|
|
|
|
] );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
|
|
|
|
|
$slotDiffRenderer->addModules( $this->getOutput() );
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get complete diff table, including header
|
2004-04-17 07:37:55 +00:00
|
|
|
*
|
2020-11-21 01:11:54 +00:00
|
|
|
* @param string|false $otitle Header for old text or false
|
|
|
|
|
* @param string|false $ntitle Header for new text or false
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $notice HTML between diff header and body
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
2023-01-09 08:05:52 +00:00
|
|
|
* @return string|false
|
2004-04-17 07:37:55 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function getDiff( $otitle, $ntitle, $notice = '' ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$body = $this->getDiffBody();
|
|
|
|
|
if ( $body === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-04 13:43:09 +00:00
|
|
|
|
|
|
|
|
$multi = $this->getMultiNotice();
|
|
|
|
|
// Display a message when the diff is empty
|
|
|
|
|
if ( $body === '' ) {
|
|
|
|
|
$notice .= '<div class="mw-diff-empty">' .
|
|
|
|
|
$this->msg( 'diff-empty' )->parse() .
|
|
|
|
|
"</div>\n";
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-10 14:32:48 +00:00
|
|
|
if ( $this->cacheHitKey !== null ) {
|
|
|
|
|
$body .= "\n<!-- diff cache key " . htmlspecialchars( $this->cacheHitKey ) . " -->\n";
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-04 13:43:09 +00:00
|
|
|
return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
|
2024-05-04 10:00:17 +00:00
|
|
|
private function incrementStats( string $cacheStatus ): void {
|
|
|
|
|
$stats = MediaWikiServices::getInstance()->getStatsFactory();
|
|
|
|
|
$stats->getCounter( 'diff_cache_total' )
|
|
|
|
|
->setLabel( 'status', $cacheStatus )
|
|
|
|
|
->copyToStatsdAt( 'diff_cache.' . $cacheStatus )
|
|
|
|
|
->increment();
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-17 07:37:55 +00:00
|
|
|
/**
|
2010-11-07 16:28:11 +00:00
|
|
|
* Get the diff table body, without header
|
2004-04-17 07:37:55 +00:00
|
|
|
*
|
2020-11-21 01:11:54 +00:00
|
|
|
* @return string|false
|
2004-04-17 07:37:55 +00:00
|
|
|
*/
|
2010-11-18 20:34:02 +00:00
|
|
|
public function getDiffBody() {
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mCacheHit = true;
|
2010-11-07 16:28:11 +00:00
|
|
|
// Check if the diff should be hidden from this user
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$this->isContentOverridden ) {
|
|
|
|
|
if ( !$this->loadRevisionData() ) {
|
|
|
|
|
return false;
|
2020-04-29 16:38:25 +00:00
|
|
|
} elseif ( $this->mOldRevisionRecord &&
|
2021-02-24 15:46:13 +00:00
|
|
|
!$this->mOldRevisionRecord->userCan(
|
2020-03-11 01:41:49 +00:00
|
|
|
RevisionRecord::DELETED_TEXT,
|
2021-02-24 15:46:13 +00:00
|
|
|
$this->getAuthority()
|
2020-03-11 01:41:49 +00:00
|
|
|
)
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
|
|
|
|
return false;
|
2020-04-29 16:38:25 +00:00
|
|
|
} elseif ( $this->mNewRevisionRecord &&
|
2021-02-24 15:46:13 +00:00
|
|
|
!$this->mNewRevisionRecord->userCan(
|
2020-03-11 01:41:49 +00:00
|
|
|
RevisionRecord::DELETED_TEXT,
|
2021-02-24 15:46:13 +00:00
|
|
|
$this->getAuthority()
|
|
|
|
|
) ) {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Short-circuit
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord === false || (
|
|
|
|
|
$this->mOldRevisionRecord &&
|
|
|
|
|
$this->mNewRevisionRecord &&
|
|
|
|
|
$this->mOldRevisionRecord->getId() &&
|
|
|
|
|
$this->mOldRevisionRecord->getId() == $this->mNewRevisionRecord->getId()
|
|
|
|
|
) ) {
|
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->onDifferenceEngineShowEmptyOldContent( $this ) ) {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2016-07-08 16:46:20 +00:00
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
// Cacheable?
|
|
|
|
|
$key = false;
|
2020-04-15 19:52:47 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$cache = $services->getMainWANObjectCache();
|
|
|
|
|
$stats = $services->getStatsdDataFactory();
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mOldid && $this->mNewid ) {
|
2022-11-13 14:37:10 +00:00
|
|
|
$key = $cache->makeKey( ...$this->getDiffBodyCacheKeyParams() );
|
2013-10-27 02:47:28 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
// Try cache
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( !$this->mRefreshCache ) {
|
2015-10-15 02:45:03 +00:00
|
|
|
$difftext = $cache->get( $key );
|
2019-02-19 20:54:33 +00:00
|
|
|
if ( is_string( $difftext ) ) {
|
2024-05-04 10:00:17 +00:00
|
|
|
$this->incrementStats( 'hit' );
|
2017-11-07 11:44:53 +00:00
|
|
|
$difftext = $this->localiseDiff( $difftext );
|
2023-06-10 14:32:48 +00:00
|
|
|
$this->cacheHitKey = $key;
|
2010-11-07 16:28:11 +00:00
|
|
|
return $difftext;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
} // don't try to load but save the result
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mCacheHit = false;
|
2023-06-10 14:32:48 +00:00
|
|
|
$this->cacheHitKey = null;
|
2004-04-17 07:37:55 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
// Loadtext is permission safe, this just clears out the diff
|
|
|
|
|
if ( !$this->loadText() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$difftext = '';
|
|
|
|
|
// We've checked for revdelete at the beginning of this method; it's OK to ignore
|
|
|
|
|
// read permissions here.
|
|
|
|
|
$slotContents = $this->getSlotContents();
|
|
|
|
|
foreach ( $this->getSlotDiffRenderers() as $role => $slotDiffRenderer ) {
|
2019-01-20 23:11:59 +00:00
|
|
|
try {
|
|
|
|
|
$slotDiff = $slotDiffRenderer->getDiff( $slotContents[$role]['old'],
|
|
|
|
|
$slotContents[$role]['new'] );
|
|
|
|
|
} catch ( IncompatibleDiffTypesException $e ) {
|
|
|
|
|
$slotDiff = $this->getSlotError( $e->getMessageObject()->parse() );
|
|
|
|
|
}
|
2018-09-24 21:10:08 +00:00
|
|
|
if ( $slotDiff && $role !== SlotRecord::MAIN ) {
|
2018-11-19 11:39:56 +00:00
|
|
|
// FIXME: ask SlotRoleHandler::getSlotNameMessage
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$slotTitle = $role;
|
|
|
|
|
$difftext .= $this->getSlotHeader( $slotTitle );
|
|
|
|
|
}
|
|
|
|
|
$difftext .= $slotDiff;
|
|
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
// Save to cache for 7 days
|
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->onAbortDiffCache( $this ) ) {
|
2024-05-04 10:00:17 +00:00
|
|
|
$this->incrementStats( 'uncacheable' );
|
2020-06-22 20:36:04 +00:00
|
|
|
} elseif ( $key !== false ) {
|
2024-05-04 10:00:17 +00:00
|
|
|
$this->incrementStats( 'miss' );
|
2015-10-15 02:45:03 +00:00
|
|
|
$cache->set( $key, $difftext, 7 * 86400 );
|
2010-11-07 16:28:11 +00:00
|
|
|
} else {
|
2024-05-04 10:00:17 +00:00
|
|
|
$this->incrementStats( 'uncacheable' );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2017-11-07 11:44:53 +00:00
|
|
|
// localise line numbers and title attribute text
|
2020-06-22 20:36:04 +00:00
|
|
|
$difftext = $this->localiseDiff( $difftext );
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return $difftext;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-26 21:24:59 +00:00
|
|
|
/**
|
|
|
|
|
* Get the diff table body for one slot, without header
|
|
|
|
|
*
|
|
|
|
|
* @param string $role
|
|
|
|
|
* @return string|false
|
|
|
|
|
*/
|
|
|
|
|
public function getDiffBodyForRole( $role ) {
|
|
|
|
|
$diffRenderers = $this->getSlotDiffRenderers();
|
|
|
|
|
if ( !isset( $diffRenderers[$role] ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$slotContents = $this->getSlotContents();
|
2019-01-20 23:11:59 +00:00
|
|
|
try {
|
|
|
|
|
$slotDiff = $diffRenderers[$role]->getDiff( $slotContents[$role]['old'],
|
|
|
|
|
$slotContents[$role]['new'] );
|
|
|
|
|
} catch ( IncompatibleDiffTypesException $e ) {
|
|
|
|
|
$slotDiff = $this->getSlotError( $e->getMessageObject()->parse() );
|
|
|
|
|
}
|
2023-06-21 01:05:25 +00:00
|
|
|
if ( $slotDiff === '' ) {
|
2018-07-26 21:24:59 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 21:10:08 +00:00
|
|
|
if ( $role !== SlotRecord::MAIN ) {
|
2018-07-26 21:24:59 +00:00
|
|
|
// TODO use human-readable role name at least
|
|
|
|
|
$slotTitle = $role;
|
|
|
|
|
$slotDiff = $this->getSlotHeader( $slotTitle ) . $slotDiff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->localiseDiff( $slotDiff );
|
|
|
|
|
}
|
|
|
|
|
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
/**
|
|
|
|
|
* Get a slot header for inclusion in a diff body (as a table row).
|
|
|
|
|
*
|
|
|
|
|
* @param string $headerText The text of the header
|
|
|
|
|
* @return string
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
protected function getSlotHeader( $headerText ) {
|
|
|
|
|
// The old revision is missing on oldid=<first>&diff=prev; only 2 columns in that case.
|
2020-04-29 16:38:25 +00:00
|
|
|
$columnCount = $this->mOldRevisionRecord ? 4 : 2;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$userLang = $this->getLanguage()->getHtmlCode();
|
|
|
|
|
return Html::rawElement( 'tr', [ 'class' => 'mw-diff-slot-header', 'lang' => $userLang ],
|
|
|
|
|
Html::element( 'th', [ 'colspan' => $columnCount ], $headerText ) );
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 23:11:59 +00:00
|
|
|
/**
|
|
|
|
|
* Get an error message for inclusion in a diff body (as a table row).
|
|
|
|
|
*
|
2023-09-23 15:09:06 +00:00
|
|
|
* @param string $errorText The HTML of the error
|
2019-01-20 23:11:59 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getSlotError( $errorText ) {
|
|
|
|
|
// The old revision is missing on oldid=<first>&diff=prev; only 2 columns in that case.
|
|
|
|
|
$columnCount = $this->mOldRevisionRecord ? 4 : 2;
|
|
|
|
|
$userLang = $this->getLanguage()->getHtmlCode();
|
|
|
|
|
return Html::rawElement( 'tr', [ 'class' => 'mw-diff-slot-error', 'lang' => $userLang ],
|
2023-09-23 15:09:06 +00:00
|
|
|
Html::rawElement( 'td', [ 'colspan' => $columnCount ], $errorText ) );
|
2019-01-20 23:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-04 20:15:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get the cache key parameters
|
|
|
|
|
*
|
|
|
|
|
* Subclasses can replace the first element in the array to something
|
|
|
|
|
* more specific to the type of diff (e.g. "inline-diff"), or append
|
|
|
|
|
* if the cache should vary on more things. Overriding entirely should
|
|
|
|
|
* be avoided.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.31
|
|
|
|
|
*
|
2020-11-21 01:11:54 +00:00
|
|
|
* @return string[]
|
2022-10-08 12:15:06 +00:00
|
|
|
* @phan-return non-empty-array<string>
|
2017-11-04 20:15:26 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDiffBodyCacheKeyParams() {
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( !$this->mOldid || !$this->mNewid ) {
|
2023-06-09 15:01:45 +00:00
|
|
|
throw new BadMethodCallException( 'mOldid and mNewid must be set to get diff cache key.' );
|
2013-10-27 02:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-04 20:15:26 +00:00
|
|
|
$params = [
|
|
|
|
|
'diff',
|
|
|
|
|
self::DIFF_VERSION,
|
|
|
|
|
"old-{$this->mOldid}",
|
|
|
|
|
"rev-{$this->mNewid}"
|
|
|
|
|
];
|
|
|
|
|
|
2023-07-03 08:27:47 +00:00
|
|
|
$extraKeys = [];
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
if ( !$this->isSlotDiffRenderer ) {
|
|
|
|
|
foreach ( $this->getSlotDiffRenderers() as $slotDiffRenderer ) {
|
2023-07-03 08:27:47 +00:00
|
|
|
$extraKeys = array_merge( $extraKeys, $slotDiffRenderer->getExtraCacheKeys() );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 08:27:47 +00:00
|
|
|
ksort( $extraKeys );
|
|
|
|
|
return array_merge( $params, array_values( $extraKeys ) );
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements DifferenceEngineSlotDiffRenderer::getExtraCacheKeys(). Only used when
|
|
|
|
|
* DifferenceEngine is wrapped in DifferenceEngineSlotDiffRenderer.
|
2020-11-21 01:11:54 +00:00
|
|
|
* @return string[]
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @internal for use by DifferenceEngineSlotDiffRenderer only
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
public function getExtraCacheKeys() {
|
|
|
|
|
// This method is called when the DifferenceEngine is used for a slot diff. We only care
|
|
|
|
|
// about special things, not the revision IDs, which are added to the cache key by the
|
|
|
|
|
// page-level DifferenceEngine, and which might not have a valid value for this object.
|
|
|
|
|
$this->mOldid = 123456789;
|
|
|
|
|
$this->mNewid = 987654321;
|
|
|
|
|
|
|
|
|
|
// This will repeat a bunch of unnecessary key fields for each slot. Not nice but harmless.
|
|
|
|
|
$params = $this->getDiffBodyCacheKeyParams();
|
|
|
|
|
|
|
|
|
|
// Try to get rid of the standard keys to keep the cache key human-readable:
|
|
|
|
|
// call the getDiffBodyCacheKeyParams implementation of the base class, and if
|
|
|
|
|
// the child class includes the same keys, drop them.
|
|
|
|
|
// Uses an obscure PHP feature where static calls to non-static methods are allowed
|
|
|
|
|
// as long as we are already in a non-static method of the same class, and the call context
|
|
|
|
|
// ($this) will be inherited.
|
|
|
|
|
// phpcs:ignore Squiz.Classes.SelfMemberReference.NotUsed
|
|
|
|
|
$standardParams = DifferenceEngine::getDiffBodyCacheKeyParams();
|
|
|
|
|
if ( array_slice( $params, 0, count( $standardParams ) ) === $standardParams ) {
|
|
|
|
|
$params = array_slice( $params, count( $standardParams ) );
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-04 20:15:26 +00:00
|
|
|
return $params;
|
2013-10-27 02:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-29 23:30:32 +00:00
|
|
|
/**
|
2023-07-03 08:27:47 +00:00
|
|
|
* @param array $options for the difference engine. Available options:
|
|
|
|
|
* - diff-type: The text diff format, e.g. "table" or "inline". If the
|
|
|
|
|
* specified format is not supported, the option will be ignored, so
|
|
|
|
|
* the site default format (table) will be used.
|
|
|
|
|
* - expand-url: If true, put full URLs in href attributes (for action=render)
|
|
|
|
|
* FIXME: expand-url is not a slot diff option, it is a DifferenceEngine option.
|
2023-07-26 12:54:23 +00:00
|
|
|
* - inline-toggle: If true, and the inline format is supported
|
|
|
|
|
* a format selector toggle switch will be shown.
|
2019-10-29 23:30:32 +00:00
|
|
|
*/
|
|
|
|
|
public function setSlotDiffOptions( $options ) {
|
2023-07-03 08:27:47 +00:00
|
|
|
$validatedOptions = [];
|
|
|
|
|
if ( isset( $options['diff-type'] )
|
|
|
|
|
&& $this->getTextDiffer()->hasFormat( $options['diff-type'] )
|
|
|
|
|
) {
|
|
|
|
|
$validatedOptions['diff-type'] = $options['diff-type'];
|
|
|
|
|
}
|
|
|
|
|
if ( !empty( $options['expand-url'] ) ) {
|
|
|
|
|
$validatedOptions['expand-url'] = true;
|
|
|
|
|
}
|
2023-07-25 00:47:29 +00:00
|
|
|
if ( !empty( $options['inline-toggle'] ) ) {
|
|
|
|
|
$validatedOptions['inline-toggle'] = true;
|
|
|
|
|
}
|
2023-07-03 08:27:47 +00:00
|
|
|
$this->slotDiffOptions = $validatedOptions;
|
2019-10-29 23:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 01:35:08 +00:00
|
|
|
/**
|
|
|
|
|
* Set query parameters to append to diff page links
|
|
|
|
|
*
|
|
|
|
|
* @since 1.41
|
|
|
|
|
*
|
|
|
|
|
* @param array $params
|
|
|
|
|
*/
|
|
|
|
|
public function setExtraQueryParams( $params ) {
|
|
|
|
|
$this->extraQueryParams = $params;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 09:12:19 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a diff, no caching.
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*
|
|
|
|
|
* @param Content $old Old content
|
|
|
|
|
* @param Content $new New content
|
2012-06-12 09:12:19 +00:00
|
|
|
*
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @throws Exception If old or new content is not an instance of TextContent.
|
2012-12-09 03:12:12 +00:00
|
|
|
* @return bool|string
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated since 1.32, use a SlotDiffRenderer instead.
|
2012-06-12 09:12:19 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function generateContentDiffBody( Content $old, Content $new ) {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$slotDiffRenderer = $new->getContentHandler()->getSlotDiffRenderer( $this->getContext() );
|
|
|
|
|
if (
|
|
|
|
|
$slotDiffRenderer instanceof DifferenceEngineSlotDiffRenderer
|
|
|
|
|
&& $this->isSlotDiffRenderer
|
|
|
|
|
) {
|
|
|
|
|
// Oops, we are just about to enter an infinite loop (the slot-level DifferenceEngine
|
|
|
|
|
// called a DifferenceEngineSlotDiffRenderer that wraps the same DifferenceEngine class).
|
|
|
|
|
// This will happen when a content model has no custom slot diff renderer, it does have
|
|
|
|
|
// a custom difference engine, but that does not override this method.
|
2024-02-08 23:12:50 +00:00
|
|
|
throw new LogicException( get_class( $this ) . ': could not maintain backwards compatibility. '
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
. 'Please use a SlotDiffRenderer.' );
|
2012-08-21 14:26:14 +00:00
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return $slotDiffRenderer->getDiff( $old, $new ) . $this->getDebugString();
|
2012-06-12 09:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a diff, no caching
|
|
|
|
|
*
|
2014-07-24 17:42:45 +00:00
|
|
|
* @param string $otext Old text, must be already segmented
|
|
|
|
|
* @param string $ntext New text, must be already segmented
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
2024-02-08 23:12:50 +00:00
|
|
|
* @throws LogicException If content handling for text content is configured in a way
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* that makes maintaining B/C hard.
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool|string
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated since 1.32, use a TextSlotDiffRenderer instead.
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function generateTextDiffBody( $otext, $ntext ) {
|
2020-01-18 20:25:04 +00:00
|
|
|
$slotDiffRenderer = $this->contentHandlerFactory
|
|
|
|
|
->getContentHandler( CONTENT_MODEL_TEXT )
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
->getSlotDiffRenderer( $this->getContext() );
|
|
|
|
|
if ( !( $slotDiffRenderer instanceof TextSlotDiffRenderer ) ) {
|
|
|
|
|
// Someone used the GetSlotDiffRenderer hook to replace the renderer.
|
|
|
|
|
// This is too unlikely to happen to bother handling properly.
|
2024-02-08 23:12:50 +00:00
|
|
|
throw new LogicException( 'The slot diff renderer for text content should be a '
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
. 'TextSlotDiffRenderer subclass' );
|
2016-03-11 21:11:43 +00:00
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return $slotDiffRenderer->getTextDiff( $otext, $ntext ) . $this->getDebugString();
|
2016-03-04 22:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-22 13:35:17 +00:00
|
|
|
* Process DiffEngine config and get a sensible, usable engine
|
2016-03-04 22:41:50 +00:00
|
|
|
*
|
2019-11-05 15:07:06 +00:00
|
|
|
* @return string 'wikidiff2', 'php', or path to an executable
|
2023-04-07 19:40:34 +00:00
|
|
|
* @internal For use by this class and within Core only.
|
2016-03-04 22:41:50 +00:00
|
|
|
*/
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
public static function getEngine() {
|
2023-07-03 08:27:47 +00:00
|
|
|
$differenceEngine = new self;
|
|
|
|
|
$engine = $differenceEngine->getTextDiffer()->getEngineForFormat( 'table' );
|
|
|
|
|
if ( $engine === 'external' ) {
|
|
|
|
|
return MediaWikiServices::getInstance()->getMainConfig()
|
|
|
|
|
->get( MainConfigNames::ExternalDiffEngine );
|
2019-11-05 15:07:06 +00:00
|
|
|
} else {
|
2023-07-03 08:27:47 +00:00
|
|
|
return $engine;
|
2019-11-05 15:07:06 +00:00
|
|
|
}
|
2017-11-04 20:15:26 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Generate a debug comment indicating diff generating time,
|
|
|
|
|
* server node, and generator backend.
|
2013-10-29 23:43:53 +00:00
|
|
|
*
|
2021-11-04 21:32:39 +00:00
|
|
|
* @param string $generator What diff engine was used
|
2013-10-29 23:43:53 +00:00
|
|
|
*
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return string
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2010-11-27 19:01:51 +00:00
|
|
|
protected function debug( $generator = "internal" ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
if ( !$this->enableDebugComment ) {
|
|
|
|
|
return '';
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = [ $generator ];
|
2022-04-25 15:19:41 +00:00
|
|
|
if ( $this->getConfig()->get( MainConfigNames::ShowHostnames ) ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$data[] = wfHostname();
|
|
|
|
|
}
|
|
|
|
|
$data[] = wfTimestamp( TS_DB );
|
2013-11-20 19:11:57 +00:00
|
|
|
|
|
|
|
|
return "<!-- diff generator: " .
|
2013-11-21 18:30:01 +00:00
|
|
|
implode( " ", array_map( "htmlspecialchars", $data ) ) .
|
2013-11-20 19:11:57 +00:00
|
|
|
" -->\n";
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-21 01:11:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
private function getDebugString() {
|
|
|
|
|
$engine = self::getEngine();
|
|
|
|
|
if ( $engine === 'wikidiff2' ) {
|
|
|
|
|
return $this->debug( 'wikidiff2' );
|
2019-11-05 15:07:06 +00:00
|
|
|
} elseif ( $engine === 'php' ) {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
return $this->debug( 'native PHP' );
|
|
|
|
|
} else {
|
|
|
|
|
return $this->debug( "external $engine" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 11:44:53 +00:00
|
|
|
/**
|
|
|
|
|
* Localise diff output
|
|
|
|
|
*
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function localiseDiff( $text ) {
|
2023-07-03 08:27:47 +00:00
|
|
|
return $this->getTextDiffer()->localize( $this->getTextDiffFormat(), $text );
|
2017-11-07 11:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-19 10:24:00 +00:00
|
|
|
/**
|
|
|
|
|
* Replace a common convention for language-independent line numbers with
|
|
|
|
|
* the text in the user's language.
|
|
|
|
|
*
|
2023-10-02 23:20:49 +00:00
|
|
|
* @deprecated since 1.41, use BaseTextDiffer::localizeLineNumbers()
|
2023-07-19 10:24:00 +00:00
|
|
|
* @param string $text
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function localiseLineNumbers( $text ) {
|
|
|
|
|
return preg_replace_callback( '/<!--LINE (\d+)-->/',
|
|
|
|
|
function ( array $matches ) {
|
|
|
|
|
if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
|
|
|
|
|
}, $text );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* If there are revisions between the ones being compared, return a note saying so.
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
2010-11-18 00:08:37 +00:00
|
|
|
* @return string
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function getMultiNotice() {
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
// The notice only make sense if we are diffing two saved revisions of the same page.
|
|
|
|
|
if (
|
2020-04-29 16:38:25 +00:00
|
|
|
!$this->mOldRevisionRecord || !$this->mNewRevisionRecord
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|| !$this->mOldPage || !$this->mNewPage
|
|
|
|
|
|| !$this->mOldPage->equals( $this->mNewPage )
|
2020-04-29 16:38:25 +00:00
|
|
|
|| $this->mOldRevisionRecord->getId() === null
|
|
|
|
|
|| $this->mNewRevisionRecord->getId() === null
|
2019-11-20 18:19:00 +00:00
|
|
|
// (T237709) Deleted revs might have different page IDs
|
2020-04-29 16:38:25 +00:00
|
|
|
|| $this->mNewPage->getArticleID() !== $this->mOldRevisionRecord->getPageId()
|
|
|
|
|
|| $this->mNewPage->getArticleID() !== $this->mNewRevisionRecord->getPageId()
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
2010-11-07 16:28:11 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord->getTimestamp() > $this->mNewRevisionRecord->getTimestamp() ) {
|
|
|
|
|
$oldRevRecord = $this->mNewRevisionRecord; // flip
|
|
|
|
|
$newRevRecord = $this->mOldRevisionRecord; // flip
|
2011-04-05 23:28:39 +00:00
|
|
|
} else { // normal case
|
2020-04-29 16:38:25 +00:00
|
|
|
$oldRevRecord = $this->mOldRevisionRecord;
|
|
|
|
|
$newRevRecord = $this->mNewRevisionRecord;
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2005-08-31 02:22:05 +00:00
|
|
|
|
2021-11-19 23:19:42 +00:00
|
|
|
// Don't show the notice if too many rows must be scanned
|
2014-07-23 20:04:48 +00:00
|
|
|
// @todo show some special message for that case
|
2023-08-05 03:47:35 +00:00
|
|
|
$nEdits = 0;
|
|
|
|
|
$revisionIdList = $this->revisionStore->getRevisionIdsBetween(
|
2020-03-26 22:40:22 +00:00
|
|
|
$this->mNewPage->getArticleID(),
|
2020-04-29 16:38:25 +00:00
|
|
|
$oldRevRecord,
|
|
|
|
|
$newRevRecord,
|
2020-03-26 22:40:22 +00:00
|
|
|
1000
|
|
|
|
|
);
|
2023-08-05 03:47:35 +00:00
|
|
|
// only count revisions that are visible
|
|
|
|
|
if ( count( $revisionIdList ) > 0 ) {
|
|
|
|
|
foreach ( $revisionIdList as $revisionId ) {
|
|
|
|
|
$revision = $this->revisionStore->getRevisionById( $revisionId );
|
|
|
|
|
if ( $revision->getUser( RevisionRecord::FOR_THIS_USER, $this->getAuthority() ) ) {
|
|
|
|
|
$nEdits++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-07 22:18:19 +00:00
|
|
|
if ( $nEdits > 0 && $nEdits <= 1000 ) {
|
2023-04-09 14:25:17 +00:00
|
|
|
// Use an invalid username to get the wiki's default gender (as fallback)
|
|
|
|
|
$newRevUserForGender = '[HIDDEN]';
|
2011-04-05 23:28:39 +00:00
|
|
|
$limit = 100; // use diff-multi-manyusers if too many users
|
2020-04-08 02:36:23 +00:00
|
|
|
try {
|
|
|
|
|
$users = $this->revisionStore->getAuthorsBetween(
|
|
|
|
|
$this->mNewPage->getArticleID(),
|
2020-04-29 16:38:25 +00:00
|
|
|
$oldRevRecord,
|
|
|
|
|
$newRevRecord,
|
2020-04-08 02:36:23 +00:00
|
|
|
null,
|
|
|
|
|
$limit
|
|
|
|
|
);
|
|
|
|
|
$numUsers = count( $users );
|
2014-02-05 11:02:29 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$newRevUser = $newRevRecord->getUser( RevisionRecord::RAW );
|
|
|
|
|
$newRevUserText = $newRevUser ? $newRevUser->getName() : '';
|
2023-04-09 14:25:17 +00:00
|
|
|
$newRevUserSafe = $newRevRecord->getUser(
|
|
|
|
|
RevisionRecord::FOR_THIS_USER,
|
|
|
|
|
$this->getAuthority()
|
|
|
|
|
);
|
|
|
|
|
$newRevUserForGender = $newRevUserSafe ? $newRevUserSafe->getName() : '[HIDDEN]';
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $numUsers == 1 && $users[0]->getName() == $newRevUserText ) {
|
2020-04-08 02:36:23 +00:00
|
|
|
$numUsers = 0; // special case to say "by the same user" instead of "by one other user"
|
|
|
|
|
}
|
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
|
$numUsers = 0;
|
2014-01-08 20:29:42 +00:00
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2023-04-09 14:25:17 +00:00
|
|
|
return self::intermediateEditsMsg( $nEdits, $numUsers, $limit, $newRevUserForGender );
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2019-01-09 16:15:21 +00:00
|
|
|
return '';
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-18 00:08:37 +00:00
|
|
|
/**
|
|
|
|
|
* Get a notice about how many intermediate edits and users there are
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
|
|
|
|
* @param int $numEdits
|
|
|
|
|
* @param int $numUsers
|
|
|
|
|
* @param int $limit
|
2023-04-09 14:25:17 +00:00
|
|
|
* @param string $lastUser
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
2010-11-18 00:08:37 +00:00
|
|
|
* @return string
|
2010-11-27 19:01:51 +00:00
|
|
|
*/
|
2023-04-09 14:25:17 +00:00
|
|
|
public static function intermediateEditsMsg( $numEdits, $numUsers, $limit, $lastUser = '[HIDDEN]' ) {
|
2014-01-08 20:29:42 +00:00
|
|
|
if ( $numUsers === 0 ) {
|
|
|
|
|
$msg = 'diff-multi-sameuser';
|
2023-04-09 14:25:17 +00:00
|
|
|
return wfMessage( $msg )
|
|
|
|
|
->numParams( $numEdits, $numUsers )
|
|
|
|
|
->params( $lastUser )
|
|
|
|
|
->parse();
|
2014-01-08 20:29:42 +00:00
|
|
|
} elseif ( $numUsers > $limit ) {
|
2010-11-18 00:08:37 +00:00
|
|
|
$msg = 'diff-multi-manyusers';
|
|
|
|
|
$numUsers = $limit;
|
|
|
|
|
} else {
|
2014-01-08 20:29:42 +00:00
|
|
|
$msg = 'diff-multi-otherusers';
|
2010-11-18 00:08:37 +00:00
|
|
|
}
|
2013-11-20 19:11:57 +00:00
|
|
|
|
2011-11-10 13:06:52 +00:00
|
|
|
return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
|
2010-11-18 00:08:37 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2019-08-21 15:51:10 +00:00
|
|
|
/**
|
2020-04-29 16:38:25 +00:00
|
|
|
* @param RevisionRecord $revRecord
|
2019-08-21 15:51:10 +00:00
|
|
|
* @return bool whether the user can see and edit the revision.
|
|
|
|
|
*/
|
2020-04-29 16:38:25 +00:00
|
|
|
private function userCanEdit( RevisionRecord $revRecord ) {
|
2021-02-24 15:46:13 +00:00
|
|
|
if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
|
2019-08-21 15:51:10 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
/**
|
|
|
|
|
* Get a header for a specified revision.
|
|
|
|
|
*
|
2021-05-02 02:44:33 +00:00
|
|
|
* @param RevisionRecord $rev
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $complete 'complete' to get the header wrapped depending
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
* the visibility of the revision and a link to edit the page.
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
|
|
|
|
* @return string HTML fragment
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
*/
|
2021-05-02 02:44:33 +00:00
|
|
|
public function getRevisionHeader( RevisionRecord $rev, $complete = '' ) {
|
2011-11-21 16:13:21 +00:00
|
|
|
$lang = $this->getLanguage();
|
2011-11-10 13:06:52 +00:00
|
|
|
$user = $this->getUser();
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$revtimestamp = $rev->getTimestamp();
|
2011-11-10 13:06:52 +00:00
|
|
|
$timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
|
|
|
|
|
$dateofrev = $lang->userDate( $revtimestamp, $user );
|
|
|
|
|
$timeofrev = $lang->userTime( $revtimestamp, $user );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2011-11-10 13:06:52 +00:00
|
|
|
$header = $this->msg(
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$rev->isCurrent() ? 'currentrev-asof' : 'revisionasof',
|
|
|
|
|
$timestamp,
|
|
|
|
|
$dateofrev,
|
|
|
|
|
$timeofrev
|
2019-09-07 09:27:30 +00:00
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
|
|
|
|
if ( $complete !== 'complete' ) {
|
2019-09-07 09:27:30 +00:00
|
|
|
return $header->escaped();
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-19 09:51:15 +00:00
|
|
|
$title = $rev->getPageAsLinkTarget();
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2019-08-21 15:51:10 +00:00
|
|
|
if ( $this->userCanEdit( $rev ) ) {
|
2022-12-17 20:50:05 +00:00
|
|
|
$header = $this->linkRenderer->makeKnownLink(
|
|
|
|
|
$title,
|
|
|
|
|
$header->text(),
|
2023-10-25 15:57:37 +00:00
|
|
|
[],
|
2022-12-17 20:50:05 +00:00
|
|
|
[ 'oldid' => $rev->getId() ]
|
|
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$editQuery = [ 'action' => 'edit' ];
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
if ( !$rev->isCurrent() ) {
|
2016-03-19 00:08:06 +00:00
|
|
|
$editQuery['oldid'] = $rev->getId();
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-27 02:03:46 +00:00
|
|
|
$key = $this->getAuthority()->probablyCan( 'edit', $rev->getPage() ) ? 'editold' : 'viewsourceold';
|
2019-09-07 09:27:30 +00:00
|
|
|
$msg = $this->msg( $key )->text();
|
2023-10-13 17:41:34 +00:00
|
|
|
$editLink = $this->linkRenderer->makeKnownLink( $title, $msg, [], $editQuery );
|
2014-07-05 17:57:37 +00:00
|
|
|
$header .= ' ' . Html::rawElement(
|
|
|
|
|
'span',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-diff-edit' ],
|
2014-07-05 17:57:37 +00:00
|
|
|
$editLink
|
|
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
} else {
|
2022-12-17 20:50:05 +00:00
|
|
|
$header = $header->escaped();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 18:31:19 +00:00
|
|
|
// Machine readable information
|
|
|
|
|
$header .= Html::element( 'span',
|
|
|
|
|
[
|
|
|
|
|
'class' => 'mw-diff-timestamp',
|
|
|
|
|
'data-timestamp' => wfTimestamp( TS_ISO_8601, $revtimestamp ),
|
|
|
|
|
], ''
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-17 20:50:05 +00:00
|
|
|
if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
|
|
|
|
|
return Html::rawElement(
|
|
|
|
|
'span',
|
|
|
|
|
[ 'class' => Linker::getRevisionDeletedClass( $rev ) ],
|
|
|
|
|
$header
|
|
|
|
|
);
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $header;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Add the header to a diff body
|
2011-06-01 16:27:46 +00:00
|
|
|
*
|
2013-11-20 19:11:57 +00:00
|
|
|
* @param string $diff Diff body
|
|
|
|
|
* @param string $otitle Old revision header
|
|
|
|
|
* @param string $ntitle New revision header
|
2013-11-20 19:22:36 +00:00
|
|
|
* @param string $multi Notice telling user that there are intermediate
|
|
|
|
|
* revisions between the ones being compared
|
2013-11-20 19:11:57 +00:00
|
|
|
* @param string $notice Other notices, e.g. that user is viewing deleted content
|
2013-10-29 23:43:53 +00:00
|
|
|
*
|
2011-06-01 16:27:46 +00:00
|
|
|
* @return string
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
|
2011-07-23 19:03:54 +00:00
|
|
|
// shared.css sets diff in interface language/dir, but the actual content
|
|
|
|
|
// is often in a different language, mostly the page content language/dir
|
2023-05-18 14:43:20 +00:00
|
|
|
$header = Html::openElement( 'table', [
|
2020-04-16 13:53:59 +00:00
|
|
|
'class' => [
|
|
|
|
|
'diff',
|
2023-03-16 06:48:38 +00:00
|
|
|
// The following classes are used here:
|
2023-09-29 22:24:10 +00:00
|
|
|
// * diff-type-table
|
|
|
|
|
// * diff-type-inline
|
|
|
|
|
'diff-type-' . $this->getTextDiffFormat(),
|
|
|
|
|
// The following classes are used here:
|
2023-03-16 06:48:38 +00:00
|
|
|
// * diff-contentalign-left
|
|
|
|
|
// * diff-contentalign-right
|
2020-04-16 13:53:59 +00:00
|
|
|
'diff-contentalign-' . $this->getDiffLang()->alignStart(),
|
2023-03-16 06:48:38 +00:00
|
|
|
// The following classes are used here:
|
|
|
|
|
// * diff-editfont-monospace
|
|
|
|
|
// * diff-editfont-sans-serif
|
|
|
|
|
// * diff-editfont-serif
|
2022-04-22 12:21:13 +00:00
|
|
|
'diff-editfont-' . $this->userOptionsLookup->getOption(
|
|
|
|
|
$this->getUser(),
|
|
|
|
|
'editfont'
|
|
|
|
|
)
|
2020-04-16 13:53:59 +00:00
|
|
|
],
|
2015-12-03 12:12:25 +00:00
|
|
|
'data-mw' => 'interface',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-04-17 21:49:52 +00:00
|
|
|
$userLang = htmlspecialchars( $this->getLanguage()->getHtmlCode() );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
|
|
|
|
if ( !$diff && !$otitle ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
$header .= "
|
2018-03-05 18:24:37 +00:00
|
|
|
<tr class=\"diff-title\" lang=\"{$userLang}\">
|
2017-07-03 06:51:10 +00:00
|
|
|
<td class=\"diff-ntitle\">{$ntitle}</td>
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
</tr>";
|
|
|
|
|
$multiColspan = 1;
|
2010-11-07 16:28:11 +00:00
|
|
|
} else {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
if ( $diff ) { // Safari/Chrome show broken output if cols not used
|
|
|
|
|
$header .= "
|
2017-07-03 06:51:10 +00:00
|
|
|
<col class=\"diff-marker\" />
|
|
|
|
|
<col class=\"diff-content\" />
|
|
|
|
|
<col class=\"diff-marker\" />
|
|
|
|
|
<col class=\"diff-content\" />";
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
$colspan = 2;
|
|
|
|
|
$multiColspan = 4;
|
|
|
|
|
} else {
|
|
|
|
|
$colspan = 1;
|
|
|
|
|
$multiColspan = 2;
|
|
|
|
|
}
|
2013-06-10 17:43:47 +00:00
|
|
|
if ( $otitle || $ntitle ) {
|
2021-08-12 14:45:04 +00:00
|
|
|
// FIXME Hardcoding values from TableDiffFormatter.
|
2021-09-16 13:47:16 +00:00
|
|
|
$deletedClass = 'diff-side-deleted';
|
|
|
|
|
$addedClass = 'diff-side-added';
|
2013-06-10 17:43:47 +00:00
|
|
|
$header .= "
|
2018-03-05 18:24:37 +00:00
|
|
|
<tr class=\"diff-title\" lang=\"{$userLang}\">
|
2021-09-16 13:47:16 +00:00
|
|
|
<td colspan=\"$colspan\" class=\"diff-otitle {$deletedClass}\">{$otitle}</td>
|
|
|
|
|
<td colspan=\"$colspan\" class=\"diff-ntitle {$addedClass}\">{$ntitle}</td>
|
2013-06-10 17:43:47 +00:00
|
|
|
</tr>";
|
|
|
|
|
}
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2010-11-07 16:28:11 +00:00
|
|
|
|
|
|
|
|
if ( $multi != '' ) {
|
2018-03-05 18:24:37 +00:00
|
|
|
$header .= "<tr><td colspan=\"{$multiColspan}\" " .
|
2017-07-03 06:51:10 +00:00
|
|
|
"class=\"diff-multi\" lang=\"{$userLang}\">{$multi}</td></tr>";
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
if ( $notice != '' ) {
|
2018-03-05 18:24:37 +00:00
|
|
|
$header .= "<tr><td colspan=\"{$multiColspan}\" " .
|
|
|
|
|
"class=\"diff-notice\" lang=\"{$userLang}\">{$notice}</td></tr>";
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return $header . $diff . "</table>";
|
2008-03-21 11:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-12 09:12:19 +00:00
|
|
|
/**
|
|
|
|
|
* Use specified text instead of loading from the database
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param Content $oldContent
|
|
|
|
|
* @param Content $newContent
|
2012-10-05 13:03:24 +00:00
|
|
|
* @since 1.21
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
* @deprecated since 1.32, use setRevisions or ContentHandler::getSlotDiffRenderer.
|
2012-06-12 09:12:19 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function setContent( Content $oldContent, Content $newContent ) {
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mOldContent = $oldContent;
|
|
|
|
|
$this->mNewContent = $newContent;
|
2012-03-23 15:18:20 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mTextLoaded = 2;
|
|
|
|
|
$this->mRevisionsLoaded = true;
|
2018-07-11 08:48:49 +00:00
|
|
|
$this->isContentOverridden = true;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$this->slotDiffRenderers = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Use specified text instead of loading from the database.
|
|
|
|
|
* @param RevisionRecord|null $oldRevision
|
|
|
|
|
* @param RevisionRecord $newRevision
|
|
|
|
|
*/
|
|
|
|
|
public function setRevisions(
|
2019-10-06 17:01:52 +00:00
|
|
|
?RevisionRecord $oldRevision, RevisionRecord $newRevision
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
) {
|
|
|
|
|
if ( $oldRevision ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mOldRevisionRecord = $oldRevision;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$this->mOldid = $oldRevision->getId();
|
|
|
|
|
$this->mOldPage = Title::newFromLinkTarget( $oldRevision->getPageAsLinkTarget() );
|
|
|
|
|
// This method is meant for edit diffs and such so there is no reason to provide a
|
|
|
|
|
// revision that's not readable to the user, but check it just in case.
|
2019-02-08 13:05:13 +00:00
|
|
|
$this->mOldContent = $oldRevision->getContent( SlotRecord::MAIN,
|
2021-02-27 02:03:46 +00:00
|
|
|
RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
if ( !$this->mOldContent ) {
|
|
|
|
|
$this->addRevisionLoadError( 'old' );
|
|
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
} else {
|
2018-08-20 14:49:56 +00:00
|
|
|
$this->mOldPage = null;
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mOldRevisionRecord = $this->mOldid = false;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
}
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewRevisionRecord = $newRevision;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$this->mNewid = $newRevision->getId();
|
|
|
|
|
$this->mNewPage = Title::newFromLinkTarget( $newRevision->getPageAsLinkTarget() );
|
2018-09-24 21:10:08 +00:00
|
|
|
$this->mNewContent = $newRevision->getContent( SlotRecord::MAIN,
|
2021-02-27 02:03:46 +00:00
|
|
|
RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
|
When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.
Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.
So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
This avoids an unnecessary cache fetch, and avoids making
decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
error.
In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
layer.
* Return null from RevisionRecord::getContent() on a broader set of
errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
now throws in more cases.
In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
message available via getRevisionLoadErrors(). In the diff page, show
the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
appropriate error message (missing-revision-content). But having
$this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
that.
* In EditPage undo, there was already handling for null content, but I
improved the error message: "does not exist or was deleted" seems more
appropriate than "conflicting intermediate edits".
Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-11-29 03:38:29 +00:00
|
|
|
if ( !$this->mNewContent ) {
|
|
|
|
|
$this->addRevisionLoadError( 'new' );
|
|
|
|
|
}
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
|
|
|
|
|
$this->mRevisionsIdsLoaded = $this->mRevisionsLoaded = true;
|
2019-02-07 09:21:19 +00:00
|
|
|
$this->mTextLoaded = $oldRevision ? 2 : 1;
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
$this->isContentOverridden = false;
|
|
|
|
|
$this->slotDiffRenderers = null;
|
2012-06-12 09:12:19 +00:00
|
|
|
}
|
2012-03-23 15:18:20 +00:00
|
|
|
|
2011-07-23 19:03:54 +00:00
|
|
|
/**
|
|
|
|
|
* Set the language in which the diff text is written
|
2018-06-19 19:37:17 +00:00
|
|
|
*
|
|
|
|
|
* @param Language $lang
|
2011-07-23 19:03:54 +00:00
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
2018-06-19 19:48:40 +00:00
|
|
|
public function setTextLanguage( Language $lang ) {
|
|
|
|
|
$this->mDiffLang = $lang;
|
2011-07-23 19:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
/**
|
|
|
|
|
* Maps a revision pair definition as accepted by DifferenceEngine constructor
|
|
|
|
|
* to a pair of actual integers representing revision ids.
|
|
|
|
|
*
|
|
|
|
|
* @param int $old Revision id, e.g. from URL parameter 'oldid'
|
|
|
|
|
* @param int|string $new Revision id or strings 'next' or 'prev', e.g. from URL parameter 'diff'
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
2018-08-20 14:49:56 +00:00
|
|
|
* @return array List of two revision ids, older first, later second.
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
* Zero signifies invalid argument passed.
|
|
|
|
|
* false signifies that there is no previous/next revision ($old is the oldest/newest one).
|
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
|
|
|
* @phan-return (int|false)[]
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
*/
|
|
|
|
|
public function mapDiffPrevNext( $old, $new ) {
|
|
|
|
|
if ( $new === 'prev' ) {
|
|
|
|
|
// Show diff between revision $old and the previous one. Get previous one from DB.
|
|
|
|
|
$newid = intval( $old );
|
2019-08-27 02:45:33 +00:00
|
|
|
$oldid = false;
|
2020-11-14 01:52:36 +00:00
|
|
|
$newRev = $this->revisionStore->getRevisionById( $newid );
|
2019-08-27 02:45:33 +00:00
|
|
|
if ( $newRev ) {
|
2020-11-14 01:52:36 +00:00
|
|
|
$oldRev = $this->revisionStore->getPreviousRevision( $newRev );
|
2019-08-27 02:45:33 +00:00
|
|
|
if ( $oldRev ) {
|
|
|
|
|
$oldid = $oldRev->getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
} elseif ( $new === 'next' ) {
|
|
|
|
|
// Show diff between revision $old and the next one. Get next one from DB.
|
|
|
|
|
$oldid = intval( $old );
|
2019-08-27 02:45:33 +00:00
|
|
|
$newid = false;
|
2020-11-14 01:52:36 +00:00
|
|
|
$oldRev = $this->revisionStore->getRevisionById( $oldid );
|
2019-08-27 02:45:33 +00:00
|
|
|
if ( $oldRev ) {
|
2020-11-14 01:52:36 +00:00
|
|
|
$newRev = $this->revisionStore->getNextRevision( $oldRev );
|
2019-08-27 02:45:33 +00:00
|
|
|
if ( $newRev ) {
|
|
|
|
|
$newid = $newRev->getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
} else {
|
|
|
|
|
$oldid = intval( $old );
|
|
|
|
|
$newid = intval( $new );
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchReturn getId does not return null here
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $oldid, $newid ];
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
private function loadRevisionIds() {
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mRevisionsIdsLoaded ) {
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mRevisionsIdsLoaded = true;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$old = $this->mOldid;
|
|
|
|
|
$new = $this->mNewid;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
[ $this->mOldid, $this->mNewid ] = self::mapDiffPrevNext( $old, $new );
|
|
|
|
|
if ( $new === 'next' && $this->mNewid === false ) {
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
# if no result, NewId points to the newest old revision. The only newer
|
|
|
|
|
# revision is cur, which is "0".
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mNewid = 0;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
Correctly update wl_notificationtimestamp when viewing old revisions
== Prelude ==
wl_notificationtimestamp controls sending the user e-mail
notifications about changes to pages, as well as showing the "updated
since last visit" markers on history pages, recent changes and
watchlist.
== The bug ==
Previously, on every view of a page, the notification timestamp was
cleared, regardless of whether the user as actually viewing the latest
revision. When viewing a diff, however, the timestamp was cleared only
if one of the revisions being compared was the latest one of its page.
The same behavior applied to talk page message indicators (which are
actually stored sepately to cater to anonymous users).
This was inconsistent and surprising when one was attempting to, say,
go through the 50 new posts to a discussion page in a peacemeal
fashion.
== The fix ==
If the revision being viewed is the latest (or can't be determined),
the timestamp is cleared as previously, as this is necessary to
reenable e-mail notifications for given user and page.
If the revision isn't the latest, the timestamp is updated to
revision's timestamp plus one second. This uses up to two simple
(selectField) indexed queries per page view, only fired when we
do not already know we're looking at the latest version.
Talk page indicator is updated to point at the next revision after the
one being viewed, or cleared if viewing the latest revision. The
UserClearNewTalkNotification hook gained $oldid as the second argument
(a backwards-compatible change). In Skin, we no longer ignore the
indicator being present if we're viewing the talk page, as it might
still be valid.
== The bonus ==
Comments and formatting was updated in a few places, including
tables.sql and Wiki.php.
The following functions gained a second, optional $oldid parameter
(holy indirection, Batman!):
* WikiPage#doViewUpdates()
* User#clearNotification()
* WatchedItem#resetNotificationTimestamp()
DifferenceEngine gained a public method mapDiffPrevNext() used
to parse the ids from URL parameters like oldid=12345&diff=prev,
factored out of loadRevisionIds(). A bug where the NewDifferenceEngine
hook would not be called in some cases, dating back to its
introduction in r45518, was fixed in the process.
Bug: 41759
Change-Id: I4144ba1987b8d7a7e8b24f4f067eedac2ae44459
2013-09-16 10:31:40 +00:00
|
|
|
|
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->onNewDifferenceEngine(
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable False positive
|
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->getTitle(), $this->mOldid, $this->mNewid, $old, $new );
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
2018-08-20 14:49:56 +00:00
|
|
|
* Load revision metadata for the specified revisions. If newid is 0, then compare
|
|
|
|
|
* the old revision in oldid to the current revision of the current page (as defined
|
|
|
|
|
* by the request context); if oldid is 0, then compare the revision in newid to the
|
|
|
|
|
* immediately previous one.
|
2010-11-07 16:28:11 +00:00
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* If oldid is false, leave the corresponding RevisionRecord object set to false. This can
|
2019-03-24 23:55:42 +00:00
|
|
|
* happen with 'diff=prev' pointing to a non-existent revision, and is also used directly
|
|
|
|
|
* by the API.
|
2011-06-01 16:27:46 +00:00
|
|
|
*
|
2020-04-29 16:38:25 +00:00
|
|
|
* @return bool Whether both revisions were loaded successfully. Setting mOldRevisionRecord
|
2018-08-20 14:49:56 +00:00
|
|
|
* to false counts as successful loading.
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function loadRevisionData() {
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mRevisionsLoaded ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
return $this->isContentOverridden ||
|
|
|
|
|
( $this->mOldRevisionRecord !== null && $this->mNewRevisionRecord !== null );
|
2010-11-07 16:28:11 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
// Whether it succeeds or fails, we don't want to try again
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mRevisionsLoaded = true;
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
|
|
|
|
$this->loadRevisionIds();
|
|
|
|
|
|
2021-05-02 23:55:07 +00:00
|
|
|
// Load the new RevisionRecord object
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mNewid ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewRevisionRecord = $this->revisionStore->getRevisionById( $this->mNewid );
|
2013-10-04 13:43:09 +00:00
|
|
|
} else {
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewRevisionRecord = $this->revisionStore->getRevisionByTitle( $this->getTitle() );
|
2013-10-04 13:43:09 +00:00
|
|
|
}
|
Big cleanup to DifferenceEngine:
* Call Linker methods statically
* Factorised a lot of duplicate code, such as "Mark patrolled" links, revisions headers, etc.
* Removed showFirstRevision() and made that case be handled through the normal showDiffPage(). In such case, the header will look like a normal diff page, except it is centred. For this, addHeader() will now center the "new revision" header if the string passed to the "old revision" header and the diff is empty. getDiffBody() will also return an empty string if $mOldRev is false.
* Showing only one revision when the previous was not found will also ask to unhide the revision is deleted as in normal case
* Backed out code that generates the revision header from loadRevisionData() so that this function does not make a mix of backend and UI stuff. Factorised the code in getRevisionHeader().
* Lazy-load page's language and revisions IDs (in case of "prev", "next", etc. are passed) instead of doing that in constructor.
* Made a good part of links compatible with Special:ComparePages, such as navigation links, "undo", etc. that links to the title corresponding to the revision and not the given title in the constuctor.
* "Current revision as of" can also be displayed on the old revision, useful when comparing two current revisions in Special:ComparePages
* Removed navigation, undo and rollback links when comparing two different pages, this can confuses users thinking they are comparing two revisions of the same page. Also clicking on a "undo" link in such case will give "revision not found".
* Check if the user can read the revisions before sending a external editor file
2011-10-05 19:55:04 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( !$this->mNewRevisionRecord instanceof RevisionRecord ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
return false;
|
2011-06-01 16:27:46 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
// Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewid = $this->mNewRevisionRecord->getId();
|
2022-01-21 08:55:23 +00:00
|
|
|
$this->mNewPage = $this->mNewid ?
|
|
|
|
|
Title::newFromLinkTarget( $this->mNewRevisionRecord->getPageAsLinkTarget() ) :
|
|
|
|
|
null;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2021-05-02 23:55:07 +00:00
|
|
|
// Load the old RevisionRecord object
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mOldRevisionRecord = false;
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mOldid ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mOldRevisionRecord = $this->revisionStore->getRevisionById( $this->mOldid );
|
2013-11-11 16:35:19 +00:00
|
|
|
} elseif ( $this->mOldid === 0 ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
$revRecord = $this->revisionStore->getPreviousRevision( $this->mNewRevisionRecord );
|
2022-01-21 08:55:23 +00:00
|
|
|
// No previous revision; mark to show as first-version only.
|
|
|
|
|
$this->mOldid = $revRecord ? $revRecord->getId() : false;
|
|
|
|
|
$this->mOldRevisionRecord = $revRecord ?? false;
|
2020-04-29 16:38:25 +00:00
|
|
|
} /* elseif ( $this->mOldid === false ) leave mOldRevisionRecord false; */
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord === null ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord && $this->mOldRevisionRecord->getId() ) {
|
|
|
|
|
$this->mOldPage = Title::newFromLinkTarget(
|
|
|
|
|
$this->mOldRevisionRecord->getPageAsLinkTarget()
|
|
|
|
|
);
|
[MCR] Render multi-slot diffs
Move logic for rendering a diff between two content objects out of
DifferenceEngine, into a new SlotDiffRenderer class. Make
DifferenceEngine use multiple SlotDiffRenderers, one per slot.
This separates the class tree for changing high-level diff properties
such as the header or the revision selection method (same as before:
subclass DifferenceEngine and override ContentHandler::getDiffEngineClass
or implement GetDifferenceEngine) and the one for changing the actual
diff rendering for a given content type (subclass SlotDiffRenderer and
override ContentHandler::getSlotDiffRenderer or implement
GetSlotDiffRenderer). To keep B/C, when SlotDiffRenderer is not overridden
for a given content type but DifferenceEngine is, that DifferenceEngine
will be used instead.
The weak point of the scheme is overriding the DifferenceEngine methods
passing control to the SlotDiffRenderers (the ones calling
getDifferenceEngines), without calling the parent. These are:
showDiffStyle, getDiffBody, getDiffBodyCacheKeyParams. Extensions doing
that will probably break in unpredictable ways (most likely, only
showing the main slot diff). Nothing in gerrit does it, at least.
A new GetSlotDiffRenderer hook is added to modify rendering for content
models not owned by the extension, much like how GetDifferenceEngine
works.
Also deprecates public access to mNewRev/mOldRev and creates public
getters instead. DifferenceEngine never supported external changes to
those properties, this just acknowledges it.
Bug: T194731
Change-Id: I2f8a9dbebd2290b7feafb20e2bb2a2693e18ba11
Depends-On: I04e885a33bfce5bccc807b9bcfe1eaa577a9fd47
Depends-On: I203d8895bf436b7fee53fe4718dede8a3b1768bc
2018-07-11 09:24:07 +00:00
|
|
|
} else {
|
|
|
|
|
$this->mOldPage = null;
|
2007-05-16 17:57:00 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2013-07-06 20:53:27 +00:00
|
|
|
// Load tags information for both revisions
|
2023-07-05 08:57:11 +00:00
|
|
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
2018-11-27 17:48:18 +00:00
|
|
|
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mOldid !== false ) {
|
2023-08-01 16:34:16 +00:00
|
|
|
$tagIds = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( 'ct_tag_id' )
|
|
|
|
|
->from( 'change_tag' )
|
|
|
|
|
->where( [ 'ct_rev_id' => $this->mOldid ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchFieldValues();
|
2018-11-27 17:48:18 +00:00
|
|
|
$tags = [];
|
|
|
|
|
foreach ( $tagIds as $tagId ) {
|
|
|
|
|
try {
|
|
|
|
|
$tags[] = $changeTagDefStore->getName( (int)$tagId );
|
|
|
|
|
} catch ( NameTableAccessException $exception ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->mOldTags = implode( ',', $tags );
|
2013-07-06 20:53:27 +00:00
|
|
|
} else {
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mOldTags = false;
|
2013-07-06 20:53:27 +00:00
|
|
|
}
|
2018-11-27 17:48:18 +00:00
|
|
|
|
2023-08-01 16:34:16 +00:00
|
|
|
$tagIds = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( 'ct_tag_id' )
|
|
|
|
|
->from( 'change_tag' )
|
|
|
|
|
->where( [ 'ct_rev_id' => $this->mNewid ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchFieldValues();
|
2018-11-27 17:48:18 +00:00
|
|
|
$tags = [];
|
|
|
|
|
foreach ( $tagIds as $tagId ) {
|
|
|
|
|
try {
|
|
|
|
|
$tags[] = $changeTagDefStore->getName( (int)$tagId );
|
|
|
|
|
} catch ( NameTableAccessException $exception ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->mNewTags = implode( ',', $tags );
|
2013-07-06 20:53:27 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return true;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Load the text of the revisions, as well as revision data.
|
2018-08-20 14:49:56 +00:00
|
|
|
* When the old revision is missing (mOldRev is false), loading mOldContent is not attempted.
|
2011-06-01 16:27:46 +00:00
|
|
|
*
|
2018-07-11 08:48:49 +00:00
|
|
|
* @return bool Whether the content of both revisions could be loaded successfully.
|
2018-08-20 14:49:56 +00:00
|
|
|
* (When mOldRev is false, that still counts as a success.)
|
|
|
|
|
*
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function loadText() {
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mTextLoaded == 2 ) {
|
2020-04-29 16:38:25 +00:00
|
|
|
return $this->loadRevisionData() &&
|
|
|
|
|
( $this->mOldRevisionRecord === false || $this->mOldContent )
|
2018-08-20 14:49:56 +00:00
|
|
|
&& $this->mNewContent;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-25 07:26:20 +00:00
|
|
|
// Whether it succeeds or fails, we don't want to try again
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mTextLoaded = 2;
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
if ( !$this->loadRevisionData() ) {
|
|
|
|
|
return false;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
if ( $this->mOldRevisionRecord ) {
|
|
|
|
|
$this->mOldContent = $this->mOldRevisionRecord->getContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
RevisionRecord::FOR_THIS_USER,
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->getAuthority()
|
2019-07-21 14:32:13 +00:00
|
|
|
);
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mOldContent === null ) {
|
2010-11-07 16:28:11 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewContent = $this->mNewRevisionRecord->getContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
RevisionRecord::FOR_THIS_USER,
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->getAuthority()
|
2019-07-21 14:32:13 +00:00
|
|
|
);
|
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->onDifferenceEngineLoadTextAfterNewContentIsLoaded( $this );
|
2018-08-20 14:49:56 +00:00
|
|
|
if ( $this->mNewContent === null ) {
|
|
|
|
|
return false;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return true;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
/**
|
|
|
|
|
* Load the text of the new revision, not the old one
|
2011-06-01 16:27:46 +00:00
|
|
|
*
|
2018-07-11 08:48:49 +00:00
|
|
|
* @return bool Whether the content of the new revision could be loaded successfully.
|
2010-11-07 16:28:11 +00:00
|
|
|
*/
|
2014-02-25 08:23:32 +00:00
|
|
|
public function loadNewText() {
|
2013-11-11 16:35:19 +00:00
|
|
|
if ( $this->mTextLoaded >= 1 ) {
|
2018-07-11 08:48:49 +00:00
|
|
|
return $this->loadRevisionData();
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2013-11-11 16:35:19 +00:00
|
|
|
$this->mTextLoaded = 1;
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
if ( !$this->loadRevisionData() ) {
|
|
|
|
|
return false;
|
2004-08-30 23:45:05 +00:00
|
|
|
}
|
2013-08-25 07:26:20 +00:00
|
|
|
|
2020-04-29 16:38:25 +00:00
|
|
|
$this->mNewContent = $this->mNewRevisionRecord->getContent(
|
|
|
|
|
SlotRecord::MAIN,
|
|
|
|
|
RevisionRecord::FOR_THIS_USER,
|
2021-02-27 02:03:46 +00:00
|
|
|
$this->getAuthority()
|
2019-07-21 14:32:13 +00:00
|
|
|
);
|
2013-08-25 07:26:20 +00:00
|
|
|
|
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->onDifferenceEngineAfterLoadNewText( $this );
|
2016-11-17 02:14:26 +00:00
|
|
|
|
2010-11-07 16:28:11 +00:00
|
|
|
return true;
|
2004-04-17 07:37:55 +00:00
|
|
|
}
|
2014-03-03 17:08:05 +00:00
|
|
|
|
2023-07-03 08:27:47 +00:00
|
|
|
/**
|
|
|
|
|
* Get the TextDiffer which will be used for rendering text
|
|
|
|
|
*
|
|
|
|
|
* @return ManifoldTextDiffer
|
|
|
|
|
*/
|
|
|
|
|
protected function getTextDiffer() {
|
|
|
|
|
if ( $this->textDiffer === null ) {
|
|
|
|
|
$this->textDiffer = new ManifoldTextDiffer(
|
|
|
|
|
$this->getContext(),
|
|
|
|
|
$this->getDiffLang(),
|
|
|
|
|
$this->getConfig()->get( MainConfigNames::DiffEngine ),
|
2023-07-06 05:39:17 +00:00
|
|
|
$this->getConfig()->get( MainConfigNames::ExternalDiffEngine ),
|
|
|
|
|
$this->getConfig()->get( MainConfigNames::Wikidiff2Options )
|
2023-07-03 08:27:47 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $this->textDiffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of supported text diff formats
|
|
|
|
|
*
|
|
|
|
|
* @since 1.41
|
|
|
|
|
* @return array|string[]
|
|
|
|
|
*/
|
|
|
|
|
public function getSupportedFormats() {
|
|
|
|
|
return $this->getTextDiffer()->getFormats();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the selected text diff format
|
|
|
|
|
*
|
|
|
|
|
* @since 1.41
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getTextDiffFormat() {
|
|
|
|
|
return $this->slotDiffOptions['diff-type'] ?? 'table';
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-24 09:44:45 +00:00
|
|
|
}
|