-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathFBPush_OnArticleSave.php
49 lines (39 loc) · 1.52 KB
/
FBPush_OnArticleSave.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* @author Sean Colombo, adjusted by aran@organicdesign.co.nz
*
* Pushes an item to Facebook wall on ArticleSave event
*/
$wgExtensionMessagesFiles['FBPush_OnArticleSave'] = dirname( __FILE__ ) . '/FBPush_OnArticleSave.i18n.php';
$wgFbPushEventClasses[] = 'FBPush_OnArticleSave';
$wgFbTimeBetweenPosts = 0;
class FBPush_OnArticleSave extends FacebookPushEvent {
protected $isAllowedUserPreferenceName = 'facebook-push-allow-OnEdit';
static $messageName = 'facebook-msg-OnEdit';
static $eventImage = 'edits.png';
public function init() {
global $wgHooks;
$wgHooks['ArticleSaveComplete'][] = $this;
}
function onArticleSaveComplete( &$article, &$user, $text, $summary, $minor, $watch, $sec, &$flags, $rev, &$status, $baseId ) {
global $wgSitename, $wgFbTimeBetweenPosts;
if( $rev ) {
// Post to wall if time since last post greater then specified $wgFbTimeBetweenPosts
$ts = $rev->getTimestamp();
if( $wgFbTimeBetweenPosts < $ts - $user->getOption( 'fb-last-edit-timestamp' ) ) {
$params = array(
'$ARTICLENAME' => $article->getTitle()->getPrefixedText(),
'$WIKINAME' => $wgSitename,
'$ARTICLE_URL' => $article->getTitle()->getFullURL( 'ref=fbfeed&fbtype=articlesave' ),
'$EVENTIMG' => self::$eventImage,
'$SUMMARY' => $summary,
'$TEXT' => self::shortenText( self::parseArticle( $article, $text ) )
);
self::pushEvent( self::$messageName, $params, __CLASS__ );
$user->setOption( 'fb-last-edit-timestamp', $ts );
$user->saveSettings();
}
}
return true;
}
}