Merge "rdbms: use Database::getDomainId for transaction logging calls"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 0b28074..c3df0e5 100644 (file)
@@ -1470,7 +1470,7 @@ class WikiPage implements Page, IDBAccessObject {
                $bSlots = $b->getRevisionRecord()->getSlots();
                $changedRoles = $aSlots->getRolesWithDifferentContent( $bSlots );
 
-               return ( $changedRoles !== [ 'main' ] );
+               return ( $changedRoles !== [ 'main' ] && $changedRoles !== [] );
        }
 
        /**
@@ -1625,7 +1625,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @return DerivedPageDataUpdater
         */
        private function newDerivedDataUpdater() {
-               global $wgContLang, $wgRCWatchCategoryMembership, $wgArticleCountMethod;
+               global $wgRCWatchCategoryMembership, $wgArticleCountMethod;
 
                $derivedDataUpdater = new DerivedPageDataUpdater(
                        $this, // NOTE: eventually, PageUpdater should not know about WikiPage
@@ -1633,7 +1633,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $this->getParserCache(),
                        JobQueueGroup::singleton(),
                        MessageCache::singleton(),
-                       $wgContLang,
+                       MediaWikiServices::getInstance()->getContentLanguage(),
                        LoggerFactory::getInstance( 'SaveParse' )
                );
 
@@ -1870,7 +1870,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Get parser options suitable for rendering the primary article wikitext
         *
-        * @see ContentHandler::makeParserOptions
+        * @see ParserOptions::newCanonical
         *
         * @param IContextSource|User|string $context One of the following:
         *        - IContextSource: Use the User and the Language of the provided
@@ -1882,7 +1882,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @return ParserOptions
         */
        public function makeParserOptions( $context ) {
-               $options = $this->getContentHandler()->makeParserOptions( $context );
+               $options = ParserOptions::newCanonical( $context );
 
                if ( $this->getTitle()->isConversionTable() ) {
                        // @todo ConversionTable should become a separate content model, so
@@ -2301,14 +2301,13 @@ class WikiPage implements Page, IDBAccessObject {
         * @return string
         */
        protected function formatExpiry( $expiry ) {
-               global $wgContLang;
-
                if ( $expiry != 'infinity' ) {
+                       $contLang = MediaWikiServices::getInstance()->getContentLanguage();
                        return wfMessage(
                                'protect-expiring',
-                               $wgContLang->timeanddate( $expiry, false, false ),
-                               $wgContLang->date( $expiry, false, false ),
-                               $wgContLang->time( $expiry, false, false )
+                               $contLang->timeanddate( $expiry, false, false ),
+                               $contLang->date( $expiry, false, false ),
+                               $contLang->time( $expiry, false, false )
                        )->inContentLanguage()->text();
                } else {
                        return wfMessage( 'protect-expiry-indefinite' )
@@ -2366,13 +2365,12 @@ class WikiPage implements Page, IDBAccessObject {
         * @return string
         */
        public function protectDescriptionLog( array $limit, array $expiry ) {
-               global $wgContLang;
-
                $protectDescriptionLog = '';
 
                foreach ( array_filter( $limit ) as $action => $restrictions ) {
                        $expiryText = $this->formatExpiry( $expiry[$action] );
-                       $protectDescriptionLog .= $wgContLang->getDirMark() .
+                       $protectDescriptionLog .=
+                               MediaWikiServices::getInstance()->getContentLanguage()->getDirMark() .
                                "[$action=$restrictions] ($expiryText)";
                }
 
@@ -2537,20 +2535,16 @@ class WikiPage implements Page, IDBAccessObject {
                // Note array_intersect() preserves keys from the first arg, and we're
                // assuming $revQuery has `revision` primary and isn't using subtables
                // for anything we care about.
-               $res = $dbw->select(
+               $dbw->lockForUpdate(
                        array_intersect(
                                $revQuery['tables'],
                                [ 'revision', 'revision_comment_temp', 'revision_actor_temp' ]
                        ),
-                       '1',
                        [ 'rev_page' => $id ],
                        __METHOD__,
-                       'FOR UPDATE',
+                       [],
                        $revQuery['joins']
                );
-               foreach ( $res as $row ) {
-                       // Fetch all rows in case the DB needs that to properly lock them.
-               }
 
                // If SCHEMA_COMPAT_WRITE_OLD is set, also select all extra fields we still write,
                // so we can copy it to the archive table.
@@ -2845,7 +2839,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function commitRollback( $fromP, $summary, $bot,
                &$resultDetails, User $guser, $tags = null
        ) {
-               global $wgUseRCPatrol, $wgContLang;
+               global $wgUseRCPatrol;
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -2926,13 +2920,14 @@ class WikiPage implements Page, IDBAccessObject {
                $targetEditorForPublic = $target->getUser( RevisionRecord::FOR_PUBLIC );
 
                // Allow the custom summary to use the same args as the default message
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
                $args = [
                        $targetEditorForPublic ? $targetEditorForPublic->getName() : null,
                        $currentEditorForPublic ? $currentEditorForPublic->getName() : null,
                        $s->rev_id,
-                       $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
+                       $contLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
                        $current->getId(),
-                       $wgContLang->timeanddate( $current->getTimestamp() )
+                       $contLang->timeanddate( $current->getTimestamp() )
                ];
                if ( $summary instanceof Message ) {
                        $summary = $summary->params( $args )->inContentLanguage()->text();
@@ -3347,23 +3342,10 @@ class WikiPage implements Page, IDBAccessObject {
                foreach ( $deleted as $catName ) {
                        $cat = Category::newFromName( $catName );
                        Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
-               }
-
-               // Refresh counts on categories that should be empty now
-               if ( count( $deleted ) ) {
-                       $rows = $dbw->select(
-                               'category',
-                               [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
-                               [ 'cat_title' => $deleted, 'cat_pages <= 100' ],
-                               __METHOD__
-                       );
-                       foreach ( $rows as $row ) {
-                               $cat = Category::newFromRow( $row );
-                               // T166757: do the update after this DB commit
-                               DeferredUpdates::addCallableUpdate( function () use ( $cat ) {
-                                       $cat->refreshCounts();
-                               } );
-                       }
+                       // Refresh counts on categories that should be empty now (after commit, T166757)
+                       DeferredUpdates::addCallableUpdate( function () use ( $cat ) {
+                               $cat->refreshCountsIfEmpty();
+                       } );
                }
        }
 
@@ -3496,7 +3478,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function getMutableCacheKeys( WANObjectCache $cache ) {
                $linkCache = MediaWikiServices::getInstance()->getLinkCache();
 
-               return $linkCache->getMutableCacheKeys( $cache, $this->getTitle()->getTitleValue() );
+               return $linkCache->getMutableCacheKeys( $cache, $this->getTitle() );
        }
 
 }