Merge "Add logic for "tags" in ApiBase"
[lhc/web/wiklou.git] / includes / logging / DeleteLogFormatter.php
index 7fe77b4..f0598aa 100644 (file)
@@ -216,4 +216,67 @@ class DeleteLogFormatter extends LogFormatter {
                                return '';
                }
        }
+
+       protected function getParametersForApi() {
+               $entry = $this->entry;
+               $params = array();
+
+               $subtype = $this->entry->getSubtype();
+               if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
+                       $rawParams = $entry->getParameters();
+                       if ( $subtype === 'event' ) {
+                               array_unshift( $rawParams, 'logging' );
+                       }
+
+                       static $map = array(
+                               '4::type',
+                               '5::ids',
+                               '6::ofield',
+                               '7::nfield',
+                               '4::ids' => '5::ids',
+                               '5::ofield' => '6::ofield',
+                               '6::nfield' => '7::nfield',
+                       );
+                       foreach ( $map as $index => $key ) {
+                               if ( isset( $rawParams[$index] ) ) {
+                                       $rawParams[$key] = $rawParams[$index];
+                                       unset( $rawParams[$index] );
+                               }
+                       }
+
+                       $old = $this->parseBitField( $rawParams['6::ofield'] );
+                       $new = $this->parseBitField( $rawParams['7::nfield'] );
+                       if ( !is_array( $rawParams['5::ids'] ) ) {
+                               $rawParams['5::ids'] = explode( ',', $rawParams['5::ids'] );
+                       }
+
+                       $params = array(
+                               '::type' => $rawParams['4::type'],
+                               ':array:ids' => $rawParams['5::ids'],
+                               ':assoc:old' => array( 'bitmask' => $old ),
+                               ':assoc:new' => array( 'bitmask' => $new ),
+                       );
+
+                       static $fields = array(
+                               Revision::DELETED_TEXT => 'content',
+                               Revision::DELETED_COMMENT => 'comment',
+                               Revision::DELETED_USER => 'user',
+                               Revision::DELETED_RESTRICTED => 'restricted',
+                       );
+                       foreach ( $fields as $bit => $key ) {
+                               $params[':assoc:old'][$key] = (bool)( $old & $bit );
+                               $params[':assoc:new'][$key] = (bool)( $new & $bit );
+                       }
+               }
+
+               return $params;
+       }
+
+       public function formatParametersForApi() {
+               $ret = parent::formatParametersForApi();
+               if ( isset( $ret['ids'] ) ) {
+                       ApiResult::setIndexedTagName( $ret['ids'], 'id' );
+               }
+               return $ret;
+       }
 }