Difference between revisions of "Extension talk:SearchLog.php"

From Organic Design wiki
(Change source-code blocks to standard format)
 
Line 16: Line 16:
 
:you can use a regular expression to convert the # into # --[[User:Sven|Sven]] 11:32, 8 February 2008 (NZDT)
 
:you can use a regular expression to convert the # into # --[[User:Sven|Sven]] 11:32, 8 February 2008 (NZDT)
 
:At about line 95 if you change the for loop to;
 
:At about line 95 if you change the for loop to;
{{code|<php>
+
<source lang="php">
  foreach ($total as $k => $v) {
+
foreach ($total as $k => $v) {
 
                                 $k = preg_replace("/#/", "&#35;", $k);
 
                                 $k = preg_replace("/#/", "&#35;", $k);
 
                                 $table .= "<tr><td>$k</td><td>$v</td></tr>\n";
 
                                 $table .= "<tr><td>$k</td><td>$v</td></tr>\n";
 
                               }
 
                               }
</php>
+
</source>  
}}
 
 
that should now show the raw UTF-8 characters --[[User:Sven|Sven]]. If the regex converted the &'s then unicode like  '&rarr;' would also be converted to &#38;rarr; --[[User:Sven|Sven]] 11:39, 8 February 2008 (NZDT)
 
that should now show the raw UTF-8 characters --[[User:Sven|Sven]]. If the regex converted the &'s then unicode like  '&rarr;' would also be converted to &#38;rarr; --[[User:Sven|Sven]] 11:39, 8 February 2008 (NZDT)
 
: Can you download the new version and see if it what you want, you can test it on this wiki at [[Special:SearchLog]] --[[User:Sven|Sven]] 12:11, 8 February 2008 (NZDT)
 
: Can you download the new version and see if it what you want, you can test it on this wiki at [[Special:SearchLog]] --[[User:Sven|Sven]] 12:11, 8 February 2008 (NZDT)
 
:: That does not help. If yor need, I could send you my log - it is small. By the way, in the code you wrote  
 
:: That does not help. If yor need, I could send you my log - it is small. By the way, in the code you wrote  
{{code|<php>
+
<source lang="php">
 
$k = preg_replace("/&/", "&#38;", $k);
 
$k = preg_replace("/&/", "&#38;", $k);
</php>
+
</source>  
}}
 
 
:: what is correct? And [[Special:SearchLog]] does not work: I see no statistic. --[[User:Konstbel|Konstbel]] 06:17, 13 February 2008 (NZDT)
 
:: what is correct? And [[Special:SearchLog]] does not work: I see no statistic. --[[User:Konstbel|Konstbel]] 06:17, 13 February 2008 (NZDT)
 
::: the fix is in [[Extension:SearchLog.php]] ([http://www.organicdesign.co.nz/wiki/index.php?title=Extension%3ASearchLog.php&diff=81153&oldid=79828 diff]). The Special page lookslike it is useable only by the Sysops, it should be accessible to test now. I have found another issue with ^M's stuffing up the log file, so I will have to address that, probably with a regex m/\r//g; --[[User:Sven|Sven]] 08:46, 13 February 2008 (NZDT)
 
::: the fix is in [[Extension:SearchLog.php]] ([http://www.organicdesign.co.nz/wiki/index.php?title=Extension%3ASearchLog.php&diff=81153&oldid=79828 diff]). The Special page lookslike it is useable only by the Sysops, it should be accessible to test now. I have found another issue with ^M's stuffing up the log file, so I will have to address that, probably with a regex m/\r//g; --[[User:Sven|Sven]] 08:46, 13 February 2008 (NZDT)
Line 45: Line 43:
 
::::::: Ou, YES! In your case non-english chars left intact (case-sensitive), in my - incorrectly lowercased. We need fix that. --[[User:Konstbel|Konstbel]] 22:52, 14 February 2008 (NZDT)
 
::::::: Ou, YES! In your case non-english chars left intact (case-sensitive), in my - incorrectly lowercased. We need fix that. --[[User:Konstbel|Konstbel]] 22:52, 14 February 2008 (NZDT)
 
::::::::I've changed the line
 
::::::::I've changed the line
{{code|<php>$i = strtolower(trim($phrase));</php>}}
+
<source lang="php">
 +
$i = strtolower(trim($phrase));
 +
</source>  
 
::::::::to  
 
::::::::to  
{{code|<php>$i = mb_strtolower(trim($phrase),"UTF-8");</php>}}
+
<source lang="php">
 +
$i = mb_strtolower(trim($phrase),"UTF-8");
 +
</source>  
 
::::::::that works for me. --[[User:Konstbel|Konstbel]] 21:46, 18 February 2008 (NZDT)
 
::::::::that works for me. --[[User:Konstbel|Konstbel]] 21:46, 18 February 2008 (NZDT)
  
Line 73: Line 75:
 
* I have the same issue with the count always displaying as '''1'''.  I'm running MW-1.11.1
 
* I have the same issue with the count always displaying as '''1'''.  I'm running MW-1.11.1
 
:: OK, "rescue yourself". The error is in line  
 
:: OK, "rescue yourself". The error is in line  
{{code|<php>
+
<source lang="php">
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i]++ : 1;
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i]++ : 1;
</php>}}
+
</source>  
 
the right code is  
 
the right code is  
{{code|<php>
+
<source lang="php">
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i] + 1 : 1;
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i] + 1 : 1;
</php>}}
+
</source>  
 
In addition I've added tha square brackets in the line
 
In addition I've added tha square brackets in the line
{{code|<php>
+
<source lang="php">
 
$table .= "<tr><td>[[$k]]</td><td>$v</td></tr>\n";
 
$table .= "<tr><td>[[$k]]</td><td>$v</td></tr>\n";
</php>}}
+
</source>  
 
so, the search phrases now works as hyper-links
 
so, the search phrases now works as hyper-links
 
--[[User:Konstbel|Konstbel]] 01:21, 20 March 2008 (NZST)
 
--[[User:Konstbel|Konstbel]] 01:21, 20 March 2008 (NZST)
 
: Thanks for the feedback. Feel free in future to add your suggestions to the article code. The population of the array $total is equivalent to
 
: Thanks for the feedback. Feel free in future to add your suggestions to the article code. The population of the array $total is equivalent to
{{code|<php>
+
<source lang="php">
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? ++$total[$i] : 1;
 
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? ++$total[$i] : 1;
</php>
+
</source>  
}}
 
 
This works. Creating links out of the phrases searched is a good idea, generally they will be red, unless an article has been created later on. Your fix and suggestion has been added to the new version 1.0.8 --[[User:Sven|Sven]] 04:10, 20 March 2008 (NZST)
 
This works. Creating links out of the phrases searched is a good idea, generally they will be red, unless an article has been created later on. Your fix and suggestion has been added to the new version 1.0.8 --[[User:Sven|Sven]] 04:10, 20 March 2008 (NZST)

Latest revision as of 18:11, 22 May 2015

Search result page instead of editting page

I am just wondering how we can link the search string (like organic) to its result page in search at http://www.organicdesign.co.nz/Special:Search?search=organic&go=Go

I tried different ideas trying to replace/recreate $k but none of them worked.

Also, it would be useful to display the username who searched for the string and "Guest" when not logged in.

Thanks,

Problem with UTF8 chars

The search log incorrectly displays UTF-8 characters (as black diamonds with question sign inside). Could you help to fix that?

The UTF-8 is converted automatically when in the source code of an html page, to stop it rendering you need to escape wither the & or the # with its UTF-8 code e.g.
To display ¼ as &#188;
you can use a regular expression to convert the # into &#35; --Sven 11:32, 8 February 2008 (NZDT)
At about line 95 if you change the for loop to;
foreach ($total as $k => $v) {
                                $k = preg_replace("/#/", "&#35;", $k);
                                $table .= "<tr><td>$k</td><td>$v</td></tr>\n";
                              }

that should now show the raw UTF-8 characters --Sven. If the regex converted the &'s then unicode like '→' would also be converted to &rarr; --Sven 11:39, 8 February 2008 (NZDT)

Can you download the new version and see if it what you want, you can test it on this wiki at Special:SearchLog --Sven 12:11, 8 February 2008 (NZDT)
That does not help. If yor need, I could send you my log - it is small. By the way, in the code you wrote
$k = preg_replace("/&/", "&#38;", $k);
what is correct? And Special:SearchLog does not work: I see no statistic. --Konstbel 06:17, 13 February 2008 (NZDT)
the fix is in Extension:SearchLog.php (diff). The Special page lookslike it is useable only by the Sysops, it should be accessible to test now. I have found another issue with ^M's stuffing up the log file, so I will have to address that, probably with a regex m/\r//g; --Sven 08:46, 13 February 2008 (NZDT)
Yes, I've downloaded it, but it does not help. The only difference I see is a replacement of "&", but "&" is absent in my log. I've downloaded my log to File:Wikilog.doc (its a plain text, not MSWord document), could you look? --Konstbel 22:59, 13 February 2008 (NZDT)
That's fun: I see russian word in your Special:SearchLog, but new searches do not logged aren't they? --Konstbel 23:05, 13 February 2008 (NZDT)
I have just logged a new search, if you have a search that did not, can you paste it in a
<pre>...
tag here please --Sven 06:29, 14 February 2008 (NZDT)
I have tested your log see;
Screenshot using User:Konstbels log file -File:Wikilog.doc

These characters do not look right to me. Were your searches russian characters that were different to that? --Sven 06:25, 14 February 2008 (NZDT)

OK, I've just pressed wrong button: only "Binocular" button is logged. Your log works correct, I see correct russian letters there:
RusTest1.gif,
and here is my log, as I see it in UTF-8 editor (in Notepad looks the same but without line feeds):
RusTest2.gif.
I've saved the HTML code of your and my Special:SearchLog page, your UTF-8 chars look correct, but not mine. I suppose some unwanted encoding while reading log file from the disk: the text "123_тест" looks like (hex) 31 32 33 5F D1 82 D0 B5 D1 81 D1 82 in the log file and like 31 32 33 5F F1 82 F0 B5 F1 83 F1 82 in HTML, so some chars were partially "lowercased".
Ou, YES! In your case non-english chars left intact (case-sensitive), in my - incorrectly lowercased. We need fix that. --Konstbel 22:52, 14 February 2008 (NZDT)
I've changed the line
$i = strtolower(trim($phrase));
to
$i = mb_strtolower(trim($phrase),"UTF-8");
that works for me. --Konstbel 21:46, 18 February 2008 (NZDT)

Searches containing ^M (\r) characters

The log file formatting seems to be getting stuffed up by ^M characters e.g.

20080212,08:06:16,195.225.177.39,go,pezos fimipufo gakma^M
<a href="http://ka282141.ru7xdjv.net/sitemap23.html ">lota</a> http://ka282141.ru7xdjv.net/sitemap23.html [url=http://ka282141.ru7xdjv.net/sitemap23.html ]livi[/url]  wosub
20080212,22:54:52,161.53.9.39,go,Only for you:^M
<a href="http://volny.cz/topamax/">Topamax</a>^M
<a href="http://condylox.hit.bg/">Condylox</a>^M
<a href="http://enterprisecar.hit.bg/">Enterprise rent a car</a>^M
<a href="http://cardealer.hit.bg/">Car dealer</a>^M
^M
See you!

It probably needs a search and replace s/\r//g; --Sven 08:52, 13 February 2008 (NZDT)

Counting does not work

Another problem: "Number of occurrences" always displays "1". I tried to search you site for "123_тест" and "ajax", but the counters in Special:SearchLog still showing only one occurrence of each phrase. --Konstbel 22:02, 18 February 2008 (NZDT)

I checked on my local development machine and it worked fine, however the reason that this could happen is if the log file is readable, but not writable, i.e. new searches do not add to the log file, hense the number of occurrences does not increase. This appears to be happening on Organic Design we probably just need to change the permissions on the file to allow write access. I will check later tonite. --Sven 11:24, 19 February 2008 (NZDT)
No, new searches are added to log file at Organic Design (I searched for "my_search"), but the counter is always "one", regardless of times I searched this phrase. --Konstbel 05:27, 28 February 2008 (NZDT)
  • I have the same issue with the count always displaying as 1. I'm running MW-1.11.1
OK, "rescue yourself". The error is in line
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i]++ : 1;

the right code is

if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? $total[$i] + 1 : 1;

In addition I've added tha square brackets in the line

$table .= "<tr><td>[[$k]]</td><td>$v</td></tr>\n";

so, the search phrases now works as hyper-links --Konstbel 01:21, 20 March 2008 (NZST)

Thanks for the feedback. Feel free in future to add your suggestions to the article code. The population of the array $total is equivalent to
if ($period == $wgSearchLogEntireLog || $period == $p) $total[$i] = isset($total[$i]) ? ++$total[$i] : 1;

This works. Creating links out of the phrases searched is a good idea, generally they will be red, unless an article has been created later on. Your fix and suggestion has been added to the new version 1.0.8 --Sven 04:10, 20 March 2008 (NZST)