From ad49482553546cacaf5762b3c56f7e29a9c7bf9d Mon Sep 17 00:00:00 2001 From: Raze Soldier Date: Sun, 5 Apr 2020 11:25:19 +0800 Subject: [PATCH] Further 1.34 compatibility fix (#38) * Change \ObjectCache::getMainWANInstance() to \MediaWiki\MediaWikiServices::getInstance()->getMainWANObjectCache() * Use ParserOutput::getText() options instead of ParserOptions::setEditSection() * Change ParserOptions::setEditSection() to options * Use AtEase instead of wfSuppressWarnings() and wfRestoreWarnings() --- includes/API.php | 6 ++---- includes/PopularPosts.php | 6 ++++-- includes/SpamFilter.php | 11 +++++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/API.php b/includes/API.php index a2bf555..78a7d1f 100644 --- a/includes/API.php +++ b/includes/API.php @@ -59,8 +59,6 @@ private function fetchPosts($pageid) { $comments = $this->convertPosts($page->posts); - // This is slow, use cache - $cache = \ObjectCache::getMainWANInstance(); $popular = PopularPosts::getFromPageId($pageid); $popularRet = $this->convertPosts($popular); @@ -151,6 +149,7 @@ private function executeListAll() { } $query->fetch(); + /** @var Post[] $posts */ $posts = $query->posts; // We fetched one extra row. If it exists in response, then we know we have more to fetch. @@ -354,10 +353,9 @@ public function execute() { // Set options for parsing $opt = new \ParserOptions($this->getUser()); - $opt->setEditSection(false); // Edit button will not work! $output = $parser->parse($text, \Title::newFromId($page), $opt); - $text = $output->getText(); + $text = $output->getText(['enableSectionEditLinks' => false]); // Edit button will not work! // Get all mentioned user $mentioned = Helper::generateMentionedList($output, $postObject); diff --git a/includes/PopularPosts.php b/includes/PopularPosts.php index 866ffa0..f246a6b 100644 --- a/includes/PopularPosts.php +++ b/includes/PopularPosts.php @@ -1,6 +1,8 @@ pageid; - $cache = \ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $key = wfMemcKey('flowthread', 'popular', $pageid); $cachedValue = $cache->get($key); if ($cachedValue === false) { @@ -23,7 +25,7 @@ public static function invalidateCache($post) { } private static function fetchFromCache($pageid) { - $cache = \ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $key = wfMemcKey('flowthread', 'popular', $pageid); $cachedValue = $cache->get($key); if ($cachedValue === false) { diff --git a/includes/SpamFilter.php b/includes/SpamFilter.php index 14da1c1..71ad8c7 100644 --- a/includes/SpamFilter.php +++ b/includes/SpamFilter.php @@ -1,15 +1,18 @@ getMainWANObjectCache(); return $cache->getWithSetCallback( wfMemcKey('flowthread', 'spamblacklist'), 60, @@ -184,4 +187,4 @@ public static function validate($text, $poster, $wikitext) { public static function sanitize($html) { return preg_replace('/position(?:\/\*[^*]*\*+([^\/*][^*]*\*+)*\/|\s)*:(?:\/\*[^*]*\*+([^\/*][^*]*\*+)*\/|\s)*fixed/i', '', $html); } -} \ No newline at end of file +}