Merge "Add a hook for collapsible content"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.edit.preview.js
index 6de537a..3b19b35 100644 (file)
@@ -41,6 +41,7 @@
 
                copySelectors = [
                        // Main
+                       '.mw-indicators',
                        '#firstHeading',
                        '#wikiPreview',
                        '#wikiDiff',
@@ -74,6 +75,7 @@
 
                api = new mw.Api();
                postData = {
+                       formatversion: 2,
                        action: 'parse',
                        title: mw.config.get( 'wgPageName' ),
                        summary: $summary.textSelection( 'getContents' ),
@@ -88,8 +90,8 @@
                        }
 
                        diffRequest = api.post( {
+                               formatversion: 2,
                                action: 'query',
-                               indexpageids: true,
                                prop: 'revisions',
                                titles: mw.config.get( 'wgPageName' ),
                                rvdifftotext: $textbox.textSelection( 'getContents' ),
 
                        // Wait for the summary before showing the diff so the page doesn't jump twice
                        $.when( diffRequest, parseRequest ).done( function ( response ) {
-                               var diffHtml,
-                                       query = response[ 0 ].query;
+                               var diffHtml;
                                try {
-                                       diffHtml = query.pages[ query.pageids[ 0 ] ]
-                                               .revisions[ 0 ].diff[ '*' ];
+                                       diffHtml = response[ 0 ].query.pages[ 0 ]
+                                               .revisions[ 0 ].diff.body;
                                        $wikiDiff.find( 'table.diff tbody' ).html( diffHtml );
                                        mw.hook( 'wikipage.diff' ).fire( $wikiDiff.find( 'table.diff' ) );
                                } catch ( e ) {
                        $wikiDiff.hide();
 
                        $.extend( postData, {
-                               prop: 'text|displaytitle|modules|jsconfigvars|categorieshtml|templates|langlinks|limitreporthtml',
+                               prop: 'text|indicators|displaytitle|modules|jsconfigvars|categorieshtml|templates|langlinks|limitreporthtml',
                                text: $textbox.textSelection( 'getContents' ),
                                pst: true,
                                preview: true,
                                                response.parse.modulestyles
                                        ) );
                                }
+
+                               newList = [];
+                               $.each( response.parse.indicators, function ( name, indicator ) {
+                                       newList.push(
+                                               $( '<div>' )
+                                                       .addClass( 'mw-indicator' )
+                                                       .attr( 'id', mw.util.escapeId( 'mw-indicator-' + name ) )
+                                                       .html( indicator )
+                                                       .get( 0 ),
+                                               // Add a whitespace between the <div>s because
+                                               // they get displayed with display: inline-block
+                                               document.createTextNode( '\n' )
+                                       );
+                               } );
+                               $( '.mw-indicators' ).empty().append( newList );
+
                                if ( response.parse.displaytitle ) {
                                        $displaytitle = $( $.parseHTML( response.parse.displaytitle ) );
                                        $( '#firstHeading' ).msg(
                                        );
                                }
                                if ( response.parse.categorieshtml ) {
-                                       $( '#catlinks' ).replaceWith( response.parse.categorieshtml[ '*' ] );
+                                       $content = $( $.parseHTML( response.parse.categorieshtml ) );
+                                       mw.hook( 'wikipage.categories' ).fire( $content );
+                                       $( '.catlinks[data-mw="interface"]' ).replaceWith( $content );
                                }
                                if ( response.parse.templates ) {
                                        newList = [];
                                                li = $( '<li>' )
                                                        .append( $( '<a>' )
                                                                .attr( {
-                                                                       href: mw.util.getUrl( template[ '*' ] ),
-                                                                       'class': ( template.exists !== undefined ? '' : 'new' )
+                                                                       href: mw.util.getUrl( template.title ),
+                                                                       'class': ( template.exists ? '' : 'new' )
                                                                } )
-                                                               .text( template[ '*' ] )
+                                                               .text( template.title )
                                                        );
                                                newList.push( li );
                                        } );
                                        $editform.find( '.templatesUsed .mw-editfooter-list' ).detach().empty().append( newList ).appendTo( '.templatesUsed' );
                                }
                                if ( response.parse.limitreporthtml ) {
-                                       $( '.limitreport' ).html( response.parse.limitreporthtml[ '*' ] );
+                                       $( '.limitreport' ).html( response.parse.limitreporthtml );
                                }
                                if ( response.parse.langlinks && mw.config.get( 'skin' ) === 'vector' ) {
                                        newList = [];
                                                        .append( $( '<a>' )
                                                                .attr( {
                                                                        href: langlink.url,
-                                                                       title: langlink[ '*' ] + ' - ' + langlink.langname,
+                                                                       title: langlink.title + ' - ' + langlink.langname,
                                                                        lang: langlink.lang,
                                                                        hreflang: langlink.lang
                                                                } )
                                        $list.detach().empty().append( newList ).prependTo( $parent );
                                }
 
-                               if ( response.parse.text[ '*' ] ) {
+                               if ( response.parse.text ) {
                                        $content = $wikiPreview.children( '.mw-content-ltr,.mw-content-rtl' );
                                        $content
                                                .detach()
-                                               .html( response.parse.text[ '*' ] );
+                                               .html( response.parse.text );
 
                                        mw.hook( 'wikipage.content' ).fire( $content );
 
                                isSubject = ( section === 'new' ),
                                summaryMsg = isSubject ? 'subject-preview' : 'summary-preview',
                                $summaryPreview = $editform.find( '.mw-summary-preview' ).empty();
-                       if ( parse && parse.parsedsummary && parse.parsedsummary[ '*' ] !== '' ) {
+                       if ( parse && parse.parsedsummary ) {
                                $summaryPreview.append(
                                        mw.message( summaryMsg ).parse(),
                                        ' ',
                                        $( '<span>' ).addClass( 'comment' ).html(
                                                // There is no equivalent to rawParams
                                                mw.message( 'parentheses' ).escaped()
-                                                       .replace( '$1', parse.parsedsummary[ '*' ] )
+                                                       .replace( '$1', parse.parsedsummary )
                                        )
                                );
                        }