Merge "ChangesListSpecialPage: Add urlversion and make urlversion=2 ignore defaults"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index bf8e632..5332d7e 100644 (file)
@@ -385,6 +385,13 @@ abstract class ApiBase extends ContextSource {
 
        /**
         * Indicates whether this module requires write mode
+        *
+        * This should return true for modules that may require synchronous database writes.
+        * Modules that do not need such writes should also not rely on master database access,
+        * since only read queries are needed and each master DB is a single point of failure.
+        * Additionally, requests that only need replica DBs can be efficiently routed to any
+        * datacenter via the Promise-Non-Write-API-Action header.
+        *
         * @return bool
         */
        public function isWriteMode() {
@@ -1856,6 +1863,23 @@ abstract class ApiBase extends ContextSource {
                        throw new MWException( 'Successful status passed to ApiBase::dieStatus' );
                }
 
+               // ApiUsageException needs a fatal status, but this method has
+               // historically accepted any non-good status. Convert it if necessary.
+               $status->setOK( false );
+               if ( !$status->getErrorsByType( 'error' ) ) {
+                       $newStatus = Status::newGood();
+                       foreach ( $status->getErrorsByType( 'warning' ) as $err ) {
+                               call_user_func_array(
+                                       [ $newStatus, 'fatal' ],
+                                       array_merge( [ $err['message'] ], $err['params'] )
+                               );
+                       }
+                       if ( !$newStatus->getErrorsByType( 'error' ) ) {
+                               $newStatus->fatal( 'unknownerror-nocode' );
+                       }
+                       $status = $newStatus;
+               }
+
                throw new ApiUsageException( $this, $status );
        }