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