X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Frevisiondelete%2FRevisionDeleter.php;h=bea846048ff6e5cbd09a80de437bf10ed686db80;hb=d48bd95a47cc8526acc741d53b78d7daa8f05407;hp=2de19acf390ad7c629235a0f09180d49539638bf;hpb=59183f670a9e60975632414b25b05f16edf06485;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/revisiondelete/RevisionDeleter.php b/includes/revisiondelete/RevisionDeleter.php index 2de19acf39..bea846048f 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. @@ -86,18 +146,59 @@ 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 ); } /** @@ -106,7 +207,7 @@ class RevisionDeleter { * so that this key can be used instead. * * @param $title Title - * @param $revid + * @param $revid * @return bool|mixed */ public static function checkRevisionExistence( $title, $revid ) { @@ -125,4 +226,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; + } }