User:Charlie Huggard/MediaWiki Hacks

As promised by my user page, this page will contains changes made to MediaWiki software on cirl.missouri.edu. Most of these changes were made for MediaWiki version 1.5.6 on a Gentoo machine. I did recently upgrade to 1.6.5 (with a tad bit of difficulty >_<). Unfortunately I did modify core code in some of these, so I may be downloading 1.7 and attempting modifications in a nicer way in the near future. All of these should be considered to be dirty dirty hacks. Let me know what you think on my talk pages!

Short URL
Before I saw the instructions at Using a very short URL, I did the following to get rid of index.php URLs: DefaultType application/x-httpd-php $wgScript          = "$wgScriptPath/wiki"; $wgRedirectScript  = "$wgScriptPath/goto";
 * Hard Link - I created hard links from index.php and redirect.php to wiki and goto respectively.
 * .htaccess - To my .htaccess file I added the line:
 * LocalSettings.php - I changed the lines to look like this:

Version 1
I felt that users of the CIRL wiki should be the only ones who should be able to edit their User pages. I guess there are extensions now that do this, but when I was looking I didn't find one. $wgOnlyUserEditUserPage = false; $wgGroupPermissions['sysop']['editalluserpages'] = true;
 * includes/DefaultSettings.php - I added the following lines
 * I set the $wgOnlyUserEditUserPage to true in LocalSettings.php

function userCanEdit { global $wgOnlyUserEditUserPage; if(NS_USER == $this->mNamespace && $wgOnlyUserEditUserPage) { global $wgUser; return ($wgUser->isAllowed('editalluserpages')|| $wgUser->getName==$this->getText); } else { return $this->userCan('edit'); } }
 * includes/Title.php - I changed the following functions to read as shown

function userCanMove { global $wgOnlyUserEditUserPage; if(NS_USER == $this->mNamespace && $wgOnlyUserEditUserPage) { global $wgUser; return ($wgUser->isAllowed('editalluserpages')|| $wgUser->getName==$this->getText); } else { return $this->userCan('move'); } }

Version 2
When I upgraded to MediaWiki 1.6.5 I came up with a slightly better way. $wgOnlyUserEditUserPage = true; $wgGroupPermissions['sysop']['editalluserpages'] = true;
 * LocalSettings.php - I added the following lines

# Protect User Pages from Editing global $wgOnlyUserEditUserPage; if( $wgOnlyUserEditUserPage      && NS_USER == $this->mNamespace       && !preg_match('/^'.preg_quote($wgUser->getName, '/').'/', $this->mTextform)       && !$wgUser->isAllowed('editalluserpages')       && ( $action == 'move' || $action='edit' ) ) { wfProfileOut( $fname ); return false; }
 * includes/Title.php - I added the following to the userCan function:

Custom Namespace Logos
If you notice on the cirl.missouri.edu site the User namespace has a different logo than the main namespace. (There is also a sandbox namespace that is only accessible to registered users that has a 3rd logo). To accomplish this I did the following: function text( $str ) { global $wgTitle, $wgNamespaceLogos; if('logopath'==$str && isset($wgNamespaceLogos[$wgTitle->getNamespace])) { echo htmlspecialchars( $wgNamespaceLogos[$wgTitle->getNamespace] ); } else { echo htmlspecialchars( $this->data[$str] ); } }  $wgNamespaceLogos = array (       NS_SANDBOX => "$wgStylePath/common/images/wiki_sandbox.png",       NS_SANDBOX_TALK => "$wgStylePath/common/images/wiki_sandbox.png",       NS_USER => "$wgStylePath/common/images/wiki_user.png",       NS_USER_TALK => "$wgStylePath/common/images/wiki_user.png",  );
 * includes/SkinTemplate.php - I changed the text function to the following
 * LocalSettings.php - I added a new array mapping numeric namespace numbers to their non-default logos

Calendar Enhancements
I used Cdamian's Calendar Extension for upcoming events. I did however got sick of Calendar pages showing up in the wanted pages so I changed the query in includes/SpecialWantedpages.php to "SELECT 'Wantedpages' AS type,       pl_namespace AS namespace,       pl_title AS title,       COUNT(*) AS value  FROM $pagelinks  LEFT JOIN $page  ON pl_namespace=page_namespace AND pl_title=page_title  WHERE page_namespace IS NULL  AND pl_title not like 'Calendar/%'  GROUP BY pl_namespace,pl_title  HAVING COUNT(*) > 1";

Others Extensions/Hacks I use

 * Hidden pages
 * WikiTeX