* 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.
* (bug 10530) Introduce optional "sp-contributions-explain" message for
additional explanation in Special:Contributions
* (bug 10520) Preview licences during upload via AJAX (toggle with
- $wgAjaxLicencePreview)
+ $wgAjaxLicensePreview)
* New Parser::setTransparentTagHook for parser extension and template
compatibility
* Introduced 'ContributionsToolLinks' hook; see docs/hooks.txt for more
* to ensure that client-side caches don't keep obsolete copies of global
* styles.
*/
-$wgStyleVersion = '85';
+$wgStyleVersion = '86';
# Server-side caching:
/**
* Enable previewing licences via AJAX
*/
-$wgAjaxLicencePreview = true;
+$wgAjaxLicensePreview = true;
/**
* Allow DISPLAYTITLE to change title display
if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
-if( $wgAjaxLicencePreview )
- $wgAjaxExportList[] = 'UploadForm::ajaxGetLicencePreview';
+if( $wgAjaxLicensePreview )
+ $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
wfSeedRandom();
}
/**
- * Render a preview of a given licence for the AJAX preview on upload
+ * Render a preview of a given license for the AJAX preview on upload
*
- * @param string $licence
+ * @param string $license
* @return string
*/
- public static function ajaxGetLicencePreview( $licence ) {
- global $wgParser;
- $licence = self::getLicenceTitle( $licence );
- if( $licence instanceof Title && $licence->exists() ) {
- $title = SpecialPage::getTitleFor( 'Upload' );
- $revision = Revision::newFromTitle( $licence );
- $output = $wgParser->parse( $revision->getText(), $title, new ParserOptions() );
- return $output->getText();
- }
- return wfMsgHtml( 'license-nopreview' );
- }
-
- /**
- * Get the title of the page associated with a given licence
- * string, i.e. do a quick resolution of {{$license}} without
- * invoking the full parser
- *
- * @param string $licence
- * @return Title
- */
- private static function getLicenceTitle( $licence ) {
- $template = substr( $licence, 0, 1 ) != ':';
- $title = Title::newFromText( ltrim( $licence, ':' ) );
- if( $title instanceof Title && $title->getNamespace() == NS_MAIN ) {
- return $template
- ? Title::makeTitle( NS_TEMPLATE, $title->getText() )
- : $title;
- }
- return $title;
+ public static function ajaxGetLicensePreview( $license ) {
+ global $wgParser, $wgUser;
+ $text = '{{' . $license . '}}';
+ $title = Title::makeTitle( NS_IMAGE, 'Sample.jpg' );
+ $options = ParserOptions::newFromUser( $wgUser );
+
+ // Expand subst: first, then live templates...
+ $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
+ $output = $wgParser->parse( $text, $title, $options );
+
+ return $output->getText();
}
/**
*/
function mainUploadForm( $msg='' ) {
global $wgOut, $wgUser;
- global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicencePreview;
+ global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
global $wgStylePath, $wgStyleVersion;
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
- $useAjaxLicencePreview = $wgUseAjax && $wgAjaxLicencePreview;
+ $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
$adc = wfBoolToStr( $useAjaxDestCheck );
- $alp = wfBoolToStr( $useAjaxLicencePreview );
+ $alp = wfBoolToStr( $useAjaxLicensePreview );
$wgOut->addScript( "<script type=\"text/javascript\">
wgAjaxUploadDestCheck = {$adc};
-wgAjaxLicencePreview = {$alp};
+wgAjaxLicensePreview = {$alp};
</script>
<script type=\"text/javascript\" src=\"{$wgStylePath}/common/upload.js?{$wgStyleVersion}\"></script>
" );
</td>
</tr>
<tr>" );
- if( $useAjaxLicencePreview ) {
+ if( $useAjaxLicensePreview ) {
$wgOut->addHtml( "
<td></td>
- <td id=\"mw-licence-preview\"></td>
+ <td id=\"mw-license-preview\"></td>
</tr>
<tr>" );
}
function licenseSelectorCheck() {
var selector = document.getElementById( "wpLicense" );
+ var selection = selector.options[selector.selectedIndex].value;
if( selector.selectedIndex > 0 ) {
- var selection = selector.options[selector.selectedIndex].value;
if( selection == "" ) {
// Option disabled, but browser is broken and doesn't respect this
selector.selectedIndex = 0;
- } else {
- // We might show a preview
- if( wgAjaxLicencePreview ) {
- wgUploadLicenceObj.fetchPreview( selection );
- }
}
}
+ // We might show a preview
+ if( wgAjaxLicensePreview ) {
+ wgUploadLicenseObj.fetchPreview( selection );
+ }
}
function licenseSelectorFixup() {
}
}
-var wgUploadLicenceObj = {
+var wgUploadLicenseObj = {
'responseCache' : { '' : '' },
- 'fetchPreview': function( licence ) {
- if( licence in this.responseCache ) {
- this.showPreview( this.responseCache[licence] );
+ 'fetchPreview': function( license ) {
+ if( license == "" ) {
+ this.showPreview( "" );
+ } else if( license in this.responseCache ) {
+ this.showPreview( this.responseCache[license] );
} else {
- injectSpinner( document.getElementById( 'wpLicense' ), 'licence' );
- sajax_do_call( 'UploadForm::ajaxGetLicencePreview', [licence],
+ injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
+ sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license],
function( result ) {
- wgUploadLicenceObj.processResult( result, licence );
+ wgUploadLicenseObj.processResult( result, license );
}
);
}
},
- 'processResult' : function( result, licence ) {
- removeSpinner( 'licence' );
+ 'processResult' : function( result, license ) {
+ removeSpinner( 'license' );
this.showPreview( result.responseText );
- this.responseCache[licence] = result.responseText;
+ this.responseCache[license] = result.responseText;
},
'showPreview' : function( preview ) {
- var previewPanel = document.getElementById( 'mw-licence-preview' );
+ var previewPanel = document.getElementById( 'mw-license-preview' );
if( previewPanel.innerHTML != preview )
previewPanel.innerHTML = preview;
}