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