r107554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107553‎ | r107554 | r107555 >
Date:06:03, 29 December 2011
Author:varnent
Status:deferred
Tags:
Comment:
functions merged into post-merger TweetANew extension
Modified paths:
  • /trunk/extensions/TweetANew/SendToTwitter.php (deleted) (history)
  • /trunk/extensions/TweetANew/wiki2twitter.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/TweetANew/SendToTwitter.php
@@ -1,84 +0,0 @@
2 -<?php
3 -/**
4 - * SendToTwitter extension - sends twitter a tweet when a page is changed
5 - *
6 - * @file
7 - * @ingroup Extensions
8 - * @version 1.0
9 - * @author Rohit Keshwani
10 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11 - * @link http://www.mediawiki.org/wiki/Extension:SendToTwitter Documentation
12 - */
13 -
14 -if ( !defined( 'MEDIAWIKI' ) )
15 - die( "This is not a valid entry point.\n" );
16 -
17 -// Extension credits that will show up on Special:Version
18 -$wgExtensionCredits['other'][] = array(
19 - 'name' => 'SendToTwitter',
20 - 'version' => '1.0',
21 - 'author' => 'Rohit Keshwani',
22 - 'url' => 'http://www.mediawiki.org/wiki/Extension:SendToTwitter',
23 - 'description' => 'Extension to send twitter a tweet when a page is changed.',
24 -);
25 -
26 -#Configuration parameters
27 -$wgSendToTwitterUsername = 'TWITTERUSERNAME';
28 -$wgSendToTwitterPassword = 'TWITTERPASSWORD';
29 -$wgSendToTwitterWikiURL = 'http://www.example.com/w';
30 -
31 -$wgHooks['EditPage::attemptSave'][] = 'QueryTwitter';
32 -function QueryTwitter( &$q ) {
33 - global $wgTitle, $wgArticle;
34 - global $wgSendToTwitterUsername, $wgSendToTwitterPassword, $wgSendToTwitterWikiURL;
35 -
36 - $title = $wgTitle;
37 - $article = $wgArticle;
38 - $wurl = $wgSendToTwitterWikiURL;
39 -
40 - $test2 = explode( "\n", $article->getContent() );
41 -
42 - // The message you want to send
43 - $ch = curl_init();
44 - $timeout = 5;
45 - curl_setopt( $ch, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url=' . $wurl . urlencode( $title ) );
46 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
47 - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
48 - curl_setopt( $ch, CURLOPT_HEADER, 0);
49 - $test = curl_exec( $ch );
50 - curl_close( $ch );
51 -
52 - $switcher = rand( 1, 3 );
53 - switch( $switcher ) {
54 - case 1:
55 - $message = 'looks like somebody updated ' . $title . ' at ' . $test;
56 - break;
57 - case 2:
58 - $message = $title . ' was recently changed: ' . $test . ' Check it out!';
59 - break;
60 - case 3:
61 - $message = 'Check out ' . $test . ' it has some new content on ' . $title;
62 - break;
63 - }
64 -
65 - // The twitter API address
66 - $url = 'http://twitter.com/statuses/update.xml';
67 - // Alternative JSON version
68 - // $url = 'http://twitter.com/statuses/update.json';
69 - // Set up and execute the curl process
70 - $curl_handle = curl_init();
71 - curl_setopt( $curl_handle, CURLOPT_URL, "$url" );
72 - curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 2 );
73 - curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, 1 );
74 - curl_setopt( $curl_handle, CURLOPT_POST, 1 );
75 - curl_setopt( $curl_handle, CURLOPT_POSTFIELDS, "status=$message" );
76 - curl_setopt( $curl_handle, CURLOPT_USERPWD, "$wgSendToTwitterUsername:$wgSendToTwitterPassword" );
77 - $buffer = curl_exec( $curl_handle );
78 - curl_close( $curl_handle );
79 - // check for success or failure
80 - if( empty( $buffer ) ) {
81 - return false;
82 - } else {
83 - return true;
84 - }
85 -}
\ No newline at end of file
Index: trunk/extensions/TweetANew/wiki2twitter.php
@@ -1,36 +0,0 @@
2 -<?php
3 -if ( !defined( 'MEDIAWIKI' ) ) {
4 - die( 'This file is a MediaWiki extension, it is not a valid entry point' );
5 -}
6 -require_once('settings.php');
7 -
8 -// set the hook
9 -$wgHooks['ArticleSaveComplete'][] = 'fnMyHook';
10 -
11 -// update twitter
12 -function fnMyHook( &$article, &$user, $text, $summary, &$minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId ) {
13 -
14 - //FLAGS+MINOR ARTICLE; (DIFF) USER (SUMMARY)
15 - if ($article->mMinorEdit==1) {
16 - $twit_text .= "m ";
17 - }
18 -
19 - $link = "http://habbowiki.org/index.php?title=" . urlencode($article->mTitle) . "&diff=" . $article->mOldId . "&oldid=" . $article->mRevIdFetched;
20 - //$twit_text = file_get_contents('http://tinyurl.com/api-create.php?url='.$link);
21 - $twit_text .= $link;
22 - $twit_text .= " ";
23 - require_once('twitterOAuth.php');
24 -
25 - /* Sessions are used to keep track of tokens while user authenticates with twitter */
26 - /* settings provided by settings.php */
27 -
28 - /* Create TwitterOAuth with app key/secret and user access key/secret */
29 - $to = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_access_token, $oauth_access_token_secret);
30 -
31 - $twit_text .= $article->mTitle."; ".$user->mName." (".$summary.")";
32 -
33 - $content = $to->OAuthRequest('http://twitter.com/statuses/update.xml', array('status' => $twit_text), 'POST');
34 -
35 - return true;
36 -}
37 -?>
\ No newline at end of file

Status & tagging log