r47890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47889‎ | r47890 | r47891 >
Date:13:25, 28 February 2009
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
* API: (bug 13209) Add rvdiffto parameter to prop=revisions
* Add $wgAPIMaxUncachedDiffs (default 1) which controls how many non-cached diffs will be served per request
* Tweak DifferenceEngine.php a bit to make cache status accessible, and remove a useless 'parseinline' which broke diff generation in the API
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -27,6 +27,7 @@
2828 var $mOldRev, $mNewRev;
2929 var $mRevisionsLoaded = false; // Have the revisions been loaded
3030 var $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
 31+ var $mCacheHit = false; // Was the diff fetched from cache?
3132 var $htmldiff;
3233
3334 protected $unhide = false;
@@ -52,9 +53,8 @@
5354 $this->mNewid = intval($old);
5455 $this->mOldid = $this->mTitle->getPreviousRevisionID( $this->mNewid );
5556 } elseif ( 'next' === $new ) {
56 - # Show diff between revision $old and the previous one.
57 - # Get previous one from DB.
58 - #
 57+ # Show diff between revision $old and the next one.
 58+ # Get next one from DB.
5959 $this->mOldid = intval($old);
6060 $this->mNewid = $this->mTitle->getNextRevisionID( $this->mOldid );
6161 if ( false === $this->mNewid ) {
@@ -76,6 +76,18 @@
7777 function getTitle() {
7878 return $this->mTitle;
7979 }
 80+
 81+ function wasCacheHit() {
 82+ return $this->mCacheHit;
 83+ }
 84+
 85+ function getOldid() {
 86+ return $this->mOldid;
 87+ }
 88+
 89+ function getNewid() {
 90+ return $this->mNewid;
 91+ }
8092
8193 function showDiffPage( $diffOnly = false ) {
8294 global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol, $wgEnableHtmlDiff;
@@ -537,11 +549,16 @@
538550 function getDiffBody() {
539551 global $wgMemc;
540552 wfProfileIn( __METHOD__ );
 553+ $this->mCacheHit = true;
541554 // Check if the diff should be hidden from this user
 555+ if ( !$this->loadRevisionData() )
 556+ return '';
542557 if ( $this->mOldRev && !$this->mOldRev->userCan(Revision::DELETED_TEXT) ) {
543558 return '';
544559 } else if ( $this->mNewRev && !$this->mNewRev->userCan(Revision::DELETED_TEXT) ) {
545560 return '';
 561+ } else if ( $this->mOldRev && $this->mNewRev && $this->mOldRev->getID() == $this->mNewRev->getID() ) {
 562+ return '';
546563 }
547564 // Cacheable?
548565 $key = false;
@@ -559,6 +576,7 @@
560577 }
561578 } // don't try to load but save the result
562579 }
 580+ $this->mCacheHit = false;
563581
564582 // Loadtext is permission safe, this just clears out the diff
565583 if ( !$this->loadText() ) {
@@ -691,7 +709,7 @@
692710
693711 function localiseLineNumbersCb( $matches ) {
694712 global $wgLang;
695 - return wfMsgExt( 'lineno', array( 'parseinline' ), $wgLang->formatNum( $matches[1] ) );
 713+ return wfMsgExt( 'lineno', array (), $wgLang->formatNum( $matches[1] ) );
696714 }
697715
698716
@@ -773,10 +791,10 @@
774792
775793 // Load the new revision object
776794 $this->mNewRev = $this->mNewid
777 - ? Revision::newFromId( $this->mNewid )
778 - : Revision::newFromTitle( $this->mTitle );
 795+ ? Revision::newFromId( $this->mNewid )
 796+ : Revision::newFromTitle( $this->mTitle );
779797 if( !$this->mNewRev instanceof Revision )
780 - return false;
 798+ return false;
781799
782800 // Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
783801 $this->mNewid = $this->mNewRev->getId();
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -100,6 +100,26 @@
101101 if ($pageCount > 1 && $enumRevMode)
102102 $this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages');
103103
 104+ if (!is_null($params['diffto'])) {
 105+ if ($params['diffto'] == 'cur')
 106+ $params['diffto'] = 0;
 107+ if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0)
 108+ && $params['diffto'] != 'prev' && $params['diffto'] != 'next')
 109+ $this->dieUsage('rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto');
 110+ // Check whether the revision exists and is readable,
 111+ // DifferenceEngine returns a rather ambiguous empty
 112+ // string if that's not the case
 113+ if ($params['diffto'] != 0) {
 114+ $difftoRev = Revision::newFromID($params['diffto']);
 115+ if (!$difftoRev)
 116+ $this->dieUsageMsg(array('nosuchrevid', $params['diffto']));
 117+ if (!$difftoRev->userCan(Revision::DELETED_TEXT)) {
 118+ $this->setWarning("Couldn't diff to r{$difftoRev->getID()}: content is hidden");
 119+ $params['diffto'] = null;
 120+ }
 121+ }
 122+ }
 123+
104124 $this->addTables('revision');
105125 $this->addFields(Revision::selectFields());
106126 $this->addTables('page');
@@ -116,6 +136,7 @@
117137 $this->fld_size = isset ($prop['size']);
118138 $this->fld_user = isset ($prop['user']);
119139 $this->token = $params['token'];
 140+ $this->diffto = $params['diffto'];
120141
121142 if ( !is_null($this->token) || $pageCount > 0) {
122143 $this->addFields( Revision::selectPageFields() );
@@ -288,7 +309,7 @@
289310 }
290311
291312 private function extractRowInfo( $revision ) {
292 -
 313+ $title = $revision->getTitle();
293314 $vals = array ();
294315
295316 if ($this->fld_ids) {
@@ -325,11 +346,8 @@
326347 if (strval($comment) !== '')
327348 $vals['comment'] = $comment;
328349 }
329 - }
 350+ }
330351
331 - if(!is_null($this->token) || ($this->fld_content && $this->expandTemplates))
332 - $title = $revision->getTitle();
333 -
334352 if(!is_null($this->token))
335353 {
336354 $tokenFunctions = $this->getTokenFunctions();
@@ -372,6 +390,22 @@
373391 } else if ($this->fld_content) {
374392 $vals['texthidden'] = '';
375393 }
 394+
 395+ if (!is_null($this->diffto)) {
 396+ global $wgAPIMaxUncachedDiffs;
 397+ static $n = 0; // Numer of uncached diffs we've had
 398+ if($n< $wgAPIMaxUncachedDiffs) {
 399+ $engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
 400+ $difftext = $engine->getDiffBody();
 401+ $vals['diff']['from'] = $engine->getOldid();
 402+ $vals['diff']['to'] = $engine->getNewid();
 403+ ApiResult::setContent($vals['diff'], $difftext);
 404+ if(!$engine->wasCacheHit())
 405+ $n++;
 406+ } else {
 407+ $vals['diff']['notcached'] = '';
 408+ }
 409+ }
376410 return $vals;
377411 }
378412
@@ -429,6 +463,7 @@
430464 ApiBase :: PARAM_ISMULTI => true
431465 ),
432466 'continue' => null,
 467+ 'diffto' => null,
433468 );
434469 }
435470
@@ -448,6 +483,8 @@
449484 'section' => 'only retrieve the content of this section',
450485 'token' => 'Which tokens to obtain for each revision',
451486 'continue' => 'When more results are available, use this to continue',
 487+ 'diffto' => array('Revision ID to diff each revision to.',
 488+ 'Use "prev", "next" and "cur" for the previous, next and current revision respectively.'),
452489 );
453490 }
454491
Index: trunk/phase3/includes/api/ApiBase.php
@@ -988,4 +988,4 @@
989989 public static function getBaseVersion() {
990990 return __CLASS__ . ': $Id$';
991991 }
992 -}
\ No newline at end of file
 992+}
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3562,6 +3562,12 @@
35633563 $wgAPIMaxResultSize = 8388608;
35643564
35653565 /**
 3566+ * The maximum number of uncached diffs that can be retrieved in one API
 3567+ * request. Set this to 0 to disable API diffs altogether
 3568+ */
 3569+$wgAPIMaxUncachedDiffs = 1;
 3570+
 3571+/**
35663572 * Parser test suite files to be run by parserTests.php when no specific
35673573 * filename is passed to it.
35683574 *
Index: trunk/phase3/RELEASE-NOTES
@@ -265,6 +265,7 @@
266266 aliases already listed in siprop=namespaces
267267 * (bug 17529) rvend ignored when rvstartid is specified
268268 * (bug 17626) Added uiprop=email to list=userinfo
 269+* (bug 13209) Added rvdiffto parameter to prop=revisions
269270
270271 === Languages updated in 1.15 ===
271272

Follow-up revisions

RevisionCommit summaryAuthorDate
r48216(bug 17863) Fix regression from r47890 that broke Show changes on the edit fo...catrope11:00, 9 March 2009

Comments

#Comment by Siebrand (talk | contribs)   18:42, 8 March 2009

FIXME: In UI page edit, "Show changes" now gives a diff between the 2 previous versions, instead of between the latest version and the editor version.

Status & tagging log