Migrate remaining usages of Title::userCan() to PermissionManager
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 931740c..7909ed3 100644 (file)
@@ -1904,7 +1904,11 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: this logic should not be in the storage layer, it's here for compatibility
                // with 1.31 behavior. Applying the 'autopatrol' right should be done in the same
                // place the 'bot' right is handled, which is currently in EditPage::attemptSave.
-               if ( $needsPatrol && $this->getTitle()->userCan( 'autopatrol', $user ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
+               if ( $needsPatrol && $permissionManager->userCan(
+                       'autopatrol', $user, $this->getTitle()
+               ) ) {
                        $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
                }
 
@@ -1962,9 +1966,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @deprecated since 1.32, use getDerivedDataUpdater instead.
         *
         * @param Content $content
-        * @param Revision|RevisionRecord|int|null $revision Revision object.
-        *        For backwards compatibility, a revision ID is also accepted,
-        *        but this is deprecated.
+        * @param Revision|RevisionRecord|null $revision Revision object.
         *        Used with vary-revision or vary-revision-id.
         * @param User|null $user
         * @param string|null $serialFormat IGNORED
@@ -1987,19 +1989,13 @@ class WikiPage implements Page, IDBAccessObject {
                        $user = $wgUser;
                }
 
-               if ( !is_object( $revision ) ) {
-                       $revid = $revision;
-                       // This code path is deprecated, and nothing is known to
-                       // use it, so performance here shouldn't be a worry.
-                       if ( $revid !== null ) {
-                               wfDeprecated( __METHOD__ . ' with $revision = revision ID', '1.25' );
-                               $store = $this->getRevisionStore();
-                               $revision = $store->getRevisionById( $revid, Revision::READ_LATEST );
-                       } else {
-                               $revision = null;
+               if ( $revision !== null ) {
+                       if ( $revision instanceof Revision ) {
+                               $revision = $revision->getRevisionRecord();
+                       } elseif ( !( $revision instanceof RevisionRecord ) ) {
+                               throw new InvalidArgumentException(
+                                       __METHOD__ . ': invalid $revision argument type ' . gettype( $revision ) );
                        }
-               } elseif ( $revision instanceof Revision ) {
-                       $revision = $revision->getRevisionRecord();
                }
 
                $slots = RevisionSlotsUpdate::newFromContent( [ SlotRecord::MAIN => $content ] );
@@ -2114,8 +2110,6 @@ class WikiPage implements Page, IDBAccessObject {
         *   - defer: one of the DeferredUpdates constants, or false to run immediately (default: false).
         *     Note that even when this is set to false, some updates might still get deferred (as
         *     some update might directly add child updates to DeferredUpdates).
-        *   - transactionTicket: a transaction ticket from LBFactory::getEmptyTransactionTicket(),
-        *     only when defer is false (default: null)
         * @since 1.32
         */
        public function doSecondaryDataUpdates( array $options = [] ) {
@@ -3277,7 +3271,11 @@ class WikiPage implements Page, IDBAccessObject {
                // TODO: this logic should not be in the storage layer, it's here for compatibility
                // with 1.31 behavior. Applying the 'autopatrol' right should be done in the same
                // place the 'bot' right is handled, which is currently in EditPage::attemptSave.
-               if ( $wgUseRCPatrol && $this->getTitle()->userCan( 'autopatrol', $guser ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
+               if ( $wgUseRCPatrol && $permissionManager->userCan(
+                       'autopatrol', $guser, $this->getTitle()
+               ) ) {
                        $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
                }
 
@@ -3327,7 +3325,7 @@ class WikiPage implements Page, IDBAccessObject {
                        return [ [ 'alreadyrolled',
                                        htmlspecialchars( $this->mTitle->getPrefixedText() ),
                                        htmlspecialchars( $fromP ),
-                                       htmlspecialchars( $targetEditorForPublic ? $targetEditorForPublic->getName() : '' )
+                                       htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() : '' )
                        ] ];
                }