Git Product home page Git Product logo

q2a-edit-history's People

Contributors

svivian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

q2a-edit-history's Issues

Revisions Page: Displaying list of all edits

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 */

Code for "Edited on ..." in Answer-meta

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);
}

Link to revisions not always visible

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.

Improving the text compare feature

Example of recent version:

image

The plugin also considers line breaks (not the HTML ones, but ENTER key, next line) as change. I suggest to ignore those, to get a better overview.

"Edited" word should also be included in the link for showing the edits

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.

Original post on revision listing displays different from post on site (since br tags are added)

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.

Clarifying if plugin is for public use or only admin use

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

On revisions-list: First entry is original post, better not display "Edited 2012-09-05 ..." notice

... 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

Error on edit history insert when using external authentication

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 =)

Do not log ninja edits

Don't log edits within a few minutes of each other. (Or update it with the latest revision?)

Make 'edit by' line more visible (CSS)

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 by is empty if anonymous poster

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']);

Why is there a column "reason" in qa_edit_history?

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

Row Size Limit

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.