* Fixed a bug where moving a page would cause the following SQL error when
[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( "recentchanges" ) );
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', 'links', '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 = "SELECT page_id,page_namespace,page_title,rev_user,rev_comment," .
71 "rev_user_text,rev_timestamp,rev_minor_edit,page_is_new FROM $categorylinks, $revision, $page " .
72 "WHERE rev_timestamp > '{$cutoff}' {$cmq} AND cl_from=page_id AND cl_to=$catkey " .
73 "GROUP BY page_id,page_namespace,page_title,rev_user,rev_comment,rev_user_text," .
74 "rev_timestamp,rev_minor_edit,page_is_new ORDER BY rev_timestamp DESC LIMIT {$limit}";
75 } else {
76 $sql = "SELECT page_id,page_namespace,page_title,rev_user,rev_comment," .
77 "rev_user_text,rev_timestamp,rev_minor_edit,page_is_new FROM $links, $revision, $page " .
78 "WHERE rev_timestamp > '{$cutoff}' {$cmq} AND l_to=page_id AND l_from=$id " .
79 "GROUP BY page_id,page_namespace,page_title,rev_user,rev_comment,rev_user_text," .
80 "rev_timestamp,rev_minor_edit,page_is_new ORDER BY rev_timestamp DESC LIMIT {$limit}";
81 }
82 $res = $dbr->query( $sql, $fname );
83
84 $wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
85 $note = wfMsg( "rcnote", $limit, $days );
86 $wgOut->addHTML( "<hr />\n{$note}\n<br />" );
87
88 $note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
89 "target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
90 false, $mlink );
91
92 $wgOut->addHTML( $note."\n" );
93
94 $list =& new ChangesList( $sk );
95 $s = $list->beginRecentChangesList();
96 $count = $dbr->numRows( $res );
97
98 $counter = 1;
99 while ( $limit ) {
100 if ( 0 == $count ) { break; }
101 $obj = $dbr->fetchObject( $res );
102 --$count;
103
104 $rc = RecentChange::newFromCurRow( $obj );
105 $rc->counter = $counter++;
106 $s .= $list->recentChangesLine( $rc );
107 --$limit;
108 }
109 $s .= $list->endRecentChangesList();
110
111 $dbr->freeResult( $res );
112 $wgOut->addHTML( $s );
113 }
114
115 ?>