Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5957738
EditSummariesAid.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
EditSummariesAid.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Aid
;
use
MediaWiki\MediaWikiServices
;
use
MediaWiki\Utils\MWTimestamp
;
use
Wikimedia\Rdbms\SelectQueryBuilder
;
/**
* Translation aid that provides last X edit summaries for a translation
*
* @author Eugene Wang'ombe
* @license GPL-2.0-or-later
* @since 2022.04
*/
class
EditSummariesAid
extends
TranslationAid
{
private
const
COMMENT_COUNT
=
3
;
public
function
getData
():
array
{
$pageTitle
=
$this
->
handle
->
getTitle
();
if
(
!
$pageTitle
->
exists
()
)
{
return
[];
}
$mwService
=
MediaWikiServices
::
getInstance
();
$revisionFactory
=
$mwService
->
getRevisionFactory
();
// Build the query to fetch the last x revisions
$dbr
=
$mwService
->
getDBLoadBalancer
()->
getConnection
(
DB_REPLICA
);
$aid
=
$pageTitle
->
getArticleID
();
$result
=
$revisionFactory
->
newSelectQueryBuilder
(
$dbr
)
->
joinComment
()
->
where
(
[
'rev_page'
=>
$aid
]
)
->
orderBy
(
[
'rev_timestamp'
,
'rev_id'
],
SelectQueryBuilder
::
SORT_DESC
)
->
limit
(
self
::
COMMENT_COUNT
)
->
caller
(
__METHOD__
)
->
fetchResultSet
();
$editSummaries
=
[];
$commentFormatter
=
$mwService
->
getCommentFormatter
();
foreach
(
$result
as
$row
)
{
$revision
=
$revisionFactory
->
newRevisionFromRow
(
$row
);
$comment
=
$revision
->
getComment
();
// The result of getComment() may return null. In that case
// skip processing of the summary.
if
(
!
$comment
)
{
continue
;
}
$message
=
$commentFormatter
->
format
(
$comment
->
message
->
text
()
);
$editSummaries
[]
=
[
'humanTimestamp'
=>
$this
->
context
->
getLanguage
()
->
getHumanTimestamp
(
new
MWTimestamp
(
$revision
->
getTimestamp
()
)
),
'timestamp'
=>
$revision
->
getTimestamp
(),
'summary'
=>
$message
,
'revisionId'
=>
$revision
->
getId
()
];
}
return
$editSummaries
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 05:18 (2 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
be/db/9d8e04998bee6937d2be544a9d5e
Default Alt Text
EditSummariesAid.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment