Tag Archives: MediaWiki

Delete old revisions in MediaWiki

A course instructor just asked if he could delete revision histories so he could reuse group project pages in his wiki without exposing the previous history to the next group of users. Generally deleting anything in a MediaWiki is quite difficult, I knew this may have been possible via a command line maintenance script DeleteOldRevisions.php but this was not the greatest solution (who wants to be bothered each term to run this) after a Google found this great extension SpecialDeleteOldRevisions2 which did the trick and then some . Allows wild card revision deletes along with date range revision deletes. Very handy for any stand alone course wiki installs.

delete old mediawiki revisions

Direct upload to YouTube through MediaWiki

Might be of interest for those who want to get more content into their YouTube EDU account.

We have have been experimenting with ways to get content into YouTube from a single app with a trusted user base. So that meant either MediaWiki or WordPress (only two apps we have with CWL right now). WordPress was the first choice but there was nothing out there, eventually found this great little extension from Travis Derouin of http://www.wikihow.com called YouTubeAuthSub which takes advantage of the YouTube AuthSub/ClientLogin features.

After quite a few email exchanges with Travis I managed to get it working (discovered someone mangled the SVN on MediaWiki.org hosting his extension without his knowledge) ended up finding a working copy from the Wikia SVN in the mean time…


You probably do not want all users in your wiki to access this extension so I recommend creating a YouTube group on your wiki install and assigning users to that group through the Special:UserRights . To add a group to MediaWiki add something like this to your LocalSettings.php:

## YouTube Namespace
define("NS_YOUTUBE", 116);
define("NS_YOUTUBE_TALK", 117);

$wgExtraNamespaces[NS_YOUTUBE] = "YouTube";
$wgExtraNamespaces[NS_YOUTUBE_TALK] = "YouTube_talk";

## Subpages has to be enabled explictly.
$wgNamespacesWithSubpages[NS_YOUTUBE] = false;
$wgNamespacesWithSubpages[NS_YOUTUBE_TALK] = false;

$wgContentNamespaces[] = NS_YOUTUBE;

You will also need to add this to the extension YouTubeAuthSub/YouTubeAuthSub_body.php after the $this->setHeaders(); in the function execute()

# Check permissions
/// OLT BEGIN ///
// Make sure the user is in the youtube OR sysop group
$isYouTubeEduGroup = ( in_array('youtube', $wgUser->getGroups()) || in_array('sysop', $wgUser->getGroups()) );
if(!$isYouTubeEduGroup ) {

if( !$wgUser->isLoggedIn() ) {
$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
$wgOut->showErrorPage( 'badaccess', 'badaccess-groups', $result = array('YouTube') );
/// OLT END ///

Possible Bugs

We recently had issues with some accounts because of a change in the YouTube API which they did not warn users against! They basically decided to add “=” into some of the tokens. The original code used a split() to extract tokens so this broke. I recommend doing something really ugly like this to avoid failed tokens if you are having issues (for some reason not all accounts have issues).

Look for the foreach ($lines as $line) { in the YouTubeAuthSub_body.php and add and comment the following:

/// OLT BEGIN ///
// Check if string contains Auth
$authPat = '/^Auth/';
$token = substr($line, 5);

// Check if string contains YouTubeUser
$userPat = '/^YouTubeUser/';
if(!empty($userMatch)) {
$YouTubeUser = substr($line, 12);

/// OLT END ///

** This does not work. YouTube API decided to add = into token strings so split breaks.

$params = split("=", $line);

switch ($params[0]) {
case "Auth":
$token = $params[1];
case "YouTubeUser":
$YouTubeUser = $params[1];


Other change YouTube change the client login URL look for the:

$result = wfSpecialYouTubePost("https://www.google.com/youtube/accounts/ClientLogin?"

and change to:

$result = wfSpecialYouTubePost("https://www.google.com/accounts/ClientLogin?"

To Do
Add ability to add to playlists within the YouTube account, not sure when I will get to this but it is a “to do” maybe someone will to do it first 🙂

That’s it.