Extension talk:HitCounters

About this board

Please create Phabricator tasks if you run into bugs
I need bug reports in Phabricator so that they can be worked on. If you run into a problem with one of the following, please create a phabricator task and link to it here. -- MarkAHershberger(talk) 16:03, 30 July 2016 (UTC)

--> Archived talk

Upgrade from TopTenPages (1.24)

4
5.10.10.117 (talkcontribs)

Hello everyone, I'm looking to upgrade a wiki from version 1.24 to the current MW version. Currently, it's using the "TopTenPages" extension for tracking view counts. I've noticed that "TopTenPages" has eventually become dependent on "HitCounts". However, the "HitCounts" extension is not currently installed. Is it possible to migrate from "TopTenPages" to "HitCounts" and then follow the instructions to preserve the view counts for the updated wiki?

WikiForMen (talkcontribs)

Hopefully you have followed these instructions while upgrading:

https://www.mediawiki.org/w/index.php?oldid=6146163#Migration

If not, you will have eliminate your hitcounter values. ;-)

For upgrading a wiki from version 1.24 you have to install HitCounters version compatible with REL1_25, i.e.:

https://github.com/WikiMANNia/Mediawiki-Extension-HitCounters/releases/tag/REL1_25-v0.5.0

So you should upgrade first to version 1.25, install HitCounters REL1_25-v0.5.0, update your database ("maintenance/update.php"). This will save your hitcounter values into a new hitcounter table. After that you may upgrade to a current MW version.

134.34.7.73 (talkcontribs)

Thanks for these very clear instructions!

WikiForMen (talkcontribs)

You may have a backup of your database.

1. You may start with the backup of your database, following the steps above mentioned.

2. You may use a parallel installation with DB name "25_yourdatabasename" and Domain 25.yourdomain.org and following the above mentionend steps. Then you may copy manually both database tables "hit_counter" and "hit_counter_extension" from DB "25_yourdatabasename" into "yourdatabasename".

Reply to "Upgrade from TopTenPages (1.24)"

Make special page transcludable

1
S0ring (talkcontribs)

Is it possible to make Special:PopularPages transcludable? If yes, how?


In the older Extension:TopTenPages extension it was possible to do something like:

<TopTenPages offset=0 >30</TopTenPages> || {{Special:ContributionScores/25/100}}

but this attempt didn't work {{Special:PopularPages}}, it shows the URL only

Reply to "Make special page transcludable"
WikiForMen (talkcontribs)

1. In HCUpdater.php the stuff around 'rename_table.sql' should be removed, because it is only needed in MediaWiki in Version 1.25.

2. In HitCounters.hooks.php the "$contLang->formatNum()" does not set the punctuation correctly in the internationalisation of the comma number:

		$totalViews = HitCounters::views() ?? 0;
		$extraStats = [
			'hitcounters-statistics-header-views' => [
				'hitcounters-statistics-views-total' => $totalViews,
				'hitcounters-statistics-views-peredit' => $contLang->formatNum(
					$totalViews
					? sprintf( '%.2f', $totalViews / SiteStats::edits() )
					: 0
				) ],
			'hitcounters-statistics-mostpopular' => self::getMostViewedPages( $statsPage )
		];

Moreover, it does not prevent the division by zero.

This should do the job accurately:

		$totalEdits = SiteStats::edits() ?? 0;
		$totalViews = HitCounters::views() ?? 0;
		$extraStats['hitcounters-statistics-header-views']
			['hitcounters-statistics-views-total'] = $totalViews;
		$extraStats['hitcounters-statistics-header-views']
			['hitcounters-statistics-views-peredit'] =
				( $totalEdits > 0 )
				? sprintf( '%.2f', $totalViews / $totalEdits )
				: 0;
				) ],
			'hitcounters-statistics-mostpopular' => self::getMostViewedPages( $statsPage )
		];

3. In SpecialPopularPages.php, what exactly is "getPrefixedText()" doing here?

		$link = $this->getLinkRenderer()->makeKnownLink(
			$title,
			$this->getContentLanguage()->convert( $title->getPrefixedText() )
		);

I guess, this is doing the job as well:

		$link = $this->getLinkRenderer()->makeKnownLink( $title )
		);

--WikiForMen (talk) 18:55, 4 October 2023 (UTC)

Pppery (talkcontribs)
Reply to "Code Review"

Special:PopularPages limit

2
John Koughto (talkcontribs)

I did install this extension however the Special:PopularPages is limited to 10000 entries (navigating using offset= in the URL).

It's not cached and i.e. Special:ShortPages on the same wiki is capable of displaying items from 10001 and more (the wiki have about 80000 articles).

Is there a way to make it so it loads more than 10000 entries? I did check the code and it seems there are no visible limit in this extension and the special page itself is marked as not expensive (so MiserMode shouldn't have effect on it).

WikiForMen (talkcontribs)

I found this in "abstract class QueryPage":

	/**
	 * Get max number of results we can return in miser mode.
	 *
	 * Most QueryPage subclasses use inefficient paging, so limit the max amount we return
	 *
	 * @stable to override
	 * @since 1.27
	 * @return int
	 */
	protected function getMaxResults() {
		// Max of 10000, unless we store more than 10000 in query cache.
		return max( $this->getConfig()->get( 'QueryCacheLimit' ), 10000 );
	}

Try to add this into "class SpecialPopularPages":

	protected function getMaxResults() {
		$your_limit = 20000;
		return max( $this->getConfig()->get( 'QueryCacheLimit' ), $your_limit );
	}

--WikiForMen (talk) 19:09, 4 October 2023 (UTC)

Reply to "Special:PopularPages limit"

Error: Class 'MWNamespace' not found

3
Vicarage (talkcontribs)

MediaWiki 1.39.1 PHP 7.4.3-4ubuntu2.19 (apache2handler) MySQL 8.0.34-0ubuntu0.20.04.1 ICU 66.1

HitCounters-REL1_39-e759c39.tar.gz

did the composer install and ran the update script. I get

[35f31966c348bbdee9c42ea7] /Special:PopularPages Error: Class 'MWNamespace' not found

Backtrace:

from /var/www/html/wiki/underfoot/extensions/HitCounters/includes/HitCounters.body.php(134)
#0 /var/www/html/wiki/underfoot/extensions/HitCounters/includes/SpecialPopularPages.php(52): HitCounters\HitCounters::getQueryInfo()

and

Fatal error: Declaration of MWCallbackStream::write($string) must be compatible with Psr\Http\Message\StreamInterface::write(string $string): int in /var/www/html/wiki/underfoot/includes/http/MWCallbackStream.php on line 46

I see https://www.mediawiki.org/wiki/Manual:MWNamespace.php/en says

This feature was removed from MediaWiki core in version 1.39 (phab:rMWea1c106ea9a3) (after being deprecated in 1.34). Please see NamespaceInfo.php for an alternative way to use this feature.
WikiForMen (talkcontribs)
Vicarage (talkcontribs)
Reply to "Error: Class 'MWNamespace' not found"

Hit Counts not registering

2
2600:4041:2028:4500:C0CE:60FC:5078:D26B (talkcontribs)

We downloaded the 1.35 version of the Extension for our MediaWiki 1.35 version and installed, successfully ran update.php, and see the hit_counter and hit_counter_extension tables in our database.

No matter how many times I visit pages on our wiki, no record gets created in either table though.

I see warnings in log about "use of undefined constant DB_PRIMARY" in ViewCountUpdate.php (that it seems to resolve fine), which tells me that the scripts are being called. I tried changing the script to get a log statement to print which failed, and the script's existing wfDebugLog statements dont appear in logs either.

I used mysql commands to insert a record artificially into hit_counter table with a page_id and view count, and visiting that page will display "page has been accessed 5 times" at bottom, as well as appearing now on Popular Pages. But will still not increment on its own (even when other users, signed in or not, visit pages).

Suggested solutions on similar posts below did not help either. Anyone have any ideas what we could try at this point?

WikiForMen (talkcontribs)
Reply to "Hit Counts not registering"

Updating Database Not Working

3
Cozbaldwin (talkcontribs)

Hi there. First time installing this extension. I put the folder in the extensions directory. I added the include to localsettings. I went to /mw-config to update the database and it's on the "installation complete" screen. So i went ahead and restarted the whole installation. Completed. But when I load a page full of code not unlike what people have documented here previously. It seems like this would be simple enough but I don't know what else to do.

I'm guessing the database was not updated and looking at it, I'm not seeing a hitcounters table either, so yeah. How can I force the database to add the HitCounters tables? Do I need to have the include turned ON in localsettings when running the upgrade? (I had to turn it off because the wiki was inaccessible to my users)...

Cozbaldwin (talkcontribs)

UPDATE! yes! in fact, you DO need to have the loadextension in localsettings turned on when running the database update/restart installation. It now works!

Wikidev23 (talkcontribs)

Thanks for noting that you have to Restart the update script, not mentioned anywhere else.

Reply to "Updating Database Not Working"

Installation with Composer requires Git?

1
Eric L8s (talkcontribs)

Hi there,

I was trying to install the extension with Composer as suggested and Composer says the following:

In GitDownloader.php line 77:

  git was not found in your PATH, skipping source download

Reply to "Installation with Composer requires Git?"

Hit Count reported in Popular Pages is incorrect

8
PaulTimperley (talkcontribs)

This MediaWiki-based wiki has been running for some years without issues. I added the HitCounters extension when that was removed from the main software install; again, no issues until recently.

A few days ago I updated the site to version 1.38.1. HitCounters extension is 0.3.4.

in Special Pages -> Popular Pages, all pages show the same (large) hit count as the site's Main Page.

The hit count at the bottom of each page is still correct, and increments when the page is refreshed.

I assume the bug was not there with the previous MediaWiki version 1.37.1, I think I would have noticed.

103.140.78.202 (talkcontribs)

I suspect this has someting to do with the join_conds on getQueryInfo

Saucy (talkcontribs)

I have the same issue. Anyone know of a way to fix this?

Mochome (talkcontribs)

I have the same issue (mw1.38.1), so I looked at the log file and found the following output:

SELECT p.page_namespace AS `namespace`,p.page_title AS `title`,h.page_counter AS `value`,p.page_len AS `length`  FROM `page` `p`,`hit_counter` `h`    WHERE p.page_is_redirect = 0 AND p.page_namespace IN (0,12,4,3000)   ORDER BY value DESC LIMIT 51

I don't see a JOIN clause for hit_counter and page, is this the expected behavior?

217.71.1.56 (talkcontribs)

I have the same issue for 1.38

Mochome (talkcontribs)

I tried changing includes/HitCounters.body.php line 133 (public static function getQueryInfo) 'page' to 'p' then it seems to work.

132                         'join_conds' => [
133 #                               'page' => [
133                                 'p' => [
134                                         'INNER JOIN',
135                                         'p.page_id = h.page_id'
136                                 ]
137                         ]
212.84.154.148 (talkcontribs)

Thanks Mochome, this was also the fix for me!

Reply to "Hit Count reported in Popular Pages is incorrect"

Not Registering Hits Or Showing Page Hit Counts on page

2
Nwroble (talkcontribs)

I have MediaWiki version 1.35 installed. I attempted to install HitCounters version 0.3.4. I have followed all the configuration steps I can see in the extension description page, however, for some reason in my environment it does not seem to be working. After doing the update.php I do see that the tables exist in the mariadb database, and the Special:Version table does indicate the extension is installed. I queried both of the database tables and they exist but neither has data. Have visited multiple pages several times but nothing is shown on the pages, the database, or the statistics pages. Wondering if something else is preventing the hits from being registered. I have LDAP authentication stack working and you must be a logged in user to create/edit pages. Hoping someone might have ideas. Thanks for any assistance.

173.30.219.19 (talkcontribs)

Can you try accessing a page with couple different browsers? After I did that a few times I am now seeing "This page has been accessed 4 times." at bottom of page.

Reply to "Not Registering Hits Or Showing Page Hit Counts on page"