MediaWikiArticlePreview

Da PiemonteWireless.

MediaWiki Article Preview

This Mediawiki extension permits to include in an article a part of another, choosing how many initial and ending characters the included article must show. I made this to show in homepage last written articles in a blog form.

Usage example:

 <articlepreview fch="900" lch="300">ReversingWoW</articlepreview>

This code includes first 900 chars and last 300 chars of article titled ReversingWoW.


For novice in Mediawiki extension, save the PHP code you find in the bottom part of this page in a file named yourmediawiki/extensions/articlePreview.php and then add this line at the end of LocalSettings.php

include('extensions/articlePreview.php');


This is the PHP extension code (articlePreview.php file):

<?php
# Get Article preview
#
# Tag :
#   <articlepreview>article title</articlepreview>
#
# Enjoy !

$wgExtensionFunctions[] = 'wfPreviewArticle';
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'articlePreview',
        'description' => 'Get Article Preview',
        'author' => 'Simone Rotondo',
        'url' => 'http://www.piemontewireless.net'
);

function wfPreviewArticle() {
  global $wgParser;
  $wgParser->setHook('articlepreview', 'previewArticle');
}

# The callback function
function previewArticle($input, $argv, &$parser) {
  global $mediaWiki,$wgOut;

  $a = null;
  $t = Title::newFromText($input);
  $a = $mediaWiki->articleFromTitle($t);

  // take first and last 100 chars
  $acont = $a->getContent();
  $fch=800; $lch=400;
  if (array_key_exists('fch', $argvÿ { $fch=$argv['fch']; }
  if (array_key_exists('lch', $argvÿ { $lch=$argv['lch']; }
  $fchars = substr($acont, 0, $fch);
  $lchars = substr($acont, -$lch);
  $astripcont = $fchars . "<br>[.........]<br>" . $lchars;

  $poutput = $parser->parse( $astripcont, $parser->mTitle, $parser->mOptions, false, false );
  $output = $poutput->getText();

  return $output;
}
?>

57 Rating: 2.3/5 (3 votes cast)

Strumenti personali