r24247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24246‎ | r24247 | r24248 >
Date:19:19, 18 July 2007
Author:brion
Status:old
Tags:
Comment:
Tweaks to the AJAX license preview:
* Rename 'licence' to 'license' for consistency with the rest of the code.
* The preview code was assuming simple templates with no parameters and no subst:s, which failed on most of the selections used now on Commons. Now doing a full pre-save transform and parse on {{$license}}, just as will be done on the final save.
* When selecting 'None' again after another option, the preview pane is now cleared.

A fun 'todo' might be to also pass the currently selected filename, if any, to the license preview. Some of the templates in use attempt to use the current-page-name variables to include a self-link. At the moment using a hardcoded 'Image:Sample.jpg' for the virtual title on the preview rendering.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.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,17 +1,16 @@
22 function licenseSelectorCheck() {
33 var selector = document.getElementById( "wpLicense" );
 4+ var selection = selector.options[selector.selectedIndex].value;
45 if( selector.selectedIndex > 0 ) {
5 - var selection = selector.options[selector.selectedIndex].value;
66 if( selection == "" ) {
77 // Option disabled, but browser is broken and doesn't respect this
88 selector.selectedIndex = 0;
9 - } else {
10 - // We might show a preview
11 - if( wgAjaxLicencePreview ) {
12 - wgUploadLicenceObj.fetchPreview( selection );
13 - }
149 }
1510 }
 11+ // We might show a preview
 12+ if( wgAjaxLicensePreview ) {
 13+ wgUploadLicenseObj.fetchPreview( selection );
 14+ }
1615 }
1716
1817 function licenseSelectorFixup() {
@@ -138,31 +137,33 @@
139138 }
140139 }
141140
142 -var wgUploadLicenceObj = {
 141+var wgUploadLicenseObj = {
143142
144143 'responseCache' : { '' : '' },
145144
146 - 'fetchPreview': function( licence ) {
147 - if( licence in this.responseCache ) {
148 - this.showPreview( this.responseCache[licence] );
 145+ 'fetchPreview': function( license ) {
 146+ if( license == "" ) {
 147+ this.showPreview( "" );
 148+ } else if( license in this.responseCache ) {
 149+ this.showPreview( this.responseCache[license] );
149150 } else {
150 - injectSpinner( document.getElementById( 'wpLicense' ), 'licence' );
151 - sajax_do_call( 'UploadForm::ajaxGetLicencePreview', [licence],
 151+ injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
 152+ sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license],
152153 function( result ) {
153 - wgUploadLicenceObj.processResult( result, licence );
 154+ wgUploadLicenseObj.processResult( result, license );
154155 }
155156 );
156157 }
157158 },
158159
159 - 'processResult' : function( result, licence ) {
160 - removeSpinner( 'licence' );
 160+ 'processResult' : function( result, license ) {
 161+ removeSpinner( 'license' );
161162 this.showPreview( result.responseText );
162 - this.responseCache[licence] = result.responseText;
 163+ this.responseCache[license] = result.responseText;
163164 },
164165
165166 'showPreview' : function( preview ) {
166 - var previewPanel = document.getElementById( 'mw-licence-preview' );
 167+ var previewPanel = document.getElementById( 'mw-license-preview' );
167168 if( previewPanel.innerHTML != preview )
168169 previewPanel.innerHTML = preview;
169170 }
Index: trunk/phase3/includes/Setup.php
@@ -258,8 +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';
 262+if( $wgAjaxLicensePreview )
 263+ $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
264264
265265 wfSeedRandom();
266266
Index: trunk/phase3/includes/SpecialUpload.php
@@ -559,43 +559,25 @@
560560 }
561561
562562 /**
563 - * Render a preview of a given licence for the AJAX preview on upload
 563+ * Render a preview of a given license for the AJAX preview on upload
564564 *
565 - * @param string $licence
 565+ * @param string $license
566566 * @return string
567567 */
568 - public static function ajaxGetLicencePreview( $licence ) {
569 - global $wgParser;
570 - $licence = self::getLicenceTitle( $licence );
571 - if( $licence instanceof Title && $licence->exists() ) {
572 - $title = SpecialPage::getTitleFor( 'Upload' );
573 - $revision = Revision::newFromTitle( $licence );
574 - $output = $wgParser->parse( $revision->getText(), $title, new ParserOptions() );
575 - return $output->getText();
576 - }
577 - return wfMsgHtml( 'license-nopreview' );
 568+ public static function ajaxGetLicensePreview( $license ) {
 569+ global $wgParser, $wgUser;
 570+ $text = '{{' . $license . '}}';
 571+ $title = Title::makeTitle( NS_IMAGE, 'Sample.jpg' );
 572+ $options = ParserOptions::newFromUser( $wgUser );
 573+
 574+ // Expand subst: first, then live templates...
 575+ $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
 576+ $output = $wgParser->parse( $text, $title, $options );
 577+
 578+ return $output->getText();
578579 }
579580
580581 /**
581 - * Get the title of the page associated with a given licence
582 - * string, i.e. do a quick resolution of {{$license}} without
583 - * invoking the full parser
584 - *
585 - * @param string $licence
586 - * @return Title
587 - */
588 - private static function getLicenceTitle( $licence ) {
589 - $template = substr( $licence, 0, 1 ) != ':';
590 - $title = Title::newFromText( ltrim( $licence, ':' ) );
591 - if( $title instanceof Title && $title->getNamespace() == NS_MAIN ) {
592 - return $template
593 - ? Title::makeTitle( NS_TEMPLATE, $title->getText() )
594 - : $title;
595 - }
596 - return $title;
597 - }
598 -
599 - /**
600582 * Stash a file in a temporary directory for later processing
601583 * after the user has confirmed it.
602584 *
@@ -750,19 +732,19 @@
751733 */
752734 function mainUploadForm( $msg='' ) {
753735 global $wgOut, $wgUser;
754 - global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicencePreview;
 736+ global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
755737 global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
756738 global $wgStylePath, $wgStyleVersion;
757739
758740 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
759 - $useAjaxLicencePreview = $wgUseAjax && $wgAjaxLicencePreview;
 741+ $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
760742
761743 $adc = wfBoolToStr( $useAjaxDestCheck );
762 - $alp = wfBoolToStr( $useAjaxLicencePreview );
 744+ $alp = wfBoolToStr( $useAjaxLicensePreview );
763745
764746 $wgOut->addScript( "<script type=\"text/javascript\">
765747 wgAjaxUploadDestCheck = {$adc};
766 -wgAjaxLicencePreview = {$alp};
 748+wgAjaxLicensePreview = {$alp};
767749 </script>
768750 <script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
769751 " );
@@ -889,10 +871,10 @@
890872 </td>
891873 </tr>
892874 <tr>" );
893 - if( $useAjaxLicencePreview ) {
 875+ if( $useAjaxLicensePreview ) {
894876 $wgOut->addHtml( "
895877 <td></td>
896 - <td id=\"mw-licence-preview\"></td>
 878+ <td id=\"mw-license-preview\"></td>
897879 </tr>
898880 <tr>" );
899881 }
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 = '85';
 1205+$wgStyleVersion = '86';
12061206
12071207
12081208 # Server-side caching:
@@ -2563,7 +2563,7 @@
25642564 /**
25652565 * Enable previewing licences via AJAX
25662566 */
2567 -$wgAjaxLicencePreview = true;
 2567+$wgAjaxLicensePreview = true;
25682568
25692569 /**
25702570 * Allow DISPLAYTITLE to change title display
Index: trunk/phase3/RELEASE-NOTES
@@ -137,7 +137,7 @@
138138 * (bug 10530) Introduce optional "sp-contributions-explain" message for
139139 additional explanation in Special:Contributions
140140 * (bug 10520) Preview licences during upload via AJAX (toggle with
141 - $wgAjaxLicencePreview)
 141+ $wgAjaxLicensePreview)
142142 * New Parser::setTransparentTagHook for parser extension and template
143143 compatibility
144144 * Introduced 'ContributionsToolLinks' hook; see docs/hooks.txt for more

Follow-up revisions

RevisionCommit summaryAuthorDate
r24276Merged revisions 24213-24275 via svnmerge from...david20:20, 19 July 2007

Status & tagging log