Refactored parser output handling slightly, and added a hook function, to allow exten...
[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 extract( $dbr->tableNames( 'recentchanges', 'categorylinks', 'pagelinks', 'revision', 'page' , "watchlist" ) );
71
72 $uid = $wgUser->getID();
73
74 $GROUPBY = "
75 GROUP BY rc_cur_id,rc_namespace,rc_title,
76 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
77 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type
78 " . ($uid ? ",wl_user" : "") . "
79 ORDER BY rc_timestamp DESC
80 LIMIT {$limit}";
81
82 // If target is a Category, use categorylinks and invert from and to
83 if( $nt->getNamespace() == NS_CATEGORY ) {
84 $catkey = $dbr->addQuotes( $nt->getDBKey() );
85 $sql = "SELECT /* wfSpecialRecentchangeslinked */
86 rc_id,
87 rc_cur_id,
88 rc_namespace,
89 rc_title,
90 rc_this_oldid,
91 rc_last_oldid,
92 rc_user,
93 rc_comment,
94 rc_user_text,
95 rc_timestamp,
96 rc_minor,
97 rc_bot,
98 rc_new,
99 rc_patrolled,
100 rc_type
101 " . ($uid ? ",wl_user" : "") . "
102 FROM $categorylinks, $recentchanges
103 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
104 WHERE rc_timestamp > '{$cutoff}'
105 {$cmq}
106 AND cl_from=rc_cur_id
107 AND cl_to=$catkey
108 $GROUPBY
109 ";
110 } else {
111 $sql =
112 "SELECT /* wfSpecialRecentchangeslinked */
113 rc_id,
114 rc_cur_id,
115 rc_namespace,
116 rc_title,
117 rc_user,
118 rc_comment,
119 rc_user_text,
120 rc_this_oldid,
121 rc_last_oldid,
122 rc_timestamp,
123 rc_minor,
124 rc_bot,
125 rc_new,
126 rc_patrolled,
127 rc_type
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->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
142 $note = wfMsg( "rcnote", $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 $counter = 1;
156 while ( $limit ) {
157 if ( 0 == $count ) { break; }
158 $obj = $dbr->fetchObject( $res );
159 --$count;
160 $rc = RecentChange::newFromRow( $obj );
161 $rc->counter = $counter++;
162 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
163 --$limit;
164 }
165 $s .= $list->endRecentChangesList();
166
167 $dbr->freeResult( $res );
168 $wgOut->addHTML( $s );
169 }
170
171 ?>