Physikerwelt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189448
Change subject: Support regular action purge
......................................................................
Support regular action purge
Maybe the purge hook can be used
It needs to be proven that this method does not affect the purge speed
for pages without math (99%) seriously.
Bug: T74537
Change-Id: I105bcbb3c9177f23144fb196141feadbe3ebbd15
---
M Math.hooks.php
M Math.php
M MathRenderer.php
3 files changed, 57 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math
refs/changes/48/189448/1
diff --git a/Math.hooks.php b/Math.hooks.php
index c9e6482..b16e3cb 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -288,4 +288,35 @@
global $wgOut;
$wgOut->addModules( array( 'ext.math.editbutton.enabler' ) );
}
+
+
+ /**
+ * @param Article $article
+ */
+ public static function onArticlePurge( &$article ) {
+ $content = $article->getPage()->getContent()->getNativeData();
+ $mathTags = self::extractMathTagsFromWikiText( $content );
+ if ( sizeof( $mathTags ) > 0 ){
+ $ctx = $article->getContext();
+ $parser = ParserOptions::newFromContext( $ctx );
+ $mode = (int)$parser->getUser()->getOption( 'math' );
+ foreach( $mathTags as $tag ){
+ $renderer = MathRenderer::getRenderer( $tag[0],
$tag[1], $mode );
+ $renderer->deleteFromDatabase();
+ }
+ }
+ }
+
+ /**
+ * @param $content
+ *
+ * @return array
+ */
+ public static function extractMathTagsFromWikiText( $content ) {
+ $wikiText = Sanitizer::removeHTMLcomments( $content );
+ $wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', '',
$wikiText );
+ $math = array();
+ Parser::extractTagsAndParams( array( 'math' ), $wikiText, $math
);
+ return $math;
+ }
}
diff --git a/Math.php b/Math.php
index 4dca145..0a3bbb1 100644
--- a/Math.php
+++ b/Math.php
@@ -219,6 +219,7 @@
$wgHooks['UnitTestsList'][] = 'MathHooks::onRegisterUnitTests';
$wgHooks['PageRenderingHash'][] = 'MathHooks::onPageRenderingHash';
$wgHooks['EditPageBeforeEditToolbar'][] =
'MathHooks::onEditPageBeforeEditToolbar';
+$wgHooks['ArticlePurge'][] = 'MathHooks::onArticlePurge';
$dir = __DIR__ . '/';
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
diff --git a/MathRenderer.php b/MathRenderer.php
index 7e69eb1..7916c6c 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -371,6 +371,31 @@
}
/**
+ * @return bool
+ */
+ public function deleteFromDatabase() {
+ if ( $this->storedInDatabase === null ){
+ $this->readFromDatabase();
+ }
+ if ( $this->storedInDatabase === true ){
+ if ( wfReadOnly() ) {
+ return false;
+ }
+ $dbw = wfGetDB( DB_MASTER );
+ wfDebugLog( 'Math', 'delete entry for $' . $this->tex .
'$ from database (hash:' . $this->getMd5() . ")\n" );
+ try {
+ $res = $dbw->delete( $this->getMathTableName(),
+ array( 'math_inputhash' =>
$this->getInputHash() ), __METHOD__ );
+ return $res === true;
+ } catch (DBUnexpectedError $e) {
+ wfDebugLog( 'Math', 'Cannot delete cached
entry. The following DB exception occurred'. $e->getMessage() );
+ return false;
+ }
+ }
+
+ }
+
+ /**
* Returns sanitized attributes
*
* @param string $tag element name
@@ -515,15 +540,6 @@
*/
function isPurge( ) {
if ( $this->purge ) {
- return true;
- }
- $request = RequestContext::getMain()->getRequest();
- // TODO: Figure out if ?action=purge
- // $action = $request->getText('action'); //always returns ''
- // until this issue is resolved we use ?mathpurge=true instead
- $mathpurge = $request->getBool( 'mathpurge', false );
- if ( $mathpurge ) {
- wfDebugLog( 'Math', 'Re-Rendering on user request' );
return true;
} else {
return false;
--
To view, visit https://gerrit.wikimedia.org/r/189448
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I105bcbb3c9177f23144fb196141feadbe3ebbd15
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits