Extension:WSStats: Difference between revisions
MW v1.35x |
No edit summary |
||
| Line 7: | Line 7: | ||
|hook1=ParserFirstCallInit |
|hook1=ParserFirstCallInit |
||
|hook2=BeforePageDisplay |
|hook2=BeforePageDisplay |
||
|hook3=LoadExtensionSchemaUpdates |
|||
|hook4=ScribuntoExternalLibraries |
|||
|hook5=AdminLinks |
|||
|newhook1=<!-- hooks added by the extension, see [[Template:Extension]] for details --> |
|newhook1=<!-- hooks added by the extension, see [[Template:Extension]] for details --> |
||
|newhook2= |
|newhook2= |
||
| Line 15: | Line 18: | ||
|imagesize= |
|imagesize= |
||
|version=1.0.8 |
|version=1.0.8 |
||
|update= |
|update=28-09-2023 |
||
|version preview= |
|version preview= |
||
|update preview= |
|update preview= |
||
|compatibility policy= |
|compatibility policy=ltsrel |
||
|mediawiki=1. |
|mediawiki=1.35.+;1.39+ |
||
|php= |
|php= |
||
|needs-updatephp=yes |
|needs-updatephp=yes |
||
| Line 40: | Line 43: | ||
|hook4=AdminLinks |
|hook4=AdminLinks |
||
}} |
}} |
||
Version 1.0.8 will be the last release for MediaWiki Version 1.35.x |
|||
Version 2.0.0 is for MediaWiki version 1.39.x. |
|||
{{note|1=Make sure you update to at least version 1.0.6 due to a security risk|2=warn}} |
{{note|1=Make sure you update to at least version 1.0.6 due to a security risk|2=warn}} |
||
'''WSStats''' extension counts pageviews by user using the before page display hook. There is no client JavaScript run or any trackers installed. |
'''WSStats''' extension counts pageviews by user using the before page display hook. There is no client JavaScript run or any trackers installed. |
||
* Version 2.0.0 : REL 1.39 only. Added statistics for Special Pages. Lua equivalent functions for statistics. Special Page added. |
|||
* Version 1.0.8 : Removed global references |
* Version 1.0.8 : Removed global references |
||
* Version 1.0.7 : Added statistics over time for pages |
* Version 1.0.7 : Added statistics over time for pages |
||
| Line 68: | Line 78: | ||
{{ExtensionInstall|db-update=yes|registration=required}} |
{{ExtensionInstall|db-update=yes|registration=required}} |
||
=== Upgrading === |
|||
If you are upgrading from a version before 2.0, then you must visit the Special Page : '''Special:WSStats'''. If the database tables need updating, it will show you there and you can update the tables. You will have to update the tables for statistics to be accurate. This is because we now allow to get statistics based on page titles, while the previous version of WSStats did not store titles. |
|||
== Configuration parameters == |
== Configuration parameters == |
||
| Line 76: | Line 89: | ||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgWSStats= |
$wgWSStats=[]; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
| Line 84: | Line 97: | ||
//Record anonymous users |
//Record anonymous users |
||
$wgWSStats['skip_anonymous']=false; |
$wgWSStats['skip_anonymous']=false; |
||
| ⚫ | |||
By default Special Pages are counted as well. To omit Special pages set the following : |
|||
| ⚫ | |||
// Special Pages statistics |
|||
$wgWSStats['countSpecialPages'] = false; // defaults to true |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
| Line 93: | Line 113: | ||
$wgWSStats['skip_user_groups'][]='admin'; |
$wgWSStats['skip_user_groups'][]='admin'; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Count all hits.. |
|||
| ⚫ | |||
$wgWSStats = array(); |
|||
$wgWSStats['count_all_usergroups'] = true; |
|||
| ⚫ | |||
{{note|1=If you have set <syntaxhighlight lang="php" inline>$wgWSStats['count_all']=true;</syntaxhighlight> then <syntaxhighlight lang="php" inline>$wgWSStats['skip_user_groups']</syntaxhighlight> is ignored.}} |
|||
Skip page with certain text in their referer url. Default action=edit and veaction=edit are ignored. This configuration option is case sensitive. |
Skip page with certain text in their referer url. Default action=edit and veaction=edit are ignored. This configuration option is case sensitive. |
||
| Line 120: | Line 131: | ||
{{#wsstats:id=9868}} |
{{#wsstats:id=9868}} |
||
</pre> |
</pre> |
||
You can also ask for statistics based on title, instead of Page Id's. |
|||
'''Ask number of hits for page with title : Main Page''' |
|||
''This returns a number'' |
|||
<pre> |
|||
{{#wsstats:title=Main Page}} |
|||
</pre> |
|||
''About dates. Dates are in a format of YYYY-MM-DD. Internally WSStats works with Date and Time. |
|||
This means a date of '''2023-10-30''' will internally become '''2023-10-30 00:00:00'''. You can also search by date and time. See the example about this.'' |
|||
'''Ask number of hits for page id : 714 since start date 2018-09-01''' |
'''Ask number of hits for page id : 714 since start date 2018-09-01''' |
||
| Line 126: | Line 151: | ||
<pre> |
<pre> |
||
{{#wsstats:id=714 |
{{#wsstats:id=714 |
||
|start date= |
|start date=2023-09-01}} |
||
</pre> |
</pre> |
||
| Line 134: | Line 159: | ||
<pre> |
<pre> |
||
{{#wsstats:id=714 |
{{#wsstats:id=714 |
||
|start date= |
|start date=2023-02-01|end date=2023-09-08}} |
||
</pre> |
</pre> |
||
'''You can also get statistics based on date and time Get number of hits for page id : 714 from start date 2023-10-30 14:00:00 and end date 2023-10-30 16:00:00''' |
|||
''This returns a number'' |
|||
<pre> |
|||
{{#wsstats:id=714 |
|||
|start date=2023-10-30 14:00:00 |
|||
|end date=2023-10-30 16:00:00 |
|||
}} |
|||
</pre> |
|||
'''Filter results on registered users or anonymous users''' |
'''Filter results on registered users or anonymous users''' |
||
| Line 142: | Line 178: | ||
<pre> |
<pre> |
||
{{#wsstats:id=714 |
{{#wsstats:id=714 |
||
|start date= |
|start date=2023-02-01 |
||
|end date= |
|end date=2023-02-08 |
||
|type=only anonymous}} |
|type=only anonymous}} |
||
</pre> |
</pre> |
||
| Line 149: | Line 185: | ||
<pre> |
<pre> |
||
{{#wsstats:id=714 |
{{#wsstats:id=714 |
||
|start date= |
|start date=2023-02-01 |
||
|end date= |
|end date=2023-02-08 |
||
|type=only user}} |
|type=only user}} |
||
</pre> |
</pre> |
||
| Line 164: | Line 200: | ||
<pre> |
<pre> |
||
{{#wsstats:stats |
{{#wsstats:stats |
||
|start date= |
|start date=2023-02-01 |
||
|end date= |
|end date=2023-02-08}} |
||
</pre> |
</pre> |
||
| Line 197: | Line 233: | ||
{{#wsstats:stats |
{{#wsstats:stats |
||
|id=1 |
|id=1 |
||
|start date= |
|start date=2023-02-01 |
||
|end date= |
|end date=2023-02-08 |
||
|limit 100 |
|limit 100 |
||
}} |
}} |
||
| Line 208: | Line 244: | ||
<pre> |
<pre> |
||
{{#wsstats:stats |
{{#wsstats:stats |
||
|start date= |
|start date=2023-02-01 |
||
|end date= |
|end date=2023-02-08 |
||
|unique}} |
|unique}} |
||
</pre> |
</pre> |
||
| Line 226: | Line 262: | ||
|limit=20}} |
|limit=20}} |
||
</pre> |
</pre> |
||
== Using the lua functions == |
|||
New in version 2.0 |
|||
There are two Lua function you can use. |
|||
For the parser function that returns a table ( {{#wsstats:stats.. ) you can use wsstats.stats(). |
|||
For the parser function that returns a number ( {{wsstats:... ) you can use wsstats.stat(); |
|||
All the arguments are the same as for the parser functions, except : |
|||
* start date = startDate |
|||
* end date = endDate |
|||
==== Example ==== |
|||
If you create a Module called WSStats and you add the following content : |
|||
<pre>lua |
|||
local p = {} |
|||
function p.stats(frame) |
|||
stats = mw.wsstats.stats( frame.args ) |
|||
return stats |
|||
end |
|||
function p.stat(frame) |
|||
stat = mw.wsstats.stat( frame.args ) |
|||
return stat |
|||
end |
|||
return p |
|||
</pre> |
|||
You can then do calls like : |
|||
<pre> |
|||
{{#invoke:wsstats|stats}} // returns a Lua table |
|||
</pre> |
|||
<pre> |
|||
{{#invoke:wsstats|stat|id=1|startDate=2023-09-25|endDate=2023-09-26}} |
|||
</pre> |
|||
'''Date format to use''' |
'''Date format to use''' |
||
Revision as of 09:05, 28 September 2023
Release status: stable |
|
|---|---|
| Implementation | Parser extension |
| Description | Collect page statistics |
| Author(s) | Charlot Cobben (Sen-Saitalk) |
| Latest version | 1.0.8 (28-09-2023) |
| Compatibility policy | For every MediaWiki release that is a Long Term Support release there is a corresponding branch in the extension. |
| MediaWiki | 1.35.+;1.39+ |
| Database changes | Yes |
| Composer | wikibase-solutions/w-s-stats |
|
$wgWSSStats |
|
|
wikibasesolutions, page statistics |
|
| Licence | GNU General Public License 2.0 or later |
| Download | GitHub:
Note: [README] |
Version 1.0.8 will be the last release for MediaWiki Version 1.35.x
Version 2.0.0 is for MediaWiki version 1.39.x.
WSStats extension counts pageviews by user using the before page display hook. There is no client JavaScript run or any trackers installed.
- Version 2.0.0 : REL 1.39 only. Added statistics for Special Pages. Lua equivalent functions for statistics. Special Page added.
- Version 1.0.8 : Removed global references
- Version 1.0.7 : Added statistics over time for pages
- Version 1.0.6 : Fixed path to sql tables
- Version 1.0.5 : Rewrote database queries to use MW database abstraction layer. extension manifest 2 and all user input is validated.
- Version 1.0.4 : Security fix! Unhandled user input. Update to 1.0.4 as soon as possible.
- Version 1.0.3 : Top X list changed as it no longer shows deleted pages
- Version 1.0.2 : Catched request for title on a non-existing page
- Version 1.0.1 : Code clean-up and i18n messages added
- Version 1.0.0 : Added support for setting limit and export as WSArrays
- Version 0.8.2 : Added support for filtering only unique visitors
- Version 0.8.1 : adminlinks added
- Version 0.8.0 : Clean Up
- Version 0.1.9 : Fetch Title changes
- Version 0.1.8 : Removed dbprefix class variable
- Version 0.1.7 : Show top visited pages with date range. Show as csv option
- Version 0.1.6 : Filter results on user or anonymous
- Version 0.1.5 : Added more configuration options
- Version 0.1.3 : Fixed error in MySQL
- Version 0.1.2 : Skip usergroup results
- Version 0.1.1 : Initial release
Installation
- Download and place the file(s) in a directory called
WSStatsin yourextensions/folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'WSStats' );
- Run the update script which will automatically create the necessary database tables that this extension needs.
Done – Navigate to Special:Versionon your wiki to verify that the extension is successfully installed.
Upgrading
If you are upgrading from a version before 2.0, then you must visit the Special Page : Special:WSStats. If the database tables need updating, it will show you there and you can update the tables. You will have to update the tables for statistics to be accurate. This is because we now allow to get statistics based on page titles, while the previous version of WSStats did not store titles.
Configuration parameters
By default Anonymous users and sysops are skipped from stats recording. To change this add following to LocalSettings.php..
Start with:
$wgWSStats=[];
Allow statistics for anonymous users..
//Record anonymous users
$wgWSStats['skip_anonymous']=false;
By default Special Pages are counted as well. To omit Special pages set the following :
// Special Pages statistics
$wgWSStats['countSpecialPages'] = false; // defaults to true
Skip users in the following groups..
//Skip if user is in following groups
$wgWSStats['skip_user_groups'][]='sysop';
$wgWSStats['skip_user_groups'][]='admin';
Skip page with certain text in their referer url. Default action=edit and veaction=edit are ignored. This configuration option is case sensitive.
$wgWSStats['ignore_in_url'][] = 'Template:Test';
$wgWSStats['ignore_in_url'][] = 'action=edit';
Using the parser functions
To retrieve statistics you can use the following parser function :
Ask number of hits for page id : 9868
This returns a number
{{#wsstats:id=9868}}
You can also ask for statistics based on title, instead of Page Id's.
Ask number of hits for page with title : Main Page
This returns a number
{{#wsstats:title=Main Page}}
About dates. Dates are in a format of YYYY-MM-DD. Internally WSStats works with Date and Time.
This means a date of 2023-10-30 will internally become 2023-10-30 00:00:00. You can also search by date and time. See the example about this.
Ask number of hits for page id : 714 since start date 2018-09-01
This returns a number
{{#wsstats:id=714
|start date=2023-09-01}}
Ask number of hits for page id : 714 since start date 2018-02-01 and end date 2018-09-08
This returns a number
{{#wsstats:id=714
|start date=2023-02-01|end date=2023-09-08}}
You can also get statistics based on date and time Get number of hits for page id : 714 from start date 2023-10-30 14:00:00 and end date 2023-10-30 16:00:00
This returns a number
{{#wsstats:id=714
|start date=2023-10-30 14:00:00
|end date=2023-10-30 16:00:00
}}
Filter results on registered users or anonymous users
This returns a number
{{#wsstats:id=714
|start date=2023-02-01
|end date=2023-02-08
|type=only anonymous}}
This returns a number
{{#wsstats:id=714
|start date=2023-02-01
|end date=2023-02-08
|type=only user}}
Get the top ten pages sorted by hits
This returns a table
{{#wsstats:stats}}
Get the top ten pages sorted by hits in a date range
This returns a table from 2018-02-01 00:00:00 up to 2018-02-08 00:00:00 ( so not including 2018-02-08 )
{{#wsstats:stats
|start date=2023-02-01
|end date=2023-02-08}}
Get the top ten pages sorted by hits and show as csv
This returns a string with the results comma seperated (e.g. 1230;51,1;17,921)
{{#wsstats:stats
|format:csv}}
Get the top ten pages sorted by hits and insert in a WSArrays variable
This returns an empty string and sets the WSArray key. Nothing happens when the WSArrays extension is not installed
{{#wsstats:stats
|format:wsarrays}}
|name=<wsarray key name>}}
Get the result from WSArrays:
{{#caprint:<wsarray key name>}}
Get statistics of one page during a time period and limit to 100 results
New since version 1.0.7
This returns a table
{{#wsstats:stats
|id=1
|start date=2023-02-01
|end date=2023-02-08
|limit 100
}}
For all queries you can add a unique identifier to only return unique views
This returns a table
{{#wsstats:stats
|start date=2023-02-01
|end date=2023-02-08
|unique}}
This returns a table
{{#wsstats:stats
|unique}}
For all top ten stats queries you can add limit to get less or more than ten results
This returns a table
{{#wsstats:stats
|unique
|limit=20}}
Using the lua functions
New in version 2.0
There are two Lua function you can use.
For the parser function that returns a table ( {{#wsstats:stats.. ) you can use wsstats.stats().
For the parser function that returns a number ( {{wsstats:... ) you can use wsstats.stat();
All the arguments are the same as for the parser functions, except :
- start date = startDate
- end date = endDate
Example
If you create a Module called WSStats and you add the following content :
lua
local p = {}
function p.stats(frame)
stats = mw.wsstats.stats( frame.args )
return stats
end
function p.stat(frame)
stat = mw.wsstats.stat( frame.args )
return stat
end
return p
You can then do calls like :
{{#invoke:wsstats|stats}} // returns a Lua table
{{#invoke:wsstats|stat|id=1|startDate=2023-09-25|endDate=2023-09-26}}
Date format to use
| Date | Translates to |
|---|---|
| 2018-02-01 | First of February 2018 |
| 2018-02-01 11 | First of February 2018 at 11am |
| 2018-02-01 11:15 | First of February 2018 at a quarter past eleven in the morning |
| 2018-02-01 14:15:30 | First of February 2018 at a quarter past two in the afternoon and 30 seconds |
If no statistics the result will be 0
