Index: trunk/phase3/skins/common/upload.js |
— | — | @@ -1,9 +1,16 @@ |
2 | 2 | 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 | + } |
8 | 15 | } |
9 | 16 | } |
10 | 17 | |
— | — | @@ -132,4 +139,34 @@ |
133 | 140 | } |
134 | 141 | } |
135 | 142 | |
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 @@ |
2286 | 2286 | function wfScript( $script = 'index' ) { |
2287 | 2287 | global $wgScriptPath, $wgScriptExtension; |
2288 | 2288 | 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'; |
2289 | 2300 | } |
\ No newline at end of file |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -258,6 +258,8 @@ |
259 | 259 | if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch'; |
260 | 260 | if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch'; |
261 | 261 | if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning'; |
| 262 | +if( $wgAjaxLicencePreview ) |
| 263 | + $wgAjaxExportList[] = 'UploadForm::ajaxGetLicencePreview'; |
262 | 264 | |
263 | 265 | wfSeedRandom(); |
264 | 266 | |
Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -556,8 +556,45 @@ |
557 | 557 | } |
558 | 558 | return $s; |
559 | 559 | } |
| 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 | + } |
560 | 578 | |
561 | 579 | /** |
| 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 | + /** |
562 | 599 | * Stash a file in a temporary directory for later processing |
563 | 600 | * after the user has confirmed it. |
564 | 601 | * |
— | — | @@ -712,18 +749,23 @@ |
713 | 750 | */ |
714 | 751 | function mainUploadForm( $msg='' ) { |
715 | 752 | global $wgOut, $wgUser; |
716 | | - global $wgUseCopyrightUpload, $wgAjaxUploadDestCheck, $wgUseAjax; |
| 753 | + global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicencePreview; |
717 | 754 | global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI; |
718 | | - global $wgStylePath; |
| 755 | + global $wgStylePath, $wgStyleVersion; |
719 | 756 | |
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 | + " ); |
721 | 769 | |
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 | | - |
728 | 770 | if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) |
729 | 771 | { |
730 | 772 | wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); |
— | — | @@ -794,7 +836,7 @@ |
795 | 837 | "size='40' />" . |
796 | 838 | "<input type='hidden' name='wpSourceType' value='file' />" ; |
797 | 839 | } |
798 | | - if ( $useAjax ) { |
| 840 | + if ( $useAjaxDestCheck ) { |
799 | 841 | $warningRow = "<tr><td colspan='2' id='wpDestFile-warning'> </td></tr>"; |
800 | 842 | $destOnkeyup = 'onkeyup="wgUploadWarningObj.keypress();"'; |
801 | 843 | } else { |
— | — | @@ -845,8 +887,13 @@ |
846 | 888 | </select> |
847 | 889 | </td> |
848 | 890 | </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 | + } |
851 | 898 | } |
852 | 899 | |
853 | 900 | if ( $wgUseCopyrightUpload ) { |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1201,7 +1201,7 @@ |
1202 | 1202 | * to ensure that client-side caches don't keep obsolete copies of global |
1203 | 1203 | * styles. |
1204 | 1204 | */ |
1205 | | -$wgStyleVersion = '82'; |
| 1205 | +$wgStyleVersion = '83'; |
1206 | 1206 | |
1207 | 1207 | |
1208 | 1208 | # Server-side caching: |
— | — | @@ -2560,6 +2560,11 @@ |
2561 | 2561 | $wgAjaxUploadDestCheck = true; |
2562 | 2562 | |
2563 | 2563 | /** |
| 2564 | + * Enable previewing licences via AJAX |
| 2565 | + */ |
| 2566 | +$wgAjaxLicencePreview = true; |
| 2567 | + |
| 2568 | +/** |
2564 | 2569 | * Allow DISPLAYTITLE to change title display |
2565 | 2570 | */ |
2566 | 2571 | $wgAllowDisplayTitle = true; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -136,6 +136,8 @@ |
137 | 137 | * (bug 1962) Allow HTML attributes on <math> |
138 | 138 | * (bug 10530) Introduce optional "sp-contributions-explain" message for |
139 | 139 | additional explanation in Special:Contributions |
| 140 | +* (bug 10520) Preview licences during upload via AJAX (toggle with |
| 141 | + $wgAjaxLicencePreview) |
140 | 142 | |
141 | 143 | == Bugfixes since 1.10 == |
142 | 144 | |