svivian / q2a-edit-history Goto Github PK
View Code? Open in Web Editor NEWA Q2A plugin to store post edits
A Q2A plugin to store post edits
Cause current q2a script crash and not display. Probably, this plugin is too old compare to current q2a script
Thanks
As far as I could see, you are not checking against another userid.
Scenario: User 1 does an edit, user 2 does an edit 3 min later. Now, in v0.9, edit version of user 1 gets overwritten.
This should be saved actually.
We need to compare the editor (userid) as well.
Hi Scott, just wanted to give you the new code that you can add to qa-edh-revisions.php, after line 56 "$this->recent_edits( $qa_content );" to display all edits:
/* eetv added */
// retrieve URL variable
if( isset($_GET['show']) ) {
$showMode = (int) $_GET['show'];
}
else {
$showMode = 0; // default
}
// showModes
// 0 - default: show only questions, hides admin
// 1 - show only questions, includes admin
// 2 - show questions+answers, hides admin
// 3 - show questions+answers, includes admin
$days = 7; // last days to show from today
$showAdminEdits = false;
if($showMode==1 || $showMode==3) $showAdminEdits=true;
$adminUserId = 1; // userid 1 should be admin!
// set language string herefile: qa_lang_html('edithistory/revision_list_title');
$qa_content['title'] = "Revision List (last ".$days." days)";
// return if not admin!
$level=qa_get_logged_in_level();
if ($level<QA_USER_LEVEL_ADMIN) {
$qa_content['custom0']='<div>Zugriff nicht erlaubt</div>';
return $qa_content;
}
// counter for custom html output
$c = 2;
// get list of posts
$queryRevisionList = qa_db_query_sub( 'SELECT postid, updated, title, tags, userid FROM ^edit_history
WHERE updated > DATE_ADD(NOW(), INTERVAL -'.$days.' DAY)
ORDER BY updated DESC');
$htmloutput = "<table>";
$htmloutput .= "<thead> <th>Date</th> <th>Post</th> <th>User</th> </thead>";
while ( ($row = qa_db_read_one_assoc($queryRevisionList,true)) !== null ) {
// get link to revision post
$activity_url = qa_path_to_root() . 'revisions/' . $row['postid'];
// get link to original question
$post_url = qa_path_to_root() . qa_path_html( qa_q_request( $row['postid'], $row['title'] ) ); // $row['postid'];
// workaround to get link to answer
$display_post_url = "";
if(strlen($post_url)>14) {
$display_post_url = '<a style="font-size:10px;color:#777;" href="'.$post_url.'">see live version</a>';
}
// if anonymous user edits his post then userid is NULL, catch it
if($row['userid'] == $adminUserId && !$showAdminEdits) {
// do not show admin edits
continue;
}
else if(!isset($row['title']) && ($showMode==1 || $showMode==0) ) {
// do not show answers, answers do not have title set
continue;
}
// anonymous user
else if($row['userid'] === NULL) {
$revLink = isset($row['title']) ? $row['title'] : "Answer was edited";
// display date as before x time
$updateTime = implode('', qa_when_to_html( strtotime($row['updated']), qa_opt('show_full_date_days')));
$htmloutput .= '<tr> <td>'.$updateTime.'</td>
<td><a href="'.$activity_url.'">'.$revLink.'</a> <br />'.$display_post_url.'</td>
<td>anonymous</td></tr>';
}
else {
// get user details (display avatar and name)
$username = qa_db_read_all_assoc(qa_db_query_sub('SELECT handle FROM ^users WHERE userid = #',$row['userid']), 'handle');
$user = qa_db_select_with_pending( qa_db_user_account_selectspec($username, false) );
$revLink = isset($row['title']) ? $row['title'] : "Answer was edited";
// display date as before x time
$updateTime = implode('', qa_when_to_html( strtotime($row['updated']), qa_opt('show_full_date_days')));
$htmloutput .= '<tr> <td>'.$updateTime.'</td>
<td><a href="'.$activity_url.'">'.$revLink.'</a> <br />'.$display_post_url.'</td>
<td>'. qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), false) . " " . qa_get_one_user_html($user['handle'], false).'</td></tr>';
}
}
$htmloutput .= "</table>";
/* output into theme */
// admin options
$qa_content['custom'.++$c] = '<p>Options: <a href="?show=0">all Q (without admin)</a> | <a href="?show=1">all Q (with admin)</a> | ';
$qa_content['custom'.++$c] = '<a href="?show=2">all Q+A (without admin)</a> | <a href="?show=3">all Q+A (with admin)</a></p>';
// revision list
$qa_content['custom'.++$c] = '<div class="revisionList" style="border-radius:0; margin-top:-2px; min-height:350px;">';
$qa_content['custom'.++$c] = $htmloutput;
$qa_content['custom'.++$c] = '</div>'; // end revisionList
// custom css for qa-main
$qa_content['custom'.++$c] = '<style type="text/css">.qa-main { margin:20px 0 0 60px; width:640px; } table {width:616px;} thead,th { text-align:center;border:1px solid #CCC; background:#FFC; padding:8px; } td { padding:8px; } </style>';
return $qa_content;
/* END eetv added */
Maybe this helps, it shows an edit notice directly under "Answered on ... by ..." like it can be found with the questions:
public function post_meta($post, $class, $prefix=null, $separator='<BR/>')
{
// only link when there are actual revisions
if(in_array($post['raw']['postid'], $this->rev_postids))
{
$url = qa_path_html('revisions/' . $post['raw']['postid']);
// question meta
if(isset($post['when_2']))
{
// $post['when_2']['data'] = '<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">' . $post['when_2']['data'] . '</a>';
// prefix is only set "vor x Minuten", but after a week the date is displayed (no prefix), e.g. "Mär 3"
$meta_before = !empty($post['when_2']['prefix']) ? $post['when_2']['prefix'] : '';
$meta_before .= ' '.!empty($post['when_2']['data']) ? $post['when_2']['data'] : '';
$post['what_2'] = '
<div class="post-meta-edited">
<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">' . $post['what_2'] . '</a>
'.$meta_before.'
</div>
';
// $post['who_2']['suffix'] .= '';
unset($post['who_2']);
unset($post['when_2']);
}
// answer edit, q2a core does not give them a what_2 for the edit
else if(isset($post['when']))
{
// get edit time and editor
$lastedit = qa_db_read_one_assoc(
qa_db_query_sub('
SELECT updated, userid
FROM ^edit_history
WHERE postid = #
ORDER BY `updated` DESC
LIMIT 1
', $post['raw']['postid'])
);
$meta_before_arr = qa_when_to_html(strtotime($lastedit['updated']), qa_opt('show_full_date_days'));
$meta_before = isset($meta_before_arr['prefix']) ? $meta_before_arr['prefix'] : '';
$meta_before .= $meta_before_arr['data'];
$post['what_2'] = '
<div class="post-meta-edited">
<a rel="nofollow" href="'.$url.'" class="'.$class.'-revised">Edited</a>
'.$meta_before.'
</div>
';
}
}
parent::post_meta($post, $class, $prefix, $separator);
}
The link to view the revisions is only visible when the last action was an edit. Retagging, selecting an answer, reshowing etc do not link to the revisions.
Also need to remove link in the first place if there are no revision.
Notice: Undefined index: content in /q2a-edit-history/qa-edh-revisions.php on line 266
Happens when the post has been deleted and the revisions page is called for this post.
PHP gave me the error that function qa_block_words_replace() does not exist.
So I think you need to add this line before the foreach:
// censor posts
require_once QA_INCLUDE_DIR.('qa-util-string.php');
$options = array( 'blockwordspreg' => qa_get_block_words_preg(), 'fulldatedays' => qa_opt('show_full_date_days') );
If you implement https://github.com/echteinfachtv/q2a-edit-history/blob/master/qa-revision-page.php it would be great to see a link for each revision to delete the revision entry (only for admins).
Currently only the time behaves as a link to show the edits, but actually the "edited" word should be linked to the edits page.
To remove confusion I have seen in stackoverflow, there both the word "edited" and time is lined to the edits page.
If edited word is linked to that edits page then it will be easy for users to understand what that link would be for.
I just saw that the plugin parses linebreaks from the content as
tags.
Compare how:
I updated the wysiwyg editor plugin (CKEditor v3.6.4) today. Unfortunately it writes the opening
tag followed with a text linebreak, for instance:
This my text.
Version 1.5 broke the compatibility with single sign-on (external users) by referencing table qa_users, that is not present when QA_EXTERNAL_USERS is set.
Hi Scott,
I just realized that you are using the revision tool for your users. I discovered the "nofollow" that you added and think now, you let your users see their changes.
In my situation the admin uses the edit-history only for tracking changes to prevent abuse, such as a user deleting all his posts, or another user with privileges going wild... this is why I prevented others from accessing the plugin's page, see my fork: https://github.com/echteinfachtv/q2a-edit-history/blob/master/qa-revision-page.php
Maybe this should be communicated? Or put as a setting?
Kai
I like the feature that the edits are not tracked within the first 5 min after the post creation.
However, today I noticed that it does not work for newly created questions and answers. Those edits get tracked even under 5 min.
Maybe you can help?
... as this causes irritation. Better to display the first with "Original Post:".
I came across this when I modified qa-edh-revisions.php to display "edited by {username}".
Furthermore, the recent revision-list displays an edit date for the original post which is the same date as the date of the 1st revision.
In the foreach I had to store the username to display it for the next revision as the "first revision" is the original. That was a bit confusing but I understand that the original must go into the $revisions array as this necessary to use diff_string.
Please take a look at my modifications in the foreach($revisions as $rev) from line 87: https://github.com/echteinfachtv/q2a-edit-history/blob/master/qa-edh-revisions.php
Greetings,
Kai
On my first test of this plugin I got a query fail error:
[Mon Dec 04 19:52:49 2017] [notice] [client 10.1.11.92] PHP Question2Answer MySQL query error 1366: Incorrect integer value: 'c067284' for column 'userid' at row 1 - Query: INSERT INTO qa_edit_history (postid, updated, title, content, tags, userid)\n\t\t\t VALUES (40, NOW(), '{post content}', '{post tags}', 'c067284'), referer: {post url}?state=edit-40
As you can see, I'm using a VARCHAR(7) userid, but edit-history seems to initialyze its table with a hard-coded INT(10).
Changing the column data type fixed the issue for me, but I think it should be corrected in the initialization query. I'm yet to study how to get the custom data type from qa-external and plan on making a pull request, but if someone more proficient at q2a development steps in, I'd be glad =)
Don't log edits within a few minutes of each other. (Or update it with the latest revision?)
I tried the plugin with the layer.
As far as I understand, the revision should be linked to the post.
If you check e.g. http://www.gute-mathe-fragen.de/5089/einheiten-umrechnen-wie-1-7-10-4-km-0-0017-10-mm there is no revision set. Actually there are 3 different edits of this post.
Don't log edits when "save silently" checkbox is ticked.
In file https://github.com/svivian/q2a-edit-history/blob/475cb1f9f007a3525c9ac6f0ee79e5cfd6644631/qa-edit-history.php use instead:
content varchar(8000) DEFAULT NULL,
this:
content varchar(".QA_DB_MAX_CONTENT_LENGTH.") DEFAULT NULL,
I just noticed that changes from my 12000 char content in ^posts table were not stored completely.
Gray line on gray background is not visible enough.
I suggest making the revision line light yellow and give a bit more padding:
$qh[] = '.diff-date { background: #eee; padding: 2px; margin: 5px 0; } ';
to for instance:
$qh[] = '.diff-date { background: #FFC; border:1px solid #999; border-radius:5px; padding: 8px; margin: 5px 0 0 -2px; } ';
Edit notice on revision page is empty, i.e.
'edited_when_by' => 'Edited ^1 by ^2',
^2 is empty.
To solve this, in qa-edh-revisions.php add:
if($rev['editedby']=="") { $rev['editedby'] = "anonymous"; }
before: $edited_when_by = qa_lang_html_sub('edithistory/original_post_by', $rev['editedby']);
I guess you wanted to implement a "reason" for editing?
For my site this is not necessary, but for another use case... Maybe we can make that an option in the admin section.
By default I would have this turned off.
Kai
I was getting a Row Size Limit error for my database when installed q2a-edit-history. In order to fix, I changed QA_DB_MAX_CONTENT_LENGTH to a smaller value in qa-config.php. Maybe add an option to do this in setup?
If a question is retagged and after some time it is edited silently. Then it says {retagged "time" ago by user_name}. And the time is linked to the edits page which should not be storing the edits.
As this was discussed before, suggest edit is way better to improve community content by community only.
So will this feature be introduced this time as you are onto updating your plugins.
http://question2answer.org/qa/38559/feature-request-suggest-edit-feature
Or can you make a plugin which can handle community requests at one place. The requests can be for edits, flags, close a question. One plugin to handle all these requests at once.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.