In light of religious terrorist attacks in Paris, please see Category:blasphemy!

Freedom Porn:free technology/LicenceOnUpload

From Freedom Porn
Jump to: navigation, search

There is an inbuilt system which is suppose to be doing that, but on #mediawiki nobody knows what that system is, and why have one system when we can create our own?

Copyright notice

It is based in many aspects on mediawiki:Extension:CategoryOnUpload by Robert Leverington.

Available under the terms of GNU General Public License 3.0

Produced in the year 2012.
GPLv3
For more information please see Freedom Porn:copyrights.


Installation

  • Create LicenceOnUpload directory in $IP/extensions/
  • Create two files there from #Code section.
  • Edit $IP/includes/specials/SpecialUpload.php
    • Find lines:
                } else {
                        $descriptor['License'] = array(
                                'type' => 'select',
                                'class' => 'Licenses',
                                'section' => 'description',
                                'id' => 'wpLicense',
                                'label-message' => 'license',
                        );
                }
    • Comment out (or delete) everything in the else statement.
  • Either:
    • Place the templates that will be shown in the dropdown menu in Category:licence templates with the name of the licence as the sort order.
    • Create $wgLicenceOnUploadList array in your LocalSettings.php, put the licences information there. # Create $wgLicenceOnUploadDefault which should be equal to the name of the licence used by default.
On this site LocalSettings.php has the following:
require_once("{$IP}/extensions/LicenceOnUpload/LicenceOnUpload.php");
$wgLicenceOnUploadList=array(
        array('text'=>'Free Art License', 'template'=>'free_art'),
        array('text'=>'Public Domain', 'template'=>'public_domain'),
        array('text'=>'GNU Free Document License v1.3', 'template'=>'gfdl'),
        array('text'=>'Creative Commons public domain declaration', 'template'=>'cc0'),
        array('text'=>'Creative Commons Attribution 3.0 Unported', 'template'=>'cc-by-3.0'),
        array('text'=>'Creative Commons ShareAlike 1.0 Generic', 'template'=>'cc
-sa-1.0'),
        array('text'=>'Creative Commons Attribution-ShareAlike 3.0 Unported', 'template'=>'cc-by-sa-3.0'),
        );
$wgLicenceOnUploadDefault='free_art';
$wgLicenceOnUploadAllowNone=true;

Code

LicenceOnUpload.php

<?php
/**
 * LicenceOnUpload Extension
 *
 * Adds a selection box to the upload page for choosing a category.
 *
 * Warning: Should not be enabled on wikis with lots of categories.
 *
 * @ingroup Extensions
 *
 * @link http://www.mediawiki.org/wiki/Extension:LicenceOnUpload
 *
 * @author Robert Leverington <robert@rhl.me.uk>
 * @copyright Copyright © 2008 - 2009 Robert Leverington.
 * @license GNU General Public License 3.0
 */
 
// Ensure accessed via a valid entry point.
if ( !defined( 'MEDIAWIKI' ) ) die( 'Invalid entry point.' );
 
// Register extension credits.
$wgExtensionCredits[ 'other' ][] = array(
	'path'          => __FILE__,
	'name'          => 'LicenceOnUpload',
	'url'           => '',
	'author'        => 'Robert Leverington/VolodyA! V Anarhist',
	'version'       => '1.1.1',
	'decriptionmsg' => 'licenceonupload-desc'
);
 
// Register internationalisation file.
$wgExtensionMessagesFiles[ 'LicenceOnUpload' ] = dirname( __FILE__ ) . '/LicenceOnUpload.i18n.php';
 
// Register required hooks.
$wgHooks[ 'UploadForm:initial'          ][] = 'efLicenceOnUploadForm';
$wgHooks[ 'UploadForm:BeforeProcessing' ][] = 'efLicenceOnUploadProcess';
 
// Initialize configuration variables.
$wgLicenceOnUploadDefault = null;
$wgLicenceOnUploadAllowNone = true;
$wgLicenceOnUploadList = null;
 
/**
 * Adds a licence selection box to the end of the default UploadForm table.
 */
function efLicenceOnUploadForm( $uploadFormObj ) {
	/* Get the database prefix, needed for 1.12 to do custom query. When 1.13
	 * is released it can be removed and the category table used instead.
	 */
	global $wgDBprefix;
 
	/* Load extension messages, currently only used for the label beside the
	 * select box.
	 */
 
 
	/* Begin generation of the form, output the table row, label, open the
	 * select box, and add the default option for not adding a category at all.
	 */
	$lic =
		Xml::openElement( 'tr' ) .
			Xml::openElement( 'td', array( 'align' => 'right' ) ) .
				Xml::label( wfMsg( 'licenceonupload-label' ), 'wpUploadLicence' ) .
			Xml::closeElement( 'td' ) .
			Xml::openElement( 'td' ) .
				Xml::openElement( 'select', array( 'name' => 'wpUploadLicence', 'id' => 'wpUploadLicence' ) );
 
	/* Get whether or not to allow the "none" option.
	 */
	global $wgLicenceOnUploadAllowNone;
 
	/* If permitted output the "none" option.
	 */
	if ( $wgLicenceOnUploadAllowNone ) {
		$lic .= Xml::option( wfMsg( 'licenceonupload-none' ), '#' );
	}
 
	/* Get deault licence, to compare with licence option being output, so the
	 * default licence can be selected.
	 */
	global $wgLicenceOnUploadDefault, $wgLicenceOnUploadList;
 
	if ( !is_array( $wgLicenceOnUploadList ) ) {
		/* Get a database read object.
		 */
		$dbr = wfGetDB( DB_SLAVE );
 
		/* Not the best way of getting what we want, API should be used instead.
		 * However, it works and doesn't work slowly, so it's on the low TODO.
		 *
		 * The intention is to allow people to place their licence templates in the
		 * [[Category:licence templates]] (use <noinclude>). The text provided for
		 * sorting will be used as a display string. So for example if on the page
		 * Template:public_domain you put [[Category:licence templates|PD]] then
		 * the user will see "PD" in their drop down list.
		 */
		$res = $dbr->query( 'SELECT page_title AS template, cl_sortkey_prefix AS text FROM ' . $wgDBprefix . 'categorylinks LEFT JOIN '.$wgDBprefix .'page ON page_id=cl_from WHERE cl_to="licence_templates";' );
 
		/* Generate options for all the templates in the specified category
		 */
		while ( $row = $dbr->fetchObject( $res ) ) {
			/* Add option to output, if it is the default then make it selected too.
			 */
			$lic .= Xml::option( $row->text, $row->template, ( $row->template == $wgLicenceOnUploadDefault ) );
		}
	} else {
		foreach ( $wgLicenceOnUploadList as $licence ) {
			/* Add option to output, if it is the default then make it selected too.
			 */
			$lic .= Xml::option( $licence['text'], $licence['template'], ( $licence['template'] == $wgLicenceOnUploadDefault ) );
		}
	}
 
	/* Close all the open elements, finished generation.
	 */
	$lic .= Xml::closeElement( 'select' ) .
		Xml::closeElement( 'td' ) .
		Xml::closeElement( 'tr' );
 
	$date = "";
 
	$date .= Xml::openElement( 'tr' ) .
		 Xml::openElement( 'td', array( 'align' => 'right' ) ) .
		 Xml::label( wfMsg( 'licenceonupload-date' ), 'wpUploadLicenceDate' ) .
		 Xml::closeElement( 'td' ) .
		 Xml::openElement( 'td' ) .
		 Xml::openElement( 'input', array( 'name' => 'wpUploadLicenceDate', 'id' => 'wpUploadLicenceDate', 'type' => 'date', 'value' => date('Y-m-d'), 'max' => date('Y-m-d') ) ) .
		 Xml::closeElement( 'td' ) .
		 Xml::closeElement( 'tr' );
 
	/* Add the licence selector to the start of the form so that other
	 * extensions can still change stuff and this doesn't override them. But we
	 * can be sure that the table hasn't been closed.
	 */
	$old = $uploadFormObj->uploadFormTextAfterSummary;
	$uploadFormObj->uploadFormTextAfterSummary = $lic . $date . $old;
 
	/* Return true to ensure processing is continued and an exception is not
	 * generated.
	 */
	return true;
}
 
/**
 * Append the category statement to the end of the upload summary.
 */
function efLicenceOnUploadProcess( $uploadFormObj ) {
	/* Get the request object.
	 */
	global $wgRequest;
 
	/* Get the name of the category being added.
	 */
	$lic = $wgRequest->getText( 'wpUploadLicence' );
 
	/* Append the category statement to the end of the upload summary if the
	 * cateogry is not '#' (indicating no category to be added).
	 */
	if ( $lic != '#' ) {
		$uploadFormObj->mComment .= "\n\n" . '{{' . $wgRequest->getText( 'wpUploadLicence' ) . "\n" . '|date=' . $wgRequest->getText( 'wpUploadLicenceDate' ) ."\n" . '}}';
	}
 
	/* Return true to ensure processing is continued and an exception is not
	 * generated.
	 */
	return true;
}

LicenceOnUpload.i18n.php

<?php
/**
 * Internationalisation file for LicenceOnUpload extension.
 *
 * @file
 * @ingroup Extensions
 */
 
$messages = array();
 
/** Message documentation (Message documentation)
 * @author VolodyA! V Anarhist
 */
$messages['qqq'] = array(
	'licenceonupload-desc' => 'Description on [[Special:Version]] of the LicenceOnUpload extension.',
	'licenceonupload-label' => 'The label that is present on the Special:Upload to select the licence',
	'licenceonupload-date' => 'The label for the date',
);
 
/** English
 * @author VolodyA! V Anarhist
 */
$messages['en'] = array(
	'licenceonupload-desc' => 'Allows adding the licences to the uploaded files automatically.',
	'licenceonupload-label' => 'Licence:',
	'licenceonupload-date' => 'Date:',
 
	'licenceonupload-none'  => '-', # Do not translate or duplicate this message to other languages.
);
 
/** Russian
 * @author VolodyA! V Anarhist
 */
$messages['ru'] = array(
	'licenceonupload-desc' => 'Позволяет автоматически добавлять лицензии на страницу описания загружаемых файлов.',
	'licenceonupload-label' => 'Лицензия:',
	'licenceonupload-date' => 'Дата:',
);