r113175 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113174‎ | r113175 | r113176 >
Date:20:13, 6 March 2012
Author:reedy
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1 (modified) (history)
  • /branches/wmf/1.19wmf1/includes (modified) (history)
  • /branches/wmf/1.19wmf1/includes/specials (modified) (history)
  • /branches/wmf/1.19wmf1/includes/specials/SpecialContributions.php (modified) (history)
  • /branches/wmf/1.19wmf1/maintenance/populateRevisionSha1.php (modified) (history)
  • /branches/wmf/1.19wmf1/resources/mediawiki.action/mediawiki.action.edit.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/maintenance/populateRevisionSha1.php
@@ -36,32 +36,38 @@
3737
3838 protected function doDBUpdates() {
3939 $db = $this->getDB( DB_MASTER );
 40+
4041 if ( !$db->tableExists( 'revision' ) ) {
4142 $this->error( "revision table does not exist", true );
42 - }
43 - if ( !$db->tableExists( 'archive' ) ) {
 43+ } elseif ( !$db->tableExists( 'archive' ) ) {
4444 $this->error( "archive table does not exist", true );
4545 }
4646
4747 $this->output( "Populating rev_sha1 column\n" );
48 - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
 48+ $rc = $this->doSha1Updates( 'revision', 'rev_id', 'rev' );
4949
5050 $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();
5254
5355 $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" );
5456 return true;
5557 }
5658
5759 /**
 60+ * @param $table string
 61+ * @param $idCol
 62+ * @param $prefix string
5863 * @return Integer Rows changed
5964 */
60 - protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
 65+ protected function doSha1Updates( $table, $idCol, $prefix ) {
 66+ $db = $this->getDB( DB_MASTER );
6167 $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
6268 $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
6369 if ( !$start || !$end ) {
6470 $this->output( "...$table table seems to be empty.\n" );
65 - return true;
 71+ return 0;
6672 }
6773
6874 $count = 0;
@@ -77,20 +83,7 @@
7884
7985 $db->begin();
8086 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 ) ) {
9588 $count++;
9689 }
9790 }
@@ -102,6 +95,90 @@
10396 }
10497 return $count;
10598 }
 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+ }
106183 }
107184
108185 $maintClass = "PopulateRevisionSha1";
Index: branches/wmf/1.19wmf1/includes/specials/SpecialContributions.php
@@ -791,9 +791,16 @@
792792 array( 'action' => 'history' )
793793 );
794794
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+ }
798805
799806 $lang = $this->getLanguage();
800807 $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true );
Property changes on: branches/wmf/1.19wmf1/includes/specials
___________________________________________________________________
Modified: svn:mergeinfo
801808 Merged /trunk/phase3/includes/specials:r112995,113169
Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
802809 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;
54
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 );
1517 } else {
16 - this.buttons.push( [].slice.call( arguments ) );
 18+ toolbar.buttons.push( [].slice.call( arguments ) );
1719 }
1820 },
19 - insertButton : function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
 21+ insertButton: function ( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) {
2022 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 || '',
2729 'class': 'mw-toolbar-editbutton'
28 - } ).click( function() {
 30+ } ).click( function () {
2931 mw.toolbar.insertTags( tagOpen, tagClose, sampleText, selectText );
3032 return false;
3133 } );
3234
33 - this.$toolbar.append( image );
 35+ toolbar.$toolbar.append( image );
3436 return true;
3537 },
3638
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 ) {
4145 currentFocused.textSelection(
42 - 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
 46+ 'encapsulateSelection', {
 47+ 'pre': tagOpen,
 48+ 'peri': sampleText,
 49+ 'post': tagClose
 50+ }
4351 );
4452 }
4553 },
4654
4755 // For backwards compatibility
48 - init : function() {},
 56+ init: function () {}
 57+ };
4958
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 );
6686 }
67 - return true;
6887 }
69 - };
7088
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;
7494
75 - $( document ).ready( function() {
76 - mw.toolbar.onReady();
77 -
7895 // Make sure edit summary does not exceed byte limit
7996 $( '#wpSummary' ).byteLimit( 250 );
8097
@@ -81,32 +98,37 @@
8299 * Restore the edit box scroll state following a preview operation,
83100 * and set up a form submission handler to remember this state
84101 */
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 ) {
91110 editBox.scrollTop = scrollTop.value;
92111 }
93 - $editForm.submit( function() {
 112+ $editForm.submit( function () {
94113 scrollTop.value = editBox.scrollTop;
95114 });
96115 }
97 - };
98 - scrollEditBox();
 116+ }() );
99117
100 - $( 'textarea, input:text' ).focus( function() {
 118+ $( 'textarea, input:text' ).focus( function () {
101119 currentFocused = $(this);
102120 });
103121
104122 // HACK: make currentFocused work with the usability iframe
105123 // 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' );
107125 if ( iframe.length > 0 ) {
108126 $( 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+ } );
111132 }
112133 });
113 -})(jQuery);
 134+
 135+}( jQuery, mediaWiki ) );
Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
114136 Merged /trunk/phase3:r111795,111881,111920,112573,112995,113169

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111795(bug 34373) - 'populateRevisionSha1.php misses archive rows, whose text is st...aaron21:48, 17 February 2012
r111881r111795: update line to remove bogus $db argumentaaron19:47, 19 February 2012
r111920r111795: Split out upgradeLegacyArchiveRow() function and added NS/title to c...aaron11:00, 20 February 2012
r112573[mediawiki.action.edit] Clean up and bug fixes...krinkle03:17, 28 February 2012
r112995(bug 34922) If rev_parent_id is null, then the character delta displayed on S...bawolff00:51, 5 March 2012
r113169Minor followup to r111795, make doSha1LegacyUpdates return it's count value s...reedy19:21, 6 March 2012

Status & tagging log