Merge "Make mediawiki.special.pageLanguage work again"
[lhc/web/wiklou.git] / includes / Revision.php
index 24c025f..f4f6dca 100644 (file)
@@ -1366,6 +1366,17 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
+               // Not allowed to have rev_page equal to 0, false, etc.
+               if ( !$this->mPage ) {
+                       $title = $this->getTitle();
+                       if ( $title instanceof Title ) {
+                               $titleText = ' for page ' . $title->getPrefixedText();
+                       } else {
+                               $titleText = '';
+                       }
+                       throw new MWException( "Cannot insert revision$titleText: page ID must be nonzero" );
+               }
+
                $this->checkContentModel();
 
                $data = $this->mText;
@@ -1505,11 +1516,18 @@ class Revision implements IDBAccessObject {
                }
 
                $content = $this->getContent( Revision::RAW );
+               $prefixedDBkey = $title->getPrefixedDBkey();
+               $revId = $this->mId;
 
-               if ( !$content || !$content->isValid() ) {
-                       $t = $title->getPrefixedDBkey();
-
-                       throw new MWException( "Content of $t is not valid! Content model is $model" );
+               if ( !$content ) {
+                       throw new MWException(
+                               "Content of revision $revId ($prefixedDBkey) could not be loaded for validation!"
+                       );
+               }
+               if ( !$content->isValid() ) {
+                       throw new MWException(
+                               "Content of revision $revId ($prefixedDBkey) is not valid! Content model is $model"
+                       );
                }
        }
 
@@ -1519,7 +1537,7 @@ class Revision implements IDBAccessObject {
         * @return string
         */
        public static function base36Sha1( $text ) {
-               return wfBaseConvert( sha1( $text ), 16, 36, 31 );
+               return Wikimedia\base_convert( sha1( $text ), 16, 36, 31 );
        }
 
        /**
@@ -1530,12 +1548,13 @@ class Revision implements IDBAccessObject {
         */
        protected function loadText() {
                // Caching may be beneficial for massive use of external storage
-               global $wgRevisionCacheExpiry, $wgMemc;
+               global $wgRevisionCacheExpiry;
 
+               $cache = ObjectCache::getMainWANInstance();
                $textId = $this->getTextId();
                $key = wfMemcKey( 'revisiontext', 'textid', $textId );
                if ( $wgRevisionCacheExpiry ) {
-                       $text = $wgMemc->get( $key );
+                       $text = $cache->get( $key );
                        if ( is_string( $text ) ) {
                                wfDebug( __METHOD__ . ": got id $textId from cache\n" );
                                return $text;
@@ -1582,7 +1601,7 @@ class Revision implements IDBAccessObject {
 
                # No negative caching -- negative hits on text rows may be due to corrupted slave servers
                if ( $wgRevisionCacheExpiry && $text !== false ) {
-                       $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
+                       $cache->set( $key, $text, $wgRevisionCacheExpiry );
                }
 
                return $text;
@@ -1620,8 +1639,10 @@ class Revision implements IDBAccessObject {
                        array(
                                'page_id' => $pageId,
                                'page_latest=rev_id',
-                               ),
-                       __METHOD__ );
+                       ),
+                       __METHOD__,
+                       array( 'FOR UPDATE' ) // T51581
+               );
 
                if ( $current ) {
                        if ( !$user ) {