r113517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113516‎ | r113517 | r113518 >
Date:20:10, 9 March 2012
Author:wikinaut
Status:new (Comments)
Tags:
Comment:
add tracking category feature (enabled by default). Each page using this extension get automatically the tracking category with MediaWiki:Wikiarticlefeeds-tracking-category name (= RSS authoring page). Tracking-Cat-Feature can be disabled, or a different MediaWiki message text can be assigned. Documentation of the switch is inline and follows on MediaWiki.
Modified paths:
  • /trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.i18n.php (modified) (history)
  • /trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.php (modified) (history)
  • /trunk/extensions/WikiArticleFeeds/WikiArticleFeeds_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiArticleFeeds/WikiArticleFeeds_body.php
@@ -3,6 +3,13 @@
44 class WikiArticleFeeds{
55
66 function feedStart( $text, $params = array() ) {
 7+ global $wgParser, $wgWikiArticleFeedsTrackingCategory;
 8+
 9+ if ( $wgWikiArticleFeedsTrackingCategory === true ) {
 10+ $wgParser->addTrackingCategory( 'wikiarticlefeeds-tracking-category' );
 11+ } elseif ( is_string( $wgWikiArticleFeedsTrackingCategory ) ) {
 12+ $wgParser->addTrackingCategory( $wgWikiArticleFeedsTrackingCategory );
 13+ }
714 return '<!-- FEED_START -->';
815 }
916
Index: trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.i18n.php
@@ -10,6 +10,7 @@
1111
1212 $messages['en'] = array(
1313 'wikiarticlefeeds-desc' => 'Produces feeds generated from MediaWiki pages',
 14+ 'wikiarticlefeeds-tracking-category' => 'RSS authoring page',
1415 'wikiarticlefeeds_combined_description' => 'This is a combined feed, containing items from several feed sources.',
1516 );
1617
@@ -19,6 +20,7 @@
2021 */
2122 $messages['qqq'] = array(
2223 'wikiarticlefeeds-desc' => '{{desc}}',
 24+ 'wikiarticlefeeds-tracking-category' => 'The name of a category for all pages which use the WikiArticleFeeds parser extension. The category is automatically added unless the feature is disabled.',
2325 );
2426
2527 /** Afrikaans (Afrikaans)
Index: trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.php
@@ -157,3 +157,16 @@
158158
159159 $wgWikiArticleFeeds = new WikiArticleFeeds();
160160 $wgHooks['ParserBeforeTidy'][] = array( $wgWikiArticleFeeds, 'WikiArticleFeeds::itemTagsPlaceholderCorrections' );
 161+
 162+// Parameter to enable the automatic tracking category
 163+// for all pages using this parser extension
 164+//
 165+// Category name [[MediaWiki:Wikiarticlefeeds-tracking-category]] (default)
 166+// $wgWikiArticleFeedsTrackingCategory = true;
 167+//
 168+// you can assign a specific category name [[MediaWiki:Wikiarticlefeeds-mycategory]]
 169+// $wgWikiArticleFeedsTrackingCategory = 'wikiarticlefeeds-mycategory';
 170+//
 171+// you can disable the use of a tracking category
 172+// $wgWikiArticleFeedsTrackingCategory = false;
 173+$wgWikiArticleFeedsTrackingCategory = true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r113541follow up rr113517 . Using the parser as passed as parameter appears to be a ...wikinaut23:13, 9 March 2012
r114170removed the redundant code for handling tracking categories. By using '-' for...wikinaut19:02, 19 March 2012

Comments

#Comment by MaxSem (talk | contribs)   20:46, 9 March 2012
  1. What if the parse is being performed by a different parser, not $wgParser? Calling parser gets passed as third parameter to the tag hook, use it.
  2. [[Category:RSS authoring page]] is not proper Ennglish.
#Comment by Wikinaut (talk | contribs)   20:48, 9 March 2012

Hi, pls. can you indicate exactly what to change ?

#Comment by Wikinaut (talk | contribs)   20:50, 9 March 2012

I mean, I don't know what you mean by "different parser". I am willing to learn, please let me know what I should change, or please, can you change it ?

#Comment by MaxSem (talk | contribs)   20:56, 9 March 2012
$p = new Parser();
$po = new ParserOptions();
$parser->parse( $text, $title, $po );

Tracking category doesn't gets added.

#Comment by Wikinaut (talk | contribs)   21:09, 9 March 2012

MaxSem, pls. indicate *exactly* what you would like me to change where in the code. I am willing to learn, but cannot know everything. I have the code running in all of my large wikis without problems.

If you think, my code should be changed, I appreciate, that you guide me a little bit (better).

#Comment by Wikinaut (talk | contribs)   21:06, 9 March 2012

"Tracking category doesn't gets added. " it does after editing.

#Comment by MaxSem (talk | contribs)   21:10, 9 March 2012

Riiiight. Because ordinary editing uses $wgParser. Unlike my example which fails because you always add this category to $wgParser.

#Comment by Wikinaut (talk | contribs)   21:12, 9 March 2012

You have more experience than I. Please let me know, how I can improve my code (currently, I do not know).

#Comment by Jeremyb (talk | contribs)   22:22, 9 March 2012

I pointed you to Manual:Tag extensions#Example on IRC and you still did not make any attempt at fixing this yourself. (AFAICT. and you requested a diff)

I made a diff but I'm not sure it's correct (either the MW bits or the php in general) and you /quit before I finished it.

From 1c5adc1e0b16d43591a57bfa78bc0e0f0902d896 Mon Sep 17 00:00:00 2001
From: jeremyb
Date: Fri, 9 Mar 2012 21:43:29 +0000
Subject: [PATCH] change per CR comments @ [[Special:Code/MediaWiki/113517|r113517]] to match
 [https://www.mediawiki.org/wiki/Manual:Tag_extensions?oldid=503252#Example https://www.mediawiki.org/wiki/Manual:Tag_extensions?oldid=503252#Example]

---
 WikiArticleFeeds.i18n.magic.php |    2 +-
 WikiArticleFeeds_body.php       |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/WikiArticleFeeds.i18n.magic.php b/WikiArticleFeeds.i18n.magic.php
index fb42a71..7299650 100644
--- a/WikiArticleFeeds.i18n.magic.php
+++ b/WikiArticleFeeds.i18n.magic.php
@@ -58,4 +58,4 @@ $magicWords['sr-ec'] = array(
 /** Serbian (Latin script) (‪Srpski (latinica)‬) */
 $magicWords['sr-el'] = array(
 	'itemtags' => array( 0, 'oznakestavke', 'oznake_stavke' ),
-);
\ No newline at end of file
+);
diff --git a/WikiArticleFeeds_body.php b/WikiArticleFeeds_body.php
index 8880048..98906d1 100644
--- a/WikiArticleFeeds_body.php
+++ b/WikiArticleFeeds_body.php
@@ -2,13 +2,13 @@
 
 class WikiArticleFeeds{
 
-	function feedStart( $text, $params = array() ) {
-		global $wgParser, $wgWikiArticleFeedsTrackingCategory;
+	function feedStart( $text, $params = array(), Parser $parser) {
+		global $wgWikiArticleFeedsTrackingCategory;
 
 		if ( $wgWikiArticleFeedsTrackingCategory === true ) {
-			$wgParser->addTrackingCategory( 'wikiarticlefeeds-tracking-category' );
+			$parser->addTrackingCategory( 'wikiarticlefeeds-tracking-category' );
 		} elseif ( is_string( $wgWikiArticleFeedsTrackingCategory ) ) {
-			$wgParser->addTrackingCategory( $wgWikiArticleFeedsTrackingCategory );
+			$parser->addTrackingCategory( $wgWikiArticleFeedsTrackingCategory );
 		}
 		return '<!-- FEED_START -->';
 	}
@@ -25,13 +25,13 @@ class WikiArticleFeeds{
 		return ( $text ? '<!-- ITEM_TAGS ' . base64_encode( serialize( $text ) ) . ' -->':'' );
 	}
 
-	function itemTagsFunction( $parser ) {
+	function itemTagsFunction( Parser $parser ) {
 		$tags = func_get_args();
 		array_shift( $tags );
 		return ( !empty( $tags ) ? '<pre>@ITEMTAGS@' . base64_encode( serialize( implode( ',', $tags ) ) ) . '@ITEMTAGS@</pre>':'' );
 	}
 
-	function itemTagsPlaceholderCorrections( $parser, &$text ) {
+	function itemTagsPlaceholderCorrections( Parser $parser, &$text ) {
 		$text = preg_replace(
 			'|<pre>@ITEMTAGS@([0-9a-zA-Z\\+\\/]+=*)@ITEMTAGS@</pre>|',
 			'<!-- ITEM_TAGS $1 -->',
@@ -41,7 +41,7 @@ class WikiArticleFeeds{
 	}
 
 	# Sets up the WikiArticleFeeds Parser hooks
-	static function wfWikiArticleFeedsSetup( $parser ) {
+	static function wfWikiArticleFeedsSetup( Parser $parser ) {
 		global $wgWikiArticleFeeds;
 
 		$parser->setHook( 'startFeed', array( $wgWikiArticleFeeds, 'feedStart' ) );
-- 
1.7.2.5
#Comment by Wikinaut (talk | contribs)   23:16, 9 March 2012

see follow up r113541

#Comment by Wikinaut (talk | contribs)   09:34, 10 March 2012

set new (see follow up r113541 where it is resolved)

#Comment by Wikinaut (talk | contribs)   06:57, 21 March 2012

Info: tracking category _parameter_ removed in r114170.

Status & tagging log