Make autopatrol third option in rc_patrolled and use it in API
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index d266e1d..f45036c 100644 (file)
@@ -26,7 +26,6 @@ use MediaWiki\MediaWikiServices;
 use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\FakeResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
-use Wikimedia\Rdbms\DBError;
 use Wikimedia\Rdbms\DBUnexpectedError;
 
 /**
@@ -1147,14 +1146,16 @@ class WikiPage implements Page, IDBAccessObject {
                        return;
                }
 
-               Hooks::run( 'PageViewUpdates', [ $this, $user ] );
-               // Update newtalk / watchlist notification status
-               try {
-                       $user->clearNotification( $this->mTitle, $oldid );
-               } catch ( DBError $e ) {
-                       // Avoid outage if the master is not reachable
-                       MWExceptionHandler::logException( $e );
-               }
+               // Update newtalk / watchlist notification status;
+               // Avoid outage if the master is not reachable by using a deferred updated
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( $user, $oldid ) {
+                               Hooks::run( 'PageViewUpdates', [ $this, $user ] );
+
+                               $user->clearNotification( $this->mTitle, $oldid );
+                       },
+                       DeferredUpdates::PRESEND
+               );
        }
 
        /**
@@ -1780,7 +1781,7 @@ class WikiPage implements Page, IDBAccessObject {
                        // Update recentchanges
                        if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                // Mark as patrolled if the user can do so
-                               $patrolled = $wgUseRCPatrol && !count(
+                               $autopatrolled = $wgUseRCPatrol && !count(
                                                $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
                                // Add RC row to the DB
                                RecentChange::notifyEdit(
@@ -1796,7 +1797,8 @@ class WikiPage implements Page, IDBAccessObject {
                                        $oldContent ? $oldContent->getSize() : 0,
                                        $newsize,
                                        $revisionId,
-                                       $patrolled,
+                                       $autopatrolled ? RecentChange::PRC_AUTOPATROLLED :
+                                               RecentChange::PRC_UNPATROLLED,
                                        $tags
                                );
                        }
@@ -2774,7 +2776,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param int $u1 Unused
         * @param bool $u2 Unused
         * @param array|string &$error Array of errors to append to
-        * @param User $user The deleting user
+        * @param User $deleter The deleting user
         * @param array $tags Tags to apply to the deletion action
         * @param string $logsubtype
         * @return Status Status object; if successful, $status->value is the log_id of the
@@ -2782,7 +2784,7 @@ class WikiPage implements Page, IDBAccessObject {
         *   found, $status is a non-fatal 'cannotdelete' error
         */
        public function doDeleteArticleReal(
-               $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
+               $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $deleter = null,
                $tags = [], $logsubtype = 'delete'
        ) {
                global $wgUser, $wgContentHandlerUseDB, $wgCommentTableSchemaMigrationStage,
@@ -2801,9 +2803,9 @@ class WikiPage implements Page, IDBAccessObject {
                // Avoid PHP 7.1 warning of passing $this by reference
                $wikiPage = $this;
 
-               $user = is_null( $user ) ? $wgUser : $user;
+               $deleter = is_null( $deleter ) ? $wgUser : $deleter;
                if ( !Hooks::run( 'ArticleDelete',
-                       [ &$wikiPage, &$user, &$reason, &$error, &$status, $suppress ]
+                       [ &$wikiPage, &$deleter, &$reason, &$error, &$status, $suppress ]
                ) ) {
                        if ( $status->isOK() ) {
                                // Hook aborted but didn't set a fatal status
@@ -2947,7 +2949,7 @@ class WikiPage implements Page, IDBAccessObject {
                $logtype = $suppress ? 'suppress' : 'delete';
 
                $logEntry = new ManualLogEntry( $logtype, $logsubtype );
-               $logEntry->setPerformer( $user );
+               $logEntry->setPerformer( $deleter );
                $logEntry->setTarget( $logTitle );
                $logEntry->setComment( $reason );
                $logEntry->setTags( $tags );
@@ -2963,11 +2965,11 @@ class WikiPage implements Page, IDBAccessObject {
 
                $dbw->endAtomic( __METHOD__ );
 
-               $this->doDeleteUpdates( $id, $content, $revision, $user );
+               $this->doDeleteUpdates( $id, $content, $revision, $deleter );
 
                Hooks::run( 'ArticleDeleteComplete', [
                        &$wikiPageBeforeDelete,
-                       &$user,
+                       &$deleter,
                        $reason,
                        $id,
                        $content,