Prevent fatal error if $wgCookieSetOnAutoblock is changed to false
[lhc/web/wiklou.git] / includes / Revision.php
index 0f8d0bd..b812191 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  */
 use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
 
 /**
  * @todo document
@@ -86,6 +87,7 @@ class Revision implements IDBAccessObject {
        const DELETED_USER = 4;
        const DELETED_RESTRICTED = 8;
        const SUPPRESSED_USER = 12; // convenience
+       const SUPPRESSED_ALL = 15; // convenience
 
        // Audience options for accessors
        const FOR_PUBLIC = 1;
@@ -1046,11 +1048,10 @@ class Revision implements IDBAccessObject {
         *   to the $audience parameter
         *
         * @deprecated since 1.21, use getContent() instead
-        * @todo Replace usage in core
         * @return string
         */
        public function getText( $audience = self::FOR_PUBLIC, User $user = null ) {
-               ContentHandler::deprecated( __METHOD__, '1.21' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                $content = $this->getContent( $audience, $user );
                return ContentHandler::getContentText( $content ); # returns the raw content text, if applicable
@@ -1396,6 +1397,11 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
+               // We're inserting a new revision, so we have to use master anyway.
+               // If it's a null revision, it may have references to rows that
+               // are not in the replica yet (the text row).
+               $this->mQueryFlags |= self::READ_LATEST;
+
                // Not allowed to have rev_page equal to 0, false, etc.
                if ( !$this->mPage ) {
                        $title = $this->getTitle();
@@ -1577,19 +1583,20 @@ class Revision implements IDBAccessObject {
         * @return string|bool The revision's text, or false on failure
         */
        private function loadText() {
-               // Caching may be beneficial for massive use of external storage
                global $wgRevisionCacheExpiry;
 
-               if ( !$wgRevisionCacheExpiry ) {
-                       return $this->fetchText();
-               }
-
                $cache = ObjectCache::getMainWANInstance();
+               if ( $cache->getQoS( $cache::ATTR_EMULATION ) <= $cache::QOS_EMULATION_SQL ) {
+                       // Do not cache RDBMs blobs in...the RDBMs store
+                       $ttl = $cache::TTL_UNCACHEABLE;
+               } else {
+                       $ttl = $wgRevisionCacheExpiry ?: $cache::TTL_UNCACHEABLE;
+               }
 
                // No negative caching; negative hits on text rows may be due to corrupted replica DBs
                return $cache->getWithSetCallback(
-                       $key = $cache->makeKey( 'revisiontext', 'textid', $this->getTextId() ),
-                       $wgRevisionCacheExpiry,
+                       $cache->makeKey( 'revisiontext', 'textid', $this->getTextId() ),
+                       $ttl,
                        function () {
                                return $this->fetchText();
                        },
@@ -1897,7 +1904,7 @@ class Revision implements IDBAccessObject {
         * @since 1.28
         */
        public static function newKnownCurrent( IDatabase $db, $pageId, $revId ) {
-               $cache = ObjectCache::getMainWANInstance();
+               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        // Page/rev IDs passed in from DB to reflect history merges
                        $cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),