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[2] will contain
34 * an array of strings describing the items that were unhidden, and $arr[3] 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.
42 protected static function getChanges( $n, $o ) {
44 $ret = array( 0 => array(), 1 => array(), 2 => array() );
45 // Build bitfield changes in language
46 self
::checkItem( 'revdelete-content',
47 Revision
::DELETED_TEXT
, $diff, $n, $ret );
48 self
::checkItem( 'revdelete-summary',
49 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
50 self
::checkItem( 'revdelete-uname',
51 Revision
::DELETED_USER
, $diff, $n, $ret );
52 // Restriction application to sysops
53 if( $diff & Revision
::DELETED_RESTRICTED
) {
54 if( $n & Revision
::DELETED_RESTRICTED
)
55 $ret[2][] = 'revdelete-restricted';
57 $ret[2][] = 'revdelete-unrestricted';
63 * Gets a log message to describe the given revision visibility change. This
64 * message will be of the form "[hid {content, edit summary, username}];
65 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
67 * @param $count Integer: The number of effected revisions.
68 * @param $nbitfield Integer: The new bitfield for the revision.
69 * @param $obitfield Integer: The old bitfield for the revision.
70 * @param $isForLog Boolean
71 * @param $forContent Boolean
73 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
74 global $wgLang, $wgContLang;
76 $lang = $forContent ?
$wgContLang : $wgLang;
77 $msgFunc = $forContent ?
"wfMsgForContent" : "wfMsg";
79 $changes = self
::getChanges( $nbitfield, $obitfield );
80 array_walk( $changes, array( __CLASS__
, 'expandMessageArray' ), $forContent );
82 $changesText = array();
84 if( count( $changes[0] ) ) {
85 $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
87 if( count( $changes[1] ) ) {
88 $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
91 $s = $lang->semicolonList( $changesText );
92 if( count( $changes[2] ) ) {
93 $s .= $s ?
' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
96 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
97 return wfMsgExt( $msg, $forContent ?
array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
100 private static function expandMessageArray(& $msg, $key, $forContent) {
101 if ( is_array ( $msg ) ) {
102 array_walk( $msg, array( __CLASS__
, 'expandMessageArray' ), $forContent );
105 $msg = wfMsgForContent($msg);
112 // Get DB field name for URL param...
113 // Future code for other things may also track
114 // other types of revision-specific changes.
115 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
116 public static function getRelationType( $typeName ) {
117 if ( isset( SpecialRevisionDelete
::$deprecatedTypeMap[$typeName] ) ) {
118 $typeName = SpecialRevisionDelete
::$deprecatedTypeMap[$typeName];
120 if ( isset( SpecialRevisionDelete
::$allowedTypes[$typeName] ) ) {
121 $class = SpecialRevisionDelete
::$allowedTypes[$typeName]['list-class'];
122 $list = new $class( null, null, null );
123 return $list->getIdField();
130 * Checks if a revision still exists in the revision table.
131 * If it doesn't, returns the corresponding ar_timestamp field
132 * so that this key can be used instead.
134 * @param $title Title
138 public static function checkRevisionExistence( $title, $revid ) {
139 $dbr = wfGetDB( DB_SLAVE
);
140 $exists = $dbr->selectField( 'revision', '1',
141 array( 'rev_id' => $revid ), __METHOD__
);
147 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
148 array( 'ar_namespace' => $title->getNamespace(),
149 'ar_title' => $title->getDBkey(),
150 'ar_rev_id' => $revid ), __METHOD__
);
156 * Creates utility links for log entries.
158 * @param $title Title
159 * @param $paramArray Array
164 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
167 if( count($paramArray) >= 2 ) {
168 // Different revision types use different URL params...
169 $originalKey = $key = $paramArray[0];
170 // $paramArray[1] is a CSV of the IDs
171 $Ids = explode( ',', $paramArray[1] );
175 // For if undeleted revisions are found amidst deleted ones.
176 $undeletedRevisions = array();
178 // This is not going to work if some revs are deleted and some
180 if ($key == 'revision') {
181 // Nothing to do; deleted revisions can still be looked up by ID.
184 // Diff link for single rev deletions
185 if( count($Ids) == 1 && !count($undeletedRevisions) ) {
186 // Live revision diffs...
187 if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
188 $revert[] = $skin->link(
193 'diff' => intval( $Ids[0] ),
196 array( 'known', 'noclasses' )
198 // Deleted revision diffs...
199 } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
200 $revert[] = $skin->link(
201 SpecialPage
::getTitleFor( 'Undelete' ),
205 'target' => $title->getPrefixedDBKey(),
207 'timestamp' => $Ids[0]
209 array( 'known', 'noclasses' )
214 // View/modify link...
215 if ( count( $undeletedRevisions ) ) {
216 // @todo FIXME: THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
217 // It's not possible to pass a list of both deleted and
218 // undeleted revisions to SpecialRevisionDelete, so we're
219 // stuck with two links. See bug 23363.
220 $restoreLinks = array();
222 $restoreLinks[] = $skin->link(
223 SpecialPage
::getTitleFor( 'Revisiondelete' ),
224 $messages['revdel-restore-visible'],
227 'target' => $title->getPrefixedText(),
228 'type' => $originalKey,
229 'ids' => implode( ',', $undeletedRevisions ),
231 array( 'known', 'noclasses' )
234 $restoreLinks[] = $skin->link(
235 SpecialPage
::getTitleFor( 'Revisiondelete' ),
236 $messages['revdel-restore-deleted'],
239 'target' => $title->getPrefixedText(),
241 'ids' => implode(',', $Ids),
243 array( 'known', 'noclasses' )
246 $revert[] = $messages['revdel-restore'] . ' [' .
247 $wgLang->pipeList( $restoreLinks ) . ']';
249 $revert[] = $skin->link(
250 SpecialPage
::getTitleFor( 'Revisiondelete' ),
251 $messages['revdel-restore'],
254 'target' => $title->getPrefixedText(),
256 'ids' => implode(',', $Ids),
258 array( 'known', 'noclasses' )
263 return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );