Open main menu

Extension:MisesQuote

MediaWiki extensions manual
OOjs UI icon alert-invert.svg
MisesQuote
Release status: unstable
LvMQuote.png
Implementation Tag
Description Makes it easy to generate random Ludwig von Mises quotations
Author(s) (Leucostictetalk)
Latest version 1.0.0
MediaWiki 1.19
License GPL
Download No link
Example http://wiki.mises.org
misesquote
Translate the MisesQuote extension if it is available at translatewiki.net
Check usage and version matrix.

This extension makes it easy to generate random Ludwig von Mises quotations.

Contents

InstallationEdit

  • Create a folder in the extensions folder named MisesQuote
  • Move the files to the extensions/MisesQuote/ folder
  • Edit LocalSettings.php in the root of your MediaWiki installation, and add the following line near the bottom:
require_once("$IP/extensions/MisesQuote/MisesQuote.php");

UsageEdit

Simply add a <misesquote/> tag wherever you want a randomly-generated Ludwig von Mises quote to appear. It is recommended that you add the misesquote: prefix to your interwiki table (url: http://wiki.mises.org/$1) and copy and paste this text into Template:Misesquote on your wiki.

FilesEdit

MisesQuote.phpEdit

<?php
/**
 * MisesQuote MediaWiki extension.
 *
 * This extension makes it easy to generate random Ludwig von Mises
 * quotations.
 *
 * Written by Leucosticte
 * https://www.mediawiki.org/wiki/User:Leucosticte
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @ingroup Extensions
 */

if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
        die( 1 );
}

$wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'MisesQuote',
        'author' => 'Nathan Larson',
        'url' => 'https://mediawiki.org/wiki/Extension:MisesQuote',
        'description' => 'Adds <nowiki><misesquote/></nowiki> tag, for Ludwig von Mises quotations',
        'version' => '1.0.1'
);

$wgExtensionFunctions[] = "MisesQuote::misesQuotation";

class MisesQuote {
        public static function misesQuotation() {
                global $wgParser;
                $wgParser->setHook( "misesquote", "MisesQuote::renderMisesQuote" );
        }

        public static function renderMisesQuote( $input, $params, $parser ) {
                $parser->disableCache();
                $output = '<script language="Javascript">';
                $contents = file_get_contents ('http://mises.org/quote.aspx?format=js');
                $quoteBegin = strpos( $contents, '\"' );
                $quoteEnd = strpos( $contents, '\"' , $quoteBegin + 1 );
                $quote = substr ( $contents, $quoteBegin + 2, $quoteEnd - $quoteBegin - 2 );
                $sourceBegin = strpos ( $contents, 'Source=' );
                $sourceEnd = strpos ( $contents, "'", $sourceBegin );
                $source = substr ( $contents, $sourceBegin + 7, $sourceEnd - $sourceBegin - 7 );
                $output = '{{misesquote|quote=' . $quote . '|source=' . $source . '}}';
                $output = $parser->internalParse( $output );
                return $output;
        }
}