Merge "ApiComparePages: Add 'fromsection' and 'tosection' parameters"
[lhc/web/wiklou.git] / includes / api / ApiComparePages.php
index 953bc10..5486594 100644 (file)
@@ -94,6 +94,26 @@ class ApiComparePages extends ApiBase {
                        $this->dieWithError( 'apierror-baddiff' );
                }
 
+               // Extract sections, if told to
+               if ( isset( $params['fromsection'] ) ) {
+                       $fromContent = $fromContent->getSection( $params['fromsection'] );
+                       if ( !$fromContent ) {
+                               $this->dieWithError(
+                                       [ 'apierror-compare-nosuchfromsection', wfEscapeWikiText( $params['fromsection'] ) ],
+                                       'nosuchfromsection'
+                               );
+                       }
+               }
+               if ( isset( $params['tosection'] ) ) {
+                       $toContent = $toContent->getSection( $params['tosection'] );
+                       if ( !$toContent ) {
+                               $this->dieWithError(
+                                       [ 'apierror-compare-nosuchtosection', wfEscapeWikiText( $params['tosection'] ) ],
+                                       'nosuchtosection'
+                               );
+                       }
+               }
+
                // Get the diff
                $context = new DerivativeContext( $this->getContext() );
                if ( $relRev && $relRev->getTitle() ) {
@@ -175,14 +195,17 @@ class ApiComparePages extends ApiBase {
                                $rev = Revision::newFromId( $revId );
                                if ( !$rev ) {
                                        // Titles of deleted revisions aren't secret, per T51088
+                                       $arQuery = Revision::getArchiveQueryInfo();
                                        $row = $this->getDB()->selectRow(
-                                               'archive',
+                                               $arQuery['tables'],
                                                array_merge(
-                                                       Revision::selectArchiveFields(),
+                                                       $arQuery['fields'],
                                                        [ 'ar_namespace', 'ar_title' ]
                                                ),
                                                [ 'ar_rev_id' => $revId ],
-                                               __METHOD__
+                                               __METHOD__,
+                                               [],
+                                               $arQuery['joins']
                                        );
                                        if ( $row ) {
                                                $rev = Revision::newFromArchiveRow( $row );
@@ -285,14 +308,17 @@ class ApiComparePages extends ApiBase {
                        $rev = Revision::newFromId( $revId );
                        if ( !$rev && $this->getUser()->isAllowedAny( 'deletedtext', 'undelete' ) ) {
                                // Try the 'archive' table
+                               $arQuery = Revision::getArchiveQueryInfo();
                                $row = $this->getDB()->selectRow(
-                                       'archive',
+                                       $arQuery['tables'],
                                        array_merge(
-                                               Revision::selectArchiveFields(),
+                                               $arQuery['fields'],
                                                [ 'ar_namespace', 'ar_title' ]
                                        ),
                                        [ 'ar_rev_id' => $revId ],
-                                       __METHOD__
+                                       __METHOD__,
+                                       [],
+                                       $arQuery['joins']
                                );
                                if ( $row ) {
                                        $rev = Revision::newFromArchiveRow( $row );
@@ -438,6 +464,7 @@ class ApiComparePages extends ApiBase {
                        'text' => [
                                ApiBase::PARAM_TYPE => 'text'
                        ],
+                       'section' => null,
                        'pst' => false,
                        'contentformat' => [
                                ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),