Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 66 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FlaggedRevsLog | |
0.00% |
0 / 66 |
|
0.00% |
0 / 5 |
306 | |
0.00% |
0 / 1 |
updateReviewLog | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
72 | |||
updateStabilityLog | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
updateStabilityLogOnMove | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
stabilityLogParams | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
expandParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\MediaWikiServices; |
4 | use MediaWiki\Title\Title; |
5 | use MediaWiki\User\User; |
6 | |
7 | class FlaggedRevsLog { |
8 | /** |
9 | * Record a log entry on the review action |
10 | * @param Title $title |
11 | * @param array<string,int> $dims |
12 | * @param string $comment |
13 | * @param int $revId revision ID |
14 | * @param int $stableId prior stable revision ID |
15 | * @param bool $approve approved? (otherwise unapproved) |
16 | * @param User $user performing the action |
17 | */ |
18 | public static function updateReviewLog( |
19 | Title $title, array $dims, |
20 | $comment, $revId, $stableId, $approve, $user |
21 | ) { |
22 | # Tag rating list (e.g. accuracy=x, depth=y, style=z) |
23 | $ratings = []; |
24 | # Skip rating list if flagging is just an 0/1 feature... |
25 | if ( !FlaggedRevs::binaryFlagging() ) { |
26 | // Give grep a chance to find the usages: |
27 | // revreview-accuracy-0, revreview-accuracy-1, revreview-accuracy-2, |
28 | // revreview-accuracy-3, revreview-accuracy-4, revreview-accuracy |
29 | foreach ( $dims as $quality => $level ) { |
30 | $ratings[] = wfMessage( "revreview-$quality" )->inContentLanguage()->text() . |
31 | wfMessage( 'colon-separator' )->inContentLanguage()->text() . |
32 | wfMessage( "revreview-$quality-$level" )->inContentLanguage()->text(); |
33 | } |
34 | } |
35 | // Approved revisions |
36 | if ( $approve ) { |
37 | # Make comma-separated list of ratings |
38 | $rating = $ratings |
39 | ? '[' . implode( ', ', $ratings ) . ']' |
40 | : ''; |
41 | # Append comment with ratings |
42 | if ( $rating != '' ) { |
43 | $comment .= $comment ? " $rating" : $rating; |
44 | } |
45 | # Sort into the proper action (useful for filtering) |
46 | $action = RevisionReviewForm::ACTION_APPROVE; |
47 | if ( !$stableId ) { // first time |
48 | $action .= "-i"; |
49 | } |
50 | // De-approved revisions |
51 | } else { |
52 | $action = RevisionReviewForm::ACTION_UNAPPROVE; |
53 | } |
54 | $ts = MediaWikiServices::getInstance() |
55 | ->getRevisionLookup() |
56 | ->getTimestampFromId( $revId, IDBAccessObject::READ_LATEST ); |
57 | |
58 | $logEntry = new ManualLogEntry( 'review', $action ); |
59 | $logEntry->setPerformer( $user ); |
60 | $logEntry->setTarget( $title ); |
61 | $logEntry->setComment( $comment ); |
62 | |
63 | # Param format is <rev id, old stable id, rev timestamp> |
64 | $logEntry->setParameters( [ $revId, $stableId, $ts ] ); |
65 | # Make log easily searchable by rev_id |
66 | $logEntry->setRelations( [ 'rev_id' => $revId ] ); |
67 | |
68 | $logid = $logEntry->insert(); |
69 | $logEntry->publish( $logid, 'udp' ); |
70 | } |
71 | |
72 | /** |
73 | * Record a log entry on the stability config change action |
74 | * @param Title $title |
75 | * @param array $config |
76 | * @param array $oldConfig |
77 | * @param string $reason |
78 | * @param User $user performing the action |
79 | */ |
80 | public static function updateStabilityLog( |
81 | Title $title, array $config, array $oldConfig, $reason, $user |
82 | ) { |
83 | if ( FRPageConfig::configIsReset( $config ) ) { |
84 | # We are going back to default settings |
85 | $action = 'reset'; |
86 | } else { |
87 | # We are changing to non-default settings |
88 | $action = ( $oldConfig === FRPageConfig::getDefaultVisibilitySettings() ) |
89 | ? 'config' // set a custom configuration |
90 | : 'modify'; // modified an existing custom configuration |
91 | } |
92 | |
93 | $logEntry = new ManualLogEntry( 'stable', $action ); |
94 | $logEntry->setPerformer( $user ); |
95 | $logEntry->setTarget( $title ); |
96 | $logEntry->setComment( $reason ); |
97 | $params = self::stabilityLogParams( $config ); |
98 | $logEntry->setParameters( $params ); |
99 | |
100 | $logId = $logEntry->insert(); |
101 | $logEntry->publish( $logId ); |
102 | } |
103 | |
104 | /** |
105 | * Record move of settings in stability log |
106 | * @param Title $newTitle |
107 | * @param Title $oldTitle |
108 | * @param string $reason |
109 | * @param User $user performing the action |
110 | */ |
111 | public static function updateStabilityLogOnMove( |
112 | Title $newTitle, Title $oldTitle, $reason, $user |
113 | ) { |
114 | $logEntry = new ManualLogEntry( 'stable', 'move_stable' ); |
115 | $logEntry->setPerformer( $user ); |
116 | $logEntry->setTarget( $newTitle ); |
117 | |
118 | // Build comment for log |
119 | $comment = wfMessage( |
120 | 'prot_1movedto2', |
121 | $oldTitle->getPrefixedText(), |
122 | $newTitle->getPrefixedText() |
123 | )->inContentLanguage()->text(); |
124 | if ( $reason ) { |
125 | $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason; |
126 | } |
127 | $logEntry->setComment( $comment ); |
128 | |
129 | $logEntry->setParameters( [ |
130 | '4::oldtitle' => $oldTitle->getPrefixedText(), |
131 | ] ); |
132 | |
133 | $logId = $logEntry->insert(); |
134 | $logEntry->publish( $logId ); |
135 | } |
136 | |
137 | /** |
138 | * Get log params (associate array) from a stability config |
139 | * @param array $config |
140 | * @return array (associative) |
141 | */ |
142 | public static function stabilityLogParams( array $config ) { |
143 | $params = $config; |
144 | if ( !FlaggedRevs::useOnlyIfProtected() ) { |
145 | $params['precedence'] = 1; // b/c hack for presenting log params... |
146 | } |
147 | return $params; |
148 | } |
149 | |
150 | /** |
151 | * Expand a list of log params into an associative array |
152 | * For legacy log entries |
153 | * @param string[] $pars |
154 | * @return string[] (associative) |
155 | */ |
156 | public static function expandParams( array $pars ) { |
157 | $res = []; |
158 | $pars = array_filter( $pars ); |
159 | foreach ( $pars as $paramAndValue ) { |
160 | [ $param, $value ] = explode( '=', $paramAndValue, 2 ); |
161 | $res[$param] = $value; |
162 | } |
163 | return $res; |
164 | } |
165 | } |