Index: trunk/phase3/includes/Licenses.php |
— | — | @@ -0,0 +1,168 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A License class for use on Special:Upload |
| 5 | + * |
| 6 | + * @package MediaWiki |
| 7 | + * @subpackage SpecialPage |
| 8 | + * |
| 9 | + * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 10 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +class Licenses { |
| 14 | + /**#@+ |
| 15 | + * @access private |
| 16 | + */ |
| 17 | + /** |
| 18 | + * @var string |
| 19 | + */ |
| 20 | + var $msg; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var array |
| 24 | + */ |
| 25 | + var $licenses = array(); |
| 26 | + |
| 27 | + /** |
| 28 | + * @var string |
| 29 | + */ |
| 30 | + var $html; |
| 31 | + |
| 32 | + /** |
| 33 | + * Constrictor |
| 34 | + * |
| 35 | + * @param string $str The string to build the licenses member from, will use |
| 36 | + * wfMsgForContent( 'licenses' ) if null (default: null) |
| 37 | + */ |
| 38 | + function Licenses( $str = null ) { |
| 39 | + // PHP sucks, this should be possible in the constructor |
| 40 | + $this->msg = is_null( $str ) ? wfMsgForContent( 'licenses' ) : $str; |
| 41 | + $this->html = ''; |
| 42 | + |
| 43 | + $this->makeLicenses(); |
| 44 | + $tmp = $this->getLicenses(); |
| 45 | + $this->makeHtml( $tmp ); |
| 46 | + } |
| 47 | + |
| 48 | + /**#@+ |
| 49 | + * @access private |
| 50 | + */ |
| 51 | + function makeLicenses() { |
| 52 | + $levels = array(); |
| 53 | + $lines = explode( "\n", $this->msg ); |
| 54 | + |
| 55 | + foreach ( $lines as $line ) { |
| 56 | + if ( strpos( $line, '*' ) !== 0 ) |
| 57 | + continue; |
| 58 | + else { |
| 59 | + list( $level, $line ) = $this->trimStars( $line ); |
| 60 | + |
| 61 | + if ( strpos( $line, '|' ) !== false ) { |
| 62 | + $obj = new License( $line ); |
| 63 | + // TODO: Do this without using eval() |
| 64 | + eval( '$this->licenses' . $this->makeIndexes( $levels ) . '[] = $obj;' ); |
| 65 | + } else { |
| 66 | + if ( $level < count( $levels ) ) |
| 67 | + $levels = array_slice( $levels, count( $levels ) - $level ); |
| 68 | + if ( $level == count( $levels ) ) |
| 69 | + $levels[$level - 1] = $line; |
| 70 | + else if ( $level > count( $levels ) ) |
| 71 | + $levels[] = $line; |
| 72 | + |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + function trimStars( $str ) { |
| 79 | + $i = $count = 0; |
| 80 | + |
| 81 | + while ($str[$i++] == '*') |
| 82 | + ++$count; |
| 83 | + |
| 84 | + return array( $count, ltrim( $str, '* ' ) ); |
| 85 | + } |
| 86 | + |
| 87 | + function makeIndexes( $arr ) { |
| 88 | + $str = ''; |
| 89 | + |
| 90 | + foreach ( $arr as $item ) |
| 91 | + $str .= '["' . addslashes( $item ) . '"]'; |
| 92 | + |
| 93 | + return $str; |
| 94 | + } |
| 95 | + |
| 96 | + function makeHtml( &$tagset, $depth = 0 ) { |
| 97 | + foreach ( $tagset as $key => $val ) |
| 98 | + if ( is_array( $val ) ) { |
| 99 | + |
| 100 | + $this->html .= $this->outputOption( |
| 101 | + $this->msg( $key ), |
| 102 | + array( |
| 103 | + 'value' => '' |
| 104 | + ), |
| 105 | + $depth |
| 106 | + ); |
| 107 | + $this->makeHtml( $val, $depth + 1 ); |
| 108 | + } else { |
| 109 | + $this->html .= $this->outputOption( |
| 110 | + $this->msg( $val->text ), |
| 111 | + array( |
| 112 | + 'value' => $val->template |
| 113 | + ), |
| 114 | + $depth |
| 115 | + ); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + function outputOption( $val, $attribs = null, $depth ) { |
| 120 | + $val = str_repeat( /*   */ "\xc2\xa0", $depth ) . $val; |
| 121 | + return str_repeat( "\t", $depth ) . wfElement( 'option', $attribs, $val ) . "\n"; |
| 122 | + } |
| 123 | + |
| 124 | + function msg( $str ) { |
| 125 | + $out = wfMsg( $str ); |
| 126 | + return wfNoMsg( $str, $out ) ? $str : $out; |
| 127 | + } |
| 128 | + |
| 129 | + /**#@-*/ |
| 130 | + |
| 131 | + /** |
| 132 | + * Accessor for $this->licenses |
| 133 | + * |
| 134 | + * @return array |
| 135 | + */ |
| 136 | + function getLicenses() { return $this->licenses; } |
| 137 | + |
| 138 | + /** |
| 139 | + * Accessor for $this->html |
| 140 | + * |
| 141 | + * @return string |
| 142 | + */ |
| 143 | + function getHtml() { return $this->html; } |
| 144 | +} |
| 145 | + |
| 146 | +class License { |
| 147 | + /** |
| 148 | + * @var string |
| 149 | + */ |
| 150 | + var $template; |
| 151 | + |
| 152 | + /** |
| 153 | + * @var string |
| 154 | + */ |
| 155 | + var $text; |
| 156 | + |
| 157 | + /** |
| 158 | + * Constructor |
| 159 | + * |
| 160 | + * @param string $str |
| 161 | + */ |
| 162 | + function License( $str ) { |
| 163 | + list( $template, $text ) = explode( '|', $str, 2 ); |
| 164 | + |
| 165 | + $this->template = $template; |
| 166 | + $this->text = $text; |
| 167 | + } |
| 168 | +} |
| 169 | +?> |
Property changes on: trunk/phase3/includes/Licenses.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 170 | + native |
Added: svn:keywords |
2 | 171 | + Author Date Id Revision |
Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -8,9 +8,9 @@ |
9 | 9 | /** |
10 | 10 | * |
11 | 11 | */ |
12 | | -require_once( 'Image.php' ); |
13 | | -require_once( 'MacBinary.php' ); |
14 | | - |
| 12 | +require_once 'Image.php'; |
| 13 | +require_once 'MacBinary.php'; |
| 14 | +require_once 'Licenses.php'; |
15 | 15 | /** |
16 | 16 | * Entry point |
17 | 17 | */ |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | /**#@+ |
31 | 31 | * @access private |
32 | 32 | */ |
33 | | - var $mUploadFile, $mUploadDescription, $mIgnoreWarning, $mUploadError; |
| 33 | + var $mUploadFile, $mUploadDescription, $mLicense ,$mIgnoreWarning, $mUploadError; |
34 | 34 | var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion; |
35 | 35 | var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload; |
36 | 36 | var $mOname, $mSessionKey, $mStashed, $mDestFile, $mRemoveTempFile; |
— | — | @@ -53,6 +53,7 @@ |
54 | 54 | $this->mUpload = $request->getCheck( 'wpUpload' ); |
55 | 55 | |
56 | 56 | $this->mUploadDescription = $request->getText( 'wpUploadDescription' ); |
| 57 | + $this->mLicense = $request->getText( 'wpLicense' ); |
57 | 58 | $this->mUploadCopyStatus = $request->getText( 'wpUploadCopyStatus' ); |
58 | 59 | $this->mUploadSource = $request->getText( 'wpUploadSource'); |
59 | 60 | |
— | — | @@ -281,6 +282,7 @@ |
282 | 283 | $img = Image::newFromName( $this->mUploadSaveName ); |
283 | 284 | $success = $img->recordUpload( $this->mUploadOldVersion, |
284 | 285 | $this->mUploadDescription, |
| 286 | + $this->mLicense, |
285 | 287 | $this->mUploadCopyStatus, |
286 | 288 | $this->mUploadSource ); |
287 | 289 | |
— | — | @@ -490,6 +492,7 @@ |
491 | 493 | <input type='hidden' name='wpIgnoreWarning' value='1' /> |
492 | 494 | <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" /> |
493 | 495 | <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" /> |
| 496 | + <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" /> |
494 | 497 | <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" /> |
495 | 498 | {$copyright} |
496 | 499 | <table border='0'> |
— | — | @@ -538,6 +541,12 @@ |
539 | 542 | $sourcefilename = wfMsgHtml( 'sourcefilename' ); |
540 | 543 | $destfilename = wfMsgHtml( 'destfilename' ); |
541 | 544 | $summary = wfMsgWikiHtml( 'fileuploadsummary' ); |
| 545 | + |
| 546 | + $licenses = new Licenses(); |
| 547 | + $license = wfMsgHtml( 'license' ); |
| 548 | + $nolicense = wfMsgHtml( 'nolicense' ); |
| 549 | + $licenseshtml = $licenses->getHtml(); |
| 550 | + |
542 | 551 | $ulb = wfMsgHtml( 'uploadbtn' ); |
543 | 552 | |
544 | 553 | |
— | — | @@ -576,8 +585,20 @@ |
577 | 586 | <textarea tabindex='2' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" |
578 | 587 | . htmlspecialchars( $this->mUploadDescription ) . |
579 | 588 | "</textarea> |
| 589 | + </td></tr><tr>" ); |
| 590 | + |
| 591 | + if ( $licenseshtml != '' ) { |
| 592 | + $wgOut->addHTML( " |
| 593 | + <td align='right'>$license:</td> |
| 594 | + <td align='left'> |
| 595 | + <select name='wpLicense'> |
| 596 | + <option value=''>$nolicense</option> |
| 597 | + $licenseshtml |
| 598 | + </select> |
580 | 599 | </td></tr><tr> |
581 | | - {$source} |
| 600 | + "); |
| 601 | + } |
| 602 | + $wgOut->addHtml( "{$source} |
582 | 603 | </tr> |
583 | 604 | <tr><td></td><td align='left'> |
584 | 605 | <input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" /> |
Index: trunk/phase3/includes/Image.php |
— | — | @@ -1253,7 +1253,7 @@ |
1254 | 1254 | /** |
1255 | 1255 | * Record an image upload in the upload log and the image table |
1256 | 1256 | */ |
1257 | | - function recordUpload( $oldver, $desc, $copyStatus = '', $source = '' ) { |
| 1257 | + function recordUpload( $oldver, $desc, $license, $copyStatus = '', $source = '' ) { |
1258 | 1258 | global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList; |
1259 | 1259 | global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList; |
1260 | 1260 | |
— | — | @@ -1272,11 +1272,21 @@ |
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | if ( $wgUseCopyrightUpload ) { |
| 1276 | + if ( $license != '' ) { |
| 1277 | + $licensetxt = '== ' . wfMsg( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n"; |
| 1278 | + } |
1276 | 1279 | $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" . |
1277 | 1280 | '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" . |
| 1281 | + "$licensetxt" . |
1278 | 1282 | '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ; |
1279 | 1283 | } else { |
1280 | | - $textdesc = $desc; |
| 1284 | + if ( $license != '' ) { |
| 1285 | + $filedesc = $desc == '' ? '' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n"; |
| 1286 | + $textdesc = $filedesc . |
| 1287 | + '== ' . wfMsg ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n"; |
| 1288 | + } else { |
| 1289 | + $textdesc = $desc; |
| 1290 | + } |
1281 | 1291 | } |
1282 | 1292 | |
1283 | 1293 | $now = $dbw->timestamp(); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -71,8 +71,8 @@ |
72 | 72 | * (bug 2885) More PHP 5.1 fixes: skin, search, log, undelete |
73 | 73 | * Fix interlanguage links on special pages when extra namespaces configured |
74 | 74 | * IP privacy fix for blocklist search on autoblocks |
| 75 | +* Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses |
75 | 76 | |
76 | | - |
77 | 77 | === Caveats === |
78 | 78 | |
79 | 79 | Some output, particularly involving user-supplied inline HTML, may not |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -1032,6 +1032,9 @@ |
1033 | 1033 | 'sourcefilename' => 'Source filename', |
1034 | 1034 | 'destfilename' => 'Destination filename', |
1035 | 1035 | |
| 1036 | +'license' => 'License', |
| 1037 | +'nolicense' => 'None', |
| 1038 | + |
1036 | 1039 | # Image list |
1037 | 1040 | # |
1038 | 1041 | 'imagelist' => 'File list', |
— | — | @@ -2734,7 +2737,7 @@ |
2735 | 2738 | if ($i == $m) { |
2736 | 2739 | $s = $l[$i]; |
2737 | 2740 | } else if ($i == $m - 1) { |
2738 | | - $s = $l[$i] . ' ' . $this->getMessage('and') . ' ' . $s; |
| 2741 | + $s = $l[$i] . ' ' . wfMsg('and') . ' ' . $s; |
2739 | 2742 | } else { |
2740 | 2743 | $s = $l[$i] . ', ' . $s; |
2741 | 2744 | } |