Difference between revisions of "User:Bumsakalaka"

Jump to navigation Jump to search
Line 718: Line 718:
** <p>Call public <code><nowiki>static function onArticlePurge( &$article ) { ... }</nowiki></code>
** <p>Call public <code><nowiki>static function onArticlePurge( &$article ) { ... }</nowiki></code>
<pre style="margin-left:5ex"><nowiki>
<pre style="margin-left:5ex"><nowiki>
To use the ArticlePurge hook with different caches for mobile and desktop versions of the same page in MediaWiki, you can follow these steps:


Register the Hook: First, you need to register the ArticlePurge hook in your extension. This can be done in your extension’s extension.json file1. Here is an example:
extension.json
JSON


{
{
Line 728: Line 726:
   }
   }
}
}
AI-generated code. Review and use carefully. More info on FAQ.
In this example, MediaWiki\\Extension\\MyExtension\\Hooks::onArticlePurge is the function that will be called when the ArticlePurge hook is triggered1.


Define the Hook Function: Next, you need to define the onArticlePurge function in your extension. This function will be called when an article is purged. Here is an example:
extenstion file
PHP


namespace MediaWiki\Extension\MyExtension;
namespace MediaWiki\Extension\MyExtension;
Line 751: Line 746:
         return true;
         return true;
     }
     }
}</nowiki</pre>
}</nowiki></pre>
</p>
</p>
** Another solution CustomCacheKey,but it looks like not used that $thatus->value['cacheKey'] value when reading the cache, need to be tests. If this is working, this will be best solution.
<pre><nowiki><?php
extensions/CustomCacheKey/CustomCacheKey.php
class CustomCacheKey {
    public static function onPageContentSaveComplete($wikiPage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status) {
        // Your custom logic here
        // Modify the cache key based on the page content, user, or other factors
        $cacheKey = $wikiPage->getTitle()->getPrefixedDBkey();
        if (wfMobileDetect()) {
            $cacheKey .= '_mobile'; // Add your custom suffix
        }
        // Set the modified cache key
        $status->value['cacheKey'] = $cacheKey;
    }
}
extension.json
{
    "Hooks": {
        "PageContentSaveComplete": "CustomCacheKey::onPageContentSaveComplete"
    }
}
</nowiki></pre>