Using javascript for Back link

Bug #628113 reported by Mitsuhiro Yoshida
22
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Hugh Davenport

Bug Description

Now we are using $_SERVER['HTTP_REFERER'] to get a previous view page.
But for example the following 2nd case, we can not go back to the Top Page.

1. Top Page > Links and Resources > Site view 001 > Back > Top Page
2. Top Page > Links and Resources > Site view 001 > Public view by user001 > Back > Site view 001 > Back > public view by user001 > Back > Site view 001

So how about changing view/view.php as below?

File: view/view.php
Line: 179

[ Before ]
if ($USER->is_logged_in() && !empty($_SERVER['HTTP_REFERER'])) {
    $page = get_config('wwwroot') . 'view/view.php?id=' . $viewid . ($new ? '&new=1' : '');
    if ($_SERVER['HTTP_REFERER'] != $page) {
        $smarty->assign('backurl', $_SERVER['HTTP_REFERER']);
    }
}

[ After ]
if ($USER->is_logged_in() && !empty($_SERVER['HTTP_REFERER'])) {
    $page = get_config('wwwroot') . 'view/view.php?id=' . $viewid . ($new ? '&new=1' : '');
    if ($_SERVER['HTTP_REFERER'] != $page) {
        $smarty->assign('backurl', 'javascript:history.back()');
    }
}

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

This would mean that views are reliant on javascript being enabled

Revision history for this message
Mitsuhiro Yoshida (mits) wrote :

Yes, you are right.
But using 'javascript:history.back()' is the easiest way to avoid Back link loop.

Revision history for this message
Ruslan Kabalin (rkabalin) wrote :

Basically the bug is that when you follow the link in the view that leads to another view, you get in the loop as "back" button always points to the previous view. Solution can be preserving $_SERVER['HTTP_REFERER'] in session when view is open the first time and setting backurl to the one stored in session, if $_SERVER['HTTP_REFERER'] indicates that the view was open from another view.

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

Ruslan and I have just had a go at replicating this one - it's not the easiest bug to replicate. This is the top-right back button.
Although javascript is probably the easiest way of fixing this, it won't work for all users. That said we could perhaps using some javascript to change the link once the page is displayed. It wouldn't fix the issue for those with JS disabled, but it would for a majority of cases.

Changed in mahara:
status: New → Confirmed
Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

I'd just suggest removing the 'back' link, except I think it could be useful for logged-out users who don't have the top navigation.

Changed in mahara:
milestone: 1.3.0 → none
Revision history for this message
François Marier (fmarier) wrote :

Relying on the REFERER is a bad idea because lots of privacy-related software/proxies strip it out or fake it.

Changed in mahara:
importance: Wishlist → Low
milestone: none → 1.4.0
Revision history for this message
François Marier (fmarier) wrote :

Let's grep through the code to find out where it's used and whether or not it can be replaced/removed.

Changed in mahara:
importance: Low → Medium
Changed in mahara:
importance: Medium → Low
Changed in mahara:
assignee: nobody → Hugh Davenport (hugh-catalyst)
Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

so the back button is used in the following:

view/view.php
view/artefact.php
user/view.php

all three only display it for logged in users, and only when microheaders is ON

The looping will happen if it came from ANY of those three pages.

I do find it a useful feature for the microview.

If the owner is the logged on user, they instead get an edit this page button

I would make following suggestions:
- As it is a useful feature, fix it up so it doesn't loop
- also find other places where it could be useful and add it in (maybe seperate bug/feature for this)
- remove constraint of having a logged in user (ie public nonlogged in will still get back button)
- When page is editable, show both edit button and back button

Also seperate bug, will file. When a non logged in user accesses a public site page the "edit this page" is present, but when they access a public user-owned page, it doesn't appear.

Ideas? comments?

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

Bug for non logged in users edit is filed at https://bugs.launchpad.net/mahara/+bug/778240

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

Bug for editable page not showing both buttons is filed at https://bugs.launchpad.net/mahara/+bug/778249

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

Still left for discussion is
- should feature be kept and back loop fixed?
- should non-logged in users be able to use the back button feature.

I would suggest both, I will file a new bug for the non-logged in users

Note for the non-logged in users, the back button is already shown for public profiles in user/view.php

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

non logged in users bug filed at https://bugs.launchpad.net/mahara/+bug/778255

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

I think for this, the javascript is the best solution.

We can have no button for browsers with javascript disabled.
For those with javascript, add in the button dynamically with JS

This approach may upset some of you, but there are several other places where the non javascript get slightly less functionality.

Cheers,

Hugh

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :
Changed in mahara:
status: Confirmed → In Progress
Changed in mahara:
status: In Progress → Fix Committed
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.