Multi-user setup and page creation

What’s the best way to display who of two users was the last to modify a page?
I’m not sure this is even possible, but want to think out loud.

Scenario 1:

  • both users are logged in the panel, a post-hook add a timelog entry in a structured field, writing user name and date
  • or, kirby can somehow read how was the last to modify the page, and there’s a method along the lines of $page->user()->modified()

Scenario 2:

  • the file gets modified from outside the panel, so no user login, but both users can potentially have a github account, and be part of the website repo that is the website in question, and I can fetch from the last commit, username (or email address) and timestamp; I plan to integrate this plugin to each article page anyway — https://github.com/rtfpessoa/diff2html

Now, Scenario 2 might work, but is there anything existing like Scenario 1?

I began to work on a wiki using kirby, and am curious to explore all these details along the way.

Well, yes, you could use hooks to write to the individual pages.

Or if you work with Git, you could use the Autogit plugin to auto commit changes together with the user name. If not, the Logger plugin logs all loggable changes to a file. You could modify the latter plugin to just log certain events or changes done by individual users.

thank you.

in both instances though, you can see the changes through the panel. is there a way to output that to the website as well?

The logger plugin stores the stuff in a text file, so it shouldn’t be a problem to extract the information from there. But of course, if you want to display this information on every page, it might make more sense to store it with the page. Really depends on your use case.

With the Autogit plugin, you would have to access this information from the repo.

Kirby itself does not store data about who modified what and when. The Panel stores some information in the user file (the last modified page), but that does not contain any timestamps.

If you want to pull information from a repo anyway, like described in your second scenario, then you might as well use that to pull information from a repo in the first scenario.

I think you can probably combine a couple of things to get the desired result. I use this to put the page modified date into meta tags:

<?= $page->modified('c') ?>

I have the following blueprint fields so i can capture other date info from the page:

  author:
    label: Author
    type:  user
    width: 1/2
    help: Who created this page?
  created:
    label: Created
    type: datetime
    default: today
    date:
      format: DD-MM-YYYY
    time:
      interval: 10
    width: 1/2
    help: When was this page created?
  modified:
    label: Modified
    type: datetime
    default: today
    date:
      format: DD-MM-YYYY
    time:
      interval: 10
    override: true
    width: 1/2
    help: When was this page modified? Defaults to now.

You could tie that in with the User field so when you put the data together, it gives what you want.

Page modified on <?= $page->modified('d/m/Y H:i') ?> by <?= $page->author() ?>

I just checked the docs for the user field and it doesnt look like there is a way to make it default to the currently logged in user. You can only default to a named user. If you want it to auto select the logged in user, you will probablky have to make your own custom field.

The user field defaults to the current user if it is required. I wouldn’t rely on the modified method if the page can be modified from outside the Panel. Also, the user field is not updated if the page is modified.

hmm yes. Trickier then it sounds. Your forever fighting two disconnected streams of information. Github does push out an RSS feed and JSOn data of changes, so you could use that, but you would need a way to find the page in the feed and marry it up with the Kirby page. You would also need to know which Github user = which Kirby user.

I’ve successfully pulled in RSS feed data from a Medium blog into a Kirby site before to display the blog articles, it’s not too hard. It’s kind of a proof of concept, I haven’t polished it off yet, but there some stuff in this thread that should help you out if you went in that direction.

In any case it seems a lot of effort to marry these two information streams.

@afincato May I asked what your use case is for such an effort to get this information?

I think its comes down to how useful this information is. What is the subject matter of pages? Personally, as a website reader, I only care about how old a page is if i’m trying to find out about technical stuff. If your pages are about something thats likely to be out of date and no longer useful in a years time, it’s probably worth knowing the publication or revision time, so the reader can gauge if it is still relevant.

Does seem like an awful lot of effort though :slight_smile:

Well, yes, the most important information for me as a reader is the date when the stuff was created or updated. This is particular useful for technical stuff. In other scenarios, however, I might be very interested to know who the information is coming from.

But that is exactly the reason why I asked for the use case. Because without that information, the discussion what everyone prefers doesn’t really help the case.

Thank you for the ideas and suggestions!

I need to get both informations (last user who modified the page, and timestamp of when that happened).

As said, I’m working on a wiki, and want to know who did what whenever a page has been edited, like Mediawiki (that runs wikipedia) does.

We use git anyway to track text changes and diff that on a word basis, which is the reason why I want to implement the diff2html plugin. But I also realised that many times a new article might be created from the panel.

Auto git seems indeed what I am looking for, I wasn’t sure about it the other day, but will give it a try now. And it’s cool it adds as commit user based on the logged in users (should test how that works with multiple users though).

This should work, my Logger plugin is based partly on the Autogit stuff and logs all users with a timestamp. Also, I used the “git-commit-and-push” plugin in an older project which worked well as well.

Autogit seems to be doing what I need, more or less. I’ll look into how to fetch the last user who modified the file, and possibly the timestamp as well — though I just tested if $page->modified() works also when you edit the page from outside the panel (eg by opening the text file), and it works.

I have to adjust the timezone though (it defaults to UTC, instead of UTC +1).

Try <?= $page->modified('c') ?>. Seems to work for me. Result is something like:

2018-02-17T17:21:29+00:00

I have a feeling you probably need the PHP timezone properly set in php.ini for it to accuratly add +01:00 on the end.

Yep, I set c::set('timezone','Europe/Berlin'); in config.php.

First time this happens, but I think it’s because I’m running a very bare-bones server w/ php -S localhost:800x, for which many options are not supported or built-in.

php.ini is the best place, but you could try doing it in your .htaccess.

php_value date.timezone "Europe/Berlin"

Just remember to remove it when you push to live :slight_smile:

What operating system are you on?

I upgraded to macOS High Sierra last November, and did not bother to setup a m+a+m+p setup with homebrew this time, since php 7.1 is built-in and wanted to try a more fluid setup.

Might change my mind soon though :stuck_out_tongue:

Well, give Valet a go. It’s extremely light weight. I used to use Vagrant but thats a huge overhead. Valet leans on the stuff already installed and makes a few things easier. Kirby runs great on it, and its really easy to setup multiple sites (basically you point it at a folder of projects, and suddenly they are all reachable in a browser). It’s voodoo if you ask me :slight_smile:

Much much quicker then setting up a m+a+m+p setup by hand.

Thank you!

Looks exactly the kind of wrap providing the few extra functions I miss from the previous setup: eg, dropping a kirby folder inside /Projects open the browser and type folder-name.dev. Boom!

Your welcome. It uses .test as domain name by default, but you can change it real easy after install:

$ valet domain dev

I prefer .dev too :slight_smile: The nice thing about Valet is it has HTTPS built in, aswell as being able to share sites from your machine to the outside world. Great for giving clients a quick peek without deploying it.