Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[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 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 require_once( 'SpecialRecentchanges.php' );
11
12 /**
13 * Entrypoint
14 * @param string $par parent page we will look at
15 */
16 function wfSpecialRecentchangeslinked( $par = NULL ) {
17 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
18 $fname = 'wfSpecialRecentchangeslinked';
19
20 $days = $wgRequest->getInt( 'days' );
21 $target = isset($par) ? $par : $wgRequest->getText( 'target' );
22 $hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
23
24 $wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
25 $sk = $wgUser->getSkin();
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 = (int)$wgUser->getOption( 'rcdays', 7 );
47 }
48 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
49
50 $dbr =& wfGetDB( DB_SLAVE );
51 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
52
53 $hideminor = ($hideminor ? 1 : 0);
54 if ( $hideminor ) {
55 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
56 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
57 "&days={$days}&limit={$limit}&hideminor=0" );
58 } else {
59 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
60 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
61 "&days={$days}&limit={$limit}&hideminor=1" );
62 }
63 if ( $hideminor ) {
64 $cmq = 'AND rc_minor=0';
65 } else { $cmq = ''; }
66
67 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
68 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
69
70 $uid = $wgUser->getID();
71
72 $GROUPBY = "
73 GROUP BY rc_cur_id,rc_namespace,rc_title,
74 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
75 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
76 " . ($uid ? ",wl_user" : "") . "
77 ORDER BY rc_timestamp DESC
78 LIMIT {$limit}";
79
80 // If target is a Category, use categorylinks and invert from and to
81 if( $nt->getNamespace() == NS_CATEGORY ) {
82 $catkey = $dbr->addQuotes( $nt->getDBKey() );
83 $sql = "SELECT /* wfSpecialRecentchangeslinked */
84 rc_id,
85 rc_cur_id,
86 rc_namespace,
87 rc_title,
88 rc_this_oldid,
89 rc_last_oldid,
90 rc_user,
91 rc_comment,
92 rc_user_text,
93 rc_timestamp,
94 rc_minor,
95 rc_bot,
96 rc_new,
97 rc_patrolled,
98 rc_type,
99 rc_old_len,
100 rc_new_len
101 " . ($uid ? ",wl_user" : "") . "
102 FROM $categorylinks, $recentchanges
103 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
104 WHERE rc_timestamp > '{$cutoff}'
105 {$cmq}
106 AND cl_from=rc_cur_id
107 AND cl_to=$catkey
108 $GROUPBY
109 ";
110 } else {
111 $sql =
112 "SELECT /* wfSpecialRecentchangeslinked */
113 rc_id,
114 rc_cur_id,
115 rc_namespace,
116 rc_title,
117 rc_user,
118 rc_comment,
119 rc_user_text,
120 rc_this_oldid,
121 rc_last_oldid,
122 rc_timestamp,
123 rc_minor,
124 rc_bot,
125 rc_new,
126 rc_patrolled,
127 rc_type,
128 rc_old_len,
129 rc_new_len
130 " . ($uid ? ",wl_user" : "") . "
131 FROM $pagelinks, $recentchanges
132 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
133 WHERE rc_timestamp > '{$cutoff}'
134 {$cmq}
135 AND pl_namespace=rc_namespace
136 AND pl_title=rc_title
137 AND pl_from=$id
138 $GROUPBY
139 ";
140 }
141 $res = $dbr->query( $sql, $fname );
142
143 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
144 $note = wfMsg( "rcnote", $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
145 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
146
147 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
148 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
149 false, $mlink );
150
151 $wgOut->addHTML( $note."\n" );
152
153 $list = ChangesList::newFromUser( $wgUser );
154 $s = $list->beginRecentChangesList();
155 $count = $dbr->numRows( $res );
156
157 $counter = 1;
158 while ( $limit ) {
159 if ( 0 == $count ) { break; }
160 $obj = $dbr->fetchObject( $res );
161 --$count;
162 $rc = RecentChange::newFromRow( $obj );
163 $rc->counter = $counter++;
164 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
165 --$limit;
166 }
167 $s .= $list->endRecentChangesList();
168
169 $dbr->freeResult( $res );
170 $wgOut->addHTML( $s );
171 }
172
173 ?>