r24095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24094‎ | r24095 | r24096 >
Date:22:06, 14 July 2007
Author:robchurch
Status:old
Tags:
Comment:
(bug 10520) Preview licences during upload via AJAX
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/skins/common/upload.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/upload.js
@@ -1,9 +1,16 @@
22 function licenseSelectorCheck() {
3 - var selector = document.getElementById("wpLicense");
4 - if (selector.selectedIndex > 0 &&
5 - selector.options[selector.selectedIndex].value == "" ) {
6 - // Browser is broken, doesn't respect disabled attribute on <option>
7 - selector.selectedIndex = 0;
 3+ var selector = document.getElementById( "wpLicense" );
 4+ if( selector.selectedIndex > 0 ) {
 5+ var selection = selector.options[selector.selectedIndex].value;
 6+ if( selection == "" ) {
 7+ // Option disabled, but browser is broken and doesn't respect this
 8+ selector.selectedIndex = 0;
 9+ } else {
 10+ // We might show a preview
 11+ if( wgAjaxLicencePreview ) {
 12+ wgUploadLicenceObj.fetchPreview( selection );
 13+ }
 14+ }
815 }
916 }
1017
@@ -132,4 +139,34 @@
133140 }
134141 }
135142
136 -addOnloadHook(licenseSelectorFixup);
 143+var wgUploadLicenceObj = {
 144+
 145+ 'responseCache' : { '' : '' },
 146+
 147+ 'fetchPreview': function( licence ) {
 148+ if( licence in this.responseCache ) {
 149+ this.showPreview( this.responseCache[licence] );
 150+ } else {
 151+ sajax_do_call( 'UploadForm::ajaxGetLicencePreview', [licence],
 152+ function( result ) {
 153+ wgUploadLicenceObj.processResult( result, licence );
 154+ }
 155+ );
 156+ }
 157+ },
 158+
 159+ 'processResult' : function( result, licence ) {
 160+ this.showPreview( result.responseText );
 161+ this.responseCache[licence] = result.responseText;
 162+ },
 163+
 164+ 'showPreview' : function( preview ) {
 165+ var previewPanel = document.getElementById( 'mw-licence-preview' );
 166+ if( previewPanel.innerHTML != preview ) {
 167+ previewPanel.innerHTML = preview;
 168+ }
 169+ }
 170+
 171+}
 172+
 173+addOnloadHook( licenseSelectorFixup );
\ No newline at end of file
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2285,4 +2285,15 @@
22862286 function wfScript( $script = 'index' ) {
22872287 global $wgScriptPath, $wgScriptExtension;
22882288 return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
 2289+}
 2290+
 2291+/**
 2292+ * Convenience function converts boolean values into "true"
 2293+ * or "false" (string) values
 2294+ *
 2295+ * @param bool $value
 2296+ * @return string
 2297+ */
 2298+function wfBoolToStr( $value ) {
 2299+ return $value ? 'true' : 'false';
22892300 }
\ No newline at end of file
Index: trunk/phase3/includes/Setup.php
@@ -258,6 +258,8 @@
259259 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
260260 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
261261 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
 262+if( $wgAjaxLicencePreview )
 263+ $wgAjaxExportList[] = 'UploadForm::ajaxGetLicencePreview';
262264
263265 wfSeedRandom();
264266
Index: trunk/phase3/includes/SpecialUpload.php
@@ -556,8 +556,45 @@
557557 }
558558 return $s;
559559 }
 560+
 561+ /**
 562+ * Render a preview of a given licence for the AJAX preview on upload
 563+ *
 564+ * @param string $licence
 565+ * @return string
 566+ */
 567+ public static function ajaxGetLicencePreview( $licence ) {
 568+ global $wgParser;
 569+ $licence = self::getLicenceTitle( $licence );
 570+ if( $licence instanceof Title && $licence->exists() ) {
 571+ $title = SpecialPage::getTitleFor( 'Upload' );
 572+ $revision = Revision::newFromTitle( $licence );
 573+ $output = $wgParser->parse( $revision->getText(), $title, new ParserOptions() );
 574+ return $output->getText();
 575+ }
 576+ return '';
 577+ }
560578
561579 /**
 580+ * Get the title of the page associated with a given licence
 581+ * string, i.e. do a quick resolution of {{$license}} without
 582+ * invoking the full parser
 583+ *
 584+ * @param string $licence
 585+ * @return Title
 586+ */
 587+ private static function getLicenceTitle( $licence ) {
 588+ $template = substr( $licence, 0, 1 ) != ':';
 589+ $title = Title::newFromText( ltrim( $licence, ':' ) );
 590+ if( $title instanceof Title && $title->getNamespace() == NS_MAIN ) {
 591+ return $template
 592+ ? Title::makeTitle( NS_TEMPLATE, $title->getText() )
 593+ : $title;
 594+ }
 595+ return $title;
 596+ }
 597+
 598+ /**
562599 * Stash a file in a temporary directory for later processing
563600 * after the user has confirmed it.
564601 *
@@ -712,18 +749,23 @@
713750 */
714751 function mainUploadForm( $msg='' ) {
715752 global $wgOut, $wgUser;
716 - global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck, $wgUseAjax;
 753+ global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicencePreview;
717754 global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
718 - global $wgStylePath;
 755+ global $wgStylePath, $wgStyleVersion;
719756
720 - $useAjax = $wgAjaxUploadDestCheck && $wgUseAjax;
 757+ $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
 758+ $useAjaxLicencePreview = $wgUseAjax && $wgAjaxLicencePreview;
 759+
 760+ $adc = wfBoolToStr( $useAjaxDestCheck );
 761+ $alp = wfBoolToStr( $useAjaxLicencePreview );
 762+
 763+ $wgOut->addScript( "<script type=\"text/javascript\">
 764+wgAjaxUploadDestCheck = {$adc};
 765+wgAjaxLicencePreview = {$alp};
 766+</script>
 767+<script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
 768+ " );
721769
722 - $wgOut->addScript(
723 - "<script type='text/javascript'>wgAjaxUploadDestCheck = " .
724 - ($useAjax ? 'true' : 'false' ) . ";</script>\n" .
725 - "<script type='text/javascript' src=\"$wgStylePath/common/upload.js?1\"></script>\n"
726 - );
727 -
728770 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
729771 {
730772 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
@@ -794,7 +836,7 @@
795837 "size='40' />" .
796838 "<input type='hidden' name='wpSourceType' value='file' />" ;
797839 }
798 - if ( $useAjax ) {
 840+ if ( $useAjaxDestCheck ) {
799841 $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'>&nbsp</td></tr>";
800842 $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"';
801843 } else {
@@ -845,8 +887,13 @@
846888 </select>
847889 </td>
848890 </tr>
849 - <tr>
850 - ");
 891+ <tr>" );
 892+ if( $useAjaxLicencePreview ) {
 893+ $wgOut->addHtml( "
 894+ <td id=\"mw-licence-preview\" colspan=\"2\"></td>
 895+ </tr>
 896+ <tr>" );
 897+ }
851898 }
852899
853900 if ( $wgUseCopyrightUpload ) {
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1201,7 +1201,7 @@
12021202 * to ensure that client-side caches don't keep obsolete copies of global
12031203 * styles.
12041204 */
1205 -$wgStyleVersion = '82';
 1205+$wgStyleVersion = '83';
12061206
12071207
12081208 # Server-side caching:
@@ -2560,6 +2560,11 @@
25612561 $wgAjaxUploadDestCheck = true;
25622562
25632563 /**
 2564+ * Enable previewing licences via AJAX
 2565+ */
 2566+$wgAjaxLicencePreview = true;
 2567+
 2568+/**
25642569 * Allow DISPLAYTITLE to change title display
25652570 */
25662571 $wgAllowDisplayTitle = true;
Index: trunk/phase3/RELEASE-NOTES
@@ -136,6 +136,8 @@
137137 * (bug 1962) Allow HTML attributes on <math>
138138 * (bug 10530) Introduce optional "sp-contributions-explain" message for
139139 additional explanation in Special:Contributions
 140+* (bug 10520) Preview licences during upload via AJAX (toggle with
 141+ $wgAjaxLicencePreview)
140142
141143 == Bugfixes since 1.10 ==
142144

Follow-up revisions

RevisionCommit summaryAuthorDate
r24215Merged revisions 24095-24212 via svnmerge from...david21:19, 17 July 2007

Status & tagging log