Extension:CCAgreement

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
CCAgreement

Release status:Extension status beta

ImplementationTemplate:Extension#type User interface
DescriptionTemplate:Extension#description Agreement with Creative Commons licencing
Author(s)Template:Extension#username Josef Martiňák (Jossmarttalk)
Latest versionTemplate:Extension#version 0.1.1 (2012-06-21)
MediaWikiTemplate:Extension#mediawiki 1.22
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GPL
Download see here
ExampleTemplate:Extension#example test signup
Hooks usedTemplate:Extension#hook
BeforePageDisplayManual:Hooks/BeforePageDisplay

Translate the CCAgreement extension if it is available at translatewiki.net

Check usage and version matrix.

The CCAgreement extension changes the look of the SignUp page. New user confirms then by clicking the submit button an agreement with Creative Commons licencing.

It is developed for www.wikiskripta.eu and www.wikilectures.eu and there are currently three language versions: Czech, English and German.

Installation[edit]

  • Create folder extensions/CCAgreement and put in the CCAgreement.php and CCAgreement.i18n.php.
  • In LocalSettings.php add this line
require_once( "$IP/extensions/CCAgreement/CCAgreement.php" );

Code[edit]

CCAgreement.php[edit]

<?php

####################################################################################################
# Extension changes the look of the SignUp page. New user confirms by clicking  		   
# the submit button an agreement with Creative Commons licencing.                   		
####################################################################################################

if (!defined('MEDIAWIKI')) {
echo <<<EOT
	To install my extension, put the following line in LocalSettings.php:
	require_once( "\$IP/extensions/CCAgreement/CCAgreement.php" );
EOT;
exit( 1 );
}

$wgExtensionCredits['specialpage'][] = array(
	'name' => 'CCAgreement',
	'author' => 'Josef Martiňák',
	'url' => "https://www.mediawiki.org/wiki/Extension:CCAgreement",
	'descriptionmsg' => 'cca-desc',
	'version' => '0.1.1',
);

 
$dir = dirname(__FILE__) . '/';

 
$wgExtensionMessagesFiles['CCAgreement'] = $dir . 'CCAgreement.i18n.php';
$wgHooks['BeforePageDisplay'][] = 'AddLicencing';


function AddLicencing(&$out,&$skin) { 
	$context = $out;
	$title = $context->getTitle();
	if($title->isSpecialPage() && SpecialPage::resolveAlias($title->getBaseText()) == "Userlogin"){
		$query = $context->getRequest()->getQueryValues();
		if(!empty($query["type"]) && $query["type"] == "signup"){
 
			// Change submit button text and position
			$out->mBodytext = preg_replace("/(id=\"wpCreateaccount\"[^>]*)value=\"[^\"]*\"/",
				"$1value=\"".$context->msg('cca-submit-button')->text()."\"",$out->mBodytext);
			 
			// Append the licence iframe and text message
			$tmp = "\n<br/>";
			if($context->getLanguage()->getCode() == "cs") {
				$tmp .= "<iframe src= \"http://creativecommons.org/licenses/by/3.0/cz/\" ";
				$tmp .= "width=\"800\" height=\"1150\"></iframe>\n";
			}
			else {
				$tmp .= "<iframe src= \"http://creativecommons.org/licenses/by/3.0/cz/deed.en\" ";
				$tmp .= "width=\"800\" height=\"1150\" ></iframe>\n";
			}
			$tmp .= "<br/><br/>".$context->msg('cca-agreement')->parse()."<br/><br/>\n";
			$out->mBodytext = preg_replace("/(<div class=\"mw-submit\">)/","$tmp$1",$out->mBodytext);
		}
	}
	return true;
}

CCAgreement.i18n.php[edit]

<?php

$messages = array();

/* *** English *** */
$messages['en'] = array(
	'cca-desc' => 'Assures an agreement to Creative Commons licencing',
	'cca-submit-button' => 'I AGREE - create account',
	'cca-agreement' => 'I will release all my texts under the licence above. Details can be found at [[{{SITENAME}}:Author Law]].',
);
 
/* *** Czech *** */
$messages['cs'] = array(
	'cca-desc' => 'Potvrzení souhlasu s licencí Creative Commons',
	'cca-submit-button' => 'SOUHLASÍM - vytvořit účet',
	'cca-agreement' => 'Všechny své texty uvolním za podmínek výše uvedené licence. Další podrobnosti jsou na stránce [[{{SITENAME}}:Autorské právo]].',
);

/* *** German *** */
$messages['de'] = array(
	'cca-desc' => 'Stellt die Zustimmung zur Lizenzierung gemäß Creative Commons sicher',
	'cca-submit-button' => 'Ich stimme zu − Benutzerkonto erstellen',
	'cca-agreement' => 'Ich werde alle meine Beiträge gemäß obig benannter Lizenz veröffentlichen. Weitere Einzelheiten sind auf der Seite [[{{SITENAME}}:Autorenrichtlinie]] verfügbar.',
);