52°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • Hiding text from non-registered users in MediaWiki

    September 2, 2008

    In a semi-private wiki I maintain, we are using whitelisting to make some pages visible to the public but not others. Authentication is done off of an IMAP server, and only registered users have full access tothe wiki. We still run in to the occasional page where most info should be public, but only certain bits should not appear to the public. Things like server passwords, or phone numbers should be hidden except to registered users. I created this plugin so that we can hide bits and pieces of pages from non-registered users, while making the rest of the page public. Just add a <private> tag around the text you want hidden, and you're good to go.

    Copy this code to a "extensions/PrivateBlocks.php", and add the following line to LocalSettings.php:

    require_once( 'extensions/PrivateBlocks.php' );
    

    PrivateBlocks.php

    <?php
    
    $wgExtensionFunctions[] = "wfPrivateBlocks";
    $wgExtensionCredits['parserhook'][] = array(
            'name' => 'PrivateBlocks',
            'author' => 'Aaron Parecki',
            'description' => 'Adds <nowiki><private></nowiki> tag for hiding text to non-registered users',
            'url' => 'http://blog.neverusethisfont.com/2008/09/hiding-text-from-non-registered-users-in-mediawiki/'
    );
    
    function wfPrivateBlocks() {
        global $wgParser;    
        $wgParser->setHook( "private", "privateBlock" );
    }
    
    # The callback function for converting the input text to HTML output
    function privateBlock($input, $args)
    {
        if( $_SESSION['wsUserID'] == 0 )
        {
            return "";
        } 
        else
        {
            return $input;
        }
    }
    
    ?>
    
    Tue, Sep 2, 2008 6:10pm -07:00 #mediawiki #plugin #wiki
Posted in /articles

Hi, I'm Aaron Parecki, Director of Identity Standards at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming. (detailed bio)

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Director of Identity Standards at Okta
  • IndieWebCamp Founder
  • OAuth WG Editor
  • OpenID Board Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2025 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv