* (bug 4059) fix 'hide minor edits' on Recentchangeslinked
[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 rc_minor=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 = "SELECT /* wfSpecialRecentchangeslinked */
71 rc_cur_id page_id,
72 rc_namespace page_namespace,
73 rc_title page_title,
74 rc_this_oldid rev_id,
75 rc_user rev_user,
76 rc_comment rev_comment,
77 rc_user_text rev_user_text,
78 rc_timestamp rev_timestamp,
79 rc_minor rev_minor_edit,
80 rc_new page_is_new
81 FROM $categorylinks, $recentchanges
82 WHERE rc_timestamp > '{$cutoff}'
83 {$cmq}
84 AND cl_from=rc_cur_id
85 AND cl_to=$catkey
86 GROUP BY page_id,page_namespace,page_title,
87 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
88 page_is_new
89 ORDER BY rev_timestamp DESC
90 LIMIT {$limit};
91 ";
92 } else {
93 $sql =
94 "SELECT /* wfSpecialRecentchangeslinked */
95 rc_cur_id page_id,
96 rc_namespace page_namespace,
97 rc_title page_title,
98 rc_user rev_user,
99 rc_comment rev_comment,
100 rc_user_text rev_user_text,
101 rc_this_oldid,
102 rc_timestamp rev_timestamp,
103 rc_minor rev_minor_edit,
104 rc_new page_is_new
105 FROM $pagelinks, $recentchanges
106 WHERE rc_timestamp > '{$cutoff}'
107 {$cmq}
108 AND pl_namespace=rc_namespace
109 AND pl_title=rc_title
110 AND pl_from=$id
111 GROUP BY page_id,page_namespace,page_title,
112 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
113 page_is_new
114 ORDER BY rev_timestamp DESC
115 LIMIT {$limit}";
116 }
117 $res = $dbr->query( $sql, $fname );
118
119 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
120 $note = wfMsg( "rcnote", $limit, $days );
121 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
122
123 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
124 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
125 false, $mlink );
126
127 $wgOut->addHTML( $note."\n" );
128
129 $list = ChangesList::newFromUser( $wgUser );
130 $s = $list->beginRecentChangesList();
131 $count = $dbr->numRows( $res );
132
133 $counter = 1;
134 while ( $limit ) {
135 if ( 0 == $count ) { break; }
136 $obj = $dbr->fetchObject( $res );
137 --$count;
138
139 $rc = RecentChange::newFromCurRow( $obj );
140 $rc->counter = $counter++;
141 $s .= $list->recentChangesLine( $rc );
142 --$limit;
143 }
144 $s .= $list->endRecentChangesList();
145
146 $dbr->freeResult( $res );
147 $wgOut->addHTML( $s );
148 }
149
150 ?>