Skip to content

Commit

Permalink
Further 1.34 compatibility fix (#38)
Browse files Browse the repository at this point in the history
* 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()
  • Loading branch information
RazeSoldier authored Apr 5, 2020
1 parent 6adb773 commit ad49482
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 2 additions & 4 deletions includes/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions includes/PopularPosts.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace FlowThread;

use MediaWiki\MediaWikiServices;

class PopularPosts {

const CACHE_TTL = 3600;
Expand All @@ -11,7 +13,7 @@ public static function getFromPageId($pageid) {

public static function invalidateCache($post) {
$pageid = $post->pageid;
$cache = \ObjectCache::getMainWANInstance();
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$key = wfMemcKey('flowthread', 'popular', $pageid);
$cachedValue = $cache->get($key);
if ($cachedValue === false) {
Expand All @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions includes/SpamFilter.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
namespace FlowThread;

use MediaWiki\MediaWikiServices;
use Wikimedia\AtEase\AtEase;

class SpamFilter {

/**
* Validate if a regular expression is valid
*/
private static function validateRegex($regex) {
wfSuppressWarnings();
AtEase::suppressWarnings();
$ok = preg_match($regex, '');
wfRestoreWarnings();
AtEase::restoreWarnings();

if ($ok === false) {
return false;
Expand Down Expand Up @@ -121,7 +124,7 @@ private static function parseLines($lines) {
}

private static function getBlackList() {
$cache = \ObjectCache::getMainWANInstance();
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback(
wfMemcKey('flowthread', 'spamblacklist'),
60,
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit ad49482

Please sign in to comment.