* (bug 7405) Make Linker methods static. Patch by Dan Li.
[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
27 # Validate the title
28 $nt = Title::newFromURL( $target );
29 if( !is_object( $nt ) ) {
30 $wgOut->errorPage( 'notargettitle', 'notargettext' );
31 return;
32 }
33
34 # Check for existence
35 # Do a quiet redirect back to the page itself if it doesn't
36 if( !$nt->exists() ) {
37 $wgOut->redirect( $nt->getLocalUrl() );
38 return;
39 }
40
41 $id = $nt->getArticleId();
42
43 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
44
45 if ( ! $days ) {
46 $days = $wgUser->getOption( 'rcdays' );
47 if ( ! $days ) { $days = 7; }
48 }
49 $days = (int)$days;
50 list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
51
52 $dbr =& wfGetDB( DB_SLAVE );
53 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
54
55 $hideminor = ($hideminor ? 1 : 0);
56 if ( $hideminor ) {
57 $mlink = Linker::makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
58 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
59 "&days={$days}&limit={$limit}&hideminor=0" );
60 } else {
61 $mlink = Linker::makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
62 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
63 "&days={$days}&limit={$limit}&hideminor=1" );
64 }
65 if ( $hideminor ) {
66 $cmq = 'AND rc_minor=0';
67 } else { $cmq = ''; }
68
69 extract( $dbr->tableNames( 'recentchanges', 'categorylinks', 'pagelinks', 'revision', 'page' , "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
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 " . ($uid ? ",wl_user" : "") . "
101 FROM $categorylinks, $recentchanges
102 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
103 WHERE rc_timestamp > '{$cutoff}'
104 {$cmq}
105 AND cl_from=rc_cur_id
106 AND cl_to=$catkey
107 $GROUPBY
108 ";
109 } else {
110 $sql =
111 "SELECT /* wfSpecialRecentchangeslinked */
112 rc_id,
113 rc_cur_id,
114 rc_namespace,
115 rc_title,
116 rc_user,
117 rc_comment,
118 rc_user_text,
119 rc_this_oldid,
120 rc_last_oldid,
121 rc_timestamp,
122 rc_minor,
123 rc_bot,
124 rc_new,
125 rc_patrolled,
126 rc_type
127 " . ($uid ? ",wl_user" : "") . "
128 FROM $pagelinks, $recentchanges
129 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
130 WHERE rc_timestamp > '{$cutoff}'
131 {$cmq}
132 AND pl_namespace=rc_namespace
133 AND pl_title=rc_title
134 AND pl_from=$id
135 $GROUPBY
136 ";
137 }
138 $res = $dbr->query( $sql, $fname );
139
140 $wgOut->addHTML("&lt; ".Linker::makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
141 $note = wfMsg( "rcnote", $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
142 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
143
144 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
145 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
146 false, $mlink );
147
148 $wgOut->addHTML( $note."\n" );
149
150 $list = ChangesList::newFromUser( $wgUser );
151 $s = $list->beginRecentChangesList();
152 $count = $dbr->numRows( $res );
153
154 $counter = 1;
155 while ( $limit ) {
156 if ( 0 == $count ) { break; }
157 $obj = $dbr->fetchObject( $res );
158 --$count;
159 $rc = RecentChange::newFromRow( $obj );
160 $rc->counter = $counter++;
161 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
162 --$limit;
163 }
164 $s .= $list->endRecentChangesList();
165
166 $dbr->freeResult( $res );
167 $wgOut->addHTML( $s );
168 }
169
170 ?>