00001 <?php 00002 00003 require_once( "Feed.php" ); 00004 00005 function wfSpecialRecentchanges( $par ) 00006 { 00007 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; 00008 global $wgRequest, $wgSitename, $wgLanguageCode; 00009 global $wgFeedClasses; 00010 $fname = "wfSpecialRecentchanges"; 00011 00012 # Get query parameters 00013 $feedFormat = $wgRequest->getVal( "feed" ); 00014 00015 $defaultDays = $wgUser->getOption( 'rcdays' ); 00016 if ( !$defaultDays ) { 00017 $defaultDays = 3; 00018 } 00019 00020 $days = $wgRequest->getInt( 'days', $defaultDays ); 00021 $hideminor = $wgRequest->getBool( 'hideminor', $wgUser->getOption( 'hideminor' ) ) ? 1 : 0; 00022 $from = $wgRequest->getText( 'from' ); 00023 $hidebots = $wgRequest->getBool( 'hidebots', true ) ? 1 : 0; 00024 $hideliu = $wgRequest->getBool( 'hideliu', false ) ? 1 : 0; 00025 00026 # Get query parameters from path 00027 if( $par ) { 00028 $bits = preg_split( '/\s*,\s*/', trim( $par ) ); 00029 if( in_array( "hidebots", $bits ) ) $hidebots = 1; 00030 if( in_array( "bots", $bits ) ) $hidebots = 0; 00031 if( in_array( "hideminor", $bits ) ) $hideminor = 1; 00032 if( in_array( "minor", $bits ) ) $hideminor = 0; 00033 if( in_array( "hideliu", $bits) ) $hideliu = 1; 00034 } 00035 00036 $sql = "SELECT MAX(rc_timestamp) AS lastmod FROM recentchanges"; 00037 $res = wfQuery( $sql, DB_READ, $fname ); 00038 $s = wfFetchObject( $res ); 00039 # 10 seconds server-side caching max 00040 $wgOut->setSquidMaxage( 10 ); 00041 if( $wgOut->checkLastModified( $s->lastmod ) ){ 00042 # Client cache fresh and headers sent, nothing more to do. 00043 return; 00044 } 00045 00046 $rctext = wfMsg( "recentchangestext" ); 00047 00048 # The next few lines can probably be commented out now that wfMsg can get text from the DB 00049 $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'"; 00050 $res = wfQuery( $sql, DB_READ, $fname ); 00051 if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) { 00052 $rctext = $s->cur_text; 00053 } 00054 00055 $wgOut->addWikiText( $rctext ); 00056 00057 list( $limit, $offset ) = wfCheckLimits( 100, "rclimit" ); 00058 $now = wfTimestampNow(); 00059 $cutoff_unixtime = time() - ( $days * 86400 ); 00060 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400); 00061 $cutoff = wfUnix2Timestamp( $cutoff_unixtime ); 00062 if(preg_match('/^[0-9]{14}$/', $from) and $from > $cutoff) { 00063 $cutoff = $from; 00064 } else { 00065 unset($from); 00066 } 00067 00068 $sk = $wgUser->getSkin(); 00069 $showhide = array( wfMsg( "show" ), wfMsg( "hide" )); 00070 00071 if ( $hideminor ) { 00072 $hidem = "AND rc_minor=0"; 00073 } else { 00074 $hidem = ""; 00075 } 00076 00077 if( $hidebots ) { 00078 $hidem .= " AND rc_bot=0"; 00079 } 00080 00081 if ( $hideliu ) { 00082 $hidem .= " AND rc_user=0"; 00083 } 00084 $hideliu = ($hideliu ? 1 : 0); 00085 #$hideparams = "hideminor={$hideminor}&hideliu={$hideliu}&hidebots={$hidebots}"; 00086 $urlparams = array( "hideminor" => $hideminor, "hideliu" => $hideliu, "hidebots" => $hidebots ); 00087 $hideparams = wfArrayToCGI( $urlparams ); 00088 00089 $minorLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ), 00090 $showhide[1-$hideminor], wfArrayToCGI( array( "hideminor" => 1-$hideminor ), $urlparams ) ); 00091 $botLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ), 00092 $showhide[1-$hidebots], wfArrayToCGI( array( "hidebots" => 1-$hidebots ), $urlparams ) ); 00093 $liuLink = $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ), 00094 $showhide[1-$hideliu], wfArrayToCGI( array( "hideliu" => 1-$hideliu ), $urlparams ) ); 00095 00096 $uid = $wgUser->getID(); 00097 $sql2 = "SELECT recentchanges.*" . ($uid ? ",wl_user" : "") . " FROM recentchanges " . 00098 ($uid ? "LEFT OUTER JOIN watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace & 65534 " : "") . 00099 "WHERE rc_timestamp > '{$cutoff}' {$hidem} " . 00100 "ORDER BY rc_timestamp DESC LIMIT {$limit}"; 00101 00102 $res = wfQuery( $sql2, DB_READ, $fname ); 00103 $rows = array(); 00104 while( $row = wfFetchObject( $res ) ){ 00105 $rows[] = $row; 00106 } 00107 00108 if(isset($from)) { 00109 $note = wfMsg( "rcnotefrom", $wgLang->formatNum( $limit ), 00110 $wgLang->timeanddate( $from, true ) ); 00111 } else { 00112 $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) ); 00113 } 00114 $wgOut->addHTML( "\n<hr />\n{$note}\n<br />" ); 00115 00116 $note = rcDayLimitLinks( $days, $limit, "Recentchanges", $hideparams, false, $minorLink, $botLink, $liuLink ); 00117 00118 $note .= "<br />\n" . wfMsg( "rclistfrom", 00119 $sk->makeKnownLink( $wgLang->specialPage( "Recentchanges" ), 00120 $wgLang->timeanddate( $now, true ), "{$hideparams}&from=$now" ) ); 00121 00122 $wgOut->addHTML( "{$note}\n" ); 00123 00124 if( isset($wgFeedClasses[$feedFormat]) ) { 00125 $feed = new $wgFeedClasses[$feedFormat]( 00126 $wgSitename . " - " . wfMsg( "recentchanges" ) . " [" . $wgLanguageCode . "]", 00127 htmlspecialchars( wfMsg( "recentchangestext" ) ), 00128 $wgTitle->getFullUrl() ); 00129 $feed->outHeader(); 00130 foreach( $rows as $obj ) { 00131 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title ); 00132 $talkpage = $title->getTalkPage(); 00133 $item = new FeedItem( 00134 $title->getPrefixedText(), 00135 htmlspecialchars( $obj->rc_comment ), 00136 $title->getFullURL(), 00137 $obj->rc_timestamp, 00138 $obj->rc_user_text, 00139 $talkpage->getFullURL() 00140 ); 00141 $feed->outItem( $item ); 00142 } 00143 $feed->outFooter(); 00144 } else { 00145 $wgOut->setSyndicated( true ); 00146 $s = $sk->beginRecentChangesList(); 00147 $counter = 1; 00148 foreach( $rows as $obj ){ 00149 if( $limit == 0) { 00150 break; 00151 } 00152 00153 if ( ! ( $hideminor && $obj->rc_minor ) ) { 00154 $rc = RecentChange::newFromRow( $obj ); 00155 $rc->counter = $counter++; 00156 $s .= $sk->recentChangesLine( $rc, !empty( $obj->wl_user ) ); 00157 --$limit; 00158 } 00159 } 00160 $s .= $sk->endRecentChangesList(); 00161 $wgOut->addHTML( $s ); 00162 } 00163 wfFreeResult( $res ); 00164 } 00165 00166 function rcCountLink( $lim, $d, $page="Recentchanges", $more="" ) 00167 { 00168 global $wgUser, $wgLang; 00169 $sk = $wgUser->getSkin(); 00170 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ), 00171 ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( "all" ) ), "{$more}" . 00172 ($d ? "days={$d}&" : "") . "limit={$lim}" ); 00173 return $s; 00174 } 00175 00176 function rcDaysLink( $lim, $d, $page="Recentchanges", $more="" ) 00177 { 00178 global $wgUser, $wgLang; 00179 $sk = $wgUser->getSkin(); 00180 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ), 00181 ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), "{$more}days={$d}" . 00182 ($lim ? "&limit={$lim}" : "") ); 00183 return $s; 00184 } 00185 00186 function rcDayLimitLinks( $days, $limit, $page="Recentchanges", $more="", $doall = false, $minorLink = "", 00187 $botLink = "", $liuLink = "" ) 00188 { 00189 if ($more != "") $more .= "&"; 00190 $cl = rcCountLink( 50, $days, $page, $more ) . " | " . 00191 rcCountLink( 100, $days, $page, $more ) . " | " . 00192 rcCountLink( 250, $days, $page, $more ) . " | " . 00193 rcCountLink( 500, $days, $page, $more ) . 00194 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" ); 00195 $dl = rcDaysLink( $limit, 1, $page, $more ) . " | " . 00196 rcDaysLink( $limit, 3, $page, $more ) . " | " . 00197 rcDaysLink( $limit, 7, $page, $more ) . " | " . 00198 rcDaysLink( $limit, 14, $page, $more ) . " | " . 00199 rcDaysLink( $limit, 30, $page, $more ) . 00200 ( $doall ? ( " | " . rcDaysLink( $limit, 0, $page, $more ) ) : "" ); 00201 $shm = wfMsg( "showhideminor", $minorLink, $botLink, $liuLink ); 00202 $note = wfMsg( "rclinks", $cl, $dl, $shm ); 00203 return $note; 00204 } 00205 00206 # Obsolete? Isn't called from anywhere and $mlink isn't defined 00207 function rcLimitLinks( $page="Recentchanges", $more="", $doall = false ) 00208 { 00209 if ($more != "") $more .= "&"; 00210 $cl = rcCountLink( 50, 0, $page, $more ) . " | " . 00211 rcCountLink( 100, 0, $page, $more ) . " | " . 00212 rcCountLink( 250, 0, $page, $more ) . " | " . 00213 rcCountLink( 500, 0, $page, $more ) . 00214 ( $doall ? ( " | " . rcCountLink( 0, $days, $page, $more ) ) : "" ); 00215 $note = wfMsg( "rclinks", $cl, "", $mlink ); 00216 return $note; 00217 } 00218 00219 ?>