1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Compare commits

...

113 Commits

Author SHA1 Message Date
luceos
e3435a3f30 Apply fixes from StyleCI
[ci skip] [skip ci]
2021-04-22 12:06:47 +00:00
Daniel Klabbers
cd0a31a6e7 Harden formatter
- prevents __PHP_Incomplete_Class
- stores a revision
2021-04-22 14:05:37 +02:00
flarum-bot
43d6b3104d Bundled output for commit 33bd99d376 [skip ci] 2021-04-21 11:27:23 +00:00
David Wheatley
33bd99d376 Fix uses of loading spinner (#2797)
* Update Loading Indicator

- Fix mistake in LoadingIndicator Less
- Middle align the loading indicator when inline
- Fix Loading Indicator not correctly accepting container class names
- Add inline and block attributes

* Fix loading indicator in composer

* Fix loading indicator on notification list

* Fix loading indicator on discussion page

* Fix loading indicator on button

* Update more uses of loading indicator

* Fix loading indicator in Search box

* Fix AvatarEditor loading spinner

* Set default spinner props

* Replace "tiny" with "small" in Less

* Improve spinner vertical centring in buttons

* Reduce size specificity

* Use single attribute for block/inline

* Use new display attribute

* Use classes for different sizes

* Use `display=block` by default
2021-04-21 12:26:09 +01:00
Alexander Skvortsov
eb4b18a979 Combine search tests
#b62debf031f1d3aec9cb5e92d9df54cb8ab3a3b1 and #b6f0b01307884b11388eff1ae2d814b7f57715aa
 both added/improved searching tests, but did so in separate files. As a result, the tests did not consider each other, and when both were merged, started failing. This commit combines the tests into one file that tests both order and search in titles.
2021-04-20 19:16:59 -04:00
Sami Mazouz
b62debf031 Add user id slug driver (#2787) 2021-04-20 23:52:53 +01:00
Alexander Skvortsov
1f2411e15e Fix searching titles in discussions (#2698)
* Fix searching titles in discussions

* Apply fixes from StyleCI

* Fix tests

* Distinct by discussion ID

* Replace distinct with groupBy

Co-authored-by: Alexander Skvortsov <askvortsov1@users.noreply.github.com>
2021-04-20 18:52:14 -04:00
flarum-bot
d99df936b1 Bundled output for commit 9716a15c31 [skip ci] 2021-04-20 16:26:39 +00:00
David Wheatley
9716a15c31 Add accessibility attributes to loading spinner (#2799) 2021-04-20 17:25:23 +01:00
Alexander Skvortsov
5e2340bf10 Fix registering custom searchers, allow searchers without fulltext (#2755) 2021-04-19 16:59:53 -04:00
Alexander Skvortsov
c84939b19c Filesystem Extender and Tests (#2732) 2021-04-19 16:25:08 -04:00
Alexander Skvortsov
4974c91481 Asset Publish Command (#2731) 2021-04-19 15:51:28 -04:00
Alexander Skvortsov
f67149bb06 Use Laravel filesystem interface for assets and avatars (#2729)
* WIP: Use Laravel filesystem interface where possible
* Drop vendorFilesystem
* Support getting URL of cloud-based logo and favicon
* FilesystemAdapter should always be cloud
* Get base avatar URL from filesystem adapter
* Restore deleted getAsset method

Co-authored-by: Alexander Skvortsov <askvortsov1@users.noreply.github.com>
2021-04-19 21:11:03 +02:00
Alexander Skvortsov
a2d77d7b81 Rename relevant migration so it runs again (#2793) 2021-04-19 14:14:07 -04:00
flarum-bot
da4264c8a3 Bundled output for commit 0f9526ba9f [skip ci] 2021-04-19 14:37:25 +00:00
Alexander Skvortsov
0f9526ba9f Adjust search height on resize (#2775)
Identified as a potential issue in https://github.com/flarum/core/pull/2650

When typing, the keyboard generally obstructs half the screen. However, when the keyboard is closed, search results don't expand to take up full space.
2021-04-19 10:36:04 -04:00
Alexander Skvortsov
e77365f32f Add id to migrations table (#2794) 2021-04-19 10:35:21 -04:00
Alexander Skvortsov
c7c456cb3e Remove unused container argument 2021-04-18 17:20:14 -04:00
Alexander Skvortsov
fb51fb4e6d Drop session from user class (#2790)
This was originally introduced in 3612ca7aca, but has not seen usage, since usually when the session needs to be modified, the request is available.

It causes issues with certain queue drivers, as it can't be serialized.

It's also not entirely accurate, as a user can have multiple sessions at once. Therefore, a given session is a property of the request, not of the user.

The reason this causes issues in the Queue is that when a Job has payload that consists User(s), the Queue will try to serialize that. Serializing the User object will require serializing the session too; this causes a Serialization of Closure is not allowed error, see image.

One can circumvent that in many ways, the most obvious one is adding a __sleep and __wakeup implementation in the User class (or the session handler). But as we aren't really using the session on the User model anywhere in core, bundled or most community extensions it is best to simply detach this from the user.
2021-04-16 15:53:05 -04:00
Sami Mazouz
5b7d364b87 Update laravel docs references to 8.x (#2788) 2021-04-16 13:26:15 +01:00
Sami Mazouz
39a6106854 Add unparse to Formatter extender (#2780) 2021-04-14 11:34:49 +01:00
Sami Mazouz
9e3699ea47 Access request actor in error handler (#2410)
* Add an ActorReference class to store the actor `$request->getAttribute('actorReference')->getActor()`
* Add a middleware to inject the actor reference
* Deprecate `$request->getAttribute('actor')`
2021-04-12 18:42:22 +01:00
Alexander Skvortsov
b6f0b01307 Fix relevance sort (#2773)
- Adds a field to QueryCriteria that determines whether the sort provided is the controller's default sort
- Set this field to true iff sort not in query params. Default it to false
- Override $sort if a new default sort has been set on search state, and the param is true.
- Add tests!
2021-04-11 22:21:56 -04:00
Sami Mazouz
548f1321f1 Require unique route names (#2771) 2021-04-10 20:38:25 +01:00
flarum-bot
e376cf2079 Bundled output for commit 286027ff27 [skip ci] 2021-04-10 14:45:12 +00:00
David Wheatley
286027ff27 Push lockfile from Linux to fix missing chokidar 2021-04-10 14:39:05 +00:00
David Wheatley
e52b769ceb Add option to build with Webpack Bundle Analyzer (#2708)
* Add option to build with webpack bundle analyzer

* Bump npm to v7 as recommended in actions/setup-node#213

* Workaround for npm/cli#558

* Add missing dep
2021-04-10 15:00:48 +01:00
Adam Hosker
b1f166d82a Remove MyISAM Requirement (#2442)
- Remove Database Engine Default of InnoDB
- Remove Hard Coded MyISAM requirement
2021-04-09 08:13:47 -04:00
flarum-bot
63675c81d6 Bundled output for commit f76524a5de [skip ci] 2021-04-08 23:43:36 +00:00
David Wheatley
f76524a5de Replace spin.js with a CSS-only loading spinner (#2764)
* Create CSS only loading indicator

* Core mods to fix Loading Indicator usage

* Remove extra whitespace

* Attrs interface extends ComponentAttrs and is exported

* Add doc block about custom styling
2021-04-09 00:42:32 +01:00
David Wheatley
c006931798 Cache npm cache between JS build runs (#2710) 2021-04-08 20:29:37 +01:00
flarum-bot
a5ec39b5cf Bundled output for commit c75db75efe [skip ci] 2021-04-08 11:36:26 +00:00
David Wheatley
c75db75efe Bump dependencies, add missing typing libraries (#2753)
* Bump dependencies and add missing typing libraries

* Fix expose-loader breaking changes

* Expose jQuery using its own typings instead of ours

* Extend jQuery typings with our own custom $.fn helpers

* Use jQuery typings for Component's `this.$` attribute

* Format webpack config file

* Use Spin.js 3.1.0
2021-04-08 12:35:10 +01:00
David Wheatley
300dadff60 Add code scanning workflow to identify common issues (#2744)
* Add code scanning workflow to identify common issues

* Don't run CodeQL if the only changes in a push/PR are .less or .md files

* Change cron

* Change workflow name to include language

* Make indents consistent with other workflows
2021-04-08 12:15:27 +01:00
Alexander Skvortsov
94d69fe15f Introduce RequestUtil to encapsulate getting/setting actor on requests(#2449) 2021-04-07 23:33:05 -04:00
Alexander Skvortsov
da598db376 Allow configuring default enabled extensions as part of installation (#2757)
This is needed for the testing library
2021-04-07 22:47:54 -04:00
Alexander Skvortsov
d31e0573f8 Don't fail silently on cache clear (#2756) 2021-04-07 22:13:08 -04:00
Sami Mazouz
2968341f77 Fix a missed getRouteData() (#2774) 2021-04-07 20:08:21 -04:00
flarum-bot
9839370701 Bundled output for commit 40dc6d0feb [skip ci] 2021-04-07 22:26:04 +00:00
Alexander Skvortsov
40dc6d0feb Preloaded API document Improvements (#2754)
* Invalidate preloadedApiDocument if URL has changed
* Revert to using `getRouteData()[0]`
2021-04-07 23:25:01 +01:00
flarum-bot
945f6478b5 Bundled output for commit 69a10c97be [skip ci] 2021-04-07 18:31:38 +00:00
David Wheatley
69a10c97be Merge "Remove unneeded vendor prefixes" (#2766) 2021-04-07 19:30:15 +01:00
Daniël Klabbers
0074f0c984 Removes duplication of cache clearing (#2738) 2021-04-07 17:29:32 +01:00
David Wheatley
19465fb522 Fix missing vendor prefix on post scrubber; move styles to Less 2021-04-05 23:19:52 +01:00
David Wheatley
0fe7723a7f Remove unneeded vendor prefixes 2021-04-05 20:27:47 +00:00
flarum-bot
fbe2813378 Bundled output for commit 4b69a35260 [skip ci] 2021-04-05 15:28:37 +00:00
David Wheatley
4b69a35260 Replace classList with clsx library (#2760) 2021-04-05 16:27:16 +01:00
Alexander Skvortsov
5e8155e1cc Remove unnecessary and imperceptible fade (#2685)
This concern was raised in https://discuss.flarum.org/d/26422-idearequest-make-header-background-color-match-exact-value-from-config.
2021-04-04 01:49:31 +01:00
flarum-bot
0f0f2b6d4e Bundled output for commit 3dae397c65 [skip ci] 2021-04-03 02:16:32 +00:00
David Wheatley
3dae397c65 Merge "Small Admin Patches" (#2739) from flarum/ck/adminux-patch2 into master
- Fixes #2736
- Fixes #2728
2021-04-03 03:14:41 +01:00
David Wheatley
7025a7f5e0 Pin GitHub Actions at specific tags and commits (#2748)
* Pin 3rd party action

* Pin GitHub-maintained actions to tag

* Bump Bundlewatch Node.js to v14 LTS

I have no clue what my thought process was when creating this workflow
initially. Thrown this in here as it's a minor change and it's silly to
make a PR just to update this number, in my opinion.
2021-04-03 01:00:26 +01:00
flarum-bot
12f6b1b375 Bundled output for commit 2de57af7c8 [skip ci] 2021-03-30 00:20:26 +00:00
David Sevilla Martin
2de57af7c8 Move forum & admin app declarations to separate files 2021-03-29 20:19:15 -04:00
Sami Mazouz
1c4817a0b3 Eager loading extender (#2724)
* Eager loading extender
* Add tests for the eager loading extender
2021-03-25 15:36:39 +01:00
KyrneDev
0eefbf0374 Help on redraw 2021-03-24 17:30:13 -10:00
KyrneDev
90c0bc410e Null name/desc breaks search fix 2021-03-24 17:29:54 -10:00
Sami Mazouz
d642fb531c Improve ApiSerializer tests (#2733)
The ApiSerializerTest was added before the ApiController extender, so I used a workaround at the time to check for the existence of the relationships on the serializer.
2021-03-23 17:33:51 -04:00
Alexander Skvortsov
706eaeda41 Use anonymous class for FakeApp (#2725)
It's a better implementation than declaring a second class in the same file, which can confuse IDEs. Furthermore, FakeApp shouldn't be used outside this file.
2021-03-22 19:00:36 +01:00
Sami Mazouz
3cc18c1da2 Eager load ListPostsController needed relations (#2717)
* Eager load ListPostsController needed relations
* Add comment explaining the reason for eagerloading
2021-03-22 09:54:18 +01:00
Alexander Skvortsov
8dd57ffed2 Include task scheduler in core 2021-03-19 18:01:38 -04:00
Alexander Skvortsov
d29495203b Move laravel helpers back in, deprecate perpetually 2021-03-19 18:01:38 -04:00
flarum-bot
783c563305 Bundled output for commit 908d087e00 [skip ci] 2021-03-19 18:14:58 +00:00
Alexander Skvortsov
908d087e00 Remove deprecated code from beta 16 (#2705) 2021-03-19 19:13:50 +01:00
sl-kr
374189d48e Refactor AccountActivationMailer and SendConfirmationEmailController (#2493)
* Add AccountActivationMailerTrait and use in AccountActivationMailer and SendConfirmationEmailController
* Remove prefix

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
2021-03-19 18:06:41 +01:00
flarum-bot
fe8dda6fd0 Bundled output for commit cd9ee48af6 [skip ci] 2021-03-18 22:04:58 +00:00
David Wheatley
cd9ee48af6 [A11Y] Add aria-label and landmark role to search input (#2669)
* Adds role="search" to Search container
* Add aria-label to search input

See this page for more info:
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Search_role
2021-03-18 23:03:01 +01:00
flarum-bot
2e9078a7cf Bundled output for commit 0cc12aed95 [skip ci] 2021-03-18 21:39:56 +00:00
David Wheatley
0cc12aed95 [A11Y] Fix nav drawer being focusable when off-screen on small viewports (#2666)
* Fix nav drawer being focusable when off-screen on small viewports

Fixes #2565

* Implement review suggestions

* Format
2021-03-18 22:38:32 +01:00
David Wheatley
59fdd7628a Speed up JS linting (#2709)
* Install Prettier only, instead of all deps

* Allow running on workflow dispatch

Allows manually triggered CI runs by org members

* Update Node to latest LTS; update step descriptions
2021-03-18 21:14:10 +00:00
David Wheatley
298f6c39f2 Add bundlewatch to track bundle size changes in PRs (#2695)
(Below steps already performed, but kept for future reference.)

Head here to get auth ID: https://service.bundlewatch.io/setup-github
Create repo secret called `BUNDLEWATCH_GITHUB_TOKEN` with the token inside
2021-03-17 14:54:42 +00:00
Alexander Skvortsov
233b97329c Drop the generate:migration command (#2686)
Core source code should contain things necessary for core to run. Development tooling like this belongs in external packages, like the upcoming Flarum CLI.
2021-03-16 12:41:07 -04:00
flarum-bot
1b5b143930 Bundled output for commit 0d139e6133 [skip ci] 2021-03-16 14:52:59 +00:00
David Wheatley
0d139e6133 [A11Y] Add aria-label to dropdown toggles (#2668)
Implement custom accessible dropdown toggle labels for forum components

Making the a11y label more specific to the specific action it performs is critical for good UX with assistive technologies.
2021-03-16 10:50:36 -04:00
Ian Morland
0e6a60bd5b Canonical URL: use UrlGenerator in place of extracting the url from request (#2674) 2021-03-15 21:43:59 -04:00
flarum-bot
6e4c75eba6 Bundled output for commit 386f3d3db1 [skip ci] 2021-03-16 01:43:29 +00:00
David Sevilla Martín
386f3d3db1 Fix Stream function code being shown when renaming discussion (#2693) 2021-03-15 21:42:22 -04:00
Alexander Skvortsov
9fffb8ec1a L8 requires constructor arguments to PhpEngine 2021-03-15 12:48:47 -04:00
Daniel Klabbers
92e590f1ab Release v0.1.0-beta.16 constant updated 2021-03-15 16:21:21 +01:00
Daniel Klabbers
098908cb4a Release v0.1.0-beta.16 2021-03-15 16:09:23 +01:00
Sami Mazouz
901846d0cf Beta 16 Changelog (#2687)
* Beta 16 Changelog

* Review tweaks

* Consistent letter casing

* IOS -> iOS

* Removed accidentally added F

* Csrf -> CSRF

Co-authored-by: David Wheatley <hi@davwheat.dev>
2021-03-15 14:55:47 +01:00
Daniel Klabbers
5a3aefb76c npm audit fix 2021-03-15 13:25:12 +01:00
Alexander Skvortsov
cf2a636e81 Apply GetModelIsPrivate BC mode to CommentPost, not Post 2021-03-13 17:16:18 -05:00
Alexander Skvortsov
a8ba510655 Fix ModelPrivate docblocks 2021-03-13 17:15:50 -05:00
Alexander Skvortsov
9c3b6c596f Merge pull request #2684 from flarum/as/filter-mutator-consistency
Make filter mutator API consistent with search mutator API.
2021-03-13 17:01:33 -05:00
Alexander Skvortsov
2310d782a3 Fix Index content, only use search when applicable. 2021-03-12 15:30:36 -05:00
Alexander Skvortsov
e9642250ae Provide active filters to filter state 2021-03-12 15:30:14 -05:00
flarum-bot
a6dd545dbc Bundled output for commit a64c39835a [skip ci] 2021-03-12 05:35:57 +00:00
Alexander Skvortsov
a64c39835a Fix shaky composer on safari mobile
When the composer is opened while scrolled to the absolute bottom of the page (via hitting the "reply" button, `window.scrollTop` has a value of ~600px greater than it should. This doesn't seem to be the composer element's height (which appears to be 0 at the time). This incorrect scrollTop positions the composer off screen, which causes Safari to freak out and shake the element violently as it tries to scroll to the cursor (which is now off screen).

We can get around this by calculating scrollTop ourselves.

Fixes https://github.com/flarum/core/issues/2683
2021-03-12 00:23:37 -05:00
Alexander Skvortsov
db0d8e89c7 Make filter mutator API consistent with search mutator API.
This is inline with the docblock for the Filter extender, and is much more sensible.
2021-03-11 23:12:49 -05:00
flarum-bot
4e126708e9 Bundled output for commit b88a7cb33b [skip ci] 2021-03-09 03:46:55 +00:00
Alexander Skvortsov
b88a7cb33b Search: dont adjust height if not rendered 2021-03-08 22:45:39 -05:00
flarum-bot
a2f52c09fd Bundled output for commit 30017eef09 [skip ci] 2021-03-08 21:31:49 +00:00
Alexander Skvortsov
30017eef09 Send username as author filter value instead of id.
For consistency with the Discussion AuthorFilterGambit, this should be sent usernames, not numerical ids.
2021-03-08 16:29:48 -05:00
flarum-bot
d0ffa26b0b Bundled output for commit 612a57c466 [skip ci] 2021-03-08 21:25:06 +00:00
Alexander Skvortsov
612a57c466 Use new author key for filtering posts
Fixes https://github.com/flarum/core/issues/2671
2021-03-08 16:21:36 -05:00
Alexander Skvortsov
91e8b56961 Add deprecated "user" filter for posts
In the filterer refactor for ListPostsController, the filter key was changed to `author` for consistency with the AuthorFilterGambit used in discussions. This commit adds a deprecated `user` filter back in for a release to allow for a graceful transition
2021-03-08 16:20:26 -05:00
flarum-bot
ba9665e9db Bundled output for commit 8eea0985a4 [skip ci] 2021-03-07 22:37:00 +00:00
Alexander Skvortsov
8eea0985a4 Split JSDoc directives to separate lines. 2021-03-07 17:35:58 -05:00
flarum-bot
1bcb9d3ea1 Bundled output for commit 2c3e1f9923 [skip ci] 2021-03-07 21:33:50 +00:00
Alexander Skvortsov
2c3e1f9923 Use flarum/testing for test infrastructure (#2545) 2021-03-07 16:32:41 -05:00
Sami Mazouz
bc607e089e Eagerload some needed relations in ListDiscussionsController (#2639) 2021-03-07 16:32:23 -05:00
Sami Mazouz
91d5d9c176 Use absolute positioning for the Composer on Safari (#2660) 2021-03-07 16:31:46 -05:00
Alexander Skvortsov
3aa118ab94 Fix search box out of screen (#2650)
Programatically set search results max height
2021-03-07 16:31:23 -05:00
Daniël Klabbers
4b0ad6972d added optional powered-by header (#2618) 2021-03-05 10:05:13 -05:00
Daniël Klabbers
84ded0ce50 Laravel components v8 (#2576)
- update actions ci
- include json for 4 spaces tab
- provide output int for process code exit
- adhere to parent type hint of builder
- mailer instance now needs a name, multiple can be instantiated
- getOriginal now uses mutators in the model
- Temporarily loosen MailableInterface requirements. This avoids an immediate BC break for classes in extensions that implement this interface.
- Temporarily provide (and autoload) old symfony translator interface
- make queue exception handler compatible with the contract of L8
- Update phpunit schema for newer version
- Update phpunit assert calls for newer version
2021-03-05 09:43:35 -05:00
Sami Mazouz
725863a6e2 Move TextEditor styles to common (#2661)
Now that TextEditor js component is shared, it only makes sense to also 
have its styles shared
2021-03-05 08:14:19 -05:00
Alexander Skvortsov
c81f629b0b Rename app to container (#2609)
* Rename `app` helper to `resolve`, deprecate old version
* Rename $this->app to $this->container in service providers

We no longer couple Flarum\Foundation\Application to the Laravel container; instead, we use the container separately. Changing our naming to reflect that will make things clearer.
2021-03-04 22:14:48 -05:00
flarum-bot
15cbe4daaa Bundled output for commit ddac07d991 [skip ci] 2021-03-04 21:52:50 +00:00
Alexander Skvortsov
ddac07d991 Move TextEditor to common (#2649) 2021-03-04 16:51:34 -05:00
Clark Winkelmann
08ba2599d7 Refactor Access Tokens (#2651)
- Make session token-based instead of user-based
- Clear current session access tokens on logout
- Introduce increment ID so we can show tokens to moderators in the future without exposing secrets
- Switch to type classes to manage the different token types. New implementation fixes #2075
- Drop ability to customize lifetime per-token
- Add developer access keys that don't expire. These must be created from the database for now
- Add title in preparation for the developer token UI
- Add IP and user agent logging
- Delete all non-remember tokens in migration
2021-03-04 16:50:38 -05:00
Blake Payne
8eef7230e9 Updated GroupFilterGambit to prevent hidden groups being visible wher… (#2657)
Updated GroupFilterGambit to prevent hidden groups being visible where they shouldn't be and to ensure that only the selected groups are returned on a search. Fixes #2559
2021-03-04 10:08:12 -05:00
flarum-bot
a61f9e7328 Bundled output for commit a65e1de641 [skip ci] 2021-03-03 23:52:04 +00:00
daniellesniak
a65e1de641 Convert common helpers to Typescript (#2541) 2021-03-03 18:50:54 -05:00
341 changed files with 14185 additions and 3750 deletions

View File

@@ -15,5 +15,5 @@ indent_size = 2
[*.{diff,md}]
trim_trailing_whitespace = false
[*.{php,xml}]
[*.{php,xml,json}]
indent_size = 4

View File

@@ -7,10 +7,24 @@ on:
jobs:
build:
name: JS / Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: flarum/action-build@master
- name: Check out code
uses: actions/checkout@v2
- name: Restore npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('js/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Our action will install npm, cd into `./js`, run `npm run build`,
# then commit and upload any changes
- name: Build production JS
uses: flarum/action-build@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

76
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,76 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
# Run on:
# - pushes to master, or
# - PRs with a base of `master`
# - which do not **only** consist of changes to .md or .less files
on:
push:
branches: [ master ]
paths-ignore:
- '**/*.md'
- '**/*.less'
pull_request:
branches: [ master ]
paths-ignore:
- '**/*.md'
- '**/*.less'
schedule:
- cron: '0 0 * * 1,3,5'
jobs:
analyze:
name: Analyze / ${{ matrix.language }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@@ -1,6 +1,7 @@
name: Lint
on:
workflow_dispatch:
push:
paths:
- 'js/src/**'
@@ -10,22 +11,18 @@ on:
jobs:
prettier:
name: JS / Prettier
runs-on: ubuntu-latest
name: JS / Prettier
steps:
- uses: actions/checkout@master
- name: Check out code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: "12"
node-version: "14"
- name: Install JS dependencies
run: npm ci
working-directory: ./js
- name: Check JS code for formatting
run: node_modules/.bin/prettier --check src
- name: Check JS formatting
run: npx prettier --check src
working-directory: ./js

45
.github/workflows/pr_size_change.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Bundle size checker
on:
workflow_dispatch:
push:
paths:
- "js/**"
pull_request:
paths:
- "js/**"
jobs:
bundlewatch:
runs-on: ubuntu-latest
name: Bundlewatch
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Use npm v7
run: sudo npm install -g npm@7.x.x
- name: Install JS dependencies
# We need to use `npm install` here. If we don't, the workflow will fail.
run: npm install
working-directory: ./js
- name: Build production assets
run: npm run build
working-directory: ./js
- name: Check bundle size change
run: node_modules/.bin/bundlewatch --config .bundlewatch.config.json
working-directory: ./js
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

View File

@@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: [7.3, 7.4, '8.0']
service: ['mysql:5.7', mariadb]
prefix: ['', flarum_]
@@ -21,12 +21,6 @@ jobs:
prefixStr: (prefix)
exclude:
- php: 7.2
service: 'mysql:5.7'
prefix: flarum_
- php: 7.2
service: mariadb
prefix: flarum_
- php: 7.3
service: 'mysql:5.7'
prefix: flarum_
@@ -49,10 +43,11 @@ jobs:
name: 'PHP ${{ matrix.php }} / ${{ matrix.db }} ${{ matrix.prefixStr }}'
steps:
- uses: actions/checkout@master
- name: Check out code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@0b9d33cd0782337377999751fc10ea079fdd7104 # pin@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
@@ -80,3 +75,5 @@ jobs:
- name: Run Composer tests
run: composer test
env:
COMPOSER_PROCESS_TIMEOUT: 600

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@ composer.phar
node_modules
.DS_Store
Thumbs.db
tests/.phpunit.result.cache
/tests/integration/tmp
.vagrant
.idea/*

View File

@@ -12,7 +12,3 @@ disabled:
- phpdoc_order
- phpdoc_separation
- phpdoc_types
finder:
exclude:
- "stubs"

View File

@@ -1,5 +1,96 @@
# Changelog
## [0.1.0-beta.16](https://github.com/flarum/core/compare/v0.1.0-beta.15...v0.1.0-beta.16)
### Added
- Allow event subscribers (https://github.com/flarum/core/pull/2535)
- Allow Settings extender to have a default value (https://github.com/flarum/core/pull/2495)
- Allow hooking into the sending of notifications before being send (https://github.com/flarum/core/pull/2533)
- PHP 8 support (https://github.com/flarum/core/pull/2507)
- Search extender (https://github.com/flarum/core/pull/2483)
- User badges to post preview (https://github.com/flarum/core/pull/2555)
- Optional extension dependencies allow a booting order (https://github.com/flarum/core/pull/2579)
- Auth extender (https://github.com/flarum/core/pull/2176)
- `X-Powered-By` header added to allow indexers easier data aggregation of Flarum adoption (https://github.com/flarum/core/pull/2618)
### Changed
- Run integration tests in transaction (https://github.com/flarum/core/pull/2304)
- Allow policies to return a boolean for simplified allow/deny (https://github.com/flarum/core/pull/2534)
- Converted highlight helper to typescript (https://github.com/flarum/core/pull/2532)
- Add accessibility attributes to Mark as Read button (https://github.com/flarum/core/pull/2564)
- Dismiss errors on change email modal upon a new request ([00913d5](https://github.com/flarum/core/commit/00913d5b0be2172cfce1f16aaf64a24f3d2e6d4b))
- Disabled extensions now are marked with a red circle instead of a red dot (https://github.com/flarum/core/pull/2562)
- Extension dependency errors now show the extension title instead of the ID (https://github.com/flarum/core/pull/2563)
- Change `mutate` method on ApiSerializer extender to `attributes` (https://github.com/flarum/core/pull/2578)
- Moved locale files to the core from the language pack (https://github.com/flarum/core/pull/2408)
- AdminPage extensibility and generic improvements (https://github.com/flarum/core/pull/2593)
- Remove entry of authors, link to https://flarum.org/team (https://github.com/flarum/core/pull/2625)
- Search and filtering are split (https://github.com/flarum/core/pull/2454)
- Move IP identification into a middleware (https://github.com/flarum/core/pull/2624)
- Editor Driver abstraction introduced (https://github.com/flarum/core/pull/2594)
- Allow overriding routes (https://github.com/flarum/core/pull/2577)
- Split user edit permissions into permissions for editing of user credentials, username, groups and suspending (https://github.com/flarum/core/pull/2620)
- Reduced number of admin extension categories (https://github.com/flarum/core/pull/2604)
- Move search related classes to a dedicated Query namespace (https://github.com/flarum/core/pull/2645)
- Rewrite common helpers into typescript (https://github.com/flarum/core/pull/2541)
- `TextEditor` is moved to the common namespace for use in the admin frontend (https://github.com/flarum/core/pull/2649)
- Update Laravel/Illuminate components to 8 (https://github.com/flarum/core/pull/2576)
- Eager load relations in discussion listing to improve performance (https://github.com/flarum/core/pull/2639)
- Adopt flarum/testing package (https://github.com/flarum/core/pull/2545)
- Replace `user` gambit with `author` gambit ([612a57c](https://github.com/flarum/core/commit/612a57c4664415a3ea120103483645c32acc6f12))
- Posts page of on user profile loads posts using username instead of id ([30017ee](https://github.com/flarum/core/commit/30017eef09ae9e78640c4e2cacd4909fffa8d775))
### Fixed
- Transform css breaks iOS scroll functionality (https://github.com/flarum/core/pull/2527)
- Composer header is hidden on mobile devices (https://github.com/flarum/core/pull/2279)
- Cannot delete a post or discussion of a deleted user (https://github.com/flarum/core/pull/2521)
- DiscussionListPane jumps around not keeping the scroll position (https://github.com/flarum/core/pull/2402)
- Infinite scroll on notifications dropdown broken (https://github.com/flarum/core/pull/2524)
- The show language selector switch remains toggled on ([9347b12](https://github.com/flarum/core/commit/9347b12b47bf4ab97ffb7ca92673604b237c1012))
- Model Visibility extender throws exception on extensions that aren't installed or enabled (https://github.com/flarum/core/pull/2580)
- Extensions are marked as enabled when enabling fails to unmet extension dependencies (https://github.com/flarum/core/pull/2558)
- Routes to admin extension pages without a valid ID break the admin page (https://github.com/flarum/core/pull/2584)
- Disabled fieldset use an incorrect CSS property `disallowed` (https://github.com/flarum/core/pull/2585)
- Scrolling to a post that is already loaded the Load More button shows and does not trigger (https://github.com/flarum/core/pull/2388)
- Opening discussions on some mobile devices require a double tap (https://github.com/flarum/core/pull/2607)
- iOS devices show erratic behavior in the post stream while updating (https://github.com/flarum/core/pull/2548)
- Small mobile screens partially hides the composer when the keyboard is open (https://github.com/flarum/core/pull/2631)
- Clearing cache does not clear the template cache in storage/views (https://github.com/flarum/core/pull/2648)
- Boot errors show critical information (https://github.com/flarum/core/pull/2633)
- List user endpoint discloses last online even if user choose against it (https://github.com/flarum/core/pull/2634)
- Group gambit disclosed hidden groups (https://github.com/flarum/core/pull/2657)
- Search results on small windows not fully visible (https://github.com/flarum/core/pull/2650)
- Composer goes off screen on Safari when starting to type (https://github.com/flarum/core/pull/2660)
- A search that has no results shows the search results dropdown ([b88a7cb](https://github.com/flarum/core/commit/b88a7cb33b56e318f11670e9e2d563aef94db039))
- The composer modal moves around when typing on Safari ([a64c398](https://github.com/flarum/core/commit/a64c39835aba43e831209609f4a9638ae589aa41))
### Removed
- Deprecated CSRF wildcard path match
- Deprecated policy and visibility scoping events
- Deprecated post types event
- Deprecated validation events
- Deprecated notification events
- Deprecated floodgate
- Deprecated user preferences event
- Deprecated formatting events
- Deprecated api events
- Deprecated bootstrap.php support
- PHP 7.2 support (https://github.com/flarum/core/pull/2507)
- Bidi attribute in the rendered HTML (https://github.com/flarum/core/pull/2602)
- `AccessToken::find`, use `AccessToken::findValid` instead (https://github.com/flarum/core/pull/2651)
### Deprecated
- `GetModelIsPrivate` event (https://github.com/flarum/core/pull/2587)
- `CheckingPassword` event (https://github.com/flarum/core/pull/2176)
- `event()` helper (https://github.com/flarum/core/pull/2608)
- `AccessToken::generate` argument `$lifetime` (https://github.com/flarum/core/pull/2651)
- `Rememberer::remember` argument `$token` should receive an instance of `RememberAccessToken` with `AccessToken` being deprecated (https://github.com/flarum/core/pull/2651)
- `Rememberer::rememberUser` (https://github.com/flarum/core/pull/2651)
- `SessionAuthenticator::logIn` argument `$userId`, should be replaced with `AccessToken` (https://github.com/flarum/core/pull/2651)
- `TextEditor` has been moved to `common` (https://github.com/flarum/core/pull/2649)
- `UserFilter` ([91e8b56](https://github.com/flarum/core/commit/91e8b569618957c86757ef89bac666e9102db5ae))
## [0.1.0-beta.15](https://github.com/flarum/core/compare/v0.1.0-beta.14.1...v0.1.0-beta.15)
### Added
@@ -210,7 +301,7 @@
- SES mail support (#2011)
- Backward compatibility layer for `Flarum\Mail\DriverInterface`, new methods from beta.12 are now required
- `Flarum\Util\Str` helper class
- `Flarum\Event\ConfigureMiddleware` event
- `Flarum\Event\ConfigureMiddleware` event
### Deprecated
- `Flarum\Event\AbstractConfigureRoutes` event class

View File

@@ -1,7 +1,10 @@
{
"name": "flarum/core",
"description": "Delightfully simple forum software.",
"keywords": ["forum", "discussion"],
"keywords": [
"forum",
"discussion"
],
"homepage": "https://flarum.org/",
"license": "MIT",
"authors": [
@@ -17,27 +20,29 @@
"docs": "https://flarum.org/docs/"
},
"require": {
"php": ">=7.2",
"php": ">=7.3",
"axy/sourcemap": "^0.1.4",
"components/font-awesome": "^5.14.0",
"dflydev/fig-cookies": "^3.0.0",
"doctrine/dbal": "^2.7",
"dragonmantank/cron-expression": "^3.1.0",
"franzl/whoops-middleware": "^2.0.0",
"illuminate/bus": "^6.0",
"illuminate/cache": "^6.0",
"illuminate/config": "^6.0",
"illuminate/container": "^6.0",
"illuminate/contracts": "^6.0",
"illuminate/database": "^6.0",
"illuminate/events": "^6.0",
"illuminate/filesystem": "^6.0",
"illuminate/hashing": "^6.0",
"illuminate/mail": "^6.0",
"illuminate/queue": "^6.0",
"illuminate/session": "^6.0",
"illuminate/support": "^6.0",
"illuminate/validation": "^6.0",
"illuminate/view": "^6.0",
"illuminate/bus": "^8.0",
"illuminate/cache": "^8.0",
"illuminate/config": "^8.0",
"illuminate/console": "^8.0",
"illuminate/container": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/database": "^8.0",
"illuminate/events": "^8.0",
"illuminate/filesystem": "^8.0",
"illuminate/hashing": "^8.0",
"illuminate/mail": "^8.0",
"illuminate/queue": "^8.0",
"illuminate/session": "^8.0",
"illuminate/support": "^8.0",
"illuminate/validation": "^8.0",
"illuminate/view": "^8.0",
"intervention/image": "^2.5.0",
"laminas/laminas-diactoros": "^2.4.1",
"laminas/laminas-httphandlerrunner": "^1.2.0",
@@ -54,18 +59,17 @@
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"s9e/text-formatter": "^2.3.6",
"symfony/config": "^4.3.4",
"symfony/console": "^4.3.4",
"symfony/event-dispatcher": "^4.3.4",
"symfony/config": "^5.2.2",
"symfony/console": "^5.2.2",
"symfony/event-dispatcher": "^5.2.2",
"symfony/mime": "^5.2.0",
"symfony/translation": "^4.3.4",
"symfony/yaml": "^4.3.4",
"symfony/translation": "^5.1.5",
"symfony/yaml": "^5.2.2",
"tobscure/json-api": "^0.3.0",
"wikimedia/less.php": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0"
"flarum/testing": "^0.1.0-beta.16"
},
"autoload": {
"psr-4": {

View File

@@ -0,0 +1,8 @@
{
"files": [
{
"path": "./dist/*.js"
}
],
"defaultCompression": "gzip"
}

16
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

18
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

10522
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,32 +2,40 @@
"private": true,
"name": "@flarum/core",
"dependencies": {
"@babel/preset-typescript": "^7.10.1",
"@types/mithril": "^2.0.3",
"bootstrap": "^3.4.1",
"classnames": "^2.2.5",
"clsx": "^1.1.1",
"color-thief-browser": "^2.0.2",
"dayjs": "^1.8.28",
"expose-loader": "^0.7.5",
"flarum-webpack-config": "0.1.0-beta.10",
"jquery": "^3.5.1",
"dayjs": "^1.10.4",
"expose-loader": "^1.0.3",
"jquery": "^3.6.0",
"jquery.hotkeys": "^0.1.0",
"lodash-es": "^4.17.14",
"lodash-es": "^4.17.21",
"mithril": "^2.0.4",
"punycode": "^2.1.1",
"spin.js": "^3.1.0",
"textarea-caret": "^3.1.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-merge": "^4.1.4"
"textarea-caret": "^3.1.0"
},
"devDependencies": {
"husky": "^4.2.5",
"prettier": "2.0.2"
"@babel/preset-typescript": "^7.13.0",
"@types/jquery": "^3.5.5",
"@types/lodash-es": "^4.17.4",
"@types/mithril": "^2.0.7",
"@types/punycode": "^2.1.0",
"@types/textarea-caret": "^3.0.0",
"bundlewatch": "^0.3.2",
"cross-env": "^7.0.3",
"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"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"analyze": "cross-env ANALYZER=true npm run build",
"format": "prettier --write src",
"format-check": "prettier --check src"
},

14
js/shims.d.ts vendored
View File

@@ -19,9 +19,21 @@ import Application from './src/common/Application';
* to (and should not) bundle these themselves.
*/
declare global {
const $: typeof _$;
// $ is already defined by `@types/jquery`
const m: Mithril.Static;
const dayjs: typeof _dayjs;
// Extend JQuery with our custom functions, defined with $.fn
interface JQuery {
/**
* Creates a tooltip on a jQuery element reference.
*
* Optionally accepts placement and delay options.
*
* Returns the same reference to allow for method chaining.
*/
tooltip: (tooltipOptions?: { placement?: 'top' | 'bottom' | 'left' | 'right'; delay?: number }) => JQuery;
}
}
/**

8
js/src/admin/app.ts Normal file
View File

@@ -0,0 +1,8 @@
import Admin from './AdminApplication';
const app = new Admin();
// @ts-ignore
window.app = app;
export default app;

View File

@@ -126,16 +126,17 @@ export default class AdminNav extends Component {
categorizedExtensions[category].map((extension) => {
const query = this.query().toUpperCase();
const title = extension.extra['flarum-extension'].title;
const title = extension.extra['flarum-extension'].title || '';
const description = extension.description || '';
if (!query || title.toUpperCase().includes(query) || extension.description.toUpperCase().includes(query)) {
if (!query || title.toUpperCase().includes(query) || description.toUpperCase().includes(query)) {
items.add(
`extension-${extension.id}`,
<ExtensionLinkButton
href={app.route('extension', { id: extension.id })}
extensionId={extension.id}
className="ExtensionNavButton"
title={extension.description}
title={description}
>
{title}
</ExtensionLinkButton>,

View File

@@ -98,35 +98,41 @@ export default class AdminPage extends Page {
return entry.call(this);
}
const setting = entry.setting;
const help = entry.help;
delete entry.help;
const { setting, help, ...componentAttrs } = entry;
delete componentAttrs.help;
const value = this.setting([setting])();
if (['bool', 'checkbox', 'switch', 'boolean'].includes(entry.type)) {
if (['bool', 'checkbox', 'switch', 'boolean'].includes(componentAttrs.type)) {
return (
<div className="Form-group">
<Switch state={!!value && value !== '0'} onchange={this.settings[setting]} {...entry}>
{entry.label}
<Switch state={!!value && value !== '0'} onchange={this.settings[setting]} {...componentAttrs}>
{componentAttrs.label}
</Switch>
<div className="helpText">{help}</div>
</div>
);
} else if (['select', 'dropdown', 'selectdropdown'].includes(entry.type)) {
} else if (['select', 'dropdown', 'selectdropdown'].includes(componentAttrs.type)) {
return (
<div className="Form-group">
<label>{entry.label}</label>
<label>{componentAttrs.label}</label>
<div className="helpText">{help}</div>
<Select value={value || entry.default} options={entry.options} buttonClassName="Button" onchange={this.settings[setting]} {...entry} />
<Select
value={value || componentAttrs.default}
options={componentAttrs.options}
buttonClassName="Button"
onchange={this.settings[setting]}
{...componentAttrs}
/>
</div>
);
} else {
entry.className = classList(['FormControl', entry.className]);
componentAttrs.className = classList(['FormControl', componentAttrs.className]);
return (
<div className="Form-group">
{entry.label ? <label>{entry.label}</label> : ''}
{componentAttrs.label ? <label>{componentAttrs.label}</label> : ''}
<div className="helpText">{help}</div>
<input type={entry.type} bidi={this.setting(setting)} {...entry} />
<input type={componentAttrs.type} bidi={this.setting(setting)} {...componentAttrs} />
</div>
);
}

View File

@@ -1,9 +1,4 @@
import AdminApplication from './AdminApplication';
const app = new AdminApplication();
// Backwards compatibility
window.app = app;
import app from './app';
export { app };

View File

@@ -159,6 +159,8 @@ export default class Application {
title = '';
titleCount = 0;
initialRoute;
load(payload) {
this.data = payload;
this.translator.locale = payload.locale;
@@ -174,6 +176,8 @@ export default class Application {
this.session = new Session(this.store.getById('users', this.data.session.userId), this.data.session.csrfToken);
this.mount();
this.initialRoute = window.location.href;
}
bootExtensions(extensions) {
@@ -226,7 +230,8 @@ export default class Application {
* @public
*/
preloadedApiDocument() {
if (this.data.apiDocument) {
// If the URL has changed, the preloaded Api document is invalid.
if (this.data.apiDocument && window.location.href === this.initialRoute) {
const results = this.store.pushPayload(this.data.apiDocument);
this.data.apiDocument = null;

View File

@@ -77,12 +77,12 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
* containing all of the `li` elements inside the DOM element of this
* component.
*
* @param {String} [selector] a jQuery-compatible selector string
* @returns {jQuery} the jQuery object for the DOM node
* @param [selector] a jQuery-compatible selector string
* @returns the jQuery object for the DOM node
* @final
*/
protected $(selector) {
const $element = $(this.element);
protected $(selector: string): JQuery {
const $element = $(this.element) as JQuery<HTMLElement>;
return selector ? $element.find(selector) : $element;
}
@@ -94,7 +94,7 @@ export default abstract class Component<T extends ComponentAttrs = ComponentAttr
* @see https://mithril.js.org/hyperscript.html#mselector,-attributes,-children
*/
static component(attrs = {}, children = null): Mithril.Vnode {
const componentAttrs = Object.assign({}, attrs);
const componentAttrs = Object.assign({}, attrs) as Record<string, unknown>;
return m(this as any, componentAttrs, children);
}

View File

@@ -1,6 +1,7 @@
import * as extend from './extend';
import Session from './Session';
import Store from './Store';
import BasicEditorDriver from './utils/BasicEditorDriver';
import evented from './utils/evented';
import liveHumanTimes from './utils/liveHumanTimes';
import ItemList from './utils/ItemList';
@@ -56,6 +57,8 @@ import ModalManager from './components/ModalManager';
import Button from './components/Button';
import Modal from './components/Modal';
import GroupBadge from './components/GroupBadge';
import TextEditor from './components/TextEditor';
import TextEditorButton from './components/TextEditorButton';
import Model from './Model';
import Application from './Application';
import fullTime from './helpers/fullTime';
@@ -74,6 +77,7 @@ export default {
extend: extend,
Session: Session,
Store: Store,
'utils/BasicEditorDriver': BasicEditorDriver,
'utils/evented': evented,
'utils/liveHumanTimes': liveHumanTimes,
'utils/ItemList': ItemList,
@@ -130,6 +134,8 @@ export default {
'components/Button': Button,
'components/Modal': Modal,
'components/GroupBadge': GroupBadge,
'components/TextEditor': TextEditor,
'components/TextEditorButton': TextEditorButton,
Model: Model,
Application: Application,
'helpers/fullTime': fullTime,

View File

@@ -69,7 +69,7 @@ export default class Button extends Component {
return [
iconName && iconName !== true ? icon(iconName, { className: 'Button-icon' }) : '',
children ? <span className="Button-label">{children}</span> : '',
this.attrs.loading ? <LoadingIndicator size="tiny" className="LoadingIndicator--inline" /> : '',
this.attrs.loading ? <LoadingIndicator size="small" display="inline" /> : '',
];
}
}

View File

@@ -46,7 +46,7 @@ export default class Checkbox extends Component {
* @protected
*/
getDisplay() {
return this.attrs.loading ? <LoadingIndicator size="tiny" /> : icon(this.attrs.state ? 'fas fa-check' : 'fas fa-times');
return this.attrs.loading ? <LoadingIndicator display="unset" size="small" /> : icon(this.attrs.state ? 'fas fa-check' : 'fas fa-times');
}
/**

View File

@@ -13,6 +13,7 @@ import listItems from '../helpers/listItems';
* - `icon` The name of an icon to show in the dropdown toggle button.
* - `caretIcon` The name of an icon to show on the right of the button.
* - `label` The label of the dropdown toggle button. Defaults to 'Controls'.
* - `accessibleToggleLabel` The label used to describe the dropdown toggle button to assistive readers. Defaults to 'Toggle dropdown menu'.
* - `onhide`
* - `onshow`
*
@@ -25,6 +26,7 @@ export default class Dropdown extends Component {
attrs.menuClassName = attrs.menuClassName || '';
attrs.label = attrs.label || '';
attrs.caretIcon = typeof attrs.caretIcon !== 'undefined' ? attrs.caretIcon : 'fas fa-caret-down';
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.lib.dropdown.toggle_dropdown_accessible_label');
}
oninit(vnode) {
@@ -92,7 +94,13 @@ export default class Dropdown extends Component {
*/
getButton(children) {
return (
<button className={'Dropdown-toggle ' + this.attrs.buttonClassName} data-toggle="dropdown" onclick={this.attrs.onclick}>
<button
className={'Dropdown-toggle ' + this.attrs.buttonClassName}
aria-haspopup="menu"
aria-label={this.attrs.accessibleToggleLabel}
data-toggle="dropdown"
onclick={this.attrs.onclick}
>
{this.getButtonContent(children)}
</button>
);

View File

@@ -1,43 +0,0 @@
import Component from '../Component';
import { Spinner } from 'spin.js';
/**
* The `LoadingIndicator` component displays a loading spinner with spin.js.
*
* ### Attrs
*
* - `size` The spin.js size preset to use. Defaults to 'small'.
*
* All other attrs will be assigned as attributes on the DOM element.
*/
export default class LoadingIndicator extends Component {
view() {
const attrs = Object.assign({}, this.attrs);
attrs.className = 'LoadingIndicator ' + (attrs.className || '');
delete attrs.size;
return <div {...attrs}>{m.trust('&nbsp;')}</div>;
}
oncreate(vnode) {
super.oncreate(vnode);
const options = { zIndex: 'auto', color: this.$().css('color') };
switch (this.attrs.size) {
case 'large':
Object.assign(options, { lines: 10, length: 8, width: 4, radius: 8 });
break;
case 'tiny':
Object.assign(options, { lines: 8, length: 2, width: 2, radius: 3 });
break;
default:
Object.assign(options, { lines: 8, length: 4, width: 3, radius: 5 });
}
new Spinner(options).spin(this.element);
}
}

View File

@@ -0,0 +1,80 @@
import Component, { ComponentAttrs } from '../Component';
import classList from '../utils/classList';
export interface LoadingIndicatorAttrs extends ComponentAttrs {
/**
* Custom classes fro the loading indicator's container.
*/
className?: string;
/**
* Custom classes for the loading indicator's container.
*/
containerClassName?: string;
/**
* Optional size to specify for the loading indicator.
*/
size?: 'large' | 'medium' | 'small';
/**
* Optional attributes to apply to the loading indicator's container.
*/
containerAttrs?: Partial<ComponentAttrs>;
/**
* Display type of the spinner.
*
* @default 'block'
*/
display?: 'block' | 'inline' | 'unset';
}
/**
* The `LoadingIndicator` component displays a simple CSS-based loading spinner.
*
* To set a custom color, use the CSS `color` property.
*
* To increase spacing around the spinner, use the CSS `height` property on the
* spinner's **container**. Setting the `display` attribute to `block` will set
* a height of `100px` by default.
*
* To apply a custom size to the loading indicator, set the `--size` and
* `--thickness` CSS custom properties on the loading indicator container.
*
* If you *really* want to change how this looks as part of your custom theme,
* you can override the `border-radius` and `border` then set either a
* background image, or use `content: "\<glyph>"` (e.g. `content: "\f1ce"`)
* and `font-family: 'Font Awesome 5 Free'` to set an FA icon if you'd rather.
*
* ### Attrs
*
* - `containerClassName` Class name(s) to apply to the indicator's parent
* - `className` Class name(s) to apply to the indicator itself
* - `display` Determines how the spinner should be displayed (`inline`, `block` (default) or `unset`)
* - `size` Size of the loading indicator (`small`, `medium` or `large`)
* - `containerAttrs` Optional attrs to be applied to the container DOM element
*
* All other attrs will be assigned as attributes on the DOM element.
*/
export default class LoadingIndicator extends Component<LoadingIndicatorAttrs> {
view() {
const { display = 'block', size = 'medium', containerClassName, className, ...attrs } = this.attrs;
const completeClassName = classList('LoadingIndicator', className);
const completeContainerClassName = classList(
'LoadingIndicator-container',
display !== 'unset' && `LoadingIndicator-container--${display}`,
size && `LoadingIndicator-container--${size}`,
containerClassName
);
return (
<div
aria-label={app.translator.trans('core.lib.loading_indicator.accessible_label')}
role="status"
{...attrs.containerAttrs}
data-size={size}
className={completeContainerClassName}
>
<div aria-hidden className={completeClassName} {...attrs} />
</div>
);
}
}

View File

@@ -24,7 +24,12 @@ export default class SplitDropdown extends Dropdown {
return [
Button.component(buttonAttrs, firstChild.children),
<button className={'Dropdown-toggle Button Button--icon ' + this.attrs.buttonClassName} data-toggle="dropdown">
<button
className={'Dropdown-toggle Button Button--icon ' + this.attrs.buttonClassName}
aria-haspopup="menu"
aria-label={this.attrs.accessibleToggleLabel}
data-toggle="dropdown"
>
{icon(this.attrs.icon, { className: 'Button-icon' })}
{icon('fas fa-caret-down', { className: 'Button-caret' })}
</button>,

View File

@@ -1,7 +1,7 @@
import Component from '../../common/Component';
import ItemList from '../../common/utils/ItemList';
import listItems from '../../common/helpers/listItems';
import Button from '../../common/components/Button';
import Component from '../Component';
import ItemList from '../utils/ItemList';
import listItems from '../helpers/listItems';
import Button from './Button';
import BasicEditorDriver from '../utils/BasicEditorDriver';

View File

@@ -1,4 +1,4 @@
import Button from '../../common/components/Button';
import Button from './Button';
/**
* The `TextEditorButton` component displays a button suitable for the text

View File

@@ -1,26 +1,28 @@
import * as Mithril from 'mithril';
import User from '../models/User';
/**
* The `avatar` helper displays a user's avatar.
*
* @param {User} user
* @param {Object} attrs Attributes to apply to the avatar element
* @return {Object}
* @param user
* @param attrs Attributes to apply to the avatar element
*/
export default function avatar(user, attrs = {}) {
export default function avatar(user: User, attrs: Object = {}): Mithril.Vnode {
attrs.className = 'Avatar ' + (attrs.className || '');
let content = '';
let content: string = '';
// If the `title` attribute is set to null or false, we don't want to give the
// avatar a title. On the other hand, if it hasn't been given at all, we can
// safely default it to the user's username.
const hasTitle = attrs.title === 'undefined' || attrs.title;
const hasTitle: boolean | string = attrs.title === 'undefined' || attrs.title;
if (!hasTitle) delete attrs.title;
// If a user has been passed, then we will set up an avatar using their
// uploaded image, or the first letter of their username if they haven't
// uploaded one.
if (user) {
const username = user.displayName() || '?';
const avatarUrl = user.avatarUrl();
const username: string = user.displayName() || '?';
const avatarUrl: string = user.avatarUrl();
if (hasTitle) attrs.title = attrs.title || username;

View File

@@ -1,15 +1,16 @@
import * as Mithril from 'mithril';
import Separator from '../components/Separator';
import classList from '../utils/classList';
function isSeparator(item) {
function isSeparator(item): boolean {
return item.tag === Separator;
}
function withoutUnnecessarySeparators(items) {
function withoutUnnecessarySeparators(items: Array<Mithril.Vnode>): Array<Mithril.Vnode> {
const newItems = [];
let prevItem;
items.filter(Boolean).forEach((item, i) => {
items.filter(Boolean).forEach((item: Mithril.Vnode, i: number) => {
if (!isSeparator(item) || (prevItem && !isSeparator(prevItem) && i !== items.length - 1)) {
prevItem = item;
newItems.push(item);
@@ -22,14 +23,11 @@ function withoutUnnecessarySeparators(items) {
/**
* The `listItems` helper wraps a collection of components in <li> tags,
* stripping out any unnecessary `Separator` components.
*
* @param {*} items
* @return {Array}
*/
export default function listItems(items) {
export default function listItems(items: Mithril.Vnode | Array<Mithril.Vnode>): Array<Mithril.Vnode> {
if (!(items instanceof Array)) items = [items];
return withoutUnnecessarySeparators(items).map((item) => {
return withoutUnnecessarySeparators(items).map((item: Mithril.Vnode) => {
const isListItem = item.tag && item.tag.isListItem;
const active = item.tag && item.tag.isActive && item.tag.isActive(item.attrs);
const className = (item.attrs && item.attrs.itemClassName) || item.itemClassName;
@@ -40,7 +38,7 @@ export default function listItems(items) {
item.key = item.attrs.key;
}
const node = isListItem ? (
const node: Mithril.Vnode = isListItem ? (
item
) : (
<li

View File

@@ -1,12 +1,11 @@
import * as Mithril from 'mithril';
import User from '../models/User';
import icon from './icon';
/**
* The `useronline` helper displays a green circle if the user is online
*
* @param {User} user
* @return {Object}
*/
export default function userOnline(user) {
export default function userOnline(user: User): Mithril.Vnode {
if (user.lastSeenAt() && user.isOnline()) {
return <span className="UserOnline">{icon('fas fa-circle')}</span>;
}

View File

@@ -1,11 +1,11 @@
import * as Mithril from 'mithril';
import User from '../models/User';
/**
* The `username` helper displays a user's username in a <span class="username">
* tag. If the user doesn't exist, the username will be displayed as [deleted].
*
* @param {User} user
* @return {Object}
*/
export default function username(user) {
export default function username(user: User): Mithril.Vnode {
const name = (user && user.displayName()) || app.translator.trans('core.lib.username.deleted_text');
return <span className="username">{name}</span>;

View File

@@ -1,6 +1,8 @@
import 'expose-loader?$!expose-loader?jQuery!jquery';
import 'expose-loader?m!mithril';
import 'expose-loader?dayjs!dayjs';
// Expose jQuery, mithril and dayjs to the window browser object
import 'expose-loader?exposes[]=$&exposes[]=jQuery!jquery';
import 'expose-loader?exposes=m!mithril';
import 'expose-loader?exposes=dayjs!dayjs';
import 'bootstrap/js/affix';
import 'bootstrap/js/dropdown';
import 'bootstrap/js/modal';

View File

@@ -31,7 +31,24 @@ export default class Drawer {
* @public
*/
hide() {
$('#app').removeClass('drawerOpen');
/**
* As part of hiding the drawer, this function also ensures that the drawer
* correctly animates out, while ensuring it is not part of the navigation
* tree while off-screen.
*
* More info: https://github.com/flarum/core/pull/2666#discussion_r595381014
*/
const $app = $('#app');
if (!$app.hasClass('drawerOpen')) return;
const $drawer = $('#drawer');
// Used to prevent `visibility: hidden` from breaking the exit animation
$drawer.css('visibility', 'visible').one('transitionend', () => $drawer.css('visibility', ''));
$app.removeClass('drawerOpen');
if (this.$backdrop) this.$backdrop.remove();
}

View File

@@ -1,26 +0,0 @@
/**
* The `classList` utility creates a list of class names by joining an object's
* keys, but only for values which are truthy.
*
* @example
* classList({ foo: true, bar: false, qux: 'qaz' });
* // "foo qux"
*
* @param {Object} classes
* @return {String}
*/
export default function classList(classes) {
let classNames;
if (classes instanceof Array) {
classNames = classes.filter((name) => name);
} else {
classNames = [];
for (const i in classes) {
if (classes[i]) classNames.push(i);
}
}
return classNames.join(' ');
}

View File

@@ -0,0 +1,12 @@
import clsx from 'clsx';
/**
* This util exposes `clsx` to core and extensions as a re-usable utility.
*
* For full documentation, see `clsx` on GitHub.
*
* @see https://github.com/lukeed/clsx
*/
const classList = clsx;
export default classList;

View File

@@ -16,6 +16,7 @@ import NotificationListState from './states/NotificationListState';
import GlobalSearchState from './states/GlobalSearchState';
import DiscussionListState from './states/DiscussionListState';
import ComposerState from './states/ComposerState';
import isSafariMobile from './utils/isSafariMobile';
export default class ForumApplication extends Application {
/**
@@ -138,6 +139,12 @@ export default class ForumApplication extends Application {
m.redraw();
}
});
if (isSafariMobile()) {
$(() => {
$('.App').addClass('mobile-safari');
});
}
}
/**

8
js/src/forum/app.ts Normal file
View File

@@ -0,0 +1,8 @@
import Forum from './ForumApplication';
const app = new Forum();
// @ts-ignore
window.app = app;
export default app;

View File

@@ -36,8 +36,6 @@ import HeaderSecondary from './components/HeaderSecondary';
import ComposerButton from './components/ComposerButton';
import DiscussionList from './components/DiscussionList';
import ReplyPlaceholder from './components/ReplyPlaceholder';
import TextEditor from './components/TextEditor';
import TextEditorButton from './components/TextEditorButton';
import AvatarEditor from './components/AvatarEditor';
import Post from './components/Post';
import SettingsPage from './components/SettingsPage';
@@ -73,7 +71,7 @@ import DiscussionListItem from './components/DiscussionListItem';
import LoadingPost from './components/LoadingPost';
import PostsUserPage from './components/PostsUserPage';
import DiscussionPageResolver from './resolvers/DiscussionPageResolver';
import BasicEditorDriver from './utils/BasicEditorDriver';
import BasicEditorDriver from '../common/utils/BasicEditorDriver';
import routes from './routes';
import ForumApplication from './ForumApplication';
@@ -87,7 +85,6 @@ export default Object.assign(compat, {
'utils/UserControls': UserControls,
'utils/Pane': Pane,
'utils/BasicEditorDriver': BasicEditorDriver,
'utils/SuperTextarea': BasicEditorDriver, // @deprecated beta 16, remove beta 17
'states/ComposerState': ComposerState,
'states/DiscussionListState': DiscussionListState,
'states/GlobalSearchState': GlobalSearchState,
@@ -116,8 +113,6 @@ export default Object.assign(compat, {
'components/ComposerButton': ComposerButton,
'components/DiscussionList': DiscussionList,
'components/ReplyPlaceholder': ReplyPlaceholder,
'components/TextEditor': TextEditor,
'components/TextEditorButton': TextEditorButton,
'components/AvatarEditor': AvatarEditor,
'components/Post': Post,
'components/SettingsPage': SettingsPage,

View File

@@ -52,7 +52,13 @@ export default class AvatarEditor extends Component {
ondragend={this.disableDragover.bind(this)}
ondrop={this.dropUpload.bind(this)}
>
{this.loading ? <LoadingIndicator /> : user.avatarUrl() ? icon('fas fa-pencil-alt') : icon('fas fa-plus-circle')}
{this.loading ? (
<LoadingIndicator display="unset" size="large" />
) : user.avatarUrl() ? (
icon('fas fa-pencil-alt')
) : (
icon('fas fa-plus-circle')
)}
</a>
<ul className="Dropdown-menu Menu">{listItems(this.controlItems().toArray())}</ul>
</div>

View File

@@ -265,7 +265,17 @@ export default class Composer extends Component {
this.animateHeightChange().then(() => this.focus());
if (app.screen() === 'phone') {
this.$().css('top', 0);
// On safari fixed position doesn't properly work on mobile,
// So we use absolute and set the top value.
// https://github.com/flarum/core/issues/2652
// Due to another safari bug, `scrollTop` is unreliable when
// at the very bottom of the page AND opening the composer.
// So we fallback to a calculated version of scrollTop.
// https://github.com/flarum/core/issues/2683
const scrollElement = document.documentElement;
const topOfViewport = Math.min(scrollElement.scrollTop, scrollElement.scrollHeight - scrollElement.clientHeight);
this.$().css('top', $('.App').is('.mobile-safari') ? topOfViewport : 0);
this.showBackdrop();
}
}

View File

@@ -1,10 +1,11 @@
import Component from '../../common/Component';
import LoadingIndicator from '../../common/components/LoadingIndicator';
import ConfirmDocumentUnload from '../../common/components/ConfirmDocumentUnload';
import TextEditor from './TextEditor';
import TextEditor from '../../common/components/TextEditor';
import avatar from '../../common/helpers/avatar';
import listItems from '../../common/helpers/listItems';
import ItemList from '../../common/utils/ItemList';
import classList from '../../common/utils/classList';
/**
* The `ComposerBody` component handles the body, or the content, of the
@@ -66,7 +67,7 @@ export default class ComposerBody extends Component {
})}
</div>
</div>
{LoadingIndicator.component({ className: 'ComposerBody-loading' + (this.loading ? ' active' : '') })}
<LoadingIndicator display="unset" containerClassName={classList('ComposerBody-loading', this.loading && 'active')} size="large" />
</div>
</ConfirmDocumentUnload>
);

View File

@@ -19,7 +19,7 @@ export default class DiscussionList extends Component {
let loading;
if (state.isLoading()) {
loading = LoadingIndicator.component();
loading = <LoadingIndicator />;
} else if (state.moreResults) {
loading = Button.component(
{

View File

@@ -87,6 +87,7 @@ export default class DiscussionListItem extends Component {
icon: 'fas fa-ellipsis-v',
className: 'DiscussionListItem-controls',
buttonClassName: 'Button Button--icon Button--flat Slidable-underneath Slidable-underneath--right',
accessibleToggleLabel: app.translator.trans('core.forum.discussion_controls.toggle_dropdown_accessible_label'),
},
controls
)

View File

@@ -73,23 +73,25 @@ export default class DiscussionPage extends Page {
<div className="DiscussionPage">
<DiscussionListPane state={app.discussions} />
<div className="DiscussionPage-discussion">
{discussion
? [
DiscussionHero.component({ discussion }),
<div className="container">
<nav className="DiscussionPage-nav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
<div className="DiscussionPage-stream">
{PostStream.component({
discussion,
stream: this.stream,
onPositionChange: this.positionChanged.bind(this),
})}
</div>
</div>,
]
: LoadingIndicator.component({ className: 'LoadingIndicator--block' })}
{discussion ? (
[
DiscussionHero.component({ discussion }),
<div className="container">
<nav className="DiscussionPage-nav">
<ul>{listItems(this.sidebarItems().toArray())}</ul>
</nav>
<div className="DiscussionPage-stream">
{PostStream.component({
discussion,
stream: this.stream,
onPositionChange: this.positionChanged.bind(this),
})}
</div>
</div>,
]
) : (
<LoadingIndicator />
)}
</div>
</div>
);
@@ -189,6 +191,7 @@ export default class DiscussionPage extends Page {
icon: 'fas fa-ellipsis-v',
className: 'App-primaryControl',
buttonClassName: 'Button--primary',
accessibleToggleLabel: app.translator.trans('core.forum.discussion_controls.toggle_dropdown_accessible_label'),
},
DiscussionControls.controls(this.discussion, this).toArray()
)

View File

@@ -237,7 +237,8 @@ export default class EditUserModal extends Modal {
}
/**
* @internal @protected
* @internal
* @protected
*/
userIsAdmin(user) {
return user.groups().some((g) => g.id() === Group.ADMINISTRATOR_ID);

View File

@@ -57,6 +57,7 @@ export default class HeaderSecondary extends Component {
SelectDropdown.component(
{
buttonClassName: 'Button Button--link',
accessibleToggleLabel: app.translator.trans('core.forum.header.locale_dropdown_accessible_label'),
},
locales
),

View File

@@ -172,6 +172,7 @@ export default class IndexPage extends Page {
{
buttonClassName: 'Button',
className: 'App-titleControl',
accessibleToggleLabel: app.translator.trans('core.forum.index.toggle_sidenav_dropdown_accessible_label'),
},
this.navItems(this).toArray()
)
@@ -227,6 +228,7 @@ export default class IndexPage extends Page {
{
buttonClassName: 'Button',
label: sortOptions[app.search.params().sort] || Object.keys(sortMap).map((key) => sortOptions[key])[0],
accessibleToggleLabel: app.translator.trans('core.forum.index_sort.toggle_dropdown_accessible_label'),
},
Object.keys(sortOptions).map((value) => {
const label = sortOptions[value];

View File

@@ -84,7 +84,7 @@ export default class NotificationList extends Component {
})
: ''}
{state.isLoading() ? (
<LoadingIndicator className="LoadingIndicator--block" />
<LoadingIndicator />
) : pages.length ? (
''
) : (

View File

@@ -9,6 +9,8 @@ export default class NotificationsDropdown extends Dropdown {
attrs.menuClassName = attrs.menuClassName || 'Dropdown-menu--right';
attrs.label = attrs.label || app.translator.trans('core.forum.notifications.tooltip');
attrs.icon = attrs.icon || 'fas fa-bell';
// For best a11y support, both `title` and `aria-label` should be used
attrs.accessibleToggleLabel = attrs.accessibleToggleLabel || app.translator.trans('core.forum.notifications.toggle_dropdown_accessible_label');
super.initAttrs(attrs);
}

View File

@@ -61,6 +61,7 @@ export default class Post extends Component {
icon="fas fa-ellipsis-h"
onshow={() => this.$('.Post-actions').addClass('open')}
onhide={() => this.$('.Post-actions').removeClass('open')}
accessibleToggleLabel={app.translator.trans('core.forum.post_controls.toggle_dropdown_accessible_label')}
>
{controls}
</Dropdown>

View File

@@ -112,7 +112,6 @@ export default class PostStreamScrubber extends Component {
// Now we want to make the scrollbar handle draggable. Let's start by
// preventing default browser events from messing things up.
.css({ cursor: 'pointer', 'user-select': 'none' })
.bind('dragstart mousedown touchstart', (e) => e.preventDefault());
// When the mouse is pressed on the scrollbar handle, we capture some
@@ -124,7 +123,6 @@ export default class PostStreamScrubber extends Component {
this.indexStart = 0;
this.$('.Scrubber-handle')
.css('cursor', 'move')
.bind('mousedown touchstart', this.onmousedown.bind(this))
// Exempt the scrollbar handle from the 'jump to' click event.

View File

@@ -121,7 +121,7 @@ export default class PostsUserPage extends UserPage {
loadResults(offset) {
return app.store.find('posts', {
filter: {
user: this.user.id(),
author: this.user.username(),
type: 'comment',
},
page: { offset, limit: this.loadLimit },

View File

@@ -49,7 +49,7 @@ export default class RenameDiscussionModal extends Modal {
this.loading = true;
const title = this.newTitle;
const title = this.newTitle();
const currentTitle = this.currentTitle;
// If the title is different to what it was before, then save it. After the

View File

@@ -71,8 +71,11 @@ export default class Search extends Component {
// Hide the search view if no sources were loaded
if (!this.sources.length) return <div></div>;
const searchLabel = extractText(app.translator.trans('core.forum.header.search_placeholder'));
return (
<div
role="search"
className={
'Search ' +
classList({
@@ -85,16 +88,17 @@ export default class Search extends Component {
>
<div className="Search-input">
<input
aria-label={searchLabel}
className="FormControl"
type="search"
placeholder={extractText(app.translator.trans('core.forum.header.search_placeholder'))}
placeholder={searchLabel}
value={this.state.getValue()}
oninput={(e) => this.state.setValue(e.target.value)}
onfocus={() => (this.hasFocus = true)}
onblur={() => (this.hasFocus = false)}
/>
{this.loadingSources ? (
LoadingIndicator.component({ size: 'tiny', className: 'Button Button--icon Button--link' })
<LoadingIndicator size="small" display="inline" containerClassName="Button Button--icon Button--link" />
) : currentSearch ? (
<button className="Search-clear Button Button--icon Button--link" onclick={this.clear.bind(this)}>
{icon('fas fa-times-circle')}
@@ -110,9 +114,23 @@ export default class Search extends Component {
);
}
updateMaxHeight() {
// Since extensions might add elements above the search box on mobile,
// we need to calculate and set the max height dynamically.
const resultsElementMargin = 14;
const maxHeight =
window.innerHeight - this.element.querySelector('.Search-input>.FormControl').getBoundingClientRect().bottom - resultsElementMargin;
this.element.querySelector('.Search-results').style['max-height'] = `${maxHeight}px`;
}
onupdate() {
// Highlight the item that is currently selected.
this.setIndex(this.getCurrentNumericIndex());
// If there are no sources, the search view is not shown.
if (!this.sources.length) return;
this.updateMaxHeight();
}
oncreate(vnode) {
@@ -177,6 +195,13 @@ export default class Search extends Component {
.one('mouseup', (e) => e.preventDefault())
.select();
});
this.updateMaxHeightHandler = this.updateMaxHeight.bind(this);
window.addEventListener('resize', this.updateMaxHeightHandler);
}
onremove() {
window.removeEventListener('resize', this.updateMaxHeightHandler);
}
/**

View File

@@ -17,6 +17,8 @@ export default class SessionDropdown extends Dropdown {
attrs.className = 'SessionDropdown';
attrs.buttonClassName = 'Button Button--user Button--flat';
attrs.menuClassName = 'Dropdown-menu--right';
attrs.accessibleToggleLabel = app.translator.trans('core.forum.header.session_dropdown_accessible_label');
}
view(vnode) {

View File

@@ -40,6 +40,7 @@ export default class UserCard extends Component {
menuClassName: 'Dropdown-menu--right',
buttonClassName: this.attrs.controlsButtonClassName,
label: app.translator.trans('core.forum.user_controls.button'),
accessibleToggleLabel: app.translator.trans('core.forum.user_controls.toggle_dropdown_accessible_label'),
icon: 'fas fa-ellipsis-v',
},
controls

View File

@@ -51,7 +51,7 @@ export default class UserPage extends Page {
</div>
</div>,
]
: [<LoadingIndicator className="LoadingIndicator--block" />]}
: [<LoadingIndicator display="block" />]}
</div>
);
}

View File

@@ -1,12 +1,8 @@
import 'expose-loader?punycode!punycode';
import 'expose-loader?ColorThief!color-thief-browser';
// Expose punycode and ColorThief to the window browser object
import 'expose-loader?exposes=punycode!punycode';
import 'expose-loader?exposes=ColorThief!color-thief-browser';
import ForumApplication from './ForumApplication';
const app = new ForumApplication();
// Backwards compatibility
window.app = app;
import app from './app';
export { app };

View File

@@ -1,7 +1,7 @@
import subclassOf from '../../common/utils/subclassOf';
import Stream from '../../common/utils/Stream';
import ReplyComposer from '../components/ReplyComposer';
import EditorDriverInterface from '../utils/EditorDriverInterface';
import EditorDriverInterface from '../../common/utils/EditorDriverInterface';
class ComposerState {
constructor() {

View File

@@ -0,0 +1,13 @@
/**
* @see https://stackoverflow.com/a/31732310
*/
export default function isSafariMobile(): boolean {
return (
'ontouchstart' in window &&
navigator.vendor &&
navigator.vendor.includes('Apple') &&
navigator.userAgent &&
!navigator.userAgent.includes('CriOS') &&
!navigator.userAgent.includes('FxiOS')
);
}

View File

@@ -1,15 +1,26 @@
const config = require('flarum-webpack-config');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const merge = require('webpack-merge');
const useBundleAnalyzer = process.env.ANALYZER === 'true';
const plugins = [];
if (useBundleAnalyzer) {
plugins.push(new BundleAnalyzerPlugin());
}
module.exports = merge(config(), {
output: {
library: 'flarum.core'
library: 'flarum.core',
},
// temporary TS configuration
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
plugins,
});
module.exports['module'].rules[0].test = /\.(tsx?|js)$/;

View File

@@ -123,6 +123,9 @@
// the left side of the screen. On other devices, the drawer has no specific
// appearance.
@media @phone {
.App:not(.drawerOpen) .App-drawer {
visibility: hidden;
}
.drawerOpen {
overflow: hidden;
}

View File

@@ -90,14 +90,11 @@
.Button-label {
.transition(margin-right 0.1s);
}
.LoadingIndicator {
.LoadingIndicator-container {
color: inherit;
margin: 0 -5px 0 -15px;
}
&.loading {
.Button-label {
margin-right: 20px;
}
margin-top: -0.175em;
margin-left: 4px;
}
}

View File

@@ -15,13 +15,9 @@
float: left;
margin-left: -65px;
margin-top: -4px;
.LoadingIndicator {
display: inline-block;
margin-left: 20px;
}
}
}
.Checkbox--switch .Checkbox-display {
width: 50px;
height: 28px;
@@ -31,8 +27,28 @@
background: @control-bg;
.transition(background-color 0.2s);
.LoadingIndicator {
--size: 22px !important;
&-container {
height: 22px;
}
}
.on& {
background: #58a400;
.LoadingIndicator-container {
// Show loading indicator over the switch button
justify-content: flex-end;
}
}
.off& {
.LoadingIndicator-container {
// Show loading indicator over the switch button
justify-content: flex-start;
}
}
&:before {

View File

@@ -2,13 +2,64 @@
// Loading Indicators
.LoadingIndicator {
position: relative;
color: @muted-color;
@spin-time: 750ms;
// Use the value of `color` to maintain backwards compatibility
border-color: currentColor;
border-width: var(--thickness);
border-style: solid;
border-top-color: transparent;
border-radius: 50%;
width: var(--size);
height: var(--size);
animation: spin @spin-time linear infinite;
// <div> container around the spinner
// Used for positioning
&-container {
--size: 24px;
--thickness: 2px;
color: @muted-color;
// Center vertically and horizontally
// Allows people to set `height` and it'll stay centered within the new height
display: flex;
align-items: center;
justify-content: center;
// Size
&--large {
--size: 32px;
--thickness: 3px;
}
&--small {
--size: 18px;
}
// Display types
&--block {
height: 100px;
}
&--inline {
display: inline-block;
vertical-align: middle;
}
}
}
.LoadingIndicator--inline {
display: inline-block;
width: 25px;
}
.LoadingIndicator--block {
height: 100px;
@keyframes spin {
from {
transform: rotate(0);
}
to {
transform: rotate(1turn);
}
}

View File

@@ -8,14 +8,14 @@
&.focused {
margin-left: -400px;
input, .Search-results {
input,
.Search-results {
width: 400px;
}
}
}
}
.Search-results {
max-height: 70vh;
overflow: auto;
left: auto;
right: 0;
@@ -62,11 +62,21 @@
.transition(all 0.4s);
box-sizing: inherit !important;
}
.LoadingIndicator-container {
height: 36px;
}
.Button {
float: left;
margin-left: -36px;
width: 36px !important;
outline: none;
width: 36px !important;
&.LoadingIndicator {
width: var(--size) !important;
padding: 0;
}
}
}

View File

@@ -0,0 +1,49 @@
.TextEditor .TextEditor-editor {
border-radius: 0;
padding: 0 0 10px;
border: 0;
resize: none;
color: @text-color;
font-size: 14px;
line-height: 1.7;
&, &:focus, &[disabled] {
background: none;
border: 0;
}
@media @phone {
font-size: 16px; // minimum font-size required to prevent page zoom on focus in iOS 10
}
}
.TextEditor-controls {
margin: 0;
padding: 10px 0;
list-style-type: none;
overflow-x: auto;
white-space: nowrap;
li {
display: inline-block;
margin-right: 10px;
}
}
.TextEditor-toolbar {
.Button--icon {
width: 28px;
}
}
@media @tablet-up {
.TextEditor-controls {
margin: 0 -20px 0 -105px;
padding: 10px 20px;
border-top: 1px solid @control-bg;
.fullScreen & {
margin: 0;
border-top: 0;
padding: 20px 0;
}
}
}

View File

@@ -25,5 +25,6 @@
@import "Placeholder";
@import "Search";
@import "Select";
@import "TextEditor";
@import "Tooltip";
@import "ValidationError";

View File

@@ -1,5 +1,5 @@
.header-background() {
background: fade(@header-bg, 98%);
background: @header-bg;
position: fixed;
top: 0;
left: 0;

View File

@@ -1,227 +1,151 @@
// Vendor Prefixes
//
// All vendor mixins are deprecated as of v3.2.0 due to the introduction of
// Autoprefixer in our Gruntfile. They will be removed in v4.
// - Animations
// - Backface visibility
// - Box shadow
// - Box sizing
// - Content columns
// - Hyphens
// - Placeholder text
// - Transformations
// - Transitions
// - User Select
// These aim to ensure that Flarum remains compatible with most modern devices.
// The vendor presets below are to try to remain compatible with iOS 9+ and other
// major browsers (Chrome/Firefox/new Edge/Safari desktop).
// Animations
// These remain for backwards compatibility with existing styles.
.animation(@animation) {
-webkit-animation: @animation;
-o-animation: @animation;
animation: @animation;
animation: @animation;
}
.animation-name(@name) {
-webkit-animation-name: @name;
animation-name: @name;
animation-name: @name;
}
.animation-duration(@duration) {
-webkit-animation-duration: @duration;
animation-duration: @duration;
animation-duration: @duration;
}
.animation-timing-function(@timing-function) {
-webkit-animation-timing-function: @timing-function;
animation-timing-function: @timing-function;
animation-timing-function: @timing-function;
}
.animation-delay(@delay) {
-webkit-animation-delay: @delay;
animation-delay: @delay;
animation-delay: @delay;
}
.animation-iteration-count(@iteration-count) {
-webkit-animation-iteration-count: @iteration-count;
animation-iteration-count: @iteration-count;
animation-iteration-count: @iteration-count;
}
.animation-direction(@direction) {
-webkit-animation-direction: @direction;
animation-direction: @direction;
animation-direction: @direction;
}
.animation-fill-mode(@fill-mode) {
-webkit-animation-fill-mode: @fill-mode;
animation-fill-mode: @fill-mode;
animation-fill-mode: @fill-mode;
}
// Backface visibility
// Prevent browsers from flickering when using CSS 3D transforms.
// Default value is `visible`, but can be changed to `hidden`
.backface-visibility(@visibility){
.backface-visibility(@visibility) {
// Safari
-webkit-backface-visibility: @visibility;
-moz-backface-visibility: @visibility;
backface-visibility: @visibility;
backface-visibility: @visibility;
}
// Drop shadows
//
// Note: Deprecated `.box-shadow()` as of v3.1.0 since all of Bootstrap's
// supported browsers that have box shadow capabilities now support it.
// These remain for backwards compatibility with existing styles.
.box-shadow(@shadow) {
-webkit-box-shadow: @shadow; // iOS <4.3 & Android <4.1
box-shadow: @shadow;
box-shadow: @shadow;
}
// Box sizing
// These remain for backwards compatibility with existing styles.
.box-sizing(@boxmodel) {
-webkit-box-sizing: @boxmodel;
-moz-box-sizing: @boxmodel;
box-sizing: @boxmodel;
box-sizing: @boxmodel;
}
// CSS3 Content Columns
.content-columns(@column-count; @column-gap: @grid-gutter-width) {
// Safari
-webkit-column-count: @column-count;
-moz-column-count: @column-count;
column-count: @column-count;
column-count: @column-count;
// Safari
-webkit-column-gap: @column-gap;
-moz-column-gap: @column-gap;
column-gap: @column-gap;
column-gap: @column-gap;
}
// Optional hyphenation
.hyphens(@mode: auto) {
word-wrap: break-word;
// Safari
-webkit-hyphens: @mode;
-moz-hyphens: @mode;
-ms-hyphens: @mode; // IE10+
-o-hyphens: @mode;
hyphens: @mode;
hyphens: @mode;
}
// Placeholder text
.placeholder(@color) {
// Firefox
&::-moz-placeholder {
// Safari
&::-webkit-input-placeholder,
&::placeholder {
color: @color;
opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
}
&:-ms-input-placeholder { color: @color; } // Internet Explorer 10+
&::-webkit-input-placeholder { color: @color; } // Safari and Chrome
}
// Transformations
// These remain for backwards compatibility with existing styles.
.scale(@ratio) {
-webkit-transform: scale(@ratio);
-ms-transform: scale(@ratio); // IE9 only
-o-transform: scale(@ratio);
transform: scale(@ratio);
transform: scale(@ratio);
}
.scale(@ratioX; @ratioY) {
-webkit-transform: scale(@ratioX, @ratioY);
-ms-transform: scale(@ratioX, @ratioY); // IE9 only
-o-transform: scale(@ratioX, @ratioY);
transform: scale(@ratioX, @ratioY);
transform: scale(@ratioX, @ratioY);
}
.scaleX(@ratio) {
-webkit-transform: scaleX(@ratio);
-ms-transform: scaleX(@ratio); // IE9 only
-o-transform: scaleX(@ratio);
transform: scaleX(@ratio);
transform: scaleX(@ratio);
}
.scaleY(@ratio) {
-webkit-transform: scaleY(@ratio);
-ms-transform: scaleY(@ratio); // IE9 only
-o-transform: scaleY(@ratio);
transform: scaleY(@ratio);
transform: scaleY(@ratio);
}
.skew(@x; @y) {
-webkit-transform: skewX(@x) skewY(@y);
-ms-transform: skewX(@x) skewY(@y); // See https://github.com/twbs/bootstrap/issues/4885; IE9+
-o-transform: skewX(@x) skewY(@y);
transform: skewX(@x) skewY(@y);
transform: skewX(@x) skewY(@y);
}
.translate(@x; @y) {
-webkit-transform: translate(@x, @y);
-ms-transform: translate(@x, @y); // IE9 only
-o-transform: translate(@x, @y);
transform: translate(@x, @y);
transform: translate(@x, @y);
}
.translate3d(@x; @y; @z) {
-webkit-transform: translate3d(@x, @y, @z);
transform: translate3d(@x, @y, @z);
transform: translate3d(@x, @y, @z);
}
.rotate(@degrees) {
-webkit-transform: rotate(@degrees);
-ms-transform: rotate(@degrees); // IE9 only
-o-transform: rotate(@degrees);
transform: rotate(@degrees);
transform: rotate(@degrees);
}
.rotateX(@degrees) {
-webkit-transform: rotateX(@degrees);
-ms-transform: rotateX(@degrees); // IE9 only
-o-transform: rotateX(@degrees);
transform: rotateX(@degrees);
transform: rotateX(@degrees);
}
.rotateY(@degrees) {
-webkit-transform: rotateY(@degrees);
-ms-transform: rotateY(@degrees); // IE9 only
-o-transform: rotateY(@degrees);
transform: rotateY(@degrees);
transform: rotateY(@degrees);
}
.perspective(@perspective) {
-webkit-perspective: @perspective;
-moz-perspective: @perspective;
perspective: @perspective;
perspective: @perspective;
}
.perspective-origin(@perspective) {
-webkit-perspective-origin: @perspective;
-moz-perspective-origin: @perspective;
perspective-origin: @perspective;
perspective-origin: @perspective;
}
.transform-origin(@origin) {
-webkit-transform-origin: @origin;
-moz-transform-origin: @origin;
-ms-transform-origin: @origin; // IE9 only
transform-origin: @origin;
transform-origin: @origin;
}
// Transitions
// These remain for backwards compatibility with existing styles.
.transition(@transition) {
-webkit-transition: @transition;
-o-transition: @transition;
transition: @transition;
transition: @transition;
}
.transition-property(@transition-property) {
-webkit-transition-property: @transition-property;
transition-property: @transition-property;
transition-property: @transition-property;
}
.transition-delay(@transition-delay) {
-webkit-transition-delay: @transition-delay;
transition-delay: @transition-delay;
transition-delay: @transition-delay;
}
.transition-duration(@transition-duration) {
-webkit-transition-duration: @transition-duration;
transition-duration: @transition-duration;
transition-duration: @transition-duration;
}
.transition-timing-function(@timing-function) {
-webkit-transition-timing-function: @timing-function;
transition-timing-function: @timing-function;
transition-timing-function: @timing-function;
}
.transition-transform(@transition) {
-webkit-transition: -webkit-transform @transition;
-moz-transition: -moz-transform @transition;
-o-transition: -o-transform @transition;
transition: transform @transition;
transition: transform @transition;
}
// User select
// For selecting text on the page
.user-select(@select) {
// Safari + MS Edge
-webkit-user-select: @select;
-moz-user-select: @select;
-ms-user-select: @select; // IE10+
user-select: @select;
user-select: @select;
}

View File

@@ -2,7 +2,7 @@
text-align: center;
margin-top: 10px;
.LoadingIndicator {
.LoadingIndicator-container {
height: 46px;
}
}

View File

@@ -23,7 +23,7 @@
&.dragover .Dropdown-toggle {
opacity: 1;
}
.LoadingIndicator {
.LoadingIndicator-container {
color: #fff;
position: absolute;
left: 0;

View File

@@ -92,7 +92,7 @@
border-radius: @border-radius @border-radius 0 0;
&.active {
display: block;
display: flex;
}
}
.ComposerBody-editor {
@@ -120,6 +120,12 @@
max-height: 100%;
padding-top: @header-height-phone;
// Fixes a bug where fixed position doesn't properly work in Safari mobile
// https://github.com/flarum/core/issues/2652
.mobile-safari & {
position: absolute;
}
&:before {
content: " ";
.header-background();
@@ -319,56 +325,3 @@
left: @pane-width;
}
}
// ------------------------------------
// Text Editor
.TextEditor .TextEditor-editor {
border-radius: 0;
padding: 0 0 10px;
border: 0;
resize: none;
color: @text-color;
font-size: 14px;
line-height: 1.7;
&, &:focus, &[disabled] {
background: none;
border: 0;
}
@media @phone {
font-size: 16px; // minimum font-size required to prevent page zoom on focus in iOS 10
}
}
.TextEditor-controls {
margin: 0;
padding: 10px 0;
list-style-type: none;
overflow-x: auto;
white-space: nowrap;
li {
display: inline-block;
margin-right: 10px;
}
}
.TextEditor-toolbar {
.Button--icon {
width: 28px;
}
}
@media @tablet-up {
.TextEditor-controls {
margin: 0 -20px 0 -105px;
padding: 10px 20px;
border-top: 1px solid @control-bg;
.fullScreen & {
margin: 0;
border-top: 0;
padding: 20px 0;
}
}
}

View File

@@ -10,9 +10,10 @@
.DiscussionList-loadMore {
text-align: center;
margin-top: 10px;
}
.DiscussionList-loadMore .LoadingIndicator {
height: 46px;
.LoadingIndicator-container {
height: 46px;
}
}
@media @phone {

View File

@@ -18,6 +18,8 @@
height: 300px;
min-height: 50px; // JavaScript sets a max-height
position: relative;
cursor: pointer;
.user-select(none);
}
.Scrubber-before, .Scrubber-after {
border-left: 1px solid @control-bg;
@@ -42,6 +44,7 @@
background: transparent;
width: 100%;
padding: 5px 0;
cursor: move;
}
.Scrubber-bar {
height: 100%;

View File

@@ -278,6 +278,7 @@ core:
rename_button: => core.ref.rename
reply_button: => core.ref.reply
restore_button: => core.ref.restore
toggle_dropdown_accessible_label: Toggle discussion actions dropdown menu
# These translations are used in the discussion list.
discussion_list:
@@ -316,10 +317,12 @@ core:
header:
admin_button: Administration
back_to_index_tooltip: Back to Discussion List
locale_dropdown_accessible_label: Change forum locale
log_in_link: => core.ref.log_in
log_out_button: => core.ref.log_out
profile_button: Profile
search_placeholder: Search Forum
session_dropdown_accessible_label: Toggle session options dropdown menu
settings_button: => core.ref.settings
sign_up_link: => core.ref.sign_up
@@ -332,6 +335,7 @@ core:
meta_title_text: => core.ref.all_discussions
refresh_tooltip: Refresh
start_discussion_button: => core.ref.start_a_discussion
toggle_sidenav_dropdown_accessible_label: Toggle navigation dropdown menu
# These translations are used by the sorting control above the discussion list.
index_sort:
@@ -339,6 +343,7 @@ core:
newest_button: Newest
oldest_button: Oldest
relevance_button: Relevance
toggle_dropdown_accessible_label: Change discussion list sorting
top_button: Top
# These translations are used in the Log In modal dialog.
@@ -359,6 +364,7 @@ core:
mark_all_as_read_tooltip: => core.ref.mark_all_as_read
mark_as_read_tooltip: Mark as Read
title: => core.ref.notifications
toggle_dropdown_accessible_label: View notifications
tooltip: => core.ref.notifications
# These translations are used by tooltips displayed for individual posts.
@@ -375,6 +381,7 @@ core:
edit_button: => core.ref.edit
hide_confirmation: "Are you sure you want to delete this post?"
restore_button: => core.ref.restore
toggle_dropdown_accessible_label: Toggle post controls dropdown menu
# These translations are used in the scrubber to the right of the post stream.
post_scrubber:
@@ -448,6 +455,7 @@ core:
delete_error_message: "Deletion of user <i>{username} ({email})</i> failed"
delete_success_message: "User <i>{username} ({email})</i> was deleted"
edit_button: => core.ref.edit
toggle_dropdown_accessible_label: Toggle user controls dropdown menu
# These translations are used in the alert that is shown when a new user has not confirmed their email address.
user_email_confirmation:
@@ -462,6 +470,10 @@ core:
badge:
hidden_tooltip: Hidden
# These translations are used in the dropdown component.
dropdown:
toggle_dropdown_accessible_label: Toggle dropdown menu
# These translations are displayed as error messages.
error:
dependent_extensions_message: "Cannot disable {extension} until the following dependent extensions are disabled: {extensions}"
@@ -471,6 +483,10 @@ core:
permission_denied_message: You do not have permission to do that.
rate_limit_exceeded_message: You're going a little too quickly. Please try again in a few seconds.
# These translations are used in the loading indicator component.
loading_indicator:
accessible_label: => core.ref.loading
# These translations are used as suffixes when abbreviating numbers.
number_suffix:
kilo_text: K
@@ -493,7 +509,7 @@ core:
content:
javascript_disabled_message: This site is best viewed in a modern browser with JavaScript enabled.
load_error_message: Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.
loading_text: Loading...
loading_text: => core.ref.loading
# Translations in this namespace are displayed in the basic HTML discussion view.
discussion:
@@ -612,6 +628,7 @@ core:
icon: Icon
icon_text: "Enter the name of any <a>FontAwesome</a> icon class, <em>including</em> the <code>fas fa-</code> prefix."
load_more: Load More
loading: Loading...
log_in: Log In
log_out: Log Out
mark_all_as_read: Mark All as Read

View File

@@ -30,8 +30,6 @@ return [
$table->integer('hide_user_id')->unsigned()->nullable();
$table->unique(['discussion_id', 'number']);
$table->engine = 'MyISAM';
});
$connection = $schema->getConnection();

View File

@@ -0,0 +1,43 @@
<?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.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->string('type', 100)->index();
});
// Since all active sessions will stop working on update due to switching from user_id to access_token
// We can do things simple here by terminating all tokens that have the previously default lifetime
$schema->getConnection()->table('access_tokens')
->where('lifetime_seconds', 3600)
->delete();
// We will then assume that all remaining tokens are remember tokens
// This will include tokens that previously had a custom lifetime
$schema->getConnection()->table('access_tokens')
->update([
'type' => 'session_remember',
]);
$schema->table('access_tokens', function (Blueprint $table) {
$table->dropColumn('lifetime_seconds');
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->dropColumn('type');
$table->integer('lifetime_seconds');
});
}
];

View File

@@ -0,0 +1,35 @@
<?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.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
// Replace primary key with unique index so we can create a new primary
$table->dropPrimary('token');
$table->unique('token');
});
// This needs to be done in a second statement because of the order Laravel runs operations in
$schema->table('access_tokens', function (Blueprint $table) {
// Introduce new increment-based ID
$table->increments('id')->first();
});
},
'down' => function (Builder $schema) {
$schema->table('access_tokens', function (Blueprint $table) {
$table->dropColumn('id');
$table->dropIndex('token');
$table->primary('token');
});
}
];

View File

@@ -0,0 +1,21 @@
<?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.
*/
use Flarum\Database\Migration;
return Migration::addColumns('access_tokens', [
'title' => ['string', 'length' => 150, 'nullable' => true],
// Accommodates both IPv4 and IPv6 as strings
'last_ip_address' => ['string', 'length' => 45, 'nullable' => true],
// Technically, there's no limit to a user agent length
// Most are around 150 in length, and the general recommendation seems to be below 200
// We're going to use the longest string possible to be safe
// There will still be exceptions, we'll just truncate them
'last_user_agent' => ['string', 'length' => 255, 'nullable' => true],
]);

View File

@@ -0,0 +1,27 @@
<?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.
*/
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return [
'up' => function (Builder $schema) {
if (! $schema->hasColumn('migrations', 'id')) {
$schema->table('migrations', function (Blueprint $table) {
$table->increments('id')->first();
});
}
},
'down' => function (Builder $schema) {
$schema->table('migrations', function (Blueprint $table) {
$table->dropColumn('id');
});
}
];

View File

@@ -36,19 +36,20 @@ class AdminServiceProvider extends AbstractServiceProvider
*/
public function register()
{
$this->app->extend(UrlGenerator::class, function (UrlGenerator $url) {
return $url->addCollection('admin', $this->app->make('flarum.admin.routes'), 'admin');
$this->container->extend(UrlGenerator::class, function (UrlGenerator $url) {
return $url->addCollection('admin', $this->container->make('flarum.admin.routes'), 'admin');
});
$this->app->singleton('flarum.admin.routes', function () {
$this->container->singleton('flarum.admin.routes', function () {
$routes = new RouteCollection;
$this->populateRoutes($routes);
return $routes;
});
$this->app->singleton('flarum.admin.middleware', function () {
$this->container->singleton('flarum.admin.middleware', function () {
return [
HttpMiddleware\InjectActorReference::class,
'flarum.admin.error_handler',
HttpMiddleware\ParseJsonBody::class,
HttpMiddleware\StartSession::class,
@@ -61,23 +62,23 @@ class AdminServiceProvider extends AbstractServiceProvider
];
});
$this->app->bind('flarum.admin.error_handler', function () {
$this->container->bind('flarum.admin.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
$this->app['flarum.config']->inDebugMode() ? $this->app->make(WhoopsFormatter::class) : $this->app->make(ViewFormatter::class),
$this->app->tagged(Reporter::class)
$this->container->make(Registry::class),
$this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class),
$this->container->tagged(Reporter::class)
);
});
$this->app->bind('flarum.admin.route_resolver', function () {
return new HttpMiddleware\ResolveRoute($this->app->make('flarum.admin.routes'));
$this->container->bind('flarum.admin.route_resolver', function () {
return new HttpMiddleware\ResolveRoute($this->container->make('flarum.admin.routes'));
});
$this->app->singleton('flarum.admin.handler', function () {
$this->container->singleton('flarum.admin.handler', function () {
$pipe = new MiddlewarePipe;
foreach ($this->app->make('flarum.admin.middleware') as $middleware) {
$pipe->pipe($this->app->make($middleware));
foreach ($this->container->make('flarum.admin.middleware') as $middleware) {
$pipe->pipe($this->container->make($middleware));
}
$pipe->pipe(new HttpMiddleware\ExecuteRoute());
@@ -85,9 +86,9 @@ class AdminServiceProvider extends AbstractServiceProvider
return $pipe;
});
$this->app->bind('flarum.assets.admin', function () {
$this->container->bind('flarum.assets.admin', function () {
/** @var \Flarum\Frontend\Assets $assets */
$assets = $this->app->make('flarum.assets.factory')('admin');
$assets = $this->container->make('flarum.assets.factory')('admin');
$assets->js(function (SourceCollector $sources) {
$sources->addFile(__DIR__.'/../../js/dist/admin.js');
@@ -97,17 +98,17 @@ class AdminServiceProvider extends AbstractServiceProvider
$sources->addFile(__DIR__.'/../../less/admin.less');
});
$this->app->make(AddTranslations::class)->forFrontend('admin')->to($assets);
$this->app->make(AddLocaleAssets::class)->to($assets);
$this->container->make(AddTranslations::class)->forFrontend('admin')->to($assets);
$this->container->make(AddLocaleAssets::class)->to($assets);
return $assets;
});
$this->app->bind('flarum.frontend.admin', function () {
$this->container->bind('flarum.frontend.admin', function () {
/** @var \Flarum\Frontend\Frontend $frontend */
$frontend = $this->app->make('flarum.frontend.factory')('admin');
$frontend = $this->container->make('flarum.frontend.factory')('admin');
$frontend->content($this->app->make(Content\AdminPayload::class));
$frontend->content($this->container->make(Content\AdminPayload::class));
return $frontend;
});
@@ -120,14 +121,14 @@ class AdminServiceProvider extends AbstractServiceProvider
{
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.admin');
$events = $this->app->make('events');
$events = $this->container->make('events');
$events->listen(
[Enabled::class, Disabled::class, ClearingCache::class],
function () {
$recompile = new RecompileFrontendAssets(
$this->app->make('flarum.assets.admin'),
$this->app->make(LocaleManager::class)
$this->container->make('flarum.assets.admin'),
$this->container->make(LocaleManager::class)
);
$recompile->flush();
}
@@ -137,8 +138,8 @@ class AdminServiceProvider extends AbstractServiceProvider
Saved::class,
function (Saved $event) {
$recompile = new RecompileFrontendAssets(
$this->app->make('flarum.assets.admin'),
$this->app->make(LocaleManager::class)
$this->container->make('flarum.assets.admin'),
$this->container->make(LocaleManager::class)
);
$recompile->whenSettingsSaved($event);
}
@@ -150,7 +151,7 @@ class AdminServiceProvider extends AbstractServiceProvider
*/
protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$factory = $this->container->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);

View File

@@ -9,6 +9,7 @@
namespace Flarum\Admin\Middleware;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
@@ -18,7 +19,7 @@ class RequireAdministrateAbility implements Middleware
{
public function process(Request $request, Handler $handler): Response
{
$request->getAttribute('actor')->assertAdmin();
RequestUtil::getActor($request)->assertAdmin();
return $handler->handle($request);
}

View File

@@ -30,18 +30,18 @@ class ApiServiceProvider extends AbstractServiceProvider
*/
public function register()
{
$this->app->extend(UrlGenerator::class, function (UrlGenerator $url) {
return $url->addCollection('api', $this->app->make('flarum.api.routes'), 'api');
$this->container->extend(UrlGenerator::class, function (UrlGenerator $url) {
return $url->addCollection('api', $this->container->make('flarum.api.routes'), 'api');
});
$this->app->singleton('flarum.api.routes', function () {
$this->container->singleton('flarum.api.routes', function () {
$routes = new RouteCollection;
$this->populateRoutes($routes);
return $routes;
});
$this->app->singleton('flarum.api.throttlers', function () {
$this->container->singleton('flarum.api.throttlers', function () {
return [
'bypassThrottlingAttribute' => function ($request) {
if ($request->getAttribute('bypassThrottling')) {
@@ -51,12 +51,13 @@ class ApiServiceProvider extends AbstractServiceProvider
];
});
$this->app->bind(Middleware\ThrottleApi::class, function ($app) {
return new Middleware\ThrottleApi($app->make('flarum.api.throttlers'));
$this->container->bind(Middleware\ThrottleApi::class, function ($container) {
return new Middleware\ThrottleApi($container->make('flarum.api.throttlers'));
});
$this->app->singleton('flarum.api.middleware', function () {
$this->container->singleton('flarum.api.middleware', function () {
return [
HttpMiddleware\InjectActorReference::class,
'flarum.api.error_handler',
HttpMiddleware\ParseJsonBody::class,
Middleware\FakeHttpMethods::class,
@@ -71,23 +72,23 @@ class ApiServiceProvider extends AbstractServiceProvider
];
});
$this->app->bind('flarum.api.error_handler', function () {
$this->container->bind('flarum.api.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
new JsonApiFormatter($this->app['flarum.config']->inDebugMode()),
$this->app->tagged(Reporter::class)
$this->container->make(Registry::class),
new JsonApiFormatter($this->container['flarum.config']->inDebugMode()),
$this->container->tagged(Reporter::class)
);
});
$this->app->bind('flarum.api.route_resolver', function () {
return new HttpMiddleware\ResolveRoute($this->app->make('flarum.api.routes'));
$this->container->bind('flarum.api.route_resolver', function () {
return new HttpMiddleware\ResolveRoute($this->container->make('flarum.api.routes'));
});
$this->app->singleton('flarum.api.handler', function () {
$this->container->singleton('flarum.api.handler', function () {
$pipe = new MiddlewarePipe;
foreach ($this->app->make('flarum.api.middleware') as $middleware) {
$pipe->pipe($this->app->make($middleware));
foreach ($this->container->make('flarum.api.middleware') as $middleware) {
$pipe->pipe($this->container->make($middleware));
}
$pipe->pipe(new HttpMiddleware\ExecuteRoute());
@@ -95,7 +96,7 @@ class ApiServiceProvider extends AbstractServiceProvider
return $pipe;
});
$this->app->singleton('flarum.api.notification_serializers', function () {
$this->container->singleton('flarum.api.notification_serializers', function () {
return [
'discussionRenamed' => BasicDiscussionSerializer::class
];
@@ -109,9 +110,9 @@ class ApiServiceProvider extends AbstractServiceProvider
{
$this->setNotificationSerializers();
AbstractSerializeController::setContainer($this->app);
AbstractSerializeController::setContainer($this->container);
AbstractSerializer::setContainer($this->app);
AbstractSerializer::setContainer($this->container);
}
/**
@@ -119,7 +120,7 @@ class ApiServiceProvider extends AbstractServiceProvider
*/
protected function setNotificationSerializers()
{
$serializers = $this->app->make('flarum.api.notification_serializers');
$serializers = $this->container->make('flarum.api.notification_serializers');
foreach ($serializers as $type => $serializer) {
NotificationSerializer::setSubjectSerializer($type, $serializer);
@@ -133,7 +134,7 @@ class ApiServiceProvider extends AbstractServiceProvider
*/
protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$factory = $this->container->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);

View File

@@ -12,6 +12,7 @@ namespace Flarum\Api;
use Exception;
use Flarum\Foundation\ErrorHandling\JsonApiFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Http\RequestUtil;
use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
@@ -56,7 +57,7 @@ class Client
{
$request = ServerRequestFactory::fromGlobals(null, $queryParams, $body);
$request = $request->withAttribute('actor', $actor);
$request = RequestUtil::withActor($request, $actor);
if (is_string($controller)) {
$controller = $this->container->make($controller);

View File

@@ -11,6 +11,9 @@ namespace Flarum\Api\Controller;
use Flarum\Api\JsonApiResponse;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
@@ -84,6 +87,11 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
*/
protected static $beforeSerializationCallbacks = [];
/**
* @var array
*/
protected static $loadRelations = [];
/**
* {@inheritdoc}
*/
@@ -139,6 +147,47 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
*/
abstract protected function createElement($data, SerializerInterface $serializer);
/**
* Eager loads the required relationships.
*
* @param Collection $models
* @param array $relations
* @return void
*/
protected function loadRelations(Collection $models, array $relations): void
{
$addedRelations = [];
foreach (array_reverse(array_merge([static::class], class_parents($this))) as $class) {
if (isset(static::$loadRelations[$class])) {
$addedRelations = array_merge($addedRelations, static::$loadRelations[$class]);
}
}
if (! empty($addedRelations)) {
usort($addedRelations, function ($a, $b) {
return substr_count($a, '.') - substr_count($b, '.');
});
foreach ($addedRelations as $relation) {
if (strpos($relation, '.') !== false) {
$parentRelation = Str::beforeLast($relation, '.');
if (! in_array($parentRelation, $relations, true)) {
continue;
}
}
$relations[] = $relation;
}
}
if (! empty($relations)) {
$relations = array_unique($relations);
$models->loadMissing($relations);
}
}
/**
* @param ServerRequestInterface $request
* @return array
@@ -207,6 +256,11 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
return new Parameters($request->getQueryParams());
}
protected function sortIsDefault(ServerRequestInterface $request): bool
{
return ! Arr::get($request->getQueryParams(), 'sort');
}
/**
* Set the serializer that will serialize data for the endpoint.
*
@@ -348,4 +402,13 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
static::$beforeSerializationCallbacks[$controllerClass][] = $callback;
}
public static function setLoadRelations(string $controllerClass, array $relations)
{
if (! isset(static::$loadRelations[$controllerClass])) {
static::$loadRelations[$controllerClass] = [];
}
static::$loadRelations[$controllerClass] = array_merge(static::$loadRelations[$controllerClass], $relations);
}
}

View File

@@ -10,6 +10,7 @@
namespace Flarum\Api\Controller;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Http\RequestUtil;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\Console\Input\ArrayInput;
@@ -35,7 +36,7 @@ class ClearCacheController extends AbstractDeleteController
*/
protected function delete(ServerRequestInterface $request)
{
$request->getAttribute('actor')->assertAdmin();
RequestUtil::getActor($request)->assertAdmin();
$this->command->run(
new ArrayInput([]),

View File

@@ -12,6 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Discussion\Command\ReadDiscussion;
use Flarum\Discussion\Command\StartDiscussion;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@@ -53,7 +54,7 @@ class CreateDiscussionController extends AbstractCreateController
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$ipAddress = $request->getAttribute('ipAddress');
$discussion = $this->bus->dispatch(

View File

@@ -11,6 +11,7 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\GroupSerializer;
use Flarum\Group\Command\CreateGroup;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
@@ -42,7 +43,7 @@ class CreateGroupController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new CreateGroup($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
new CreateGroup(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
);
}
}

View File

@@ -11,6 +11,7 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Discussion\Command\ReadDiscussion;
use Flarum\Http\RequestUtil;
use Flarum\Post\Command\PostReply;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
@@ -52,7 +53,7 @@ class CreatePostController extends AbstractCreateController
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
$ipAddress = $request->getAttribute('ipAddress');

View File

@@ -9,7 +9,8 @@
namespace Flarum\Api\Controller;
use Flarum\Http\AccessToken;
use Flarum\Http\RememberAccessToken;
use Flarum\Http\SessionAccessToken;
use Flarum\User\Exception\NotAuthenticatedException;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
@@ -58,7 +59,6 @@ class CreateTokenController implements RequestHandlerInterface
$identification = Arr::get($body, 'identification');
$password = Arr::get($body, 'password');
$lifetime = Arr::get($body, 'lifetime', 3600);
$user = $this->users->findByIdentification($identification);
@@ -66,8 +66,14 @@ class CreateTokenController implements RequestHandlerInterface
throw new NotAuthenticatedException;
}
$token = AccessToken::generate($user->id, $lifetime);
$token->save();
if (Arr::get($body, 'remember')) {
$token = RememberAccessToken::generate($user->id);
} else {
$token = SessionAccessToken::generate($user->id);
}
// We do a first update here to log the IP/agent of the token creator, even if the token is never used afterwards
$token->touch($request);
return new JsonResponse([
'token' => $token->token,

Some files were not shown because too many files have changed in this diff Show More