recentchanges based recentchanges linked
[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, $wgTitle, $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 if (is_null($target)) {
29 $wgOut->errorpage( 'notargettitle', 'notargettext' );
30 return;
31 }
32 $nt = Title::newFromURL( $target );
33 if( !$nt ) {
34 $wgOut->errorpage( 'notargettitle', 'notargettext' );
35 return;
36 }
37 $id = $nt->getArticleId();
38
39 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
40
41 if ( ! $days ) {
42 $days = $wgUser->getOption( 'rcdays' );
43 if ( ! $days ) { $days = 7; }
44 }
45 $days = (int)$days;
46 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
47
48 $dbr =& wfGetDB( DB_SLAVE );
49 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
50
51 $hideminor = ($hideminor ? 1 : 0);
52 if ( $hideminor ) {
53 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
54 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
55 "&days={$days}&limit={$limit}&hideminor=0" );
56 } else {
57 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
58 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
59 "&days={$days}&limit={$limit}&hideminor=1" );
60 }
61 if ( $hideminor ) {
62 $cmq = 'AND rev_minor_edit=0';
63 } else { $cmq = ''; }
64
65 extract( $dbr->tableNames( 'recentchanges', 'categorylinks', 'pagelinks', 'revision', 'page' ) );
66
67 // If target is a Category, use categorylinks and invert from and to
68 if( $nt->getNamespace() == NS_CATEGORY ) {
69 $catkey = $dbr->addQuotes( $nt->getDBKey() );
70 $sql =
71 "SELECT page_id,page_namespace,page_title,rev_id,rev_user,rev_comment,
72 rev_user_text,rev_timestamp,rev_minor_edit,
73 page_is_new
74 FROM $categorylinks, $revision, $page
75 WHERE rev_timestamp > '{$cutoff}' AND page_touched > '{$cutoff}'
76 {$cmq}
77 AND rev_page=page_id
78 AND cl_from=page_id
79 AND cl_to=$catkey
80 GROUP BY page_id,page_namespace,page_title,
81 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
82 page_is_new
83 ORDER BY rev_timestamp DESC
84 LIMIT {$limit}";
85 } else {
86 $sql =
87 "SELECT /* wfSpecialRecentchangeslinked */
88 rc_cur_id page_id,
89 rc_namespace page_namespace,
90 rc_title page_title,
91 rc_user rev_user,
92 rc_comment rev_comment,
93 rc_user_text rev_user_text,
94 rc_this_oldid,
95 rc_timestamp rev_timestamp,
96 rc_minor rev_minor_edit,
97 rc_new page_is_new
98 FROM $pagelinks, $recentchanges
99 WHERE rc_timestamp > '{$cutoff}'
100 {$cmq}
101 AND pl_namespace=rc_namespace
102 AND pl_title=rc_title
103 AND pl_from=$id
104 GROUP BY page_id,page_namespace,page_title,
105 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
106 page_is_new
107 ORDER BY rev_timestamp DESC
108 LIMIT {$limit}";
109 }
110 $res = $dbr->query( $sql, $fname );
111
112 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
113 $note = wfMsg( "rcnote", $limit, $days );
114 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
115
116 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
117 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
118 false, $mlink );
119
120 $wgOut->addHTML( $note."\n" );
121
122 $list = ChangesList::newFromUser( $wgUser );
123 $s = $list->beginRecentChangesList();
124 $count = $dbr->numRows( $res );
125
126 $counter = 1;
127 while ( $limit ) {
128 if ( 0 == $count ) { break; }
129 $obj = $dbr->fetchObject( $res );
130 --$count;
131
132 $rc = RecentChange::newFromCurRow( $obj );
133 $rc->counter = $counter++;
134 $s .= $list->recentChangesLine( $rc );
135 --$limit;
136 }
137 $s .= $list->endRecentChangesList();
138
139 $dbr->freeResult( $res );
140 $wgOut->addHTML( $s );
141 }
142
143 ?>