Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for accesskey shortcuts #684

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rybak
Copy link

@rybak rybak commented Dec 24, 2022

Overview

Implementation of #609. See more details in the commit message of the first commit.

Notes

I didn't know where to put function accesskey, so there are two copies: one in Handlers.hs and one in Layout.hs. Perhaps it should go into src/Network/Gitit/Util.hs? It doesn't seem to have any code related to HTML generation at the moment.

I also don't know how exactly generation of default help page works, so I've just added new section "Keyboard shortcuts" to the bottom of data/Help.page. I wrote conservatively little about how keyboard shortcuts work, just referring the user to MediaWiki's manual, but I'm open to expanding the help text however you see fit.

Testing

I've tested every accesskey locally by running Gitit from the repository:

$ stack build && stack exec gitit -- -f my.config

I couldn't build the code as is (I get Prelude.chr: bad argument: 1644167202 at the very end of stack build), but applying #683 locally fixed this issue for me.

HTML attribute `accesskey` [1] allows user to quickly navigate the
website.  Add support for `accesskey` to links of Gitit using the
shortcut scheme of MediaWiki [2].  This would allow users who edit
MediaWiki websites to more easily navigate Gitit webpages.

Closes jgm#609

[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey
[2] Documented in detail on English Wikipedia, one of the main instances
    of MediaWiki: https://en.wikipedia.org/wiki/Wikipedia:Keyboard_shortcuts
    See also https://www.mediawiki.org/wiki/Manual:Access_keys and
    https://meta.wikimedia.org/wiki/Help:Keyboard_shortcuts
Document accesskey addition of previous commit in the "Help" page added
to Gitit wikis by default.  The descriptions are partially borrowed from
English Wikipedia's page about similar MediaWiki feature, attribution to
authors is of that page is at
https://en.wikipedia.org/w/index.php?title=Wikipedia:Keyboard_shortcuts&action=history
@rybak
Copy link
Author

rybak commented Dec 25, 2022

CI on Windows failed because of haskell-hvr/missingh#59, it seems.

@jgm
Copy link
Owner

jgm commented Dec 26, 2022

I'm trying to upgrade the stack resolver, but it looks like we're stuck until hoauth2 puts out a release that works on text >= 2.
freizl/hoauth2#174

else tabli ViewTab << anchor !
[href $ base' ++ urlForPage page ++
case rev of
Just r -> "?revision=" ++ r
Nothing -> ""] << "view"
Nothing -> "", accesskey 'c'] << "view"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation (as of commit 94cb5a4) when looking at a revision of a page, the c accesskey is useless. There is no way to go from a revision to the current/latest version of the page, which MediaWiki supports. For example, on https://en.wikipedia.org/w/index.php?title=Human&oldid=1128628188 pressing the accesskey combination with c navigates to https://en.wikipedia.org/wiki/Human

After using this for a bit, I think it would be better to mimic MediaWiki and move accesskey="c" to a link, which would always go to the current version of the page, i.e. something along these lines:

diff --git a/data/templates/content.st b/data/templates/content.st
index 0d1229d..9c39d64 100644
--- a/data/templates/content.st
+++ b/data/templates/content.st
@@ -2,7 +2,7 @@
   $if(revision)$
     <h2 class="revision">Revision $revision$ (click the page title to view the current version)</h2>
   $endif$
-  <h1 class="pageTitle"><a href="$base$$pageUrl$">$pagetitle$</a></h1>
+  <h1 class="pageTitle"><a href="$base$$pageUrl$" accesskey="c">$pagetitle$</a></h1>
   <div class="subpages"><a href="../">&lt; parent directory</a>
     <a href="$base$$pageUrl$/">&gt; this directory</a>
   </div>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, however, would not work for switching from discussion pages (e.g. @Sandbox) to content pages. 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants