Use wfWikiID() instead of $wgDBname in wfIncrStats()
[lhc/web/wiklou.git] / includes / api / ApiQueryRevisions.php
index ad40a64..33000e1 100644 (file)
@@ -439,12 +439,14 @@ class ApiQueryRevisions extends ApiQueryBase {
                        }
                }
 
-               if ( $this->fld_sha1 ) {
+               if ( $this->fld_sha1 && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
                        if ( $revision->getSha1() != '' ) {
                                $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
                        } else {
                                $vals['sha1'] = '';
                        }
+               } elseif ( $this->fld_sha1 ) {
+                       $vals['sha1hidden'] = '';
                }
 
                if ( $this->fld_contentmodel ) {
@@ -496,14 +498,14 @@ class ApiQueryRevisions extends ApiQueryBase {
                        // Expand templates after getting section content because
                        // template-added sections don't count and Parser::preprocess()
                        // will have less input
-                       if ( $this->section !== false ) {
+                       if ( $content && $this->section !== false ) {
                                $content = $content->getSection( $this->section, false );
                                if ( !$content ) {
                                        $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
                                }
                        }
                }
-               if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
+               if ( $this->fld_content && $content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
                        $text = null;
 
                        if ( $this->generateXML ) {
@@ -546,9 +548,9 @@ class ApiQueryRevisions extends ApiQueryBase {
 
                        if ( $text === null ) {
                                $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
+                               $model = $content->getModel();
 
                                if ( !$content->isSupportedFormat( $format ) ) {
-                                       $model = $content->getModel();
                                        $name = $title->getPrefixedDBkey();
 
                                        $this->dieUsage( "The requested format {$this->contentFormat} is not supported ".
@@ -556,20 +558,31 @@ class ApiQueryRevisions extends ApiQueryBase {
                                }
 
                                $text = $content->serialize( $format );
+
+                               // always include format and model.
+                               // Format is needed to deserialize, model is needed to interpret.
                                $vals['contentformat'] = $format;
+                               $vals['contentmodel'] = $model;
                        }
 
                        if ( $text !== false ) {
                                ApiResult::setContent( $vals, $text );
                        }
                } elseif ( $this->fld_content ) {
-                       $vals['texthidden'] = '';
+                       if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
+                               $vals['texthidden'] = '';
+                       } else {
+                               $vals['textmissing'] = '';
+                       }
                }
 
                if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
                        global $wgAPIMaxUncachedDiffs;
                        static $n = 0; // Number of uncached diffs we've had
-                       if ( $n < $wgAPIMaxUncachedDiffs ) {
+
+                       if ( is_null( $content ) ) {
+                               $vals['textmissing'] = '';
+                       } elseif ( $n < $wgAPIMaxUncachedDiffs ) {
                                $vals['diff'] = array();
                                $context = new DerivativeContext( $this->getContext() );
                                $context->setTitle( $title );
@@ -782,8 +795,12 @@ class ApiQueryRevisions extends ApiQueryBase {
                                        ApiBase::PROP_TYPE => 'string',
                                        ApiBase::PROP_NULLABLE => true
                                ),
-                               'texthidden' => 'boolean'
-                       )
+                               'texthidden' => 'boolean',
+                               'textmissing' => 'boolean',
+                       ),
+                       'contentmodel' => array(
+                               'contentmodel' => 'string'
+                       ),
                );
 
                self::addTokenProperties( $props, $this->getTokenFunctions() );