Uncyclopedia:Community Wishlist Survey/2022/Page protection status indicators

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Quick implementation[edit source]

Here's a quick 'n' dirty (yet functional) implementation of the aforementioned feature:

// Quick CockLock implementation, per the specs at
// https://en.uncyclopedia.co/w/index.php?title=Forum:Community_Wishlist_Survey_2022&oldid=6141282#Page_protection_status_indicators
// @date 22 January 2022
// @author Jack Phoenix
$wgHooks['BeforePageDisplay'][] = function( OutputPage $out, Skin $skin ) {
	$title = $out->getTitle();
	// XXX PITFALL WARNING
	// Title#isProtected considers NS_SPECIAL protected
	// We *literally* do NOT want that behavior here because IT MAKES NO FUCKING SENSE WHATSOEVER.
	// We care about editability here, and NS_SPECIAL is never editable (even if *parts of*
	// it are, via system messages)
	if ( $title->isProtected() && !$title->inNamespace( NS_SPECIAL ) ) {
		// @note There is no i18n msg for this in core (I think core uses the "Project:Policy"
		// page for everything by default, whereas most real, older wikis have had separate
		// "Project:Deletion policy", "Project:Protection policy", etc. pages for decades).
		// So I just hard-coded in the name of a valid, known-good page.
		$helpPage = Title::makeTitle( NS_PROJECT, 'Protected page' );
		/*
		// Can this even happen? I doubt it, but if it can, uncomment this:
		if ( !$helpPage ) {
			return;
		}
		*/
		// https://upload.wikimedia.org/wikipedia/en/5/59/Padlock.svg
		$imgURLRegular = '//upload.wikimedia.org/wikipedia/en/thumb/5/59/Padlock.svg/20px-Padlock.svg.png';
		$imgURL15x = '//upload.wikimedia.org/wikipedia/en/thumb/5/59/Padlock.svg/30px-Padlock.svg.png';
		$imgURL2x = '//upload.wikimedia.org/wikipedia/en/thumb/5/59/Padlock.svg/40px-Padlock.svg.png';
		$html = '<a href="' . htmlspecialchars( $helpPage->getFullURL(), ENT_QUOTES ) . '">' .
			'<img src="' . $imgURLRegular . '" srcset="' . $imgURL15x . ' 1.5x, ' . $imgURL2x . ' 2x" alt="' .
				$out->msg( 'protectedpage' )->escaped() . '" />' .
			'</a>';
		$newIndicator = [
			// contents can be raw HTML, OOUI widget, etc. - basically anything!
			'cocklock' => $html
		];
		// setIndicators() will merge arrays using the plus operator, hence this oughta be safe...
		$out->setIndicators( $newIndicator );
	}
};

I've tested this locally on my MediaWiki 1.35 box and it works, but I see no reason why this wouldn't work as-is on Uncyc's current, woefully outdated MW 1.32 since OutputPage#setIndicators was introduced in MW 1.25.

As you can see, this example:

  • hardcodes the image link target to Uncyclopedia:Protected page
  • has support for HiDPI
  • uses commons:File:Padlock.svg as the image (this can and should be changed, I doubt we want to be hotlinking a Commons image on all of our protected pages...)
  • lacks a proper title attribute for the image

This is indeed a very quick, pure PHP implementation that can be just slapped into Uncyc's settings file and we can call it a day, but if needed, I can package this into a "proper" MediaWiki extension with an appropriate extension.json file and whatnot.

Either way, it works and adds a lock icon to any and all protected pages. --Sai.png Jack Phoenix, professional killer admin (Whine?) (Wikia ads) 11:30, 22 January 2022 (UTC)

This is now finally live.
I decided to extension-ify the thing for the ease of maintenance and whatnot. The source code is available at https://git.legoktm.com/ashley/mediawiki-extensions-CockLock and it supports MediaWiki 1.31+. (Turns out that the original version, posted above, was fully functional on ancient MediaWikis like our current one, but the extension-ified version, version 1.0, was not because I made the image customizable and used a method that had a different name prior to MediaWiki 1.34. This is now fixed in version 1.1 of CockLock.)
The lock icon image (currently just a copy of File:Padlock.svg) is editable via File:CockLock icon.svg and the help page to which it links is editable via MediaWiki:Cocklock-help-page.
Please let me know your thoughts etc. on this. --Sai.png Jack Phoenix, professional killer admin (Whine?) (Wikia ads) 12:02, 28 February 2022 (UTC)