From: Ævar Arnfjörð Bjarmason Date: Mon, 29 Aug 2005 16:43:48 +0000 (+0000) Subject: * Support for a license selection box on Special:Upload, configurable from MediaWiki... X-Git-Tag: 1.6.0~1761 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=33db62d428d13aa0464eb03341c9916fc094bc74;p=lhc%2Fweb%2Fwiklou.git * Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bc3a62ff84..b966582300 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -71,7 +71,7 @@ fully support the editing toolbar, but was found to be too confusing. * (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 === diff --git a/includes/Image.php b/includes/Image.php index ecae80a74c..bbf1d428c9 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -1253,7 +1253,7 @@ class Image /** * 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; @@ -1272,11 +1272,21 @@ class Image } 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(); diff --git a/includes/Licenses.php b/includes/Licenses.php new file mode 100644 index 0000000000..1925e8690b --- /dev/null +++ b/includes/Licenses.php @@ -0,0 +1,168 @@ + + * @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; + } +} +?> diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index c17fea2aed..6919fd2112 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -8,9 +8,9 @@ /** * */ -require_once( 'Image.php' ); -require_once( 'MacBinary.php' ); - +require_once 'Image.php'; +require_once 'MacBinary.php'; +require_once 'Licenses.php'; /** * Entry point */ @@ -29,7 +29,7 @@ class UploadForm { /**#@+ * @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; @@ -53,6 +53,7 @@ class UploadForm { $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'); @@ -281,6 +282,7 @@ class UploadForm { $img = Image::newFromName( $this->mUploadSaveName ); $success = $img->recordUpload( $this->mUploadOldVersion, $this->mUploadDescription, + $this->mLicense, $this->mUploadCopyStatus, $this->mUploadSource ); @@ -490,6 +492,7 @@ class UploadForm { mSessionKey ) . "\" /> mUploadDescription ) . "\" /> + mLicense ) . "\" /> mDestFile ) . "\" /> {$copyright} @@ -538,6 +541,12 @@ class UploadForm { $sourcefilename = wfMsgHtml( 'sourcefilename' ); $destfilename = wfMsgHtml( 'destfilename' ); $summary = wfMsgWikiHtml( 'fileuploadsummary' ); + + $licenses = new Licenses(); + $license = wfMsgHtml( 'license' ); + $nolicense = wfMsgHtml( 'nolicense' ); + $licenseshtml = $licenses->getHtml(); + $ulb = wfMsgHtml( 'uploadbtn' ); @@ -576,8 +585,20 @@ class UploadForm { + " ); + + if ( $licenseshtml != '' ) { + $wgOut->addHTML( " + + - {$source} + "); + } + $wgOut->addHtml( "{$source}
$license: +
diff --git a/languages/Language.php b/languages/Language.php index 1da727124f..7515de76dd 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1032,6 +1032,9 @@ created and by whom, and anything else you may know about it. If this is an imag 'sourcefilename' => 'Source filename', 'destfilename' => 'Destination filename', +'license' => 'License', +'nolicense' => 'None', + # Image list # 'imagelist' => 'File list', @@ -2734,7 +2737,7 @@ class Language { 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; }