wiki.techinc.nl/includes/SpecialRecentchangeslinked.php

172 lines
4.6 KiB
PHP
Raw Normal View History

<?php
/**
2004-09-03 15:23:37 +00:00
* This is to display changes made to all articles linked in an article.
* @package MediaWiki
* @subpackage SpecialPage
*/
/**
*
*/
2004-09-03 15:23:37 +00:00
require_once( 'SpecialRecentchanges.php' );
2003-04-14 23:10:40 +00:00
/**
2004-09-03 15:23:37 +00:00
* Entrypoint
* @param string $par parent page we will look at
*/
function wfSpecialRecentchangeslinked( $par = NULL ) {
global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
2004-09-03 15:23:37 +00:00
$fname = 'wfSpecialRecentchangeslinked';
2003-04-14 23:10:40 +00:00
2004-04-01 12:53:01 +00:00
$days = $wgRequest->getInt( 'days' );
$target = isset($par) ? $par : $wgRequest->getText( 'target' );
2004-04-01 12:53:01 +00:00
$hideminor = $wgRequest->getBool( 'hideminor' ) ? 1 : 0;
2006-01-07 13:31:29 +00:00
$wgOut->setPagetitle( wfMsg( 'recentchangeslinked' ) );
2003-04-14 23:10:40 +00:00
$sk = $wgUser->getSkin();
# Validate the title
$nt = Title::newFromURL( $target );
if( !is_object( $nt ) ) {
$wgOut->errorPage( 'notargettitle', 'notargettext' );
2003-04-14 23:10:40 +00:00
return;
}
# Check for existence
# Do a quiet redirect back to the page itself if it doesn't
if( !$nt->exists() ) {
$wgOut->redirect( $nt->getLocalUrl() );
return;
}
$id = $nt->getArticleId();
2006-01-07 13:31:29 +00:00
$wgOut->setSubtitle( htmlspecialchars( wfMsg( 'rclsub', $nt->getPrefixedText() ) ) );
2003-04-14 23:10:40 +00:00
if ( ! $days ) {
2004-09-03 15:23:37 +00:00
$days = $wgUser->getOption( 'rcdays' );
2003-04-14 23:10:40 +00:00
if ( ! $days ) { $days = 7; }
}
$days = (int)$days;
2004-09-03 15:23:37 +00:00
list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
$dbr =& wfGetDB( DB_SLAVE );
$cutoff = $dbr->timestamp( time() - ( $days * 86400 ) );
2003-04-14 23:10:40 +00:00
$hideminor = ($hideminor ? 1 : 0);
2003-04-14 23:10:40 +00:00
if ( $hideminor ) {
$mlink = $sk->makeKnownLink( $wgContLang->specialPage( 'Recentchangeslinked' ),
2005-08-16 21:02:15 +00:00
wfMsg( 'show' ), 'target=' . htmlspecialchars( $nt->getPrefixedURL() ) .
2003-04-14 23:10:40 +00:00
"&days={$days}&limit={$limit}&hideminor=0" );
} else {
$mlink = $sk->makeKnownLink( $wgContLang->specialPage( "Recentchangeslinked" ),
2005-08-16 21:02:15 +00:00
wfMsg( "hide" ), "target=" . htmlspecialchars( $nt->getPrefixedURL() ) .
2003-04-14 23:10:40 +00:00
"&days={$days}&limit={$limit}&hideminor=1" );
}
if ( $hideminor ) {
$cmq = 'AND rc_minor=0';
2004-09-03 15:23:37 +00:00
} else { $cmq = ''; }
2003-04-14 23:10:40 +00:00
extract( $dbr->tableNames( 'recentchanges', 'categorylinks', 'pagelinks', 'revision', 'page' , "watchlist" ) );
$uid = $wgUser->getID();
2006-01-07 13:31:29 +00:00
// If target is a Category, use categorylinks and invert from and to
if( $nt->getNamespace() == NS_CATEGORY ) {
$catkey = $dbr->addQuotes( $nt->getDBKey() );
2006-01-07 13:09:30 +00:00
$sql = "SELECT /* wfSpecialRecentchangeslinked */
rc_id,
rc_cur_id,
rc_namespace,
rc_title,
rc_this_oldid,
rc_last_oldid,
rc_user,
rc_comment,
rc_user_text,
rc_timestamp,
rc_minor,
rc_new,
rc_patrolled,
rc_type
" . ($uid ? ",wl_user" : "") . "
FROM $categorylinks, $recentchanges
" . ($uid ? "LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
WHERE rc_timestamp > '{$cutoff}'
{$cmq}
AND cl_from=rc_cur_id
AND cl_to=$catkey
GROUP BY rc_cur_id,rc_namespace,rc_title,
rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
rc_new
ORDER BY rc_timestamp DESC
LIMIT {$limit};
";
} else {
$sql =
2006-01-07 13:09:30 +00:00
"SELECT /* wfSpecialRecentchangeslinked */
rc_id,
rc_cur_id,
rc_namespace,
rc_title,
rc_user,
rc_comment,
rc_user_text,
rc_this_oldid,
rc_last_oldid,
rc_timestamp,
rc_minor,
rc_new,
rc_patrolled,
rc_type
" . ($uid ? ",wl_user" : "") . "
FROM $pagelinks, $recentchanges
" . ($uid ? " LEFT OUTER JOIN $watchlist ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "
WHERE rc_timestamp > '{$cutoff}'
{$cmq}
AND pl_namespace=rc_namespace
AND pl_title=rc_title
AND pl_from=$id
GROUP BY rc_cur_id,rc_namespace,rc_title,
rc_user,rc_comment,rc_user_text,rc_timestamp,rc_minor,
rc_new
ORDER BY rc_timestamp DESC
LIMIT {$limit}";
}
$res = $dbr->query( $sql, $fname );
2003-04-14 23:10:40 +00:00
2004-05-06 15:30:05 +00:00
$wgOut->addHTML("&lt; ".$sk->makeKnownLinkObj($nt, "", "redirect=no" )."<br />\n");
$note = wfMsg( "rcnote", $limit, $days, $wgLang->timeAndDate( wfTimestampNow(), true ) );
$wgOut->addHTML( "<hr />\n{$note}\n<br />" );
2003-04-14 23:10:40 +00:00
$note = rcDayLimitlinks( $days, $limit, "Recentchangeslinked",
"target=" . $nt->getPrefixedURL() . "&hideminor={$hideminor}",
false, $mlink );
2004-09-03 15:23:37 +00:00
$wgOut->addHTML( $note."\n" );
2003-04-14 23:10:40 +00:00
$list = ChangesList::newFromUser( $wgUser );
$s = $list->beginRecentChangesList();
$count = $dbr->numRows( $res );
2006-01-07 13:31:29 +00:00
2004-04-19 09:15:01 +00:00
$counter = 1;
2003-04-14 23:10:40 +00:00
while ( $limit ) {
if ( 0 == $count ) { break; }
$obj = $dbr->fetchObject( $res );
2003-04-14 23:10:40 +00:00
--$count;
# print_r ( $obj ) ;
# print "<br/>\n" ;
2003-04-14 23:10:40 +00:00
$rc = RecentChange::newFromRow( $obj );
2004-04-19 09:15:01 +00:00
$rc->counter = $counter++;
$s .= $list->recentChangesLine( $rc , !empty( $obj->wl_user) );
2003-04-14 23:10:40 +00:00
--$limit;
}
$s .= $list->endRecentChangesList();
2003-04-14 23:10:40 +00:00
$dbr->freeResult( $res );
2003-04-14 23:10:40 +00:00
$wgOut->addHTML( $s );
}
?>