Difference between revisions of "Extension:SearchLog.php"

From Organic Design wiki
(Changed to a specialpage)
Line 2: Line 2:
 
# Extension:SearchLog{{Category:Extensions}}{{#Security:*|dev}}{{#Security:view|*}}{{php}}
 
# Extension:SearchLog{{Category:Extensions}}{{#Security:*|dev}}{{#Security:view|*}}{{php}}
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
# - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
+
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:SpecialPage}}
 
   
 
   
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
   
 
   
define('SEARCHLOG_VERSION','0.0.1, 2007-05-17');
+
define('SEARCHLOG_VERSION','0.0.0, 2007-05-20');
 
+
$wgSearchLogFile       = dirname(__FILE__)."/search.log";
+
$wgSearchLogPath       = dirname(__FILE__);
 
$wgExtensionFunctions[] = 'wfSetupSearchLog';
 
$wgExtensionFunctions[] = 'wfSetupSearchLog';
 
+
$wgExtensionCredits['other'][] = array(
+
$wgExtensionCredits['specialpage'][] = array(
'name'        => 'SearchLog',
+
'name'        => 'Special:SearchLog',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
 
'author'      => '[http://www.organicdesign.co.nz/nad User:Nad]',
'description' => 'An example extension made with [http://www.mediawiki.org/wiki/Extension:SearchLog Extension:SearchLog]',
+
'description' => 'Logs usage of the search box and allows reporting of keyword totals during given time periods',
'url'        => 'http://www.organicdesign.co.nz/Extension:Example',
+
'url'        => 'http://www.mediawiki.org/wiki/Extension:SearchLog',
 
'version'    => SEARCHLOG_VERSION
 
'version'    => SEARCHLOG_VERSION
 
);
 
);
  
 +
# Called from SpecialPage::execute()
 +
wfSpecialSearchLog($param,&$specialpage) {
 +
global $wgOut;
 +
$title = Title::makeTitle(NS_SPECIAL,'SearchLog');
 +
 +
# Render a dropdown of months/years covered by the range of the log entries
 +
$wgOut->addHTML(
 +
wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'POST'),null)
 +
. '<textarea name="target" cols=25 rows=10></textarea>'
 +
. wfElement('input',array('type' => 'submit'))
 +
. '</form>'
 +
);
 +
}
 +
 +
# Called from $wgExtensionFunctions array when initialising extensions
 
function wfSetupSearchLog() {
 
function wfSetupSearchLog() {
global $wgSearchLogFile,$wgUser;
+
global $wgMessageCache,$wgSpecialPages,$wgSearchLogPath,$wgUser;
  
 
# If a search has been posted, log the info
 
# If a search has been posted, log the info
Line 28: Line 43:
 
else $type = 'other';
 
else $type = 'other';
  
# Log the data to the file
+
# Append the data to the file
if ($fh = fopen($wgSearchLogFile,'a')) {
+
if ($fh = fopen("$wgSearchLogPath/search.log",'a')) {
fwrite($fh,
+
#fwrite($fh,...
 
}
 
}
 
}
 
}
}  
+
 
 +
# Add the messages used by the specialpage
 +
$wgMessageCache->addMessages(array(
 +
'searchlog' => 'Logs usage of the search box and allows reporting of keyword totals during given time periods',
 +
));
 +
 +
# Add the specialpage to the environment
 +
$wgSpecialPages['SearchLog'] = array(
 +
'SpecialPage', # class to instantiate
 +
'SearchLog',  # name as seen in links
 +
'sysop',      # user rights required
 +
true,          # listed in special:specialpages
 +
false,        # function called by execute() - defaults to wfSpecial{$name}
 +
false,        # file included by execute() - defaults to Special{$name}.php, only used if no function
 +
false          # includable
 +
);
 +
}
 
?>
 
?>

Revision as of 01:30, 20 May 2007

<?php

  1. Extension:SearchLog
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

{{#Security:*|dev}}{{#Security:view|*}}Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:SpecialPage

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('SEARCHLOG_VERSION','0.0.0, 2007-05-20');

$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 );

  1. Called from SpecialPage::execute()

wfSpecialSearchLog($param,&$specialpage) { global $wgOut; $title = Title::makeTitle(NS_SPECIAL,'SearchLog');

# Render a dropdown of months/years covered by the range of the log entries $wgOut->addHTML( wfElement('form',array('action' => $title->getLocalURL('action=submit'),'method' => 'POST'),null) . '<textarea name="target" cols=25 rows=10></textarea>' . wfElement('input',array('type' => 'submit')) . '</form>' ); }

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupSearchLog() { global $wgMessageCache,$wgSpecialPages,$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['go'])) $type = 'fulltext'; else $type = 'other';

# Append the data to the file if ($fh = fopen("$wgSearchLogPath/search.log",'a')) { #fwrite($fh,... } }

# Add the messages used by the specialpage $wgMessageCache->addMessages(array( 'searchlog' => 'Logs usage of the search box and allows reporting of keyword totals during given time periods', ));

# Add the specialpage to the environment $wgSpecialPages['SearchLog'] = array( 'SpecialPage', # class to instantiate 'SearchLog', # name as seen in links 'sysop', # user rights required true, # listed in special:specialpages false, # function called by execute() - defaults to wfSpecial{$name} false, # file included by execute() - defaults to Special{$name}.php, only used if no function false # includable ); } ?>