saper has uploaded a new change for review.
https://gerrit.wikimedia.org/r/254646
Change subject: Redefine HitCounters magic words
......................................................................
Redefine HitCounters magic words
{{NUMBEROFVIEWS}} is now the total number
of visits to the site, as it was before
this extensions got extracted from
the MediaWiki core
{{NUMBEROFPAGEVIEWS}} is a new magic words
that provides number of visits to the page,
as presented in the page's footer.
This is what {{NUMBEROFVIEWS}} presented
in the earlier versions of this extension.
Bump extension version to 0.3
Bug: T105862
Change-Id: Ie2ce867643a465b58272a09bf3abedc3b5947e34
---
M HitCounters.body.php
M HitCounters.hooks.php
M HitCounters.i18n.magic.php
M HitCounters.php
M extension.json
5 files changed, 39 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/HitCounters
refs/changes/46/254646/1
diff --git a/HitCounters.body.php b/HitCounters.body.php
index cba4fc7..f938f67 100644
--- a/HitCounters.body.php
+++ b/HitCounters.body.php
@@ -88,6 +88,9 @@
}
/**
+ *
+ * {{NUMBEROFVIEWS}} - number of total views of the site
+ *
* We can't choose our parameters since this is a hook and we
* don't really need to use the $parser and $cache parameters.
*
@@ -96,6 +99,17 @@
public static function numberOfViews(
Parser &$parser, PPFrame $frame, $args
) {
+ return self::views( );
+ }
+
+ /*
+ * {{NUMBEROFPAGEVIEWS}} - number of total views of the page
+ *
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public static function numberOfPageViews(
+ Parser &$parser, PPFrame $frame, $args
+ ) {
return self::getCount( $frame->title );
}
diff --git a/HitCounters.hooks.php b/HitCounters.hooks.php
index bf0d594..f38e388 100644
--- a/HitCounters.hooks.php
+++ b/HitCounters.hooks.php
@@ -79,13 +79,21 @@
return $ret;
}
+ protected static function getMagicWords() {
+ return array(
+ 'numberofviews' => array(
'HitCounters\HitCounters', 'numberOfViews' ),
+ 'numberofpageviews' => array(
'HitCounters\HitCounters', 'numberOfPageViews' )
+ );
+ }
+
public static function onMagicWordwgVariableIDs( array &$variableIDs ) {
- $variableIDs[] = 'numberofviews';
+ $variableIDs = array_merge( $variableIDs, array_keys(
self::getMagicWords() ) );
}
public static function onParserFirstCallInit( Parser $parser ) {
- $parser->setFunctionHook( 'numberofviews',
'HitCounters:numberOfViews',
- Parser::SFH_OBJECT_ARGS );
+ foreach( self::getMagicWords() as $magicWord =>
$processingFunction )
+ $parser->setFunctionHook( $magicWord,
$processingFunction,
+ Parser::SFH_OBJECT_ARGS );
return true;
}
@@ -93,11 +101,16 @@
array $cache, &$magicWordId, &$ret, PPFrame &$frame ) {
global $wgDisableCounters;
- if ( !$wgDisableCounters && $magicWordId === 'numberofviews' ) {
- $ret = CoreParserFunctions::formatRaw(
- HitCounters::numberOfViews( $parser, $frame,
null ), null );
- } elseif ( $wgDisableCounters && $magicWordId ===
'numberofviews' ) {
- wfDebugLog( 'HitCounters', 'Counters are disabled!' );
+ foreach( self::getMagicWords() as $magicWord =>
$processingFunction ) {
+ if ( $magicWord === $magicWordId ) {
+ if ( !$wgDisableCounters ) {
+ $ret = CoreParserFunctions::formatRaw(
+ call_user_func(
$processingFunction, $parser, $frame, null ), null );
+ return true;
+ } else {
+ wfDebugLog( 'HitCounters', 'Counters
are disabled!' );
+ }
+ }
}
return true;
}
diff --git a/HitCounters.i18n.magic.php b/HitCounters.i18n.magic.php
index 3180fbc..dde1174 100644
--- a/HitCounters.i18n.magic.php
+++ b/HitCounters.i18n.magic.php
@@ -8,6 +8,7 @@
/** English (English) */
$magicWords['en'] = array(
'numberofviews' => array( 0, 'NUMBEROFVIEWS' ),
+ 'numberofpageviews' => array( 0, 'NUMBEROFPAGEVIEWS' ),
);
/** Egyptian Arabic (مصرى) */
@@ -163,4 +164,4 @@
/** Vietnamese (Tiếng Việt) */
$magicWords['vi'] = array(
'numberofviews' => array( 0, 'SỐ_LẦN_XEM', 'SỐLẦNXEM' ),
-);
\ No newline at end of file
+);
diff --git a/HitCounters.php b/HitCounters.php
index 501a46e..706aab4 100644
--- a/HitCounters.php
+++ b/HitCounters.php
@@ -11,7 +11,7 @@
* @copyright 2015 Mark A. Hershberger
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public
License, version 3
* (or later)
- * @version GIT: 0.1
+ * @version GIT: 0.3
* @link https://www.mediawiki.org/wiki/Extension:HitCounters
*/
diff --git a/extension.json b/extension.json
index 4194547..1826005 100644
--- a/extension.json
+++ b/extension.json
@@ -1,7 +1,7 @@
{
"name": "HitCounters",
"namemsg": "hitcounters-extensionname",
- "version": "0.2",
+ "version": "0.3",
"author": [
"[//mwstake.org Mark A. Hershberger]"
],
--
To view, visit https://gerrit.wikimedia.org/r/254646
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2ce867643a465b58272a09bf3abedc3b5947e34
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/HitCounters
Gerrit-Branch: master
Gerrit-Owner: saper <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits