X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Frevisiondelete%2FRevisionDeleter.php;h=dbcb3d7dda5ddeb7679ace88316d77f3952ea263;hb=aa6f866bd196e666b9c6e295733276d6a018dbba;hp=d2e10e1a27fe6f1f2b085318d15e1006288fcc13;hpb=3a26db55ab4ba908b76cd9982794d1eeafb4afa0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/revisiondelete/RevisionDeleter.php b/includes/revisiondelete/RevisionDeleter.php index d2e10e1a27..dbcb3d7dda 100644 --- a/includes/revisiondelete/RevisionDeleter.php +++ b/includes/revisiondelete/RevisionDeleter.php @@ -22,11 +22,71 @@ */ /** - * Temporary b/c interface, collection of static functions. - * @ingroup SpecialPage + * General controller for RevDel, used by both SpecialRevisiondelete and + * ApiRevisionDelete. * @ingroup RevisionDelete */ class RevisionDeleter { + /** List of known revdel types, with their corresponding list classes */ + private static $allowedTypes = array( + 'revision' => 'RevDel_RevisionList', + 'archive' => 'RevDel_ArchiveList', + 'oldimage' => 'RevDel_FileList', + 'filearchive' => 'RevDel_ArchivedFileList', + 'logging' => 'RevDel_LogList', + ); + + /** Type map to support old log entries */ + private static $deprecatedTypeMap = array( + 'oldid' => 'revision', + 'artimestamp' => 'archive', + 'oldimage' => 'oldimage', + 'fileid' => 'filearchive', + 'logid' => 'logging', + ); + + /** + * Lists the valid possible types for revision deletion. + * + * @since 1.22 + * @return array + */ + public static function getTypes() { + return array_keys( self::$allowedTypes ); + } + + /** + * Gets the canonical type name, if any. + * + * @since 1.22 + * @param string $typeName + * @return string|null + */ + public static function getCanonicalTypeName( $typeName ) { + if ( isset( self::$deprecatedTypeMap[$typeName] ) ) { + $typeName = self::$deprecatedTypeMap[$typeName]; + } + return isset( self::$allowedTypes[$typeName] ) ? $typeName : null; + } + + /** + * Instantiate the appropriate list class for a given list of IDs. + * + * @since 1.22 + * @param string $typeName RevDel type, see RevisionDeleter::getTypes() + * @param IContextSource $context + * @param Title $title + * @param array $ids + * @return RevDel_List + */ + public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) { + $typeName = self::getCanonicalTypeName( $typeName ); + if ( !$typeName ) { + throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" ); + } + return new self::$allowedTypes[$typeName]( $context, $title, $ids ); + } + /** * Checks for a change in the bitfield for a certain option and updates the * provided array accordingly. @@ -39,7 +99,7 @@ class RevisionDeleter { * @param array $arr the array to update. */ protected static function checkItem( $desc, $field, $diff, $new, &$arr ) { - if( $diff & $field ) { + if ( $diff & $field ) { $arr[( $new & $field ) ? 0 : 1][] = $desc; } } @@ -73,11 +133,12 @@ class RevisionDeleter { self::checkItem( 'revdelete-uname', Revision::DELETED_USER, $diff, $n, $ret ); // Restriction application to sysops - if( $diff & Revision::DELETED_RESTRICTED ) { - if( $n & Revision::DELETED_RESTRICTED ) + if ( $diff & Revision::DELETED_RESTRICTED ) { + if ( $n & Revision::DELETED_RESTRICTED ) { $ret[2][] = 'revdelete-restricted'; - else + } else { $ret[2][] = 'revdelete-unrestricted'; + } } return $ret; } @@ -85,20 +146,62 @@ class RevisionDeleter { /** Get DB field name for URL param... * Future code for other things may also track * other types of revision-specific changes. + * @param string $typeName * @return string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name */ public static function getRelationType( $typeName ) { - if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) { - $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName]; + $typeName = self::getCanonicalTypeName( $typeName ); + if ( !$typeName ) { + return null; } - if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) { - $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class']; - return call_user_func( array( $class, 'getRelationType' ) ); - } else { + return call_user_func( array( self::$allowedTypes[$typeName], 'getRelationType' ) ); + } + + /** + * Get the user right required for the RevDel type + * @since 1.22 + * @param string $typeName + * @return string User right + */ + public static function getRestriction( $typeName ) { + $typeName = self::getCanonicalTypeName( $typeName ); + if ( !$typeName ) { + return null; + } + return call_user_func( array( self::$allowedTypes[$typeName], 'getRestriction' ) ); + } + + /** + * Get the revision deletion constant for the RevDel type + * @since 1.22 + * @param string $typeName + * @return int RevDel constant + */ + public static function getRevdelConstant( $typeName ) { + $typeName = self::getCanonicalTypeName( $typeName ); + if ( !$typeName ) { return null; } + return call_user_func( array( self::$allowedTypes[$typeName], 'getRevdelConstant' ) ); + } + + /** + * Suggest a target for the revision deletion + * @since 1.22 + * @param string $typeName + * @param Title|null $title User-supplied target + * @param array $ids + * @return Title|null + */ + public static function suggestTarget( $typeName, $target, array $ids ) { + $typeName = self::getCanonicalTypeName( $typeName ); + if ( !$typeName ) { + return $target; + } + return call_user_func( array( self::$allowedTypes[$typeName], 'suggestTarget' ), $target, $ids ); } + /** * Checks if a revision still exists in the revision table. * If it doesn't, returns the corresponding ar_timestamp field @@ -124,4 +227,24 @@ class RevisionDeleter { return $timestamp; } + + /** + * Put together a rev_deleted bitfield + * @since 1.22 + * @param array $bitPars extractBitParams() params + * @param int $oldfield current bitfield + * @return array + */ + public static function extractBitfield( $bitPars, $oldfield ) { + // Build the actual new rev_deleted bitfield + $newBits = 0; + foreach ( $bitPars as $const => $val ) { + if ( $val == 1 ) { + $newBits |= $const; // $const is the *_deleted const + } elseif ( $val == -1 ) { + $newBits |= ( $oldfield & $const ); // use existing + } + } + return $newBits; + } }