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