Fix #153 path by <stehan dot walter at epfl dot ch>
[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, $wgTitle, $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( 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 rev_minor_edit=0';
63 } else { $cmq = ''; }
64
65 extract( $dbr->tableNames( 'categorylinks', 'pagelinks', 'revision', 'page' ) );
66
67 // If target is a Category, use categorylinks and invert from and to
68 if( $nt->getNamespace() == NS_CATEGORY ) {
69 $catkey = $dbr->addQuotes( $nt->getDBKey() );
70 $sql =
71 "SELECT page_id,page_namespace,page_title,rev_id,rev_user,rev_comment,
72 rev_user_text,rev_timestamp,rev_minor_edit,
73 page_is_new
74 FROM $categorylinks, $revision, $page
75 WHERE rev_timestamp > '{$cutoff}'
76 {$cmq}
77 AND rev_page=page_id
78 AND cl_from=page_id
79 AND cl_to=$catkey
80 GROUP BY page_id,page_namespace,page_title,
81 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
82 page_is_new
83 ORDER BY rev_timestamp DESC
84 LIMIT {$limit}";
85 } else {
86 $sql =
87 "SELECT page_id,page_namespace,page_title,
88 rev_user,rev_comment,rev_user_text,rev_id,rev_timestamp,rev_minor_edit,
89 page_is_new
90 FROM $pagelinks, $revision, $page
91 WHERE rev_timestamp > '{$cutoff}'
92 {$cmq}
93 AND rev_page=page_id
94 AND pl_namespace=page_namespace
95 AND pl_title=page_title
96 AND pl_from=$id
97 GROUP BY page_id,page_namespace,page_title,
98 rev_user,rev_comment,rev_user_text,rev_timestamp,rev_minor_edit,
99 page_is_new
100 ORDER BY rev_timestamp DESC
101 LIMIT {$limit}";
102 }
103 $res = $dbr->query( $sql, $fname );
104
105 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
106 $note = wfMsg( "rcnote", $limit, $days );
107 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
108
109 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
110 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
111 false, $mlink );
112
113 $wgOut->addHTML( $note."\n" );
114
115 $list =& new ChangesList( $sk );
116 $s = $list->beginRecentChangesList();
117 $count = $dbr->numRows( $res );
118
119 $counter = 1;
120 while ( $limit ) {
121 if ( 0 == $count ) { break; }
122 $obj = $dbr->fetchObject( $res );
123 --$count;
124
125 $rc = RecentChange::newFromCurRow( $obj );
126 $rc->counter = $counter++;
127 $s .= $list->recentChangesLine( $rc );
128 --$limit;
129 }
130 $s .= $list->endRecentChangesList();
131
132 $dbr->freeResult( $res );
133 $wgOut->addHTML( $s );
134 }
135
136 ?>