]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/webapps/wiki/wiki.factor
webapps.wiki: adding search bar
[factor.git] / extra / webapps / wiki / wiki.factor
index 5339a3d6546a7b98dce1eb4dce2b9eebcc703e61..3074915bb04599bfda52c3ebb122bb606c3d687d 100644 (file)
@@ -1,22 +1,12 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel hashtables calendar random assocs
-namespaces make splitting sequences sorting math.order present
-io.files io.directories io.encodings.ascii
-syndication farkup
-html.components html.forms
-http.server
-http.server.dispatchers
-furnace.actions
-furnace.utilities
-furnace.recaptcha
-furnace.redirection
-furnace.auth
-furnace.auth.login
-furnace.boilerplate
-furnace.syndication
-validators
-db.types db.tuples lcs urls ;
+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 http.server.dispatchers
+http.server.static kernel lcs make namespaces present random
+regexp sequences simple-tokenizer sorting splitting unicode urls
+validators ;
 IN: webapps.wiki
 
 : wiki-url ( rest path -- url )
@@ -297,7 +287,7 @@ M: revision feed-entry-url id>> revision-url ;
                 [ "new" [ from-object ] nest-form ]
                 bi*
             ]
-            [ [ content>> string-lines ] bi@ lcs-diff "diff" set-value ]
+            [ [ content>> split-lines ] bi@ lcs-diff "diff" set-value ]
             2bi
         ] >>init
 
@@ -316,6 +306,33 @@ M: revision feed-entry-url id>> revision-url ;
 
         { 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-with
+                [ 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 ;
@@ -363,10 +380,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 ;