GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main page
  • Get MediaWiki
  • Get extensions
  • Tech blog
  • Contribute
  • User help
  • FAQ
  • Technical manual
  • Support desk
  • Communication
  • Developer portal
  • Code statistics
  • Community portal
  • Recent changes

This view

  • Original page
  • New address

GeezerVison is showing www.mediawiki.org — Extension:BacktickCode - MediaWiki

This extension stores its source code on a editable wiki page rather than in a code repository. As a result, this code may be maliciously altered.
It may contain security vulnerabilities, and will not receive localisation updates from translatewiki.net . Developers are strongly encouraged to host their code in a code repository rather than a wiki page so that the extension can be properly maintained, reviewed, and kept secure.

This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored.

MediaWiki extensions manual
BacktickCode
Release status: unmaintained
Implementation Tag
Description Wrap `text between backticks` in <code> tags.
Author(s) Joel Thornton (joelpttalk)
Latest version 1.1 (2020-02-16)
MediaWiki 1.5+
PHP 5.3+
Database changes No
Hooks used
  • InternalParseBeforeLinks
Licence GNU General Public License 2.0 or later
Download See the code section

The BacktickCode extension wraps ‎<code> tags around wikitext which is placed `between backtick characters`.

This provides a handy wiki-editing shortcut for wikis that expect a lot of inlined ‎<code> snippets in its pages, and functions similarly to the standard MediaWiki ''' -> ‎<b> bold formatting shortcut.

Backtick characters within ‎<pre> blocks will not be altered by this extension. Backticks outside of ‎<pre> blocks can also be output to the page by escaping them as \`.

Installing

  • Copy the code into a file and place the file(s) in a directory called BacktickCode in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    require_once "$IP/extensions/BacktickCode/BacktickCode.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code

BacktickCode.php
<?php
/**
 * @author Joel Thornton <[email protected]>
 * @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 */

if(!defined('MEDIAWIKI')) {
    die("This is an extension to the MediaWiki package and cannot be run standalone.");
}

// Register as an extention
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'BacktickCode',
        'version' => '1.1',
        'url' => 'https://www.mediawiki.org/wiki/Extension:BacktickCode',
        'author' => array('Joel Thornton', 'Sk4p'),
        'description' => 'Allows to show text as <code> between backticks (`)',
);

// Register hooks
$wgHooks['InternalParseBeforeLinks'][] = function( &$parser, &$text, &$stripState ) {
        // We replace '`...`' by '<code>...</code>' and '\`' by '`'.

        // This is hard, because MediaWiki itself uses backticks in
        // the `UNIQ and QINU` blocks.  We find that when we just
        // change pairs of ` `, we break the stripstate badly.  So
        // first we're going to "hide" those by turning the backticks
        // into tildes.
        //
        $fixprefix = preg_replace('/`/', '~', Parser::MARKER_PREFIX);
        $fixsuffix = preg_replace('/`/', '~', Parser::MARKER_SUFFIX);

        $text = str_replace(Parser::MARKER_PREFIX, $fixprefix, $text);
        $text = str_replace(Parser::MARKER_SUFFIX, $fixsuffix, $text);

        // Now that those are tildes, we can do the replace.  We check
        // for \x7f to ensure our pair of backticks isn't spanning a
        // UNIQ/QINU set.
        $text = preg_replace('/([^\\\\]|^)`([^`\x7f]*)`/', '$1<code>$2</code>', $text);
        $text = preg_replace('/\\\\\`/', '`', $text);

        // Now put the prefix/suffixes back to normal.
        $text = str_replace($fixprefix, Parser::MARKER_PREFIX, $text);
        $text = str_replace($fixsuffix, Parser::MARKER_SUFFIX, $text);

        return true;
};
Retrieved from "https://www.mediawiki.org/w/index.php?title=Extension:BacktickCode&oldid=6563800"
Categories:
  • Extensions which host their code in-wiki
  • Unmaintained extensions
  • Tag extensions
  • InternalParseBeforeLinks extensions
  • GPL licensed extensions
  • All extensions
  • Extensions not using extension registration
Hidden categories:
  • Extensions without an image
  • Extensions without a compatibility policy
  • Extensions with manual MediaWiki version
  • Extensions not in ExtensionJson
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.