d4136679e4d80386ef252804f847c3f6a85cf454
[lhc/web/wiklou.git] / includes / SpecialRecentchangeslinked.php
1 <?php
2 /**
3 * This is to display changes made to all articles linked in an article.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 require_once( 'SpecialRecentchanges.php' );
11
12 /**
13 * Entrypoint
14 * @param string $par parent page we will look at
15 */
16 function wfSpecialRecentchangeslinked( $par = NULL ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
18 $fname = 'wfSpecialRecentchangeslinked';
19
20 $days = $wgRequest->getInt( 'days' );
21 $target = isset($par) ? $par : $wgRequest->getText( 'target' );
22 $hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
23
24 $wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
25 $sk = $wgUser->getSkin();
26
27 if (is_null($target)) {
28 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 return;
30 }
31 $nt = Title::newFromURL( $target );
32 if( !$nt ) {
33 $wgOut->errorpage( 'notargettitle', 'notargettext' );
34 return;
35 }
36 $id = $nt->getArticleId();
37
38 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $nt->getPrefixedText() ) );
39 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
40
41 if ( ! $days ) {
42 $days = (int)$wgUser->getOption( 'rcdays', 7 );
43 }
44 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
45
46 $dbr = wfGetDB( DB_SLAVE,'recentchangeslinked' );
47 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
48
49 $hideminor = ($hideminor ? 1 : 0);
50 if ( $hideminor ) {
51 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
52 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
53 "&days={$days}&limit={$limit}&hideminor=0" );
54 } else {
55 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
56 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
57 "&days={$days}&limit={$limit}&hideminor=1" );
58 }
59 if ( $hideminor ) {
60 $cmq = 'AND rc_minor=0';
61 } else { $cmq = ''; }
62
63 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
64 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
65
66 $uid = $wgUser->getID();
67
68 $GROUPBY = "
69 GROUP BY rc_cur_id,rc_namespace,rc_title,
70 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_deleted,
71 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
72 " . ($uid ? ",wl_user" : "") . "
73 ORDER BY rc_timestamp DESC
74 LIMIT {$limit}";
75
76 // If target is a Category, use categorylinks and invert from and to
77 if( $nt->getNamespace() == NS_CATEGORY ) {
78 $catkey = $dbr->addQuotes( $nt->getDBKey() );
79 $sql = "SELECT /* wfSpecialRecentchangeslinked */
80 rc_id,
81 rc_cur_id,
82 rc_namespace,
83 rc_title,
84 rc_this_oldid,
85 rc_last_oldid,
86 rc_user,
87 rc_comment,
88 rc_user_text,
89 rc_timestamp,
90 rc_minor,
91 rc_bot,
92 rc_new,
93 rc_patrolled,
94 rc_type,
95 rc_old_len,
96 rc_new_len,
97 rc_deleted
98 " . ($uid ? ",wl_user" : "") . "
99 FROM $categorylinks, $recentchanges
100 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
101 WHERE rc_timestamp > '{$cutoff}'
102 {$cmq}
103 AND cl_from=rc_cur_id
104 AND cl_to=$catkey
105 $GROUPBY
106 ";
107 } else {
108 $sql =
109 "SELECT /* wfSpecialRecentchangeslinked */
110 rc_id,
111 rc_cur_id,
112 rc_namespace,
113 rc_title,
114 rc_user,
115 rc_comment,
116 rc_user_text,
117 rc_this_oldid,
118 rc_last_oldid,
119 rc_timestamp,
120 rc_minor,
121 rc_bot,
122 rc_new,
123 rc_patrolled,
124 rc_type,
125 rc_old_len,
126 rc_new_len,
127 rc_deleted
128 " . ($uid ? ",wl_user" : "") . "
129 FROM $pagelinks, $recentchanges
130 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
131 WHERE rc_timestamp > '{$cutoff}'
132 {$cmq}
133 AND pl_namespace=rc_namespace
134 AND pl_title=rc_title
135 AND pl_from=$id
136 $GROUPBY
137 ";
138 }
139 $res = $dbr->query( $sql, $fname );
140
141 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
142 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
143 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
144
145 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
146 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
147 false, $mlink );
148
149 $wgOut->addHTML( $note."\n" );
150
151 $list = ChangesList::newFromUser( $wgUser );
152 $s = $list->beginRecentChangesList();
153 $count = $dbr->numRows( $res );
154
155 $rchanges = array();
156 if ( $count ) {
157 $counter = 1;
158 while ( $limit ) {
159 if ( 0 == $count ) { break; }
160 $obj = $dbr->fetchObject( $res );
161 --$count;
162 $rc = RecentChange::newFromRow( $obj );
163 $rc->counter = $counter++;
164 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
165 --$limit;
166 $rchanges[] = $rc;
167 }
168 } else {
169 $wgOut->addWikiText( wfMsg('recentchangeslinked-noresult') );
170 }
171 $s .= $list->endRecentChangesList();
172
173 $dbr->freeResult( $res );
174 $wgOut->addHTML( $s );
175
176 global $wgSitename, $wgFeedClasses, $wgTitle, $wgContLanguageCode;
177 $feedFormat = $wgRequest->getVal( 'feed' );
178 if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
179 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) . ' [' . $wgContLanguageCode . ']';
180 $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
181 htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
182
183 $feedItems = array();
184 foreach( $rchanges as $rc ) {
185 $title = $rc->getTitle();
186 $titleStr = $title->getFullText();
187 $titleUrl = $title->getFullUrl();
188 $timestamp = $rc->getAttribute('rc_timestamp');
189 $user = $rc->getAttribute('rc_user_text');
190 $comment = $rc->getAttribute('rc_comment');
191 $message = ( $comment ? 'recentchangeslinked-feed-entry-comment' : 'recentchangeslinked-feed-entry' );
192 $content = wfMsgHtml( $message, $user, $titleStr, $comment );
193
194 $feedItems[] = new FeedItem( $titleStr, $content, $titleUrl, $timestamp, $user );
195 }
196
197 $wgOut->disable();
198 $feed->outHeader();
199 foreach( $feedItems as &$item ) {
200 $feed->outItem( $item );
201 }
202 $feed->outFooter();
203 }
204 }
205
206