* (bug 2885) More PHP 5.1 fixes: skin, search, log, undelete
* Fix interlanguage links on special pages when extra namespaces configured
* IP privacy fix for blocklist search on autoblocks
-
+* Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses
=== Caveats ===
/**
* Record an image upload in the upload log and the image table
*/
- function recordUpload( $oldver, $desc, $copyStatus = '', $source = '' ) {
+ function recordUpload( $oldver, $desc, $license, $copyStatus = '', $source = '' ) {
global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
}
if ( $wgUseCopyrightUpload ) {
+ if ( $license != '' ) {
+ $licensetxt = '== ' . wfMsg( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+ }
$textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
'== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
+ "$licensetxt" .
'== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
} else {
- $textdesc = $desc;
+ if ( $license != '' ) {
+ $filedesc = $desc == '' ? '' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n";
+ $textdesc = $filedesc .
+ '== ' . wfMsg ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+ } else {
+ $textdesc = $desc;
+ }
}
$now = $dbw->timestamp();
--- /dev/null
+<?php
+/**
+ * A License class for use on Special:Upload
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ *
+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+
+class Licenses {
+ /**#@+
+ * @access private
+ */
+ /**
+ * @var string
+ */
+ var $msg;
+
+ /**
+ * @var array
+ */
+ var $licenses = array();
+
+ /**
+ * @var string
+ */
+ var $html;
+
+ /**
+ * Constrictor
+ *
+ * @param string $str The string to build the licenses member from, will use
+ * wfMsgForContent( 'licenses' ) if null (default: null)
+ */
+ function Licenses( $str = null ) {
+ // PHP sucks, this should be possible in the constructor
+ $this->msg = is_null( $str ) ? wfMsgForContent( 'licenses' ) : $str;
+ $this->html = '';
+
+ $this->makeLicenses();
+ $tmp = $this->getLicenses();
+ $this->makeHtml( $tmp );
+ }
+
+ /**#@+
+ * @access private
+ */
+ function makeLicenses() {
+ $levels = array();
+ $lines = explode( "\n", $this->msg );
+
+ foreach ( $lines as $line ) {
+ if ( strpos( $line, '*' ) !== 0 )
+ continue;
+ else {
+ list( $level, $line ) = $this->trimStars( $line );
+
+ if ( strpos( $line, '|' ) !== false ) {
+ $obj = new License( $line );
+ // TODO: Do this without using eval()
+ eval( '$this->licenses' . $this->makeIndexes( $levels ) . '[] = $obj;' );
+ } else {
+ if ( $level < count( $levels ) )
+ $levels = array_slice( $levels, count( $levels ) - $level );
+ if ( $level == count( $levels ) )
+ $levels[$level - 1] = $line;
+ else if ( $level > count( $levels ) )
+ $levels[] = $line;
+
+ }
+ }
+ }
+ }
+
+ function trimStars( $str ) {
+ $i = $count = 0;
+
+ while ($str[$i++] == '*')
+ ++$count;
+
+ return array( $count, ltrim( $str, '* ' ) );
+ }
+
+ function makeIndexes( $arr ) {
+ $str = '';
+
+ foreach ( $arr as $item )
+ $str .= '["' . addslashes( $item ) . '"]';
+
+ return $str;
+ }
+
+ function makeHtml( &$tagset, $depth = 0 ) {
+ foreach ( $tagset as $key => $val )
+ if ( is_array( $val ) ) {
+
+ $this->html .= $this->outputOption(
+ $this->msg( $key ),
+ array(
+ 'value' => ''
+ ),
+ $depth
+ );
+ $this->makeHtml( $val, $depth + 1 );
+ } else {
+ $this->html .= $this->outputOption(
+ $this->msg( $val->text ),
+ array(
+ 'value' => $val->template
+ ),
+ $depth
+ );
+ }
+ }
+
+ function outputOption( $val, $attribs = null, $depth ) {
+ $val = str_repeat( /*   */ "\xc2\xa0", $depth ) . $val;
+ return str_repeat( "\t", $depth ) . wfElement( 'option', $attribs, $val ) . "\n";
+ }
+
+ function msg( $str ) {
+ $out = wfMsg( $str );
+ return wfNoMsg( $str, $out ) ? $str : $out;
+ }
+
+ /**#@-*/
+
+ /**
+ * Accessor for $this->licenses
+ *
+ * @return array
+ */
+ function getLicenses() { return $this->licenses; }
+
+ /**
+ * Accessor for $this->html
+ *
+ * @return string
+ */
+ function getHtml() { return $this->html; }
+}
+
+class License {
+ /**
+ * @var string
+ */
+ var $template;
+
+ /**
+ * @var string
+ */
+ var $text;
+
+ /**
+ * Constructor
+ *
+ * @param string $str
+ */
+ function License( $str ) {
+ list( $template, $text ) = explode( '|', $str, 2 );
+
+ $this->template = $template;
+ $this->text = $text;
+ }
+}
+?>
/**
*
*/
-require_once( 'Image.php' );
-require_once( 'MacBinary.php' );
-
+require_once 'Image.php';
+require_once 'MacBinary.php';
+require_once 'Licenses.php';
/**
* Entry point
*/
/**#@+
* @access private
*/
- var $mUploadFile, $mUploadDescription, $mIgnoreWarning, $mUploadError;
+ var $mUploadFile, $mUploadDescription, $mLicense ,$mIgnoreWarning, $mUploadError;
var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion;
var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
var $mOname, $mSessionKey, $mStashed, $mDestFile, $mRemoveTempFile;
$this->mUpload = $request->getCheck( 'wpUpload' );
$this->mUploadDescription = $request->getText( 'wpUploadDescription' );
+ $this->mLicense = $request->getText( 'wpLicense' );
$this->mUploadCopyStatus = $request->getText( 'wpUploadCopyStatus' );
$this->mUploadSource = $request->getText( 'wpUploadSource');
$img = Image::newFromName( $this->mUploadSaveName );
$success = $img->recordUpload( $this->mUploadOldVersion,
$this->mUploadDescription,
+ $this->mLicense,
$this->mUploadCopyStatus,
$this->mUploadSource );
<input type='hidden' name='wpIgnoreWarning' value='1' />
<input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" />
<input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />
+ <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
<input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" />
{$copyright}
<table border='0'>
$sourcefilename = wfMsgHtml( 'sourcefilename' );
$destfilename = wfMsgHtml( 'destfilename' );
$summary = wfMsgWikiHtml( 'fileuploadsummary' );
+
+ $licenses = new Licenses();
+ $license = wfMsgHtml( 'license' );
+ $nolicense = wfMsgHtml( 'nolicense' );
+ $licenseshtml = $licenses->getHtml();
+
$ulb = wfMsgHtml( 'uploadbtn' );
<textarea tabindex='2' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>"
. htmlspecialchars( $this->mUploadDescription ) .
"</textarea>
+ </td></tr><tr>" );
+
+ if ( $licenseshtml != '' ) {
+ $wgOut->addHTML( "
+ <td align='right'>$license:</td>
+ <td align='left'>
+ <select name='wpLicense'>
+ <option value=''>$nolicense</option>
+ $licenseshtml
+ </select>
</td></tr><tr>
- {$source}
+ ");
+ }
+ $wgOut->addHtml( "{$source}
</tr>
<tr><td></td><td align='left'>
<input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" />
'sourcefilename' => 'Source filename',
'destfilename' => 'Destination filename',
+'license' => 'License',
+'nolicense' => 'None',
+
# Image list
#
'imagelist' => 'File list',
if ($i == $m) {
$s = $l[$i];
} else if ($i == $m - 1) {
- $s = $l[$i] . ' ' . $this->getMessage('and') . ' ' . $s;
+ $s = $l[$i] . ' ' . wfMsg('and') . ' ' . $s;
} else {
$s = $l[$i] . ', ' . $s;
}