Index: branches/wmf/1.19wmf1/maintenance/populateRevisionSha1.php |
— | — | @@ -36,32 +36,38 @@ |
37 | 37 | |
38 | 38 | protected function doDBUpdates() { |
39 | 39 | $db = $this->getDB( DB_MASTER ); |
| 40 | + |
40 | 41 | if ( !$db->tableExists( 'revision' ) ) { |
41 | 42 | $this->error( "revision table does not exist", true ); |
42 | | - } |
43 | | - if ( !$db->tableExists( 'archive' ) ) { |
| 43 | + } elseif ( !$db->tableExists( 'archive' ) ) { |
44 | 44 | $this->error( "archive table does not exist", true ); |
45 | 45 | } |
46 | 46 | |
47 | 47 | $this->output( "Populating rev_sha1 column\n" ); |
48 | | - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' ); |
| 48 | + $rc = $this->doSha1Updates( 'revision', 'rev_id', 'rev' ); |
49 | 49 | |
50 | 50 | $this->output( "Populating ar_sha1 column\n" ); |
51 | | - $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' ); |
| 51 | + $ac = $this->doSha1Updates( 'archive', 'ar_rev_id', 'ar' ); |
| 52 | + $this->output( "Populating ar_sha1 column legacy rows\n" ); |
| 53 | + $ac += $this->doSha1LegacyUpdates(); |
52 | 54 | |
53 | 55 | $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" ); |
54 | 56 | return true; |
55 | 57 | } |
56 | 58 | |
57 | 59 | /** |
| 60 | + * @param $table string |
| 61 | + * @param $idCol |
| 62 | + * @param $prefix string |
58 | 63 | * @return Integer Rows changed |
59 | 64 | */ |
60 | | - protected function doSha1Updates( $db, $table, $idCol, $prefix ) { |
| 65 | + protected function doSha1Updates( $table, $idCol, $prefix ) { |
| 66 | + $db = $this->getDB( DB_MASTER ); |
61 | 67 | $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ ); |
62 | 68 | $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ ); |
63 | 69 | if ( !$start || !$end ) { |
64 | 70 | $this->output( "...$table table seems to be empty.\n" ); |
65 | | - return true; |
| 71 | + return 0; |
66 | 72 | } |
67 | 73 | |
68 | 74 | $count = 0; |
— | — | @@ -77,20 +83,7 @@ |
78 | 84 | |
79 | 85 | $db->begin(); |
80 | 86 | foreach ( $res as $row ) { |
81 | | - if ( $table === 'archive' ) { |
82 | | - $rev = Revision::newFromArchiveRow( $row ); |
83 | | - } else { |
84 | | - $rev = new Revision( $row ); |
85 | | - } |
86 | | - $text = $rev->getRawText(); |
87 | | - if ( !is_string( $text ) ) { |
88 | | - # This should not happen, but sometimes does (bug 20757) |
89 | | - $this->output( "Text of revision {$row->$idCol} unavailable!\n" ); |
90 | | - } else { |
91 | | - $db->update( $table, |
92 | | - array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ), |
93 | | - array( $idCol => $row->$idCol ), |
94 | | - __METHOD__ ); |
| 87 | + if ( $this->upgradeRow( $row, $table, $idCol, $prefix ) ) { |
95 | 88 | $count++; |
96 | 89 | } |
97 | 90 | } |
— | — | @@ -102,6 +95,90 @@ |
103 | 96 | } |
104 | 97 | return $count; |
105 | 98 | } |
| 99 | + |
| 100 | + /** |
| 101 | + * @return int |
| 102 | + */ |
| 103 | + protected function doSha1LegacyUpdates() { |
| 104 | + $count = 0; |
| 105 | + $db = $this->getDB( DB_MASTER ); |
| 106 | + $res = $db->select( 'archive', '*', array( 'ar_rev_id IS NULL' ), __METHOD__ ); |
| 107 | + |
| 108 | + $updateSize = 0; |
| 109 | + $db->begin(); |
| 110 | + foreach ( $res as $row ) { |
| 111 | + if ( $this->upgradeLegacyArchiveRow( $row ) ) { |
| 112 | + ++$count; |
| 113 | + } |
| 114 | + if ( ++$updateSize >= 100 ) { |
| 115 | + $updateSize = 0; |
| 116 | + $db->commit(); |
| 117 | + $this->output( "Commited row with ar_timestamp={$row->ar_timestamp}\n" ); |
| 118 | + wfWaitForSlaves(); |
| 119 | + $db->begin(); |
| 120 | + } |
| 121 | + } |
| 122 | + $db->commit(); |
| 123 | + return $count; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @param $row |
| 128 | + * @param $table |
| 129 | + * @param $idCol |
| 130 | + * @param $prefix |
| 131 | + * @return bool |
| 132 | + */ |
| 133 | + protected function upgradeRow( $row, $table, $idCol, $prefix ) { |
| 134 | + $db = $this->getDB( DB_MASTER ); |
| 135 | + if ( $table === 'archive' ) { |
| 136 | + $rev = Revision::newFromArchiveRow( $row ); |
| 137 | + } else { |
| 138 | + $rev = new Revision( $row ); |
| 139 | + } |
| 140 | + $text = $rev->getRawText(); |
| 141 | + if ( !is_string( $text ) ) { |
| 142 | + # This should not happen, but sometimes does (bug 20757) |
| 143 | + $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" ); |
| 144 | + return false; |
| 145 | + } else { |
| 146 | + $db->update( $table, |
| 147 | + array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ), |
| 148 | + array( $idCol => $row->$idCol ), |
| 149 | + __METHOD__ |
| 150 | + ); |
| 151 | + return true; |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * @param $row |
| 157 | + * @return bool |
| 158 | + */ |
| 159 | + protected function upgradeLegacyArchiveRow( $row ) { |
| 160 | + $db = $this->getDB( DB_MASTER ); |
| 161 | + $rev = Revision::newFromArchiveRow( $row ); |
| 162 | + $text = $rev->getRawText(); |
| 163 | + if ( !is_string( $text ) ) { |
| 164 | + # This should not happen, but sometimes does (bug 20757) |
| 165 | + $this->output( "Text of revision with timestamp {$row->ar_timestamp} unavailable!\n" ); |
| 166 | + return false; |
| 167 | + } else { |
| 168 | + # Archive table as no PK, but (NS,title,time) should be near unique. |
| 169 | + # Any duplicates on those should also have duplicated text anyway. |
| 170 | + $db->update( 'archive', |
| 171 | + array( 'ar_sha1' => Revision::base36Sha1( $text ) ), |
| 172 | + array( |
| 173 | + 'ar_namespace' => $row->ar_namespace, |
| 174 | + 'ar_title' => $row->ar_title, |
| 175 | + 'ar_timestamp' => $row->ar_timestamp, |
| 176 | + 'ar_len' => $row->ar_len // extra sanity |
| 177 | + ), |
| 178 | + __METHOD__ |
| 179 | + ); |
| 180 | + return true; |
| 181 | + } |
| 182 | + } |
106 | 183 | } |
107 | 184 | |
108 | 185 | $maintClass = "PopulateRevisionSha1"; |
Index: branches/wmf/1.19wmf1/includes/specials/SpecialContributions.php |
— | — | @@ -791,9 +791,16 @@ |
792 | 792 | array( 'action' => 'history' ) |
793 | 793 | ); |
794 | 794 | |
795 | | - $parentLen = isset( $this->mParentLens[$row->rev_parent_id] ) ? $this->mParentLens[$row->rev_parent_id] : 0; |
796 | | - $chardiff = ' . . ' . ChangesList::showCharacterDifference( |
797 | | - $parentLen, $row->rev_len ) . ' . . '; |
| 795 | + if ( $row->rev_parent_id === null ) { |
| 796 | + // For some reason rev_parent_id isn't populated for this row. |
| 797 | + // Its rumoured this is true on wikipedia for some revisions (bug 34922). |
| 798 | + // Next best thing is to have the total number of bytes. |
| 799 | + $chardiff = ' . . ' . Linker::formatRevisionSize( $row->rev_len ) . ' . . '; |
| 800 | + } else { |
| 801 | + $parentLen = isset( $this->mParentLens[$row->rev_parent_id] ) ? $this->mParentLens[$row->rev_parent_id] : 0; |
| 802 | + $chardiff = ' . . ' . ChangesList::showCharacterDifference( |
| 803 | + $parentLen, $row->rev_len ) . ' . . '; |
| 804 | + } |
798 | 805 | |
799 | 806 | $lang = $this->getLanguage(); |
800 | 807 | $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true ); |
Property changes on: branches/wmf/1.19wmf1/includes/specials |
___________________________________________________________________ |
Modified: svn:mergeinfo |
801 | 808 | Merged /trunk/phase3/includes/specials:r112995,113169 |
Property changes on: branches/wmf/1.19wmf1/includes |
___________________________________________________________________ |
Modified: svn:mergeinfo |
802 | 809 | Merged /trunk/phase3/includes:r112995,113169 |
Index: branches/wmf/1.19wmf1/resources/mediawiki.action/mediawiki.action.edit.js |
— | — | @@ -1,79 +1,96 @@ |
2 | | -(function( $ ) { |
3 | | - // currentFocus is used to determine where to insert tags |
4 | | - var currentFocused = $( '#wpTextbox1' ); |
| 2 | +( function ( $, mw ) { |
| 3 | + var isReady, toolbar, currentFocused; |
5 | 4 | |
6 | | - mw.toolbar = { |
7 | | - $toolbar : false, |
8 | | - buttons : [], |
9 | | - isReady : false, |
10 | | - // If you want to add buttons, use |
11 | | - // mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ); |
12 | | - addButton : function() { |
13 | | - if ( this.isReady ) { |
14 | | - this.insertButton.apply( this, arguments ); |
| 5 | + isReady = false; |
| 6 | + |
| 7 | + toolbar = { |
| 8 | + $toolbar: false, |
| 9 | + buttons: [], |
| 10 | + /** |
| 11 | + * If you want to add buttons, use |
| 12 | + * mw.toolbar.addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ); |
| 13 | + */ |
| 14 | + addButton: function () { |
| 15 | + if ( isReady ) { |
| 16 | + toolbar.insertButton.apply( toolbar, arguments ); |
15 | 17 | } else { |
16 | | - this.buttons.push( [].slice.call( arguments ) ); |
| 18 | + toolbar.buttons.push( [].slice.call( arguments ) ); |
17 | 19 | } |
18 | 20 | }, |
19 | | - insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { |
| 21 | + insertButton: function ( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { |
20 | 22 | var image = $('<img>', { |
21 | | - width : 23, |
22 | | - height : 22, |
23 | | - src : imageFile, |
24 | | - alt : speedTip, |
25 | | - title : speedTip, |
26 | | - id : imageId || '', |
| 23 | + width : 23, |
| 24 | + height: 22, |
| 25 | + src : imageFile, |
| 26 | + alt : speedTip, |
| 27 | + title : speedTip, |
| 28 | + id : imageId || '', |
27 | 29 | 'class': 'mw-toolbar-editbutton' |
28 | | - } ).click( function() { |
| 30 | + } ).click( function () { |
29 | 31 | mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText ); |
30 | 32 | return false; |
31 | 33 | } ); |
32 | 34 | |
33 | | - this.$toolbar.append( image ); |
| 35 | + toolbar.$toolbar.append( image ); |
34 | 36 | return true; |
35 | 37 | }, |
36 | 38 | |
37 | | - // apply tagOpen/tagClose to selection in textarea, |
38 | | - // use sampleText instead of selection if there is none |
39 | | - insertTags : function( tagOpen, tagClose, sampleText, selectText) { |
40 | | - if ( currentFocused.length ) { |
| 39 | + /** |
| 40 | + * apply tagOpen/tagClose to selection in textarea, |
| 41 | + * use sampleText instead of selection if there is none. |
| 42 | + */ |
| 43 | + insertTags: function ( tagOpen, tagClose, sampleText, selectText ) { |
| 44 | + if ( currentFocused && currentFocused.length ) { |
41 | 45 | currentFocused.textSelection( |
42 | | - 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose } |
| 46 | + 'encapsulateSelection', { |
| 47 | + 'pre': tagOpen, |
| 48 | + 'peri': sampleText, |
| 49 | + 'post': tagClose |
| 50 | + } |
43 | 51 | ); |
44 | 52 | } |
45 | 53 | }, |
46 | 54 | |
47 | 55 | // For backwards compatibility |
48 | | - init : function() {}, |
| 56 | + init: function () {} |
| 57 | + }; |
49 | 58 | |
50 | | - onReady : function() { |
51 | | - this.$toolbar = $( '#toolbar' ); |
52 | | - this.isReady = true; |
53 | | - // Legacy |
54 | | - // Merge buttons from mwCustomEditButtons |
55 | | - var buttons = [].concat( this.buttons, window.mwCustomEditButtons ); |
56 | | - for ( var i = 0; i < buttons.length; i++ ) { |
57 | | - if ( $.isArray( buttons[i] ) ) { |
58 | | - // Passes our button array as arguments |
59 | | - this.insertButton.apply( this, buttons[i] ); |
60 | | - } else { |
61 | | - // Legacy mwCustomEditButtons is an object |
62 | | - var c = buttons[i]; |
63 | | - this.insertButton( c.imageFile, c.speedTip, c.tagOpen, |
64 | | - c.tagClose, c.sampleText, c.imageId, c.selectText ); |
65 | | - } |
| 59 | + // Legacy (for compatibility with the code previously in skins/common.edit.js) |
| 60 | + window.addButton = toolbar.addButton; |
| 61 | + window.insertTags = toolbar.insertTags; |
| 62 | + |
| 63 | + // Explose publicly |
| 64 | + mw.toolbar = toolbar; |
| 65 | + |
| 66 | + $( document ).ready( function () { |
| 67 | + var buttons, i, c, iframe; |
| 68 | + |
| 69 | + // currentFocus is used to determine where to insert tags |
| 70 | + currentFocused = $( '#wpTextbox1' ); |
| 71 | + |
| 72 | + // Populate the selector cache for $toolbar |
| 73 | + toolbar.$toolbar = $( '#toolbar' ); |
| 74 | + |
| 75 | + // Legacy: Merge buttons from mwCustomEditButtons |
| 76 | + buttons = [].concat( toolbar.buttons, window.mwCustomEditButtons ); |
| 77 | + for ( i = 0; i < buttons.length; i++ ) { |
| 78 | + if ( $.isArray( buttons[i] ) ) { |
| 79 | + // Passes our button array as arguments |
| 80 | + toolbar.insertButton.apply( toolbar, buttons[i] ); |
| 81 | + } else { |
| 82 | + // Legacy mwCustomEditButtons is an object |
| 83 | + c = buttons[i]; |
| 84 | + toolbar.insertButton( c.imageFile, c.speedTip, c.tagOpen, |
| 85 | + c.tagClose, c.sampleText, c.imageId, c.selectText ); |
66 | 86 | } |
67 | | - return true; |
68 | 87 | } |
69 | | - }; |
70 | 88 | |
71 | | - //Legacy |
72 | | - window.addButton = mw.toolbar.addButton; |
73 | | - window.insertTags = mw.toolbar.insertTags; |
| 89 | + // This causes further calls to addButton to go to insertion directly |
| 90 | + // instead of to the toolbar.buttons queue. |
| 91 | + // It is important that this is after the one and only loop through |
| 92 | + // the the toolbar.buttons queue |
| 93 | + isReady = true; |
74 | 94 | |
75 | | - $( document ).ready( function() { |
76 | | - mw.toolbar.onReady(); |
77 | | - |
78 | 95 | // Make sure edit summary does not exceed byte limit |
79 | 96 | $( '#wpSummary' ).byteLimit( 250 ); |
80 | 97 | |
— | — | @@ -81,32 +98,37 @@ |
82 | 99 | * Restore the edit box scroll state following a preview operation, |
83 | 100 | * and set up a form submission handler to remember this state |
84 | 101 | */ |
85 | | - var scrollEditBox = function() { |
86 | | - var editBox = document.getElementById( 'wpTextbox1' ); |
87 | | - var scrollTop = document.getElementById( 'wpScrolltop' ); |
88 | | - var $editForm = $( '#editform' ); |
89 | | - if( $editForm.length && editBox && scrollTop ) { |
90 | | - if( scrollTop.value ) { |
| 102 | + ( function scrollEditBox() { |
| 103 | + var editBox, scrollTop, $editForm; |
| 104 | + |
| 105 | + editBox = document.getElementById( 'wpTextbox1' ); |
| 106 | + scrollTop = document.getElementById( 'wpScrolltop' ); |
| 107 | + $editForm = $( '#editform' ); |
| 108 | + if ( $editForm.length && editBox && scrollTop ) { |
| 109 | + if ( scrollTop.value ) { |
91 | 110 | editBox.scrollTop = scrollTop.value; |
92 | 111 | } |
93 | | - $editForm.submit( function() { |
| 112 | + $editForm.submit( function () { |
94 | 113 | scrollTop.value = editBox.scrollTop; |
95 | 114 | }); |
96 | 115 | } |
97 | | - }; |
98 | | - scrollEditBox(); |
| 116 | + }() ); |
99 | 117 | |
100 | | - $( 'textarea, input:text' ).focus( function() { |
| 118 | + $( 'textarea, input:text' ).focus( function () { |
101 | 119 | currentFocused = $(this); |
102 | 120 | }); |
103 | 121 | |
104 | 122 | // HACK: make currentFocused work with the usability iframe |
105 | 123 | // With proper focus detection support (HTML 5!) this'll be much cleaner |
106 | | - var iframe = $( '.wikiEditor-ui-text iframe' ); |
| 124 | + iframe = $( '.wikiEditor-ui-text iframe' ); |
107 | 125 | if ( iframe.length > 0 ) { |
108 | 126 | $( iframe.get( 0 ).contentWindow.document ) |
109 | | - .add( iframe.get( 0 ).contentWindow.document.body ) // for IE |
110 | | - .focus( function() { currentFocused = iframe; } ); |
| 127 | + // for IE |
| 128 | + .add( iframe.get( 0 ).contentWindow.document.body ) |
| 129 | + .focus( function () { |
| 130 | + currentFocused = iframe; |
| 131 | + } ); |
111 | 132 | } |
112 | 133 | }); |
113 | | -})(jQuery); |
| 134 | + |
| 135 | +}( jQuery, mediaWiki ) ); |
Property changes on: branches/wmf/1.19wmf1 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
114 | 136 | Merged /trunk/phase3:r111795,111881,111920,112573,112995,113169 |