add #455: Featured page in wiki
This commit is contained in:
parent
cf9df28ddd
commit
6da85b89a7
8 changed files with 152 additions and 0 deletions
Binary file not shown.
BIN
docs/upgrades/packages-7.8.0/default-wiki-page-edit.wgpkg
Normal file
BIN
docs/upgrades/packages-7.8.0/default-wiki-page-edit.wgpkg
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -35,6 +35,7 @@ reorganizeAdSpaceProperties($session);
|
||||||
fixTemplateSettingsFromShunt($session);
|
fixTemplateSettingsFromShunt($session);
|
||||||
addSubscribableAspect( $session );
|
addSubscribableAspect( $session );
|
||||||
addMatrixColumnDefaults($session);
|
addMatrixColumnDefaults($session);
|
||||||
|
addFeaturedPageWiki( $session );
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
@ -48,6 +49,19 @@ finish($session); # this line required
|
||||||
# print "DONE!\n" unless $quiet;
|
# print "DONE!\n" unless $quiet;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Add the column for featured wiki pages
|
||||||
|
sub exampleFunction {
|
||||||
|
my $session = shift;
|
||||||
|
print "\tAdding featured pages to the Wiki " unless $quiet;
|
||||||
|
|
||||||
|
$session->db->write(
|
||||||
|
"ALTER TABLE WikiPage ADD COLUMN isFeatured INT(1)",
|
||||||
|
);
|
||||||
|
|
||||||
|
print "DONE!\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Add tables for the subscribable aspect
|
# Add tables for the subscribable aspect
|
||||||
sub addSubscribableAspect {
|
sub addSubscribableAspect {
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,11 @@ sub definition {
|
||||||
defaultValue => '',
|
defaultValue => '',
|
||||||
noFormPost => 1,
|
noFormPost => 1,
|
||||||
},
|
},
|
||||||
|
isFeatured => {
|
||||||
|
fieldType => "yesNo",
|
||||||
|
defaultValue => 0,
|
||||||
|
noFormPost => 1,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
push @$definition,
|
push @$definition,
|
||||||
|
|
@ -205,6 +210,7 @@ sub getEditForm {
|
||||||
formContent => WebGUI::Form::HTMLArea($session, { name => 'content', richEditId => $wiki->get('richEditor'), value => $self->get('content') }) ,
|
formContent => WebGUI::Form::HTMLArea($session, { name => 'content', richEditId => $wiki->get('richEditor'), value => $self->get('content') }) ,
|
||||||
formSubmit => WebGUI::Form::submit($session, { value => 'Save' }),
|
formSubmit => WebGUI::Form::submit($session, { value => 'Save' }),
|
||||||
formProtect => WebGUI::Form::yesNo($session, { name => "isProtected", value=>$self->getValue("isProtected")}),
|
formProtect => WebGUI::Form::yesNo($session, { name => "isProtected", value=>$self->getValue("isProtected")}),
|
||||||
|
formFeatured => WebGUI::Form::yesNo( $session, { name => 'isFeatured', value=>$self->getValue('isFeatured')}),
|
||||||
formKeywords => WebGUI::Form::keywords($session, {
|
formKeywords => WebGUI::Form::keywords($session, {
|
||||||
name => "keywords",
|
name => "keywords",
|
||||||
value => WebGUI::Keyword->new($session)->getKeywordsForAsset({asset=>$self}),
|
value => WebGUI::Keyword->new($session)->getKeywordsForAsset({asset=>$self}),
|
||||||
|
|
@ -404,6 +410,7 @@ sub processPropertiesFromFormPost {
|
||||||
|
|
||||||
if ($wiki->canAdminister) {
|
if ($wiki->canAdminister) {
|
||||||
$properties->{isProtected} = $self->session->form->get("isProtected");
|
$properties->{isProtected} = $self->session->form->get("isProtected");
|
||||||
|
$properties->{isFeatured} = $self->session->form->get("isFeatured");
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->update($properties);
|
$self->update($properties);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,24 @@ use URI::Escape;
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 appendFeaturedPageVars ( var, asset )
|
||||||
|
|
||||||
|
Append the template variables to C<var> for the featured page C<asset>. Returns
|
||||||
|
the C<var> for convenience.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub appendFeaturedPageVars {
|
||||||
|
my ( $self, $var, $asset ) = @_;
|
||||||
|
my $assetVar = $asset->getTemplateVars;
|
||||||
|
for my $key ( keys %{$assetVar} ) {
|
||||||
|
$var->{ 'featured_' . $key } = $assetVar->{$key};
|
||||||
|
}
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 appendMostPopular ($var, [ $limit ])
|
=head2 appendMostPopular ($var, [ $limit ])
|
||||||
|
|
||||||
=head3 $var
|
=head3 $var
|
||||||
|
|
@ -419,6 +437,25 @@ sub definition {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getFeaturedPageIds ( )
|
||||||
|
|
||||||
|
Get the asset IDs of the pages that are marked as Featured.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getFeaturedPageIds {
|
||||||
|
my ( $self ) = @_;
|
||||||
|
|
||||||
|
my $assetIds = $self->getLineage( ['children'], {
|
||||||
|
joinClass => 'WebGUI::Asset::WikiPage',
|
||||||
|
whereClause => 'isFeatured = 1',
|
||||||
|
} );
|
||||||
|
|
||||||
|
return $assetIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 getRssFeedItems ()
|
=head2 getRssFeedItems ()
|
||||||
|
|
||||||
Returns an array reference of hash references. Each hash reference has a title,
|
Returns an array reference of hash references. Each hash reference has a title,
|
||||||
|
|
@ -547,6 +584,7 @@ Render the front page of the wiki.
|
||||||
|
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
my $var = $self->getTemplateVars;
|
my $var = $self->getTemplateVars;
|
||||||
$var->{ description } = $self->autolinkHtml( $var->{ description } );
|
$var->{ description } = $self->autolinkHtml( $var->{ description } );
|
||||||
$var->{ keywordCloud }
|
$var->{ keywordCloud }
|
||||||
|
|
@ -555,6 +593,15 @@ sub view {
|
||||||
displayFunc=>"byKeyword",
|
displayFunc=>"byKeyword",
|
||||||
});
|
});
|
||||||
my $template = $self->{_frontPageTemplate};
|
my $template = $self->{_frontPageTemplate};
|
||||||
|
|
||||||
|
# Get a random featured page
|
||||||
|
my $featuredIds = $self->getFeaturedPageIds;
|
||||||
|
my $featuredId = $featuredIds->[ int( rand @$featuredIds ) - 1 ];
|
||||||
|
my $featured = WebGUI::Asset->newByDynamicClass( $session, $featuredId );
|
||||||
|
if ( $featured ) {
|
||||||
|
$self->appendFeaturedPageVars( $var, $featured );
|
||||||
|
}
|
||||||
|
|
||||||
$self->appendSearchBoxVars($var);
|
$self->appendSearchBoxVars($var);
|
||||||
$self->appendRecentChanges($var, $self->get('recentChangesCountFront'));
|
$self->appendRecentChanges($var, $self->get('recentChangesCountFront'));
|
||||||
$self->appendMostPopular($var, $self->get('mostPopularCountFront'));
|
$self->appendMostPopular($var, $self->get('mostPopularCountFront'));
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,13 @@ our $I18N =
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => 'Body text for help page',
|
context => 'Body text for help page',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
'isFeatured label' => {
|
||||||
|
message => q{Feature this on the front page},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => 'Label for asset property',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
77
t/Asset/Wobject/WikiMaster/featured.t
Normal file
77
t/Asset/Wobject/WikiMaster/featured.t
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
# vim:syntax=perl
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# Please read the legal notices (docs/legal.txt) and the license
|
||||||
|
# (docs/license.txt) that came with this distribution before using
|
||||||
|
# this software.
|
||||||
|
#------------------------------------------------------------------
|
||||||
|
# http://www.plainblack.com info@plainblack.com
|
||||||
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Test the featured page of the Wiki
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
use strict;
|
||||||
|
use lib "$FindBin::Bin/../../../lib";
|
||||||
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
|
use WebGUI::Session;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Init
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
my $import = WebGUI::Asset->getImportNode( $session );
|
||||||
|
|
||||||
|
my $wiki
|
||||||
|
= $import->addChild( {
|
||||||
|
className => 'WebGUI::Asset::Wobject::WikiMaster',
|
||||||
|
} );
|
||||||
|
|
||||||
|
my $page
|
||||||
|
= $wiki->addChild( {
|
||||||
|
className => 'WebGUI::Asset::WikiPage',
|
||||||
|
}, undef, undef, { skipAutoCommitWorkflows => 1 } );
|
||||||
|
|
||||||
|
my $featuredPage
|
||||||
|
= $wiki->addChild( {
|
||||||
|
className => 'WebGUI::Asset::WikiPage',
|
||||||
|
isFeatured => 1,
|
||||||
|
title => "Escape From Shawshank!",
|
||||||
|
content => 'A how-to book',
|
||||||
|
}, undef, undef, { skipAutoCommitWorkflows => 1 } );
|
||||||
|
|
||||||
|
WebGUI::Test->tagsToRollback( WebGUI::VersionTag->getWorking( $session ) );
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Tests
|
||||||
|
|
||||||
|
plan tests => 2; # Increment this number for each test you create
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
|
||||||
|
cmp_deeply(
|
||||||
|
$wiki->getFeaturedPageIds,
|
||||||
|
[ $featuredPage->getId ],
|
||||||
|
"getFeaturedPageIds contains only featured pages",
|
||||||
|
);
|
||||||
|
|
||||||
|
cmp_deeply(
|
||||||
|
$wiki->appendFeaturedPageVars({}, $featuredPage),
|
||||||
|
superhashof( {
|
||||||
|
featured_title => $featuredPage->get('title'),
|
||||||
|
featured_content => $featuredPage->get('content'),
|
||||||
|
} ),
|
||||||
|
"appendFeaturedPageVars returns correct variables, prefixed with 'featured_'",
|
||||||
|
);
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Cleanup
|
||||||
|
END {
|
||||||
|
|
||||||
|
}
|
||||||
|
#vim:ft=perl
|
||||||
Loading…
Add table
Add a link
Reference in a new issue