Topic on Extension talk:KeyCAPTCHA

KeyCaptcha is still calling functions which were deprecated in MW1.21

1
Carlb (talkcontribs)

The code for this extension was written for MW 1.16-1.18; because of the lack of a consistent interface between the various versions of core MW code and extensions, many of the functions it was calling no longer exist. In addition to the issues documented at Extension:KeyCAPTCHA#MediaWiki_1.27+ there are a few more functions which no longer exist in MW 1.31: wfMsgForContent() has joined wfEmptyMsg() on the scrap heap and Revision::getText() is also gone as of Jan 2017.

In an attempt to keep this extension running on existing sites, I've had to make these changes to extensions/keyCaptcha/keyCaptcha.php (around lines 81-100) to disable the captcha-addurl-whitelist setting and replace $rev->getText() with functions that are available in the current MW releases:

                function filterLink( $url ) {
                        global $wgCaptchaWhitelist;
#                       $source = wfMsgForContent( 'captcha-addurl-whitelist' );

#                       $whitelist = wfEmptyMsg( 'captcha-addurl-whitelist', $source )
#                               ? false
#                               : $this->buildRegexes( explode( "\n", $source ) );
                        $whitelist = false;

                        $cwl = $wgCaptchaWhitelist !== false ? preg_match( $wgCaptchaWhitelist, $url ) : false;
                        $wl  = $whitelist          !== false ? preg_match( $whitelist, $url )          : false;
                        return !( $cwl || $wl );
                }

                function loadText( $editPage, $section ) {
                        $rev = Revision::newFromTitle( $editPage->mTitle );
                        if ( is_null( $rev ) ) {
                                return "";
                        } else {
#                               replace "$text = $rev->getText();" with these two due to deprecation:
                                $content = $rev->getContent(Revision::FOR_PUBLIC, null );
                                $text =  ContentHandler::getContentText( $content );    

                                if ( $section != '' ) {
                                        global $wgParser;
                                        return $wgParser->getSection( $text, $section );
                                } else {
                                        return $text;
                                }
                        }
                }

where the comment # marker indicates code I've had to disable, with the replacement "kludged" in directly below.

Of course, this is no insurance against other pieces of this extension breaking or against keycaptcha.com going away someday (and, without the proprietary external server, the extension will presumably be completely useless some day). The original creator of this extension has been silent for years, which is unfortunate as this looks to be a strong CAPTCHA which has kept a lot of spam off my sites. ~~~~

Reply to "KeyCaptcha is still calling functions which were deprecated in MW1.21"