r10829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10828‎ | r10829 | r10830 >
Date:16:43, 29 August 2005
Author:avar
Status:old
Tags:
Comment:
* Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/Licenses.php (added) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

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( /* &nbsp */ "\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
1170 + native
Added: svn:keywords
2171 + Author Date Id Revision
Index: trunk/phase3/includes/SpecialUpload.php
@@ -8,9 +8,9 @@
99 /**
1010 *
1111 */
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';
1515 /**
1616 * Entry point
1717 */
@@ -29,7 +29,7 @@
3030 /**#@+
3131 * @access private
3232 */
33 - var $mUploadFile, $mUploadDescription, $mIgnoreWarning, $mUploadError;
 33+ var $mUploadFile, $mUploadDescription, $mLicense ,$mIgnoreWarning, $mUploadError;
3434 var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion;
3535 var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload;
3636 var $mOname, $mSessionKey, $mStashed, $mDestFile, $mRemoveTempFile;
@@ -53,6 +53,7 @@
5454 $this->mUpload = $request->getCheck( 'wpUpload' );
5555
5656 $this->mUploadDescription = $request->getText( 'wpUploadDescription' );
 57+ $this->mLicense = $request->getText( 'wpLicense' );
5758 $this->mUploadCopyStatus = $request->getText( 'wpUploadCopyStatus' );
5859 $this->mUploadSource = $request->getText( 'wpUploadSource');
5960
@@ -281,6 +282,7 @@
282283 $img = Image::newFromName( $this->mUploadSaveName );
283284 $success = $img->recordUpload( $this->mUploadOldVersion,
284285 $this->mUploadDescription,
 286+ $this->mLicense,
285287 $this->mUploadCopyStatus,
286288 $this->mUploadSource );
287289
@@ -490,6 +492,7 @@
491493 <input type='hidden' name='wpIgnoreWarning' value='1' />
492494 <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" />
493495 <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />
 496+ <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
494497 <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" />
495498 {$copyright}
496499 <table border='0'>
@@ -538,6 +541,12 @@
539542 $sourcefilename = wfMsgHtml( 'sourcefilename' );
540543 $destfilename = wfMsgHtml( 'destfilename' );
541544 $summary = wfMsgWikiHtml( 'fileuploadsummary' );
 545+
 546+ $licenses = new Licenses();
 547+ $license = wfMsgHtml( 'license' );
 548+ $nolicense = wfMsgHtml( 'nolicense' );
 549+ $licenseshtml = $licenses->getHtml();
 550+
542551 $ulb = wfMsgHtml( 'uploadbtn' );
543552
544553
@@ -576,8 +585,20 @@
577586 <textarea tabindex='2' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>"
578587 . htmlspecialchars( $this->mUploadDescription ) .
579588 "</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>
580599 </td></tr><tr>
581 - {$source}
 600+ ");
 601+ }
 602+ $wgOut->addHtml( "{$source}
582603 </tr>
583604 <tr><td></td><td align='left'>
584605 <input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" />
Index: trunk/phase3/includes/Image.php
@@ -1253,7 +1253,7 @@
12541254 /**
12551255 * Record an image upload in the upload log and the image table
12561256 */
1257 - function recordUpload( $oldver, $desc, $copyStatus = '', $source = '' ) {
 1257+ function recordUpload( $oldver, $desc, $license, $copyStatus = '', $source = '' ) {
12581258 global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
12591259 global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
12601260
@@ -1272,11 +1272,21 @@
12731273 }
12741274
12751275 if ( $wgUseCopyrightUpload ) {
 1276+ if ( $license != '' ) {
 1277+ $licensetxt = '== ' . wfMsg( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
 1278+ }
12761279 $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
12771280 '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
 1281+ "$licensetxt" .
12781282 '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
12791283 } 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+ }
12811291 }
12821292
12831293 $now = $dbw->timestamp();
Index: trunk/phase3/RELEASE-NOTES
@@ -71,8 +71,8 @@
7272 * (bug 2885) More PHP 5.1 fixes: skin, search, log, undelete
7373 * Fix interlanguage links on special pages when extra namespaces configured
7474 * IP privacy fix for blocklist search on autoblocks
 75+* Support for a license selection box on Special:Upload, configurable from MediaWiki:Licenses
7576
76 -
7777 === Caveats ===
7878
7979 Some output, particularly involving user-supplied inline HTML, may not
Index: trunk/phase3/languages/Language.php
@@ -1032,6 +1032,9 @@
10331033 'sourcefilename' => 'Source filename',
10341034 'destfilename' => 'Destination filename',
10351035
 1036+'license' => 'License',
 1037+'nolicense' => 'None',
 1038+
10361039 # Image list
10371040 #
10381041 'imagelist' => 'File list',
@@ -2734,7 +2737,7 @@
27352738 if ($i == $m) {
27362739 $s = $l[$i];
27372740 } else if ($i == $m - 1) {
2738 - $s = $l[$i] . ' ' . $this->getMessage('and') . ' ' . $s;
 2741+ $s = $l[$i] . ' ' . wfMsg('and') . ' ' . $s;
27392742 } else {
27402743 $s = $l[$i] . ', ' . $s;
27412744 }

Status & tagging log