Skip to content

Commit

Permalink
Item13897: The frontpage is been generated almost correctly.
Browse files Browse the repository at this point in the history
The code bootstraps the initial config and displays Main.WebHome. It seems
like not all parts of the page are generated but the overall look and feel
resembels the standard.

- Foswiki::Macros now calls macro subs with $Foswiki::app as the first
argument instead of $Foswiki::app->macros.

- Fixed some macros required to render the default page.

- Fixed $app->cfg startup initialization and bootstrapping.

- Added preferences and plugins initialization to Foswiki::App startup.

- Setup of %Foswiki::cfg alias has been moved into Foswiki::Config data
attribute default method to cope with $cfg->clear_data calls.

- Adapted some more code in Foswiki::Func

- Adaptation hot-fixes for JQueryPlugin, HomePagePlugin and
SubscriberPlugin.
  • Loading branch information
vrurg committed Apr 15, 2016
1 parent aa07ddc commit 8f9eb1d
Show file tree
Hide file tree
Showing 28 changed files with 445 additions and 389 deletions.
49 changes: 25 additions & 24 deletions HomePagePlugin/lib/Foswiki/Plugins/HomePagePlugin.pm
Expand Up @@ -27,60 +27,62 @@ sub initPlugin {
sub initializeUserHandler {
my ( $loginName, $url, $pathInfo ) = @_;

my $app = $Foswiki::app;
my $req = $app->request;
my $cfg = $app->cfg;

return
unless ( $Foswiki::Plugins::SESSION->inContext('view')
|| $Foswiki::Plugins::SESSION->inContext('login') );
unless ( $app->inContext('view')
|| $app->inContext('login') );

return
if ( $Foswiki::Plugins::SESSION->inContext('command_line') );
if ( $app->inContext('command_line') );

# Don't override web/topic if specified by url param.
return
if ( $Foswiki::Plugins::SESSION->{request}->param('defaultweb')
|| $Foswiki::Plugins::SESSION->{request}->param('topic') );
if ( $app->request->param('defaultweb')
|| $app->request->param('topic') );

my $gotoOnLogin =
( $Foswiki::cfg{HomePagePlugin}{GotoHomePageOnLogin}
and $Foswiki::Plugins::SESSION->inContext('login') );
( $cfg->data->{HomePagePlugin}{GotoHomePageOnLogin}
and $app->inContext('login') );
if ($gotoOnLogin) {
my $test = $Foswiki::Plugins::SESSION->{request}->param('username');
my $test = $app->request->param('username');
$loginName = $test if defined($test);

# pre-load the origurl with the 'login' url which forces
# templatelogin to use the requested web&topic
$Foswiki::Plugins::SESSION->{request}->param(
$app->request->param(
-name => 'origurl',
-value => $Foswiki::Plugins::SESSION->{request}->url()
-value => $app->request->url()
);
}

# we don't know the user at this point so can only set up the
# site wide default
my $path_info =
Foswiki::urlDecode( $Foswiki::Plugins::SESSION->{request}->path_info() );
my $path_info = Foswiki::urlDecode( $app->request->path_info() );

return
unless ( ( $path_info eq '' or $path_info eq '/' )
or ($gotoOnLogin) );

my $siteDefault = $Foswiki::cfg{HomePagePlugin}{SiteDefaultTopic};
my $siteDefault = $cfg->data->{HomePagePlugin}{SiteDefaultTopic};

#$Foswiki::cfg{HomePagePlugin}{HostnameMapping}
#$cfg->data->{HomePagePlugin}{HostnameMapping}
my $hostName = lc( Foswiki::Func::getUrlHost() );
if (
defined( $Foswiki::cfg{HomePagePlugin}{HostnameMapping}->{$hostName} ) )
if ( defined( $cfg->data->{HomePagePlugin}{HostnameMapping}->{$hostName} ) )
{
$siteDefault =
$Foswiki::cfg{HomePagePlugin}{HostnameMapping}->{$hostName};
$cfg->data->{HomePagePlugin}{HostnameMapping}->{$hostName};
}

my $wikiName = Foswiki::Func::getWikiName($loginName);
if ( ( defined $wikiName )
and
Foswiki::Func::topicExists( $Foswiki::cfg{UsersWebName}, $wikiName ) )
Foswiki::Func::topicExists( $cfg->data->{UsersWebName}, $wikiName ) )
{
my ( $meta, $text ) =
Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, $wikiName );
Foswiki::Func::readTopic( $cfg->data->{UsersWebName}, $wikiName );

# TODO: make fieldname a setting.
my $field = $meta->get( 'FIELD', 'HomePage' );
Expand All @@ -93,19 +95,18 @@ sub initializeUserHandler {
if ( Foswiki::Func::webExists($siteDefault) ) {

# if they only set a webname, dwim
$siteDefault .= '.' . $Foswiki::cfg{HomeTopicName};
$siteDefault .= '.' . $cfg->data->{HomeTopicName};
}

return unless defined $siteDefault;

my ( $web, $topic ) =
$Foswiki::Plugins::SESSION->normalizeWebTopicName( '', $siteDefault );
my ( $web, $topic ) = $req->normalizeWebTopicName( '', $siteDefault );

if ( Foswiki::Func::isValidWebName($web)
&& Foswiki::Func::isValidTopicName( $topic, 1 ) )
{
$Foswiki::Plugins::SESSION->{webName} = $web;
$Foswiki::Plugins::SESSION->{topicName} = $topic;
$req->web($web);
$req->topic($topic);
}

return;
Expand Down
151 changes: 82 additions & 69 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
@@ -1,13 +1,52 @@
# See bottom of file for license and copyright information
package Foswiki::Plugins::JQueryPlugin::Plugin;
use v5.14;

use Foswiki::Plugins::JQueryPlugin::Plugins ();
use Foswiki::Func ();

use strict;
use warnings;
use constant TRACE => 0;

use Moo;
use namespace::clean;
extends qw(Foswiki::AppObject);

has author => ( is => 'rw', default => 'unknown', );
has css => ( is => 'rw', default => sub { [] }, );
has debug =>
( is => 'ro', default => $Foswiki::cfg{JQueryPlugin}{Debug} || 0, );
has dependencies => ( is => 'rw', default => sub { [] }, );
has documentation => (
is => 'rw',
lazy => 1,
default => sub {
my $this = shift;
my $documentation =
$Foswiki::cfg{SystemWebName} . '.JQuery' . ucfirst( $this->name );

$documentation =~ s/:://g;
return $documentation;
},
);
has homepage => ( is => 'rw', default => 'unknown', );
has javascript => ( is => 'rw', default => sub { [] }, );
has name => ( is => 'rw', default => $class, );
has puburl => (
is => 'rw',
lazy => 1,
default => sub {
return
$Foswiki::cfg{PubUrlPath} . '/'
. $Foswiki::cfg{SystemWebName}
. '/JQueryPlugin/plugins/'
. lc( $_[0]->name );
},
);
has summary => ( is => 'rw', );
has tags => ( is => 'rw', default => sub { [] }, );
has version => ( is => 'rw', default => 'unknown', );
has idPrefix => ( is => 'rw', default => 'JQUERYPLUGIN', );

=begin TML
---+ package Foswiki::Plugins::JQueryPlugin::Plugin
Expand Down Expand Up @@ -36,7 +75,8 @@ abstract class for a jQuery plugin
=cut

sub new {
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;

# backwards compatibility: the session param is deprecated now
Expand All @@ -50,42 +90,8 @@ sub new {
shift; # ... it off the args
}

my $this = bless(
{
author => 'unknown',
css => [],
debug => $Foswiki::cfg{JQueryPlugin}{Debug} || 0,
dependencies => [],
documentation => undef,
homepage => 'unknown',
javascript => [],
name => $class,
puburl => '',
summary => undef,
tags => [],
version => 'unknown',
idPrefix => 'JQUERYPLUGIN',
@_
},
$class
);

$this->{documentation} =
$Foswiki::cfg{SystemWebName} . '.JQuery' . ucfirst( $this->{name} )
unless defined $this->{documentation};

$this->{documentation} =~ s/:://g;

unless ( $this->{puburl} ) {
$this->{puburl} =
$Foswiki::cfg{PubUrlPath} . '/'
. $Foswiki::cfg{SystemWebName}
. '/JQueryPlugin/plugins/'
. lc( $this->{name} );
}

return $this;
}
return $orig->( $class, @_ );
};

=begin TML
Expand All @@ -99,36 +105,37 @@ are fulfilled.
sub init {
my $this = shift;

return 0 if $this->{isInit};
$this->{isInit} = 1;
return 0 if $this->isInit;
$this->isInit(1);

my $header = '';
my $footer = '';

# load all css
foreach my $css ( @{ $this->{css} } ) {
foreach my $css ( @{ $this->css } ) {
$header .= $this->renderCSS($css);
}

# load all javascript
foreach my $js ( @{ $this->{javascript} } ) {
foreach my $js ( @{ $this->javascript } ) {
$footer .= $this->renderJS($js);
}

# load any i18n messages
if ( $this->{i18n} ) {
$this->renderI18N( $this->{i18n} );
if ( $this->i18n ) {
$this->renderI18N( $this->i18n );
}

# gather dependencies
my @dependencies =
('JQUERYPLUGIN::FOSWIKI'); # jquery.foswiki is in there by default

# add i18n when required
push @{ $this->{dependencies} }, "i18n" if $this->{i18n};
push @{ $this->dependencies }, "i18n" if $this->i18n;

foreach my $dep ( @{ $this->{dependencies} } ) {
if ( $dep =~ /^($this->{idPrefix}|JQUERYPLUGIN|JavascriptFiles)/ )
my $idPrefix = $this->idPrefix;
foreach my $dep ( @{ $this->dependencies } ) {
if ( $dep =~ /^($idPrefix|JQUERYPLUGIN|JavascriptFiles)/ )
{ # SMELL: there are some jquery modules that depend on non-jquery code
push @dependencies, $dep;
}
Expand All @@ -150,14 +157,16 @@ sub init {
}
}

Foswiki::Func::addToZone( 'head',
$this->{idPrefix} . '::' . uc( $this->{name} ),
$header, join( ', ', @dependencies ) );
Foswiki::Func::addToZone( 'script',
$this->{idPrefix} . '::' . uc( $this->{name} ),
$footer, join( ', ', @dependencies ) );
Foswiki::Func::addToZone(
'head', $idPrefix . '::' . uc( $this->name ),
$header, join( ', ', @dependencies )
);
Foswiki::Func::addToZone(
'script', $idPrefix . '::' . uc( $this->name ),
$footer, join( ', ', @dependencies )
);

my $contextID = $this->{name} . 'Enabled';
my $contextID = $this->name . 'Enabled';
$contextID =~ s/\W//g;
Foswiki::Func::getContext()->{$contextID} = 1;

Expand All @@ -168,10 +177,12 @@ sub renderCSS {
my ( $this, $text ) = @_;

$text =~ s/\.css$/.uncompressed.css/
if $this->{debug} && $text !~ /(\.uncompressed|_src)\./;
$text .= '?version=' . $this->{version};
if $this->debug && $text !~ /(\.uncompressed|_src)\./;
$text .= '?version=' . $this->version;
$text =
"<link rel='stylesheet' href='$this->{puburl}/$text' type='text/css' media='all' />\n";
"<link rel='stylesheet' href='"
. $this->puburl
. "/$text' type='text/css' media='all' />\n";

return $text;
}
Expand All @@ -180,10 +191,12 @@ sub renderJS {
my ( $this, $text ) = @_;

$text =~ s/\.js$/.uncompressed.js/
if $this->{debug} && $text !~ /(\.uncompressed|_src)\./;
$text .= '?version=' . $this->{version};
if $this->debug && $text !~ /(\.uncompressed|_src)\./;
$text .= '?version=' . $this->version;
$text =
"<script type='text/javascript' src='$this->{puburl}/$text'></script>\n";
"<script type='text/javascript' src='"
. $this->puburl
. "/$text'></script>\n";

return $text;
}
Expand All @@ -192,18 +205,18 @@ sub renderI18N {
my ( $this, $path ) = @_;

# open matching localization file if it exists
my $session = $Foswiki::Plugins::SESSION;
my $langTag = $session->i18n->language();
my $app = $Foswiki::app;
my $langTag = $app->i18n->language();

my $messagePath = $path . '/' . $langTag . '.js';
my $messageFile = $Foswiki::cfg{PubDir} . '/' . $messagePath;
if ( -f $messageFile ) {
my $text .=
"<script type='application/l10n' data-i18n-language='$langTag' data-i18n-namespace='"
. uc( $this->{name} )
. uc( $this->name )
. "' src='$Foswiki::cfg{PubUrlPath}/$messagePath' ></script>\n";
Foswiki::Func::addToZone(
'script', uc( $this->{name} ) . "::I8N",
'script', uc( $this->name ) . "::I8N",
$text, 'JQUERYPLUGIN::I18N'
);
}
Expand All @@ -221,18 +234,18 @@ returns the summary text for this plugin. this is either the =summary= property
sub getSummary {
my $this = shift;

my $summary = $this->{summary};
my $summary = $this->summary;

unless ( defined $summary ) {
$summary = 'n/a';
if ( $this->{'documentation'} ) {
if ( $this->documentation ) {
$summary =
Foswiki::Func::expandCommonVariables( '%INCLUDE{"'
. $this->{documentation}
. $this->documentation
. '" section="summary" warn="off"}%' );
}

$this->{summary} = $summary;
$this->summary($summary);
}

return $summary;
Expand Down

0 comments on commit 8f9eb1d

Please sign in to comment.