r87717 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87716‎ | r87717 | r87718 >
Date:14:33, 9 May 2011
Author:faurethomas
Status:deferred
Tags:
Comment:
Replace ajaxExportList by API module creation
Modified paths:
  • /trunk/extensions/WikiTweet/WikiTweet.api.php (added) (history)
  • /trunk/extensions/WikiTweet/WikiTweet.config.php (modified) (history)
  • /trunk/extensions/WikiTweet/WikiTweet.functions.php (added) (history)
  • /trunk/extensions/WikiTweet/WikiTweet.js (modified) (history)
  • /trunk/extensions/WikiTweet/WikiTweet.php (modified) (history)
  • /trunk/extensions/WikiTweet/WikiTweet2.js (modified) (history)
  • /trunk/extensions/WikiTweet/deletetweet.php (deleted) (history)
  • /trunk/extensions/WikiTweet/gettweets.php (deleted) (history)
  • /trunk/extensions/WikiTweet/subscribe.php (deleted) (history)
  • /trunk/extensions/WikiTweet/tweetmail.php (deleted) (history)
  • /trunk/extensions/WikiTweet/updatetweet.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/WikiTweet/deletetweet.php
@@ -1,15 +0,0 @@
2 -<?php
3 -if( !defined( 'MEDIAWIKI' ) ) {
4 - echo( "This file is an extension to the MediaWiki software "
5 - . "and cannot be used standalone.\n" );
6 - die( -1 );
7 -}
8 -function fnDelTweetAjax($id){
9 - include('WikiTweet.config.php');
10 - global $wgDBprefix;
11 - $dbr =& wfGetDB( DB_SLAVE );
12 - $dbr->update('wikitweet',array('`show`' => 0),array('id' => $id));
13 - $o__response = new AjaxResponse('ok');
14 - return $o__response;
15 -}
16 -?>
Index: trunk/extensions/WikiTweet/gettweets.php
@@ -1,182 +0,0 @@
2 -<?php
3 -if( !defined( 'MEDIAWIKI' ) ) {
4 - echo( "This file is an extension to the MediaWiki software "
5 - . "and cannot be used standalone.\n" );
6 - die( -1 );
7 -}
8 -function fnGetTweetsAjax($rows,$room,$user,$size='normal',$tag='',$other_room='')
9 -{
10 - global $wgDBprefix , $wgScriptPath , $wgLanguageCode;
11 - include('WikiTweet.config.php');
12 - include('WikiTweet.i18n.php');
13 -
14 - $width = "88%";
15 -
16 - $line_height = $wgWikiTweet['size'][$size]['line_height'];
17 - $font_size = $wgWikiTweet['size'][$size]['font_size'];
18 - $avatar_size = $wgWikiTweet['size'][$size]['avatar_size'];
19 - $span_avatar_width = $wgWikiTweet['size'][$size]['span_avatar_width'];
20 - $paddingli = $wgWikiTweet['size'][$size]['paddingli'];
21 - $margin_left = $wgWikiTweet['size'][$size]['margin_left'];
22 -
23 - $text = "<ol style = ' list-style-image: none;
24 - list-style-position: outside;
25 - list-style-type: none;
26 - margin-left:$margin_left;'>";
27 -
28 - $dbr =& wfGetDB( DB_SLAVE );
29 -
30 -
31 - $sql_rooms = ($room == '' or $room == 'main') ? "`room`='' OR `room`='main'" : "`room`='$room'";
32 - $res1 = $dbr->select( 'wikitweet_subscription' , '*' , "user='" . mysql_real_escape_string( $user ) . "' " );
33 - $sql_subscriptions = "";
34 - while($row1 = $dbr->fetchObject($res1))
35 - {
36 - $link = $row1->link;
37 - $type = $row1->type;
38 - $sql_subscriptions .= " OR `$type`='$link'";
39 - }
40 -
41 - if($tag!=''){
42 - $res = $dbr->select(
43 - 'wikitweet' ,
44 - '*' ,
45 - "`text` like '%$tag%' AND (`show`=1 OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user')))",
46 - __METHOD__ ,
47 - array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
48 - $text .= "<h2>".$messages[$language]['wikitweet-tweets-tagged']." <a>#$tag</a></h2>";
49 - $text .= "<p><a class='handmouse timeline'>".$messages[$language]['wikitweet-back-timeline']."...</a></p>";
50 - }
51 - elseif($other_room!=''){
52 - $res = $dbr->select(
53 - 'wikitweet' ,
54 - '*' ,
55 - "`room`='$other_room' AND (`show`=1 OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user')))",
56 - __METHOD__ ,
57 - array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
58 - $text .= "<h2>".$messages[$wgLanguageCode]['wikitweet-tweets-from-room']." \"<a>$other_room</a>\"</h2>";
59 - $text .= "<p><a class='handmouse timeline'>".$messages[$wgLanguageCode]['wikitweet-back-timeline']."...</a></p>";
60 -
61 - }
62 - else{
63 - $res = $dbr->select(
64 - 'wikitweet' ,
65 - '*' ,
66 - "(($sql_rooms $sql_subscriptions )AND `show`=1) OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user'))",
67 - __METHOD__ ,
68 - array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
69 - }
70 -
71 - while( $row = $dbr->fetchObject( $res ) )
72 - {
73 - // Pull out the fields
74 - $id = $row->id;
75 - $twext = $row->text;
76 - $tweetuser = mysql_real_escape_string($row->user);
77 - $date = $row->date;
78 - $tweet_room = $row->room;
79 - $show = $row->show;
80 - $background_color = "#FFF";
81 - $viaroom = "";
82 - $private = "";
83 - if ( $tweet_room != $room ) {
84 - $background_color = "#EFEFEF";
85 - $viaroom = "- via room <a class='handmouse room' value='$tweet_room'>$tweet_room</a>";
86 - }
87 - if ( $show == 2 ) {
88 - $background_color = "#C6DEFE";
89 - $private = "<img src='$wgScriptPath/Extensions/WikiTweet/images/lock-small.png' />";
90 - }
91 -
92 - $dateSrc = $date.' GMT';
93 - // TODO : "x hours ago, today, etc"
94 - $date_to_display = date('H:i, F jS', strtotime($dateSrc));
95 -
96 - $res2 = $dbr->select('wikitweet_avatar','avatar',"`user`='".mysql_real_escape_string($tweetuser)."' ",__METHOD__,false);
97 - $row2 = $dbr->fetchObject ( $res2 );
98 - $avatar = (count($row2)>0) ? $row2->avatar : '';
99 -
100 - $conversion_tab = array(
101 - "/\>(\S*)/is" => "><a href='$wgScriptPath/index.php/$1'>$1</a>",
102 - "/\@(\S*)/is" => "@<a href='$wgScriptPath/index.php/User:$1'>$1</a>", // TODO en anglais
103 - "/\#(\S*)/is" => "<a class='handmouse tag' value='$1'>#$1</a>",
104 - "/http(\S*)/is" => "<a href='http$1' target='_blank'>http$1</a>",
105 - "/ www(\S*)/is" => " <a href='http://www$1' target='_blank'>www$1</a>",
106 - );
107 - $twext = preg_replace(array_keys($conversion_tab), array_values($conversion_tab), $twext);
108 - $user_subscribe_text = "";
109 - $unsubscribe_string = $messages[$wgLanguageCode]['wikitweet-unsubscribe'];
110 - $subscribe_string = $messages[$wgLanguageCode]['wikitweet-subscribe'];
111 - $delete_string = $messages[$wgLanguageCode]['wikitweet-delete'];
112 - $answer_string = $messages[$wgLanguageCode]['wikitweet-answer'];
113 - $tweetuserclas = str_replace(".","__dot__",$tweetuser);
114 - $delete_tweet = "";
115 - $answer = "";
116 - if($tweetuser!=$user){
117 - $form_user = "<form style='display:none;'><input type=hidden value='$tweetuser' name='tweetuser' /></form>";
118 - $user_subscribe_text = "- <a class='handmouse user_subscribe subscribe$tweetuserclas' id='user_subscribe' style='color:#999;display:none;'>$subscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a><a style='color:#999;' class='handmouse user_unsubscribe unsubscribe$tweetuserclas'>$unsubscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a>";
119 - $res3 = $dbr->select('wikitweet_subscription','*',array(
120 - "`user`='".mysql_real_escape_string($user)."' ",
121 - "`link`='".mysql_real_escape_string($tweetuser)."' ",
122 - "`type`='user'",
123 - ));
124 - if ( $dbr->numRows($res3) == 0 ) {
125 - $user_subscribe_text = "- <a style='color:#999;' class='handmouse user_subscribe subscribe$tweetuserclas'>$subscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a><a class='handmouse user_unsubscribe unsubscribe$tweetuserclas' style='color:#999;display:none;'>$unsubscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a>";
126 - }
127 - $answer = "- <span class='answer' style='cursor:pointer;'><img src='$wgScriptPath/extensions/WikiTweet/images/answer.png'/> $answer_string $tweetuser</span>";
128 - }
129 - if((in_array($user, $wgWikiTweet['informers']) and $tweetuser == $wgWikiTweet['informuser']) or $tweetuser==$user or in_array($user, $wgWikiTweet['admin'])){
130 - $delete_tweet = " - <a class='handmouse delete_tweet' style='color:#999;'>$delete_string<span style='display:none'>$id</span></a>";
131 - }
132 - $text .= "<li class='tweet_li' id='$id' user='$tweetuser'
133 - style = ' display: list-item;
134 - margin:0;
135 - line-height: $line_height;
136 - padding: $paddingli;
137 - position:relative;
138 - background-color:$background_color;
139 - border:3px solid #FFF;
140 - border-bottom:1px solid #CCC;
141 - '>
142 - <span style = ' display:block;
143 - height: $span_avatar_width;
144 - left: 0;
145 - margin: 0 10px 0 0;
146 - overflow: hidden;
147 - position: absolute;
148 - width:$span_avatar_width;
149 - z-index: 10;
150 - /*border-bottom:1px solid #CCC;*/
151 - '>
152 - <a href='$wgScriptPath/index.php/User:$tweetuser'>
153 - <img src= '$avatar' width=$avatar_size height=$avatar_size alt='$tweetuser' border=0/>
154 - </a>
155 - </span>
156 - <span style = ' display: block;
157 - margin-left: 56px;
158 - min-height: ".$avatar_size."px;
159 - overflow: hidden;
160 - width:$width ;
161 - line-height: $line_height;
162 - font-size:$font_size;
163 - /*border-bottom:1px solid #CCC;*/
164 - '>
165 -
166 - <span style = ' line-height: $line_height;
167 - font-size:$font_size;'>
168 - <b>
169 - <a href='$wgScriptPath/index.php/User:$tweetuser'>$tweetuser</a>
170 - </b>
171 - $twext<br/>
172 - <small style='color:#999;'>$date_to_display $viaroom <span id='id_user_subscribe'>$user_subscribe_text</span><span id='tempimg2'></span>$delete_tweet $private $answer</small>
173 - </span>
174 - </span>
175 - </li>";
176 - }
177 - $text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/WikiTweet2.js"></script>';
178 - $text .= "</ol>";
179 -
180 - $o__response = new AjaxResponse($text);
181 - return $o__response;
182 -}
183 -?>
Index: trunk/extensions/WikiTweet/tweetmail.php
@@ -1,57 +0,0 @@
2 -<?php
3 -function sendWithPear($mailer, $dest, $headers, $body)
4 - {
5 - $mailResult = $mailer->send($dest, $headers, $body);
6 - if( PEAR::isError( $mailResult ) ) {
7 - return $mailResult->getMessage();
8 - } else {
9 - return true;
10 - }
11 - }
12 -function send( $to, $from, $subject, $body, $replyto=null ) {
13 - $wgOutputEncoding = 'UTF-8';
14 - $wgEnotifImpersonal = false;
15 - $wgErrorString = '';
16 - $wgEnotifMaxRecips=500;
17 - include('WikiTweet.config.php');
18 - if (is_array( $wgWikiTweet )) {
19 - require_once( 'Mail.php' );
20 - $msgid = str_replace(" ", "_", microtime());
21 - if (function_exists('posix_getpid'))
22 - $msgid .= '.' . posix_getpid();
23 - if (is_array($to)) {
24 - $dest = array();
25 - foreach ($to as $u)
26 - $dest[] = $u;
27 - } else
28 - $dest = $to;
29 - $headers['From'] = $from;
30 - if ($wgEnotifImpersonal)
31 - $headers['To'] = 'undisclosed-recipients:;';
32 - else
33 - $headers['To'] = $to;
34 - if ( $replyto ) {
35 - $headers['Reply-To'] = $replyto->toString();
36 - }
37 - $headers['Subject'] = $subject;
38 - $headers['Date'] = date( 'r' );
39 - $headers['MIME-Version'] = '1.0';
40 - $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
41 - $headers['Content-transfer-encoding'] = '8bit';
42 - $headers['Message-ID'] = "<$msgid@" . $wgWikiTweet['SMTP']['IDHost'] . '>'; // FIXME
43 - $headers['X-Mailer'] = 'MediaWiki mailer';
44 - // Create the mail object using the Mail::factory method
45 - $mail_object =& Mail::factory('smtp', $wgWikiTweet['SMTP']);
46 - if( PEAR::isError( $mail_object ) ) {
47 - wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
48 - return new WikiError( $mail_object->getMessage() );
49 - }
50 - $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
51 - foreach ($chunks as $chunk) {
52 - $e = sendWithPear($mail_object, $chunk, $headers, $body);
53 - if( $e != true)
54 - return $e;
55 - }
56 - }
57 - }
58 -?>
\ No newline at end of file
Index: trunk/extensions/WikiTweet/updatetweet.php
@@ -1,76 +0,0 @@
2 -<?php
3 -if( !defined( 'MEDIAWIKI' ) ) {
4 - echo( "This file is an extension to the MediaWiki software "
5 - . "and cannot be used standalone.\n" );
6 - die( -1 );
7 -}
8 -function fnUpdateTweetAjax($status, $user, $room, $tomail) {
9 - $text = '';
10 - include('WikiTweet.config.php');
11 - $show = ($tomail==2) ? 2 : 1;
12 - global $wgDBprefix, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname;
13 - $db = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword);
14 - mysql_select_db($wgDBname,$db);
15 -
16 - $dbr =& wfGetDB( DB_SLAVE );
17 - $dbr->insert('wikitweet',array(
18 - '`id`' => '' ,
19 - '`text`' => $status ,
20 - '`user`' => $user ,
21 - '`room`' => $room ,
22 - '`show`' => $show
23 - ));
24 -
25 - $dest=array();
26 - $user_email = $wgWikiTweet['wikimail'];
27 - include('tweetmail.php');
28 - if($tomail==1 or $tomail==2){
29 - $res = $dbr->select('user','user_email',"user_name = '$user' ");
30 - if ($dbr->numRows($res) > 0){
31 - $row = $dbr->fetchObject($res);
32 - $user_email = $row->user_email;
33 - if ($user_email!=''){
34 - $status_array = split("@",$status);
35 - $i = -1;
36 -
37 - foreach($status_array as $values){
38 - $i += 1;
39 - if ($i>0){
40 - $values_array = split(" ",$values);
41 - $username = $values_array[0];
42 - $res2 = $dbr->select('user','user_email',"user_name = '$username' ");
43 - if ($dbr->numRows($res2) > 0){
44 - $row2 = $dbr->fetchObject($res2);
45 - $useremail = $row2->user_email;
46 - if ($useremail!='')
47 - array_push($dest,$useremail);
48 - }
49 - }
50 - }
51 - }
52 - }
53 - }
54 - // r�cup�ration des abonn�s pour envoi de mail (abonn�s user ou abonn�s room)
55 - $sql1 = "SELECT DISTINCT {$wgDBprefix}user.user_email FROM {$wgDBprefix}user,{$wgDBprefix}wikitweet_subscription wt WHERE wt.user={$wgDBprefix}user.user_name AND ((wt.link = '$room' AND wt.type='room') or (wt.link='$user' AND wt.type='user')) AND wt.user!='$user' ;";
56 - $req1 = mysql_query($sql1) or die('Error SQL !');
57 - // TODO
58 -
59 - while($row1 = mysql_fetch_assoc($req1)){
60 - $useremail = $row1['user_email'];
61 - array_push($dest,$useremail);
62 - $text .= $useremail.'---';
63 - }
64 - $lenlist = 0;
65 - foreach($dest as $destmail){
66 - $lenlist += strlen($destmail);
67 - }
68 - if($lenlist>0){
69 - send( $dest, $user_email, "A new tweet for or about you !", $status);
70 - $text .= 'mail sent';
71 - }
72 -
73 - mysql_close();
74 - $o__response = new AjaxResponse($text);
75 - return $o__response;
76 -}
77 -?>
Index: trunk/extensions/WikiTweet/subscribe.php
@@ -1,34 +0,0 @@
2 -<?php
3 -if( !defined( 'MEDIAWIKI' ) ) {
4 - echo( "This file is an extension to the MediaWiki software "
5 - . "and cannot be used standalone.\n" );
6 - die( -1 );
7 -}
8 -function fnSubscribeAjax($link, $user, $type){
9 - $l__text = '';
10 - include('WikiTweet.config.php');
11 - $dbr =& wfGetDB( DB_SLAVE );
12 - $dbr->insert('wikitweet_subscription',array(
13 - '`id`' => '' ,
14 - '`user`' => $user ,
15 - '`link`' => $link ,
16 - '`type`' => $type
17 - ));
18 - $l__text .= ( $type == "user" ) ? str_replace( "." , "__dot__" , $link ) : '';
19 - $o__response = new AjaxResponse($l__text);
20 - return $o__response;
21 -}
22 -function fnUnsubscribeAjax($link, $user, $type){
23 - $l__text = '';
24 - include('WikiTweet.config.php');
25 - $dbr =& wfGetDB( DB_SLAVE );
26 - $dbr->delete('wikitweet_subscription', array(
27 - '`user`' => $user,
28 - '`link`' => $link,
29 - '`type`' => $type
30 - ));
31 - $l__text .= ( $type == "user" ) ? str_replace( "." , "__dot__" , $link ) : '';
32 - $o__response = new AjaxResponse($l__text);
33 - return $o__response;
34 -}
35 -?>
Index: trunk/extensions/WikiTweet/WikiTweet.php
@@ -9,7 +9,7 @@
1010 * with optional parameters being includes as "|param=value".
1111 *
1212 * @addtogroup Extensions
13 - * @author Thomas FAURÉ <faure.thomas@gmail.com> @whiblog
 13+ * @author Thomas FAURÉ <faure dot thomas at gmail dot com> <@whiblog>
1414 * @copyright © 2010 Thomas FAURÉ
1515 * @licence GNU General Public Licence 3.0
1616 */
@@ -31,29 +31,20 @@
3232 $wgExtensionFunctions[] = 'wikiTweeter';
3333 $wgHooks['LanguageGetMagic'][] = 'wikiTweeterMagic';
3434 $wgExtensionCredits['parserhook'][] = array(
35 - 'path' => __FILE__,
36 - 'name' => 'WikiTweet',
37 - 'author' => 'Thomas Fauré',
 35+ 'path' => __FILE__,
 36+ 'name' => 'WikiTweet',
 37+ 'author' => 'Thomas Fauré',
3838 'descriptionmsg' => 'wikitweet-desc',
39 - 'url' => 'http://www.mediawiki.org/wiki/Extension:WikiTweet',
40 - 'version' => '0.5.1'
 39+ 'url' => 'http://www.mediawiki.org/wiki/Extension:WikiTweet',
 40+ 'version' => '0.5.3'
4141 );
4242
4343 $dir = dirname(__FILE__) . '/';
4444 $wgExtensionMessagesFiles['WikiTweet'] = $dir . 'WikiTweet.i18n.php';
4545
46 -# Register Ajax functions to be called from Javascript file
47 -$wgAjaxExportList[] = 'fnGetTweetsAjax' ;
48 -$wgAjaxExportList[] = 'fnUpdateTweetAjax';
49 -$wgAjaxExportList[] = 'fnSubscribeAjax' ;
50 -$wgAjaxExportList[] = 'fnUnsubscribeAjax';
51 -$wgAjaxExportList[] = 'fnDelTweetAjax';
 46+$wgAutoloadClasses['ApiQueryWikiTweet'] = "$dir/WikiTweet.api.php";
 47+$wgAPIListModules['wikitweet'] = 'ApiQueryWikiTweet';
5248
53 -require_once( 'gettweets.php' );
54 -require_once( 'updatetweet.php' );
55 -require_once( 'subscribe.php' );
56 -require_once( 'deletetweet.php' );
57 -
5849 function wikiTweeter()
5950 {
6051 global $wgExtensionMessagesFiles, $wgParser, $wgMessageCache;
Index: trunk/extensions/WikiTweet/WikiTweet.config.php
@@ -2,8 +2,8 @@
33 $wgWikiTweet = array(
44 // User roles configuration :
55 'informuser' => "Informer",
6 - 'informers' => array("user1","user2"),
7 - 'admin' => array("user1"),
 6+ 'informers' => array("Faure.thomas","user2"),
 7+ 'admin' => array("Faure.thomas"),
88 'allowAnonymous' => True, // Is it possible to tweet anonymously ?
99 'AnonymousUser' => 'Anonymous', // Who is the "Anonymous user" (fictive user)
1010 'allowDisconnected' => False, // Is it possible to post tweet when not log in ?
Index: trunk/extensions/WikiTweet/WikiTweet.js
@@ -4,74 +4,61 @@
55 var l__rows = $("#status_update_form input[name=rows]").val();
66 var l__room = $("#status_update_form input[name=room]").val();
77 var l__user = $("#status_update_form input[name=user]").val();
8 - sajax_debug_mode = false;
98 $("#img_loader").css("display","inline");
10 - sajax_do_call("fnGetTweetsAjax", [l__rows, l__room, l__user, l__size], ajaxResponse1);
 9+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=get&wtwrows="+l__rows+"&wtwroom="+l__room+"&wtwuser="+l__user+"&wtwsize="+l__size,
 10+ function(data) {
 11+ $.each(data.query.wikitweet, function(i,item){
 12+ $("#img_loader").css("display","none");
 13+ $("#lasttweets").html(item);
 14+ if (g__timer) clearTimeout(g__timer);
 15+ g__timer = setTimeout(gettweets, refreshTime);
 16+ });
 17+ }
 18+ );
1119 }
12 -ajaxResponse1 = function handleResponse1(response) {
13 - $("#img_loader").css("display","none");
14 - $("#lasttweets").html(response.responseText);
15 - if (g__timer) clearTimeout(g__timer);
16 - g__timer = setTimeout(gettweets, refreshTime);
17 -}
1820 function gettweets_with_tag(i__tag) {
1921 var l__size = $("#status_update_form input[name=size]").val();
2022 var l__rows = $("#status_update_form input[name=rows]").val();
2123 var l__room = $("#status_update_form input[name=room]").val();
2224 var l__user = $("#status_update_form input[name=user]").val();
23 - sajax_debug_mode = false;
2425 $("#img_loader").css("display","inline");
25 - sajax_do_call("fnGetTweetsAjax", [l__rows, l__room, l__user, l__size, i__tag], ajaxResponse2);
 26+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=get&wtwrows="+l__rows+"&wtwroom="+l__room+"&wtwuser="+l__user+"&wtwsize="+l__size+"&wtwtag="+i__tag,
 27+ function(data) {
 28+ $.each(data.query.wikitweet, function(i,item){
 29+ $("#img_loader").css("display","none");
 30+ $("#lasttweets").html(item);
 31+ if (g__timer) clearTimeout(g__timer);
 32+ });
 33+ }
 34+ );
2635 }
27 -ajaxResponse2 = function handleResponse2(response) {
28 - $("#img_loader").css("display","none");
29 - $("#lasttweets").html(response.responseText);
30 - if (g__timer) clearTimeout(g__timer);
31 -}
3236 function gettweets_from_room(i__room) {
33 - var l__size = $("#status_update_form input[name=size]").val();
34 - var l__rows = $("#status_update_form input[name=rows]").val();
35 - var l__room = $("#status_update_form input[name=room]").val();
36 - var l__user = $("#status_update_form input[name=user]").val();
37 - sajax_debug_mode = false;
 37+ var l__size = escape ( $("#status_update_form input[name=size]").val() ) ;
 38+ var l__rows = escape ( $("#status_update_form input[name=rows]").val() ) ;
 39+ var l__room = escape ( $("#status_update_form input[name=room]").val() ) ;
 40+ var l__user = escape ( $("#status_update_form input[name=user]").val() ) ;
3841 $("#img_loader").css("display","inline");
39 - sajax_do_call("fnGetTweetsAjax", [l__rows, l__room, l__user, l__size, '', i__room], ajaxResponse2);
 42+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=get&wtwrows="+l__rows+"&wtwroom="+l__room+"&wtwuser="+l__user+"&wtwsize="+l__size+"&wtwother_room="+i__room,
 43+ function(data) {
 44+ $.each(data.query.wikitweet, function(i,item){
 45+ $("#img_loader").css("display","none");
 46+ $("#lasttweets").html(item);
 47+ if (g__timer) clearTimeout(g__timer);
 48+ });
 49+ }
 50+ );
4051 }
4152 function updatetweet(i__mail, i__userused){
42 - var l__status = $("#status_update_form textarea[name=status]").val();
43 - var l__room = $("#status_update_form input[name=room]").val();
44 - sajax_debug_mode = false;
45 - sajax_do_call("fnUpdateTweetAjax", [l__status, i__userused, l__room, i__mail], ajaxResponse3);
 53+ var l__status = escape( $("#status_update_form textarea[name=status]").val() ) ;
 54+ var l__room = escape( $("#status_update_form input[name=room]").val() ) ;
 55+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=update&wtwstatus="+l__status+"&wtwuser="+i__userused+"&wtwroom="+l__room+"&wtwtomail="+i__mail,
 56+ function(data) {
 57+ $("#status_update_form textarea[name=status]").val("");
 58+ $("#stringlength").html("<span>140</span>");
 59+ gettweets();
 60+ }
 61+ );
4662 }
47 -ajaxResponse3 = function handleResponse3(response) {
48 - $("#status_update_form textarea[name=status]").val("");
49 - $("#stringlength").html("<span>140</span>");
50 - gettweets();
51 -}
52 -
53 -ajaxResponse4 = function handleResponse4(response) {
54 - // ROOM SUBSCRIPTION
55 - if(data==""){
56 - $("#tempimg").html("");
57 - $("#room_subscribe").css("display", "none");
58 - $("#room_unsubscribe").css("display", "inline");
59 - }
60 - else {
61 - $("#id_room_subscribe").html("error :<br/>"+response.responseText);
62 - }
63 -}
64 -ajaxResponse5 = function handleResponse5(response) {
65 - // ROM UNSUBSCRIPTION
66 - if(data==""){
67 - $("#tempimg").html("");
68 - $("#room_unsubscribe").css("display", "none");
69 - $("#room_subscribe").css("display", "inline");
70 - }
71 - else {
72 - $("#id_room_subscribe").html("error :<br/>"+response.responseText);
73 - }
74 -}
75 -
7663 gettweets();
7764 $(document).ready(function() {
7865 $("textarea[name=status]").keyup(function() {
@@ -129,14 +116,24 @@
130117 $("#tempimg").html('<img src="'+wgScriptPath+'/extensions/WikiTweet/images/ajax-loader-mini.gif" style ="padding: 0 5px 0 5px;"/>waiting...');
131118 var i__link = $("#status_update_form input[name=room]").val();
132119 var i__user = $("#status_update_form input[name=user]").val();
133 - sajax_debug_mode = false;
134 - sajax_do_call("fnSubscribeAjax", [i__link, i__user, 'room'], ajaxResponse4);
 120+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=subscribe&wtwlink="+i__link+"&wtwuser="+i__user+"&wtwtype=room",
 121+ function(data) {
 122+ $("#tempimg").html("");
 123+ $("#room_subscribe").css("display", "none");
 124+ $("#room_unsubscribe").css("display", "inline");
 125+ }
 126+ );
135127 });
136128 $("#room_unsubscribe").click(function() {
137129 $("#tempimg").html('<img src="'+wgScriptPath+'/extensions/WikiTweet/images/ajax-loader-mini.gif" style ="padding: 0 5px 0 5px;"/>waiting...');
138130 var i__link = $("#status_update_form input[name=room]").val();
139131 var i__user = $("#status_update_form input[name=user]").val();
140 - sajax_debug_mode = false;
141 - sajax_do_call("fnUnsubscribeAjax", [i__link, i__user, 'room'], ajaxResponse5);
 132+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=unsubscribe&wtwlink="+i__link+"&wtwuser="+i__user+"&wtwtype=room",
 133+ function(data) {
 134+ $("#tempimg").html("");
 135+ $("#room_subscribe").css("display", "inline");
 136+ $("#room_unsubscribe").css("display", "none");
 137+ }
 138+ );
142139 });
143140 });
Index: trunk/extensions/WikiTweet/WikiTweet.functions.php
@@ -0,0 +1,57 @@
 2+<?php
 3+function sendWithPear($mailer, $dest, $headers, $body)
 4+ {
 5+ $mailResult = $mailer->send($dest, $headers, $body);
 6+ if( PEAR::isError( $mailResult ) ) {
 7+ return $mailResult->getMessage();
 8+ } else {
 9+ return true;
 10+ }
 11+ }
 12+function send( $to, $from, $subject, $body, $replyto=null ) {
 13+ $wgOutputEncoding = 'UTF-8';
 14+ $wgEnotifImpersonal = false;
 15+ $wgErrorString = '';
 16+ $wgEnotifMaxRecips=500;
 17+ include('WikiTweet.config.php');
 18+ if (is_array( $wgWikiTweet )) {
 19+ require_once( 'Mail.php' );
 20+ $msgid = str_replace(" ", "_", microtime());
 21+ if (function_exists('posix_getpid'))
 22+ $msgid .= '.' . posix_getpid();
 23+ if (is_array($to)) {
 24+ $dest = array();
 25+ foreach ($to as $u)
 26+ $dest[] = $u;
 27+ } else
 28+ $dest = $to;
 29+ $headers['From'] = $from;
 30+ if ($wgEnotifImpersonal)
 31+ $headers['To'] = 'undisclosed-recipients:;';
 32+ else
 33+ $headers['To'] = $to;
 34+ if ( $replyto ) {
 35+ $headers['Reply-To'] = $replyto->toString();
 36+ }
 37+ $headers['Subject'] = $subject;
 38+ $headers['Date'] = date( 'r' );
 39+ $headers['MIME-Version'] = '1.0';
 40+ $headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
 41+ $headers['Content-transfer-encoding'] = '8bit';
 42+ $headers['Message-ID'] = "<$msgid@" . $wgWikiTweet['SMTP']['IDHost'] . '>'; // FIXME
 43+ $headers['X-Mailer'] = 'MediaWiki mailer';
 44+ // Create the mail object using the Mail::factory method
 45+ $mail_object =& Mail::factory('smtp', $wgWikiTweet['SMTP']);
 46+ if( PEAR::isError( $mail_object ) ) {
 47+ wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
 48+ return new WikiError( $mail_object->getMessage() );
 49+ }
 50+ $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
 51+ foreach ($chunks as $chunk) {
 52+ $e = sendWithPear($mail_object, $chunk, $headers, $body);
 53+ if( $e != true)
 54+ return $e;
 55+ }
 56+ }
 57+ }
 58+?>
\ No newline at end of file
Property changes on: trunk/extensions/WikiTweet/WikiTweet.functions.php
___________________________________________________________________
Added: svn:eol-style
159 + native
Index: trunk/extensions/WikiTweet/WikiTweet2.js
@@ -1,20 +1,3 @@
2 -ajaxResponse6 = function handleResponse6(response) {
3 - // USER SUBSCRIPTION
4 - $("#tempimg2").html("");
5 - $(".subscribe"+response.responseText).css("display", "none");
6 - $(".unsubscribe"+response.responseText).css("display", "inline");
7 -}
8 -ajaxResponse7 = function handleResponse7(response) {
9 - // USER UNSUBSCRIPTION
10 - $("#tempimg2").html("");
11 - $(".unsubscribe"+response.responseText).css("display", "none");
12 - $(".subscribe"+response.responseText).css("display", "inline");
13 -}
14 -ajaxResponse8 = function handleResponse8(response) {
15 - // DELETE TWEET
16 - gettweets();
17 -}
18 -
192 $('.tweet_li').mouseover(function() {
203 $(this).css("border-left","3px solid #BBB");
214 }).mouseout(function(){
@@ -24,20 +7,37 @@
258 $("#tempimg2",this).html('<img src="'+wgScriptPath+'/extensions/WikiTweet/images/ajax-loader-mini.gif" style ="padding: 0 5px 0 5px;"/>waiting...');
269 var i__link = $("span",this).html();
2710 var i__user = $("#status_update_form input[name=user]").val();
28 - sajax_debug_mode = false;
29 - sajax_do_call("fnSubscribeAjax", [i__link, i__user, 'user'], ajaxResponse6);
 11+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=subscribe&wtwlink="+i__link+"&wtwuser="+i__user+"&wtwtype=user",
 12+ function(data) {
 13+ $("#tempimg2").html("");
 14+ $.each(data.query.wikitweet, function(i,item){
 15+ $(".subscribe"+item).css("display", "none");
 16+ $(".unsubscribe"+item).css("display", "inline");
 17+ });
 18+ }
 19+ );
3020 });
3121 $(".user_unsubscribe").click(function() {
3222 $("#tempimg2",this).html('<img src="'+wgScriptPath+'/extensions/WikiTweet/images/ajax-loader-mini.gif" style ="padding: 0 5px 0 5px;"/>waiting...');
3323 var i__link = $("span",this).html();
3424 var i__user = $("#status_update_form input[name=user]").val();
35 - sajax_debug_mode = false;
36 - sajax_do_call("fnUnsubscribeAjax", [i__link, i__user, 'user'], ajaxResponse7);
 25+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=unsubscribe&wtwlink="+i__link+"&wtwuser="+i__user+"&wtwtype=user",
 26+ function(data) {
 27+ $("#tempimg2").html("");
 28+ $.each(data.query.wikitweet, function(i,item){
 29+ $(".unsubscribe"+item).css("display", "none");
 30+ $(".subscribe"+item).css("display", "inline");
 31+ });
 32+ }
 33+ );
3734 });
3835 $(".delete_tweet").click(function() {
3936 var i__id = $("span",this).html();
40 - sajax_debug_mode = false;
41 - sajax_do_call("fnDelTweetAjax", [i__id], ajaxResponse8);
 37+ $.getJSON(wgScriptPath+"/api.php?action=query&format=json&list=wikitweet&wtwreq=delete&wtwid="+i__id,
 38+ function(data) {
 39+ gettweets();
 40+ }
 41+ );
4242 });
4343 $(".answer").mouseover(function(){
4444 $(this).css("text-decoration","underline");
Index: trunk/extensions/WikiTweet/WikiTweet.api.php
@@ -0,0 +1,446 @@
 2+<?php
 3+/**
 4+ * Created on May 05, 2011
 5+ *
 6+ * WikiTweet extension
 7+ *
 8+ * Copyright (C) 2011 faure dot thomas at gmail dot com
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ */
 25+/**
 26+ * Query module to get the list of the Categories beginning by a given string.
 27+ *
 28+ * @ingroup API
 29+ * @ingroup Extensions
 30+ */
 31+class ApiQueryWikiTweet extends ApiQueryBase {
 32+ public function __construct( $query, $moduleName ) {
 33+ parent::__construct( $query, $moduleName, 'wtw' );
 34+ }
 35+ public function execute() {
 36+ global $wgUser;
 37+ $params = $this->extractRequestParams();
 38+ $req = $params['req'];
 39+ $result = $this->getResult();
 40+ switch($req){
 41+ case 'get':
 42+ $rows = $params['rows'] ;
 43+ $room = $params['room'] ;
 44+ $user = $params['user'] ;
 45+ $size = (isset($params['size'])) ? $params['size'] : 'normal' ;
 46+ $tag = (isset($params['tag'])) ? $params['tag'] : '' ;
 47+ $other_room = (isset($params['other_room'])) ? $params['other_room'] : '' ;
 48+
 49+ $o__output_string = ApiQueryWikiTweet::fnGetTweetsAjax($rows,$room,$user,$size,$tag,$other_room);
 50+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $o__output_string );
 51+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'output' );
 52+ break;
 53+ case 'delete':
 54+ // TODO : user rights
 55+ $id = (isset($params['id'])) ? $params['id'] : -1 ;
 56+ if ( $id == -1 ) $this->dieUsage( 'You must enter a parameter "id" with "delete" option.', 'params' );
 57+ ApiQueryWikiTweet::fnDelTweetAjax($id);
 58+ break;
 59+ case 'update':
 60+ $status = $params['status'] ;
 61+ $user = $params['user'] ;
 62+ $room = $params['room'] ;
 63+ $tomail = $params['tomail'] ;
 64+ ApiQueryWikiTweet::fnUpdateTweetAjax($status, $user, $room, $tomail);
 65+ break;
 66+ case 'subscribe':
 67+ $type = (isset($params['type'])) ? $params['type'] : '' ;
 68+ $link = (isset($params['link'])) ? $params['link'] : '' ;
 69+ $user = (isset($params['user'])) ? $params['user'] : '' ;
 70+ $o__output_string = ApiQueryWikiTweet::fnSubscribeAjax($link, $user, $type);
 71+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $o__output_string );
 72+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'output' );
 73+ break;
 74+ case 'unsubscribe':
 75+ $type = (isset($params['type'])) ? $params['type'] : '' ;
 76+ $link = (isset($params['link'])) ? $params['link'] : '' ;
 77+ $user = (isset($params['user'])) ? $params['user'] : '' ;
 78+ $o__output_string = ApiQueryWikiTweet::fnUnsubscribeAjax($link, $user, $type);
 79+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $o__output_string );
 80+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'output' );
 81+ break;
 82+ default:
 83+ break;
 84+ }
 85+ }
 86+
 87+
 88+ public static function fnGetTweetsAjax($rows,$room,$user,$size='normal',$tag='',$other_room='')
 89+ {
 90+ global $wgDBprefix , $wgScriptPath , $wgLanguageCode;
 91+ include('WikiTweet.config.php');
 92+
 93+ $width = "88%";
 94+
 95+ $line_height = $wgWikiTweet['size'][$size]['line_height'];
 96+ $font_size = $wgWikiTweet['size'][$size]['font_size'];
 97+ $avatar_size = $wgWikiTweet['size'][$size]['avatar_size'];
 98+ $span_avatar_width = $wgWikiTweet['size'][$size]['span_avatar_width'];
 99+ $paddingli = $wgWikiTweet['size'][$size]['paddingli'];
 100+ $margin_left = $wgWikiTweet['size'][$size]['margin_left'];
 101+
 102+ $text = "<ol style = ' list-style-image: none;
 103+ list-style-position: outside;
 104+ list-style-type: none;
 105+ margin-left:$margin_left;'>";
 106+
 107+ $dbr =& wfGetDB( DB_SLAVE );
 108+
 109+
 110+ $sql_rooms = ($room == '' or $room == 'main') ? "`room`='' OR `room`='main'" : "`room`='$room'";
 111+ $res1 = $dbr->select( 'wikitweet_subscription' , '*' , "user='" . mysql_real_escape_string( $user ) . "' " );
 112+ $sql_subscriptions = "";
 113+ while($row1 = $dbr->fetchObject($res1))
 114+ {
 115+ $link = $row1->link;
 116+ $type = $row1->type;
 117+ $sql_subscriptions .= " OR `$type`='$link'";
 118+ }
 119+
 120+ if($tag!=''){
 121+ $res = $dbr->select(
 122+ 'wikitweet' ,
 123+ '*' ,
 124+ "`text` like '%$tag%' AND (`show`=1 OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user')))",
 125+ __METHOD__ ,
 126+ array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
 127+ $text .= "<h2>".wfMsg ( 'wikitweet-tweets-tagged' ) ." <a>#$tag</a></h2>";
 128+ $text .= "<p><a class='handmouse timeline'>".wfMsg('wikitweet-back-timeline')."...</a></p>";
 129+ }
 130+ elseif($other_room!=''){
 131+ $res = $dbr->select(
 132+ 'wikitweet' ,
 133+ '*' ,
 134+ "`room`='$other_room' AND (`show`=1 OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user')))",
 135+ __METHOD__ ,
 136+ array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
 137+ $text .= "<h2>".wfMsg('wikitweet-tweets-from-room')." \"<a>$other_room</a>\"</h2>";
 138+ $text .= "<p><a class='handmouse timeline'>".wfMsg('wikitweet-back-timeline')."...</a></p>";
 139+
 140+ }
 141+ else{
 142+ $res = $dbr->select(
 143+ 'wikitweet' ,
 144+ '*' ,
 145+ "(($sql_rooms $sql_subscriptions )AND `show`=1) OR (`show`=2 AND (`text` like '%@$user%' OR `user`='$user'))",
 146+ __METHOD__ ,
 147+ array("ORDER BY" =>" `date` DESC", "LIMIT" => $rows));
 148+ }
 149+
 150+ while( $row = $dbr->fetchObject( $res ) )
 151+ {
 152+ // Pull out the fields
 153+ $id = $row->id;
 154+ $twext = $row->text;
 155+ $tweetuser = mysql_real_escape_string($row->user);
 156+ $date = $row->date;
 157+ $tweet_room = $row->room;
 158+ $show = $row->show;
 159+ $background_color = "#FFF";
 160+ $viaroom = "";
 161+ $private = "";
 162+ if ( $tweet_room != $room ) {
 163+ $background_color = "#EFEFEF";
 164+ $viaroom = "- via room <a class='handmouse room' value='$tweet_room'>$tweet_room</a>";
 165+ }
 166+ if ( $show == 2 ) {
 167+ $background_color = "#C6DEFE";
 168+ $private = "<img src='$wgScriptPath/Extensions/WikiTweet/images/lock-small.png' />";
 169+ }
 170+
 171+ $dateSrc = $date.' GMT';
 172+ // TODO : "x hours ago, today, etc"
 173+ $date_to_display = date('H:i, F jS', strtotime($dateSrc));
 174+
 175+ $res2 = $dbr->select('wikitweet_avatar','avatar',"`user`='".mysql_real_escape_string($tweetuser)."' ",__METHOD__,false);
 176+ $row2 = $dbr->fetchObject ( $res2 );
 177+ $avatar = (count($row2)>0) ? $row2->avatar : '';
 178+
 179+ $conversion_tab = array(
 180+ "/\>(\S*)/is" => "><a href='$wgScriptPath/index.php/$1'>$1</a>",
 181+ "/\@(\S*)/is" => "@<a href='$wgScriptPath/index.php/User:$1'>$1</a>", // TODO en anglais
 182+ "/\#(\S*)/is" => "<a class='handmouse tag' value='$1'>#$1</a>",
 183+ "/http(\S*)/is" => "<a href='http$1' target='_blank'>http$1</a>",
 184+ "/ www(\S*)/is" => " <a href='http://www$1' target='_blank'>www$1</a>",
 185+ );
 186+ $twext = preg_replace(array_keys($conversion_tab), array_values($conversion_tab), $twext);
 187+ $user_subscribe_text = "";
 188+ $unsubscribe_string = wfMsg('wikitweet-unsubscribe');
 189+ $subscribe_string = wfMsg('wikitweet-subscribe');
 190+ $delete_string = wfMsg('wikitweet-delete');
 191+ $answer_string = wfMsg('wikitweet-answer');
 192+ $tweetuserclas = str_replace(".","__dot__",$tweetuser);
 193+ $delete_tweet = "";
 194+ $answer = "";
 195+ if($tweetuser!=$user){
 196+ $form_user = "<form style='display:none;'><input type=hidden value='$tweetuser' name='tweetuser' /></form>";
 197+ $user_subscribe_text = "- <a class='handmouse user_subscribe subscribe$tweetuserclas' id='user_subscribe' style='color:#999;display:none;'>$subscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a><a style='color:#999;' class='handmouse user_unsubscribe unsubscribe$tweetuserclas'>$unsubscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a>";
 198+ $res3 = $dbr->select('wikitweet_subscription','*',array(
 199+ "`user`='".mysql_real_escape_string($user)."' ",
 200+ "`link`='".mysql_real_escape_string($tweetuser)."' ",
 201+ "`type`='user'",
 202+ ));
 203+ if ( $dbr->numRows($res3) == 0 ) {
 204+ $user_subscribe_text = "- <a style='color:#999;' class='handmouse user_subscribe subscribe$tweetuserclas'>$subscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a><a class='handmouse user_unsubscribe unsubscribe$tweetuserclas' style='color:#999;display:none;'>$unsubscribe_string<span id='tweetuser' style='display:none'>$tweetuser</span>$form_user</a>";
 205+ }
 206+ $answer = "- <span class='answer' style='cursor:pointer;'><img src='$wgScriptPath/extensions/WikiTweet/images/answer.png'/> $answer_string $tweetuser</span>";
 207+ }
 208+ if((in_array($user, $wgWikiTweet['informers']) and $tweetuser == $wgWikiTweet['informuser']) or $tweetuser==$user or in_array($user, $wgWikiTweet['admin'])){
 209+ $delete_tweet = " - <a class='handmouse delete_tweet' style='color:#999;'>$delete_string<span style='display:none'>$id</span></a>";
 210+ }
 211+ $text .= "<li class='tweet_li' id='$id' user='$tweetuser'
 212+ style = ' display: list-item;
 213+ margin:0;
 214+ line-height: $line_height;
 215+ padding: $paddingli;
 216+ position:relative;
 217+ background-color:$background_color;
 218+ border:3px solid #FFF;
 219+ border-bottom:1px solid #CCC;
 220+ '>
 221+ <span style = ' display:block;
 222+ height: $span_avatar_width;
 223+ left: 0;
 224+ margin: 0 10px 0 0;
 225+ overflow: hidden;
 226+ position: absolute;
 227+ width:$span_avatar_width;
 228+ z-index: 10;
 229+ /*border-bottom:1px solid #CCC;*/
 230+ '>
 231+ <a href='$wgScriptPath/index.php/User:$tweetuser'>
 232+ <img src= '$avatar' width=$avatar_size height=$avatar_size alt='$tweetuser' border=0/>
 233+ </a>
 234+ </span>
 235+ <span style = ' display: block;
 236+ margin-left: 56px;
 237+ min-height: ".$avatar_size."px;
 238+ overflow: hidden;
 239+ width:$width ;
 240+ line-height: $line_height;
 241+ font-size:$font_size;
 242+ /*border-bottom:1px solid #CCC;*/
 243+ '>
 244+
 245+ <span style = ' line-height: $line_height;
 246+ font-size:$font_size;'>
 247+ <b>
 248+ <a href='$wgScriptPath/index.php/User:$tweetuser'>$tweetuser</a>
 249+ </b>
 250+ $twext<br/>
 251+ <small style='color:#999;'>$date_to_display $viaroom <span id='id_user_subscribe'>$user_subscribe_text</span><span id='tempimg2'></span>$delete_tweet $private $answer</small>
 252+ </span>
 253+ </span>
 254+ </li>";
 255+ }
 256+ $text .= '<script type="text/javascript" src="'.$wgScriptPath.'/extensions/WikiTweet/WikiTweet2.js"></script>';
 257+ $text .= "</ol>";
 258+
 259+ return $text;
 260+ }
 261+ public static function fnDelTweetAjax($id){
 262+ include('WikiTweet.config.php');
 263+ global $wgDBprefix;
 264+ $dbr =& wfGetDB( DB_SLAVE );
 265+ $dbr->update('wikitweet',array('`show`' => 0),array('id' => $id));
 266+ $o__response = new AjaxResponse('ok');
 267+ return $o__response;
 268+ }
 269+ public static function fnUpdateTweetAjax($status, $user, $room, $tomail) {
 270+ $text = '';
 271+ include('WikiTweet.config.php');
 272+ $show = ($tomail==2) ? 2 : 1;
 273+ global $wgDBprefix, $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname;
 274+ $db = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword);
 275+ mysql_select_db($wgDBname,$db);
 276+
 277+ $dbr =& wfGetDB( DB_SLAVE );
 278+ $dbr->insert('wikitweet',array(
 279+ '`id`' => '' ,
 280+ '`text`' => $status ,
 281+ '`user`' => $user ,
 282+ '`room`' => $room ,
 283+ '`show`' => $show
 284+ ));
 285+
 286+ $dest=array();
 287+ $user_email = $wgWikiTweet['wikimail'];
 288+ include('WikiTweet.functions.php');
 289+ if($tomail==1 or $tomail==2){
 290+ $res = $dbr->select('user','user_email',"user_name = '$user' ");
 291+ if ($dbr->numRows($res) > 0){
 292+ $row = $dbr->fetchObject($res);
 293+ $user_email = $row->user_email;
 294+ if ($user_email!=''){
 295+ $status_array = split("@",$status);
 296+ $i = -1;
 297+
 298+ foreach($status_array as $values){
 299+ $i += 1;
 300+ if ($i>0){
 301+ $values_array = split(" ",$values);
 302+ $username = $values_array[0];
 303+ $res2 = $dbr->select('user','user_email',"user_name = '$username' ");
 304+ if ($dbr->numRows($res2) > 0){
 305+ $row2 = $dbr->fetchObject($res2);
 306+ $useremail = $row2->user_email;
 307+ if ($useremail!='')
 308+ array_push($dest,$useremail);
 309+ }
 310+ }
 311+ }
 312+ }
 313+ }
 314+ }
 315+ // récupération des abonnés pour envoi de mail (abonnés user ou abonnés room)
 316+ $sql1 = "SELECT DISTINCT {$wgDBprefix}user.user_email FROM {$wgDBprefix}user,{$wgDBprefix}wikitweet_subscription wt WHERE wt.user={$wgDBprefix}user.user_name AND ((wt.link = '$room' AND wt.type='room') or (wt.link='$user' AND wt.type='user')) AND wt.user!='$user' ;";
 317+ $req1 = mysql_query($sql1) or die('Error SQL !');
 318+ // TODO
 319+
 320+ while($row1 = mysql_fetch_assoc($req1)){
 321+ $useremail = $row1['user_email'];
 322+ array_push($dest,$useremail);
 323+ $text .= $useremail.'---';
 324+ }
 325+ $lenlist = 0;
 326+ foreach($dest as $destmail){
 327+ $lenlist += strlen($destmail);
 328+ }
 329+ if($lenlist>0){
 330+ send( $dest, $user_email, "A new tweet for or about you !", $status);
 331+ $text .= 'mail sent';
 332+ }
 333+
 334+ mysql_close();
 335+ $o__response = new AjaxResponse($text);
 336+ return $o__response;
 337+ }
 338+ public static function fnSubscribeAjax($link, $user, $type){
 339+ $o__text = '';
 340+ include('WikiTweet.config.php');
 341+ $dbr =& wfGetDB( DB_SLAVE );
 342+ $dbr->insert('wikitweet_subscription',array(
 343+ '`id`' => '' ,
 344+ '`user`' => $user ,
 345+ '`link`' => $link ,
 346+ '`type`' => $type
 347+ ));
 348+ $o__text .= ( $type == "user" ) ? str_replace( "." , "__dot__" , $link ) : '';
 349+ return $o__text;
 350+ }
 351+ public static function fnUnsubscribeAjax($link, $user, $type){
 352+ $o__text = '';
 353+ include('WikiTweet.config.php');
 354+ $dbr =& wfGetDB( DB_SLAVE );
 355+ $dbr->delete('wikitweet_subscription', array(
 356+ '`user`' => $user,
 357+ '`link`' => $link,
 358+ '`type`' => $type
 359+ ));
 360+ $o__text .= ( $type == "user" ) ? str_replace( "." , "__dot__" , $link ) : '';
 361+ return $o__text;
 362+ }
 363+
 364+ public function getAllowedParams() {
 365+ return array(
 366+ 'req' => array (
 367+ ApiBase :: PARAM_DFLT => 'get',
 368+ ApiBase :: PARAM_TYPE => array (
 369+ 'get',
 370+ 'delete',
 371+ 'update',
 372+ 'subscribe',
 373+ 'unsubscribe'
 374+ )
 375+ ),
 376+ 'rows' => array (
 377+ ApiBase :: PARAM_TYPE => 'integer'
 378+ ),
 379+ 'room' => array (
 380+ ApiBase :: PARAM_TYPE => 'string'
 381+ ),
 382+ 'user' => array (
 383+ ApiBase :: PARAM_TYPE => 'string'
 384+ ),
 385+ 'size' => array (
 386+ ApiBase :: PARAM_TYPE => 'string'
 387+ ),
 388+ 'tag' => array (
 389+ ApiBase :: PARAM_TYPE => 'string'
 390+ ),
 391+ 'other_room' => array (
 392+ ApiBase :: PARAM_TYPE => 'string'
 393+ ),
 394+ 'id' => array (
 395+ ApiBase :: PARAM_TYPE => 'integer'
 396+ ),
 397+ 'tomail' => array (
 398+ ApiBase :: PARAM_TYPE => 'string'
 399+ ),
 400+ 'status' => array (
 401+ ApiBase :: PARAM_TYPE => 'string'
 402+ ),
 403+ 'type' => array (
 404+ ApiBase :: PARAM_DFLT => 'user',
 405+ ApiBase :: PARAM_TYPE => array (
 406+ 'user',
 407+ 'room'
 408+ )
 409+ ),
 410+ 'link' => array (
 411+ ApiBase :: PARAM_TYPE => 'string'
 412+ ),
 413+ );
 414+ }
 415+
 416+ public function getParamDescription() {
 417+ return array(
 418+ 'get' => 'Get tweets',
 419+ 'delete' => 'Delete a given tweet',
 420+ 'update' => 'Add a tweet',
 421+ 'subscribe' => 'Subscription management'
 422+ );
 423+ }
 424+
 425+ public function getDescription() {
 426+ return 'API to manage WikiTweets';
 427+ }
 428+
 429+ public function getPossibleErrors() {
 430+ return array_merge( parent::getPossibleErrors(), array(
 431+ array( 'code' => 'params', 'info' => 'You must enter a parameter "id" with "delete" option.' ),
 432+ ) );
 433+ }
 434+
 435+ protected function getExamples() {
 436+ return array(
 437+ 'api.php?action=query&list=wikitweet&wtwreq=get&wtwrows=3&wtwroom=Main&wtwuser=user1',
 438+ 'api.php?action=query&list=wikitweet&wtwreq=delete',
 439+ 'api.php?action=query&list=wikitweet&wtwreq=update',
 440+ 'api.php?action=query&list=wikitweet&wtwreq=subscribe'
 441+ );
 442+ }
 443+
 444+ public function getVersion() {
 445+ return __CLASS__ . ': $Id: WikiTweet.api.php xxxxx 2010-05-09 13:42:00Z Faure.thomas $';
 446+ }
 447+}
\ No newline at end of file
Property changes on: trunk/extensions/WikiTweet/WikiTweet.api.php
___________________________________________________________________
Added: svn:eol-style
1448 + native

Status & tagging log