Revert most of r18268 (only kept the empty <tr> removal)
[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 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( 'SpecialRecentchanges.php' );
12
13 /**
14 * Entrypoint
15 * @param string $par parent page we will look at
16 */
17 function wfSpecialRecentchangeslinked( $par = NULL ) {
18 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
19 $fname = 'wfSpecialRecentchangeslinked';
20
21 $days = $wgRequest->getInt( 'days' );
22 $target = isset($par) ? $par : $wgRequest->getText( 'target' );
23 $hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
24
25 $wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
26 $sk = $wgUser->getSkin();
27
28 # Validate the title
29 $nt = Title::newFromURL( $target );
30 if( !is_object( $nt ) ) {
31 $wgOut->errorPage( 'notargettitle', 'notargettext' );
32 return;
33 }
34
35 # Check for existence
36 # Do a quiet redirect back to the page itself if it doesn't
37 if( !$nt->exists() ) {
38 $wgOut->redirect( $nt->getLocalUrl() );
39 return;
40 }
41
42 $id = $nt->getArticleId();
43
44 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
45
46 if ( ! $days ) {
47 $days = $wgUser->getOption( 'rcdays' );
48 if ( ! $days ) { $days = 7; }
49 }
50 $days = (int)$days;
51 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
52
53 $dbr =& wfGetDB( DB_SLAVE );
54 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
55
56 $hideminor = ($hideminor ? 1 : 0);
57 if ( $hideminor ) {
58 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
59 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
60 "&days={$days}&limit={$limit}&hideminor=0" );
61 } else {
62 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
63 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
64 "&days={$days}&limit={$limit}&hideminor=1" );
65 }
66 if ( $hideminor ) {
67 $cmq = 'AND rc_minor=0';
68 } else { $cmq = ''; }
69
70 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
71 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
72
73 $uid = $wgUser->getID();
74
75 $GROUPBY = "
76 GROUP BY rc_cur_id,rc_namespace,rc_title,
77 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
78 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type
79 " . ($uid ? ",wl_user" : "") . "
80 ORDER BY rc_timestamp DESC
81 LIMIT {$limit}";
82
83 // If target is a Category, use categorylinks and invert from and to
84 if( $nt->getNamespace() == NS_CATEGORY ) {
85 $catkey = $dbr->addQuotes( $nt->getDBKey() );
86 $sql = "SELECT /* wfSpecialRecentchangeslinked */
87 rc_id,
88 rc_cur_id,
89 rc_namespace,
90 rc_title,
91 rc_this_oldid,
92 rc_last_oldid,
93 rc_user,
94 rc_comment,
95 rc_user_text,
96 rc_timestamp,
97 rc_minor,
98 rc_bot,
99 rc_new,
100 rc_patrolled,
101 rc_type,
102 rc_old_len,
103 rc_new_len
104 " . ($uid ? ",wl_user" : "") . "
105 FROM $categorylinks, $recentchanges
106 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
107 WHERE rc_timestamp > '{$cutoff}'
108 {$cmq}
109 AND cl_from=rc_cur_id
110 AND cl_to=$catkey
111 $GROUPBY
112 ";
113 } else {
114 $sql =
115 "SELECT /* wfSpecialRecentchangeslinked */
116 rc_id,
117 rc_cur_id,
118 rc_namespace,
119 rc_title,
120 rc_user,
121 rc_comment,
122 rc_user_text,
123 rc_this_oldid,
124 rc_last_oldid,
125 rc_timestamp,
126 rc_minor,
127 rc_bot,
128 rc_new,
129 rc_patrolled,
130 rc_type,
131 rc_old_len,
132 rc_new_len
133 " . ($uid ? ",wl_user" : "") . "
134 FROM $pagelinks, $recentchanges
135 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
136 WHERE rc_timestamp > '{$cutoff}'
137 {$cmq}
138 AND pl_namespace=rc_namespace
139 AND pl_title=rc_title
140 AND pl_from=$id
141 $GROUPBY
142 ";
143 }
144 $res = $dbr->query( $sql, $fname );
145
146 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
147 $note = wfMsg( "rcnote", $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
148 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
149
150 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
151 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
152 false, $mlink );
153
154 $wgOut->addHTML( $note."\n" );
155
156 $list = ChangesList::newFromUser( $wgUser );
157 $s = $list->beginRecentChangesList();
158 $count = $dbr->numRows( $res );
159
160 $counter = 1;
161 while ( $limit ) {
162 if ( 0 == $count ) { break; }
163 $obj = $dbr->fetchObject( $res );
164 --$count;
165 $rc = RecentChange::newFromRow( $obj );
166 $rc->counter = $counter++;
167 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
168 --$limit;
169 }
170 $s .= $list->endRecentChangesList();
171
172 $dbr->freeResult( $res );
173 $wgOut->addHTML( $s );
174 }
175
176 ?>