Merge "Make image pagination not require a page load."
[lhc/web/wiklou.git] / includes / revisiondelete / RevisionDeleter.php
1 <?php
2 /**
3 * Revision/log/file deletion backend
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup RevisionDelete
22 */
23
24 /**
25 * Temporary b/c interface, collection of static functions.
26 * @ingroup SpecialPage
27 * @ingroup RevisionDelete
28 */
29 class RevisionDeleter {
30 /**
31 * Checks for a change in the bitfield for a certain option and updates the
32 * provided array accordingly.
33 *
34 * @param string $desc description to add to the array if the option was
35 * enabled / disabled.
36 * @param $field Integer: the bitmask describing the single option.
37 * @param $diff Integer: the xor of the old and new bitfields.
38 * @param $new Integer: the new bitfield
39 * @param array $arr the array to update.
40 */
41 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
42 if ( $diff & $field ) {
43 $arr[( $new & $field ) ? 0 : 1][] = $desc;
44 }
45 }
46
47 /**
48 * Gets an array of message keys describing the changes made to the
49 * visibility of the revision.
50 *
51 * If the resulting array is $arr, then $arr[0] will contain an array of
52 * keys describing the items that were hidden, $arr[1] will contain
53 * an array of keys describing the items that were unhidden, and $arr[2]
54 * will contain an array with a single message key, which can be one of
55 * "revdelete-restricted", "revdelete-unrestricted" indicating (un)suppression
56 * or null to indicate nothing in particular.
57 * You can turn the keys in $arr[0] and $arr[1] into message keys by
58 * appending -hid and and -unhid to the keys respectively.
59 *
60 * @param $n Integer: the new bitfield.
61 * @param $o Integer: the old bitfield.
62 * @return array An array as described above.
63 * @since 1.19 public
64 */
65 public static function getChanges( $n, $o ) {
66 $diff = $n ^ $o;
67 $ret = array( 0 => array(), 1 => array(), 2 => array() );
68 // Build bitfield changes in language
69 self::checkItem( 'revdelete-content',
70 Revision::DELETED_TEXT, $diff, $n, $ret );
71 self::checkItem( 'revdelete-summary',
72 Revision::DELETED_COMMENT, $diff, $n, $ret );
73 self::checkItem( 'revdelete-uname',
74 Revision::DELETED_USER, $diff, $n, $ret );
75 // Restriction application to sysops
76 if ( $diff & Revision::DELETED_RESTRICTED ) {
77 if ( $n & Revision::DELETED_RESTRICTED ) {
78 $ret[2][] = 'revdelete-restricted';
79 } else {
80 $ret[2][] = 'revdelete-unrestricted';
81 }
82 }
83 return $ret;
84 }
85
86 /** Get DB field name for URL param...
87 * Future code for other things may also track
88 * other types of revision-specific changes.
89 * @return string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
90 */
91 public static function getRelationType( $typeName ) {
92 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
93 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
94 }
95 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
96 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
97 return call_user_func( array( $class, 'getRelationType' ) );
98 } else {
99 return null;
100 }
101 }
102
103 /**
104 * Checks if a revision still exists in the revision table.
105 * If it doesn't, returns the corresponding ar_timestamp field
106 * so that this key can be used instead.
107 *
108 * @param $title Title
109 * @param $revid
110 * @return bool|mixed
111 */
112 public static function checkRevisionExistence( $title, $revid ) {
113 $dbr = wfGetDB( DB_SLAVE );
114 $exists = $dbr->selectField( 'revision', '1',
115 array( 'rev_id' => $revid ), __METHOD__ );
116
117 if ( $exists ) {
118 return true;
119 }
120
121 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
122 array( 'ar_namespace' => $title->getNamespace(),
123 'ar_title' => $title->getDBkey(),
124 'ar_rev_id' => $revid ), __METHOD__ );
125
126 return $timestamp;
127 }
128 }