r78559 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78558‎ | r78559 | r78560 >
Date:12:33, 18 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on file inclusion option
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Tab.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -54,6 +54,8 @@
5555 'push-tab-err-fileinfo' => 'Could not obtain which files are used on this page. None have been pushed.',
5656 'push-tab-err-filepush-unknown' => 'File push failed for an unknown reason.',
5757 '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.)',
5860
5961 // Special page
6062 'special-push' => 'Push pages',
Index: trunk/extensions/Push/Push.php
@@ -90,6 +90,8 @@
9191 'push-tab-err-fileinfo',
9292 'push-tab-err-filepush',
9393 'push-tab-err-filepush-unknown',
 94+ 'push-tab-embedded-files',
 95+ 'push-tab-no-embedded-files'
9496 );
9597
9698 // For backward compatibility with MW < 1.17.
Index: trunk/extensions/Push/includes/Push_Tab.php
@@ -277,14 +277,24 @@
278278 * @since 0.4
279279 */
280280 protected static function displayPushOptions() {
281 - global $wgOut, $wgUser;
 281+ global $wgOut, $wgUser, $wgTitle;
282282
283283 $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'push-tab-push-options' ) ) . '</h3>' );
284284
285 - self::displayIncTemplatesOption();
 285+ $usedTemplates = array_keys(
 286+ PushFunctions::getTemplates(
 287+ array( $wgTitle->getFullText() ),
 288+ array( $wgTitle->getFullText() => true )
 289+ )
 290+ );
286291
 292+ // Get rid of the page itself.
 293+ array_shift( $usedTemplates );
 294+
 295+ self::displayIncTemplatesOption( $usedTemplates );
 296+
287297 if ( $wgUser->isAllowed( 'filepush' ) ) {
288 - self::displayIncFilesOption();
 298+ self::displayIncFilesOption( $usedTemplates );
289299 }
290300 }
291301
@@ -292,31 +302,24 @@
293303 * Outputs the HTML for the "include templates" option.
294304 *
295305 * @since 0.4
 306+ *
 307+ * @param array $templates
296308 */
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;
308311
309312 $wgOut->addInlineScript(
310 - 'var wgPushTemplates = ' . json_encode( $usedTemplates ) . ';'
 313+ 'var wgPushTemplates = ' . json_encode( $templates ) . ';'
311314 );
312315
313 - foreach ( $usedTemplates as &$template ) {
 316+ foreach ( $templates as &$template ) {
314317 $template = "[[$template]]";
315318 }
316319
317320 $wgOut->addHTML(
318321 Html::rawElement(
319322 'div',
320 - array( 'id' => 'divIncTemplates', 'style' => 'display: table-cell' ),
 323+ array( 'id' => 'divIncTemplates', 'style' => 'display: table-row' ),
321324 Xml::check( 'checkIncTemplates', $egPushIncTemplates, array( 'id' => 'checkIncTemplates' ) ) .
322325 Html::element(
323326 'label',
@@ -327,8 +330,8 @@
328331 Html::rawElement(
329332 'div',
330333 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 ) ) :
333336 htmlspecialchars( wfMsg( 'push-tab-no-used-templates' ) )
334337 )
335338 )
@@ -339,22 +342,79 @@
340343 * Outputs the HTML for the "include files" option.
341344 *
342345 * @since 0.4
 346+ *
 347+ * @param array $templates
343348 */
344 - protected static function displayIncFilesOption() {
 349+ protected static function displayIncFilesOption( array $templates ) {
345350 global $wgOut, $wgTitle, $egPushIncFiles;
346351
 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+
347367 $wgOut->addHTML(
348368 Html::rawElement(
349369 'div',
350 - array( 'id' => 'divIncFiles' ),
 370+ array( 'id' => 'divIncFiles', 'style' => 'display: table-row' ),
351371 Xml::check( 'checkIncFiles', $egPushIncFiles, array( 'id' => 'checkIncFiles' ) ) .
352372 Html::element(
353373 'label',
354374 array( 'id' => 'lblIncFiles', 'for' => 'checkIncFiles' ),
355375 wfMsg( 'push-tab-inc-files' )
356 - )
 376+ ) .
 377+ '&#160;' .
 378+ Html::rawElement(
 379+ 'div',
 380+ array( 'style' => 'display:inline; opacity:0', 'id' => 'txtFileList' ),
 381+ ''
 382+ )
357383 )
358 - );
 384+ );
359385 }
360386
 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+
361421 }
\ No newline at end of file
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -79,6 +79,44 @@
8080 }
8181 );
8282
 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+
83121 function getRemoteArticleInfo( targetId, targetUrl ) {
84122 $.getJSON(
85123 targetUrl + '/api.php?callback=?',

Follow-up revisions

RevisionCommit summaryAuthorDate
r78563Follow up to r78559jeroendedauw14:35, 18 December 2010

Status & tagging log