https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113174

Revision: 113174
Author:   reedy
Date:     2012-03-06 20:12:38 +0000 (Tue, 06 Mar 2012)
Log Message:
-----------
MFT r111795, r111881, r111920, r112573, r112995, r113169

Modified Paths:
--------------
    branches/REL1_19/phase3/includes/specials/SpecialContributions.php
    branches/REL1_19/phase3/maintenance/populateRevisionSha1.php
    branches/REL1_19/phase3/resources/mediawiki.action/mediawiki.action.edit.js

Property Changed:
----------------
    branches/REL1_19/phase3/
    branches/REL1_19/phase3/includes/
    branches/REL1_19/phase3/includes/specials/


Property changes on: branches/REL1_19/phase3
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111380,111427,111478,111571,111574,111580,111597,111658,111673,111695,111697,111809,111832,111983,112021,112034,112037,112045-112046,112049,112061,112066,112079,112128,112152,112169-112170,112172-112173,112179,112184,112290,112313,112347,112374,112383-112384,112400,112408,112451,112456,112474,112526,112533-112534,112538,112563,112566-112567,112700,112750,112838,112855,112872-112873,112988,113001,113024,113039,113046,113085,113099
   + /branches/JSTesting:100352-107913
/branches/REL1_15/phase3:51646
/branches/REL1_17/phase3:81445,81448
/branches/new-installer/phase3:43664-66004
/branches/sqlite:58211-58321
/branches/wmf/1.18wmf1:97508,111667
/trunk/phase3:111002,111029,111034,111062,111067,111076,111085,111128,111144,111251,111380,111427,111478,111571,111574,111580,111597,111658,111673,111695,111697,111795,111809,111832,111881,111920,111983,112021,112034,112037,112045-112046,112049,112061,112066,112079,112128,112152,112169-112170,112172-112173,112179,112184,112290,112313,112347,112374,112383-112384,112400,112408,112451,112456,112474,112526,112533-112534,112538,112563,112566-112567,112573,112700,112750,112838,112855,112872-112873,112988,112995,113001,113024,113039,113046,113085,113099,113169


Property changes on: branches/REL1_19/phase3/includes
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111380,111427,111571,111574,111597,111658,111673,111695,111697,111809,111832,111983,112021,112034,112037,112045-112046,112049,112061,112066,112079,112128,112152,112184,112290,112313,112347,112374,112383,112408,112451,112456,112474,112526,112533-112534,112538,112563,112566-112567,112700,112750,112838,112855,112872-112873,112988,113001,113024,113039,113046,113099
   + /branches/JSTesting/includes:100352-107913
/branches/REL1_15/phase3/includes:51646
/branches/new-installer/phase3/includes:43664-66004
/branches/sqlite/includes:58211-58321
/branches/wmf/1.18wmf1/includes:97508,111667
/branches/wmf-deployment/includes:53381
/trunk/phase3/includes:111029,111034,111067,111085,111128,111144,111251,111380,111427,111571,111574,111597,111658,111673,111695,111697,111809,111832,111983,112021,112034,112037,112045-112046,112049,112061,112066,112079,112128,112152,112184,112290,112313,112347,112374,112383,112408,112451,112456,112474,112526,112533-112534,112538,112563,112566-112567,112700,112750,112838,112855,112872-112873,112988,112995,113001,113024,113039,113046,113099,113169


Property changes on: branches/REL1_19/phase3/includes/specials
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/JSTesting/includes/specials:100352-107913
/branches/REL1_15/phase3/includes/specials:51646
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967
/trunk/phase3/includes/specials:111085,111128,111144,111251,112872-112873,112988,113001,113024,113039,113046,113099
   + /branches/JSTesting/includes/specials:100352-107913
/branches/REL1_15/phase3/includes/specials:51646
/branches/sqlite/includes/specials:58211-58321
/branches/wmf-deployment/includes/specials:53381,56967
/trunk/phase3/includes/specials:111085,111128,111144,111251,112872-112873,112988,112995,113001,113024,113039,113046,113099,113169

Modified: branches/REL1_19/phase3/includes/specials/SpecialContributions.php
===================================================================
--- branches/REL1_19/phase3/includes/specials/SpecialContributions.php  
2012-03-06 20:00:47 UTC (rev 113173)
+++ branches/REL1_19/phase3/includes/specials/SpecialContributions.php  
2012-03-06 20:12:38 UTC (rev 113174)
@@ -790,9 +790,16 @@
                        array( 'action' => 'history' )
                );
 
-               $parentLen = isset( $this->mParentLens[$row->rev_parent_id] ) ? 
$this->mParentLens[$row->rev_parent_id] : 0;
-               $chardiff = ' . . ' . ChangesList::showCharacterDifference(
-                               $parentLen, $row->rev_len ) . ' . . ';
+               if ( $row->rev_parent_id === null ) {
+                       // For some reason rev_parent_id isn't populated for 
this row.
+                       // Its rumoured this is true on wikipedia for some 
revisions (bug 34922).
+                       // Next best thing is to have the total number of bytes.
+                       $chardiff = ' . . ' . Linker::formatRevisionSize( 
$row->rev_len ) . ' . . ';
+               } else {
+                       $parentLen = isset( 
$this->mParentLens[$row->rev_parent_id] ) ? 
$this->mParentLens[$row->rev_parent_id] : 0;
+                       $chardiff = ' . . ' . 
ChangesList::showCharacterDifference(
+                                       $parentLen, $row->rev_len ) . ' . . ';
+               }
 
                $lang = $this->getLanguage();
                $comment = $lang->getDirMark() . Linker::revComment( $rev, 
false, true );

Modified: branches/REL1_19/phase3/maintenance/populateRevisionSha1.php
===================================================================
--- branches/REL1_19/phase3/maintenance/populateRevisionSha1.php        
2012-03-06 20:00:47 UTC (rev 113173)
+++ branches/REL1_19/phase3/maintenance/populateRevisionSha1.php        
2012-03-06 20:12:38 UTC (rev 113174)
@@ -36,32 +36,38 @@
 
        protected function doDBUpdates() {
                $db = $this->getDB( DB_MASTER );
+
                if ( !$db->tableExists( 'revision' ) ) {
                        $this->error( "revision table does not exist", true );
-               }
-               if ( !$db->tableExists( 'archive' ) ) {
+               } elseif ( !$db->tableExists( 'archive' ) ) {
                        $this->error( "archive table does not exist", true );
                }
 
                $this->output( "Populating rev_sha1 column\n" );
-               $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
+               $rc = $this->doSha1Updates( 'revision', 'rev_id', 'rev' );
 
                $this->output( "Populating ar_sha1 column\n" );
-               $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
+               $ac = $this->doSha1Updates( 'archive', 'ar_rev_id', 'ar' );
+               $this->output( "Populating ar_sha1 column legacy rows\n" );
+               $ac += $this->doSha1LegacyUpdates();
 
                $this->output( "rev_sha1 and ar_sha1 population complete [$rc 
revision rows, $ac archive rows].\n" );
                return true;
        }
 
        /**
+        * @param $table string
+        * @param $idCol
+        * @param $prefix string
         * @return Integer Rows changed
         */
-       protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
+       protected function doSha1Updates( $table, $idCol, $prefix ) {
+               $db = $this->getDB( DB_MASTER );
                $start = $db->selectField( $table, "MIN($idCol)", false, 
__METHOD__ );
                $end = $db->selectField( $table, "MAX($idCol)", false, 
__METHOD__ );
                if ( !$start || !$end ) {
                        $this->output( "...$table table seems to be empty.\n" );
-                       return true;
+                       return 0;
                }
 
                $count = 0;
@@ -77,20 +83,7 @@
 
                        $db->begin();
                        foreach ( $res as $row ) {
-                               if ( $table === 'archive' ) {
-                                       $rev = Revision::newFromArchiveRow( 
$row );
-                               } else {
-                                       $rev = new Revision( $row );
-                               }
-                               $text = $rev->getRawText();
-                               if ( !is_string( $text ) ) {
-                                       # This should not happen, but sometimes 
does (bug 20757)
-                                       $this->output( "Text of revision 
{$row->$idCol} unavailable!\n" );
-                               } else {
-                                       $db->update( $table,
-                                               array( "{$prefix}_sha1" => 
Revision::base36Sha1( $text ) ),
-                                               array( $idCol => $row->$idCol ),
-                                               __METHOD__ );
+                               if ( $this->upgradeRow( $row, $table, $idCol, 
$prefix ) ) {
                                        $count++;
                                }
                        }
@@ -102,6 +95,90 @@
                }
                return $count;
        }
+
+       /**
+        * @return int
+        */
+       protected function doSha1LegacyUpdates() {
+               $count = 0;
+               $db = $this->getDB( DB_MASTER );
+               $res = $db->select( 'archive', '*', array( 'ar_rev_id IS NULL' 
), __METHOD__ );
+
+               $updateSize = 0;
+               $db->begin();
+               foreach ( $res as $row ) {
+                       if ( $this->upgradeLegacyArchiveRow( $row ) ) {
+                               ++$count;
+                       }
+                       if ( ++$updateSize >= 100 ) {
+                               $updateSize = 0;
+                               $db->commit();
+                               $this->output( "Commited row with 
ar_timestamp={$row->ar_timestamp}\n" );
+                               wfWaitForSlaves();
+                               $db->begin();
+                       }
+               }
+               $db->commit();
+               return $count;
+       }
+
+       /**
+        * @param $row
+        * @param $table
+        * @param $idCol
+        * @param $prefix
+        * @return bool
+        */
+       protected function upgradeRow( $row, $table, $idCol, $prefix ) {
+               $db = $this->getDB( DB_MASTER );
+               if ( $table === 'archive' ) {
+                       $rev = Revision::newFromArchiveRow( $row );
+               } else {
+                       $rev = new Revision( $row );
+               }
+               $text = $rev->getRawText();
+               if ( !is_string( $text ) ) {
+                       # This should not happen, but sometimes does (bug 20757)
+                       $this->output( "Text of revision with 
{$idCol}={$row->$idCol} unavailable!\n" );
+                       return false;
+               } else {
+                       $db->update( $table,
+                               array( "{$prefix}_sha1" => 
Revision::base36Sha1( $text ) ),
+                               array( $idCol => $row->$idCol ),
+                               __METHOD__ 
+                       );
+                       return true;
+               }
+       }
+
+       /**
+        * @param $row
+        * @return bool
+        */
+       protected function upgradeLegacyArchiveRow( $row ) {
+               $db = $this->getDB( DB_MASTER );
+               $rev = Revision::newFromArchiveRow( $row );
+               $text = $rev->getRawText();
+               if ( !is_string( $text ) ) {
+                       # This should not happen, but sometimes does (bug 20757)
+                       $this->output( "Text of revision with timestamp 
{$row->ar_timestamp} unavailable!\n" );
+                       return false;
+               } else {
+                       # Archive table as no PK, but (NS,title,time) should be 
near unique.
+                       # Any duplicates on those should also have duplicated 
text anyway.
+                       $db->update( 'archive',
+                               array( 'ar_sha1' => Revision::base36Sha1( $text 
) ),
+                               array(
+                                       'ar_namespace' => $row->ar_namespace,
+                                       'ar_title'     => $row->ar_title,
+                                       'ar_timestamp' => $row->ar_timestamp,
+                                       'ar_len'       => $row->ar_len // extra 
sanity
+                               ),
+                               __METHOD__ 
+                       );
+                       return true;
+               }
+       }
 }
 
 $maintClass = "PopulateRevisionSha1";

Modified: 
branches/REL1_19/phase3/resources/mediawiki.action/mediawiki.action.edit.js
===================================================================
--- branches/REL1_19/phase3/resources/mediawiki.action/mediawiki.action.edit.js 
2012-03-06 20:00:47 UTC (rev 113173)
+++ branches/REL1_19/phase3/resources/mediawiki.action/mediawiki.action.edit.js 
2012-03-06 20:12:38 UTC (rev 113174)
@@ -1,79 +1,96 @@
-(function( $ ) {
-       // currentFocus is used to determine where to insert tags
-       var currentFocused = $( '#wpTextbox1' );
+( function ( $, mw ) {
+       var isReady, toolbar, currentFocused;
 
-       mw.toolbar = {
-               $toolbar : false,
-               buttons : [],
-               isReady : false,
-               // If you want to add buttons, use
-               // mw.toolbar.addButton( imageFile, speedTip, tagOpen, 
tagClose, sampleText, imageId, selectText );
-               addButton : function() {
-                       if ( this.isReady ) {
-                               this.insertButton.apply( this, arguments );
+       isReady = false;
+
+       toolbar = {
+               $toolbar: false,
+               buttons: [],
+               /**
+                * If you want to add buttons, use
+                * mw.toolbar.addButton( imageFile, speedTip, tagOpen, 
tagClose, sampleText, imageId, selectText );
+                */
+               addButton: function () {
+                       if ( isReady ) {
+                               toolbar.insertButton.apply( toolbar, arguments 
);
                        } else {
-                               this.buttons.push( [].slice.call( arguments ) );
+                               toolbar.buttons.push( [].slice.call( arguments 
) );
                        }       
                },
-               insertButton : function( imageFile, speedTip, tagOpen, 
tagClose, sampleText, imageId, selectText ) {
+               insertButton: function ( imageFile, speedTip, tagOpen, 
tagClose, sampleText, imageId, selectText ) {
                        var image = $('<img>', {
-                               width  : 23,
-                               height : 22,
-                               src    : imageFile,
-                               alt    : speedTip,
-                               title  : speedTip,
-                               id     : imageId || '',
+                               width : 23,
+                               height: 22,
+                               src   : imageFile,
+                               alt   : speedTip,
+                               title : speedTip,
+                               id    : imageId || '',
                                'class': 'mw-toolbar-editbutton'
-                       } ).click( function() {
+                       } ).click( function () {
                                mw.toolbar.insertTags( tagOpen, tagClose, 
sampleText, selectText );
                                return false;
                        } );
 
-                       this.$toolbar.append( image );
+                       toolbar.$toolbar.append( image );
                        return true;
                },
 
-               // apply tagOpen/tagClose to selection in textarea,
-               // use sampleText instead of selection if there is none
-               insertTags : function( tagOpen, tagClose, sampleText, 
selectText) {
-                       if ( currentFocused.length ) {
+               /**
+                * apply tagOpen/tagClose to selection in textarea,
+                * use sampleText instead of selection if there is none.
+                */
+               insertTags: function ( tagOpen, tagClose, sampleText, 
selectText ) {
+                       if ( currentFocused && currentFocused.length ) {
                                currentFocused.textSelection(
-                                       'encapsulateSelection', { 'pre': 
tagOpen, 'peri': sampleText, 'post': tagClose }
+                                       'encapsulateSelection', {
+                                               'pre': tagOpen,
+                                               'peri': sampleText,
+                                               'post': tagClose
+                                       }
                                );
                        }
                },
 
                // For backwards compatibility
-               init : function() {},
+               init: function () {}
+       };
 
-               onReady : function() {
-                       this.$toolbar = $( '#toolbar' );
-                       this.isReady = true;
-                       // Legacy
-                       // Merge buttons from mwCustomEditButtons
-                       var buttons = [].concat( this.buttons, 
window.mwCustomEditButtons );
-                       for ( var i = 0; i < buttons.length; i++ ) {
-                               if ( $.isArray( buttons[i] ) ) {
-                                       // Passes our button array as arguments
-                                       this.insertButton.apply( this, 
buttons[i] );
-                               } else {
-                                       // Legacy mwCustomEditButtons is an 
object
-                                       var c = buttons[i];
-                                       this.insertButton( c.imageFile, 
c.speedTip, c.tagOpen, 
-                                               c.tagClose, c.sampleText, 
c.imageId, c.selectText );
-                               }
+       // Legacy (for compatibility with the code previously in 
skins/common.edit.js)
+       window.addButton = toolbar.addButton;
+       window.insertTags = toolbar.insertTags;
+
+       // Explose publicly
+       mw.toolbar = toolbar;
+
+       $( document ).ready( function () {
+               var buttons, i, c, iframe;
+
+               // currentFocus is used to determine where to insert tags
+               currentFocused = $( '#wpTextbox1' );
+
+               // Populate the selector cache for $toolbar 
+               toolbar.$toolbar = $( '#toolbar' );
+
+               // Legacy: Merge buttons from mwCustomEditButtons
+               buttons = [].concat( toolbar.buttons, 
window.mwCustomEditButtons );
+               for ( i = 0; i < buttons.length; i++ ) {
+                       if ( $.isArray( buttons[i] ) ) {
+                               // Passes our button array as arguments
+                               toolbar.insertButton.apply( toolbar, buttons[i] 
);
+                       } else {
+                               // Legacy mwCustomEditButtons is an object
+                               c = buttons[i];
+                               toolbar.insertButton( c.imageFile, c.speedTip, 
c.tagOpen, 
+                                       c.tagClose, c.sampleText, c.imageId, 
c.selectText );
                        }
-                       return true;
                }
-       };
 
-       //Legacy
-       window.addButton =  mw.toolbar.addButton;
-       window.insertTags = mw.toolbar.insertTags;
+               // This causes further calls to addButton to go to insertion 
directly
+               // instead of to the toolbar.buttons queue.
+               // It is important that this is after the one and only loop 
through
+               // the the toolbar.buttons queue
+               isReady = true;
 
-       $( document ).ready( function() {
-               mw.toolbar.onReady();
-
                // Make sure edit summary does not exceed byte limit
                $( '#wpSummary' ).byteLimit( 250 );
 
@@ -81,32 +98,37 @@
                 * Restore the edit box scroll state following a preview 
operation,
                 * and set up a form submission handler to remember this state
                 */
-               var scrollEditBox = function() {
-                       var editBox = document.getElementById( 'wpTextbox1' );
-                       var scrollTop = document.getElementById( 'wpScrolltop' 
);
-                       var $editForm = $( '#editform' );
-                       if( $editForm.length && editBox && scrollTop ) {
-                               if( scrollTop.value ) {
+               ( function scrollEditBox() {
+                       var editBox, scrollTop, $editForm;
+
+                       editBox = document.getElementById( 'wpTextbox1' );
+                       scrollTop = document.getElementById( 'wpScrolltop' );
+                       $editForm = $( '#editform' );
+                       if ( $editForm.length && editBox && scrollTop ) {
+                               if ( scrollTop.value ) {
                                        editBox.scrollTop = scrollTop.value;
                                }
-                               $editForm.submit( function() {
+                               $editForm.submit( function () {
                                        scrollTop.value = editBox.scrollTop;
                                });
                        }
-               };
-               scrollEditBox();
+               }() );
 
-               $( 'textarea, input:text' ).focus( function() {
+               $( 'textarea, input:text' ).focus( function () {
                        currentFocused = $(this);
                });
 
                // HACK: make currentFocused work with the usability iframe
                // With proper focus detection support (HTML 5!) this'll be 
much cleaner
-               var iframe = $( '.wikiEditor-ui-text iframe' );
+               iframe = $( '.wikiEditor-ui-text iframe' );
                if ( iframe.length > 0 ) {
                        $( iframe.get( 0 ).contentWindow.document )
-                               .add( iframe.get( 0 
).contentWindow.document.body ) // for IE
-                               .focus( function() { currentFocused = iframe; } 
);
+                               // for IE
+                               .add( iframe.get( 0 
).contentWindow.document.body )
+                               .focus( function () {
+                                       currentFocused = iframe;
+                               } );
                }
        });
-})(jQuery);
+
+}( jQuery, mediaWiki ) );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to