r107557 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107556‎ | r107557 | r107558 >
Date:10:14, 29 December 2011
Author:varnent
Status:deferred
Tags:
Comment:
integrated features of SendToTwitter2 - specifically use of a checkbox when auto-tweeting is disabled - extension now functional with all planned settings included - localisation also complete - lots of clean-up and ResourceLoader integration left to do before beta stage
Modified paths:
  • /trunk/extensions/TweetANew/TweetANew.body.php (modified) (history)
  • /trunk/extensions/TweetANew/TweetANew.i18n.php (modified) (history)
  • /trunk/extensions/TweetANew/TweetANew.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TweetANew/TweetANew.body.php
@@ -4,9 +4,7 @@
55 * Class file for the TweetANew extension
66 *
77 * @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
119 */
1210
1311 // TweetANew
@@ -44,82 +42,79 @@
4543 * @param $user
4644 * @param $text
4745 * @param $summary
48 - * @param $minoredit
49 - * @param $watchthis
50 - * @param $sectionanchor
51 - * @param $flags
52 - * @param $revision
5346 * @return bool
5447 */
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;
5750
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+ );
78118 }
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 - );
124119 return true;
125120 }
126121
@@ -131,107 +126,105 @@
132127 * @param $text
133128 * @param $summary
134129 * @param $minoredit
135 - * @param $watchthis
136 - * @param $sectionanchor
137 - * @param $flags
138130 * @param $revision
139131 * @return bool
140132 */
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;
143135
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 .= '&nbsp;';
 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();
192173 }
 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 .= '&nbsp;';
 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+ );
193228 }
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 - );
236229 return true;
237230 }
238231 }
\ No newline at end of file
Index: trunk/extensions/TweetANew/TweetANew.i18n.php
@@ -13,9 +13,11 @@
1414 */
1515 $messages['en'] = array(
1616 '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]',
2022 'tweetanew-minoredit' => 'm',
2123 'tweetanew-authorcredit' => 'by',
2224 'tweetanew-newdefault' => 'NEW ARTICLE: $1 - $2',
@@ -28,15 +30,16 @@
2931 'tweetanew-edit3' => 'Check out $2 - it has some new content on $1',
3032 );
3133
32 -
3334 /** Message documentation (Message documentation)
3435 * @author Gregory Varnum
3536 */
3637 $messages['qqq'] = array(
3738 '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',
4144 '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',
4245 'tweetanew-authorcredit' => 'Used to provide credit to author of edit or new article',
4346 '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 @@
5050 * $wgTweetANewTweet['SkipMinor']
5151 * - Skip minor edits
5252 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
6853 * $wgTweetANewText['Minor']
6954 * - Indicate in tweet if edit is marked as minor - only applies if $wgTweetANewTweet['SkipMinor'] = false
7055 * Default is false
@@ -97,6 +82,27 @@
9883 * $wgTweetANewText['RealName']
9984 * - Determine if user's real name will be displayed instead of their username
10085 * 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
101107 *
102108 */
103109
@@ -104,10 +110,28 @@
105111 'New' => true,
106112 'Edit' => true,
107113 'LessMinutesOld' => 5,
108 - 'SkipMinor' => false,
109 - 'Auto' => true,
 114+ 'SkipMinor' => true,
110115 );
111116
 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+
112136 $wgTweetANewTwitter = array(
113137 'ConsumerKey' => '',
114138 'ConsumerSecret' => '',
@@ -121,20 +145,6 @@
122146 'API' => '',
123147 );
124148
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 -
139149 /**
140150 * Class and localisation
141151 *
@@ -163,4 +173,46 @@
164174 */
165175
166176 $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+ "&nbsp;<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+ "&nbsp;<label for='wpTweetANew' title='". wfMsg('tweetanew-newtooltip')."'>".wfMsg('tweetanew-newaction')."</label>";
 217+ }
 218+ return true;
 219+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r107560r107557: Consistency tweaks in preparation for adding extension to translatew...raymond11:10, 29 December 2011

Status & tagging log