Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
EditSummariesAid.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6use MediaWiki\MediaWikiServices;
7use MWTimestamp;
8
17 private const COMMENT_COUNT = 3;
18
19 public function getData(): array {
20 $pageTitle = $this->handle->getTitle();
21 if ( !$pageTitle->exists() ) {
22 return [];
23 }
24
25 $mwService = MediaWikiServices::getInstance();
26 $revisionFactory = $mwService->getRevisionFactory();
27
28 // Build the query to fetch the last x revisions
29 $dbr = $mwService->getDBLoadBalancer()->getConnection( DB_REPLICA );
30 $options = [ 'ORDER BY' => 'rev_timestamp DESC, rev_id DESC' ];
31 $options[ 'LIMIT' ] = self::COMMENT_COUNT;
32 $aid = $pageTitle->getArticleID();
33 $revQuery = $revisionFactory->getQueryInfo();
34 $result = $dbr->select(
35 $revQuery[ 'tables' ],
36 $revQuery[ 'fields' ],
37 [ 'rev_page' => $aid ],
38 __METHOD__,
39 $options,
40 $revQuery[ 'joins' ]
41 );
42
43 $editSummaries = [];
44 $commentFormatter = $mwService->getCommentFormatter();
45 foreach ( $result as $row ) {
46 $revision = $revisionFactory->newRevisionFromRow( $row );
47 $comment = $revision->getComment();
48
49 // The result of getComment() may return null. In that case
50 // skip processing of the summary.
51 if ( !$comment ) {
52 continue;
53 }
54
55 $message = $commentFormatter->format( $comment->message->text() );
56
57 $editSummaries[] = [
58 'humanTimestamp' => $this->context->getLanguage()
59 ->getHumanTimestamp( new MWTimestamp( $revision->getTimestamp() ) ),
60 'timestamp' => $revision->getTimestamp(),
61 'summary' => $message,
62 'revisionId' => $revision->getId()
63 ];
64 }
65
66 return $editSummaries;
67 }
68}
Translation aid that provides last X edit summaries for a translation.
getData()
Translation aid class should implement this function.