3 * Revision/log/file deletion backend
9 * Temporary b/c interface, collection of static functions.
10 * @ingroup SpecialPage
12 class RevisionDeleter
{
14 * Checks for a change in the bitfield for a certain option and updates the
15 * provided array accordingly.
17 * @param $desc String: description to add to the array if the option was
19 * @param $field Integer: the bitmask describing the single option.
20 * @param $diff Integer: the xor of the old and new bitfields.
21 * @param $new Integer: the new bitfield
22 * @param $arr Array: the array to update.
24 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
25 if( $diff & $field ) {
26 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
31 * Gets an array of message keys describing the changes made to the visibility
32 * of the revision. If the resulting array is $arr, then $arr[0] will contain an
33 * array of strings describing the items that were hidden, $arr[1] will contain
34 * an array of strings describing the items that were unhidden, and $arr[2] will
35 * contain an array with a single string, which can be one of "applied
36 * restrictions to sysops", "removed restrictions from sysops", or null.
38 * @param $n Integer: the new bitfield.
39 * @param $o Integer: the old bitfield.
40 * @return An array as described above.
43 public static function getChanges( $n, $o ) {
45 $ret = array( 0 => array(), 1 => array(), 2 => array() );
46 // Build bitfield changes in language
47 self
::checkItem( 'revdelete-content',
48 Revision
::DELETED_TEXT
, $diff, $n, $ret );
49 self
::checkItem( 'revdelete-summary',
50 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
51 self
::checkItem( 'revdelete-uname',
52 Revision
::DELETED_USER
, $diff, $n, $ret );
53 // Restriction application to sysops
54 if( $diff & Revision
::DELETED_RESTRICTED
) {
55 if( $n & Revision
::DELETED_RESTRICTED
)
56 $ret[2][] = 'revdelete-restricted';
58 $ret[2][] = 'revdelete-unrestricted';
63 // Get DB field name for URL param...
64 // Future code for other things may also track
65 // other types of revision-specific changes.
66 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
67 public static function getRelationType( $typeName ) {
68 if ( isset( SpecialRevisionDelete
::$deprecatedTypeMap[$typeName] ) ) {
69 $typeName = SpecialRevisionDelete
::$deprecatedTypeMap[$typeName];
71 if ( isset( SpecialRevisionDelete
::$allowedTypes[$typeName] ) ) {
72 $class = SpecialRevisionDelete
::$allowedTypes[$typeName]['list-class'];
73 return call_user_func( array( $class, 'getRelationType' ) );
80 * Checks if a revision still exists in the revision table.
81 * If it doesn't, returns the corresponding ar_timestamp field
82 * so that this key can be used instead.
88 public static function checkRevisionExistence( $title, $revid ) {
89 $dbr = wfGetDB( DB_SLAVE
);
90 $exists = $dbr->selectField( 'revision', '1',
91 array( 'rev_id' => $revid ), __METHOD__
);
97 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
98 array( 'ar_namespace' => $title->getNamespace(),
99 'ar_title' => $title->getDBkey(),
100 'ar_rev_id' => $revid ), __METHOD__
);
106 * Creates utility links for log entries.
108 * @param $title Title
109 * @param $paramArray Array
114 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
117 if ( count( $paramArray ) >= 2 ) {
118 // Different revision types use different URL params...
119 $originalKey = $key = $paramArray[0];
120 // $paramArray[1] is a CSV of the IDs
121 $Ids = explode( ',', $paramArray[1] );
125 // Diff link for single rev deletions
126 if ( count( $Ids ) == 1 ) {
127 // Live revision diffs...
128 if ( in_array( $key, array( 'oldid', 'revision' ) ) ) {
129 $revert[] = $skin->link(
134 'diff' => intval( $Ids[0] ),
137 array( 'known', 'noclasses' )
139 // Deleted revision diffs...
140 } elseif ( in_array( $key, array( 'artimestamp','archive' ) ) ) {
141 $revert[] = $skin->link(
142 SpecialPage
::getTitleFor( 'Undelete' ),
146 'target' => $title->getPrefixedDBKey(),
148 'timestamp' => $Ids[0]
150 array( 'known', 'noclasses' )
155 // View/modify link...
156 $revert[] = $skin->link(
157 SpecialPage
::getTitleFor( 'Revisiondelete' ),
158 $messages['revdel-restore'],
161 'target' => $title->getPrefixedText(),
163 'ids' => implode(',', $Ids),
165 array( 'known', 'noclasses' )
169 return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );