* (bug 6072) Add a 'border' keyword to the image syntax
[mediawiki.git] / includes / SpecialRecentchangeslinked.php
blob14508d3a8b6c43559303aaef3b064c57fb19a1a3
1 <?php
2 /**
3 * This is to display changes made to all articles linked in an article.
4 * @addtogroup SpecialPage
5 */
7 /**
9 */
10 require_once( 'SpecialRecentchanges.php' );
12 /**
13 * Entrypoint
14 * @param string $par parent page we will look at
16 function wfSpecialRecentchangeslinked( $par = NULL ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
18 $fname = 'wfSpecialRecentchangeslinked';
20 $days = $wgRequest->getInt( 'days' );
21 $target = isset($par) ? $par : $wgRequest->getText( 'target' );
22 $hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
24 $wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
25 $sk = $wgUser->getSkin();
27 if (is_null($target)) {
28 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 return;
31 $nt = Title::newFromURL( $target );
32 if( !$nt ) {
33 $wgOut->errorpage( 'notargettitle', 'notargettext' );
34 return;
36 $id = $nt->getArticleId();
38 $wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
40 if ( ! $days ) {
41 $days = (int)$wgUser->getOption( 'rcdays', 7 );
43 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
45 $dbr = wfGetDB( DB_SLAVE,'recentchangeslinked' );
46 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
48 $hideminor = ($hideminor ? 1 : 0);
49 if ( $hideminor ) {
50 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
51 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
52 "&days={$days}&limit={$limit}&hideminor=0" );
53 } else {
54 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
55 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
56 "&days={$days}&limit={$limit}&hideminor=1" );
58 if ( $hideminor ) {
59 $cmq = 'AND rc_minor=0';
60 } else { $cmq = ''; }
62 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
63 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
65 $uid = $wgUser->getID();
67 $GROUPBY = "
68 GROUP BY rc_cur_id,rc_namespace,rc_title,
69 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_deleted,
70 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
71 " . ($uid ? ",wl_user" : "") . "
72 ORDER BY rc_timestamp DESC
73 LIMIT {$limit}";
75 // If target is a Category, use categorylinks and invert from and to
76 if( $nt->getNamespace() == NS_CATEGORY ) {
77 $catkey = $dbr->addQuotes( $nt->getDBKey() );
78 $sql = "SELECT /* wfSpecialRecentchangeslinked */
79 rc_id,
80 rc_cur_id,
81 rc_namespace,
82 rc_title,
83 rc_this_oldid,
84 rc_last_oldid,
85 rc_user,
86 rc_comment,
87 rc_user_text,
88 rc_timestamp,
89 rc_minor,
90 rc_bot,
91 rc_new,
92 rc_patrolled,
93 rc_type,
94 rc_old_len,
95 rc_new_len,
96 rc_deleted
97 " . ($uid ? ",wl_user" : "") . "
98 FROM $categorylinks, $recentchanges
99 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
100 WHERE rc_timestamp > '{$cutoff}'
101 {$cmq}
102 AND cl_from=rc_cur_id
103 AND cl_to=$catkey
104 $GROUPBY
106 } else {
107 $sql =
108 "SELECT /* wfSpecialRecentchangeslinked */
109 rc_id,
110 rc_cur_id,
111 rc_namespace,
112 rc_title,
113 rc_user,
114 rc_comment,
115 rc_user_text,
116 rc_this_oldid,
117 rc_last_oldid,
118 rc_timestamp,
119 rc_minor,
120 rc_bot,
121 rc_new,
122 rc_patrolled,
123 rc_type,
124 rc_old_len,
125 rc_new_len,
126 rc_deleted
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
138 $res = $dbr->query( $sql, $fname );
140 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
141 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
142 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
144 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
145 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
146 false, $mlink );
148 $wgOut->addHTML( $note."\n" );
150 $list = ChangesList::newFromUser( $wgUser );
151 $s = $list->beginRecentChangesList();
152 $count = $dbr->numRows( $res );
154 if ( $count ) {
155 $counter = 1;
156 while ( $limit ) {
157 if ( 0 == $count ) { break; }
158 $obj = $dbr->fetchObject( $res );
159 --$count;
160 $rc = RecentChange::newFromRow( $obj );
161 $rc->counter = $counter++;
162 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
163 --$limit;
165 } else {
166 $wgOut->addWikiText( wfMsg('recentchangeslinked-noresult') );
168 $s .= $list->endRecentChangesList();
170 $dbr->freeResult( $res );
171 $wgOut->addHTML( $s );