Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Revision often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Revision, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class Revision implements IDBAccessObject { |
||
29 | /** @var int|null */ |
||
30 | protected $mId; |
||
31 | /** @var int|null */ |
||
32 | protected $mPage; |
||
33 | /** @var string */ |
||
34 | protected $mUserText; |
||
35 | /** @var string */ |
||
36 | protected $mOrigUserText; |
||
37 | /** @var int */ |
||
38 | protected $mUser; |
||
39 | /** @var bool */ |
||
40 | protected $mMinorEdit; |
||
41 | /** @var string */ |
||
42 | protected $mTimestamp; |
||
43 | /** @var int */ |
||
44 | protected $mDeleted; |
||
45 | /** @var int */ |
||
46 | protected $mSize; |
||
47 | /** @var string */ |
||
48 | protected $mSha1; |
||
49 | /** @var int */ |
||
50 | protected $mParentId; |
||
51 | /** @var string */ |
||
52 | protected $mComment; |
||
53 | /** @var string */ |
||
54 | protected $mText; |
||
55 | /** @var int */ |
||
56 | protected $mTextId; |
||
57 | /** @var int */ |
||
58 | protected $mUnpatrolled; |
||
59 | |||
60 | /** @var stdClass|null */ |
||
61 | protected $mTextRow; |
||
62 | |||
63 | /** @var null|Title */ |
||
64 | protected $mTitle; |
||
65 | /** @var bool */ |
||
66 | protected $mCurrent; |
||
67 | /** @var string */ |
||
68 | protected $mContentModel; |
||
69 | /** @var string */ |
||
70 | protected $mContentFormat; |
||
71 | |||
72 | /** @var Content|null|bool */ |
||
73 | protected $mContent; |
||
74 | /** @var null|ContentHandler */ |
||
75 | protected $mContentHandler; |
||
76 | |||
77 | /** @var int */ |
||
78 | protected $mQueryFlags = 0; |
||
79 | /** @var bool Used for cached values to reload user text and rev_deleted */ |
||
80 | protected $mRefreshMutableFields = false; |
||
81 | /** @var string Wiki ID; false means the current wiki */ |
||
82 | protected $mWiki = false; |
||
83 | |||
84 | // Revision deletion constants |
||
85 | const DELETED_TEXT = 1; |
||
86 | const DELETED_COMMENT = 2; |
||
87 | const DELETED_USER = 4; |
||
88 | const DELETED_RESTRICTED = 8; |
||
89 | const SUPPRESSED_USER = 12; // convenience |
||
90 | const SUPPRESSED_ALL = 15; // convenience |
||
91 | |||
92 | // Audience options for accessors |
||
93 | const FOR_PUBLIC = 1; |
||
94 | const FOR_THIS_USER = 2; |
||
95 | const RAW = 3; |
||
96 | |||
97 | const TEXT_CACHE_GROUP = 'revisiontext:10'; // process cache name and max key count |
||
98 | |||
99 | /** |
||
100 | * Load a page revision from a given revision ID number. |
||
101 | * Returns null if no such revision can be found. |
||
102 | * |
||
103 | * $flags include: |
||
104 | * Revision::READ_LATEST : Select the data from the master |
||
105 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
106 | * |
||
107 | * @param int $id |
||
108 | * @param int $flags (optional) |
||
109 | * @return Revision|null |
||
110 | */ |
||
111 | public static function newFromId( $id, $flags = 0 ) { |
||
114 | |||
115 | /** |
||
116 | * Load either the current, or a specified, revision |
||
117 | * that's attached to a given link target. If not attached |
||
118 | * to that link target, will return null. |
||
119 | * |
||
120 | * $flags include: |
||
121 | * Revision::READ_LATEST : Select the data from the master |
||
122 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
123 | * |
||
124 | * @param LinkTarget $linkTarget |
||
125 | * @param int $id (optional) |
||
126 | * @param int $flags Bitfield (optional) |
||
127 | * @return Revision|null |
||
128 | */ |
||
129 | View Code Duplication | public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) { |
|
145 | |||
146 | /** |
||
147 | * Load either the current, or a specified, revision |
||
148 | * that's attached to a given page ID. |
||
149 | * Returns null if no such revision can be found. |
||
150 | * |
||
151 | * $flags include: |
||
152 | * Revision::READ_LATEST : Select the data from the master (since 1.20) |
||
153 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
154 | * |
||
155 | * @param int $pageId |
||
156 | * @param int $revId (optional) |
||
157 | * @param int $flags Bitfield (optional) |
||
158 | * @return Revision|null |
||
159 | */ |
||
160 | View Code Duplication | public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) { |
|
172 | |||
173 | /** |
||
174 | * Make a fake revision object from an archive table row. This is queried |
||
175 | * for permissions or even inserted (as in Special:Undelete) |
||
176 | * @todo FIXME: Should be a subclass for RevisionDelete. [TS] |
||
177 | * |
||
178 | * @param object $row |
||
179 | * @param array $overrides |
||
180 | * |
||
181 | * @throws MWException |
||
182 | * @return Revision |
||
183 | */ |
||
184 | public static function newFromArchiveRow( $row, $overrides = [] ) { |
||
224 | |||
225 | /** |
||
226 | * @since 1.19 |
||
227 | * |
||
228 | * @param object $row |
||
229 | * @return Revision |
||
230 | */ |
||
231 | public static function newFromRow( $row ) { |
||
234 | |||
235 | /** |
||
236 | * Load a page revision from a given revision ID number. |
||
237 | * Returns null if no such revision can be found. |
||
238 | * |
||
239 | * @param IDatabase $db |
||
240 | * @param int $id |
||
241 | * @return Revision|null |
||
242 | */ |
||
243 | public static function loadFromId( $db, $id ) { |
||
246 | |||
247 | /** |
||
248 | * Load either the current, or a specified, revision |
||
249 | * that's attached to a given page. If not attached |
||
250 | * to that page, will return null. |
||
251 | * |
||
252 | * @param IDatabase $db |
||
253 | * @param int $pageid |
||
254 | * @param int $id |
||
255 | * @return Revision|null |
||
256 | */ |
||
257 | public static function loadFromPageId( $db, $pageid, $id = 0 ) { |
||
266 | |||
267 | /** |
||
268 | * Load either the current, or a specified, revision |
||
269 | * that's attached to a given page. If not attached |
||
270 | * to that page, will return null. |
||
271 | * |
||
272 | * @param IDatabase $db |
||
273 | * @param Title $title |
||
274 | * @param int $id |
||
275 | * @return Revision|null |
||
276 | */ |
||
277 | public static function loadFromTitle( $db, $title, $id = 0 ) { |
||
291 | |||
292 | /** |
||
293 | * Load the revision for the given title with the given timestamp. |
||
294 | * WARNING: Timestamps may in some circumstances not be unique, |
||
295 | * so this isn't the best key to use. |
||
296 | * |
||
297 | * @param IDatabase $db |
||
298 | * @param Title $title |
||
299 | * @param string $timestamp |
||
300 | * @return Revision|null |
||
301 | */ |
||
302 | public static function loadFromTimestamp( $db, $title, $timestamp ) { |
||
311 | |||
312 | /** |
||
313 | * Given a set of conditions, fetch a revision |
||
314 | * |
||
315 | * This method is used then a revision ID is qualified and |
||
316 | * will incorporate some basic replica DB/master fallback logic |
||
317 | * |
||
318 | * @param array $conditions |
||
319 | * @param int $flags (optional) |
||
320 | * @return Revision|null |
||
321 | */ |
||
322 | private static function newFromConds( $conditions, $flags = 0 ) { |
||
344 | |||
345 | /** |
||
346 | * Given a set of conditions, fetch a revision from |
||
347 | * the given database connection. |
||
348 | * |
||
349 | * @param IDatabase $db |
||
350 | * @param array $conditions |
||
351 | * @param int $flags (optional) |
||
352 | * @return Revision|null |
||
353 | */ |
||
354 | private static function loadFromConds( $db, $conditions, $flags = 0 ) { |
||
365 | |||
366 | /** |
||
367 | * Return a wrapper for a series of database rows to |
||
368 | * fetch all of a given page's revisions in turn. |
||
369 | * Each row can be fed to the constructor to get objects. |
||
370 | * |
||
371 | * @param LinkTarget $title |
||
372 | * @return ResultWrapper |
||
373 | * @deprecated Since 1.28 |
||
374 | */ |
||
375 | public static function fetchRevision( LinkTarget $title ) { |
||
387 | |||
388 | /** |
||
389 | * Given a set of conditions, return a ResultWrapper |
||
390 | * which will return matching database rows with the |
||
391 | * fields necessary to build Revision objects. |
||
392 | * |
||
393 | * @param IDatabase $db |
||
394 | * @param array $conditions |
||
395 | * @param int $flags (optional) |
||
396 | * @return stdClass |
||
397 | */ |
||
398 | private static function fetchFromConds( $db, $conditions, $flags = 0 ) { |
||
417 | |||
418 | /** |
||
419 | * Return the value of a select() JOIN conds array for the user table. |
||
420 | * This will get user table rows for logged-in users. |
||
421 | * @since 1.19 |
||
422 | * @return array |
||
423 | */ |
||
424 | public static function userJoinCond() { |
||
427 | |||
428 | /** |
||
429 | * Return the value of a select() page conds array for the page table. |
||
430 | * This will assure that the revision(s) are not orphaned from live pages. |
||
431 | * @since 1.19 |
||
432 | * @return array |
||
433 | */ |
||
434 | public static function pageJoinCond() { |
||
437 | |||
438 | /** |
||
439 | * Return the list of revision fields that should be selected to create |
||
440 | * a new revision. |
||
441 | * @return array |
||
442 | */ |
||
443 | public static function selectFields() { |
||
468 | |||
469 | /** |
||
470 | * Return the list of revision fields that should be selected to create |
||
471 | * a new revision from an archive row. |
||
472 | * @return array |
||
473 | */ |
||
474 | public static function selectArchiveFields() { |
||
499 | |||
500 | /** |
||
501 | * Return the list of text fields that should be selected to read the |
||
502 | * revision text |
||
503 | * @return array |
||
504 | */ |
||
505 | public static function selectTextFields() { |
||
511 | |||
512 | /** |
||
513 | * Return the list of page fields that should be selected from page table |
||
514 | * @return array |
||
515 | */ |
||
516 | public static function selectPageFields() { |
||
526 | |||
527 | /** |
||
528 | * Return the list of user fields that should be selected from user table |
||
529 | * @return array |
||
530 | */ |
||
531 | public static function selectUserFields() { |
||
534 | |||
535 | /** |
||
536 | * Do a batched query to get the parent revision lengths |
||
537 | * @param IDatabase $db |
||
538 | * @param array $revIds |
||
539 | * @return array |
||
540 | */ |
||
541 | public static function getParentLengths( $db, array $revIds ) { |
||
555 | |||
556 | /** |
||
557 | * Constructor |
||
558 | * |
||
559 | * @param object|array $row Either a database row or an array |
||
560 | * @throws MWException |
||
561 | * @access private |
||
562 | */ |
||
563 | function __construct( $row ) { |
||
724 | |||
725 | /** |
||
726 | * Get revision ID |
||
727 | * |
||
728 | * @return int|null |
||
729 | */ |
||
730 | public function getId() { |
||
733 | |||
734 | /** |
||
735 | * Set the revision ID |
||
736 | * |
||
737 | * This should only be used for proposed revisions that turn out to be null edits |
||
738 | * |
||
739 | * @since 1.19 |
||
740 | * @param int $id |
||
741 | */ |
||
742 | public function setId( $id ) { |
||
745 | |||
746 | /** |
||
747 | * Set the user ID/name |
||
748 | * |
||
749 | * This should only be used for proposed revisions that turn out to be null edits |
||
750 | * |
||
751 | * @since 1.28 |
||
752 | * @param integer $id User ID |
||
753 | * @param string $name User name |
||
754 | */ |
||
755 | public function setUserIdAndName( $id, $name ) { |
||
760 | |||
761 | /** |
||
762 | * Get text row ID |
||
763 | * |
||
764 | * @return int|null |
||
765 | */ |
||
766 | public function getTextId() { |
||
769 | |||
770 | /** |
||
771 | * Get parent revision ID (the original previous page revision) |
||
772 | * |
||
773 | * @return int|null |
||
774 | */ |
||
775 | public function getParentId() { |
||
778 | |||
779 | /** |
||
780 | * Returns the length of the text in this revision, or null if unknown. |
||
781 | * |
||
782 | * @return int|null |
||
783 | */ |
||
784 | public function getSize() { |
||
787 | |||
788 | /** |
||
789 | * Returns the base36 sha1 of the text in this revision, or null if unknown. |
||
790 | * |
||
791 | * @return string|null |
||
792 | */ |
||
793 | public function getSha1() { |
||
796 | |||
797 | /** |
||
798 | * Returns the title of the page associated with this entry or null. |
||
799 | * |
||
800 | * Will do a query, when title is not set and id is given. |
||
801 | * |
||
802 | * @return Title|null |
||
803 | */ |
||
804 | public function getTitle() { |
||
832 | |||
833 | /** |
||
834 | * Set the title of the revision |
||
835 | * |
||
836 | * @param Title $title |
||
837 | */ |
||
838 | public function setTitle( $title ) { |
||
841 | |||
842 | /** |
||
843 | * Get the page ID |
||
844 | * |
||
845 | * @return int|null |
||
846 | */ |
||
847 | public function getPage() { |
||
850 | |||
851 | /** |
||
852 | * Fetch revision's user id if it's available to the specified audience. |
||
853 | * If the specified audience does not have access to it, zero will be |
||
854 | * returned. |
||
855 | * |
||
856 | * @param int $audience One of: |
||
857 | * Revision::FOR_PUBLIC to be displayed to all users |
||
858 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
859 | * Revision::RAW get the ID regardless of permissions |
||
860 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
861 | * to the $audience parameter |
||
862 | * @return int |
||
863 | */ |
||
864 | View Code Duplication | public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) { |
|
873 | |||
874 | /** |
||
875 | * Fetch revision's user id without regard for the current user's permissions |
||
876 | * |
||
877 | * @return string |
||
878 | * @deprecated since 1.25, use getUser( Revision::RAW ) |
||
879 | */ |
||
880 | public function getRawUser() { |
||
884 | |||
885 | /** |
||
886 | * Fetch revision's username if it's available to the specified audience. |
||
887 | * If the specified audience does not have access to the username, an |
||
888 | * empty string will be returned. |
||
889 | * |
||
890 | * @param int $audience One of: |
||
891 | * Revision::FOR_PUBLIC to be displayed to all users |
||
892 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
893 | * Revision::RAW get the text regardless of permissions |
||
894 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
895 | * to the $audience parameter |
||
896 | * @return string |
||
897 | */ |
||
898 | public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
917 | |||
918 | /** |
||
919 | * Fetch revision's username without regard for view restrictions |
||
920 | * |
||
921 | * @return string |
||
922 | * @deprecated since 1.25, use getUserText( Revision::RAW ) |
||
923 | */ |
||
924 | public function getRawUserText() { |
||
928 | |||
929 | /** |
||
930 | * Fetch revision comment if it's available to the specified audience. |
||
931 | * If the specified audience does not have access to the comment, an |
||
932 | * empty string will be returned. |
||
933 | * |
||
934 | * @param int $audience One of: |
||
935 | * Revision::FOR_PUBLIC to be displayed to all users |
||
936 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
937 | * Revision::RAW get the text regardless of permissions |
||
938 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
939 | * to the $audience parameter |
||
940 | * @return string |
||
941 | */ |
||
942 | View Code Duplication | function getComment( $audience = self::FOR_PUBLIC, User $user = null ) { |
|
951 | |||
952 | /** |
||
953 | * Fetch revision comment without regard for the current user's permissions |
||
954 | * |
||
955 | * @return string |
||
956 | * @deprecated since 1.25, use getComment( Revision::RAW ) |
||
957 | */ |
||
958 | public function getRawComment() { |
||
962 | |||
963 | /** |
||
964 | * @return bool |
||
965 | */ |
||
966 | public function isMinor() { |
||
969 | |||
970 | /** |
||
971 | * @return int Rcid of the unpatrolled row, zero if there isn't one |
||
972 | */ |
||
973 | public function isUnpatrolled() { |
||
985 | |||
986 | /** |
||
987 | * Get the RC object belonging to the current revision, if there's one |
||
988 | * |
||
989 | * @param int $flags (optional) $flags include: |
||
990 | * Revision::READ_LATEST : Select the data from the master |
||
991 | * |
||
992 | * @since 1.22 |
||
993 | * @return RecentChange|null |
||
994 | */ |
||
995 | public function getRecentChange( $flags = 0 ) { |
||
1010 | |||
1011 | /** |
||
1012 | * @param int $field One of DELETED_* bitfield constants |
||
1013 | * |
||
1014 | * @return bool |
||
1015 | */ |
||
1016 | public function isDeleted( $field ) { |
||
1026 | |||
1027 | /** |
||
1028 | * Get the deletion bitfield of the revision |
||
1029 | * |
||
1030 | * @return int |
||
1031 | */ |
||
1032 | public function getVisibility() { |
||
1037 | |||
1038 | /** |
||
1039 | * Fetch revision text if it's available to the specified audience. |
||
1040 | * If the specified audience does not have the ability to view this |
||
1041 | * revision, an empty string will be returned. |
||
1042 | * |
||
1043 | * @param int $audience One of: |
||
1044 | * Revision::FOR_PUBLIC to be displayed to all users |
||
1045 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
1046 | * Revision::RAW get the text regardless of permissions |
||
1047 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
1048 | * to the $audience parameter |
||
1049 | * |
||
1050 | * @deprecated since 1.21, use getContent() instead |
||
1051 | * @return string |
||
1052 | */ |
||
1053 | public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
1059 | |||
1060 | /** |
||
1061 | * Fetch revision content if it's available to the specified audience. |
||
1062 | * If the specified audience does not have the ability to view this |
||
1063 | * revision, null will be returned. |
||
1064 | * |
||
1065 | * @param int $audience One of: |
||
1066 | * Revision::FOR_PUBLIC to be displayed to all users |
||
1067 | * Revision::FOR_THIS_USER to be displayed to $wgUser |
||
1068 | * Revision::RAW get the text regardless of permissions |
||
1069 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
1070 | * to the $audience parameter |
||
1071 | * @since 1.21 |
||
1072 | * @return Content|null |
||
1073 | */ |
||
1074 | public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
1083 | |||
1084 | /** |
||
1085 | * Get original serialized data (without checking view restrictions) |
||
1086 | * |
||
1087 | * @since 1.21 |
||
1088 | * @return string |
||
1089 | */ |
||
1090 | public function getSerializedData() { |
||
1098 | |||
1099 | /** |
||
1100 | * Gets the content object for the revision (or null on failure). |
||
1101 | * |
||
1102 | * Note that for mutable Content objects, each call to this method will return a |
||
1103 | * fresh clone. |
||
1104 | * |
||
1105 | * @since 1.21 |
||
1106 | * @return Content|null The Revision's content, or null on failure. |
||
1107 | */ |
||
1108 | protected function getContentInternal() { |
||
1124 | |||
1125 | /** |
||
1126 | * Returns the content model for this revision. |
||
1127 | * |
||
1128 | * If no content model was stored in the database, the default content model for the title is |
||
1129 | * used to determine the content model to use. If no title is know, CONTENT_MODEL_WIKITEXT |
||
1130 | * is used as a last resort. |
||
1131 | * |
||
1132 | * @return string The content model id associated with this revision, |
||
1133 | * see the CONTENT_MODEL_XXX constants. |
||
1134 | **/ |
||
1135 | public function getContentModel() { |
||
1149 | |||
1150 | /** |
||
1151 | * Returns the content format for this revision. |
||
1152 | * |
||
1153 | * If no content format was stored in the database, the default format for this |
||
1154 | * revision's content model is returned. |
||
1155 | * |
||
1156 | * @return string The content format id associated with this revision, |
||
1157 | * see the CONTENT_FORMAT_XXX constants. |
||
1158 | **/ |
||
1159 | public function getContentFormat() { |
||
1169 | |||
1170 | /** |
||
1171 | * Returns the content handler appropriate for this revision's content model. |
||
1172 | * |
||
1173 | * @throws MWException |
||
1174 | * @return ContentHandler |
||
1175 | */ |
||
1176 | public function getContentHandler() { |
||
1191 | |||
1192 | /** |
||
1193 | * @return string |
||
1194 | */ |
||
1195 | public function getTimestamp() { |
||
1198 | |||
1199 | /** |
||
1200 | * @return bool |
||
1201 | */ |
||
1202 | public function isCurrent() { |
||
1205 | |||
1206 | /** |
||
1207 | * Get previous revision for this title |
||
1208 | * |
||
1209 | * @return Revision|null |
||
1210 | */ |
||
1211 | View Code Duplication | public function getPrevious() { |
|
1220 | |||
1221 | /** |
||
1222 | * Get next revision for this title |
||
1223 | * |
||
1224 | * @return Revision|null |
||
1225 | */ |
||
1226 | View Code Duplication | public function getNext() { |
|
1235 | |||
1236 | /** |
||
1237 | * Get previous revision Id for this page_id |
||
1238 | * This is used to populate rev_parent_id on save |
||
1239 | * |
||
1240 | * @param IDatabase $db |
||
1241 | * @return int |
||
1242 | */ |
||
1243 | private function getPreviousRevisionId( $db ) { |
||
1260 | |||
1261 | /** |
||
1262 | * Get revision text associated with an old or archive row |
||
1263 | * $row is usually an object from wfFetchRow(), both the flags and the text |
||
1264 | * field must be included. |
||
1265 | * |
||
1266 | * @param stdClass $row The text data |
||
1267 | * @param string $prefix Table prefix (default 'old_') |
||
1268 | * @param string|bool $wiki The name of the wiki to load the revision text from |
||
1269 | * (same as the the wiki $row was loaded from) or false to indicate the local |
||
1270 | * wiki (this is the default). Otherwise, it must be a symbolic wiki database |
||
1271 | * identifier as understood by the LoadBalancer class. |
||
1272 | * @return string Text the text requested or false on failure |
||
1273 | */ |
||
1274 | public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) { |
||
1308 | |||
1309 | /** |
||
1310 | * If $wgCompressRevisions is enabled, we will compress data. |
||
1311 | * The input string is modified in place. |
||
1312 | * Return value is the flags field: contains 'gzip' if the |
||
1313 | * data is compressed, and 'utf-8' if we're saving in UTF-8 |
||
1314 | * mode. |
||
1315 | * |
||
1316 | * @param mixed $text Reference to a text |
||
1317 | * @return string |
||
1318 | */ |
||
1319 | public static function compressRevisionText( &$text ) { |
||
1343 | |||
1344 | /** |
||
1345 | * Re-converts revision text according to it's flags. |
||
1346 | * |
||
1347 | * @param mixed $text Reference to a text |
||
1348 | * @param array $flags Compression flags |
||
1349 | * @return string|bool Decompressed text, or false on failure |
||
1350 | */ |
||
1351 | public static function decompressRevisionText( $text, $flags ) { |
||
1388 | |||
1389 | /** |
||
1390 | * Insert a new revision into the database, returning the new revision ID |
||
1391 | * number on success and dies horribly on failure. |
||
1392 | * |
||
1393 | * @param IDatabase $dbw (master connection) |
||
1394 | * @throws MWException |
||
1395 | * @return int |
||
1396 | */ |
||
1397 | public function insertOn( $dbw ) { |
||
1512 | |||
1513 | protected function checkContentModel() { |
||
1569 | |||
1570 | /** |
||
1571 | * Get the base 36 SHA-1 value for a string of text |
||
1572 | * @param string $text |
||
1573 | * @return string |
||
1574 | */ |
||
1575 | public static function base36Sha1( $text ) { |
||
1578 | |||
1579 | /** |
||
1580 | * Lazy-load the revision's text. |
||
1581 | * Currently hardcoded to the 'text' table storage engine. |
||
1582 | * |
||
1583 | * @return string|bool The revision's text, or false on failure |
||
1584 | */ |
||
1585 | private function loadText() { |
||
1606 | |||
1607 | private function fetchText() { |
||
1663 | |||
1664 | /** |
||
1665 | * Create a new null-revision for insertion into a page's |
||
1666 | * history. This will not re-save the text, but simply refer |
||
1667 | * to the text from the previous version. |
||
1668 | * |
||
1669 | * Such revisions can for instance identify page rename |
||
1670 | * operations and other such meta-modifications. |
||
1671 | * |
||
1672 | * @param IDatabase $dbw |
||
1673 | * @param int $pageId ID number of the page to read from |
||
1674 | * @param string $summary Revision's summary |
||
1675 | * @param bool $minor Whether the revision should be considered as minor |
||
1676 | * @param User|null $user User object to use or null for $wgUser |
||
1677 | * @return Revision|null Revision or null on error |
||
1678 | */ |
||
1679 | public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) { |
||
1736 | |||
1737 | /** |
||
1738 | * Determine if the current user is allowed to view a particular |
||
1739 | * field of this revision, if it's marked as deleted. |
||
1740 | * |
||
1741 | * @param int $field One of self::DELETED_TEXT, |
||
1742 | * self::DELETED_COMMENT, |
||
1743 | * self::DELETED_USER |
||
1744 | * @param User|null $user User object to check, or null to use $wgUser |
||
1745 | * @return bool |
||
1746 | */ |
||
1747 | public function userCan( $field, User $user = null ) { |
||
1750 | |||
1751 | /** |
||
1752 | * Determine if the current user is allowed to view a particular |
||
1753 | * field of this revision, if it's marked as deleted. This is used |
||
1754 | * by various classes to avoid duplication. |
||
1755 | * |
||
1756 | * @param int $bitfield Current field |
||
1757 | * @param int $field One of self::DELETED_TEXT = File::DELETED_FILE, |
||
1758 | * self::DELETED_COMMENT = File::DELETED_COMMENT, |
||
1759 | * self::DELETED_USER = File::DELETED_USER |
||
1760 | * @param User|null $user User object to check, or null to use $wgUser |
||
1761 | * @param Title|null $title A Title object to check for per-page restrictions on, |
||
1762 | * instead of just plain userrights |
||
1763 | * @return bool |
||
1764 | */ |
||
1765 | public static function userCanBitfield( $bitfield, $field, User $user = null, |
||
1798 | |||
1799 | /** |
||
1800 | * Get rev_timestamp from rev_id, without loading the rest of the row |
||
1801 | * |
||
1802 | * @param Title $title |
||
1803 | * @param int $id |
||
1804 | * @return string|bool False if not found |
||
1805 | */ |
||
1806 | static function getTimestampFromId( $title, $id, $flags = 0 ) { |
||
1820 | |||
1821 | /** |
||
1822 | * Get count of revisions per page...not very efficient |
||
1823 | * |
||
1824 | * @param IDatabase $db |
||
1825 | * @param int $id Page id |
||
1826 | * @return int |
||
1827 | */ |
||
1828 | static function countByPageId( $db, $id ) { |
||
1836 | |||
1837 | /** |
||
1838 | * Get count of revisions per page...not very efficient |
||
1839 | * |
||
1840 | * @param IDatabase $db |
||
1841 | * @param Title $title |
||
1842 | * @return int |
||
1843 | */ |
||
1844 | static function countByTitle( $db, $title ) { |
||
1851 | |||
1852 | /** |
||
1853 | * Check if no edits were made by other users since |
||
1854 | * the time a user started editing the page. Limit to |
||
1855 | * 50 revisions for the sake of performance. |
||
1856 | * |
||
1857 | * @since 1.20 |
||
1858 | * @deprecated since 1.24 |
||
1859 | * |
||
1860 | * @param IDatabase|int $db The Database to perform the check on. May be given as a |
||
1861 | * Database object or a database identifier usable with wfGetDB. |
||
1862 | * @param int $pageId The ID of the page in question |
||
1863 | * @param int $userId The ID of the user in question |
||
1864 | * @param string $since Look at edits since this time |
||
1865 | * |
||
1866 | * @return bool True if the given user was the only one to edit since the given timestamp |
||
1867 | */ |
||
1868 | public static function userWasLastToEdit( $db, $pageId, $userId, $since ) { |
||
1892 | |||
1893 | /** |
||
1894 | * Load a revision based on a known page ID and current revision ID from the DB |
||
1895 | * |
||
1896 | * This method allows for the use of caching, though accessing anything that normally |
||
1897 | * requires permission checks (aside from the text) will trigger a small DB lookup. |
||
1898 | * The title will also be lazy loaded, though setTitle() can be used to preload it. |
||
1899 | * |
||
1900 | * @param IDatabase $db |
||
1901 | * @param int $pageId Page ID |
||
1902 | * @param int $revId Known current revision of this page |
||
1903 | * @return Revision|bool Returns false if missing |
||
1904 | * @since 1.28 |
||
1905 | */ |
||
1906 | public static function newKnownCurrent( IDatabase $db, $pageId, $revId ) { |
||
1926 | |||
1927 | /** |
||
1928 | * For cached revisions, make sure the user name and rev_deleted is up-to-date |
||
1929 | */ |
||
1930 | private function loadMutableFields() { |
||
1948 | } |
||
1949 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: