Quantcast

[MediaWiki-l] Sitenotice for all pages except one

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[MediaWiki-l] Sitenotice for all pages except one

Jean Valjean
How do I put up a sitenotice for all pages except one (e.g. Main Page)? I
want the main page to have my current content, and all other pages to have
a notice saying their content is just an archive.

I notice that when I put {{FULLPAGENAME}} in MediaWiki:Sitenotice, it
always says "MediaWiki:Sitenotice".

Otherwise, I would use an #ifeq.
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sitenotice for all pages except one

Jean Valjean
Okay, this is the code I came up with:

$wgAlreadyParsed = false;
function onParserBeforeStripSiteNotice( &$parser, &$text, &$strip_state ) {
        global $wgAlreadyParsed;
        if ( $wgAlreadyParsed ) {
                return true;
}
        $title = $parser->getTitle();
        if ( $title->getNamespace () !== 0 ) {
                return true;
        }
        $wikiPage = WikiPage::factory( $title );
        $revision = $wikiPage->getRevision();
        if ( is_null ( $revision ) ) {
                return true;
        }
        $content = $revision->getContent( Revision::RAW );
        $revisionText = ContentHandler::getContentText( $content );
        if ( $text !== $revisionText ) {
                return true;
        }
        $wgAlreadyParsed = true;
        $titleText = $title->getPrefixedText ();
        $text = "{{siteNotice|$titleText}}" . $text;
}
$wgHooks['ParserBeforeStrip'][] = 'onParserBeforeStripSiteNotice';

Then in Template:SiteNotice I put:

{{#ifeq: {{FULLPAGENAME}}|Main Page||<div class="plainlinks"
style="border:1px solid #a7d7f9; width:100%; font-size: 110%; text-align:
center; padding: 0.5ex; "><p>This page is an archive.</p></div>}}


On Wed, May 3, 2017 at 3:51 AM, Jean Valjean <[hidden email]>
wrote:

> How do I put up a sitenotice for all pages except one (e.g. Main Page)? I
> want the main page to have my current content, and all other pages to have
> a notice saying their content is just an archive.
>
> I notice that when I put {{FULLPAGENAME}} in MediaWiki:Sitenotice, it
> always says "MediaWiki:Sitenotice".
>
> Otherwise, I would use an #ifeq.
>
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sitenotice for all pages except one

Sébastien Santoro
Create an extension it will be easier ton maintain.

Divide the code in several methods too,
https://jeroendedauw.github.io/slides/craftmanship/functions/#/1

On Wed, May 3, 2017 at 11:22 PM, Jean Valjean <[hidden email]> wrote:

> Okay, this is the code I came up with:
>
> $wgAlreadyParsed = false;
> function onParserBeforeStripSiteNotice( &$parser, &$text, &$strip_state ) {
>         global $wgAlreadyParsed;
>         if ( $wgAlreadyParsed ) {
>                 return true;
> }
>         $title = $parser->getTitle();
>         if ( $title->getNamespace () !== 0 ) {
>                 return true;
>         }
>         $wikiPage = WikiPage::factory( $title );
>         $revision = $wikiPage->getRevision();
>         if ( is_null ( $revision ) ) {
>                 return true;
>         }
>         $content = $revision->getContent( Revision::RAW );
>         $revisionText = ContentHandler::getContentText( $content );
>         if ( $text !== $revisionText ) {
>                 return true;
>         }
>         $wgAlreadyParsed = true;
>         $titleText = $title->getPrefixedText ();
>         $text = "{{siteNotice|$titleText}}" . $text;
> }
> $wgHooks['ParserBeforeStrip'][] = 'onParserBeforeStripSiteNotice';
>
> Then in Template:SiteNotice I put:
>
> {{#ifeq: {{FULLPAGENAME}}|Main Page||<div class="plainlinks"
> style="border:1px solid #a7d7f9; width:100%; font-size: 110%; text-align:
> center; padding: 0.5ex; "><p>This page is an archive.</p></div>}}
>
>
> On Wed, May 3, 2017 at 3:51 AM, Jean Valjean <[hidden email]>
> wrote:
>
>> How do I put up a sitenotice for all pages except one (e.g. Main Page)? I
>> want the main page to have my current content, and all other pages to have
>> a notice saying their content is just an archive.
>>
>> I notice that when I put {{FULLPAGENAME}} in MediaWiki:Sitenotice, it
>> always says "MediaWiki:Sitenotice".
>>
>> Otherwise, I would use an #ifeq.
>>
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l



--
Sébastien Santoro aka Dereckson
http://www.dereckson.be/

_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sitenotice for all pages except one

Greg Rundlett (freephile)
In reply to this post by Jean Valjean
You could use the CSS extension [1] to simply hide the display on the Main
Page. I haven't tested it, but syntax like this on the Main Page should
work (with the CSS extension enabled):

{{ #css:
    #siteNotice { display:none; }
}}


[1] https://www.mediawiki.org/wiki/Extension:CSS

Greg Rundlett
https://eQuality-Tech.com
https://freephile.org

On Wed, May 3, 2017 at 3:51 AM, Jean Valjean <[hidden email]>
wrote:

> How do I put up a sitenotice for all pages except one (e.g. Main Page)? I
> want the main page to have my current content, and all other pages to have
> a notice saying their content is just an archive.
>
> I notice that when I put {{FULLPAGENAME}} in MediaWiki:Sitenotice, it
> always says "MediaWiki:Sitenotice".
>
> Otherwise, I would use an #ifeq.
> _______________________________________________
> MediaWiki-l mailing list
> To unsubscribe, go to:
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Loading...