User:Charlie Huggard/MediaWiki Hacks

From Wikipedia, the free encyclopedia

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!

Contents

[edit] Short URL

Before I saw the instructions at metawikipedia:Using a very short URL, I did the following to get rid of index.php URLs:

  • 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:
 DefaultType application/x-httpd-php
  • LocalSettings.php - I changed the lines to look like this:
 $wgScript           = "$wgScriptPath/wiki";
 $wgRedirectScript   = "$wgScriptPath/goto";

[edit] Userpage Edit Restrictions

[edit] 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.

  • includes/DefaultSettings.php - I added the following lines
 $wgOnlyUserEditUserPage = false;
 $wgGroupPermissions['sysop']['editalluserpages'] = true;
I set the $wgOnlyUserEditUserPage to true in LocalSettings.php
  • includes/Title.php - I changed the following functions to read as shown
 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');
      }
 }
 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');
      }
 }

[edit] Version 2

When I upgraded to MediaWiki 1.6.5 I came up with a slightly better way.

  • LocalSettings.php - I added the following lines
 $wgOnlyUserEditUserPage = true;
 $wgGroupPermissions['sysop']['editalluserpages'] = true;
  • includes/Title.php - I added the following to the userCan function:
 # 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;
 }

[edit] 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:

  • includes/SkinTemplate.php - I changed the text function to 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] );
      }
 }
  • LocalSettings.php - I added a new array mapping numeric namespace numbers to their non-default logos
 $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",
 );

[edit] 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";

[edit] Others Extensions/Hacks I use