Difference between revisions of "Extension:SearchLog.php"
m |
m |
||
Line 32: | Line 32: | ||
function execute() { | function execute() { | ||
global $wgOut,$wgSearchLogPath; | global $wgOut,$wgSearchLogPath; | ||
− | $title = Title::makeTitle(NS_SPECIAL,'SearchLog'); | + | $title = Title::makeTitle(NS_SPECIAL,'SearchLog'); |
+ | $period = $_REQUEST['period']; | ||
# Get the dates of the first and last entries for the dropdown list range | # Get the dates of the first and last entries for the dropdown list range | ||
Line 46: | Line 47: | ||
} | } | ||
− | # Construct a list of months | + | # Construct a list of months if first and last successfully obtained |
$months = ''; | $months = ''; | ||
if ($y1 && $y2) while (($y1*100+$m1) <= ($y2*100+$m2)) { | if ($y1 && $y2) while (($y1*100+$m1) <= ($y2*100+$m2)) { | ||
− | $ | + | $p = strftime('%b %Y',mktime(0,0,0,$m1,1,$y1)); |
− | $selected = $ | + | $selected = $p == $period ? ' selected' : ''; |
− | $months .= "<option$selected>$ | + | $months .= "<option$selected>$p</option>\n"; |
if ($m1 == 12) { $m1 = 1; $y1++; } else $m1++; | if ($m1 == 12) { $m1 = 1; $y1++; } else $m1++; | ||
} | } | ||
Line 62: | Line 63: | ||
. '</form>' | . '</form>' | ||
); | ); | ||
+ | |||
+ | # Generate a report if a period was specified | ||
+ | if ($period) { | ||
+ | } | ||
} | } | ||
Revision as of 04:09, 23 May 2007
<?php
- Extension:SearchLog
{{#Security:*|dev}}{{#Security:view|*}}Template:Php
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:SpecialPage
- - Started: 2007-05-16
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('SEARCHLOG_VERSION','0.0.0, 2007-05-21');
$wgSearchLogPath = dirname(__FILE__); $wgExtensionFunctions[] = 'wfSetupSearchLog';
$wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:SearchLog', 'author' => 'User:Nad', 'description' => 'Logs usage of the search box and allows reporting of keyword totals during given time periods', 'url' => 'http://www.mediawiki.org/wiki/Extension:SearchLog', 'version' => SEARCHLOG_VERSION );
require_once "$IP/includes/SpecialPage.php";
class SpecialSearchLog extends SpecialPage {
# Constructor function SpecialSearchLog() { SpecialPage::SpecialPage('SearchLog'); }
# Override SpecialPage::execute() function execute() { global $wgOut,$wgSearchLogPath; $title = Title::makeTitle(NS_SPECIAL,'SearchLog'); $period = $_REQUEST['period'];
# Get the dates of the first and last entries for the dropdown list range if ($fh = fopen("$wgSearchLogPath/search.log",'r')) { if (ereg('^([0-9]{4})([0-9]{2})[0-9]{2},',fread($fh,16),$m)) list(,$y1,$m1,$d1) = $m; $len = fstat($fh); $len = $len['size'] % 1024; fseek($fh,-$len,SEEK_END); $end = explode("\n",fread($fh,$len)); $end = $end[count($end)-2]; if (ereg('^([0-9]{4})([0-9]{2})[0-9]{2},',$end,$m)) list(,$y2,$m2,$d2) = $m; fclose($fh); }
# Construct a list of months if first and last successfully obtained $months = ; if ($y1 && $y2) while (($y1*100+$m1) <= ($y2*100+$m2)) { $p = strftime('%b %Y',mktime(0,0,0,$m1,1,$y1)); $selected = $p == $period ? ' selected' : ; $months .= "<option$selected>$p</option>\n"; if ($m1 == 12) { $m1 = 1; $y1++; } else $m1++; }
# Render the months as a dropdown-list $wgOut->addHTML( wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'POST'),null) . "Select time period: <select name=\"period\"><option>Entire log</option>$months</select>" . wfElement('input',array('type' => 'submit')) . '</form>' );
# Generate a report if a period was specified if ($period) { } }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupSearchLog() { global $wgLanguageCode,$wgMessageCache,$wgSearchLogPath,$wgUser;
# If a search has been posted, log the info if (isset($_REQUEST['search'])) { if (isset($_REQUEST['go'])) $type = 'go'; else if (isset($_REQUEST['fulltext'])) $type = 'fulltext'; else $type = 'other';
# Append the data to the file if ($fh = fopen("$wgSearchLogPath/search.log",'a')) { $text = date('Ymd,H:i:s,').$wgUser->getName().",$type,".$_REQUEST['search']; fwrite($fh,"$text\n"); fclose($fh); } }
# Add the messages used by the specialpage $wgMessageCache->addMessages(array( 'searchlog' => 'Search Log', ));
# Add the specialpage to the environment SpecialPage::addPage(new SpecialSearchLog()); } ?>