Extension:UserPageViewTracker

Description
This extension allows users who have the right "userpagehits" to track usage of the site. It will display the pages visited per users, # of visits, and last visit.

Every time a user visits a page, a table in the database gets updated with the hit count for the user on that page. In other words, for every page & user combination, there is a hitcount.

The special page displays this information and allows the filtering of users to either include only or exclude. A list of users can be provided by using the pipe symbol (|) as a delimiter.

Installation

 * 1) Execute the SQL scripts below to create the table and view needed by the extension. Make sure to set the appropriate prefix.
 * 2) Copy & paste the PHP code below into a new file called "UserPageViewTracker.php" located in your extensions directory.
 * 3) Add the lines to the end of your LocalSettings.php file:

You will now have a new security group called "userpagehits" you can assign users to.

UserPageViewTracker.php
';       	        $s .=   $up->getNavigationBar ; } else { $s .=  ' '. wfMsgHTML('listusers-noresult'). ' ';	       };

$wgOut->addHTML( $s ); } }

require_once("$IP/includes/Pager.php");

class UserPageHitsPager extends AlphabeticPager {	protected $rowCount = 0;
 * 1) create a custom pager

function __construct($username=null) { global $wgRequest; $this->filterUsers = $filterUsers != "" ? $filterUsers : $wgRequest->getVal( 'filterusers' ); $this->filterUserList = explode("|", $this->filterUsers);

$this->ignoreUsers = $ignoreUsers != "" ? $ignoreUsers : $wgRequest->getVal( 'ignoreusers' ); $this->ignoreUserList = explode("|", $this->ignoreUsers); parent::__construct; }

function getIndexField { return "rownum"; }

function getQueryInfo { list ($userpagehits) = wfGetDB->tableNamesN('user_page_hits'); $conds = array; if($this->filterUsers) { $includeUsers = "user_name in ( '";			$includeUsers .= implode("', '", $this->filterUserList)."')"; $conds[] = $includeUsers; #$conds[] = "user_name = ".wfGetDB->addQuotes($this->requestedUser); }		if($this->ignoreUsers) { $excludeUsers = "user_name not in ( '";			$excludeUsers .= implode("', '", $this->ignoreUserList)."')"; $conds[] = $excludeUsers; }		$table = "(select @rownum:=@rownum+1 as rownum,";		$table .= "user_name, user_real_name, page_namespace, page_title,hits, last ";		$table .= "from (select @rownum:=0) r, ";		$table .= "(select user_name, user_real_name, page_namespace, page_title,hits,"; $table .= "last from user_page_hits) p) results"; return array(			'tables' => " $table ",			'fields' => array( 'rownum', 'user_name', 'user_real_name', 'page_namespace', 'page_title', 'hits', "concat(substr(last, 1, 4),'-',substr(last,5,2),'-',substr(last,7,2),' ',substr(last,9,2),':',substr(last,11,2),':',substr(last,13,2)) AS last"),			'conds' => $conds		);

}

function formatRow( $row ) { $userPage = Title::makeTitle( NS_USER, $row->user_name ); $name = $this->getSkin->makeLinkObj( $userPage, htmlspecialchars( $userPage->getText ) ); $pageTitle = Title::makeTitle( $row->page_namespace, $row->page_title ); if($row->page_namespace > 0) { $pageFullName = $pageTitle->getNsText.":".htmlspecialchars($pageTitle->getText ); } else { $pageFullName = htmlspecialchars( $pageTitle->getText); }		$page = $this->getSkin->makeLinkObj( $pageTitle, $pageFullName );

$this->rowCount += 1;

$res = ' '; $res .= "$this->rowCount "; $res .= ' '.$name.' '; if ($row->user_real_name) {			$res .= $row->user_real_name.' '; }		else {			$res .= ' '; }		$res .= "$page "; $res .= "$row->hits "; $res .= "$row->last "; $res .= " \n"; return $res; }

function getBody { if (!$this->mQueryDone) { $this->doQuery; }		$batch = new LinkBatch; $db = $this->mDb;

$this->mResult->rewind;

$this->rowCount = 0;

while ( $row = $this->mResult->fetchObject ) { $batch->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) ); }		$batch->execute; $this->mResult->rewind; return parent::getBody; }

#this is where we set up the form at the top of the special page to be able to set filters function getPageHeader { $out = "\n"; $out .="Usernames: "; $out .=""; $out .="       "; $out .="Usernames: "; $out .=""; $out .=" \n \n"; return $out; }

/**	 * Preserve filter offset parameters when paging * @return array */	function getDefaultQuery { $query = parent::getDefaultQuery; if( $this->filterUsers != '' ) $query['filterusers'] = $this->filterUsers; if( $this->ignoreUsers != '' ) $query['ignoreusers'] = $this->ignoreUsers; return $query; }

}

?>