Index: trunk/extensions/TweetANew/TweetANew.body.php |
— | — | @@ -4,9 +4,7 @@ |
5 | 5 | * Class file for the TweetANew extension |
6 | 6 | * |
7 | 7 | * @addtogroup Extensions |
8 | | - * @author Joachim De Schrijver |
9 | | - * @license LGPL |
10 | | - * ToDo - many listed below - general removal of duplication and overall cleanup |
| 8 | + * @license GPL |
11 | 9 | */ |
12 | 10 | |
13 | 11 | // TweetANew |
— | — | @@ -44,82 +42,79 @@ |
45 | 43 | * @param $user |
46 | 44 | * @param $text |
47 | 45 | * @param $summary |
48 | | - * @param $minoredit |
49 | | - * @param $watchthis |
50 | | - * @param $sectionanchor |
51 | | - * @param $flags |
52 | | - * @param $revision |
53 | 46 | * @return bool |
54 | 47 | */ |
55 | | - public static function TweetANewNewArticle($article, $user, $text, $summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision){ |
56 | | - global $wgTweetANewTweet,$wgTweetANewText,$wgTweetANewTwitter; |
| 48 | + public static function TweetANewNewArticle($article, $user, $text, $summary){ |
| 49 | + global $wgTweetANewTweet, $wgTweetANewText, $wgTweetANewTwitter, $wgTweetANewBitly, $wgRequest; |
57 | 50 | |
58 | | - # ToDo - Check if $wgTweetANewTweet['Auto'] is enabled |
59 | | - |
60 | | - # Check if page is in content namespace |
61 | | - if ( !MWNamespace::isContent( $article->getTitle()->getNamespace() ) ) return true; |
62 | | - |
63 | | - # Make connection to Twitter |
64 | | - require_once('lib/tmhOAuth.php'); // include connection |
65 | | - $connection = new tmhOAuth(array( |
66 | | - 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'], |
67 | | - 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'], |
68 | | - 'user_token' => $wgTweetANewTwitter['AccessToken'], |
69 | | - 'user_secret' => $wgTweetANewTwitter['AccessTokenSecret'], |
70 | | - )); |
71 | | - |
72 | | - # Generate final url |
73 | | - $finalurl = self::make_final_url($article->getTitle()->getFullURL(),$wgTweetANewBitly['Login'],$wgTweetANewBitly['API']); |
74 | | - |
75 | | - # Generate $author based on $wgTweetANewText['RealName'] |
76 | | - if ( $wgTweetANewText['RealName'] ) { |
77 | | - $author = $user->getRealName(); |
| 51 | + # Check if $wgTweetANewTweet['New'] is enabled or the Tweet checkbox was selected on the edit page |
| 52 | + if ( $wgRequest->getCheck('wpTweetANew') || $wgTweetANewTweet['New'] ) { |
| 53 | + |
| 54 | + # Check if page is in content namespace or if the Tweet checkbox was selected on the edit page |
| 55 | + if ( !MWNamespace::isContent( $article->getTitle()->getNamespace() ) && !$wgRequest->getCheck('wpTweetANew') ) return true; |
| 56 | + |
| 57 | + # Make connection to Twitter |
| 58 | + require_once('lib/tmhOAuth.php'); // include connection |
| 59 | + $connection = new tmhOAuth(array( |
| 60 | + 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'], |
| 61 | + 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'], |
| 62 | + 'user_token' => $wgTweetANewTwitter['AccessToken'], |
| 63 | + 'user_secret' => $wgTweetANewTwitter['AccessTokenSecret'], |
| 64 | + )); |
| 65 | + |
| 66 | + # Generate final url |
| 67 | + $finalurl = self::make_final_url($article->getTitle()->getFullURL(),$wgTweetANewBitly['Login'],$wgTweetANewBitly['API']); |
| 68 | + |
| 69 | + # Generate $author based on $wgTweetANewText['RealName'] |
| 70 | + if ( $wgTweetANewText['RealName'] ) { |
| 71 | + $author = $user->getRealName(); |
| 72 | + } |
| 73 | + else { |
| 74 | + $author = $user->getName(); |
| 75 | + } |
| 76 | + |
| 77 | + # Generate a random tweet texts based if $wgTweetANewText['NewRandom'] is true |
| 78 | + if ( $wgTweetANewText['NewRandom'] ) { |
| 79 | + # Setup switcher using max number set by $wgTweetANewText['NewRandomMax'] |
| 80 | + $switcher = rand( 1, $wgTweetANewText['NewRandomMax'] ); |
| 81 | + # Parse random text |
| 82 | + $tweet_text .= wfMsg( 'tweetanew-new' . $switcher, array ( $article->getTitle()->getText(), $finalurl ) ); |
| 83 | + } |
| 84 | + else { |
| 85 | + # Use default tweet message format |
| 86 | + $tweet_body = wfMsg( 'tweetanew-newdefault', array ( $article->getTitle()->getText(), $finalurl ) ); |
| 87 | + $tweet_text .= $tweet_body; |
| 88 | + } |
| 89 | + |
| 90 | + # Add author info if $wgTweetANewText['NewAuthor'] is true |
| 91 | + if ( $wgTweetANewText['NewAuthor'] ) { |
| 92 | + $tweet_text .= ' '. wfMsg( 'tweetanew-authorcredit' ) .' '. $author; |
| 93 | + } |
| 94 | + |
| 95 | + # Add summary if $wgTweetANewText['NewSummary'] is true and summary text is entered |
| 96 | + if ( $summary && $wgTweetANewText['NewSummary'] ) { |
| 97 | + $tweet_text .= ' - ' . $summary; |
| 98 | + } |
| 99 | + |
| 100 | + # Calculate length of tweet factoring in longURL |
| 101 | + if (strlen($finalurl) > 20) { |
| 102 | + $tweet_text_count = (strlen($finalurl) - 20) + 140; |
| 103 | + } |
| 104 | + else { |
| 105 | + $tweet_text_count = 140; |
| 106 | + } |
| 107 | + |
| 108 | + # Check if length of tweet is beyond 140 characters and shorten if necessary |
| 109 | + if (strlen($tweet_text) > $tweet_text_count) { |
| 110 | + $tweet_text = substr($tweet_text,0, $tweet_text_count); |
| 111 | + } |
| 112 | + |
| 113 | + # Make tweet message |
| 114 | + $connection->request('POST', |
| 115 | + $connection->url('1/statuses/update'), |
| 116 | + array('status' => $tweet_text) |
| 117 | + ); |
78 | 118 | } |
79 | | - else { |
80 | | - $author = $user->getName(); |
81 | | - } |
82 | | - |
83 | | - # Generate a random tweet texts based if $wgTweetANewText['NewRandom'] is true |
84 | | - if ( $wgTweetANewText['NewRandom'] ) { |
85 | | - # Setup switcher using max number set by $wgTweetANewText['NewRandomMax'] |
86 | | - $switcher = rand( 1, $wgTweetANewText['NewRandomMax'] ); |
87 | | - # Parse random text |
88 | | - $tweet_text .= wfMsg( 'tweetanew-new' . $switcher, array ( $article->getTitle()->getText(), $finalurl ) ); |
89 | | - } |
90 | | - else { |
91 | | - # Use default tweet message format |
92 | | - $tweet_body = wfMsg( 'tweetanew-newdefault', array ( $article->getTitle()->getText(), $finalurl ) ); |
93 | | - $tweet_text .= $tweet_body; |
94 | | - } |
95 | | - |
96 | | - # Add author info if $wgTweetANewText['NewAuthor'] is true |
97 | | - if ( $wgTweetANewText['NewAuthor'] ) { |
98 | | - $tweet_text .= ' '. wfMsg( 'tweetanew-authorcredit' ) .' '. $author; |
99 | | - } |
100 | | - |
101 | | - # Add summary if $wgTweetANewText['NewSummary'] is true and summary text is entered |
102 | | - if ( $summary && $wgTweetANewText['NewSummary'] ) { |
103 | | - $tweet_text .= ' - ' . $summary; |
104 | | - } |
105 | | - |
106 | | - # Calculate length of tweet factoring in longURL |
107 | | - if (strlen($finalurl) > 20) { |
108 | | - $tweet_text_count = (strlen($finalurl) - 20) + 140; |
109 | | - } |
110 | | - else { |
111 | | - $tweet_text_count = 140; |
112 | | - } |
113 | | - |
114 | | - # Check if length of tweet is beyond 140 characters and shorten if necessary |
115 | | - if (strlen($tweet_text) > $tweet_text_count) { |
116 | | - $tweet_text = substr($tweet_text,0, $tweet_text_count); |
117 | | - } |
118 | | - |
119 | | - # Make tweet message |
120 | | - $connection->request('POST', |
121 | | - $connection->url('1/statuses/update'), |
122 | | - array('status' => $tweet_text) |
123 | | - ); |
124 | 119 | return true; |
125 | 120 | } |
126 | 121 | |
— | — | @@ -131,107 +126,105 @@ |
132 | 127 | * @param $text |
133 | 128 | * @param $summary |
134 | 129 | * @param $minoredit |
135 | | - * @param $watchthis |
136 | | - * @param $sectionanchor |
137 | | - * @param $flags |
138 | 130 | * @param $revision |
139 | 131 | * @return bool |
140 | 132 | */ |
141 | | - public static function TweetANewEditMade(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId, &$redirect){ |
142 | | - global $wgTweetANewTweet,$wgTweetANewText,$wgTweetANewTwitter,$wgArticle; |
| 133 | + public static function TweetANewEditMade(&$article, &$user, $text, $summary, $minoredit, $revision){ |
| 134 | + global $wgTweetANewTweet, $wgTweetANewText, $wgTweetANewTwitter, $wgTweetANewBitly, $wgRequest; |
143 | 135 | |
144 | | - # ToDo - Check if $wgTweetANewTweet['Auto'] is enabled |
145 | | - |
146 | | - # Check if page is in content namespace |
147 | | - if ( !MWNamespace::isContent( $article->getTitle()->getNamespace() ) ) return true; |
148 | | - |
149 | | - # Determine the time and date of last modification - skip if newer than $wgTweetANewTweet['lessminold'] setting |
150 | | - # ToDo - there must be a cleaner way of doing this |
151 | | - $dbr = wfGetDB( DB_SLAVE ); |
152 | | - $res = $dbr->select('revision', array( 'rev_timestamp' ), array('rev_page = '.$article->getID()), $fname = 'Database::select', $options = array( 'ORDER BY' => 'rev_id DESC' , 'LIMIT' => '2' )); |
153 | | - foreach($res as $row) $edittime[] = $row->rev_timestamp; |
154 | | - $edittimenow = mktime(substr($edittime[0],8,2),substr($edittime[0],10,2),substr($edittime[0],12),substr($edittime[0],4,2),substr($edittime[0],6,2),substr($edittime[0],0,4)); |
155 | | - $edittimelast = mktime(substr($edittime[1],8,2),substr($edittime[1],10,2),substr($edittime[1],12),substr($edittime[1],4,2),substr($edittime[1],6,2),substr($edittime[1],0,4)); |
156 | | - $edittimediv = $edittimenow - $edittimelast; |
157 | | - $mailtext['time_since_last_edit'] = $edittimediv; |
158 | | - if( isset( $wgTweetANewTweet['LessMinutesOld'] ) ) if ($edittimediv < ($wgTweetANewTweet['LessMinutesOld'] * 60) ) return true; |
159 | | - |
160 | | - # Only proceed if this is not the first edit to the article, in which case it's new and TweetANewNewArticle is used instead |
161 | | - if ( $wgArticle->estimateRevisionCount() == 1 ) return true; |
162 | | - |
163 | | - # Check $wgTweetANewTweet['SkipMinor'] setting to see if minor edits should be skipped |
164 | | - if ( $minoredit !== 0 && $wgTweetANewTweet['SkipMinor'] ) return true; |
165 | | - |
166 | | - # Make connection to Twitter |
167 | | - require_once('lib/tmhOAuth.php'); // include connection |
168 | | - $connection = new tmhOAuth( array ( |
169 | | - 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'], |
170 | | - 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'], |
171 | | - 'user_token' => $wgTweetANewTwitter['AccessToken'], |
172 | | - 'user_secret' => $wgTweetANewTwitter['AccessTokenSecret'], |
173 | | - ) ); |
174 | | - |
175 | | - # Generate final url |
176 | | - $finalurl = self::make_final_url($article->getTitle()->getFullURL(),$wgTweetANewBitly['Login'],$wgTweetANewBitly['API']); |
177 | | - |
178 | | - # Generate $author based on $wgTweetANewText['RealName'] |
179 | | - if ( $wgTweetANewText['RealName'] ) { |
180 | | - $author = $user->getRealName(); |
181 | | - } |
182 | | - else { |
183 | | - $author = $user->getName(); |
184 | | - } |
185 | | - |
186 | | - # Add prefix indication that edit is minor if $wgTweetANewText['Minor'] is true and !$wgTweetANewTweet['SkipMinor'] is false |
187 | | - if ( $minoredit !== 0 && $wgTweetANewText['Minor'] ) { |
188 | | - $tweet_text = wfMsg( 'tweetanew-minoredit' ); |
189 | | - # Add a space after the indicator if $wgTweetANewText['MinorSpace'] is true |
190 | | - if ( $minoredit !== 0 && $wgTweetANewText['MinorSpace'] ) { |
191 | | - $tweet_text .= ' '; |
| 136 | + # Check if $wgTweetANewTweet['Edit'] is enabled or the Tweet checkbox was selected on the edit page |
| 137 | + if ( $wgRequest->getCheck('wpTweetANewEdit') || $wgTweetANewTweet['Edit'] ) { |
| 138 | + |
| 139 | + # Check if page is in content namespace or if the Tweet checkbox was selected on the edit page |
| 140 | + if ( !MWNamespace::isContent( $article->getTitle()->getNamespace() ) && !$wgRequest->getCheck('wpTweetANewEdit') ) return true; |
| 141 | + |
| 142 | + # Determine the time and date of last modification - skip if newer than $wgTweetANewTweet['LessMinutesOld'] setting |
| 143 | + # ToDo - there must be a cleaner way of doing this |
| 144 | + $dbr = wfGetDB( DB_SLAVE ); |
| 145 | + $res = $dbr->select('revision', array( 'rev_timestamp' ), array('rev_page = '.$article->getID()), $fname = 'Database::select', $options = array( 'ORDER BY' => 'rev_id DESC' , 'LIMIT' => '2' )); |
| 146 | + foreach($res as $row) $edittime[] = $row->rev_timestamp; |
| 147 | + $edittimenow = mktime(substr($edittime[0],8,2),substr($edittime[0],10,2),substr($edittime[0],12),substr($edittime[0],4,2),substr($edittime[0],6,2),substr($edittime[0],0,4)); |
| 148 | + $edittimelast = mktime(substr($edittime[1],8,2),substr($edittime[1],10,2),substr($edittime[1],12),substr($edittime[1],4,2),substr($edittime[1],6,2),substr($edittime[1],0,4)); |
| 149 | + $edittimediv = $edittimenow - $edittimelast; |
| 150 | + if ($edittimediv < ($wgTweetANewTweet['LessMinutesOld'] * 60) ) return true; |
| 151 | + |
| 152 | + # Only proceed if this is not the first edit to the article, in which case it's new and TweetANewNewArticle is used instead |
| 153 | + if ( !$article->mTitle->exists() ) return true; |
| 154 | + |
| 155 | + # Check $wgTweetANewTweet['SkipMinor'] setting to see if minor edits should be skipped |
| 156 | + if ( $minoredit !== 0 && $wgTweetANewTweet['SkipMinor'] ) return true; |
| 157 | + |
| 158 | + # Make connection to Twitter |
| 159 | + require_once('lib/tmhOAuth.php'); // include connection |
| 160 | + $connection = new tmhOAuth( array ( |
| 161 | + 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'], |
| 162 | + 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'], |
| 163 | + 'user_token' => $wgTweetANewTwitter['AccessToken'], |
| 164 | + 'user_secret' => $wgTweetANewTwitter['AccessTokenSecret'], |
| 165 | + ) ); |
| 166 | + |
| 167 | + # Generate final url |
| 168 | + $finalurl = self::make_final_url($article->getTitle()->getFullURL(),$wgTweetANewBitly['Login'],$wgTweetANewBitly['API']); |
| 169 | + |
| 170 | + # Generate $author based on $wgTweetANewText['RealName'] |
| 171 | + if ( $wgTweetANewText['RealName'] ) { |
| 172 | + $author = $user->getRealName(); |
192 | 173 | } |
| 174 | + else { |
| 175 | + $author = $user->getName(); |
| 176 | + } |
| 177 | + |
| 178 | + # Add prefix indication that edit is minor if $wgTweetANewText['Minor'] is true and !$wgTweetANewTweet['SkipMinor'] is false |
| 179 | + if ( $minoredit !== 0 && $wgTweetANewText['Minor'] ) { |
| 180 | + $tweet_text = wfMsg( 'tweetanew-minoredit' ); |
| 181 | + # Add a space after the indicator if $wgTweetANewText['MinorSpace'] is true |
| 182 | + if ( $minoredit !== 0 && $wgTweetANewText['MinorSpace'] ) { |
| 183 | + $tweet_text .= ' '; |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + # Generate a random tweet texts based if $wgTweetANewText['EditRandom'] is true |
| 188 | + if ( $wgTweetANewText['EditRandom'] ) { |
| 189 | + # Setup switcher using max number set by $wgTweetANewText['EditRandomMax'] |
| 190 | + $switcher = rand( 1, $wgTweetANewText['EditRandomMax'] ); |
| 191 | + # Parse random text |
| 192 | + $tweet_text .= wfMsg( 'tweetanew-edit' . $switcher, array ( $article->getTitle()->getText(), $finalurl ) ); |
| 193 | + } |
| 194 | + else { |
| 195 | + # Use default tweet message format |
| 196 | + $tweet_body = wfMsg( 'tweetanew-editdefault', array ( $article->getTitle()->getText(), $finalurl ) ); |
| 197 | + $tweet_text .= $tweet_body; |
| 198 | + } |
| 199 | + |
| 200 | + # Add author info if $wgTweetANewText['EditAuthor'] is true |
| 201 | + if ( $wgTweetANewText['EditAuthor'] ) { |
| 202 | + $tweet_text .= ' '. wfMsg( 'tweetanew-authorcredit' ) .' '. $author; |
| 203 | + } |
| 204 | + |
| 205 | + # Add summary if $wgTweetANewText['EditSummary'] is true and summary text is entered |
| 206 | + if ( $summary && $wgTweetANewText['EditSummary'] ) { |
| 207 | + $tweet_text .= ' - ' . $summary; |
| 208 | + } |
| 209 | + |
| 210 | + # Calculate length of tweet factoring in longURL |
| 211 | + if (strlen($finalurl) > 20) { |
| 212 | + $tweet_text_count = (strlen($finalurl) - 20) + 140; |
| 213 | + } |
| 214 | + else { |
| 215 | + $tweet_text_count = 140; |
| 216 | + } |
| 217 | + |
| 218 | + # Check if length of tweet is beyond 140 characters and shorten if necessary |
| 219 | + if (strlen($tweet_text) > $tweet_text_count) { |
| 220 | + $tweet_text = substr($tweet_text,0, $tweet_text_count); |
| 221 | + } |
| 222 | + |
| 223 | + # Make tweet message |
| 224 | + $connection->request('POST', |
| 225 | + $connection->url('1/statuses/update'), |
| 226 | + array('status' => $tweet_text) |
| 227 | + ); |
193 | 228 | } |
194 | | - |
195 | | - # Generate a random tweet texts based if $wgTweetANewText['EditRandom'] is true |
196 | | - if ( $wgTweetANewText['EditRandom'] ) { |
197 | | - # Setup switcher using max number set by $wgTweetANewText['EditRandomMax'] |
198 | | - $switcher = rand( 1, $wgTweetANewText['EditRandomMax'] ); |
199 | | - # Parse random text |
200 | | - $tweet_text .= wfMsg( 'tweetanew-edit' . $switcher, array ( $article->getTitle()->getText(), $finalurl ) ); |
201 | | - } |
202 | | - else { |
203 | | - # Use default tweet message format |
204 | | - $tweet_body = wfMsg( 'tweetanew-editdefault', array ( $article->getTitle()->getText(), $finalurl ) ); |
205 | | - $tweet_text .= $tweet_body; |
206 | | - } |
207 | | - |
208 | | - # Add author info if $wgTweetANewText['EditAuthor'] is true |
209 | | - if ( $wgTweetANewText['EditAuthor'] ) { |
210 | | - $tweet_text .= ' '. wfMsg( 'tweetanew-authorcredit' ) .' '. $author; |
211 | | - } |
212 | | - |
213 | | - # Add summary if $wgTweetANewText['EditSummary'] is true and summary text is entered |
214 | | - if ( $summary && $wgTweetANewText['EditSummary'] ) { |
215 | | - $tweet_text .= ' - ' . $summary; |
216 | | - } |
217 | | - |
218 | | - # Calculate length of tweet factoring in longURL |
219 | | - if (strlen($finalurl) > 20) { |
220 | | - $tweet_text_count = (strlen($finalurl) - 20) + 140; |
221 | | - } |
222 | | - else { |
223 | | - $tweet_text_count = 140; |
224 | | - } |
225 | | - |
226 | | - # Check if length of tweet is beyond 140 characters and shorten if necessary |
227 | | - if (strlen($tweet_text) > $tweet_text_count) { |
228 | | - $tweet_text = substr($tweet_text,0, $tweet_text_count); |
229 | | - } |
230 | | - |
231 | | - # Make tweet message |
232 | | - $connection->request('POST', |
233 | | - $connection->url('1/statuses/update'), |
234 | | - array('status' => $tweet_text) |
235 | | - ); |
236 | 229 | return true; |
237 | 230 | } |
238 | 231 | } |
\ No newline at end of file |
Index: trunk/extensions/TweetANew/TweetANew.i18n.php |
— | — | @@ -13,9 +13,11 @@ |
14 | 14 | */ |
15 | 15 | $messages['en'] = array( |
16 | 16 | 'tweetanew-desc' => 'Tweets when an article is created or edited. Depending on preferences set for the entire wiki, either automatically or from the edit page.', |
17 | | - 'action-sendtotwitter' => 'Tweet about this edit', |
18 | | - 'accesskey-sendtotwitter' => 'e', |
19 | | - 'tooltip-sendtotwitter' => 'Send information about this edit to Twitter [alt-e]', |
| 17 | + 'tweetanew-accesskey' => 'e', |
| 18 | + 'tweetanew-newaction' => 'Tweet about this new article', |
| 19 | + 'tweetanew-newtooltip' => 'Send information about this new article to Twitter [alt-e]', |
| 20 | + 'tweetanew-editaction' => 'Tweet about this edit', |
| 21 | + 'tweetanew-edittooltip' => 'Send information about this edit to Twitter [alt-e]', |
20 | 22 | 'tweetanew-minoredit' => 'm', |
21 | 23 | 'tweetanew-authorcredit' => 'by', |
22 | 24 | 'tweetanew-newdefault' => 'NEW ARTICLE: $1 - $2', |
— | — | @@ -28,15 +30,16 @@ |
29 | 31 | 'tweetanew-edit3' => 'Check out $2 - it has some new content on $1', |
30 | 32 | ); |
31 | 33 | |
32 | | - |
33 | 34 | /** Message documentation (Message documentation) |
34 | 35 | * @author Gregory Varnum |
35 | 36 | */ |
36 | 37 | $messages['qqq'] = array( |
37 | 38 | 'tweetanew-desc' => '{{desc}}', |
38 | | - 'action-sendtotwitter' => 'Used in editpage as description for option to tweet, if auto-tweet is disabled for that type of article (edit or new)', |
39 | | - 'accesskey-sendtotwitter' => 'Access key used for option to tweet from editpage, if otherwise enabled', |
40 | | - 'tooltip-sendtotwitter' => 'Tooltip describing option to tweet form editpage, if otherwise enabled', |
| 39 | + 'tweetanew-accesskey' => 'Access key used for option to tweet from editpage, if otherwise enabled', |
| 40 | + 'tweetanew-newaction' => 'Used in editpage as description for option to tweet, if auto-tweet is disabled for new articles', |
| 41 | + 'tweetanew-newtooltip' => 'Tooltip describing option to tweet about new article from edit page, if otherwise enabled', |
| 42 | + 'tweetanew-editaction' => 'Used in editpage as description for option to tweet, if auto-tweet is disabled for edits', |
| 43 | + 'tweetanew-edittooltip' => 'Tooltip describing option to tweet about edit from edit page, if otherwise enabled', |
41 | 44 | 'tweetanew-minoredit' => 'Indicator used when edit is marked as minor, if minor edits are not already skipped - skip following indicator can be removed using MinorSpace setting', |
42 | 45 | 'tweetanew-authorcredit' => 'Used to provide credit to author of edit or new article', |
43 | 46 | 'tweetanew-newdefault' => 'Default tweet message used for new articles, if random messages are disabled. Parameters: |
Index: trunk/extensions/TweetANew/TweetANew.php |
— | — | @@ -49,21 +49,6 @@ |
50 | 50 | * $wgTweetANewTweet['SkipMinor'] |
51 | 51 | * - Skip minor edits |
52 | 52 | Default is true |
53 | | - * $wgTweetANewTwitter['ConsumerKey'] |
54 | | - * - Consumer key provided at https://dev.twitter.com/apps - be sure to have write and read permissions |
55 | | - * $wgTweetANewTwitter['ConsumerSecret'] |
56 | | - * - Consumer secret provided at https://dev.twitter.com/apps - be sure to have write and read permissions |
57 | | - * $wgTweetANewTwitter['AccessToken'] |
58 | | - * - Access token provided by the OAuth tool at https://dev.twitter.com/apps - be sure to have write and read permissions |
59 | | - * $wgTweetANewTwitter['AccessTokenSecret'] |
60 | | - * - Access token secret provided by the OAuth tool at https://dev.twitter.com/apps - be sure to have write and read permissions |
61 | | - * $wgTweetANewBitly['Enable'] |
62 | | - * - Display URL as bitly link - allowing you to track usage via your bitly account |
63 | | - * Default is false |
64 | | - * $wgTweetANewBitly['Login'] |
65 | | - * - If bitly link display is enabled, enter your bitly user account - signup at: http://bitly.com/a/sign_up |
66 | | - * $wgTweetANewBitly['API'] |
67 | | - * - If bitly link display is enabled, enter your bitly API key - find your API key at: http://bitly.com/a/your_api_key |
68 | 53 | * $wgTweetANewText['Minor'] |
69 | 54 | * - Indicate in tweet if edit is marked as minor - only applies if $wgTweetANewTweet['SkipMinor'] = false |
70 | 55 | * Default is false |
— | — | @@ -97,6 +82,27 @@ |
98 | 83 | * $wgTweetANewText['RealName'] |
99 | 84 | * - Determine if user's real name will be displayed instead of their username |
100 | 85 | * Default is false |
| 86 | + * $wgTweetANewEditpage['Enable'] |
| 87 | + * - Determine if checkbox to tweet from edit page if $wgTweetANewTweet['New'] = false or $wgTweetANewTweet['Edit'] = false |
| 88 | + * Default is false |
| 89 | + * $wgTweetANewEditpage['Checked'] |
| 90 | + * - Determine if checkbox to tweet from edit page is automatically checked |
| 91 | + * Default is false |
| 92 | + * $wgTweetANewTwitter['ConsumerKey'] |
| 93 | + * - Consumer key provided at https://dev.twitter.com/apps - be sure to have write and read permissions |
| 94 | + * $wgTweetANewTwitter['ConsumerSecret'] |
| 95 | + * - Consumer secret provided at https://dev.twitter.com/apps - be sure to have write and read permissions |
| 96 | + * $wgTweetANewTwitter['AccessToken'] |
| 97 | + * - Access token provided by the OAuth tool at https://dev.twitter.com/apps - be sure to have write and read permissions |
| 98 | + * $wgTweetANewTwitter['AccessTokenSecret'] |
| 99 | + * - Access token secret provided by the OAuth tool at https://dev.twitter.com/apps - be sure to have write and read permissions |
| 100 | + * $wgTweetANewBitly['Enable'] |
| 101 | + * - Display URL as bitly link - allowing you to track usage via your bitly account |
| 102 | + * Default is false |
| 103 | + * $wgTweetANewBitly['Login'] |
| 104 | + * - If bitly link display is enabled, enter your bitly user account - signup at: http://bitly.com/a/sign_up |
| 105 | + * $wgTweetANewBitly['API'] |
| 106 | + * - If bitly link display is enabled, enter your bitly API key - find your API key at: http://bitly.com/a/your_api_key |
101 | 107 | * |
102 | 108 | */ |
103 | 109 | |
— | — | @@ -104,10 +110,28 @@ |
105 | 111 | 'New' => true, |
106 | 112 | 'Edit' => true, |
107 | 113 | 'LessMinutesOld' => 5, |
108 | | - 'SkipMinor' => false, |
109 | | - 'Auto' => true, |
| 114 | + 'SkipMinor' => true, |
110 | 115 | ); |
111 | 116 | |
| 117 | +$wgTweetANewText = array( |
| 118 | + 'Minor' => false, // Only applies if $wgTweetANewTweet['SkipMinor'] = false |
| 119 | + 'MinorSpace' => true, // Only applies if $wgTweetANewTweet['SkipMinor'] = false and $wgTweetANewTweet['Minor'] = true |
| 120 | + 'NewRandom' => true, |
| 121 | + 'NewRandomMax' => 3, |
| 122 | + 'NewAuthor' => false, |
| 123 | + 'NewSummary' => false, |
| 124 | + 'EditRandom' => true, |
| 125 | + 'EditRandomMax' => 3, |
| 126 | + 'EditAuthor' => false, |
| 127 | + 'EditSummary' => false, |
| 128 | + 'RealName' => false, |
| 129 | +); |
| 130 | + |
| 131 | +$wgTweetANewEditpage = array( |
| 132 | + 'Enable' => false, // Only applies if $wgTweetANewTweet['New'] = false or $wgTweetANewTweet['Edit'] = false |
| 133 | + 'Checked' => false, // Only applies if $wgTweetANewEditpage['Enable'] = true |
| 134 | +); |
| 135 | + |
112 | 136 | $wgTweetANewTwitter = array( |
113 | 137 | 'ConsumerKey' => '', |
114 | 138 | 'ConsumerSecret' => '', |
— | — | @@ -121,20 +145,6 @@ |
122 | 146 | 'API' => '', |
123 | 147 | ); |
124 | 148 | |
125 | | -$wgTweetANewText = array( |
126 | | - 'Minor' => true, // Only applies if $wgTweetANewTweet['SkipMinor'] = false |
127 | | - 'MinorSpace' => true, // Only applies if $wgTweetANewTweet['SkipMinor'] = false and $wgTweetANewTweet['Minor'] = true |
128 | | - 'NewRandom' => true, |
129 | | - 'NewRandomMax' => 3, |
130 | | - 'NewAuthor' => true, |
131 | | - 'NewSummary' => true, |
132 | | - 'EditRandom' => true, |
133 | | - 'EditRandomMax' => 3, |
134 | | - 'EditAuthor' => true, |
135 | | - 'EditSummary' => true, |
136 | | - 'RealName' => true, |
137 | | -); |
138 | | - |
139 | 149 | /** |
140 | 150 | * Class and localisation |
141 | 151 | * |
— | — | @@ -163,4 +173,46 @@ |
164 | 174 | */ |
165 | 175 | |
166 | 176 | $wgHooks['ArticleInsertComplete'][] = 'TweetANew::TweetANewNewArticle'; |
167 | | -$wgHooks['ArticleSaveComplete'][] = 'TweetANew::TweetANewEditMade'; |
\ No newline at end of file |
| 177 | +$wgHooks['ArticleSaveComplete'][] = 'TweetANew::TweetANewEditMade'; |
| 178 | +$wgHooks['EditPageBeforeEditChecks'][] = 'efTweetANewEditCheckBox'; |
| 179 | + |
| 180 | +/** |
| 181 | + * Function for tweeting about new or edited articles when auto-tweet if disabled |
| 182 | + * |
| 183 | + * @param $editpage |
| 184 | + * @param $checkboxes |
| 185 | + * @param $tabindex |
| 186 | + * @return bool |
| 187 | + */ |
| 188 | +function efTweetANewEditCheckBox( &$editpage, &$checkboxes, &$tabindex) { |
| 189 | + global $wgTweetANewEditpage, $wgTweetANewTweet; |
| 190 | + |
| 191 | + # Check if article is new - if checkboxes are enabled and if auto-tweets of edits are disabled |
| 192 | + if ( $editpage->mTitle->exists() && $wgTweetANewEditpage['Enable'] && !$wgTweetANewTweet['Edit'] ) { |
| 193 | + $attribs = array( |
| 194 | + 'tabindex' => ++$tabindex, |
| 195 | + 'accesskey' => wfMsg( 'tweetanew-accesskey' ), |
| 196 | + 'id' => 'wpTweetANewEdit', |
| 197 | + ); |
| 198 | + |
| 199 | + # Prepare checkbox |
| 200 | + $checkboxes['twitter'] = |
| 201 | + Xml::check( 'wpTweetANewEdit', $wgTweetANewEditpage['Checked'], $attribs ) . |
| 202 | + " <label for='wpTweetANewEdit' title='". wfMsg('tweetanew-edittooltip')."'>".wfMsg('tweetanew-editaction')."</label>"; |
| 203 | + } |
| 204 | + |
| 205 | + # Check if article is new - if checkboxes are enabled and if auto-tweets of new articles are disabled |
| 206 | + elseif ( $wgTweetANewEditpage['Enable'] && !$wgTweetANewTweet['New'] ) { |
| 207 | + $attribs = array( |
| 208 | + 'tabindex' => ++$tabindex, |
| 209 | + 'accesskey' => wfMsg( 'tweetanew-accesskey' ), |
| 210 | + 'id' => 'wpTweetANew', |
| 211 | + ); |
| 212 | + |
| 213 | + # Prepare checkbox |
| 214 | + $checkboxes['twitter'] = |
| 215 | + Xml::check( 'wpTweetANew', $wgTweetANewEditpage['Checked'], $attribs ) . |
| 216 | + " <label for='wpTweetANew' title='". wfMsg('tweetanew-newtooltip')."'>".wfMsg('tweetanew-newaction')."</label>"; |
| 217 | + } |
| 218 | + return true; |
| 219 | +} |
\ No newline at end of file |