Abbreviations and Acronyms

Implementation

Pros:

  1. helps noobs to find out what certain common abbreviation means (as only admin can add custom abbreviations) without asking a search engine.

Cons:

  1. makes the pages' text processing take some more time for finding and marking the acronyms when creating body_r,
  2. makes the text speckled with strange links, where people want to click to find mostly nothing special but get disturbed from reading the page,
  3. as the definitions are stored in text config the non-admin user won't be able to add custom acronyms,
  4. even if the users could add custom acronyms it would look crappy being printed, as we can't hover the mouse on the printed page to see the definition,
  5. this lets the reader not to think what he reads not keeping in mind previously explained acronyms in text.

Alternative:


When we got some kind of acronym in our wiki page text we just should explain it when it's used for the first time.
Like if we write about progressive web apps (PWA) technology offered by Apple and made mature by Google,
we should first write it's abbreviation in round brackets after the definition, and then we can mention only PWA.
And all our readers, who have started to read from the beginning will understand what PWA means.
With no any unnecessary links.

evaluation


diff --git a/wacko/class/wacko.php b/wacko/class/wacko.php
index cd72a9c..ecb11fe 100644
--- a/wacko/class/wacko.php
+++ b/wacko/class/wacko.php
@@ -4713,6 +4713,43 @@
         }
     }
 
+    // ACRONYM STUFF
+    // TODO:
+    //    Why is this and interwiki in session?
+    //    What about acronym pattern without upper case?
+    function get_acronym($name)
+    {
+        // cache acronym data in _SESSION
+        $acronym = &$this->sess->acronym_conf;
+
+        if (!isset($acronym))
+        {
+            $acronym = [];
+
+            if (($lines = file(Ut::join_path(CONFIG_DIR, 'acronyms.conf'))))
+            {
+                foreach ($lines as $line)
+                {
+                    if (($line = trim($line)) && !ctype_punct($line[0]))
+                    {
+                        [$acronym_name, $acronym_description] = preg_split('/^[^\s]*\K\s/', $line);
+                        $acronym[mb_strtolower($acronym_name)] = trim($acronym_description);
+                    }
+                }
+            }
+            # UT::debug_print_r($acronym);
+        }
+
+        if (($defn = $acronym[mb_strtolower($name)] ?? null))
+        {
+            return '<abbr title="' . Ut::html($defn) . '">' . $name . '</abbr>';
+        }
+        else
+        {
+            return $name;
+        }
+    }
+
     // FORMS
     // parameter: named parameter array
     function form_open($form_name = '', $parameter = []) : string
diff --git a/wacko/config/acronyms.conf b/wacko/config/acronyms.conf
new file mode 100644
index 0000000..e00160d
--- /dev/null
+++ b/wacko/config/acronyms.conf
@@ -0,0 +1,33 @@
+ACL          Access Control List
+API          Application Programming Interface
+ASAP         As soon as possible
+ASCII        American Standard Code for Information Interchange
+BTW          By the way
+CMS          Content Management System
+CSS          Cascading Style Sheets
+DNS          Domain Name System
+FAQ          Frequently Asked Questions
+FTP          File Transfer Protocol
+FYI          For your information
+GUI          Graphical User Interface
+HTML         HyperText Markup Language
+IMHO         In my humble opinion
+IRC          Internet Relay Chat
+LAN          Local Area Network
+LOL          Laughing out loud
+OMG          Oh my God
+OS           Operating System
+OSS          Open Source Software
+RFC          Request for Comments
+ROTFL        Rolling on the floor laughing
+RTFM         Read The Fine Manual
+TIA          Thanks in advance
+TL;DR        Too long; didn't read
+TOC          Table of Contents
+URI          Uniform Resource Identifier
+URL          Uniform Resource Locator
+W3C          World Wide Web Consortium
+WTF          What the f***
+WYSIWYG      What You See Is What You Get
+WYTIWYG      What You Think Is What You Get
+ОС                Операционная Система
\ No newline at end of file
diff --git a/wacko/formatter/class/wackoformatter.php b/wacko/formatter/class/wackoformatter.php
index 8945466..b571ee1 100644
--- a/wacko/formatter/class/wackoformatter.php
+++ b/wacko/formatter/class/wackoformatter.php
@@ -261,6 +261,8 @@
             "\b[[:alnum:]]+[:][" . $object->language['ALPHANUM_P'] . "\!\.][" . $object->language['ALPHANUM_P'] . "\(\)\-\_\.\+\&\=\#]+|" .
             // disabled WikiNames
             "~([^ \t\n]+)|" .
+            // acronym
+            "\b([\p{Lu}]{2,})\b|" .
             // wiki links (beside actions)
             ($this->object->db->disable_wikilinks
                 ? ''
@@ -1204,6 +1206,15 @@
 
             return $wacko->pre_link($thing);
         }
+        // abbreviation (TODO: how it may interfere with other syntax)
+        else if (#$this->object->db->enable_acronyms
+            #&&
+                preg_match('/\b([\p{Lu}]{2,})\b/u', $thing, $matches))
+        {
+            [$acronym] = $matches;
+
+            return $wacko->get_acronym($acronym);
+        }
 
         if (($thing[0] == '~') && ($thing[1] != '~'))
         {