Index: trunk/extensions/WikiArticleFeeds/WikiArticleFeeds.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * @author Jim R. Wilson, Thomas Gries |
6 | 6 | * @maintainer Thomas Gries |
7 | 7 | * |
8 | | - * @version 0.672 |
| 8 | + * @version 0.690 |
9 | 9 | * @copyright Copyright (C) 2007 Jim R. Wilson |
10 | 10 | * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
11 | 11 | * |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | die( "This is not a valid entry point.\n" ); |
118 | 118 | } |
119 | 119 | |
120 | | -define( 'WIKIARTICLEFEEDS_VERSION', '0.672 20120217' ); |
| 120 | +define( 'WIKIARTICLEFEEDS_VERSION', '0.690 20120219' ); |
121 | 121 | |
122 | 122 | # Bring in supporting classes |
123 | 123 | require_once( "$IP/includes/Feed.php" ); |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | $wgExtensionMessagesFiles['WikiArticleFeedsMagic'] = $dir . 'WikiArticleFeeds.i18n.magic.php'; |
139 | 139 | |
140 | 140 | /** |
141 | | - * Wrapper class for consolidating all WAF related parser methods |
| 141 | + * Wrapper class for consolidating all WikiArticleFeeds related parser methods |
142 | 142 | */ |
143 | 143 | class WikiArticleFeedsParser { |
144 | 144 | function feedStart( $text, $params = array() ) { |
— | — | @@ -195,7 +195,7 @@ |
196 | 196 | # Attach Hooks |
197 | 197 | $wgHooks['OutputPageBeforeHTML'][] = 'wfAddWikiFeedHeaders'; |
198 | 198 | $wgHooks['SkinTemplateToolboxEnd'][] = 'wfWikiArticleFeedsToolboxLinks'; // introduced in 1.13 |
199 | | - |
| 199 | +$wgHooks['LinkEnd'][] = 'wfWikiArticleFeedsAddSignatureMarker'; |
200 | 200 | $wgHooks['UnknownAction'][] = 'wfWikiArticleFeedsAction'; |
201 | 201 | $wgHooks['ArticlePurge'][] = 'wfPurgeFeedsOnArticlePurge'; |
202 | 202 | |
— | — | @@ -252,6 +252,23 @@ |
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
| 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 | +/** |
256 | 273 | * Adds the Wiki feed links to the bottom of the toolbox in Monobook or like-minded skins. |
257 | 274 | * |
258 | 275 | * Usage: $wgHooks['SkinTemplateToolboxEnd'][] = 'wfWikiArticleFeedsToolboxLinks'; |
— | — | @@ -442,10 +459,10 @@ |
443 | 460 | # Parse page into feed items. |
444 | 461 | $content = $wgOut->parse( $article->getContent() . "\n__NOEDITSECTION__ __NOTOC__" ); |
445 | 462 | 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 | + ); |
450 | 467 | $feedContentSections = $matches[1]; |
451 | 468 | |
452 | 469 | # Parse and process all feeds, collecting feed items |
— | — | @@ -479,7 +496,6 @@ |
480 | 497 | if ( !$feedDescription ) { |
481 | 498 | $feedDescription = $segDesc; |
482 | 499 | } else { |
483 | | - |
484 | 500 | $feedDescription = wfMsg( 'wikiarticlefeeds_combined_description' ); |
485 | 501 | } |
486 | 502 | } |
— | — | @@ -511,30 +527,30 @@ |
512 | 528 | } |
513 | 529 | if ( $skip ) continue; |
514 | 530 | |
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 | + |
516 | 535 | $author = null; |
517 | 536 | $date = null; |
| 537 | + |
518 | 538 | $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'; |
519 | 543 | |
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 ) ); |
522 | 547 | |
523 | | - # Parse it out - if we can |
524 | 548 | if ( $isAttributable ) { |
525 | 549 | |
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 | + |
536 | 552 | $tempTimezone = date_default_timezone_get(); |
537 | 553 | date_default_timezone_set( 'UTC' ); |
538 | | - $date = date( "YmdHis" , strtotime( "$year-$month-$day $hour:$min:00 $timezone" ) ); |
| 554 | + $date = date( "YmdHis" , strtotime( $timestring ) ); |
539 | 555 | date_default_timezone_set( $tempTimezone ); |
540 | 556 | |
541 | 557 | } |