Fix for bug 13004, in which the Postgres full-text search has too many results,
[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, $wgTitle;
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 if (is_null($target)) {
28 $wgOut->errorpage( 'notargettitle', 'notargettext' );
29 return;
30 }
31 $nt = Title::newFromURL( $target );
32 if( !$nt ) {
33 $wgOut->errorpage( 'notargettitle', 'notargettext' );
34 return;
35 }
36 $id = $nt->getArticleId();
37
38 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $nt->getPrefixedText() ) );
39 $wgOut->setSyndicated();
40 $wgOut->setFeedAppendQuery( "target=" . urlencode( $target ) );
41
42 if ( ! $days ) {
43 $days = (int)$wgUser->getOption( 'rcdays', 7 );
44 }
45 list( $limit, /* offset */ ) = wfCheckLimits( 100, 'rclimit' );
46
47 $dbr = wfGetDB( DB_SLAVE,'recentchangeslinked' );
48 $cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
49
50 $hideminor = ($hideminor ? 1 : 0);
51 if ( $hideminor ) {
52 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
53 wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
54 "&days={$days}&limit={$limit}&hideminor=0" );
55 } else {
56 $mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
57 wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
58 "&days={$days}&limit={$limit}&hideminor=1" );
59 }
60 if ( $hideminor ) {
61 $cmq = 'AND rc_minor=0';
62 } else { $cmq = ''; }
63
64 list($recentchanges, $categorylinks, $pagelinks, $watchlist) =
65 $dbr->tableNamesN( 'recentchanges', 'categorylinks', 'pagelinks', "watchlist" );
66
67 $uid = $wgUser->getID();
68
69 $GROUPBY = "
70 GROUP BY rc_cur_id,rc_namespace,rc_title,
71 rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,rc_deleted,
72 rc_new, rc_id, rc_this_oldid, rc_last_oldid, rc_bot, rc_patrolled, rc_type, rc_old_len, rc_new_len
73 " . ($uid ? ",wl_user" : "") . "
74 ORDER BY rc_timestamp DESC
75 LIMIT {$limit}";
76
77 // If target is a Category, use categorylinks and invert from and to
78 if( $nt->getNamespace() == NS_CATEGORY ) {
79 $catkey = $dbr->addQuotes( $nt->getDBkey() );
80 $sql = "SELECT /* wfSpecialRecentchangeslinked */
81 rc_id,
82 rc_cur_id,
83 rc_namespace,
84 rc_title,
85 rc_this_oldid,
86 rc_last_oldid,
87 rc_user,
88 rc_comment,
89 rc_user_text,
90 rc_timestamp,
91 rc_minor,
92 rc_bot,
93 rc_new,
94 rc_patrolled,
95 rc_type,
96 rc_old_len,
97 rc_new_len,
98 rc_deleted
99 " . ($uid ? ",wl_user" : "") . "
100 FROM $categorylinks, $recentchanges
101 " . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
102 WHERE rc_timestamp > '{$cutoff}'
103 {$cmq}
104 AND cl_from=rc_cur_id
105 AND cl_to=$catkey
106 $GROUPBY
107 ";
108 } else {
109 $sql =
110 "SELECT /* wfSpecialRecentchangeslinked */
111 rc_id,
112 rc_cur_id,
113 rc_namespace,
114 rc_title,
115 rc_user,
116 rc_comment,
117 rc_user_text,
118 rc_this_oldid,
119 rc_last_oldid,
120 rc_timestamp,
121 rc_minor,
122 rc_bot,
123 rc_new,
124 rc_patrolled,
125 rc_type,
126 rc_old_len,
127 rc_new_len,
128 rc_deleted
129 " . ($uid ? ",wl_user" : "") . "
130 FROM $pagelinks, $recentchanges
131 " . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
132 WHERE rc_timestamp > '{$cutoff}'
133 {$cmq}
134 AND pl_namespace=rc_namespace
135 AND pl_title=rc_title
136 AND pl_from=$id
137 $GROUPBY
138 ";
139 }
140 $res = $dbr->query( $sql, $fname );
141
142 $wgOut->addHTML("&lt; ".$sk->makeLinkObj($nt, "", "redirect=no" )."<br />\n");
143 $note = wfMsgExt( "rcnote", array ( 'parseinline' ), $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
144 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
145
146 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
147 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
148 false, $mlink );
149
150 $wgOut->addHTML( $note."\n" );
151
152 $list = ChangesList::newFromUser( $wgUser );
153 $s = $list->beginRecentChangesList();
154 $count = $dbr->numRows( $res );
155
156 $rchanges = array();
157 if ( $count ) {
158 $counter = 1;
159 while ( $limit ) {
160 if ( 0 == $count ) { break; }
161 $obj = $dbr->fetchObject( $res );
162 --$count;
163 $rc = RecentChange::newFromRow( $obj );
164 $rc->counter = $counter++;
165 $s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
166 --$limit;
167 $rchanges[] = $obj;
168 }
169 } else {
170 $wgOut->addWikiText( wfMsg('recentchangeslinked-noresult') );
171 }
172 $s .= $list->endRecentChangesList();
173
174 $dbr->freeResult( $res );
175 $wgOut->addHTML( $s );
176
177 global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
178 $feedFormat = $wgRequest->getVal( 'feed' );
179 if( $feedFormat && isset( $wgFeedClasses[$feedFormat] ) ) {
180 $feedTitle = $wgSitename . ' - ' . wfMsgForContent( 'recentchangeslinked-title', $nt->getPrefixedText() ) . ' [' . $wgContLanguageCode . ']';
181 $feed = new $wgFeedClasses[$feedFormat]( $feedTitle,
182 htmlspecialchars( wfMsgForContent('recentchangeslinked') ), $wgTitle->getFullUrl() );
183
184 require_once( "SpecialRecentchanges.php" );
185 $wgOut->disable();
186 rcDoOutputFeed( $rchanges, $feed );
187 }
188 }
189
190