r111863 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111862‎ | r111863 | r111864 >
Date:13:16, 19 February 2012
Author:wikinaut
Status:deferred
Tags:
Comment:
fix for bug34487 PupDate not set in non-English wikis and is not detected when signature has Talkpage link between name and date. Adding extension-private attributes to user page and user_talk page links. Detecting them when rendering the feed. Extracting authors' names and timestamps using PHP strtotime() function. Relying on timestamp-delimiting timezone code in parentheses. May look hackish, but is a major improvement about previous versions, because the authors and timestamps are detected language-independently. If you have a better idea, please let us know by adding your implementation idea to https://bugzilla.wikimedia.org/show_bug.cgi?id=34487 .
Modified paths:
  • /trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.php
@@ -4,7 +4,7 @@
55 * @author Jim R. Wilson, Thomas Gries
66 * @maintainer Thomas Gries
77 *
8 - * @version 0.672
 8+ * @version 0.690
99 * @copyright Copyright (C) 2007 Jim R. Wilson
1010 * @license The MIT License - http://www.opensource.org/licenses/mit-license.php
1111 *
@@ -116,7 +116,7 @@
117117 die( "This is not a valid entry point.\n" );
118118 }
119119
120 -define( 'WIKIARTICLEFEEDS_VERSION', '0.672 20120217' );
 120+define( 'WIKIARTICLEFEEDS_VERSION', '0.690 20120219' );
121121
122122 # Bring in supporting classes
123123 require_once( "$IP/includes/Feed.php" );
@@ -137,7 +137,7 @@
138138 $wgExtensionMessagesFiles['WikiArticleFeedsMagic'] = $dir . 'WikiArticleFeeds.i18n.magic.php';
139139
140140 /**
141 - * Wrapper class for consolidating all WAF related parser methods
 141+ * Wrapper class for consolidating all WikiArticleFeeds related parser methods
142142 */
143143 class WikiArticleFeedsParser {
144144 function feedStart( $text, $params = array() ) {
@@ -195,7 +195,7 @@
196196 # Attach Hooks
197197 $wgHooks['OutputPageBeforeHTML'][] = 'wfAddWikiFeedHeaders';
198198 $wgHooks['SkinTemplateToolboxEnd'][] = 'wfWikiArticleFeedsToolboxLinks'; // introduced in 1.13
199 -
 199+$wgHooks['LinkEnd'][] = 'wfWikiArticleFeedsAddSignatureMarker';
200200 $wgHooks['UnknownAction'][] = 'wfWikiArticleFeedsAction';
201201 $wgHooks['ArticlePurge'][] = 'wfPurgeFeedsOnArticlePurge';
202202
@@ -252,6 +252,23 @@
253253 }
254254
255255 /**
 256+ * Add additional attributes to links to User- or User_talk pages.
 257+ * These are used later in wfGenerateWikiFeed to determine signatures with timestamps
 258+ * for attributing author and timestamp values to the feed item.
 259+ *
 260+ * Currently this method works only if the user page exists.
 261+ */
 262+# https://www.mediawiki.org/wiki/Manual:Hooks/LinkEnd
 263+function wfWikiArticleFeedsAddSignatureMarker( $skin, $title, $options, $text, &$attribs, $ret ) {
 264+ if ( $title->getNamespace() == NS_USER) {
 265+ $attribs['userpage-link'] = 'true';
 266+ } elseif ( $title->getNamespace() == NS_USER_TALK ) {
 267+ $attribs['usertalkpage-link'] = 'true';
 268+ }
 269+ return true;
 270+}
 271+
 272+/**
256273 * Adds the Wiki feed links to the bottom of the toolbox in Monobook or like-minded skins.
257274 *
258275 * Usage: $wgHooks['SkinTemplateToolboxEnd'][] = 'wfWikiArticleFeedsToolboxLinks';
@@ -442,10 +459,10 @@
443460 # Parse page into feed items.
444461 $content = $wgOut->parse( $article->getContent() . "\n__NOEDITSECTION__ __NOTOC__" );
445462 preg_match_all(
446 - '/<!--\\s*FEED_START\\s*-->(.*?)<!--\\s*FEED_END\\s*-->/s',
447 - $content,
448 - $matches
449 - );
 463+ '/<!--\\s*FEED_START\\s*-->(.*?)<!--\\s*FEED_END\\s*-->/s',
 464+ $content,
 465+ $matches
 466+ );
450467 $feedContentSections = $matches[1];
451468
452469 # Parse and process all feeds, collecting feed items
@@ -479,7 +496,6 @@
480497 if ( !$feedDescription ) {
481498 $feedDescription = $segDesc;
482499 } else {
483 -
484500 $feedDescription = wfMsg( 'wikiarticlefeeds_combined_description' );
485501 }
486502 }
@@ -511,30 +527,30 @@
512528 }
513529 if ( $skip ) continue;
514530
515 - # Determine the item author and date
 531+ # Try hard to determine the item author and date
 532+ # Look for a regular signatures of the layout
 533+ # userpage-link [optional user_talk page link] date (with a delimiting timezone code in parentheses)
 534+
516535 $author = null;
517536 $date = null;
 537+
518538 $signatureRegExp = '#<a href=".+?User:.+?" title="User:.+?">(.*?)</a> (\d\d):(\d\d), (\d+) ([a-z]+) (\d{4}) (\([A-Z]+\))#im';
 539+
 540+ $signatureRegExp1 = '#<.*userpage-link.*>(.*?)</a>.*<.*usertalkpage-link.*>.*</a>\) (.*\([A-Z]+\))#im';
 541+ $signatureRegExp2 = '#<.*userpage-link.*>(.*?)</a> (.*\([A-Z]+\))#im';
 542+ $signatureRegExp3 = '#<.*usertalkpage-link.*>(.*?)</a> (.*\([A-Z]+\))#im';
519543
520 - # Look for a regular ~~~~ sig
521 - $isAttributable = preg_match($signatureRegExp, $seg, $matches );
 544+ $isAttributable = ( preg_match( $signatureRegExp1, $seg, $matches )
 545+ || preg_match( $signatureRegExp2, $seg, $matches )
 546+ || preg_match( $signatureRegExp3, $seg, $matches ) );
522547
523 - # Parse it out - if we can
524548 if ( $isAttributable ) {
525549
526 - list( $author, $hour, $min, $day, $monthName, $year, $timezone ) = array_slice( $matches, 1 );
527 - $months = array(
528 - 'January' => '01', 'February' => '02', 'March' => '03', 'April' => '04',
529 - 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08',
530 - 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'
531 - );
532 - $month = $months[$monthName];
533 - $day = str_pad( $day, 2, '0', STR_PAD_LEFT );
534 - $date = $year . $month . $day . $hour . $min . '00';
535 -
 550+ list( $author, $timestring ) = array_slice( $matches, 1 );
 551+
536552 $tempTimezone = date_default_timezone_get();
537553 date_default_timezone_set( 'UTC' );
538 - $date = date( "YmdHis" , strtotime( "$year-$month-$day $hour:$min:00 $timezone" ) );
 554+ $date = date( "YmdHis" , strtotime( $timestring ) );
539555 date_default_timezone_set( $tempTimezone );
540556
541557 }

Status & tagging log