]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/webapps/wiki/wiki.factor
Remove filtering on timestamps and use short ISO8601 to display them
[factor.git] / extra / webapps / wiki / wiki.factor
index b22938b8d512f6eda4fda8d67bb6be6a42c3a8fe..d55e0e1836d2738fed09c75406e3b14f165819e3 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2008 Slava Pestov
-! See http://factorcode.org/license.txt for BSD license.
+! See https://factorcode.org/license.txt for BSD license.
 USING: accessors calendar db.tuples db.types farkup
 furnace.actions furnace.auth furnace.boilerplate
 furnace.recaptcha furnace.redirection furnace.syndication
-furnace.utilities html.forms http.server.dispatchers kernel lcs
-make namespaces present random sequences sorting splitting urls
+furnace.utilities html.forms http.server http.server.dispatchers
+http.server.static kernel lcs make namespaces present random
+regexp sequences simple-tokenizer sorting splitting unicode urls
 validators ;
 IN: webapps.wiki
 
@@ -56,7 +57,7 @@ M: revision feed-entry-date date>> ;
 M: revision feed-entry-url id>> revision-url ;
 
 : reverse-chronological-order ( seq -- sorted )
-    [ date>> ] inv-sort-with ;
+    [ date>> ] inv-sort-by ;
 
 : <revision> ( id -- revision )
     revision new swap >>id ;
@@ -87,11 +88,12 @@ M: revision feed-entry-url id>> revision-url ;
         [ validate-title ] >>init
 
         [
-            "title" value dup latest-revision [
+            "title" value
+            [
+                latest-revision
+            ] [
                 from-object
-                t link-no-follow? [
-                    { wiki "view" } <chloe-content>
-                ] with-variable
+                { wiki "view" } <chloe-content>
             ] [
                 edit-url <redirect>
             ] ?if
@@ -104,15 +106,13 @@ M: revision feed-entry-url id>> revision-url ;
 
         "id" >>rest
 
-        [ validate-integer-id ] >>init
-
         [
+            validate-integer-id
             "id" value <revision>
             select-tuple from-object
-            t link-no-follow? [
-                { wiki "view" } <chloe-content>
-            ] with-variable
-        ] >>display
+        ] >>init
+
+        { wiki "view" } >>template
 
     <article-boilerplate> ;
 
@@ -269,7 +269,7 @@ M: revision feed-entry-url id>> revision-url ;
             URL" $wiki" <redirect>
         ] >>submit
 
-     <protected>
+    <protected>
         "delete wiki articles" >>description
         { can-delete-wiki-articles? } >>capabilities ;
 
@@ -303,12 +303,39 @@ M: revision feed-entry-url id>> revision-url ;
 
         [
             f <article> select-tuples
-            [ title>> ] sort-with
+            [ title>> ] sort-by
             "articles" set-value
         ] >>init
 
         { wiki "articles" } >>template ;
 
+: <search-articles-action> ( -- action )
+    <page-action>
+
+        [
+            "search" param [ unicode:blank? ] trim
+            dup "search" set-value
+
+            [ f ] [
+                tokenize [
+                    " " "\s+" replace "\\b" dup surround
+                    "i" <optioned-regexp>
+                ] map
+            ] if-empty
+
+            [ f ] [
+                f <article> select-tuples
+                [ title>> ] sort-by
+                [ revision>> <revision> select-tuple ] map
+                swap '[ content>> _ [ first-match ] with all? ] filter
+            ] if-empty
+
+            [ "results" set-value ]
+            [ not "empty" set-value ] bi
+        ] >>init
+
+        { wiki "search" } >>template ;
+
 : list-user-edits ( -- seq )
     f <revision> "author" value >>author select-tuples
     reverse-chronological-order ;
@@ -356,10 +383,12 @@ M: revision feed-entry-url id>> revision-url ;
         <rollback-action> "rollback" add-responder
         <user-edits-action> "user-edits" add-responder
         <list-articles-action> "articles" add-responder
+        <search-articles-action> "search" add-responder
         <list-changes-action> "changes" add-responder
         <user-edits-feed-action> "user-edits.atom" add-responder
         <list-changes-feed-action> "changes.atom" add-responder
         <delete-action> "delete" add-responder
+        "vocab:webapps/wiki/icons/" <static> "icons" add-responder
     <boilerplate>
         [ init-sidebars init-relative-link-prefix ] >>init
         { wiki "wiki-common" } >>template ;