Merge "Use WebRequest instead of $_SERVER in ApiMain."
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 172a77b..5e97293 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Sep 4, 2006
  *
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -65,6 +65,7 @@ class ApiMain extends ApiBase {
 
                // Write modules
                'purge' => 'ApiPurge',
+               'setnotificationtimestamp' => 'ApiSetNotificationTimestamp',
                'rollback' => 'ApiRollback',
                'delete' => 'ApiDelete',
                'undelete' => 'ApiUndelete',
@@ -422,15 +423,22 @@ class ApiMain extends ApiBase {
         */
        protected function handleCORS() {
                global $wgCrossSiteAJAXdomains, $wgCrossSiteAJAXdomainExceptions;
-               $response = $this->getRequest()->response();
+
                $originParam = $this->getParameter( 'origin' ); // defaults to null
                if ( $originParam === null ) {
                        // No origin parameter, nothing to do
                        return true;
                }
+
+               $request = $this->getRequest();
+               $response = $request->response();
                // Origin: header is a space-separated list of origins, check all of them
-               $originHeader = isset( $_SERVER['HTTP_ORIGIN'] ) ? $_SERVER['HTTP_ORIGIN'] : '';
-               $origins = explode( ' ', $originHeader );
+               $originHeader = $request->getHeader( 'Origin' );
+               if ( $originHeader === false ) {
+                       $origins = array();
+               } else {
+                       $origins = explode( ' ', $originHeader );
+               }
                if ( !in_array( $originParam, $origins ) ) {
                        // origin parameter set but incorrect
                        // Send a 403 response
@@ -967,11 +975,11 @@ class ApiMain extends ApiBase {
        protected function getCredits() {
                return array(
                        'API developers:',
-                       '    Roan Kattouw <Firstname>.<Lastname>@gmail.com (lead developer Sep 2007-present)',
+                       '    Roan Kattouw "<Firstname>.<Lastname>@gmail.com" (lead developer Sep 2007-present)',
                        '    Victor Vasiliev - vasilvv at gee mail dot com',
                        '    Bryan Tong Minh - bryan . tongminh @ gmail . com',
                        '    Sam Reed - sam @ reedyboy . net',
-                       '    Yuri Astrakhan <Firstname><Lastname>@gmail.com (creator, lead developer Sep 2006-Sep 2007)',
+                       '    Yuri Astrakhan "<Firstname><Lastname>@gmail.com" (creator, lead developer Sep 2006-Sep 2007)',
                        '',
                        'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
                        'or file a bug report at https://bugzilla.wikimedia.org/'
@@ -1160,8 +1168,18 @@ class ApiMain extends ApiBase {
 class UsageException extends MWException {
 
        private $mCodestr;
+
+       /**
+        * @var null|array
+        */
        private $mExtraData;
 
+       /**
+        * @param $message string
+        * @param $codestr string
+        * @param $code int
+        * @param $extradata array|null
+        */
        public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
                parent::__construct( $message, $code );
                $this->mCodestr = $codestr;