Is it possible to link to specific revision of a post?


(Tobias Eigen) #1

I just made some huge changes to a wiki post, and would like to write a post explaining my changes and linking to a comparison of the original to new revision. I don’t see how that can be done. Any ideas?


(Jeff Atwood) #2

That is not possible at this time.


(Tobias Eigen) #3

OK, thanks for the quick info.


(lid) #4

Possible with this :wink:

1.Go to topic list
2. make a full page refresh (important step)
3. paste in console the code below

4.come back to this page check the buttons bellow

history::70386::2

history::70629::3

<kbd><code>history::70386::2</code></kbd>   

Thanks to a dangerous styling rule we can also hide text and put custom text .
good for SEO :japanese_goblin:

will be replaced with a messagehistory::70629::2

<kbd><code>will be replaced with a message<b>history::70629::2</b></code></kbd>  

Discourse.PostView.reopen({
    _processHistoryLink: function() {
            window.processLinks(); //scan for history::topic_id::revision pattern in a <kbd><code></code></kbd>
        }.on('didInsertElement') //fire on every post render, not ideal for processLinks function we could be fine if it fire once for each post chunks being added.
 
});
 
 
 
Discourse.__container__.lookup("route:topic").reopen({
    actions: {
        showHistoryByPostId: function(postID, rev) {
            ff = Discourse.__container__.lookup("route:topic");
            Discourse.Route.showModal(this, 'history', postID);
            this.controllerFor("history").refresh(postID, rev);
            this.controllerFor('modal').set('modalClass', 'history-modal');
            return false;
        }
    }
});
 
 
window.processLinks = function() {
    $("kbd>code").each(function(a, b) {
        b = $(b);
        var m = b.text().match(/(history)::(\d+)::(\d+)/)
        console.log("Match?", m);
        if (m != null) {
            var post_id = m[2]
            var post_rev = m[3]
            a = $("<div style='cursor:pointer;display:block !important'>See History of post " + post_id + " Rev" + post_rev + "</div>");
            a.click(function() {
                Discourse.__container__.lookup("route:topic").send("showHistoryByPostId", parseInt(post_id), parseInt(post_rev));
            });
            b.html("");
            b.append(a);
        }
    });
};

(Dan Dascalescu) #5

:+1: for links to a specific revision of a post.

https://meta.discourse.org/raw/20404 will show the raw post. https://meta.discourse.org/raw/20404?rev=X could show a given revision.


(Jeff Atwood) #6

That is a great idea @techapj can you add it to your list?


(Régis Hanol) #7

I believe it’s already available right now but I don’t remember the argument from the top of my head. @techAPJ make sure you look for it before adding this feature :wink:


(Arpit Jalan) #8

Just added this feature via:

https://github.com/discourse/discourse/commit/49edffd3c38629c631d6088b009e9e416f7c26e7

The URL for accessing raw revision post will be like https://meta.discourse.org/raw/16468?revision=2


@zogstrip I was not able to find any existing route that was showing raw revision posts. I think currently revision posts may be accessed via JSON API requests, but not in browser.


(Jeff Atwood) #9