MediaWiki  REL1_22
RevisionDeleter.php
Go to the documentation of this file.
00001 <?php
00029 class RevisionDeleter {
00031     private static $allowedTypes = array(
00032         'revision' => 'RevDel_RevisionList',
00033         'archive' => 'RevDel_ArchiveList',
00034         'oldimage' => 'RevDel_FileList',
00035         'filearchive' => 'RevDel_ArchivedFileList',
00036         'logging' => 'RevDel_LogList',
00037     );
00038 
00040     private static $deprecatedTypeMap = array(
00041         'oldid' => 'revision',
00042         'artimestamp' => 'archive',
00043         'oldimage' => 'oldimage',
00044         'fileid' => 'filearchive',
00045         'logid' => 'logging',
00046     );
00047 
00054     public static function getTypes() {
00055         return array_keys( self::$allowedTypes );
00056     }
00057 
00065     public static function getCanonicalTypeName( $typeName ) {
00066         if ( isset( self::$deprecatedTypeMap[$typeName] ) ) {
00067             $typeName = self::$deprecatedTypeMap[$typeName];
00068         }
00069         return isset( self::$allowedTypes[$typeName] ) ? $typeName : null;
00070     }
00071 
00082     public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) {
00083         $typeName = self::getCanonicalTypeName( $typeName );
00084         if ( !$typeName ) {
00085             throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
00086         }
00087         return new self::$allowedTypes[$typeName]( $context, $title, $ids );
00088     }
00089 
00101     protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
00102         if ( $diff & $field ) {
00103             $arr[( $new & $field ) ? 0 : 1][] = $desc;
00104         }
00105     }
00106 
00125     public static function getChanges( $n, $o ) {
00126         $diff = $n ^ $o;
00127         $ret = array( 0 => array(), 1 => array(), 2 => array() );
00128         // Build bitfield changes in language
00129         self::checkItem( 'revdelete-content',
00130             Revision::DELETED_TEXT, $diff, $n, $ret );
00131         self::checkItem( 'revdelete-summary',
00132             Revision::DELETED_COMMENT, $diff, $n, $ret );
00133         self::checkItem( 'revdelete-uname',
00134             Revision::DELETED_USER, $diff, $n, $ret );
00135         // Restriction application to sysops
00136         if ( $diff & Revision::DELETED_RESTRICTED ) {
00137             if ( $n & Revision::DELETED_RESTRICTED ) {
00138                 $ret[2][] = 'revdelete-restricted';
00139             } else {
00140                 $ret[2][] = 'revdelete-unrestricted';
00141             }
00142         }
00143         return $ret;
00144     }
00145 
00152     public static function getRelationType( $typeName ) {
00153         $typeName = self::getCanonicalTypeName( $typeName );
00154         if ( !$typeName ) {
00155             return null;
00156         }
00157         return call_user_func( array( self::$allowedTypes[$typeName], 'getRelationType' ) );
00158     }
00159 
00166     public static function getRestriction( $typeName ) {
00167         $typeName = self::getCanonicalTypeName( $typeName );
00168         if ( !$typeName ) {
00169             return null;
00170         }
00171         return call_user_func( array( self::$allowedTypes[$typeName], 'getRestriction' ) );
00172     }
00173 
00180     public static function getRevdelConstant( $typeName ) {
00181         $typeName = self::getCanonicalTypeName( $typeName );
00182         if ( !$typeName ) {
00183             return null;
00184         }
00185         return call_user_func( array( self::$allowedTypes[$typeName], 'getRevdelConstant' ) );
00186     }
00187 
00196     public static function suggestTarget( $typeName, $target, array $ids ) {
00197         $typeName = self::getCanonicalTypeName( $typeName );
00198         if ( !$typeName ) {
00199             return $target;
00200         }
00201         return call_user_func( array( self::$allowedTypes[$typeName], 'suggestTarget' ), $target, $ids );
00202     }
00203 
00204 
00214     public static function checkRevisionExistence( $title, $revid ) {
00215         $dbr = wfGetDB( DB_SLAVE );
00216         $exists = $dbr->selectField( 'revision', '1',
00217                 array( 'rev_id' => $revid ), __METHOD__ );
00218 
00219         if ( $exists ) {
00220             return true;
00221         }
00222 
00223         $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
00224                 array( 'ar_namespace' => $title->getNamespace(),
00225                     'ar_title' => $title->getDBkey(),
00226                     'ar_rev_id' => $revid ), __METHOD__ );
00227 
00228         return $timestamp;
00229     }
00230 
00238     public static function extractBitfield( $bitPars, $oldfield ) {
00239         // Build the actual new rev_deleted bitfield
00240         $newBits = 0;
00241         foreach ( $bitPars as $const => $val ) {
00242             if ( $val == 1 ) {
00243                 $newBits |= $const; // $const is the *_deleted const
00244             } elseif ( $val == -1 ) {
00245                 $newBits |= ( $oldfield & $const ); // use existing
00246             }
00247         }
00248         return $newBits;
00249     }
00250 }