Merge "Add mediawiki.org to default $wgNoFollowDomainExceptions"
[lhc/web/wiklou.git] / includes / Revision.php
index 305c8ff..6ab3df4 100644 (file)
@@ -116,11 +116,13 @@ class Revision implements IDBAccessObject {
                if ( $id ) {
                        // Use the specified ID
                        $conds['rev_id'] = $id;
+                       return self::newFromConds( $conds, (int)$flags );
                } else {
                        // Use a join to get the latest revision
                        $conds[] = 'rev_id=page_latest';
+                       $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
+                       return self::loadFromConds( $db, $conds, $flags );
                }
-               return self::newFromConds( $conds, (int)$flags );
        }
 
        /**
@@ -431,6 +433,36 @@ class Revision implements IDBAccessObject {
                return $fields;
        }
 
+       /**
+        * Return the list of revision fields that should be selected to create
+        * a new revision from an archive row.
+        * @return array
+        */
+       public static function selectArchiveFields() {
+               global $wgContentHandlerUseDB;
+               $fields = array(
+                       'ar_id',
+                       'ar_page_id',
+                       'ar_rev_id',
+                       'ar_text_id',
+                       'ar_timestamp',
+                       'ar_comment',
+                       'ar_user_text',
+                       'ar_user',
+                       'ar_minor_edit',
+                       'ar_deleted',
+                       'ar_len',
+                       'ar_parent_id',
+                       'ar_sha1',
+               );
+
+               if ( $wgContentHandlerUseDB ) {
+                       $fields[] = 'ar_content_format';
+                       $fields[] = 'ar_content_model';
+               }
+               return $fields;
+       }
+
        /**
         * Return the list of text fields that should be selected to read the
         * revision text
@@ -1279,8 +1311,8 @@ class Revision implements IDBAccessObject {
 
                global $wgLegacyEncoding;
                if ( $text !== false && $wgLegacyEncoding
-                       && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
-               {
+                       && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags )
+               {
                        # Old revisions kept around in a legacy encoding?
                        # Upconvert on demand.
                        # ("utf8" checked for compatibility with some broken
@@ -1421,14 +1453,14 @@ class Revision implements IDBAccessObject {
                                $t = $title->getPrefixedDBkey();
 
                                throw new MWException( "Can't save non-default content model with \$wgContentHandlerUseDB disabled: "
-                                                                               . "model is $model , default for $t is $defaultModel" );
+                                       . "model is $model, default for $t is $defaultModel" );
                        }
 
                        if ( $this->getContentFormat() != $defaultFormat ) {
                                $t = $title->getPrefixedDBkey();
 
                                throw new MWException( "Can't use non-default content format with \$wgContentHandlerUseDB disabled: "
-                                                                               . "format is $format, default for $t is $defaultFormat" );
+                                       . "format is $format, default for $t is $defaultFormat" );
                        }
                }