Adding Scripts to a Page

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding Scripts to a Page

Richard Minerich
I am currently working on an extension for MediaWiki and am having some
trouble getting scripts into the <head>
it seems as though $wgOut->addScript() does not work in the following case:


$wgExtensionFunctions[] = 'liveLocal_Install';

function liveLocal_Install()
{
    global $wgParser, $wgHooks;
    $wgParser->setHook("llmap", 'liveLocal_Render');
}

function liveLocal_Render($source, $argv)
{
    global $wgParser, $wgTitle, $wgOut, $wgliveLocalDefaults, $wgJsMimeType,
$wgliveLocalOnThisPage;

....

    $wgOut->addScript( "<script src=\"
http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js\<http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js/>"
type=\"{$wgJsMimeType}\"></script>\n" );

...

}

I am unsure if it is because the timing of when I call addScript or what.
Any help would be greatly appreciated.

-Richard Minerich
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Brion Vibber
Richard Minerich wrote:
> I am currently working on an extension for MediaWiki and am having some
> trouble getting scripts into the <head>
> it seems as though $wgOut->addScript() does not work in the following case:
[snip]
> I am unsure if it is because the timing of when I call addScript or what.
> Any help would be greatly appreciated.

You may not touch $wgOut or its output at wikitext render time (when parser hook
extensions are called). First, output is also aggressively cached  so your hook
will usually not be run again at actual output time.

Keep in mind also that rendering may happen as a background task *while
something else is being displayed*, or in a maintenance script, etc. By touching
$wgOut directly you may be corrupting the display of another page.

I've got an experimental hack for attaching additional extension hooks to run at
display time which can be set from a paser hook; see
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Aggregator/

This work is incomplete at this time.

-- brion vibber (brion @ pobox.com)
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Richard Minerich
That is quite strange. In the docs for making "special pages" they talk
about using $wgOut directly and using addHTML. I guess that is a completely
different case though. So is it possible to sneak scripts into the head
another way?

On 6/2/06, Brion Vibber <[hidden email]> wrote:

>
> Richard Minerich wrote:
> > I am currently working on an extension for MediaWiki and am having some
> > trouble getting scripts into the <head>
> > it seems as though $wgOut->addScript() does not work in the following
> case:
> [snip]
> > I am unsure if it is because the timing of when I call addScript or
> what.
> > Any help would be greatly appreciated.
>
> You may not touch $wgOut or its output at wikitext render time (when
> parser hook
> extensions are called). First, output is also aggressively cached  so your
> hook
> will usually not be run again at actual output time.
>
> Keep in mind also that rendering may happen as a background task *while
> something else is being displayed*, or in a maintenance script, etc. By
> touching
> $wgOut directly you may be corrupting the display of another page.
>
> I've got an experimental hack for attaching additional extension hooks to
> run at
> display time which can be set from a paser hook; see
> http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Aggregator/
>
> This work is incomplete at this time.
>
> -- brion vibber (brion @ pobox.com)
> _______________________________________________
> MediaWiki-l mailing list
> [hidden email]
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
>
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Joshua Yeidel
Is there an advantage to putting scripts in the head rather than in the
body?  Asking in ignorance...

-- Joshua



On 6/2/06 2:15 PM, "Richard Minerich" <[hidden email]> wrote:

> That is quite strange. In the docs for making "special pages" they talk
> about using $wgOut directly and using addHTML. I guess that is a completely
> different case though. So is it possible to sneak scripts into the head
> another way?
>
> On 6/2/06, Brion Vibber <[hidden email]> wrote:
>>
>> Richard Minerich wrote:
>>> I am currently working on an extension for MediaWiki and am having some
>>> trouble getting scripts into the <head>
>>> it seems as though $wgOut->addScript() does not work in the following
>> case:
>> [snip]
>>> I am unsure if it is because the timing of when I call addScript or
>> what.
>>> Any help would be greatly appreciated.
>>
>> You may not touch $wgOut or its output at wikitext render time (when
>> parser hook
>> extensions are called). First, output is also aggressively cached  so your
>> hook
>> will usually not be run again at actual output time.
>>
>> Keep in mind also that rendering may happen as a background task *while
>> something else is being displayed*, or in a maintenance script, etc. By
>> touching
>> $wgOut directly you may be corrupting the display of another page.
>>
>> I've got an experimental hack for attaching additional extension hooks to
>> run at
>> display time which can be set from a paser hook; see
>> http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Aggregator/
>>
>> This work is incomplete at this time.
>>
>> -- brion vibber (brion @ pobox.com)
>> _______________________________________________
>> MediaWiki-l mailing list
>> [hidden email]
>> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
>>
> _______________________________________________
> MediaWiki-l mailing list
> [hidden email]
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l

_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Brion Vibber
In reply to this post by Richard Minerich
Richard Minerich wrote:
> That is quite strange. In the docs for making "special pages" they talk
> about using $wgOut directly and using addHTML. I guess that is a completely
> different case though.

Yes, that's a completely different case. :)

> So is it possible to sneak scripts into the head another way?

You can add a site-wide hook and do it from there.

-- brion vibber (brion @ pobox.com)
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Apache virtual hosts

Michael Roach
In reply to this post by Brion Vibber
I have a box running mediawiki and am now using virtual hosts on it to
enable me to have a test version of the site running on port 8080. What is
the "proper" way to force visitors to use the full server dns name? So, if
I browse to 'http://mysite' the production wiki pops up and
'<a href="http://mysite:8080'">http://mysite:8080' the test wiki is shown. works great. love it. Now
what I want to happen is that when a visitor goes to 'http://mysite' they
get redirected to 'http://mysite.example.org' and going to
'<a href="http://mysite:8080'">http://mysite:8080' takes them to '<a href="http://mysite.example.org:8080'">http://mysite.example.org:8080'.
Basically, I want them to always be using the full canonical host name.

I'm not sure how to setup a redirect like this in Apache2.
Any tips would be appreciated.

Thanks,
Michael
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Apache virtual hosts

Arthur Guy-2
One way you can do this is setup another virtual host at the top of the
list of virtual hosts which responds to the default address
http://mysite only and includes a permanent redirect to the full
address.
Redirect / http://mysite.example.org/


Arthur
[hidden email]
 

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Michael Roach
Sent: 02 June 2006 22:28
To: MediaWiki announcements and site admin list
Subject: [Mediawiki-l] Apache virtual hosts

I have a box running mediawiki and am now using virtual hosts on it to
enable me to have a test version of the site running on port 8080. What
is
the "proper" way to force visitors to use the full server dns name? So,
if
I browse to 'http://mysite' the production wiki pops up and
'<a href="http://mysite:8080'">http://mysite:8080' the test wiki is shown. works great. love it. Now
what I want to happen is that when a visitor goes to 'http://mysite'
they
get redirected to 'http://mysite.example.org' and going to
'<a href="http://mysite:8080'">http://mysite:8080' takes them to '<a href="http://mysite.example.org:8080'">http://mysite.example.org:8080'.
Basically, I want them to always be using the full canonical host name.

I'm not sure how to setup a redirect like this in Apache2.
Any tips would be appreciated.

Thanks,
Michael
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Richard Minerich
In reply to this post by Joshua Yeidel
On 6/2/06, Joshua Yeidel <[hidden email]> wrote:
>
> Is there an advantage to putting scripts in the head rather than in the
> body?  Asking in ignorance...
>
> -- Joshua
>
>
> I'm glad you asked.. Apparently the mozilla rendering engine breaks with
many scripts if they are not in the head.


On 6/2/06, Brion Vibber <[hidden email]> wrote:

You can add a site-wide hook and do it from there.

I would do it the same way in that case (with addScript)? Which hook do you
think would be best to use?
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Apache virtual hosts

Michael Roach
In reply to this post by Michael Roach
Thanks! I need to spend more time with the apache docs :/




----- Original Message -----
From: "Arthur Guy" [[hidden email]]
Sent: 06/02/2006 04:57 PM
To: "MediaWiki announcements and site admin list" <[hidden email]>
Subject: Re: [Mediawiki-l] Apache virtual hosts

One way you can do this is setup another virtual host at the top of the
list of virtual hosts which responds to the default address
http://mysite only and includes a permanent redirect to the full
address.
Redirect / http://mysite.example.org/


Arthur
[hidden email]
 

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Michael Roach
Sent: 02 June 2006 22:28
To: MediaWiki announcements and site admin list
Subject: [Mediawiki-l] Apache virtual hosts

I have a box running mediawiki and am now using virtual hosts on it to
enable me to have a test version of the site running on port 8080. What
is
the "proper" way to force visitors to use the full server dns name? So,
if
I browse to 'http://mysite' the production wiki pops up and
'<a href="http://mysite:8080'">http://mysite:8080' the test wiki is shown. works great. love it. Now
what I want to happen is that when a visitor goes to 'http://mysite'
they
get redirected to 'http://mysite.example.org' and going to
'<a href="http://mysite:8080'">http://mysite:8080' takes them to '<a href="http://mysite.example.org:8080'">http://mysite.example.org:8080'.
Basically, I want them to always be using the full canonical host name.

I'm not sure how to setup a redirect like this in Apache2.
Any tips would be appreciated.

Thanks,
Michael
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l


_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Adding Scripts to a Page

Tels
In reply to this post by Brion Vibber
Moin,

On Friday 02 June 2006 23:05, Brion Vibber wrote:

> Richard Minerich wrote:
> > I am currently working on an extension for MediaWiki and am having
> > some trouble getting scripts into the <head>
> > it seems as though $wgOut->addScript() does not work in the following
> > case:
> [snip]
> > I am unsure if it is because the timing of when I call addScript or
> > what. Any help would be greatly appreciated.
>
> You may not touch $wgOut or its output at wikitext render time (when
> parser hook extensions are called). First, output is also aggressively
> cached  so your hook will usually not be run again at actual output
> time.
>
> Keep in mind also that rendering may happen as a background task *while
> something else is being displayed*, or in a maintenance script, etc. By
> touching $wgOut directly you may be corrupting the display of another
> page.
>
> I've got an experimental hack for attaching additional extension hooks
> to run at display time which can be set from a paser hook; see
> http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Aggregator/
>
> This work is incomplete at this time.
Still cool. Please make sure that the extension can set different hooks
for preview and final (aka saveas) rendering, as this is the only way for
extensions generating files to know which files can be removed safely
later on.

Best wishes,

Tels

--
 Signed on Sat Jun  3 04:21:08 2006 with key 0x93B84C15.
 Visit my photo gallery at http://bloodgate.com/photos/
 PGP key on http://bloodgate.com/tels.asc or per email.

 "The campaign should combat the messages of pornography by putting signs
 on buses saying sex with children is not OK." -- Mary Anne Layden in
 ttp://tinyurl.com/6a9cy


_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l

attachment0 (492 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Apache virtual hosts

Michael Roach
In reply to this post by Michael Roach

Thanks Arthur!

What I ended up doing was creating two more shell VirualHosts that match on
the short name and redirect to the full name like you suggested. Doing it
this way I don't lose the flexability of the default host which I am using
for other purposes.

P.S. What a great list!! The patience and helpful comments I've seen on
this list since picking it up a month ago have been a really refreshing
change from the usual "RTFM butthead..." replies you see so much nowadays.

From: "Arthur Guy" <[hidden email]>
---
One way you can do this is setup another virtual host at the top of the
list of virtual hosts which responds to the default address
http://mysite only and includes a permanent redirect to the full
address.
Redirect / http://mysite.example.org/
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Render problem with Special:Specialpages

Michael Roach
In reply to this post by Brion Vibber
Since upgrading to 1.6.6 I've noticed a problem with Special:Specialpages
not rendering completely. Specifically, the page title and 'Restricted
special pages' section are always present but I have to bang on the
refresh button to get the 'Special pages for all users' section to show
up. Note that this section is completely missing from the source. Also
note that it doesn't make a difference under different accounts (except of
course to determine if the Restricted special pages are shown). The
problem happens the same under Firefox and IE.

Except for my own templates, I have not made any code changes to the base
install and the problem persists after disabling all parser addons.

Has anyone else encountered this?

Thanks,
Michael
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l