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