1
0
mirror of https://github.com/flarum/core.git synced 2025-09-13 17:42:03 +02:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Alexander Skvortsov
e15e903cfe Regen lockfile with v2 2021-04-16 08:48:55 -04:00
Alexander Skvortsov
ee0299fa8c Build JS 2021-04-13 15:54:51 -04:00
Alexander Skvortsov
fd2e201a21 Dont generate license.txt
See https://stackoverflow.com/questions/64818489/webpack-omit-creation-of-license-txt-files
2021-04-13 15:51:13 -04:00
Alexander Skvortsov
f05163eda5 Use webpack 5 2021-04-13 15:50:47 -04:00
Alexander Skvortsov
b5dc653a19 Add semicolons in flarum.extension assignments
Without these, content generated by webpack 5 breaks
2021-04-13 15:47:06 -04:00
27 changed files with 1180 additions and 7209 deletions

6
js/dist/admin.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

54
js/dist/forum.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7988
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
"clsx": "^1.1.1",
"color-thief-browser": "^2.0.2",
"dayjs": "^1.10.4",
"expose-loader": "^1.0.3",
"expose-loader": "^2.0.0",
"jquery": "^3.6.0",
"jquery.hotkeys": "^0.1.0",
"lodash-es": "^4.17.21",
@@ -27,10 +27,10 @@
"flarum-webpack-config": "0.1.0-beta.10",
"husky": "^4.3.8",
"prettier": "^2.2.1",
"webpack": "^4.46.0",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^3.3.12",
"webpack-merge": "^4.2.2"
"webpack": "^5.0.0",
"webpack-bundle-analyzer": "^4.4.1",
"webpack-cli": "^4.0.0",
"webpack-merge": "^4.0.0"
},
"scripts": {
"dev": "webpack --mode development --watch",

View File

@@ -24,7 +24,6 @@ import { flattenDeep } from 'lodash-es';
import PageState from './states/PageState';
import ModalManagerState from './states/ModalManagerState';
import AlertManagerState from './states/AlertManagerState';
import ErrorPage from './components/ErrorPage';
/**
* The `App` class provides a container for an application, as well as various
@@ -200,9 +199,6 @@ export default class Application {
this.drawer = new Drawer();
// Needed so 404s don't get their URLs changed to the homepage.
// Won't affect extension routes since its added last.
this.routes.error = { path: '/:4xx...', component: ErrorPage };
m.route(document.getElementById('content'), basePath + '/', mapRoutes(this.routes, basePath));
// Add a class to the body which indicates that the page has been scrolled

View File

@@ -1,40 +0,0 @@
import Link from './Link';
import Page from './Page';
export default class ErrorPage extends Page {
oninit(vnode) {
super.oninit(vnode);
this.title = app.translator.trans(`core.forum.error.${this.attrs.errorCode}_title`);
}
oncreate(vnode) {
super.oncreate(vnode);
app.setTitle(this.title);
}
view() {
const links = {
404: '/',
};
const link = links[this.attrs.errorCode];
return (
<div className="ErrorPage">
<div className="container">
<h2>{this.title}</h2>
<p>{app.translator.trans(`core.forum.error.${this.attrs.errorCode}_text`)}</p>
<p>
{link && (
<Link href={link}>
{app.translator.trans(`core.forum.error.${this.attrs.errorCode}_link_text`, { forum: app.forum.attribute('title') })}
</Link>
)}
</p>
</div>
</div>
);
}
}

View File

@@ -1,5 +1,5 @@
// Expose jQuery, mithril and dayjs to the window browser object
import 'expose-loader?exposes[]=$&exposes[]=jQuery!jquery';
import 'expose-loader?exposes=$,jQuery!jquery';
import 'expose-loader?exposes=m!mithril';
import 'expose-loader?exposes=dayjs!dayjs';

View File

@@ -1,5 +1,4 @@
import Mithril from 'mithril';
import ErrorPage from '../components/ErrorPage';
/**
* Generates a route resolver for a given component.
@@ -33,12 +32,6 @@ export default class DefaultResolver {
}
onmatch(args, requestedPath, route) {
const errorCode = app.data.errorCode;
if (errorCode) {
delete app.data.errorCode;
return { view: () => ErrorPage.component({ errorCode }) };
}
return this.component;
}

View File

@@ -1,6 +1,7 @@
const config = require('flarum-webpack-config');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const merge = require('webpack-merge');
const TerserPlugin = require("terser-webpack-plugin");
const useBundleAnalyzer = process.env.ANALYZER === 'true';
@@ -21,6 +22,11 @@ module.exports = merge(config(), {
},
plugins,
optimization: {
minimizer: [new TerserPlugin({
extractComments: false,
})],
},
});
module.exports['module'].rules[0].test = /\.(tsx?|js)$/;

View File

@@ -303,15 +303,6 @@ core:
username_heading: => core.ref.username
username_label: => core.ref.username
error:
401_text: You do not have permission to access this page. Try again after logging in.
403_text: You do not have permission to access this page.
404_text: The page you requested could not be found.
401_title: Not Authenticated
403_title: Permission Denied
404_title: Not Found
404_link_text: "Return to {forum}"
# These translations are used in the Forgot Password modal dialog.
forgot_password:
dismiss_button: => core.ref.okay
@@ -526,6 +517,10 @@ core:
csrf_token_mismatch: You have been inactive for too long.
csrf_token_mismatch_return_link: Go back, to try again
invalid_confirmation_token: This confirmation link has already been used or is invalid.
not_authenticated: You do not have permission to access this page. Try again after logging in.
not_found: The page you requested could not be found.
not_found_return_link: "Return to {forum}"
permission_denied: You do not have permission to access this page.
unknown: An error occurred while trying to load this page.
# Translations in this namespace are displayed by the basic HTML discussion index.

View File

@@ -12,7 +12,6 @@ namespace Flarum\Admin;
use Flarum\Extension\Event\Disabled;
use Flarum\Extension\Event\Enabled;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\ErrorHandling\FrontendFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\ViewFormatter;
@@ -67,7 +66,6 @@ class AdminServiceProvider extends AbstractServiceProvider
return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class),
$this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class),
$this->container->make(FrontendFormatter::class),
$this->container->tagged(Reporter::class)
);
});

View File

@@ -73,12 +73,9 @@ class ApiServiceProvider extends AbstractServiceProvider
});
$this->container->bind('flarum.api.error_handler', function () {
$jsonFormatter = new JsonApiFormatter($this->container['flarum.config']->inDebugMode());
return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class),
$jsonFormatter,
$jsonFormatter, // This won't be used.
new JsonApiFormatter($this->container['flarum.config']->inDebugMode()),
$this->container->tagged(Reporter::class)
);
});

View File

@@ -97,11 +97,11 @@ class Frontend implements ExtenderInterface
if ($this->js) {
$assets->js(function (SourceCollector $sources) use ($moduleName) {
$sources->addString(function () {
return 'var module={}';
return 'var module={};';
});
$sources->addFile($this->js);
$sources->addString(function () use ($moduleName) {
return "flarum.extensions['$moduleName']=module.exports";
return "flarum.extensions['$moduleName']=module.exports;";
});
});
}

View File

@@ -13,8 +13,6 @@ use Flarum\Extension\Event\Disabled;
use Flarum\Extension\Event\Enabled;
use Flarum\Formatter\Formatter;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\ErrorHandling\FrontendFormatter;
use Flarum\Foundation\ErrorHandling\Middleware\ExecuteErrorToFrontend;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\ViewFormatter;
@@ -34,7 +32,6 @@ use Flarum\Settings\Event\Saved;
use Flarum\Settings\Event\Saving;
use Flarum\Settings\SettingsRepositoryInterface;
use Laminas\Stratigility\MiddlewarePipe;
use Laminas\Stratigility\MiddlewarePipeInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ForumServiceProvider extends AbstractServiceProvider
@@ -80,7 +77,6 @@ class ForumServiceProvider extends AbstractServiceProvider
return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class),
$this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class),
$this->container->make(FrontendFormatter::class),
$this->container->tagged(Reporter::class)
);
});
@@ -128,30 +124,6 @@ class ForumServiceProvider extends AbstractServiceProvider
$this->container->bind('flarum.frontend.forum', function () {
return $this->container->make('flarum.frontend.factory')('forum');
});
$this->container->when(FrontendFormatter::class)
->needs(MiddlewarePipeInterface::class)
->give(function () {
$middleware = $this->container->make('flarum.forum.middleware');
$pipe = new MiddlewarePipe;
foreach ($middleware as $middlewareClass) {
if (! in_array($middlewareClass, [
'flarum.forum.error_handler',
HttpMiddleware\InjectActorReference::class,
HttpMiddleware\RememberFromCookie::class,
HttpMiddleware\AuthenticateWithSession::class,
'flarum.forum.route_resolver',
])) {
$pipe->pipe($this->container->make($middlewareClass));
}
}
$pipe->pipe(new ExecuteErrorToFrontend('forum', $this->container->make(RouteHandlerFactory::class)));
return $pipe;
});
}
/**

View File

@@ -1,35 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation\ErrorHandling;
use Laminas\Stratigility\MiddlewarePipeInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
/**
* This formatter will route errors to the SPA frontend.
*/
class FrontendFormatter implements HttpFormatter
{
/**
* @var MiddlewarePipeInterface
*/
protected $pipe;
public function __construct(MiddlewarePipeInterface $pipe)
{
$this->pipe = $pipe;
}
public function format(HandledError $error, Request $request): Response
{
return $this->pipe->handle($request->withAttribute('error', $error));
}
}

View File

@@ -23,7 +23,6 @@ class HandledError
private $error;
private $type;
private $statusCode;
private $frontendContentClass;
private $details = [];
@@ -32,12 +31,11 @@ class HandledError
return new static($error, 'unknown', 500);
}
public function __construct(Throwable $error, $type, $statusCode, $frontendContentClass = null)
public function __construct(Throwable $error, $type, $statusCode)
{
$this->error = $error;
$this->type = $type;
$this->statusCode = $statusCode;
$this->frontendContentClass = $frontendContentClass;
}
public function withDetails(array $details): self
@@ -67,11 +65,6 @@ class HandledError
return $this->type === 'unknown';
}
public function contentClass()
{
return $this->frontendContentClass;
}
public function getDetails(): array
{
return $this->details;

View File

@@ -1,45 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Foundation\ErrorHandling\Middleware;
use Flarum\Http\RouteHandlerFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class ExecuteErrorToFrontend implements MiddlewareInterface
{
/**
* @var string
*/
protected $frontend;
/**
* @var RouteHandlerFactory
*/
protected $handlerFactory;
public function __construct(string $frontend, RouteHandlerFactory $handlerFactory)
{
$this->frontend = $frontend;
$this->handlerFactory = $handlerFactory;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$error = $request->getAttribute('error');
$contentClass = $error->contentClass();
$controller = $this->handlerFactory->toFrontend($this->frontend, new $contentClass);
return $controller($request, [])->withStatus($error->getStatusCode());
}
}

View File

@@ -10,7 +10,6 @@
namespace Flarum\Foundation\ErrorHandling;
use Flarum\Foundation\KnownError;
use Illuminate\Support\Arr;
use Throwable;
/**
@@ -25,14 +24,12 @@ class Registry
private $statusMap;
private $classMap;
private $handlerMap;
private $contentMap;
public function __construct(array $statusMap, array $classMap, array $handlerMap, array $contentMap)
public function __construct(array $statusMap, array $classMap, array $handlerMap)
{
$this->statusMap = $statusMap;
$this->classMap = $classMap;
$this->handlerMap = $handlerMap;
$this->contentMap = $contentMap;
}
/**
@@ -58,23 +55,20 @@ class Registry
{
$errorType = null;
$errorClass = get_class($error);
if ($error instanceof KnownError) {
$errorType = $error->getType();
} else {
$errorClass = get_class($error);
if (isset($this->classMap[$errorClass])) {
$errorType = $this->classMap[$errorClass];
}
}
$errorContent = Arr::get($this->contentMap, $errorClass);
if ($errorType) {
return new HandledError(
$error,
$errorType,
$this->statusMap[$errorType] ?? 500,
$errorContent
$this->statusMap[$errorType] ?? 500
);
}

View File

@@ -17,12 +17,6 @@ use Flarum\Foundation\ErrorHandling\ExceptionHandler;
use Flarum\Foundation\ErrorHandling\LogReporter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Http\Content\NotAuthenticated;
use Flarum\Http\Content\NotFound;
use Flarum\Http\Content\PermissionDenied;
use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\User\Exception\NotAuthenticatedException;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Validation\ValidationException as IlluminateValidationException;
use Tobscure\JsonApi\Exception\InvalidParameterException;
@@ -63,15 +57,6 @@ class ErrorServiceProvider extends AbstractServiceProvider
];
});
$this->container->singleton('flarum.error.contents', function () {
return [
NotAuthenticatedException::class => NotAuthenticated::class,
PermissionDeniedException::class => PermissionDenied::class,
ModelNotFoundException::class => NotFound::class,
RouteNotFoundException::class => NotFound::class,
];
});
$this->container->singleton('flarum.error.handlers', function () {
return [
IlluminateValidationException::class => ExceptionHandler\IlluminateValidationExceptionHandler::class,
@@ -85,8 +70,7 @@ class ErrorServiceProvider extends AbstractServiceProvider
return new Registry(
$this->container->make('flarum.error.statuses'),
$this->container->make('flarum.error.classes'),
$this->container->make('flarum.error.handlers'),
$this->container->make('flarum.error.contents'),
$this->container->make('flarum.error.handlers')
);
});

View File

@@ -1,24 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http\Content;
use Flarum\Frontend\Document;
use Psr\Http\Message\ServerRequestInterface as Request;
class NotAuthenticated
{
public function __invoke(Document $document, Request $request)
{
$document->title = 'Not Authenticated';
$document->payload['errorCode'] = 401;
return $document;
}
}

View File

@@ -1,24 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http\Content;
use Flarum\Frontend\Document;
use Psr\Http\Message\ServerRequestInterface as Request;
class NotFound
{
public function __invoke(Document $document, Request $request)
{
$document->title = 'Not Found';
$document->payload['errorCode'] = 404;
return $document;
}
}

View File

@@ -1,24 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http\Content;
use Flarum\Frontend\Document;
use Psr\Http\Message\ServerRequestInterface as Request;
class PermissionDenied
{
public function __invoke(Document $document, Request $request)
{
$document->title = 'Permission Denied';
$document->payload['errorCode'] = 403;
return $document;
}
}

View File

@@ -58,7 +58,6 @@ class HttpServiceProvider extends AbstractServiceProvider
return $compiledDrivers;
});
$this->container->bind(SlugManager::class, function () {
return new SlugManager($this->container->make('flarum.http.selectedSlugDrivers'));
});

View File

@@ -36,21 +36,15 @@ class HandleErrors implements Middleware
*/
protected $formatter;
/**
* @var HttpFormatter
*/
protected $frontendFormatter;
/**
* @var \Flarum\Foundation\ErrorHandling\Reporter[]
*/
protected $reporters;
public function __construct(Registry $registry, HttpFormatter $formatter, HttpFormatter $frontendFormatter, iterable $reporters)
public function __construct(Registry $registry, HttpFormatter $formatter, iterable $reporters)
{
$this->registry = $registry;
$this->formatter = $formatter;
$this->frontendFormatter = $frontendFormatter;
$this->reporters = $reporters;
}
@@ -70,10 +64,6 @@ class HandleErrors implements Middleware
}
}
if ($error->contentClass()) {
return $this->frontendFormatter->format($error, $request);
}
return $this->formatter->format($error, $request);
}
}

View File

@@ -0,0 +1,12 @@
@extends('flarum.forum::layouts.basic')
@section('content')
<p>
{{ $message }}
</p>
<p>
<a href="{{ $url->to('forum')->base() }}">
{{ $translator->trans('core.views.error.not_found_return_link', ['{forum}' => $settings->get('forum_title')]) }}
</a>
</p>
@endsection