Extension:SelectionOnUpload
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. |
SelectionOnUpload Release status: unmaintained |
|
---|---|
Implementation | User interface |
Description | Adds a selection box to the upload page for choosing something |
Author(s) | Alessandra Bilardi (Bilarditalk) |
Latest version | 0.1 (2009-09-29) |
MediaWiki | 1.15.1 |
License | GPL |
Download | No link |
$wgSelectionOnUploadEnd |
|
Introduction
editSelectionOnUpload is a derivation of Extension:CategoryOnUpload. It adds a custom selection box to the upload page, so that this extension could replace Extension:CategoryOnUpload with this configuration:
$wgSelectionOnUploadList = "your categories";
$wgSelectionOnUploadLabel = "Category: ";
$wgSelectionOnUploadStart = "[[Category:";
$wgSelectionOnUploadEnd = "]]";
Configuration about screenshot image is:
$wgSelectionOnUploadList = "paper tutorial seminar webinar image";
$wgSelectionOnUploadLabel = "Type: ";
$wgSelectionOnUploadStart = "{{box|type=";
$wgSelectionOnUploadEnd = "}}";
Comments & Feedback
editComments & Feedback discussion page.
Settings
editIn LocalSettings.php add the following code:
// 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;
}