in jspwiki-main/src/main/java/org/apache/wiki/plugin/RecentChangesPlugin.java [83:219]
public String execute( final Context context, final Map< String, String > params ) throws PluginException {
final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS );
String spacing = "4";
boolean showAuthor = true;
boolean showChangenote = true;
String tablewidth = "4";
final Engine engine = context.getEngine();
//
// Which format we want to see?
//
if( "compact".equals( params.get( PARAM_FORMAT ) ) ) {
spacing = "0";
showAuthor = false;
showChangenote = false;
tablewidth = "2";
}
final Calendar sincedate = new GregorianCalendar();
sincedate.add( Calendar.DAY_OF_MONTH, -since );
LOG.debug("Calculating recent changes from "+sincedate.getTime());
// FIXME: Should really have a since date on the getRecentChanges method.
Collection< Page > changes = engine.getManager( PageManager.class ).getRecentChanges();
super.initialize( context, params );
changes = filterWikiPageCollection( changes );
if ( changes != null ) {
Date olddate = new Date( 0 );
final DateFormat fmt = getDateFormat( context, params );
final DateFormat tfmt = getTimeFormat( context, params );
final Element rt = XhtmlUtil.element( XHTML.table );
rt.setAttribute( XHTML.ATTR_class, "recentchanges" );
rt.setAttribute( XHTML.ATTR_cellpadding, spacing );
for( final Page pageref : changes ) {
final Date lastmod = pageref.getLastModified();
if( lastmod.before( sincedate.getTime() ) ) {
break;
}
if( !isSameDay( lastmod, olddate ) ) {
final Element row = XhtmlUtil.element( XHTML.tr );
final Element col = XhtmlUtil.element( XHTML.td );
col.setAttribute( XHTML.ATTR_colspan, tablewidth );
col.setAttribute( XHTML.ATTR_class, "date" );
col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) );
rt.addContent( row );
row.addContent( col );
olddate = lastmod;
}
final String href = context.getURL( pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext()
: ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName() );
Element link = XhtmlUtil.link( href, engine.getManager( RenderingManager.class ).beautifyTitle( pageref.getName() ) );
final Element row = XhtmlUtil.element( XHTML.tr );
final Element col = XhtmlUtil.element( XHTML.td );
col.setAttribute( XHTML.ATTR_width, "30%" );
col.addContent( link );
//
// Add the direct link to the attachment info.
//
if( pageref instanceof Attachment ) {
link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null );
link.setAttribute( XHTML.ATTR_class, "infolink" );
final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null );
link.addContent( img );
col.addContent( link );
}
row.addContent( col );
rt.addContent( row );
if( pageref instanceof Attachment ) {
final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) );
td.setAttribute( XHTML.ATTR_class, "lastchange" );
row.addContent( td );
} else {
final Element infocol = XhtmlUtil.element( XHTML.td );
infocol.setAttribute( XHTML.ATTR_class, "lastchange" );
infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ),
tfmt.format( lastmod ) ) );
row.addContent( infocol );
}
//
// Display author information.
//
if( showAuthor ) {
final String author = pageref.getAuthor();
final Element authorinfo = XhtmlUtil.element( XHTML.td );
authorinfo.setAttribute( XHTML.ATTR_class, "author" );
if( author != null ) {
if( engine.getManager( PageManager.class ).wikiPageExists( author ) ) {
authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) );
} else {
authorinfo.addContent( author );
}
} else {
authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE )
.getString( "common.unknownauthor" ) );
}
row.addContent( authorinfo );
}
// Change note
if( showChangenote ) {
final String changenote = pageref.getAttribute( Page.CHANGENOTE );
final Element td_changenote = XhtmlUtil.element( XHTML.td, changenote );
td_changenote.setAttribute( XHTML.ATTR_class, "changenote" );
row.addContent( td_changenote );
}
// Revert note
/*
if( context.hasAdminPermissions() )
{
row.addElement( new td("Revert") );
}
*/
}
return XhtmlUtil.serialize( rt, XhtmlUtil.EXPAND_EMPTY_NODES );
}
return "";
}