Prevent registration/login with the username "MediaWiki default"
[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' , "watchlist" ) );
66
67 $uid = $wgUser->getID();
68
69 // If target is a Category, use categorylinks and invert from and to
70 if( $nt->getNamespace() == NS_CATEGORY ) {
71 $catkey = $dbr->addQuotes( $nt->getDBKey() );
72 $sql = "SELECT /* wfSpecialRecentchangeslinked */
73 rc_id,
74 rc_cur_id,
75 rc_namespace,
76 rc_title,
77 rc_this_oldid,
78 rc_last_oldid,
79 rc_user,
80 rc_comment,
81 rc_user_text,
82 rc_timestamp,
83 rc_minor,
84 rc_new,
85 rc_patrolled,
86 rc_type
87 " . ($uid ? ",wl_user" : "") . "
88 FROM $categorylinks, $recentchanges
89 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
90 WHERE rc_timestamp > '{$cutoff}'
91 {$cmq}
92 AND cl_from=rc_cur_id
93 AND cl_to=$catkey
94 GROUP BY rc_cur_id,rc_namespace,rc_title,
95 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
96 rc_new
97 ORDER BY rc_timestamp DESC
98 LIMIT {$limit};
99 ";
100 } else {
101 $sql =
102 "SELECT /* wfSpecialRecentchangeslinked */
103 rc_id,
104 rc_cur_id,
105 rc_namespace,
106 rc_title,
107 rc_user,
108 rc_comment,
109 rc_user_text,
110 rc_this_oldid,
111 rc_last_oldid,
112 rc_timestamp,
113 rc_minor,
114 rc_new,
115 rc_patrolled,
116 rc_type
117 " . ($uid ? ",wl_user" : "") . "
118 FROM $pagelinks, $recentchanges
119 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
120 WHERE rc_timestamp > '{$cutoff}'
121 {$cmq}
122 AND pl_namespace=rc_namespace
123 AND pl_title=rc_title
124 AND pl_from=$id
125 GROUP BY rc_cur_id,rc_namespace,rc_title,
126 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
127 rc_new
128 ORDER BY rc_timestamp DESC
129 LIMIT {$limit}";
130 }
131 $res = $dbr->query( $sql, $fname );
132
133 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
134 $note = wfMsg( "rcnote", $limit, $days );
135 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
136
137 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
138 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
139 false, $mlink );
140
141 $wgOut->addHTML( $note."\n" );
142
143 $list = ChangesList::newFromUser( $wgUser );
144 $s = $list->beginRecentChangesList();
145 $count = $dbr->numRows( $res );
146
147 $counter = 1;
148 while ( $limit ) {
149 if ( 0 == $count ) { break; }
150 $obj = $dbr->fetchObject( $res );
151 --$count;
152 # print_r ( $obj ) ;
153 # print "<br/>\n" ;
154
155 $rc = RecentChange::newFromRow( $obj );
156 $rc->counter = $counter++;
157 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
158 --$limit;
159 }
160 $s .= $list->endRecentChangesList();
161
162 $dbr->freeResult( $res );
163 $wgOut->addHTML( $s );
164 }
165
166 ?>