Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/203074

Change subject: Update revision id for termbox placeholder during doEditUpdates
......................................................................

Update revision id for termbox placeholder during doEditUpdates

This requires a core change to add a hook in the right place,
during doEditUpdates (when we then know the revision id), but
before anything is saved in ParserCache.

Furthermore, the stuff involved here is super nasty but don't
see a way to avoid this. Added @fixme in the code and we
should address it best we can.

If this approach is sane, I would like to then factor out some
of the wikibase-view-chunks hooks code into another class and
add test coverage for it.

Change-Id: Id082e563ef8591fcbe7318d9926d725047b93185
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
2 files changed, 34 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/74/203074/1

diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index d64b774..772250a 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -1178,4 +1178,37 @@
                return true;
        }
 
+       /**
+        * Called during WikiPage::doEditUpdates, when revision id is known and 
before the
+        * edit is cached in ParserCache.
+        *
+        * @param WikiPage $page
+        * @param Revision $revision
+        * @param &$editInfo data structure that contains ParserOutput and 
other info about an edit.
+        *
+        * @return bool
+        */
+       public static function onWikiPageDoEditUpdatesBeforeCache( WikiPage 
$page, Revision $revision, &$editInfo ) {
+               $wikibaseViewChunks = $editInfo->output->getExtensionData( 
'wikibase-view-chunks' );
+
+               foreach( $wikibaseViewChunks as $key => $data ) {
+                       // @fixme super nasty that wikibase-view-chunks is 
based on an array,
+                       // with numerical, positional indices, and having to 
deal with $editInfo
+                       // also doesn't make this the least bit nice.  but this 
works and is
+                       // right place and time to update the termbox 
placeholder.
+                       //
+                       // We check if the revision id is 0, which means 
unknown, and may have
+                       // been set via EntityContent::getParserOutput before 
the revision id
+                       // got set.
+                       if ( isset( $data[0] ) && $data[0] === 'termbox' && 
isset( $data[2] ) && $data[2] === 0 ) {
+                               $wikibaseViewChunks[$key][2] = 
$revision->getId();
+                               $editInfo->output->setExtensionData( 
'wikibase-view-chunks', $wikibaseViewChunks );
+                       }
+
+                       break;
+               }
+
+               return true;
+       }
+
 }
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 5a73d8e..1d1774f 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -226,6 +226,7 @@
        $wgHooks['ImportHandleRevisionXMLTag'][]            = 
'Wikibase\RepoHooks::onImportHandleRevisionXMLTag';
        $wgHooks['BaseTemplateToolbox'][]               = 
'Wikibase\RepoHooks::onBaseTemplateToolbox';
        $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 
'Wikibase\RepoHooks::onSkinTemplateBuildNavUrlsNav_urlsAfterPermalink';
+       $wgHooks['WikiPageDoEditUpdatesBeforeCache'][] = 
'Wikibase\RepoHooks::onWikiPageDoEditUpdatesBeforeCache';
 
        // update hooks
        $wgHooks['LoadExtensionSchemaUpdates'][] = 
'\Wikibase\Repo\Store\Sql\ChangesSubscriptionSchemaUpdater::onSchemaUpdate';

-- 
To view, visit https://gerrit.wikimedia.org/r/203074
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id082e563ef8591fcbe7318d9926d725047b93185
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to