15292898a650c1565023c541bbe037714a04089e
[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 = (int)$wgUser->getOption( 'rcdays', 7 );
48 }
49 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
50
51 $dbr =& wfGetDB( DB_SLAVE );
52 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
53
54 $hideminor = ($hideminor ? 1 : 0);
55 if ( $hideminor ) {
56 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
57 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
58 "&days={$days}&limit={$limit}&hideminor=0" );
59 } else {
60 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
61 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
62 "&days={$days}&limit={$limit}&hideminor=1" );
63 }
64 if ( $hideminor ) {
65 $cmq = 'AND rc_minor=0';
66 } else { $cmq = ''; }
67
68 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
69 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
70
71 $uid = $wgUser->getID();
72
73 $GROUPBY = "
74 GROUP BY rc_cur_id,rc_namespace,rc_title,
75 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
76 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
77 " . ($uid ? ",wl_user" : "") . "
78 ORDER BY rc_timestamp DESC
79 LIMIT {$limit}";
80
81 // If target is a Category, use categorylinks and invert from and to
82 if( $nt->getNamespace() == NS_CATEGORY ) {
83 $catkey = $dbr->addQuotes( $nt->getDBKey() );
84 $sql = "SELECT /* wfSpecialRecentchangeslinked */
85 rc_id,
86 rc_cur_id,
87 rc_namespace,
88 rc_title,
89 rc_this_oldid,
90 rc_last_oldid,
91 rc_user,
92 rc_comment,
93 rc_user_text,
94 rc_timestamp,
95 rc_minor,
96 rc_bot,
97 rc_new,
98 rc_patrolled,
99 rc_type,
100 rc_old_len,
101 rc_new_len
102 " . ($uid ? ",wl_user" : "") . "
103 FROM $categorylinks, $recentchanges
104 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
105 WHERE rc_timestamp > '{$cutoff}'
106 {$cmq}
107 AND cl_from=rc_cur_id
108 AND cl_to=$catkey
109 $GROUPBY
110 ";
111 } else {
112 $sql =
113 "SELECT /* wfSpecialRecentchangeslinked */
114 rc_id,
115 rc_cur_id,
116 rc_namespace,
117 rc_title,
118 rc_user,
119 rc_comment,
120 rc_user_text,
121 rc_this_oldid,
122 rc_last_oldid,
123 rc_timestamp,
124 rc_minor,
125 rc_bot,
126 rc_new,
127 rc_patrolled,
128 rc_type,
129 rc_old_len,
130 rc_new_len
131 " . ($uid ? ",wl_user" : "") . "
132 FROM $pagelinks, $recentchanges
133 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
134 WHERE rc_timestamp > '{$cutoff}'
135 {$cmq}
136 AND pl_namespace=rc_namespace
137 AND pl_title=rc_title
138 AND pl_from=$id
139 $GROUPBY
140 ";
141 }
142 $res = $dbr->query( $sql, $fname );
143
144 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
145 $note = wfMsg( "rcnote", $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
146 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
147
148 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
149 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
150 false, $mlink );
151
152 $wgOut->addHTML( $note."\n" );
153
154 $list = ChangesList::newFromUser( $wgUser );
155 $s = $list->beginRecentChangesList();
156 $count = $dbr->numRows( $res );
157
158 $counter = 1;
159 while ( $limit ) {
160 if ( 0 == $count ) { break; }
161 $obj = $dbr->fetchObject( $res );
162 --$count;
163 $rc = RecentChange::newFromRow( $obj );
164 $rc->counter = $counter++;
165 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
166 --$limit;
167 }
168 $s .= $list->endRecentChangesList();
169
170 $dbr->freeResult( $res );
171 $wgOut->addHTML( $s );
172 }
173
174 ?>