[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][FIX] Article Topics: Prevent saving article topic when name field is empty

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6920cced201a4_2a17ee681560@gitlab-sidekiq-low-urgency-cpu-bound-v2-69f7667848-tx7s5.mail>

ushindi bienvenu pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
333a676d by Alain Cisirika at 2025-11-21T20:28:12+00:00
[BP][FIX] Article Topics: Prevent saving article topic when name field is empty
---
* Fix/prevent empty topic fields
---
* [FIX] Prevent saving article topic when name field is empty

* [FIX] fix regression introduced by the MR 7892 which mde impossible to upload files

See merge request tikiwiki/tiki!7989

See merge request tikiwiki/tiki!8408

- - - - -


2 changed files:

- templates/tiki-admin_topics.tpl
- tiki-admin_topics.php


Changes:

=====================================
templates/tiki-admin_topics.tpl
=====================================
@@ -11,14 +11,14 @@
     <div class="mb-3 row">
         <label class="col-sm-2 col-form-label" for="name">{tr}Name{/tr}</label>
         <div class="col-sm-10">
-            <input type="text" name="name" id="name" class="form-control">
+            <input type="text" name="name" id="name" class="form-control" required>
         </div>
     </div>
     <div class="mb-3 row">
         <label class="col-sm-2 col-form-label" for="image">{tr}Image{/tr}</label>
         <div class="col-sm-10">
             <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
-            <input class="form-control" name="userfile1" type="file">
+            <input class="form-control" name="userfile1" type="file" accept="image/*" required>
         </div>
     </div>
     <div class="mb-3 row">


=====================================
tiki-admin_topics.php
=====================================
@@ -29,35 +29,36 @@ $access->check_permission(['tiki_p_articles_admin_topics']);
 
 if (isset($_REQUEST["addtopic"])) {
     $access->checkCsrf();
-    if (isset($_FILES['userfile1'])) {
-        if (is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
-            $filegallib = TikiLib::lib('filegal');
-            try {
-                $filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
-            } catch (Exception $e) {
-                $smarty->assign('errortype', 403);
-                $smarty->assign('msg', $e->getMessage());
-                $smarty->display("error.tpl");
-                die;
+    if (empty($_REQUEST["name"])) {
+        Feedback::error(tra("The topic's name can not be empty"));
+    } else {
+        if (isset($_FILES['userfile1'])) {
+            if (is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
+                $filegallib = TikiLib::lib('filegal');
+                try {
+                    $filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
+                } catch (Exception $e) {
+                    Feedback::errorAndDie($e->getMessage(), \Laminas\Http\Response::STATUS_CODE_403);
+                }
+                $fp = fopen($_FILES['userfile1']['tmp_name'], "rb");
+                $data = fread($fp, filesize($_FILES['userfile1']['tmp_name']));
+                fclose($fp);
+                $imgtype = $_FILES['userfile1']['type'];
+                $imgsize = $_FILES['userfile1']['size'];
+                $imgname = $_FILES['userfile1']['name'];
+            } else {
+                Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
             }
-            $fp = fopen($_FILES['userfile1']['tmp_name'], "rb");
-            $data = fread($fp, filesize($_FILES['userfile1']['tmp_name']));
-            fclose($fp);
-            $imgtype = $_FILES['userfile1']['type'];
-            $imgsize = $_FILES['userfile1']['size'];
-            $imgname = $_FILES['userfile1']['name'];
-        } else {
-            Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
         }
+        if (! isset($data)) {
+            $data = '';
+            $imgtype = '';
+            $imgsize = '';
+            $imgname = '';
+        }
+        // Store the image
+        $artlib->add_topic($_REQUEST["name"], $imgname, $imgtype, $imgsize, $data);
     }
-    if (! isset($data)) {
-        $data = '';
-        $imgtype = '';
-        $imgsize = '';
-        $imgname = '';
-    }
-    // Store the image
-    $artlib->add_topic($_REQUEST["name"], $imgname, $imgtype, $imgsize, $data);
 }
 if (isset($_REQUEST["remove"]) && $access->checkCsrf()) {
     $artlib->remove_topic($_REQUEST["remove"]);



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/333a676df957e0eda78afb269b95494c57ddf006

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/333a676df957e0eda78afb269b95494c57ddf006
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.