MediaWiki
master
|
Handle database storage of comments such as edit summaries and log reasons. More...
Public Member Functions | |
__construct (Language $lang, $stage) | |
createComment (IDatabase $dbw, $comment, array $data=null) | |
Create a new CommentStoreComment, inserting it into the database if necessary. More... | |
getComment ( $key, $row=null, $fallback=false) | |
Extract the comment from a row. More... | |
getCommentLegacy (IDatabase $db, $key, $row=null, $fallback=false) | |
Extract the comment from a row, with legacy lookups. More... | |
getFields ( $key) | |
Get SELECT fields for the comment key. More... | |
getJoin ( $key) | |
Get SELECT fields and joins for the comment key. More... | |
insert (IDatabase $dbw, $key, $comment=null, $data=null) | |
Insert a comment in preparation for a row that references it. More... | |
insertWithTempTable (IDatabase $dbw, $key, $comment=null, $data=null) | |
Insert a comment in a temporary table in preparation for a row that references it. More... | |
Static Public Member Functions | |
static | getStore () |
static | hash ( $text, $data) |
Hashing function for comment storage. More... | |
Public Attributes | |
const | COMMENT_CHARACTER_LIMIT = 500 |
Maximum length of a comment in UTF-8 characters. More... | |
const | MAX_DATA_LENGTH = 65535 |
Maximum length of serialized data in bytes. More... | |
Private Member Functions | |
getCommentInternal (?IDatabase $db, $key, $row, $fallback=false) | |
Extract the comment from a row. More... | |
insertInternal (IDatabase $dbw, $key, $comment, $data) | |
Implementation for self::insert() and self::insertWithTempTable() More... | |
Static Private Member Functions | |
static | decodeMessage ( $data) |
Decode a message that was encoded by self::encodeMessage() More... | |
static | encodeMessage (Message $msg) |
Encode a Message as a PHP data structure. More... | |
Private Attributes | |
array[] | $joinCache = [] |
Cache for self::getJoin() More... | |
Language | $lang |
Language to use for comment truncation. More... | |
int | $stage |
One of the MIGRATION_* constants, or an appropriate combination of SCHEMA_COMPAT_* constants. More... | |
array[] | $tempTables |
Define fields that use temporary tables for transitional purposes Keys are '$key', values are arrays with these possible fields: More... | |
Handle database storage of comments such as edit summaries and log reasons.
Definition at line 42 of file CommentStore.php.
CommentStore::__construct | ( | Language | $lang, |
$stage | |||
) |
Language | $lang | Language to use for comment truncation. Defaults to content language. |
int | $stage | One of the MIGRATION_* constants, or an appropriate combination of SCHEMA_COMPAT_* constants. Always MIGRATION_NEW for MediaWiki core since 1.33. |
Definition at line 103 of file CommentStore.php.
References $lang, $stage, SCHEMA_COMPAT_READ_BOTH, and SCHEMA_COMPAT_WRITE_BOTH.
CommentStore::createComment | ( | IDatabase | $dbw, |
$comment, | |||
array | $data = null |
||
) |
Create a new CommentStoreComment, inserting it into the database if necessary.
If a comment is going to be passed to self::insert()
or the like multiple times, it will be more efficient to pass a CommentStoreComment once rather than making self::insert()
do it every time through.
$comment->id
if it's not already set. If $comment->id
is already set, it will not be verified that the specified comment actually exists or that it corresponds to the comment text, message, and/or data in the CommentStoreComment. IDatabase | $dbw | Database handle to insert on. Unused if $comment is a CommentStoreComment and $comment->id is set. |
string | Message | CommentStoreComment | $comment | Comment text or Message object, or a CommentStoreComment. |
array | null | $data | Structured data to store. Keys beginning with '_' are reserved. Ignored if $comment is a CommentStoreComment. |
Definition at line 437 of file CommentStore.php.
References FormatJson\ALL_OK, FormatJson\encode(), encodeMessage(), hash(), Wikimedia\Rdbms\IDatabase\insert(), Wikimedia\Rdbms\IDatabase\insertId(), MAX_DATA_LENGTH, CommentStoreComment\newUnsavedComment(), SCHEMA_COMPAT_WRITE_NEW, Wikimedia\Rdbms\IDatabase\selectField(), and true.
Referenced by insertInternal().
|
staticprivate |
Decode a message that was encoded by self::encodeMessage()
array | $data |
Definition at line 632 of file CommentStore.php.
Referenced by getCommentInternal().
|
staticprivate |
Encode a Message as a PHP data structure.
Message | $msg |
Definition at line 613 of file CommentStore.php.
References Message\getKey(), Message\getKeysToTry(), and Message\getParams().
Referenced by createComment().
CommentStore::getComment | ( | $key, | |
$row = null , |
|||
$fallback = false |
|||
) |
Extract the comment from a row.
Use self::getJoin()
to ensure the row contains the needed data.
If you need to fake a comment in a row for some reason, set fields {$key}_text
(string) and {$key}_data
(JSON string or null).
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
stdClass | array | null | $row | Result row. |
bool | $fallback | If true, fall back as well as possible instead of throwing an exception. |
Definition at line 380 of file CommentStore.php.
References $fallback, and getCommentInternal().
|
private |
Extract the comment from a row.
Shared implementation for getComment() and getCommentLegacy()
IDatabase | null | $db | Database handle for getCommentLegacy(), or null for getComment() |
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
stdClass | array | $row | |
bool | $fallback |
Definition at line 251 of file CommentStore.php.
References $fallback, $t, FormatJson\decode(), decodeMessage(), MIGRATION_NEW, SCHEMA_COMPAT_READ_BOTH, SCHEMA_COMPAT_READ_NEW, SCHEMA_COMPAT_READ_OLD, Wikimedia\Rdbms\IDatabase\selectRow(), and wfLogWarning().
Referenced by getComment(), and getCommentLegacy().
CommentStore::getCommentLegacy | ( | IDatabase | $db, |
$key, | |||
$row = null , |
|||
$fallback = false |
|||
) |
Extract the comment from a row, with legacy lookups.
If $row
might have been generated using self::getFields()
rather than self::getJoin()
, use this. Prefer self::getComment()
if you know callers used self::getJoin()
for the row fetch.
If you need to fake a comment in a row for some reason, set fields {$key}_text
(string) and {$key}_data
(JSON string or null).
IDatabase | $db | Database handle to use for lookup |
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
stdClass | array | null | $row | Result row. |
bool | $fallback | If true, fall back as well as possible instead of throwing an exception. |
Definition at line 408 of file CommentStore.php.
References $fallback, and getCommentInternal().
CommentStore::getFields | ( | $key | ) |
Get SELECT fields for the comment key.
Each resulting row should be passed to self::getCommentLegacy()
to get the actual comment.
self::getJoin()
instead.string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
$vars
to IDatabase->select()
. All fields are aliased, so +
is safe to use. Definition at line 140 of file CommentStore.php.
References MIGRATION_NEW, SCHEMA_COMPAT_READ_BOTH, SCHEMA_COMPAT_READ_NEW, and SCHEMA_COMPAT_READ_OLD.
CommentStore::getJoin | ( | $key | ) |
Get SELECT fields and joins for the comment key.
Each resulting row should be passed to self::getComment()
to get the actual comment.
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
$table
to IDatabase->select()
$vars
to IDatabase->select()
$join_conds
to IDatabase->select()
All tables, fields, and joins are aliased, so +
is safe to use. -return array{tables:string[],fields:string[],joins:array} Definition at line 180 of file CommentStore.php.
References $t, MIGRATION_NEW, SCHEMA_COMPAT_READ_BOTH, SCHEMA_COMPAT_READ_NEW, and SCHEMA_COMPAT_READ_OLD.
|
static |
Definition at line 120 of file CommentStore.php.
Referenced by WikiPage\archiveRevisions(), Orphans\checkOrphans(), WikiPage\doUpdateRestrictions(), WikiExporter\dumpLogs(), ApiQueryBlocks\execute(), ApiQueryDeletedrevs\execute(), ApiQueryFilearchive\execute(), ApiQueryLogEvents\execute(), ApiQueryUserContribs\execute(), FeedUtils\formatDiff(), RevDelLogItem\getApiData(), RecentChange\getAttribute(), DatabaseLogEntry\getComment(), RCDatabaseLogEntry\getComment(), RevDelLogItem\getHTML(), EditPage\getLastDelete(), MediaWiki\Block\DatabaseBlock\getQueryInfo(), RecentChange\getQueryInfo(), DatabaseLogEntry\getSelectQueryData(), Title\getTitleProtectionInternal(), WikiRevision\importLogItem(), MediaWiki\Block\DatabaseBlock\initFromRow(), ManualLogEntry\insert(), RecentChange\loadFromRow(), RebuildRecentchanges\rebuildRecentChangesTablePass1(), RebuildRecentchanges\rebuildRecentChangesTablePass3(), ApiQueryProtectedTitles\run(), ApiQueryRecentChanges\run(), ApiQueryWatchlist\run(), RecentChange\save(), EditPage\showEditForm(), and XmlDumpWriter\writeLogItem().
|
static |
Hashing function for comment storage.
string | $text | Comment text |
string | null | $data | Comment data |
Definition at line 651 of file CommentStore.php.
Referenced by createComment(), and MigrateComments\loadCommentIDs().
CommentStore::insert | ( | IDatabase | $dbw, |
$key, | |||
$comment = null , |
|||
$data = null |
|||
) |
Insert a comment in preparation for a row that references it.
IDatabase | $dbw | Database handle to insert on |
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
string | Message | CommentStoreComment | null | $comment | As for self::createComment() |
array | null | $data | As for self::createComment() |
Definition at line 548 of file CommentStore.php.
References insertInternal(), MIGRATION_NEW, and SCHEMA_COMPAT_WRITE_OLD.
|
private |
Implementation for self::insert()
and self::insertWithTempTable()
IDatabase | $dbw | |
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
string | Message | CommentStoreComment | $comment | |
array | null | $data |
Definition at line 497 of file CommentStore.php.
References $t, createComment(), Wikimedia\Rdbms\IDatabase\insert(), MIGRATION_NEW, SCHEMA_COMPAT_WRITE_NEW, and SCHEMA_COMPAT_WRITE_OLD.
Referenced by insert(), and insertWithTempTable().
CommentStore::insertWithTempTable | ( | IDatabase | $dbw, |
$key, | |||
$comment = null , |
|||
$data = null |
|||
) |
Insert a comment in a temporary table in preparation for a row that references it.
This is currently needed for "rev_comment" and "img_description". In the future that requirement will be removed.
IDatabase | $dbw | Database handle to insert on |
string | $key | A key such as "rev_comment" identifying the comment field being fetched. |
string | Message | CommentStoreComment | null | $comment | As for self::createComment() |
array | null | $data | As for self::createComment() |
Definition at line 586 of file CommentStore.php.
References insertInternal(), and wfDeprecated().
|
private |
Cache for self::getJoin()
Definition at line 91 of file CommentStore.php.
|
private |
Language to use for comment truncation.
Definition at line 94 of file CommentStore.php.
Referenced by __construct().
|
private |
One of the MIGRATION_* constants, or an appropriate combination of SCHEMA_COMPAT_* constants.
Definition at line 88 of file CommentStore.php.
Referenced by __construct().
|
private |
Define fields that use temporary tables for transitional purposes Keys are '$key', values are arrays with these possible fields:
Definition at line 67 of file CommentStore.php.
const CommentStore::COMMENT_CHARACTER_LIMIT = 500 |
Maximum length of a comment in UTF-8 characters.
Longer comments will be truncated.
Definition at line 48 of file CommentStore.php.
Referenced by ProtectionForm\buildForm(), Article\confirmDelete(), ContentHandler\getAutoDeleteReason(), McrUndoAction\getFormFields(), SpecialBlock\getFormFields(), SpecialChangeContentModel\getFormFields(), EditPage\getSummaryInputAttributes(), UserrightsPage\showEditUserGroupsForm(), MovePageForm\showForm(), FileDeleteForm\showForm(), SpecialEditTags\showForm(), SpecialRevisionDelete\showForm(), SpecialUndelete\showHistory(), and SpecialTags\showTagList().
const CommentStore::MAX_DATA_LENGTH = 65535 |
Maximum length of serialized data in bytes.
Longer data will result in an exception.
Definition at line 55 of file CommentStore.php.
Referenced by createComment().