Extension:ViewCounter

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
viewCounter

Release status: beta

Implementation Parser function
Description This extension allows you access the number of views of an article or file
Author(s) João Sarmento
Last version 0.1
MediaWiki 1.10.x+
PHP php5
License GPL
Download see below
Example <viewCounter>ArticleName</viewCounter>

<viewCounter>FileName</viewCounter>

Check usage (experimental)

The viewCounter extension adds the <viewCount> tag for returning the number of times an article or file were accessed.

[edit] Installation

  1. Copy viewCounter.php to the new file viewCounter.php in your MediaWiki extensions directory.
  2. Enable the extension by adding this line to the bottom of your LocalSettings.php:
 require_once("$IP/extensions/viewCounter.php");

[edit] Usage

  • <viewCounter>ArticleName</viewCounter>
  • <viewCounter>FileName</viewCounter>

[edit] Source of ViewCounter.php

 <?php
 /**
  * MediaWiki viewCounter extension
  *
  * @version 0.1
  * @author Joao Sarmento
  * @link http://www.mediawiki.org/wiki/Extension:viewCounter
  */
 
 $wgExtensionCredits['parserhook'][] = array(
      'name' => 'viewCounter',
      'author' =>'Joao Sarmento',
      'version' => '0.1', 
      'url' => 'http://www.mediawiki.org/wiki/User:JSarmento', 
      'description' => 'This extension allows you access the number of views of an article or file'
       );
 
 $wgExtensionFunctions[] = 'registerViewCounterHandler';
 
 function registerViewCounterHandler () {
   global $wgParser;
   $wgParser->setHook( 'viewCounter', 'embedViewCounterHandler' );
 }
 
 function embedViewCounterHandler ($input) {
   global $wgDBprefix;
   $db = wfGetDB ( DB_SLAVE );
   $query = "select page_counter from `".$wgDBprefix."page` where page_title = '".$input."'";
   $res=$db->doQuery($query);
   $output=0;
   while( ($row = $db->fetchRow($res) ) != null  ){
     $output+=$row[0];
   }
   $db->freeResult($res);
 
   return $output;
 }
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox