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 |
||
| 27 | class Revision implements IDBAccessObject { |
||
| 28 | protected $mId; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var int|null |
||
| 32 | */ |
||
| 33 | protected $mPage; |
||
| 34 | protected $mUserText; |
||
| 35 | protected $mOrigUserText; |
||
| 36 | protected $mUser; |
||
| 37 | protected $mMinorEdit; |
||
| 38 | protected $mTimestamp; |
||
| 39 | protected $mDeleted; |
||
| 40 | protected $mSize; |
||
| 41 | protected $mSha1; |
||
| 42 | protected $mParentId; |
||
| 43 | protected $mComment; |
||
| 44 | protected $mText; |
||
| 45 | protected $mTextId; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var stdClass|null |
||
| 49 | */ |
||
| 50 | protected $mTextRow; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var null|Title |
||
| 54 | */ |
||
| 55 | protected $mTitle; |
||
| 56 | protected $mCurrent; |
||
| 57 | protected $mContentModel; |
||
| 58 | protected $mContentFormat; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var Content|null|bool |
||
| 62 | */ |
||
| 63 | protected $mContent; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var null|ContentHandler |
||
| 67 | */ |
||
| 68 | protected $mContentHandler; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var int |
||
| 72 | */ |
||
| 73 | protected $mQueryFlags = 0; |
||
| 74 | |||
| 75 | // Revision deletion constants |
||
| 76 | const DELETED_TEXT = 1; |
||
| 77 | const DELETED_COMMENT = 2; |
||
| 78 | const DELETED_USER = 4; |
||
| 79 | const DELETED_RESTRICTED = 8; |
||
| 80 | const SUPPRESSED_USER = 12; // convenience |
||
| 81 | |||
| 82 | // Audience options for accessors |
||
| 83 | const FOR_PUBLIC = 1; |
||
| 84 | const FOR_THIS_USER = 2; |
||
| 85 | const RAW = 3; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Load a page revision from a given revision ID number. |
||
| 89 | * Returns null if no such revision can be found. |
||
| 90 | * |
||
| 91 | * $flags include: |
||
| 92 | * Revision::READ_LATEST : Select the data from the master |
||
| 93 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
| 94 | * |
||
| 95 | * @param int $id |
||
| 96 | * @param int $flags (optional) |
||
| 97 | * @return Revision|null |
||
| 98 | */ |
||
| 99 | public static function newFromId( $id, $flags = 0 ) { |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Load either the current, or a specified, revision |
||
| 105 | * that's attached to a given link target. If not attached |
||
| 106 | * to that link target, will return null. |
||
| 107 | * |
||
| 108 | * $flags include: |
||
| 109 | * Revision::READ_LATEST : Select the data from the master |
||
| 110 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
| 111 | * |
||
| 112 | * @param LinkTarget $linkTarget |
||
| 113 | * @param int $id (optional) |
||
| 114 | * @param int $flags Bitfield (optional) |
||
| 115 | * @return Revision|null |
||
| 116 | */ |
||
| 117 | View Code Duplication | public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) { |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Load either the current, or a specified, revision |
||
| 136 | * that's attached to a given page ID. |
||
| 137 | * Returns null if no such revision can be found. |
||
| 138 | * |
||
| 139 | * $flags include: |
||
| 140 | * Revision::READ_LATEST : Select the data from the master (since 1.20) |
||
| 141 | * Revision::READ_LOCKING : Select & lock the data from the master |
||
| 142 | * |
||
| 143 | * @param int $pageId |
||
| 144 | * @param int $revId (optional) |
||
| 145 | * @param int $flags Bitfield (optional) |
||
| 146 | * @return Revision|null |
||
| 147 | */ |
||
| 148 | View Code Duplication | public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) { |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Make a fake revision object from an archive table row. This is queried |
||
| 163 | * for permissions or even inserted (as in Special:Undelete) |
||
| 164 | * @todo FIXME: Should be a subclass for RevisionDelete. [TS] |
||
| 165 | * |
||
| 166 | * @param object $row |
||
| 167 | * @param array $overrides |
||
| 168 | * |
||
| 169 | * @throws MWException |
||
| 170 | * @return Revision |
||
| 171 | */ |
||
| 172 | public static function newFromArchiveRow( $row, $overrides = [] ) { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @since 1.19 |
||
| 215 | * |
||
| 216 | * @param object $row |
||
| 217 | * @return Revision |
||
| 218 | */ |
||
| 219 | public static function newFromRow( $row ) { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Load a page revision from a given revision ID number. |
||
| 225 | * Returns null if no such revision can be found. |
||
| 226 | * |
||
| 227 | * @param IDatabase $db |
||
| 228 | * @param int $id |
||
| 229 | * @return Revision|null |
||
| 230 | */ |
||
| 231 | public static function loadFromId( $db, $id ) { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Load either the current, or a specified, revision |
||
| 237 | * that's attached to a given page. If not attached |
||
| 238 | * to that page, will return null. |
||
| 239 | * |
||
| 240 | * @param IDatabase $db |
||
| 241 | * @param int $pageid |
||
| 242 | * @param int $id |
||
| 243 | * @return Revision|null |
||
| 244 | */ |
||
| 245 | public static function loadFromPageId( $db, $pageid, $id = 0 ) { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Load either the current, or a specified, revision |
||
| 257 | * that's attached to a given page. If not attached |
||
| 258 | * to that page, will return null. |
||
| 259 | * |
||
| 260 | * @param IDatabase $db |
||
| 261 | * @param Title $title |
||
| 262 | * @param int $id |
||
| 263 | * @return Revision|null |
||
| 264 | */ |
||
| 265 | public static function loadFromTitle( $db, $title, $id = 0 ) { |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Load the revision for the given title with the given timestamp. |
||
| 282 | * WARNING: Timestamps may in some circumstances not be unique, |
||
| 283 | * so this isn't the best key to use. |
||
| 284 | * |
||
| 285 | * @param IDatabase $db |
||
| 286 | * @param Title $title |
||
| 287 | * @param string $timestamp |
||
| 288 | * @return Revision|null |
||
| 289 | */ |
||
| 290 | public static function loadFromTimestamp( $db, $title, $timestamp ) { |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Given a set of conditions, fetch a revision |
||
| 302 | * |
||
| 303 | * This method is used then a revision ID is qualified and |
||
| 304 | * will incorporate some basic slave/master fallback logic |
||
| 305 | * |
||
| 306 | * @param array $conditions |
||
| 307 | * @param int $flags (optional) |
||
| 308 | * @return Revision|null |
||
| 309 | */ |
||
| 310 | private static function newFromConds( $conditions, $flags = 0 ) { |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Given a set of conditions, fetch a revision from |
||
| 335 | * the given database connection. |
||
| 336 | * |
||
| 337 | * @param IDatabase $db |
||
| 338 | * @param array $conditions |
||
| 339 | * @param int $flags (optional) |
||
| 340 | * @return Revision|null |
||
| 341 | */ |
||
| 342 | private static function loadFromConds( $db, $conditions, $flags = 0 ) { |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Return a wrapper for a series of database rows to |
||
| 357 | * fetch all of a given page's revisions in turn. |
||
| 358 | * Each row can be fed to the constructor to get objects. |
||
| 359 | * |
||
| 360 | * @param Title $title |
||
| 361 | * @return ResultWrapper |
||
| 362 | */ |
||
| 363 | public static function fetchRevision( $title ) { |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Given a set of conditions, return a ResultWrapper |
||
| 376 | * which will return matching database rows with the |
||
| 377 | * fields necessary to build Revision objects. |
||
| 378 | * |
||
| 379 | * @param IDatabase $db |
||
| 380 | * @param array $conditions |
||
| 381 | * @param int $flags (optional) |
||
| 382 | * @return ResultWrapper |
||
| 383 | */ |
||
| 384 | private static function fetchFromConds( $db, $conditions, $flags = 0 ) { |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Return the value of a select() JOIN conds array for the user table. |
||
| 406 | * This will get user table rows for logged-in users. |
||
| 407 | * @since 1.19 |
||
| 408 | * @return array |
||
| 409 | */ |
||
| 410 | public static function userJoinCond() { |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Return the value of a select() page conds array for the page table. |
||
| 416 | * This will assure that the revision(s) are not orphaned from live pages. |
||
| 417 | * @since 1.19 |
||
| 418 | * @return array |
||
| 419 | */ |
||
| 420 | public static function pageJoinCond() { |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Return the list of revision fields that should be selected to create |
||
| 426 | * a new revision. |
||
| 427 | * @return array |
||
| 428 | */ |
||
| 429 | public static function selectFields() { |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Return the list of revision fields that should be selected to create |
||
| 457 | * a new revision from an archive row. |
||
| 458 | * @return array |
||
| 459 | */ |
||
| 460 | public static function selectArchiveFields() { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Return the list of text fields that should be selected to read the |
||
| 488 | * revision text |
||
| 489 | * @return array |
||
| 490 | */ |
||
| 491 | public static function selectTextFields() { |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Return the list of page fields that should be selected from page table |
||
| 500 | * @return array |
||
| 501 | */ |
||
| 502 | public static function selectPageFields() { |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Return the list of user fields that should be selected from user table |
||
| 515 | * @return array |
||
| 516 | */ |
||
| 517 | public static function selectUserFields() { |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Do a batched query to get the parent revision lengths |
||
| 523 | * @param IDatabase $db |
||
| 524 | * @param array $revIds |
||
| 525 | * @return array |
||
| 526 | */ |
||
| 527 | public static function getParentLengths( $db, array $revIds ) { |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Constructor |
||
| 544 | * |
||
| 545 | * @param object|array $row Either a database row or an array |
||
| 546 | * @throws MWException |
||
| 547 | * @access private |
||
| 548 | */ |
||
| 549 | function __construct( $row ) { |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Get revision ID |
||
| 713 | * |
||
| 714 | * @return int|null |
||
| 715 | */ |
||
| 716 | public function getId() { |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Set the revision ID |
||
| 722 | * |
||
| 723 | * @since 1.19 |
||
| 724 | * @param int $id |
||
| 725 | */ |
||
| 726 | public function setId( $id ) { |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Get text row ID |
||
| 732 | * |
||
| 733 | * @return int|null |
||
| 734 | */ |
||
| 735 | public function getTextId() { |
||
| 738 | |||
| 739 | /** |
||
| 740 | * Get parent revision ID (the original previous page revision) |
||
| 741 | * |
||
| 742 | * @return int|null |
||
| 743 | */ |
||
| 744 | public function getParentId() { |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Returns the length of the text in this revision, or null if unknown. |
||
| 750 | * |
||
| 751 | * @return int|null |
||
| 752 | */ |
||
| 753 | public function getSize() { |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Returns the base36 sha1 of the text in this revision, or null if unknown. |
||
| 759 | * |
||
| 760 | * @return string|null |
||
| 761 | */ |
||
| 762 | public function getSha1() { |
||
| 765 | |||
| 766 | /** |
||
| 767 | * Returns the title of the page associated with this entry or null. |
||
| 768 | * |
||
| 769 | * Will do a query, when title is not set and id is given. |
||
| 770 | * |
||
| 771 | * @return Title|null |
||
| 772 | */ |
||
| 773 | public function getTitle() { |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Set the title of the revision |
||
| 800 | * |
||
| 801 | * @param Title $title |
||
| 802 | */ |
||
| 803 | public function setTitle( $title ) { |
||
| 806 | |||
| 807 | /** |
||
| 808 | * Get the page ID |
||
| 809 | * |
||
| 810 | * @return int|null |
||
| 811 | */ |
||
| 812 | public function getPage() { |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Fetch revision's user id if it's available to the specified audience. |
||
| 818 | * If the specified audience does not have access to it, zero will be |
||
| 819 | * returned. |
||
| 820 | * |
||
| 821 | * @param int $audience One of: |
||
| 822 | * Revision::FOR_PUBLIC to be displayed to all users |
||
| 823 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
| 824 | * Revision::RAW get the ID regardless of permissions |
||
| 825 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
| 826 | * to the $audience parameter |
||
| 827 | * @return int |
||
| 828 | */ |
||
| 829 | View Code Duplication | public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) { |
|
| 838 | |||
| 839 | /** |
||
| 840 | * Fetch revision's user id without regard for the current user's permissions |
||
| 841 | * |
||
| 842 | * @return string |
||
| 843 | * @deprecated since 1.25, use getUser( Revision::RAW ) |
||
| 844 | */ |
||
| 845 | public function getRawUser() { |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Fetch revision's username if it's available to the specified audience. |
||
| 852 | * If the specified audience does not have access to the username, an |
||
| 853 | * empty string will be returned. |
||
| 854 | * |
||
| 855 | * @param int $audience One of: |
||
| 856 | * Revision::FOR_PUBLIC to be displayed to all users |
||
| 857 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
| 858 | * Revision::RAW get the text regardless of permissions |
||
| 859 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
| 860 | * to the $audience parameter |
||
| 861 | * @return string |
||
| 862 | */ |
||
| 863 | public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
| 880 | |||
| 881 | /** |
||
| 882 | * Fetch revision's username without regard for view restrictions |
||
| 883 | * |
||
| 884 | * @return string |
||
| 885 | * @deprecated since 1.25, use getUserText( Revision::RAW ) |
||
| 886 | */ |
||
| 887 | public function getRawUserText() { |
||
| 891 | |||
| 892 | /** |
||
| 893 | * Fetch revision comment if it's available to the specified audience. |
||
| 894 | * If the specified audience does not have access to the comment, an |
||
| 895 | * empty string will be returned. |
||
| 896 | * |
||
| 897 | * @param int $audience One of: |
||
| 898 | * Revision::FOR_PUBLIC to be displayed to all users |
||
| 899 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
| 900 | * Revision::RAW get the text regardless of permissions |
||
| 901 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
| 902 | * to the $audience parameter |
||
| 903 | * @return string |
||
| 904 | */ |
||
| 905 | View Code Duplication | function getComment( $audience = self::FOR_PUBLIC, User $user = null ) { |
|
| 914 | |||
| 915 | /** |
||
| 916 | * Fetch revision comment without regard for the current user's permissions |
||
| 917 | * |
||
| 918 | * @return string |
||
| 919 | * @deprecated since 1.25, use getComment( Revision::RAW ) |
||
| 920 | */ |
||
| 921 | public function getRawComment() { |
||
| 925 | |||
| 926 | /** |
||
| 927 | * @return bool |
||
| 928 | */ |
||
| 929 | public function isMinor() { |
||
| 932 | |||
| 933 | /** |
||
| 934 | * @return int Rcid of the unpatrolled row, zero if there isn't one |
||
| 935 | */ |
||
| 936 | public function isUnpatrolled() { |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Get the RC object belonging to the current revision, if there's one |
||
| 951 | * |
||
| 952 | * @param int $flags (optional) $flags include: |
||
| 953 | * Revision::READ_LATEST : Select the data from the master |
||
| 954 | * |
||
| 955 | * @since 1.22 |
||
| 956 | * @return RecentChange|null |
||
| 957 | */ |
||
| 958 | public function getRecentChange( $flags = 0 ) { |
||
| 973 | |||
| 974 | /** |
||
| 975 | * @param int $field One of DELETED_* bitfield constants |
||
| 976 | * |
||
| 977 | * @return bool |
||
| 978 | */ |
||
| 979 | public function isDeleted( $field ) { |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Get the deletion bitfield of the revision |
||
| 985 | * |
||
| 986 | * @return int |
||
| 987 | */ |
||
| 988 | public function getVisibility() { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Fetch revision text if it's available to the specified audience. |
||
| 994 | * If the specified audience does not have the ability to view this |
||
| 995 | * revision, an empty string will be returned. |
||
| 996 | * |
||
| 997 | * @param int $audience One of: |
||
| 998 | * Revision::FOR_PUBLIC to be displayed to all users |
||
| 999 | * Revision::FOR_THIS_USER to be displayed to the given user |
||
| 1000 | * Revision::RAW get the text regardless of permissions |
||
| 1001 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
| 1002 | * to the $audience parameter |
||
| 1003 | * |
||
| 1004 | * @deprecated since 1.21, use getContent() instead |
||
| 1005 | * @todo Replace usage in core |
||
| 1006 | * @return string |
||
| 1007 | */ |
||
| 1008 | public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Fetch revision content if it's available to the specified audience. |
||
| 1017 | * If the specified audience does not have the ability to view this |
||
| 1018 | * revision, null will be returned. |
||
| 1019 | * |
||
| 1020 | * @param int $audience One of: |
||
| 1021 | * Revision::FOR_PUBLIC to be displayed to all users |
||
| 1022 | * Revision::FOR_THIS_USER to be displayed to $wgUser |
||
| 1023 | * Revision::RAW get the text regardless of permissions |
||
| 1024 | * @param User $user User object to check for, only if FOR_THIS_USER is passed |
||
| 1025 | * to the $audience parameter |
||
| 1026 | * @since 1.21 |
||
| 1027 | * @return Content|null |
||
| 1028 | */ |
||
| 1029 | public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) { |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Fetch original serialized data without regard for view restrictions |
||
| 1041 | * |
||
| 1042 | * @since 1.21 |
||
| 1043 | * @return string |
||
| 1044 | */ |
||
| 1045 | public function getSerializedData() { |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * Gets the content object for the revision (or null on failure). |
||
| 1055 | * |
||
| 1056 | * Note that for mutable Content objects, each call to this method will return a |
||
| 1057 | * fresh clone. |
||
| 1058 | * |
||
| 1059 | * @since 1.21 |
||
| 1060 | * @return Content|null The Revision's content, or null on failure. |
||
| 1061 | */ |
||
| 1062 | protected function getContentInternal() { |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Returns the content model for this revision. |
||
| 1084 | * |
||
| 1085 | * If no content model was stored in the database, the default content model for the title is |
||
| 1086 | * used to determine the content model to use. If no title is know, CONTENT_MODEL_WIKITEXT |
||
| 1087 | * is used as a last resort. |
||
| 1088 | * |
||
| 1089 | * @return string The content model id associated with this revision, |
||
| 1090 | * see the CONTENT_MODEL_XXX constants. |
||
| 1091 | **/ |
||
| 1092 | public function getContentModel() { |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Returns the content format for this revision. |
||
| 1109 | * |
||
| 1110 | * If no content format was stored in the database, the default format for this |
||
| 1111 | * revision's content model is returned. |
||
| 1112 | * |
||
| 1113 | * @return string The content format id associated with this revision, |
||
| 1114 | * see the CONTENT_FORMAT_XXX constants. |
||
| 1115 | **/ |
||
| 1116 | public function getContentFormat() { |
||
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Returns the content handler appropriate for this revision's content model. |
||
| 1129 | * |
||
| 1130 | * @throws MWException |
||
| 1131 | * @return ContentHandler |
||
| 1132 | */ |
||
| 1133 | public function getContentHandler() { |
||
| 1148 | |||
| 1149 | /** |
||
| 1150 | * @return string |
||
| 1151 | */ |
||
| 1152 | public function getTimestamp() { |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * @return bool |
||
| 1158 | */ |
||
| 1159 | public function isCurrent() { |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Get previous revision for this title |
||
| 1165 | * |
||
| 1166 | * @return Revision|null |
||
| 1167 | */ |
||
| 1168 | View Code Duplication | public function getPrevious() { |
|
| 1177 | |||
| 1178 | /** |
||
| 1179 | * Get next revision for this title |
||
| 1180 | * |
||
| 1181 | * @return Revision|null |
||
| 1182 | */ |
||
| 1183 | View Code Duplication | public function getNext() { |
|
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Get previous revision Id for this page_id |
||
| 1195 | * This is used to populate rev_parent_id on save |
||
| 1196 | * |
||
| 1197 | * @param IDatabase $db |
||
| 1198 | * @return int |
||
| 1199 | */ |
||
| 1200 | private function getPreviousRevisionId( $db ) { |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Get revision text associated with an old or archive row |
||
| 1220 | * $row is usually an object from wfFetchRow(), both the flags and the text |
||
| 1221 | * field must be included. |
||
| 1222 | * |
||
| 1223 | * @param stdClass $row The text data |
||
| 1224 | * @param string $prefix Table prefix (default 'old_') |
||
| 1225 | * @param string|bool $wiki The name of the wiki to load the revision text from |
||
| 1226 | * (same as the the wiki $row was loaded from) or false to indicate the local |
||
| 1227 | * wiki (this is the default). Otherwise, it must be a symbolic wiki database |
||
| 1228 | * identifier as understood by the LoadBalancer class. |
||
| 1229 | * @return string Text the text requested or false on failure |
||
| 1230 | */ |
||
| 1231 | public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) { |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * If $wgCompressRevisions is enabled, we will compress data. |
||
| 1268 | * The input string is modified in place. |
||
| 1269 | * Return value is the flags field: contains 'gzip' if the |
||
| 1270 | * data is compressed, and 'utf-8' if we're saving in UTF-8 |
||
| 1271 | * mode. |
||
| 1272 | * |
||
| 1273 | * @param mixed $text Reference to a text |
||
| 1274 | * @return string |
||
| 1275 | */ |
||
| 1276 | public static function compressRevisionText( &$text ) { |
||
| 1300 | |||
| 1301 | /** |
||
| 1302 | * Re-converts revision text according to it's flags. |
||
| 1303 | * |
||
| 1304 | * @param mixed $text Reference to a text |
||
| 1305 | * @param array $flags Compression flags |
||
| 1306 | * @return string|bool Decompressed text, or false on failure |
||
| 1307 | */ |
||
| 1308 | public static function decompressRevisionText( $text, $flags ) { |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * Insert a new revision into the database, returning the new revision ID |
||
| 1348 | * number on success and dies horribly on failure. |
||
| 1349 | * |
||
| 1350 | * @param IDatabase $dbw (master connection) |
||
| 1351 | * @throws MWException |
||
| 1352 | * @return int |
||
| 1353 | */ |
||
| 1354 | public function insertOn( $dbw ) { |
||
| 1464 | |||
| 1465 | protected function checkContentModel() { |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Get the base 36 SHA-1 value for a string of text |
||
| 1524 | * @param string $text |
||
| 1525 | * @return string |
||
| 1526 | */ |
||
| 1527 | public static function base36Sha1( $text ) { |
||
| 1530 | |||
| 1531 | /** |
||
| 1532 | * Lazy-load the revision's text. |
||
| 1533 | * Currently hardcoded to the 'text' table storage engine. |
||
| 1534 | * |
||
| 1535 | * @return string|bool The revision's text, or false on failure |
||
| 1536 | */ |
||
| 1537 | protected function loadText() { |
||
| 1607 | |||
| 1608 | /** |
||
| 1609 | * Create a new null-revision for insertion into a page's |
||
| 1610 | * history. This will not re-save the text, but simply refer |
||
| 1611 | * to the text from the previous version. |
||
| 1612 | * |
||
| 1613 | * Such revisions can for instance identify page rename |
||
| 1614 | * operations and other such meta-modifications. |
||
| 1615 | * |
||
| 1616 | * @param IDatabase $dbw |
||
| 1617 | * @param int $pageId ID number of the page to read from |
||
| 1618 | * @param string $summary Revision's summary |
||
| 1619 | * @param bool $minor Whether the revision should be considered as minor |
||
| 1620 | * @param User|null $user User object to use or null for $wgUser |
||
| 1621 | * @return Revision|null Revision or null on error |
||
| 1622 | */ |
||
| 1623 | public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) { |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Determine if the current user is allowed to view a particular |
||
| 1683 | * field of this revision, if it's marked as deleted. |
||
| 1684 | * |
||
| 1685 | * @param int $field One of self::DELETED_TEXT, |
||
| 1686 | * self::DELETED_COMMENT, |
||
| 1687 | * self::DELETED_USER |
||
| 1688 | * @param User|null $user User object to check, or null to use $wgUser |
||
| 1689 | * @return bool |
||
| 1690 | */ |
||
| 1691 | public function userCan( $field, User $user = null ) { |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * Determine if the current user is allowed to view a particular |
||
| 1697 | * field of this revision, if it's marked as deleted. This is used |
||
| 1698 | * by various classes to avoid duplication. |
||
| 1699 | * |
||
| 1700 | * @param int $bitfield Current field |
||
| 1701 | * @param int $field One of self::DELETED_TEXT = File::DELETED_FILE, |
||
| 1702 | * self::DELETED_COMMENT = File::DELETED_COMMENT, |
||
| 1703 | * self::DELETED_USER = File::DELETED_USER |
||
| 1704 | * @param User|null $user User object to check, or null to use $wgUser |
||
| 1705 | * @param Title|null $title A Title object to check for per-page restrictions on, |
||
| 1706 | * instead of just plain userrights |
||
| 1707 | * @return bool |
||
| 1708 | */ |
||
| 1709 | public static function userCanBitfield( $bitfield, $field, User $user = null, |
||
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Get rev_timestamp from rev_id, without loading the rest of the row |
||
| 1745 | * |
||
| 1746 | * @param Title $title |
||
| 1747 | * @param int $id |
||
| 1748 | * @return string|bool False if not found |
||
| 1749 | */ |
||
| 1750 | static function getTimestampFromId( $title, $id, $flags = 0 ) { |
||
| 1764 | |||
| 1765 | /** |
||
| 1766 | * Get count of revisions per page...not very efficient |
||
| 1767 | * |
||
| 1768 | * @param IDatabase $db |
||
| 1769 | * @param int $id Page id |
||
| 1770 | * @return int |
||
| 1771 | */ |
||
| 1772 | static function countByPageId( $db, $id ) { |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Get count of revisions per page...not very efficient |
||
| 1783 | * |
||
| 1784 | * @param IDatabase $db |
||
| 1785 | * @param Title $title |
||
| 1786 | * @return int |
||
| 1787 | */ |
||
| 1788 | static function countByTitle( $db, $title ) { |
||
| 1795 | |||
| 1796 | /** |
||
| 1797 | * Check if no edits were made by other users since |
||
| 1798 | * the time a user started editing the page. Limit to |
||
| 1799 | * 50 revisions for the sake of performance. |
||
| 1800 | * |
||
| 1801 | * @since 1.20 |
||
| 1802 | * @deprecated since 1.24 |
||
| 1803 | * |
||
| 1804 | * @param IDatabase|int $db The Database to perform the check on. May be given as a |
||
| 1805 | * Database object or a database identifier usable with wfGetDB. |
||
| 1806 | * @param int $pageId The ID of the page in question |
||
| 1807 | * @param int $userId The ID of the user in question |
||
| 1808 | * @param string $since Look at edits since this time |
||
| 1809 | * |
||
| 1810 | * @return bool True if the given user was the only one to edit since the given timestamp |
||
| 1811 | */ |
||
| 1812 | public static function userWasLastToEdit( $db, $pageId, $userId, $since ) { |
||
| 1836 | } |
||
| 1837 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.