Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -54,6 +54,8 @@ |
55 | 55 | 'push-tab-err-fileinfo' => 'Could not obtain which files are used on this page. None have been pushed.', |
56 | 56 | 'push-tab-err-filepush-unknown' => 'File push failed for an unknown reason.', |
57 | 57 | 'push-tab-err-filepush' => 'File push failed: $1', |
| 58 | + 'push-tab-embedded-files' => '(Embedded files: $1)', // JS message, if you want to add plural, then fix the JS first. |
| 59 | + 'push-tab-no-embedded-files' => '(No files are embedded in this page.)', |
58 | 60 | |
59 | 61 | // Special page |
60 | 62 | 'special-push' => 'Push pages', |
Index: trunk/extensions/Push/Push.php |
— | — | @@ -90,6 +90,8 @@ |
91 | 91 | 'push-tab-err-fileinfo', |
92 | 92 | 'push-tab-err-filepush', |
93 | 93 | 'push-tab-err-filepush-unknown', |
| 94 | + 'push-tab-embedded-files', |
| 95 | + 'push-tab-no-embedded-files' |
94 | 96 | ); |
95 | 97 | |
96 | 98 | // For backward compatibility with MW < 1.17. |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -277,14 +277,24 @@ |
278 | 278 | * @since 0.4 |
279 | 279 | */ |
280 | 280 | protected static function displayPushOptions() { |
281 | | - global $wgOut, $wgUser; |
| 281 | + global $wgOut, $wgUser, $wgTitle; |
282 | 282 | |
283 | 283 | $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'push-tab-push-options' ) ) . '</h3>' ); |
284 | 284 | |
285 | | - self::displayIncTemplatesOption(); |
| 285 | + $usedTemplates = array_keys( |
| 286 | + PushFunctions::getTemplates( |
| 287 | + array( $wgTitle->getFullText() ), |
| 288 | + array( $wgTitle->getFullText() => true ) |
| 289 | + ) |
| 290 | + ); |
286 | 291 | |
| 292 | + // Get rid of the page itself. |
| 293 | + array_shift( $usedTemplates ); |
| 294 | + |
| 295 | + self::displayIncTemplatesOption( $usedTemplates ); |
| 296 | + |
287 | 297 | if ( $wgUser->isAllowed( 'filepush' ) ) { |
288 | | - self::displayIncFilesOption(); |
| 298 | + self::displayIncFilesOption( $usedTemplates ); |
289 | 299 | } |
290 | 300 | } |
291 | 301 | |
— | — | @@ -292,31 +302,24 @@ |
293 | 303 | * Outputs the HTML for the "include templates" option. |
294 | 304 | * |
295 | 305 | * @since 0.4 |
| 306 | + * |
| 307 | + * @param array $templates |
296 | 308 | */ |
297 | | - protected static function displayIncTemplatesOption() { |
298 | | - global $wgOut, $wgTitle, $wgLang, $egPushIncTemplates; |
299 | | - |
300 | | - $usedTemplates = array_keys( |
301 | | - PushFunctions::getTemplates( |
302 | | - array( $wgTitle->getFullText() ), |
303 | | - array( $wgTitle->getFullText() => true ) |
304 | | - ) |
305 | | - ); |
306 | | - |
307 | | - array_shift( $usedTemplates ); |
| 309 | + protected static function displayIncTemplatesOption( array $templates ) { |
| 310 | + global $wgOut, $wgLang, $egPushIncTemplates; |
308 | 311 | |
309 | 312 | $wgOut->addInlineScript( |
310 | | - 'var wgPushTemplates = ' . json_encode( $usedTemplates ) . ';' |
| 313 | + 'var wgPushTemplates = ' . json_encode( $templates ) . ';' |
311 | 314 | ); |
312 | 315 | |
313 | | - foreach ( $usedTemplates as &$template ) { |
| 316 | + foreach ( $templates as &$template ) { |
314 | 317 | $template = "[[$template]]"; |
315 | 318 | } |
316 | 319 | |
317 | 320 | $wgOut->addHTML( |
318 | 321 | Html::rawElement( |
319 | 322 | 'div', |
320 | | - array( 'id' => 'divIncTemplates', 'style' => 'display: table-cell' ), |
| 323 | + array( 'id' => 'divIncTemplates', 'style' => 'display: table-row' ), |
321 | 324 | Xml::check( 'checkIncTemplates', $egPushIncTemplates, array( 'id' => 'checkIncTemplates' ) ) . |
322 | 325 | Html::element( |
323 | 326 | 'label', |
— | — | @@ -327,8 +330,8 @@ |
328 | 331 | Html::rawElement( |
329 | 332 | 'div', |
330 | 333 | array( 'style' => 'display:inline; opacity:0', 'id' => 'txtTemplateList' ), |
331 | | - count( $usedTemplates ) > 0 ? |
332 | | - wfMsgExt( 'push-tab-used-templates', 'parseinline', $wgLang->listToText( $usedTemplates ), count( $usedTemplates ) ) : |
| 334 | + count( $templates ) > 0 ? |
| 335 | + wfMsgExt( 'push-tab-used-templates', 'parseinline', $wgLang->listToText( $templates ), count( $templates ) ) : |
333 | 336 | htmlspecialchars( wfMsg( 'push-tab-no-used-templates' ) ) |
334 | 337 | ) |
335 | 338 | ) |
— | — | @@ -339,22 +342,79 @@ |
340 | 343 | * Outputs the HTML for the "include files" option. |
341 | 344 | * |
342 | 345 | * @since 0.4 |
| 346 | + * |
| 347 | + * @param array $templates |
343 | 348 | */ |
344 | | - protected static function displayIncFilesOption() { |
| 349 | + protected static function displayIncFilesOption( array $templates ) { |
345 | 350 | global $wgOut, $wgTitle, $egPushIncFiles; |
346 | 351 | |
| 352 | + $allFiles = self::getImagesForPages( array( $wgTitle->getFullText() ) ); |
| 353 | + $templateFiles = self::getImagesForPages( $templates ); |
| 354 | + $pageFiles = array(); |
| 355 | + |
| 356 | + foreach ( $allFiles as $file ) { |
| 357 | + if ( !in_array( $file, $templateFiles ) ) { |
| 358 | + $pageFiles[] = $file; |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + $wgOut->addInlineScript( |
| 363 | + 'var wgPushPageFiles = ' . json_encode( $pageFiles ) . ';' . |
| 364 | + 'var wgPushTemplateFiles = ' . json_encode( $templateFiles ) . ';' |
| 365 | + ); |
| 366 | + |
347 | 367 | $wgOut->addHTML( |
348 | 368 | Html::rawElement( |
349 | 369 | 'div', |
350 | | - array( 'id' => 'divIncFiles' ), |
| 370 | + array( 'id' => 'divIncFiles', 'style' => 'display: table-row' ), |
351 | 371 | Xml::check( 'checkIncFiles', $egPushIncFiles, array( 'id' => 'checkIncFiles' ) ) . |
352 | 372 | Html::element( |
353 | 373 | 'label', |
354 | 374 | array( 'id' => 'lblIncFiles', 'for' => 'checkIncFiles' ), |
355 | 375 | wfMsg( 'push-tab-inc-files' ) |
356 | | - ) |
| 376 | + ) . |
| 377 | + ' ' . |
| 378 | + Html::rawElement( |
| 379 | + 'div', |
| 380 | + array( 'style' => 'display:inline; opacity:0', 'id' => 'txtFileList' ), |
| 381 | + '' |
| 382 | + ) |
357 | 383 | ) |
358 | | - ); |
| 384 | + ); |
359 | 385 | } |
360 | 386 | |
| 387 | + /** |
| 388 | + * Returns the names of the images embedded in a set of pages. |
| 389 | + * |
| 390 | + * @param array $pages |
| 391 | + * |
| 392 | + * @return array |
| 393 | + */ |
| 394 | + protected static function getImagesForPages( array $pages ) { |
| 395 | + $images = array(); |
| 396 | + |
| 397 | + $requestData = array( |
| 398 | + 'action' => 'query', |
| 399 | + 'format' => 'json', |
| 400 | + 'prop' => 'images', |
| 401 | + 'titles' => implode( '|', $pages ), |
| 402 | + ); |
| 403 | + |
| 404 | + $api = new ApiMain( new FauxRequest( $requestData, true ), true ); |
| 405 | + $api->execute(); |
| 406 | + $response = $api->getResultData(); |
| 407 | + |
| 408 | + if ( is_array( $response ) && array_key_exists( 'query', $response ) && array_key_exists( 'pages', $response['query'] ) ) { |
| 409 | + foreach ( $response['query']['pages'] as $page ) { |
| 410 | + if ( array_key_exists( 'images', $page ) ) { |
| 411 | + foreach ( $page['images'] as $image ) { |
| 412 | + $images[] = $image['title']; |
| 413 | + } |
| 414 | + } |
| 415 | + } |
| 416 | + } |
| 417 | + |
| 418 | + return array_unique( $images ); |
| 419 | + } |
| 420 | + |
361 | 421 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -79,6 +79,44 @@ |
80 | 80 | } |
81 | 81 | ); |
82 | 82 | |
| 83 | + $('#divIncTemplates').click(function() { |
| 84 | + setIncludeFilesText(); |
| 85 | + }); |
| 86 | + |
| 87 | + $('#divIncFiles').hover( |
| 88 | + function() { |
| 89 | + var isHidden = $('#txtFileList').css( 'opacity' ) == 0; |
| 90 | + |
| 91 | + if ( isHidden ) { |
| 92 | + setIncludeFilesText(); |
| 93 | + } |
| 94 | + |
| 95 | + $('#txtFileList').fadeTo( |
| 96 | + isHidden ? 'slow' : 'fast', |
| 97 | + 1 |
| 98 | + ); |
| 99 | + }, |
| 100 | + function() { |
| 101 | + $('#txtFileList').fadeTo( 'fast', 0.5 ) |
| 102 | + } |
| 103 | + ); |
| 104 | + |
| 105 | + function setIncludeFilesText() { |
| 106 | + if ( $('#checkIncFiles').length != 0 ) { |
| 107 | + var files = window.wgPushPageFiles; |
| 108 | + |
| 109 | + if ( $('#checkIncTemplates').attr('checked') ) { |
| 110 | + files = files.concat( window.wgPushTemplateFiles ); |
| 111 | + } |
| 112 | + |
| 113 | + $('#txtFileList').text( |
| 114 | + files.length > 0 ? |
| 115 | + mediaWiki.msg( 'push-tab-embedded-files', files.join( ', ' ) ) // TODO: i18n |
| 116 | + : mediaWiki.msg( 'push-tab-no-embedded-files' ) |
| 117 | + ); |
| 118 | + } |
| 119 | + } |
| 120 | + |
83 | 121 | function getRemoteArticleInfo( targetId, targetUrl ) { |
84 | 122 | $.getJSON( |
85 | 123 | targetUrl + '/api.php?callback=?', |