DoTheRightThing-Talk

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)
    /^\\s*(\\S*)\\s*:[^\\S\n]*(\\S*)/m
instead of
/^\\s*(\\S*):[^\\S\n]+(\\S*)/m
  • 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:                      http://images.google.com/images?q=$1 : Google images
fm:                      http://freshmeat.net/search/?section=projects&q=$1 : Freshmeat (software)
php:                     http://php.net/search.php?lang=en&show=quickref&pattern=$1 : PHP manual
pmwiki,pm,p:             http://www.google.com/search?q=site%3Apmwiki.org+$1 : PmWiki search
pmc,cookbook:            http://www.pmwiki.org/wiki/Cookbook/$1 : Cookbook recipe
pmw:                     http://www.pmwiki.org/wiki/PmWiki/$1 : PmWiki page
map,maps:                http://www.google.com/maps?q=$1 : Search Google Maps
pm:                      http://www.pmwiki.org/wiki/?action=search&q=$1 : search PmWiki.org
imdb:                    http://www.imdb.com/find?s=all&q=$1 : search IMDB for movies
ar:                      http://allrecipes.com/Search/Recipes.aspx?WithTerm=$1 : search AllRecipes
bbc:                     http://www.bbc.co.uk/search/news/$1 : search BBC News
fox:                     http://www.foxnews.com/search-results/search?q=$1&submit=Search : search FoxNews
dtrt:                    {$ScriptUrl}?n=Main.DTRT?action=edit : test : Edit this page
e,ebay:                  http://shop.ebay.com/?_from=R40&_trksid=p5197.m570.l1313&_sacat=See-All-Categories&_nkw=$1 : search ebay
a,am,amazon:             http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&x=0&y=0&field-keywords=$1 : search Amazon
alb2eng,sq2en:           http://translate.google.com/#sq|en|$1 : translate shqip-->Eng
eng2alb,en2sq:           http://translate.google.com/#en|sq|$1 : translate Eng->Alb
u2a,d2a,u2l,d2l,usd,usd2all: http://www.xe.com/ucc/convert.cgi?Amount=$1&From=USD&To=ALL : Convert USD to ALL(leke)
a2u,l2u,a2d,l2d,leke,all2usd:http://www.xe.com/ucc/convert.cgi?Amount=$1&From=ALL&To=USD : Convert ALL(leke) to USD
e2u,e2d,eur2usd:         http://www.xe.com/ucc/convert.cgi?Amount=$1&From=EUR&To=USD : Convert EURO to USD
e2a,e2l,,eur2all:        http://www.xe.com/ucc/convert.cgi?Amount=$1&From=EUR&To=ALL : Convert EURO to ALL(leke)
g2u,p2u,g2d,p2d,gbp2usd: http://www.xe.com/ucc/convert.cgi?Amount=$1&From=GBP&To=USD : Convert GBP to USD
g2a,p2a,g2l,p2l,gbp2all: http://www.xe.com/ucc/convert.cgi?Amount=$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:      http://translate.google.com/#auto|en|$1 : Any language to English
 w:       https://secure.wikimedia.org/wikipedia/en/wiki/Special:Search?go=1&search=$1 : Search en.wikipedia
 d:       https://secure.wikimedia.org/wiktionary/en/wiki/Special:Search?go=1&search=$1 : Search en.wiktionary
 archive: http://web.archive.org/archive_request_ng?collection=web&url=$1 : Web Archive, old website versions
 pm:      http://www.pmwiki.org/wiki/?action=search&q=$1 : PmWiki.org internal search
 pmn:     http://www.pmwiki.org/wiki/?action=search&q=name=*$1* : PmWiki.org "PageName contains"
 €:       http://www.xe.com/ucc/convert.cgi?From=EUR&To=USD&Amount=$1 : Convert Euros to USD, type "€ 100"
 £:       http://www.xe.com/ucc/convert.cgi?From=GBP&To=EUR&Amount=$1 : Convert GBP to Euros, type "£ 100"
 $:       http://www.xe.com/ucc/convert.cgi?From=USD&To=EUR&Amount=$1 : Convert USD to Euros, type "$ 100"
 F:       http://www.google.com/search?q=$1+F+to+C: Convert Fahrenheit to Celsius, type "F 100" (uppercase)
 C:       http://www.google.com/search?q=$1+C+to+F: Convert Celsius to Fahrenheit, type "C 100" (uppercase)
 Y,year,cal: http://5ko.free.fr/en/year.php?y=$1  : Perpetual yearly calendar, type "Y 2011"
 france:  https://maps.google.com/maps?q=from+Paris,+France,+to+$1,+France : driving directions from Paris to anywhere

 yt:      http://www.youtube.com/results?search_query=$1 : search videos on Youtube
 in:      http://www.google.com/search?q=site:instructables.com+$1 : search instructables.com

 mpg:     http://www.google.com/search?q=$1+mpg+in+l/100km : Convert miles per gallon to liters/100km, type "mpg 80"
 l100:    http://www.google.com/search?q=$1+l/100km+in+mpg : Convert liters/100km to miles per gallon, type "l100 3.2"
 mph:     http://www.google.com/search?q=$1+mph+in+kph : Convert miles per hour to km/h, type "mph 85"
 kph:     http://www.google.com/search?q=$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 site:www.example.com 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 site:example.com" instead of "site:example.com 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 example.com 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).