Jump to content

Extension:SelectionOnUpload/it

From mediawiki.org
Manuale sulle Estensioni MediaWiki
SelectionOnUpload
Stato della release: non mantenuto
Implementazione Interfaccia utente
Descrizione Adds a selection box to the upload page for choosing something
Autore(i) Alessandra Bilardi (Bilardidiscussione)
Versione 0.1 (2009-09-29)
MediaWiki 1.15.1
Licenza GPL
Scaricare Nessun collegamento

$wgSelectionOnUploadList
$wgSelectionOnUploadLabel
$wgSelectionOnUploadStart

$wgSelectionOnUploadEnd

Introduction

[edit]

SelectionOnUpload deriva da Extension:CategoryOnUpload. Aggiunge un box di selezione personalizzabile alla pagina di caricamento dei file, perciò questa estensione potrebbe rimpiazzare Extension:CategoryOnUpload con la seguente configurazione:

$wgSelectionOnUploadList = "your categories";
$wgSelectionOnUploadLabel = "Category: ";
$wgSelectionOnUploadStart = "[[Category:";
$wgSelectionOnUploadEnd = "]]";

La configurazione dello screenshot è:

$wgSelectionOnUploadList = "paper tutorial seminar webinar image";
$wgSelectionOnUploadLabel = "Type: ";
$wgSelectionOnUploadStart = "{{box|type=";
$wgSelectionOnUploadEnd = "}}";

Commenti & Feedback

[edit]

Commenti e Feedback nella pagina di discussione (in inglese).

Settings

[edit]

In LocalSettings.php aggiungere il codice che segue:

// add SelectionOnUpload
// list 
$wgSelectionOnUploadList = "your_words wordz word5";
// selection label
$wgSelectionOnUploadLabel = "Your label: ";
// wiki code before word choice
$wgSelectionOnUploadStart = "Your start--> ";
// wiki code after word choice
$wgSelectionOnUploadEnd = " <--Your end";

require_once("extensions/SelectionOnUpload/SelectionOnUpload.php");

SelectionOnUpload.php

[edit]
<?php

/**
 * SelectionOnUpload Extension
 * Adds a selection box to the upload page for choosing something
 * This interface is a derivation of CategoryOnUpload 
 */

// Ensure accessed via a valid entry point.
if( !defined( 'MEDIAWIKI' ) ) die( 'Invalid entry point.' );

// Register extension credits.
$wgExtensionCredits[ 'other' ][] = array(
	'name' => 'SelectionOnUpload',
	'author' => '[http://www.mediawiki.org/wiki/User:Bilardi Alessandra Bilardi]',
	'description'   => 'Prompts a user to select from a list when uploading a file',
	'url' => 'http://www.mediawiki.org/wiki/Extension:SelectionOnUpload',
	'version'       => '0.1',
);

// Register required hooks.
$wgHooks[ 'UploadForm:initial'          ][] = 'efSelectionOnUploadForm';
$wgHooks[ 'UploadForm:BeforeProcessing' ][] = 'efSelectionOnUploadProcess';

// Initialize configuration variables in LocalSettings.php.. example :
/**
$wgSelectionOnUploadList = "your_words wordz word5";
$wgSelectionOnUploadLabel = "Your label: ";
$wgSelectionOnUploadStart = "Your start--> ";
$wgSelectionOnUploadEnd = " <--Your end";
*/

/**
 * Adds list selection box to the end of the default UploadForm table.
 */
function efSelectionOnUploadForm( $uploadFormObj ) {

	/* Load extension messages, currently only used for the label beside the
	 * select box.
	 */
	global $wgSelectionOnUploadLabel;

	/* Begin generation of the form, output the table row, label, open the
	 * select box, and add the default option for not adding the list at all.
	 */
	$cat =
		Xml::openElement( 'tr' ) .
			Xml::openElement( 'td', array( 'align' => 'right' ) ) .
				Xml::label($wgSelectionOnUploadLabel, 'wpUploadSelection') .
			Xml::closeElement( 'td' ) .
			Xml::openElement( 'td' ) .
				Xml::openElement( 'select', array( 'name' => 'wpUploadSelection', 'id' => 'wpUploadSelection' ) );

	/* Get list
	 */
	global $wgSelectionOnUploadList;
	$res = explode(" ", $wgSelectionOnUploadList);

	/* Generate an option for each of the words in the global variable and add. A
	 * title object could be generated for each of the words so that the
	 * hacky replacement of '_' to ' ' could be removed, but it seams a waste
	 * of resources.  If this becomes an issue simply remove the # comments and
	 * comment out the first line.
	 */
	foreach( $res as $row) {

		$text   = str_replace( '_', ' ', $row );

		/* Add option to output, if it is the default then make it selected too.
		 */
		$cat .= Xml::option( $text, $row, ( $text == $wgSelectionOnUploadList ) );

	}

	/* Close all the open elements, finished generation.
	 */
	$cat .=
				Xml::closeElement( 'select' ) .
			Xml::closeElement( 'td' ) .
		Xml::closeElement( 'tr' );

	/* Add the list 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 = $cat . $old;

	/* Return true to ensure processing is continued and an exception is not
	 * generated.
	 */
	return true;

}

/**
 * Append the list statement to the end of the upload summary.
 */
function efSelectionOnUploadProcess( $uploadFormObj ) {

	/* Get the request object.
	 */
	global $wgRequest,$wgSelectionOnUploadStart,$wgSelectionOnUploadEnd;

	/* Get the name of the list being added.
	 */
	$cat = $wgRequest->getText( 'wpUploadSelection' );

	/* Append the list statement to the end of the upload summary if the
	 * list is not '#' (indicating no list to be added).
	 */
	if( $cat != '#' ) {
		$uploadFormObj->mComment .= "\n" . $wgSelectionOnUploadStart . $wgRequest->getText( 'wpUploadSelection' ) . $wgSelectionOnUploadEnd;
	}

	/* Return true to ensure processing is continued and an exception is not
	 * generated.
	 */
	return true;

}