Index: trunk/extensions/TweetANew/SendToTwitter2.php |
— | — | @@ -1,126 +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.1 |
9 | | - * @author Rohit Keshwani |
10 | | - * @author Andrew Fitzgerald |
11 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | | - * @link http://www.mediawiki.org/wiki/Extension:SendToTwitter Documentation |
13 | | - */ |
14 | | - |
15 | | -if ( !defined( 'MEDIAWIKI' ) ) |
16 | | - die( "This is not a valid entry point.\n" ); |
17 | | - |
18 | | -// Extension credits that will show up on Special:Version |
19 | | -$wgExtensionCredits['other'][] = array( |
20 | | - 'name' => 'SendToTwitter2', |
21 | | - 'version' => '2.0', |
22 | | - 'author' => 'Rohit Keshwani, Andrew Fitzgerald', |
23 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:SendToTwitter2', |
24 | | - 'description' => 'Extension to send twitter a tweet when a page is changed.', |
25 | | -); |
26 | | - |
27 | | -$dir = dirname(__FILE__) . '/'; |
28 | | -$wgExtensionMessagesFiles['SendToTwitter2'] = $dir . 'SendToTwitter2.i18n.php'; |
29 | | - |
30 | | -#Configuration parameters |
31 | | - |
32 | | -if (!isset($wgSendToTwitterUsername)) |
33 | | -{ $wgSendToTwitterUsername = ''; |
34 | | -} |
35 | | -if (!isset($wgSendToTwitterPassword)) |
36 | | -{ $wgSendToTwitterPassword = ''; |
37 | | -} |
38 | | -if (!isset($wgSendToTwitterWikiURL)) |
39 | | -{ $wgSendToTwitterWikiURL = ''; |
40 | | -} |
41 | | -if (!isset($wgSendToTwitterUseCheckBox)) |
42 | | -{ $wgSendToTwitterUseCheckBox = true; |
43 | | -} |
44 | | -if (!isset($wgSendToTwitterUseCheckBox)) |
45 | | -{ $wgSendToTwitterChecked = false; |
46 | | -} |
47 | | - |
48 | | -$wgHooks['EditPage::attemptSave'][] = 'efSendToTwitter2Save'; |
49 | | -function efSendToTwitter2Save( &$q ) { |
50 | | - global $wgRequest, $wgSendToTwitterUseCheckBox; |
51 | | - |
52 | | - if (($wgSendToTwitterUseCheckBox == false) || $wgRequest->getBool('wpSendToTwitter')) |
53 | | - { |
54 | | - wfLoadExtensionMessages( 'SendToTwitter2' ); |
55 | | - global $wgTitle, $wgArticle; |
56 | | - global $wgSendToTwitterUsername, $wgSendToTwitterPassword, $wgSendToTwitterWikiURL; |
57 | | - |
58 | | - $title = $wgTitle; |
59 | | - $titleurl = str_replace(' ','_',$wgTitle); |
60 | | - $article = $wgArticle; |
61 | | - $wurl = $wgSendToTwitterWikiURL; |
62 | | - |
63 | | - $test2 = explode( "\n", $article->getContent() ); |
64 | | - |
65 | | - // The message you want to send |
66 | | - $ch = curl_init(); |
67 | | - $timeout = 5; |
68 | | - curl_setopt( $ch, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url=' . $wurl . $titleurl ); |
69 | | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
70 | | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); |
71 | | - curl_setopt( $ch, CURLOPT_HEADER, 0); |
72 | | - $test = curl_exec( $ch ); |
73 | | - curl_close( $ch ); |
74 | | - |
75 | | - $switcher = rand( 1, 3 ); |
76 | | - |
77 | | - $message = wfMsg( 'sendtotwitter-message' . $switcher, array ( $title, $test, $q->summary )); |
78 | | - |
79 | | - if (strlen($message) > 140) |
80 | | - { $message = substr($message,0, 140); |
81 | | - } |
82 | | - |
83 | | - // The twitter API address |
84 | | - $url = 'http://twitter.com/statuses/update.xml'; |
85 | | - // Alternative JSON version |
86 | | - // $url = 'http://twitter.com/statuses/update.json'; |
87 | | - // Set up and execute the curl process |
88 | | - $curl_handle = curl_init(); |
89 | | - curl_setopt( $curl_handle, CURLOPT_URL, "$url" ); |
90 | | - curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 2 ); |
91 | | - curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, 1 ); |
92 | | - curl_setopt( $curl_handle, CURLOPT_POST, 1 ); |
93 | | - curl_setopt( $curl_handle, CURLOPT_POSTFIELDS, "status=$message" ); |
94 | | - curl_setopt( $curl_handle, CURLOPT_USERPWD, "$wgSendToTwitterUsername:$wgSendToTwitterPassword" ); |
95 | | - $buffer = curl_exec( $curl_handle ); |
96 | | - curl_close( $curl_handle ); |
97 | | - // check for success or failure |
98 | | - if( empty( $buffer ) ) { |
99 | | - return false; |
100 | | - } else { |
101 | | - return true; |
102 | | - } |
103 | | - } |
104 | | - return true; |
105 | | -} |
106 | | - |
107 | | - |
108 | | -$wgHooks['EditPageBeforeEditChecks'][] = 'efSendToTwitter2CheckBox'; |
109 | | - |
110 | | -function efSendToTwitter2CheckBox( &$editpage, &$checkboxes, &$tabindex) |
111 | | -{ |
112 | | - global $wgSendToTwitterUseCheckBox, $wgSendToTwitterChecked; |
113 | | - if ($wgSendToTwitterUseCheckBox) |
114 | | - { |
115 | | - wfLoadExtensionMessages( 'SendToTwitter2' ); |
116 | | - $attribs = array( |
117 | | - 'tabindex' => ++$tabindex, |
118 | | - 'accesskey' => wfMsg( 'accesskey-sendtotwitter' ), |
119 | | - 'id' => 'wpSendToTwitter', |
120 | | - ); |
121 | | - |
122 | | - $checkboxes['twitter'] = |
123 | | - Xml::check( 'wpSendToTwitter', $wgSendToTwitterChecked, $attribs ) . |
124 | | - " <label for='wpSendToTwitter' title='". wfMsg('tooltip-sendtotwitter')."'>".wfMsg('action-sendtotwitter')."</label>"; |
125 | | - } |
126 | | - return true; |
127 | | -} |