<commit_before><?php
# PlomWiki plugin: AutoSum
# 
# Provides to the diff summary field an automatic summary of what was
# changed, by excerpting the actual diff text.

# Hook into WritePage() to fill up an empty $summary with AutoSum().
$hook_WritePage_diff .= 'if (!$summary) $summary = AutoSum($diff_add);';

function AutoSum($diff_add) {
# Build nice short single-line summary of diff from diff text provided.
  global $nl;
  $diff_lines = explode($nl, $diff_add); 

  # Count "<" and ">" lines.
  $n_add = 0; $n_del = 0;
  foreach ($diff_lines as $line) {
    if     ('>' == $line[0]) $n_add++;
    elseif ('<' == $line[0]) $n_del++; }

  # Build summary of ">" lines.
  if (0 < $n_add) {
    $sep_to_minus = ' ';
    $prefix_add   = '[+]';
    foreach ($diff_lines as $line)
      if ('>' == $line[0]) {
        $string_add .= $sep.substr($line, 1); 
        $sep         = ' / '; } 
      else
        $sep         = ' […] '; }
  $string_add = substr($string_add, 6);

  # Build summary of "<" lines.
  if (0 < $n_del) {
    $prefix_del = '[-]';
    foreach ($diff_lines as $line)
      if ('<' == $line[0]) {
        $string_del .= $sep.substr($line, 1); 
        $sep         = ' / '; } 
      else
        $sep         = ' […] '; }
  $string_del = substr($string_del, 6);

  # Build summary string by adding everything; reduce to 100 UTF8 chars.
  $summary = 'AutoSum: '.$prefix_add.$string_add.$sep_to_minus.
                                                $prefix_del.$string_del;
  if (100 < strlen($summary))
    $summary = mb_substr($summary, 0, 99, 'UTF-8').'…';<commit_msg>Licensed AutoSum.php, and did minor formatting improvement.<commit_after><?php
# PlomWiki plugin: AutoSum. Excerpts diff text to create summary text.
# 
# Copyright 2010-2012 <NAME> / <http://www.plomlompom.de/>
# License: AGPLv3 or any later version. See file LICENSE for details.

# Hook into WritePage() to fill up an empty $summary with AutoSum().
$hook_WritePage_diff .= 'if (!$summary) $summary = AutoSum($diff_add);';

function AutoSum($diff_add) {
# Build nice short single-line summary of diff from diff text provided.
  global $nl;
  $diff_lines = explode($nl, $diff_add); 

  # Count "<" and ">" lines.
  $n_add = 0; $n_del = 0;
  foreach ($diff_lines as $line) {
    if     ('>' == $line[0]) $n_add++;
    elseif ('<' == $line[0]) $n_del++; }

  # Build summary of ">" lines.
  if (0 < $n_add) {
    $sep_to_minus = ' ';
    $prefix_add   = '[+]';
    foreach ($diff_lines as $line)
      if ('>' == $line[0]) {
        $string_add .= $sep.substr($line, 1); 
        $sep         = ' / '; } 
      else
        $sep         = ' […] '; }
  $string_add = substr($string_add, 6);

  # Build summary of "<" lines.
  if (0 < $n_del) {
    $prefix_del = '[-]';
    foreach ($diff_lines as $line)
      if ('<' == $line[0]) {
        $string_del .= $sep.substr($line, 1); 
        $sep         = ' / '; } 
      else
        $sep         = ' […] '; }
  $string_del = substr($string_del, 6);

  # Build summary string by adding everything; reduce to 100 UTF8 chars.
  $diff = $prefix_add.$string_add.$sep_to_minus.$prefix_del.$string_del;
  $summary = 'AutoSum: '.$diff;
  if (100 < strlen($summary))
    $summary = mb_substr($summary, 0, 99, 'UTF-8').'…';
{'fraction_non_alphanumeric': 0.17784615384615385, 'fraction_numerical': 0.016923076923076923, 'mean_word_length': 2.5686059275521407, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1714840', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1127, 'n_words': 301}