Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 95 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
ThreadHistoryPager | |
0.00% |
0 / 95 |
|
0.00% |
0 / 10 |
992 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getFieldMessages | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getFieldNames | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatValue | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
42 | |||
getActionDescription | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
306 | |||
getIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultSort | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isFieldSortable | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultDirections | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | use MediaWiki\Html\Html; |
4 | use MediaWiki\Linker\Linker; |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Pager\TablePager; |
7 | |
8 | class ThreadHistoryPager extends TablePager { |
9 | /** @var string[] */ |
10 | public static $change_names; |
11 | |
12 | /** @var Thread|null */ |
13 | protected $thread; |
14 | |
15 | /** @var LqtView */ |
16 | protected $view; |
17 | |
18 | /** @var \MediaWiki\Linker\LinkRenderer */ |
19 | protected $linkRenderer; |
20 | |
21 | public function __construct( LqtView $view, ?Thread $thread ) { |
22 | parent::__construct(); |
23 | |
24 | $this->thread = $thread; |
25 | $this->view = $view; |
26 | $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); |
27 | |
28 | self::$change_names = |
29 | [ |
30 | Threads::CHANGE_EDITED_ROOT => $this->msg( 'lqt_hist_comment_edited' )->plain(), |
31 | Threads::CHANGE_EDITED_SUMMARY => $this->msg( 'lqt_hist_summary_changed' )->plain(), |
32 | Threads::CHANGE_REPLY_CREATED => $this->msg( 'lqt_hist_reply_created' )->plain(), |
33 | Threads::CHANGE_NEW_THREAD => $this->msg( 'lqt_hist_thread_created' )->plain(), |
34 | Threads::CHANGE_DELETED => $this->msg( 'lqt_hist_deleted' )->plain(), |
35 | Threads::CHANGE_UNDELETED => $this->msg( 'lqt_hist_undeleted' )->plain(), |
36 | Threads::CHANGE_MOVED_TALKPAGE => $this->msg( 'lqt_hist_moved_talkpage' )->plain(), |
37 | Threads::CHANGE_EDITED_SUBJECT => $this->msg( 'lqt_hist_edited_subject' )->plain(), |
38 | Threads::CHANGE_SPLIT => $this->msg( 'lqt_hist_split' )->plain(), |
39 | Threads::CHANGE_MERGED_FROM => $this->msg( 'lqt_hist_merged_from' )->plain(), |
40 | Threads::CHANGE_MERGED_TO => $this->msg( 'lqt_hist_merged_to' )->plain(), |
41 | Threads::CHANGE_SPLIT_FROM => $this->msg( 'lqt_hist_split_from' )->plain(), |
42 | Threads::CHANGE_ROOT_BLANKED => $this->msg( 'lqt_hist_root_blanked' )->plain(), |
43 | Threads::CHANGE_ADJUSTED_SORTKEY => $this->msg( 'lqt_hist_adjusted_sortkey' )->plain() |
44 | ]; |
45 | } |
46 | |
47 | public function getQueryInfo() { |
48 | $queryInfo = [ |
49 | 'tables' => [ 'thread_history' ], |
50 | 'fields' => '*', |
51 | 'conds' => [ 'th_thread' => $this->thread->id() ], |
52 | 'options' => [ 'order by' => 'th_timestamp desc' ], |
53 | ]; |
54 | |
55 | return $queryInfo; |
56 | } |
57 | |
58 | public function getFieldMessages() { |
59 | $headers = [ |
60 | 'th_timestamp' => $this->msg( 'lqt-history-time' )->text(), |
61 | 'th_user_text' => $this->msg( 'lqt-history-user' )->text(), |
62 | 'th_change_type' => $this->msg( 'lqt-history-action' )->text(), |
63 | 'th_change_comment' => $this->msg( 'lqt-history-comment' )->text(), |
64 | ]; |
65 | |
66 | return $headers; |
67 | } |
68 | |
69 | public function getFieldNames() { |
70 | return $this->getFieldMessages(); |
71 | } |
72 | |
73 | public function formatValue( $name, $value ) { |
74 | $row = $this->mCurrentRow; |
75 | |
76 | switch ( $name ) { |
77 | case 'th_timestamp': |
78 | $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ); |
79 | return $this->linkRenderer->makeLink( |
80 | $this->getTitle(), |
81 | $formatted, |
82 | [], |
83 | [ 'lqt_oldid' => $row->th_id ] |
84 | ); |
85 | case 'th_user_text': |
86 | return Linker::userLink( |
87 | $row->th_user, |
88 | $row->th_user_text |
89 | ) . |
90 | ' ' . Linker::userToolLinks( $row->th_user, $row->th_user_text ); |
91 | case 'th_change_type': |
92 | return $this->getActionDescription( $value ); |
93 | case 'th_change_comment': |
94 | return MediaWikiServices::getInstance()->getCommentFormatter()->formatBlock( $value ); |
95 | default: |
96 | return "Unable to format $name"; |
97 | } |
98 | } |
99 | |
100 | public function getActionDescription( $type ) { |
101 | $args = []; |
102 | $revision = ThreadRevision::loadFromRow( $this->mCurrentRow ); |
103 | $changeObject = $revision->getChangeObject(); |
104 | |
105 | if ( $revision && $revision->prev() ) { |
106 | $lastChangeObject = $revision->prev()->getChangeObject(); |
107 | } else { |
108 | $lastChangeObject = null; |
109 | } |
110 | |
111 | if ( $changeObject && $changeObject->title() ) { |
112 | $args[] = $changeObject->title()->getPrefixedText(); |
113 | } else { |
114 | $args[] = ''; |
115 | } |
116 | |
117 | $msg = self::$change_names[$type]; |
118 | |
119 | switch ( $type ) { |
120 | case Threads::CHANGE_EDITED_SUBJECT: |
121 | if ( $changeObject && $lastChangeObject ) { |
122 | $args[] = $lastChangeObject->subject(); |
123 | $args[] = $changeObject->subject(); |
124 | } else { |
125 | $msg = $this->msg( 'lqt_hist_edited_subject_corrupt' )->parse(); |
126 | } |
127 | break; |
128 | case Threads::CHANGE_EDITED_ROOT: |
129 | case Threads::CHANGE_ROOT_BLANKED: |
130 | $view = $this->view; |
131 | |
132 | if ( $changeObject && $revision && $changeObject->title() ) { |
133 | $diffLink = $view->diffPermalinkURL( $changeObject, $revision ); |
134 | $args[] = $diffLink; |
135 | } else { |
136 | $args[] = ''; |
137 | if ( $type == Threads::CHANGE_EDITED_ROOT ) { |
138 | $msg = $this->msg( 'lqt_hist_comment_edited_deleted' )->parse(); |
139 | } |
140 | } |
141 | break; |
142 | case Threads::CHANGE_REPLY_CREATED: |
143 | if ( !$changeObject || !$changeObject->title() ) { |
144 | $msg = $this->msg( 'lqt_hist_reply_created_deleted' )->parse(); |
145 | } |
146 | break; |
147 | } |
148 | |
149 | $content = wfMsgReplaceArgs( $msg, $args ); |
150 | return Html::rawElement( |
151 | 'span', [ 'class' => 'plainlinks' ], $this->getOutput()->parseInlineAsInterface( $content ) |
152 | ); |
153 | } |
154 | |
155 | public function getIndexField() { |
156 | return 'th_timestamp'; |
157 | } |
158 | |
159 | public function getDefaultSort() { |
160 | return 'th_timestamp'; |
161 | } |
162 | |
163 | public function isFieldSortable( $name ) { |
164 | $sortable_fields = [ 'th_timestamp', 'th_user_text', 'th_change_type' ]; |
165 | return in_array( $name, $sortable_fields ); |
166 | } |
167 | |
168 | public function getDefaultDirections() { |
169 | return true; /* descending */ |
170 | } |
171 | } |