|Reported by:||mdawaffe||Owned by:||mdawaffe|
|Severity:||normal||Keywords:||revision needs-testing has-patch blessed|
Attached is a first pass at adding basic versioning/revisioning to WordPress.
What it does:
- Saves a copy of a post every time you edit it.
- Allows you to view (not edit) each of those copies (revisions).
- Shows diffs between any two revisions. Forward (in time) diffs only.
What it doesn't do:
- You cannot have a live-revision and a working revision to be pushed live later. I'm not sure if that feature would be useful to our core audience or not. At any rate, it's a little tricky to get working correctly.
How it works
Posts are copied into a new row in the posts table on the pre_post_update hook. Only certain (configurable by plugin) fields are saved (title, content, author, excerpt). The rest are either used internally by WP somewhere or I felt weren't useful to save.
Posts can be restored from an older revision either in full or field by field (not chunk by chunk).
The Diff engine is an extension of the PEAR Text_Diff package (which I believe to be the descendent of the MediaWiki Diff engine). The generation of the diff output is fully pluggable via the new wp_text_diff() pluggable function.
The provided function shows diffs "side by side" and with both line and word highlighting (trac style). The old content is on the left, and the new content is on the right. This presentation allows you to ignore all the color highlighting and plusses and minuses and just read either side from top to bottom to see what the post looked like in that revision.
- wp_text_diff( $left_string, $right_string, $args = null )
- wp_save_revision( $post_id )
- wp_get_revision(&$post, $output = OBJECT, $filter = 'raw')
- wp_restore_revision( $revision_id, $fields = null )
- wp_delete_revision( $revision_id )
- wp_get_post_revisions( $post_id = 0 )
- wp_list_post_revisions( $post_id = 0, $args = null )
- Open up revisions for pages as well. That's where they'll be most useful.
- Rework Autosave to store its data as a special post revision. Then we'll be able to autosave *all* posts/pages (not just drafts) and have recovery messages like "WordPress found an autosaved copy of this post that's more recent than your version, would you like to see it?"
- Review caps/permissions. Do we need any new ones like current_user_can( 'view_revision', $id )?
- Display revisions and/or diffs in front end?
- Decide how many revisions to store for each post. Right now it stores an arbitrary number. Should it be capped?
Prior work and idea sources
- http://wordpress.org/extend/plugins/post-revisions/ (me)
- http://wordpress.org/extend/plugins/blicki/ (Ryan)
- http://comox.textdrive.com/pipermail/wp-hackers/2008-March/018689.html (Paul Menard)
svn add wp-includes/Text svn add wp-incledes/wp-diff.php svn add wp-admin/revision.php
Change History (52)
comment:13 mdawaffe — 6 years ago
- Owner changed from anonymous to mdawaffe
- Status changed from new to assigned
comment:43 in reply to: ↑ 41 westi — 5 years ago
- Resolution set to fixed
- Status changed from reopened to closed