2017-08-27 15:29:18 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Service for looking up page revisions.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2018-09-20 17:29:04 +00:00
|
|
|
namespace MediaWiki\Revision;
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2021-02-08 16:33:25 +00:00
|
|
|
use MediaWiki\Page\PageIdentity;
|
2024-09-27 16:12:27 +00:00
|
|
|
use Wikimedia\Rdbms\IDBAccessObject;
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service for looking up page revisions.
|
|
|
|
|
*
|
|
|
|
|
* @note This was written to act as a drop-in replacement for the corresponding
|
2021-05-02 23:55:07 +00:00
|
|
|
* static methods in the old Revision class (which was later removed in 1.37).
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.31
|
2018-09-20 17:29:04 +00:00
|
|
|
* @since 1.32 Renamed from MediaWiki\Storage\RevisionLookup
|
2017-08-27 15:29:18 +00:00
|
|
|
*/
|
2024-02-19 08:58:53 +00:00
|
|
|
interface RevisionLookup {
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a page revision from a given revision ID number.
|
|
|
|
|
* Returns null if no such revision can be found.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::newFromId
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* $flags include:
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @param int $flags bit field, see IDBAccessObject::READ_XXX
|
2021-03-15 16:51:47 +00:00
|
|
|
* @param PageIdentity|null $page The page the revision belongs to.
|
|
|
|
|
* Providing the page may improve performance.
|
|
|
|
|
*
|
2017-08-27 15:29:18 +00:00
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public function getRevisionById( $id, $flags = 0, ?PageIdentity $page = null );
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load either the current, or a specified, revision
|
|
|
|
|
* that's attached to a given link target. If not attached
|
|
|
|
|
* to that link target, will return null.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::newFromTitle
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
2021-02-08 16:33:25 +00:00
|
|
|
* @param LinkTarget|PageIdentity $page Calling with LinkTarget is deprecated since 1.36
|
2017-08-27 15:29:18 +00:00
|
|
|
* @param int $revId (optional)
|
|
|
|
|
* @param int $flags bit field, see IDBAccessObject::READ_XXX
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
2021-02-08 16:33:25 +00:00
|
|
|
public function getRevisionByTitle( $page, $revId = 0, $flags = 0 );
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load either the current, or a specified, revision
|
|
|
|
|
* that's attached to a given page ID.
|
|
|
|
|
* Returns null if no such revision can be found.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::newFromPageId
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @param int $pageId
|
|
|
|
|
* @param int $revId (optional)
|
|
|
|
|
* @param int $flags bit field, see IDBAccessObject::READ_XXX
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
public function getRevisionByPageId( $pageId, $revId = 0, $flags = 0 );
|
|
|
|
|
|
2020-03-04 01:15:53 +00:00
|
|
|
/**
|
|
|
|
|
* Load the revision for the given title with the given timestamp.
|
|
|
|
|
* WARNING: Timestamps may in some circumstances not be unique,
|
|
|
|
|
* so this isn't the best key to use.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::loadFromTimestamp
|
2020-03-04 01:15:53 +00:00
|
|
|
*
|
2021-02-08 16:33:25 +00:00
|
|
|
* @param LinkTarget|PageIdentity $page Calling with LinkTarget is deprecated since 1.36
|
2020-03-04 01:15:53 +00:00
|
|
|
* @param string $timestamp
|
|
|
|
|
* @param int $flags Bitfield (optional) include:
|
2024-01-23 14:01:06 +00:00
|
|
|
* IDBAccessObject::READ_LATEST: Select the data from the primary DB
|
|
|
|
|
* IDBAccessObject::READ_LOCKING: Select & lock the data from the primary DB
|
|
|
|
|
* Default: IDBAccessObject::READ_NORMAL
|
2020-03-04 01:15:53 +00:00
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
public function getRevisionByTimestamp(
|
2021-02-08 16:33:25 +00:00
|
|
|
$page,
|
2020-03-04 01:15:53 +00:00
|
|
|
string $timestamp,
|
2024-01-23 14:01:06 +00:00
|
|
|
int $flags = IDBAccessObject::READ_NORMAL
|
2020-03-04 01:15:53 +00:00
|
|
|
): ?RevisionRecord;
|
|
|
|
|
|
2017-08-27 15:29:18 +00:00
|
|
|
/**
|
|
|
|
|
* Get previous revision for this title
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::getPrevious
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @param RevisionRecord $rev
|
2019-04-29 14:24:58 +00:00
|
|
|
* @param int $flags (optional) $flags include:
|
2021-09-01 21:04:40 +00:00
|
|
|
* IDBAccessObject::READ_LATEST: Select the data from the primary DB
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
2019-04-29 14:24:58 +00:00
|
|
|
public function getPreviousRevision( RevisionRecord $rev, $flags = 0 );
|
2017-08-27 15:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get next revision for this title
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::getNext
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @param RevisionRecord $rev
|
2019-04-29 14:24:58 +00:00
|
|
|
* @param int $flags (optional) $flags include:
|
2021-09-01 21:04:40 +00:00
|
|
|
* IDBAccessObject::READ_LATEST: Select the data from the primary DB
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
2019-04-29 14:24:58 +00:00
|
|
|
public function getNextRevision( RevisionRecord $rev, $flags = 0 );
|
2017-08-27 15:29:18 +00:00
|
|
|
|
Don't require Title for getTimestampFromId
3e36ba655e3a added an option for passing a page ID to this method of
Revision, and e03787afd91c switched it to a Title and made it mandatory.
This behavior propagated to the method in RevisionStore. As far as I
can tell, the parameter does not help anything, but it can add a
database query to get the page ID if it's not cached, and impedes
conversion to LinkTarget. I can't figure out any reason to not
completely drop it. I've noted it as deprecated but still supported it
for now for compatibility -- I found one extension that does pass it.
(It's ignored, though, which theoretically would be a behavior change if
someone was passing a Title that didn't match the revision ID.)
While I was at it, I added the method to RevisionLookup, although it's
only used in later patches. Properly I should move that piece to a later
patch, but it didn't seem worth the effort.
I didn't change the Revision method, because the whole Revision class is
deprecated anyway.
Change-Id: I26ef5f2bf828f0f450633b7237d26d888e2c8773
2019-04-29 14:32:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get rev_timestamp from rev_id, without loading the rest of the row.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::getTimestampFromId
|
Don't require Title for getTimestampFromId
3e36ba655e3a added an option for passing a page ID to this method of
Revision, and e03787afd91c switched it to a Title and made it mandatory.
This behavior propagated to the method in RevisionStore. As far as I
can tell, the parameter does not help anything, but it can add a
database query to get the page ID if it's not cached, and impedes
conversion to LinkTarget. I can't figure out any reason to not
completely drop it. I've noted it as deprecated but still supported it
for now for compatibility -- I found one extension that does pass it.
(It's ignored, though, which theoretically would be a behavior change if
someone was passing a Title that didn't match the revision ID.)
While I was at it, I added the method to RevisionLookup, although it's
only used in later patches. Properly I should move that piece to a later
patch, but it didn't seem worth the effort.
I didn't change the Revision method, because the whole Revision class is
deprecated anyway.
Change-Id: I26ef5f2bf828f0f450633b7237d26d888e2c8773
2019-04-29 14:32:22 +00:00
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @param int $flags
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return string|false False if not found
|
Don't require Title for getTimestampFromId
3e36ba655e3a added an option for passing a page ID to this method of
Revision, and e03787afd91c switched it to a Title and made it mandatory.
This behavior propagated to the method in RevisionStore. As far as I
can tell, the parameter does not help anything, but it can add a
database query to get the page ID if it's not cached, and impedes
conversion to LinkTarget. I can't figure out any reason to not
completely drop it. I've noted it as deprecated but still supported it
for now for compatibility -- I found one extension that does pass it.
(It's ignored, though, which theoretically would be a behavior change if
someone was passing a Title that didn't match the revision ID.)
While I was at it, I added the method to RevisionLookup, although it's
only used in later patches. Properly I should move that piece to a later
patch, but it didn't seem worth the effort.
I didn't change the Revision method, because the whole Revision class is
deprecated anyway.
Change-Id: I26ef5f2bf828f0f450633b7237d26d888e2c8773
2019-04-29 14:32:22 +00:00
|
|
|
* @since 1.34 (present earlier in RevisionStore)
|
|
|
|
|
*/
|
|
|
|
|
public function getTimestampFromId( $id, $flags = 0 );
|
|
|
|
|
|
2017-08-27 15:29:18 +00:00
|
|
|
/**
|
|
|
|
|
* Load a revision based on a known page ID and current revision ID from the DB
|
|
|
|
|
*
|
|
|
|
|
* This method allows for the use of caching, though accessing anything that normally
|
|
|
|
|
* requires permission checks (aside from the text) will trigger a small DB lookup.
|
|
|
|
|
*
|
2021-05-02 23:55:07 +00:00
|
|
|
* MCR migration note: this replaced Revision::newKnownCurrent
|
2017-08-27 15:29:18 +00:00
|
|
|
*
|
2021-02-08 16:33:25 +00:00
|
|
|
* @param PageIdentity $page the associated page
|
2017-08-27 15:29:18 +00:00
|
|
|
* @param int $revId current revision of this page
|
|
|
|
|
*
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return RevisionRecord|false Returns false if missing
|
2017-08-27 15:29:18 +00:00
|
|
|
*/
|
2021-02-08 16:33:25 +00:00
|
|
|
public function getKnownCurrentRevision( PageIdentity $page, $revId = 0 );
|
2017-08-27 15:29:18 +00:00
|
|
|
|
2020-03-07 07:07:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get the first revision of the page.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.35
|
2021-02-08 16:33:25 +00:00
|
|
|
* @param LinkTarget|PageIdentity $page Calling with LinkTarget is deprecated since 1.36
|
2020-03-07 07:07:42 +00:00
|
|
|
* @param int $flags bit field, see IDBAccessObject::READ_* constants.
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
public function getFirstRevision(
|
2021-02-08 16:33:25 +00:00
|
|
|
$page,
|
2020-03-07 07:07:42 +00:00
|
|
|
int $flags = IDBAccessObject::READ_NORMAL
|
|
|
|
|
): ?RevisionRecord;
|
|
|
|
|
|
2017-08-27 15:29:18 +00:00
|
|
|
}
|