Passed
Push — dependabot/npm_and_yarn/sass-1... ( dd05dd )
by
unknown
05:21
created
includes/AutoLoader.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@
 block discarded – undo
13 13
  */
14 14
 class AutoLoader
15 15
 {
16
-    public static function load($class)
17
-    {
18
-        // handle namespaces sensibly
19
-        if (strpos($class, "Waca") !== false) {
20
-            // strip off the initial namespace
21
-            $class = str_replace("Waca\\", "", $class);
16
+	public static function load($class)
17
+	{
18
+		// handle namespaces sensibly
19
+		if (strpos($class, "Waca") !== false) {
20
+			// strip off the initial namespace
21
+			$class = str_replace("Waca\\", "", $class);
22 22
 
23
-            // swap backslashes for forward slashes to map to directory names
24
-            $class = str_replace("\\", "/", $class);
25
-        }
23
+			// swap backslashes for forward slashes to map to directory names
24
+			$class = str_replace("\\", "/", $class);
25
+		}
26 26
 
27
-        $paths = array(
28
-            __DIR__ . '/' . $class . ".php",
29
-            __DIR__ . '/DataObjects/' . $class . ".php",
30
-            __DIR__ . '/Providers/' . $class . ".php",
31
-            __DIR__ . '/Providers/Interfaces/' . $class . ".php",
32
-            __DIR__ . '/Validation/' . $class . ".php",
33
-            __DIR__ . '/Helpers/' . $class . ".php",
34
-            __DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35
-            __DIR__ . '/' . $class . ".php",
36
-        );
27
+		$paths = array(
28
+			__DIR__ . '/' . $class . ".php",
29
+			__DIR__ . '/DataObjects/' . $class . ".php",
30
+			__DIR__ . '/Providers/' . $class . ".php",
31
+			__DIR__ . '/Providers/Interfaces/' . $class . ".php",
32
+			__DIR__ . '/Validation/' . $class . ".php",
33
+			__DIR__ . '/Helpers/' . $class . ".php",
34
+			__DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35
+			__DIR__ . '/' . $class . ".php",
36
+		);
37 37
 
38
-        foreach ($paths as $file) {
39
-            if (file_exists($file)) {
40
-                /** @noinspection PhpIncludeInspection */
41
-                require_once($file);
42
-            }
38
+		foreach ($paths as $file) {
39
+			if (file_exists($file)) {
40
+				/** @noinspection PhpIncludeInspection */
41
+				require_once($file);
42
+			}
43 43
 
44
-            if (class_exists($class)) {
45
-                return;
46
-            }
47
-        }
48
-    }
44
+			if (class_exists($class)) {
45
+				return;
46
+			}
47
+		}
48
+	}
49 49
 }
Please login to merge, or discard this patch.
includes/Fragments/RequestListData.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,8 @@
 block discarded – undo
38 38
         $requestList->requests = $requests;
39 39
 
40 40
         $userIds = array_map(
41
-            function(Request $entry) {
41
+            function(Request $entry)
42
+            {
42 43
                 return $entry->getReserved();
43 44
             },
44 45
             $requests
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -19,77 +19,77 @@
 block discarded – undo
19 19
 
20 20
 trait RequestListData
21 21
 {
22
-    // function imports from InternalPageBase etc.
23
-    protected abstract function getDatabase();
24
-
25
-    protected abstract function getXffTrustProvider();
26
-
27
-    /** @return SiteConfiguration */
28
-    protected abstract function getSiteConfiguration();
29
-
30
-    protected abstract function barrierTest($action, User $user, $pageName = null);
31
-
32
-    /**
33
-     * @param Request[] $requests
34
-     *
35
-     * @return RequestList
36
-     */
37
-    protected function prepareRequestData(array $requests) : RequestList
38
-    {
39
-        $requestList = new RequestList();
40
-        $requestList->requests = $requests;
41
-
42
-        $userIds = array_map(
43
-            function(Request $entry) {
44
-                return $entry->getReserved();
45
-            },
46
-            $requests
47
-        );
48
-
49
-        $requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
50
-
51
-        $requestList->requestTrustedIp = [];
52
-        $requestList->relatedIpRequests = [];
53
-        $requestList->relatedEmailRequests = [];
54
-
55
-        foreach ($requests as $request) {
56
-            $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
57
-                $request->getIp(),
58
-                $request->getForwardedIp()
59
-            );
60
-
61
-            // TODO: Do we really want to return results from other domains?
62
-            RequestSearchHelper::get($this->getDatabase(), null)
63
-                ->byIp($trustedIp)
64
-                ->withConfirmedEmail()
65
-                ->excludingPurgedData($this->getSiteConfiguration())
66
-                ->excludingRequest($request->getId())
67
-                ->getRecordCount($ipCount);
68
-
69
-            RequestSearchHelper::get($this->getDatabase(), null)
70
-                ->byEmailAddress($request->getEmail())
71
-                ->withConfirmedEmail()
72
-                ->excludingPurgedData($this->getSiteConfiguration())
73
-                ->excludingRequest($request->getId())
74
-                ->getRecordCount($emailCount);
75
-
76
-            $requestList->requestTrustedIp[$request->getId()] = $trustedIp;
77
-            $requestList->relatedEmailRequests[$request->getId()] = $emailCount;
78
-            $requestList->relatedIpRequests[$request->getId()] = $ipCount;
79
-
80
-            $emailDomain = explode("@", $request->getEmail())[1];
81
-            $requestList->commonEmail[$request->getId()] = in_array(strtolower($emailDomain), $this->getSiteConfiguration()->getCommonEmailDomains())
82
-               || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail();
83
-        }
84
-
85
-        $currentUser = User::getCurrent($this->getDatabase());
86
-
87
-        $requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class);
88
-        $requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class);
89
-        $requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData');
90
-        $requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail();
91
-        $requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp();
92
-
93
-        return $requestList;
94
-    }
22
+	// function imports from InternalPageBase etc.
23
+	protected abstract function getDatabase();
24
+
25
+	protected abstract function getXffTrustProvider();
26
+
27
+	/** @return SiteConfiguration */
28
+	protected abstract function getSiteConfiguration();
29
+
30
+	protected abstract function barrierTest($action, User $user, $pageName = null);
31
+
32
+	/**
33
+	 * @param Request[] $requests
34
+	 *
35
+	 * @return RequestList
36
+	 */
37
+	protected function prepareRequestData(array $requests) : RequestList
38
+	{
39
+		$requestList = new RequestList();
40
+		$requestList->requests = $requests;
41
+
42
+		$userIds = array_map(
43
+			function(Request $entry) {
44
+				return $entry->getReserved();
45
+			},
46
+			$requests
47
+		);
48
+
49
+		$requestList->userList = UserSearchHelper::get($this->getDatabase())->inIds($userIds)->fetchMap('username');
50
+
51
+		$requestList->requestTrustedIp = [];
52
+		$requestList->relatedIpRequests = [];
53
+		$requestList->relatedEmailRequests = [];
54
+
55
+		foreach ($requests as $request) {
56
+			$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp(
57
+				$request->getIp(),
58
+				$request->getForwardedIp()
59
+			);
60
+
61
+			// TODO: Do we really want to return results from other domains?
62
+			RequestSearchHelper::get($this->getDatabase(), null)
63
+				->byIp($trustedIp)
64
+				->withConfirmedEmail()
65
+				->excludingPurgedData($this->getSiteConfiguration())
66
+				->excludingRequest($request->getId())
67
+				->getRecordCount($ipCount);
68
+
69
+			RequestSearchHelper::get($this->getDatabase(), null)
70
+				->byEmailAddress($request->getEmail())
71
+				->withConfirmedEmail()
72
+				->excludingPurgedData($this->getSiteConfiguration())
73
+				->excludingRequest($request->getId())
74
+				->getRecordCount($emailCount);
75
+
76
+			$requestList->requestTrustedIp[$request->getId()] = $trustedIp;
77
+			$requestList->relatedEmailRequests[$request->getId()] = $emailCount;
78
+			$requestList->relatedIpRequests[$request->getId()] = $ipCount;
79
+
80
+			$emailDomain = explode("@", $request->getEmail())[1];
81
+			$requestList->commonEmail[$request->getId()] = in_array(strtolower($emailDomain), $this->getSiteConfiguration()->getCommonEmailDomains())
82
+			   || $request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail();
83
+		}
84
+
85
+		$currentUser = User::getCurrent($this->getDatabase());
86
+
87
+		$requestList->canBan = $this->barrierTest('set', $currentUser, PageBan::class);
88
+		$requestList->canBreakReservation = $this->barrierTest('force', $currentUser, PageBreakReservation::class);
89
+		$requestList->showPrivateData = $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData');
90
+		$requestList->dataClearEmail = $this->getSiteConfiguration()->getDataClearEmail();
91
+		$requestList->dataClearIp = $this->getSiteConfiguration()->getDataClearIp();
92
+
93
+		return $requestList;
94
+	}
95 95
 }
Please login to merge, or discard this patch.
includes/Helpers/TypeAheadHelper.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@  discard block
 block discarded – undo
12 12
 
13 13
 class TypeAheadHelper implements ITypeAheadHelper
14 14
 {
15
-    private $definedClasses = array();
15
+	private $definedClasses = array();
16 16
 
17
-    /**
18
-     * @param string   $class     CSS class to apply this typeahead to.
19
-     * @param callable $generator Generator function taking no arguments to return an array of strings.
20
-     */
21
-    public function defineTypeAheadSource($class, callable $generator)
22
-    {
23
-        $dataList = '';
24
-        foreach ($generator() as $dataItem) {
25
-            $dataList .= '"' . htmlentities($dataItem) . '", ';
26
-        }
27
-        $dataList = "[" . rtrim($dataList, ", ") . "]";
17
+	/**
18
+	 * @param string   $class     CSS class to apply this typeahead to.
19
+	 * @param callable $generator Generator function taking no arguments to return an array of strings.
20
+	 */
21
+	public function defineTypeAheadSource($class, callable $generator)
22
+	{
23
+		$dataList = '';
24
+		foreach ($generator() as $dataItem) {
25
+			$dataList .= '"' . htmlentities($dataItem) . '", ';
26
+		}
27
+		$dataList = "[" . rtrim($dataList, ", ") . "]";
28 28
 
29
-        $script = <<<JS
29
+		$script = <<<JS
30 30
 
31 31
 $('.{$class}').typeahead({
32 32
         hint: true,
@@ -39,32 +39,32 @@  discard block
 block discarded – undo
39 39
 })
40 40
 ;
41 41
 JS;
42
-        $this->definedClasses[$class] = $script;
43
-    }
42
+		$this->definedClasses[$class] = $script;
43
+	}
44 44
 
45
-    /**
46
-     * @return string HTML fragment containing a JS block for typeaheads.
47
-     */
48
-    public function getTypeAheadScriptBlock()
49
-    {
50
-        $jsBlocks = '';
45
+	/**
46
+	 * @return string HTML fragment containing a JS block for typeaheads.
47
+	 */
48
+	public function getTypeAheadScriptBlock()
49
+	{
50
+		$jsBlocks = '';
51 51
 
52
-        if (count($this->definedClasses) === 0) {
53
-            return '';
54
-        }
52
+		if (count($this->definedClasses) === 0) {
53
+			return '';
54
+		}
55 55
 
56
-        foreach ($this->definedClasses as $class => $js) {
57
-            $jsBlocks = $js . "\r\n\r\n";
58
-        }
56
+		foreach ($this->definedClasses as $class => $js) {
57
+			$jsBlocks = $js . "\r\n\r\n";
58
+		}
59 59
 
60
-        $data = <<<HTML
60
+		$data = <<<HTML
61 61
 <script type="text/javascript">
62 62
 	{$jsBlocks}
63 63
 </script>
64 64
 HTML;
65 65
 
66
-        $this->definedClasses = array();
66
+		$this->definedClasses = array();
67 67
 
68
-        return $data;
69
-    }
68
+		return $data;
69
+	}
70 70
 }
Please login to merge, or discard this patch.
includes/Helpers/SearchHelpers/UserSearchHelper.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -15,73 +15,73 @@  discard block
 block discarded – undo
15 15
 
16 16
 class UserSearchHelper extends SearchHelperBase
17 17
 {
18
-    /**
19
-     * UserSearchHelper constructor.
20
-     *
21
-     * @param PdoDatabase $database
22
-     */
23
-    public function __construct(PdoDatabase $database)
24
-    {
25
-        parent::__construct($database, 'user', User::class);
26
-    }
27
-
28
-    /**
29
-     * Initiates a search for requests
30
-     *
31
-     * @param PdoDatabase $database
32
-     *
33
-     * @return UserSearchHelper
34
-     */
35
-    public static function get(PdoDatabase $database)
36
-    {
37
-        $helper = new UserSearchHelper($database);
38
-
39
-        return $helper;
40
-    }
41
-
42
-    /**
43
-     * @param string $status
44
-     *
45
-     * @return $this
46
-     */
47
-    public function byStatus($status)
48
-    {
49
-        $this->whereClause .= ' AND status = ?';
50
-        $this->parameterList[] = $status;
51
-
52
-        return $this;
53
-    }
54
-
55
-    public function statusIn($statuses)
56
-    {
57
-        $this->inClause('status', $statuses);
58
-
59
-        return $this;
60
-    }
61
-
62
-    /**
63
-     * @param string $role
64
-     *
65
-     * @return $this
66
-     */
67
-    public function byRole($role)
68
-    {
69
-        $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user';
70
-        $this->whereClause .= ' AND r.role = ?';
71
-        $this->parameterList[] = $role;
72
-
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * @param DateTime $instant
78
-     *
79
-     * @return $this
80
-     */
81
-    public function lastActiveBefore(DateTime $instant)
82
-    {
83
-        $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?';
84
-        $this->joinClause .= <<<'SQLFRAG'
18
+	/**
19
+	 * UserSearchHelper constructor.
20
+	 *
21
+	 * @param PdoDatabase $database
22
+	 */
23
+	public function __construct(PdoDatabase $database)
24
+	{
25
+		parent::__construct($database, 'user', User::class);
26
+	}
27
+
28
+	/**
29
+	 * Initiates a search for requests
30
+	 *
31
+	 * @param PdoDatabase $database
32
+	 *
33
+	 * @return UserSearchHelper
34
+	 */
35
+	public static function get(PdoDatabase $database)
36
+	{
37
+		$helper = new UserSearchHelper($database);
38
+
39
+		return $helper;
40
+	}
41
+
42
+	/**
43
+	 * @param string $status
44
+	 *
45
+	 * @return $this
46
+	 */
47
+	public function byStatus($status)
48
+	{
49
+		$this->whereClause .= ' AND status = ?';
50
+		$this->parameterList[] = $status;
51
+
52
+		return $this;
53
+	}
54
+
55
+	public function statusIn($statuses)
56
+	{
57
+		$this->inClause('status', $statuses);
58
+
59
+		return $this;
60
+	}
61
+
62
+	/**
63
+	 * @param string $role
64
+	 *
65
+	 * @return $this
66
+	 */
67
+	public function byRole($role)
68
+	{
69
+		$this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user';
70
+		$this->whereClause .= ' AND r.role = ?';
71
+		$this->parameterList[] = $role;
72
+
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * @param DateTime $instant
78
+	 *
79
+	 * @return $this
80
+	 */
81
+	public function lastActiveBefore(DateTime $instant)
82
+	{
83
+		$this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?';
84
+		$this->joinClause .= <<<'SQLFRAG'
85 85
  LEFT JOIN (
86 86
     SELECT objectid, MAX(timestamp) timestamp 
87 87
     FROM log
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
     GROUP BY objectid
90 90
     ) approvaldate ON approvaldate.objectid = origin.id
91 91
 SQLFRAG;
92
-        $formattedDate = $instant->format("Y-m-d H:i:s");
93
-        $this->parameterList[] = $formattedDate;
94
-        $this->parameterList[] = $formattedDate;
92
+		$formattedDate = $instant->format("Y-m-d H:i:s");
93
+		$this->parameterList[] = $formattedDate;
94
+		$this->parameterList[] = $formattedDate;
95 95
 
96
-        return $this;
97
-    }
96
+		return $this;
97
+	}
98 98
 
99
-    public function getRoleMap(&$roleMap)
100
-    {
101
-        $query = <<<SQL
99
+	public function getRoleMap(&$roleMap)
100
+	{
101
+		$query = <<<SQL
102 102
             SELECT /* UserSearchHelper/roleMap */ 
103 103
                   r.user user
104 104
                 , group_concat(r.role SEPARATOR ', ') roles 
@@ -107,22 +107,22 @@  discard block
 block discarded – undo
107 107
             GROUP BY r.user
108 108
 SQL;
109 109
 
110
-        $statement = $this->database->prepare($query);
111
-        $statement->execute($this->parameterList);
110
+		$statement = $this->database->prepare($query);
111
+		$statement->execute($this->parameterList);
112 112
 
113
-        $roleMap = array();
114
-        foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
115
-            $roleMap[$row['user']] = $row['roles'];
116
-        }
113
+		$roleMap = array();
114
+		foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) {
115
+			$roleMap[$row['user']] = $row['roles'];
116
+		}
117 117
 
118
-        return $this;
119
-    }
118
+		return $this;
119
+	}
120 120
 
121
-    public function withReservedRequest()
122
-    {
123
-        $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id';
124
-        $this->groupByClause = ' GROUP BY origin.id, origin.username';
121
+	public function withReservedRequest()
122
+	{
123
+		$this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id';
124
+		$this->groupByClause = ' GROUP BY origin.id, origin.username';
125 125
 
126
-        return $this->fetchMap('username');
127
-    }
126
+		return $this->fetchMap('username');
127
+	}
128 128
 }
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IMediaWikiClient.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
 
11 11
 interface IMediaWikiClient
12 12
 {
13
-    function doApiCall($params, $method);
13
+	function doApiCall($params, $method);
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Tasks/ApiPageBase.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
 
13 13
 abstract class ApiPageBase extends TaskBase implements IRoutedTask, IApiAction
14 14
 {
15
-    final public function execute()
16
-    {
17
-        $this->main();
18
-    }
15
+	final public function execute()
16
+	{
17
+		$this->main();
18
+	}
19 19
 
20
-    /**
21
-     * @param string $routeName
22
-     */
23
-    public function setRoute($routeName)
24
-    {
25
-        // no-op
26
-    }
20
+	/**
21
+	 * @param string $routeName
22
+	 */
23
+	public function setRoute($routeName)
24
+	{
25
+		// no-op
26
+	}
27 27
 
28
-    /**
29
-     * @return string
30
-     */
31
-    public function getRouteName()
32
-    {
33
-        return 'main';
34
-    }
28
+	/**
29
+	 * @return string
30
+	 */
31
+	public function getRouteName()
32
+	{
33
+		return 'main';
34
+	}
35 35
 }
Please login to merge, or discard this patch.
includes/Tasks/XmlApiPageBase.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 
18 18
 abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction
19 19
 {
20
-    /**
21
-     * API result document
22
-     * @var DOMDocument
23
-     */
24
-    protected $document;
25
-
26
-    public function __construct()
27
-    {
28
-        $this->document = new DOMDocument('1.0');
29
-    }
30
-
31
-    /**
32
-     * Main function for this page, when no specific actions are called.
33
-     *
34
-     * @throws ApiException
35
-     * @return void
36
-     */
37
-    final protected function main()
38
-    {
39
-        if (headers_sent()) {
40
-            throw new ApiException('Headers have already been sent - this indicates a bug in the application!');
41
-        }
42
-
43
-        header("Content-Type: text/xml");
44
-
45
-        // javascript access control
46
-        $httpOrigin = WebRequest::origin();
47
-
48
-        if ($httpOrigin !== null) {
49
-            $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts();
50
-
51
-            if (in_array($httpOrigin, $CORSallowed)) {
52
-                header("Access-Control-Allow-Origin: " . $httpOrigin);
53
-            }
54
-        }
55
-
56
-        $responseData = $this->runApiPage();
57
-
58
-        ob_end_clean();
59
-        print($responseData);
60
-        ob_start();
61
-    }
62
-
63
-    /**
64
-     * Method that runs API action
65
-     *
66
-     * @param DOMElement $apiDocument
67
-     *
68
-     * @return DOMElement
69
-     */
70
-    abstract public function executeApiAction(DOMElement $apiDocument);
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    final public function runApiPage()
76
-    {
77
-        $apiDocument = $this->document->createElement("api");
78
-
79
-        try {
80
-            $apiDocument = $this->executeApiAction($apiDocument);
81
-        }
82
-            /** @noinspection PhpRedundantCatchClauseInspection */
83
-        catch (ApiException $ex) {
84
-            $exception = $this->document->createElement("error");
85
-            $exception->setAttribute("message", $ex->getMessage());
86
-            $apiDocument->appendChild($exception);
87
-        }
88
-
89
-        $this->document->appendChild($apiDocument);
90
-
91
-        return $this->document->saveXML();
92
-    }
20
+	/**
21
+	 * API result document
22
+	 * @var DOMDocument
23
+	 */
24
+	protected $document;
25
+
26
+	public function __construct()
27
+	{
28
+		$this->document = new DOMDocument('1.0');
29
+	}
30
+
31
+	/**
32
+	 * Main function for this page, when no specific actions are called.
33
+	 *
34
+	 * @throws ApiException
35
+	 * @return void
36
+	 */
37
+	final protected function main()
38
+	{
39
+		if (headers_sent()) {
40
+			throw new ApiException('Headers have already been sent - this indicates a bug in the application!');
41
+		}
42
+
43
+		header("Content-Type: text/xml");
44
+
45
+		// javascript access control
46
+		$httpOrigin = WebRequest::origin();
47
+
48
+		if ($httpOrigin !== null) {
49
+			$CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts();
50
+
51
+			if (in_array($httpOrigin, $CORSallowed)) {
52
+				header("Access-Control-Allow-Origin: " . $httpOrigin);
53
+			}
54
+		}
55
+
56
+		$responseData = $this->runApiPage();
57
+
58
+		ob_end_clean();
59
+		print($responseData);
60
+		ob_start();
61
+	}
62
+
63
+	/**
64
+	 * Method that runs API action
65
+	 *
66
+	 * @param DOMElement $apiDocument
67
+	 *
68
+	 * @return DOMElement
69
+	 */
70
+	abstract public function executeApiAction(DOMElement $apiDocument);
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	final public function runApiPage()
76
+	{
77
+		$apiDocument = $this->document->createElement("api");
78
+
79
+		try {
80
+			$apiDocument = $this->executeApiAction($apiDocument);
81
+		}
82
+			/** @noinspection PhpRedundantCatchClauseInspection */
83
+		catch (ApiException $ex) {
84
+			$exception = $this->document->createElement("error");
85
+			$exception->setAttribute("message", $ex->getMessage());
86
+			$apiDocument->appendChild($exception);
87
+		}
88
+
89
+		$this->document->appendChild($apiDocument);
90
+
91
+		return $this->document->saveXML();
92
+	}
93 93
 }
Please login to merge, or discard this patch.
includes/ConsoleTasks/PrecacheGeolocationTask.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 
15 15
 class PrecacheGeolocationTask extends ConsoleTaskBase
16 16
 {
17
-    public function execute()
18
-    {
19
-        $database = $this->getDatabase();
20
-        $locationProvider = $this->getLocationProvider();
17
+	public function execute()
18
+	{
19
+		$database = $this->getDatabase();
20
+		$locationProvider = $this->getLocationProvider();
21 21
 
22
-        while (true) {
23
-            echo "Beginning txn\n";
24
-            $database->beginTransaction();
22
+		while (true) {
23
+			echo "Beginning txn\n";
24
+			$database->beginTransaction();
25 25
 
26
-            try {
27
-                echo ". Fetching data...\n";
26
+			try {
27
+				echo ". Fetching data...\n";
28 28
 
29
-                // fetch a bunch of un-geolocated IPs from the database.
30
-                // Note we have to parse the forwardedip field in the database so we can test against the geolocation
31
-                // table.
32
-                //
33
-                // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
34
-                //
35
-                // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an
36
-                // IN() clause dynamically, sending that back to the database to check if there are geolocation entries,
37
-                // then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all
38
-                // IPs from the database before we find any at all. This way keeps all of that legwork in the database,
39
-                // at the cost of a more complex query.
40
-                $statement = $database->query(<<<SQL
29
+				// fetch a bunch of un-geolocated IPs from the database.
30
+				// Note we have to parse the forwardedip field in the database so we can test against the geolocation
31
+				// table.
32
+				//
33
+				// This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
34
+				//
35
+				// Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an
36
+				// IN() clause dynamically, sending that back to the database to check if there are geolocation entries,
37
+				// then repeating until we have 10 to process - and the fact that we'd have to potentially retrieve all
38
+				// IPs from the database before we find any at all. This way keeps all of that legwork in the database,
39
+				// at the cost of a more complex query.
40
+				$statement = $database->query(<<<SQL
41 41
                     SELECT /* PrecacheGeolocationTask */ p.prox
42 42
                     FROM (
43 43
                       SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox
@@ -54,42 +54,42 @@  discard block
 block discarded – undo
54 54
                     WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox FOR UPDATE)
55 55
                     LIMIT 10;
56 56
 SQL
57
-                );
57
+				);
58 58
 
59
-                $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
59
+				$missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
60 60
 
61
-                $count = count($missingIps);
62
-                if ($count === 0) {
63
-                    echo ". Found nothing to do.\n";
64
-                    break;
65
-                }
61
+				$count = count($missingIps);
62
+				if ($count === 0) {
63
+					echo ". Found nothing to do.\n";
64
+					break;
65
+				}
66 66
 
67
-                echo ". Picked {$count} IP addresses\n";
67
+				echo ". Picked {$count} IP addresses\n";
68 68
 
69
-                foreach ($missingIps as $ip) {
70
-                    echo ". . Getting location for {$ip}...\n";
71
-                    $data = json_encode($locationProvider->getIpLocation($ip));
72
-                    echo ". . . {$data}\n";
73
-                }
69
+				foreach ($missingIps as $ip) {
70
+					echo ". . Getting location for {$ip}...\n";
71
+					$data = json_encode($locationProvider->getIpLocation($ip));
72
+					echo ". . . {$data}\n";
73
+				}
74 74
 
75
-                echo ". IP location fetch complete.\n";
76
-                $database->commit();
77
-                echo ". Committed txn.\n";
78
-            }
79
-            catch (Exception $ex) {
80
-                echo ". Encountered exception: " . $ex->getMessage() . "\n";
81
-                $database->rollBack();
82
-                echo ". Rolled back txn\n";
83
-                throw $ex;
84
-            }
85
-            finally {
86
-                if ($database->hasActiveTransaction()) {
87
-                    $database->rollBack();
88
-                    echo ". Rolled back txn\n";
89
-                }
90
-            }
91
-        }
75
+				echo ". IP location fetch complete.\n";
76
+				$database->commit();
77
+				echo ". Committed txn.\n";
78
+			}
79
+			catch (Exception $ex) {
80
+				echo ". Encountered exception: " . $ex->getMessage() . "\n";
81
+				$database->rollBack();
82
+				echo ". Rolled back txn\n";
83
+				throw $ex;
84
+			}
85
+			finally {
86
+				if ($database->hasActiveTransaction()) {
87
+					$database->rollBack();
88
+					echo ". Rolled back txn\n";
89
+				}
90
+			}
91
+		}
92 92
 
93
-        echo "Done.\n";
94
-    }
93
+		echo "Done.\n";
94
+	}
95 95
 }
96 96
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Helpers/Interfaces/IOAuthProtocolHelper.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -15,53 +15,53 @@
 block discarded – undo
15 15
 
16 16
 interface IOAuthProtocolHelper
17 17
 {
18
-    /**
19
-     * @return stdClass
20
-     *
21
-     * @throws Exception
22
-     * @throws CurlException
23
-     */
24
-    public function getRequestToken();
18
+	/**
19
+	 * @return stdClass
20
+	 *
21
+	 * @throws Exception
22
+	 * @throws CurlException
23
+	 */
24
+	public function getRequestToken();
25 25
 
26
-    /**
27
-     * @param string $requestToken
28
-     *
29
-     * @return string
30
-     */
31
-    public function getAuthoriseUrl($requestToken);
26
+	/**
27
+	 * @param string $requestToken
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function getAuthoriseUrl($requestToken);
32 32
 
33
-    /**
34
-     * @param string $oauthRequestToken
35
-     * @param string $oauthRequestSecret
36
-     * @param string $oauthVerifier
37
-     *
38
-     * @return stdClass
39
-     * @throws CurlException
40
-     * @throws Exception
41
-     */
42
-    public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier);
33
+	/**
34
+	 * @param string $oauthRequestToken
35
+	 * @param string $oauthRequestSecret
36
+	 * @param string $oauthVerifier
37
+	 *
38
+	 * @return stdClass
39
+	 * @throws CurlException
40
+	 * @throws Exception
41
+	 */
42
+	public function callbackCompleted($oauthRequestToken, $oauthRequestSecret, $oauthVerifier);
43 43
 
44
-    /**
45
-     * @param string $oauthAccessToken
46
-     * @param string $oauthAccessSecret
47
-     *
48
-     * @return stdClass
49
-     * @throws CurlException
50
-     * @throws Exception
51
-     * @throws \MediaWiki\OAuthClient\Exception
52
-     */
53
-    public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret);
44
+	/**
45
+	 * @param string $oauthAccessToken
46
+	 * @param string $oauthAccessSecret
47
+	 *
48
+	 * @return stdClass
49
+	 * @throws CurlException
50
+	 * @throws Exception
51
+	 * @throws \MediaWiki\OAuthClient\Exception
52
+	 */
53
+	public function getIdentityTicket($oauthAccessToken, $oauthAccessSecret);
54 54
 
55
-    /**
56
-     * @param array  $apiParams    array of parameters to send to the API
57
-     * @param string $accessToken  user's access token
58
-     * @param string $accessSecret user's secret
59
-     * @param string $method       HTTP method
60
-     *
61
-     * @return stdClass
62
-     * @throws ApplicationLogicException
63
-     * @throws CurlException
64
-     * @throws Exception
65
-     */
66
-    public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET');
55
+	/**
56
+	 * @param array  $apiParams    array of parameters to send to the API
57
+	 * @param string $accessToken  user's access token
58
+	 * @param string $accessSecret user's secret
59
+	 * @param string $method       HTTP method
60
+	 *
61
+	 * @return stdClass
62
+	 * @throws ApplicationLogicException
63
+	 * @throws CurlException
64
+	 * @throws Exception
65
+	 */
66
+	public function apiCall($apiParams, $accessToken, $accessSecret, $method = 'GET');
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.