···11+<?php
22+33+/**
44+ * Copyright 2015 ppy Pty. Ltd.
55+ *
66+ * This file is part of osu!web. osu!web is distributed with the hope of
77+ * attracting more community contributions to the core ecosystem of osu!.
88+ *
99+ * osu!web is free software: you can redistribute it and/or modify
1010+ * it under the terms of the Affero GNU General Public License version 3
1111+ * as published by the Free Software Foundation.
1212+ *
1313+ * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1414+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1515+ * See the GNU Affero General Public License for more details.
1616+ *
1717+ * You should have received a copy of the GNU Affero General Public License
1818+ * along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1919+ */
2020+2121+namespace App\Http\Controllers;
2222+2323+use App;
2424+use App\Exceptions\GitHubNotFoundException;
2525+use App\Models\WikiPage;
2626+use Request;
2727+use View;
2828+2929+class WikiController extends Controller
3030+{
3131+ protected $section = 'help';
3232+ protected $actionPrefix = 'wiki-';
3333+3434+ public function show($path)
3535+ {
3636+ if (in_array(pathinfo($path, PATHINFO_EXTENSION), ['jpg', 'jpeg', 'png'], true)) {
3737+ try {
3838+ return response(WikiPage::fetchContent($path), 200)->header('Content-Type', 'image');
3939+ } catch (GitHubNotFoundException $e) {
4040+ abort(404);
4141+ }
4242+ }
4343+4444+ $locale = Request::input('locale', App::getLocale());
4545+ $pageLocales = WikiPage::pageLocales($path);
4646+ $titles = explode('/', str_replace('-', ' ', trim($path, '/')), 2);
4747+ $title = array_pop($titles);
4848+ $subtitle = array_pop($titles);
4949+5050+ try {
5151+ $page = WikiPage::page($path, $locale);
5252+ } catch (GitHubNotFoundException $e) {
5353+ $page = null;
5454+ }
5555+5656+ return view('wiki.show', compact(
5757+ 'locale',
5858+ 'page',
5959+ 'pageLocales',
6060+ 'path',
6161+ 'subtitle',
6262+ 'title'
6363+ ));
6464+ }
6565+}
···11+<?php
22+33+/**
44+ * Copyright 2015 ppy Pty. Ltd.
55+ *
66+ * This file is part of osu!web. osu!web is distributed with the hope of
77+ * attracting more community contributions to the core ecosystem of osu!.
88+ *
99+ * osu!web is free software: you can redistribute it and/or modify
1010+ * it under the terms of the Affero GNU General Public License version 3
1111+ * as published by the Free Software Foundation.
1212+ *
1313+ * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1414+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1515+ * See the GNU Affero General Public License for more details.
1616+ *
1717+ * You should have received a copy of the GNU Affero General Public License
1818+ * along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1919+ */
2020+2121+namespace App\Models;
2222+2323+use App\Exceptions\GitHubNotFoundException;
2424+use Cache;
2525+use GitHub;
2626+use Github\Exception\RuntimeException as GithubException;
2727+2828+class WikiPage
2929+{
3030+ public static function fetch($path)
3131+ {
3232+ return Cache::remember("wiki:{$path}", 60, function () use ($path) {
3333+ try {
3434+ return GitHub::repo()
3535+ ->contents()
3636+ ->show('ppy', 'osu-wiki', 'wiki/'.$path);
3737+ } catch (GithubException $e) {
3838+ if ($e->getMessage() === 'Not Found') {
3939+ throw new GitHubNotFoundException();
4040+ }
4141+4242+ throw $e;
4343+ }
4444+ });
4545+ }
4646+4747+ public static function fetchContent($path)
4848+ {
4949+ return base64_decode(static::fetch($path)['content'], true);
5050+ }
5151+5252+ public static function page($page, $locale)
5353+ {
5454+ return static::fetchContent($page.'/'.$locale.'.md');
5555+ }
5656+5757+ public static function pageLocales($page)
5858+ {
5959+ $locales = [];
6060+6161+ try {
6262+ $contents = static::fetch($page);
6363+ } catch (GitHubNotFoundException $e) {
6464+ return $locales;
6565+ }
6666+6767+ foreach ($contents as $content) {
6868+ $locales[] = str_replace('.md', '', $content['name']);
6969+ }
7070+7171+ return $locales;
7272+ }
7373+}
···11+<?php
22+33+/*
44+ * This file is part of Laravel GitHub.
55+ *
66+ * (c) Graham Campbell <graham@alt-three.com>
77+ *
88+ * For the full copyright and license information, please view the LICENSE
99+ * file that was distributed with this source code.
1010+ */
1111+1212+return [
1313+1414+ /*
1515+ |--------------------------------------------------------------------------
1616+ | Default Connection Name
1717+ |--------------------------------------------------------------------------
1818+ |
1919+ | Here you may specify which of the connections below you wish to use as
2020+ | your default connection for all work. Of course, you may use many
2121+ | connections at once using the manager class.
2222+ |
2323+ */
2424+2525+ 'default' => 'main',
2626+2727+ /*
2828+ |--------------------------------------------------------------------------
2929+ | GitHub Connections
3030+ |--------------------------------------------------------------------------
3131+ |
3232+ | Here are each of the connections setup for your application. Example
3333+ | configuration has been included, but you may add as many connections as
3434+ | you would like. Note that the 3 supported authentication methods are:
3535+ | "application", "password", and "token".
3636+ |
3737+ */
3838+3939+ 'connections' => [
4040+4141+ 'main' => [
4242+ 'token' => env('GITHUB_TOKEN'),
4343+ 'method' => 'token',
4444+ // 'backoff' => false,
4545+ // 'cache' => false,
4646+ // 'version' => 'v3',
4747+ // 'enterprise' => false,
4848+ ],
4949+5050+ 'alternative' => [
5151+ 'clientId' => 'your-client-id',
5252+ 'clientSecret' => 'your-client-secret',
5353+ 'method' => 'application',
5454+ // 'backoff' => false,
5555+ // 'cache' => false,
5656+ // 'version' => 'v3',
5757+ // 'enterprise' => false,
5858+ ],
5959+6060+ 'other' => [
6161+ 'username' => 'your-username',
6262+ 'password' => 'your-password',
6363+ 'method' => 'password',
6464+ // 'backoff' => false,
6565+ // 'cache' => false,
6666+ // 'version' => 'v3',
6767+ // 'enterprise' => false,
6868+ ],
6969+7070+ ],
7171+7272+];
···11+/**
22+ * Copyright 2015-2016 ppy Pty. Ltd.
33+ *
44+ * This file is part of osu!web. osu!web is distributed with the hope of
55+ * attracting more community contributions to the core ecosystem of osu!.
66+ *
77+ * osu!web is free software: you can redistribute it and/or modify
88+ * it under the terms of the Affero GNU General Public License version 3
99+ * as published by the Free Software Foundation.
1010+ *
1111+ * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1212+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1313+ * See the GNU Affero General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU Affero General Public License
1616+ * along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1717+ *
1818+ */
1919+2020+// this isn't actually bem =D
2121+// don't put anything else inside
2222+.wiki-content {
2323+ .content-font();
2424+ padding: (@spacing * 4) (@spacing * 2);
2525+2626+ @media @desktop {
2727+ padding-left: @padding-big;
2828+ padding-right: @padding-big;
2929+ }
3030+3131+ h1 {
3232+ font-family: @font-family-sans-serif;
3333+ font-size: @font-size--header-wiki-1;
3434+ font-weight: bold;
3535+ margin: (@spacing * 4) 0 (@spacing * 2);
3636+ }
3737+3838+ h2 {
3939+ font-family: @font-family-sans-serif;
4040+ font-size: @font-size--header-wiki-2;
4141+ font-weight: bold;
4242+ margin: (@spacing * 2) 0 @spacing;
4343+ }
4444+4545+ h3 {
4646+ font-family: @font-family-sans-serif;
4747+ font-size: @font-size--header-wiki-3;
4848+ font-weight: bold;
4949+ }
5050+}
+38
resources/assets/less/bem/wiki-language-list.less
···11+/**
22+ * Copyright 2015-2016 ppy Pty. Ltd.
33+ *
44+ * This file is part of osu!web. osu!web is distributed with the hope of
55+ * attracting more community contributions to the core ecosystem of osu!.
66+ *
77+ * osu!web is free software: you can redistribute it and/or modify
88+ * it under the terms of the Affero GNU General Public License version 3
99+ * as published by the Free Software Foundation.
1010+ *
1111+ * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1212+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1313+ * See the GNU Affero General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU Affero General Public License
1616+ * along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1717+ *
1818+ */
1919+2020+.wiki-language-list {
2121+ background-color: @gray-e;
2222+ display: flex;
2323+ flex-wrap: wrap;
2424+2525+ font-style: italic;
2626+ font-size: @font-size--title-small;
2727+2828+ padding: (@spacing * 2);
2929+3030+ @media @desktop {
3131+ padding-left: @padding-big;
3232+ padding-right: @padding-big;
3333+ }
3434+3535+ &__item {
3636+ padding-left: (@spacing * 2);
3737+ }
3838+}
···11+<?php
22+33+/**
44+ * Copyright 2015 ppy Pty. Ltd.
55+ *
66+ * This file is part of osu!web. osu!web is distributed in the hopes of
77+ * attracting more community contributions to the core ecosystem of osu!
88+ *
99+ * osu!web is free software: you can redistribute it and/or modify
1010+ * it under the terms of the Affero GNU General Public License version 3
1111+ * as published by the Free Software Foundation.
1212+ *
1313+ * osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1414+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1515+ * See the GNU Affero General Public License for more details.
1616+ *
1717+ * You should have received a copy of the GNU Affero General Public License
1818+ * along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1919+ */
2020+2121+return [
2222+ 'show' => [
2323+ 'missing' => 'Requested page not found.',
2424+ 'missing_translation' => 'Requested page not found for currently selected language.',
2525+ 'other_languages' => 'Other languages',
2626+ ],
2727+];
+64
resources/views/wiki/show.blade.php
···11+{{--
22+ Copyright 2016 ppy Pty. Ltd.
33+44+ This file is part of osu!web. osu!web is distributed with the hope of
55+ attracting more community contributions to the core ecosystem of osu!.
66+77+ osu!web is free software: you can redistribute it and/or modify
88+ it under the terms of the Affero GNU General Public License version 3
99+ as published by the Free Software Foundation.
1010+1111+ osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
1212+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1313+ See the GNU Affero General Public License for more details.
1414+1515+ You should have received a copy of the GNU Affero General Public License
1616+ along with osu!web. If not, see <http://www.gnu.org/licenses/>.
1717+--}}
1818+1919+@extends('master', [
2020+ 'titleAppend' => $path,
2121+ 'title' => null,
2222+])
2323+2424+@section('content')
2525+ <div class="osu-layout__row">
2626+ <div class="osu-page-header osu-page-header--wiki">
2727+ <div class="osu-page-header__title-box">
2828+ @if (present($subtitle))
2929+ <h2 class="osu-page-header__title osu-page-header__title--small">{{ $subtitle }}</h2>
3030+ @endif
3131+3232+ <h1 class="osu-page-header__title">{{ $title }}</h1>
3333+ </div>
3434+ </div>
3535+ </div>
3636+3737+ <div class="osu-layout__row osu-layout__row--page-compact">
3838+ @if (!empty($pageLocales))
3939+ <div class="wiki-language-list">
4040+ <div class="wiki-language-list__header">
4141+ {{ trans('wiki.show.other_languages') }}:
4242+ </div>
4343+4444+ @foreach ($pageLocales as $locale)
4545+ <a class="wiki-language-list__item" href="?locale={{ $locale }}">
4646+ {{ App\Libraries\LocaleMeta::nameFor($locale) }}
4747+ </a>
4848+ @endforeach
4949+ </div>
5050+ @endif
5151+5252+ <div class="wiki-content">
5353+ @if (present($page))
5454+ {!! Markdown::convertToHtml($page) !!}
5555+ @else
5656+ @if (empty($pageLocales))
5757+ {{ trans('wiki.show.missing') }}
5858+ @else
5959+ {{ trans('wiki.show.missing_translation') }}
6060+ @endif
6161+ @endif
6262+ </div>
6363+ </div>
6464+@endsection