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