Summary: Talk page for Do the Right Thing.
Maintainer: Petko
Users: +3 (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

I have 2 searches that I do on a very regular basis, and the logical initial token is the same (php to search for the computer language, php search in the Bible book of Philippians). I can differentiate on the basis of the 2nd argument ("php 4:4" is looking in the Bible, "php preg_replace" is looking at the language). Is there any way to go to different locations based on the $1? (Obviously I can, and do, choose alternate initial tokens, but since the logical one is just ... so ... logical I find myself making mistakes all the time and would like to fix my system since my brain can't seem to remember...)*

You can create a custom function to parse the input and return the url that needs to be opened. See the recently added "Custom functions" section, and tell me if something needs to be clarified. --Petko November 05, 2016, at 06:04 AM

Or, you may find it mnemonic to simply set uppercase "PHP" for one search, lowercase "php" for the other. --Petko November 05, 2016, at 06:25 AM

Wish I mot asking silly question : if I want to set up an "edit" shortcut action for the current pmwiki driven page, it looks like the PV's asterisk "*" is not usable. Any workaround you can think of? Shortcut I'm testing is same as : edit: {*$PageUrl}?action=edit : Edit current page

I only have one page, it has the actual page URL typed (no PV). But you can use {$PageUrl} without the asterisk: it is the same thing as {*$PageUrl} for the same physical page. And the recipe only reads the actual physical page. --Petko July 11, 2016, at 01:40 PM

Would it be doable to be given an optional parameter for opening the page in a new window ? might be something like _ : thus _g would open Google results page in a new window ? Thank you. gb July 11, 2016, at 01:32 AM

I actually always open a new tab (Ctrl+T) in my browser then type my DTRT search in the address line -- never have to open the DTRT page except when I edit it. I never use the search form. I suspect you can send the search to a new browser window/tab this way:

  1. In config.php, enable "target" attribute in forms
    function FormsTarget($pn) {
      global $InputAttrs;
      $InputAttrs[] = "target";
    $PostConfig['FormsTarget'] = 100;
  2. In a the wiki page, add "target=_blank" and "input reset"
    (:input form target=_blank...
    (:input reset:)(:input end:)

This way, the form should send the search to a new window or tab; the "reset" button will allow you to clear the form for a new search. --Petko July 11, 2016, at 06:19 AM

Indeed, from browser address field set up to use DTRT page, you are firing quickly the prefixed searches. My question was related to the fact I was not fast enough, still playing with DTRT from the form itself. Thank you. gb July 11, 2016, at 12:15 PM

Possible features/changes I'd be interested in:

  • Making the space before/after the colon optional rather than disallowed (before) or required (after)
instead of
  • Using a regex instead of a fixed string to specify what gets matched on the left
    /(?:u(?:sd)?|d)2(?:all|l(?:eke)?)/: ...
instead of
usd2all,usd2leke,usd2l,u2all,u2leke,u2l,d2all,d2leke,d2l: ...

Peter Bowers February 06, 2011, at 03:15 AM

RegExp keywords done, but need testing. Space before the ":" made optional, space after kept required (or the first "\S" selects everything). --Petko April 08, 2011, at 04:28 PM

Here's the set of DTRT definitions I'm using to date:

gi:            $1 : Google images
fm:            $1 : Freshmeat (software)
php:           $1 : PHP manual
pmwiki,pm,p:   $1 : PmWiki search
pmc,cookbook:  $1 : Cookbook recipe
pmw:           $1 : PmWiki page
map,maps:      $1 : Search Google Maps
pm:            $1 : search
imdb:          $1 : search IMDB for movies
ar:            $1 : search AllRecipes
bbc:           $1 : search BBC News
fox:           $1&submit=Search : search FoxNews
dtrt:                    {$ScriptUrl}?n=Main.DTRT?action=edit : test : Edit this page
e,ebay:        $1 : search ebay
a,am,amazon:   $1 : search Amazon
alb2eng,sq2en: |en|$1 : translate shqip-->Eng
eng2alb,en2sq: |sq|$1 : translate Eng->Alb
u2a,d2a,u2l,d2l,usd,usd2all:$1&From=USD&To=ALL : Convert USD to ALL(leke)
a2u,l2u,a2d,l2d,leke,all2usd:$1&From=ALL&To=USD : Convert ALL(leke) to USD
e2u,e2d,eur2usd:$1&From=EUR&To=USD : Convert EURO to USD
e2a,e2l,,eur2all:$1&From=EUR&To=ALL : Convert EURO to ALL(leke)
g2u,p2u,g2d,p2d,gbp2usd:$1&From=GBP&To=USD : Convert GBP to USD
g2a,p2a,g2l,p2l,gbp2all:$1&From=GBP&To=ALL : Convert GBP to ALL(leke)

What else are others using? —Peter Bowers January 22, 2011, at 03:28 PM

Here are some of my shortcuts. I think I'll add the Amazon search and the money convertor (I now google "123.4 USD in EUR"). --Petko January 22, 2011, at 04:03 PM

 tr:|en|$1 : Any language to English
 w:$1 : Search en.wikipedia
 d:$1 : Search en.wiktionary
 archive:$1 : Web Archive, old website versions
 pm:$1 : internal search
 pmn:*$1* : "PageName contains"
 €:$1 : Convert Euros to USD, type "€ 100"
 £:$1 : Convert GBP to Euros, type "£ 100"
 $:$1 : Convert USD to Euros, type "$ 100"
 F:$1+F+to+C: Convert Fahrenheit to Celsius, type "F 100" (uppercase)
 C:$1+C+to+F: Convert Celsius to Fahrenheit, type "C 100" (uppercase)
 Y,year,cal:$1  : Perpetual yearly calendar, type "Y 2011"
 france:,+France,+to+$1,+France : driving directions from Paris to anywhere

 yt:$1 : search videos on Youtube
 in:$1 : search

 mpg:$1+mpg+in+l/100km : Convert miles per gallon to liters/100km, type "mpg 80"
 l100:$1+l/100km+in+mpg : Convert liters/100km to miles per gallon, type "l100 3.2"
 mph:$1+mph+in+kph : Convert miles per hour to km/h, type "mph 85"
 kph:$1+kph+in+mph : Convert km/h to miles per hour, type "kph 50"

Note, international characters like "€" and "£" above may not work if your wiki is not using UTF-8.

You can find out the address of a custom search on any website. Perform a search for a string like "PMWIKI", then copy the url from your address bar. Paste the url to your DTRT page, replacing "PMWIKI" with "$1". --Petko January 22, 2011, at 04:18 PM

Installing DTRT has become one of the first configuration items I do on a new machine! I just noticed today when I started a search with that I ended up in an error box:
The address wasn't understood

          Firefox doesn't know how to open this address, because the protocol (site) isn't associated with any program.

It seems to be interpreting my site: as a protocol (like http:) rather than a search term. I can easily work around this by searching "foo" instead of " foo" but I'm wondering if there's a better way... Peter Bowers September 04, 2012, at 08:19 AM

I'm having the same issue, Firefox thinks a string starting with [a-z]+: is a protocol:address. When I get the error, I go at the beginning and insert "g<space>" which is treated as shortcut, that is <f6><home>g<space><enter>. Alternatively it may be convenient for you to have a dtrt shortcut "site " and write site query instead of site:example.... I haven't found the time to search the firefox documentation if unknown protocols could be sent to the search engine - if you find out a way, tell me. --Petko September 04, 2012, at 09:40 AM

I wanted to show a friend how DTRT worked and (since he's remote) the form you have documented on the main page seemed like an easy way to do it. However, when I set it up with action="{$PageUrl}" it loses my pagename. If I set it up with action="Cookbook.DoTheRightThing-Talk" then I lose my index.php? . I got it working by adding (:input hidden n "{$FullName}":) but I'm wondering if I have something wrong in my CleanUrls setup or something or if this was just an oversight in the setup of the form? Peter Bowers February 09, 2013, at 11:45 PM

It looks like wikis without CleanUrls need this additional hidden field, so I added it. --Petko February 10, 2013, at 02:50 AM

I just ran the site analyzer and it doesn't report correctly on DTRT. I believe this is due to the name of the recipe being DTRT while the name of the cookbook page is DoTheRightThing, but I'm not 100% sure... Peter Bowers February 10, 2013, at 12:04 AM

Yes, changing the RecipeInfo key fixes this. I have upload a new version with this only change. --Petko February 10, 2013, at 02:39 AM

Noted that regex must be anchored - might be a good thing to note in the docs. It makes sense, but I had some difficulty figuring out why p(?:m(?:wiki)?)? was matching "spotlight" for a while. Peter Bowers February 10, 2013, at 12:24 AM

The regular expressions are not even documented, because I'm not completely sure I want them this way. While the current complete syntax should work in the future, we may figure out some easier or simpler way to write regexps. --Petko February 10, 2013, at 02:39 AM

Talk page for the Do the Right Thing recipe (users).