Commit 4b06d0e3 authored by Troy Engel's avatar Troy Engel

adding 1.1.1

parent 50a14d62
PRELOADER EXTENSION
Version 1.1.1
© 2006 Rob Church
== Overview ==
1. Introduction
2. Requirements
3. Installation
4. Configuration
5. Feedback
6. Change Log
== 1. Introduction ==
The Preloader extension allows the creation of boilerplate text which will
be inserted into the edit form when creating new pages. Different boilerplate
text can be specified for different namespaces.
In addition, a new parser tag, <nopreload> is introduced, which is used to
denote sections which should not be preloaded, ever; useful for instructions
and advice on the boilerplate pages. This tag has no effect during a regular
parse operation.
== 2. Requirements ==
The Preloader extension requires MediaWiki 1.7.0 or later.
== 3. Installation ==
To install the Preloader extension, download all files from Subversion, and
place them into your extensions directory.
Then edit your LocalSettings.php file and add the following line:
require_once( 'extensions/Preloader.php' );
Installation can be verified through the Special:Version page on your wiki.
== 4. Configuration ==
Configuration of the boilerplate sources is done via the $wgPreloaderSource
configuration variable, which takes the following format:
$wgPreloaderSource[ <namespace index> ] = PAGE TITLE;
For instance
$wgPreloaderSource[ NS_MAIN ] = 'Template:Boilerplate';
$wgPreloaderSource[ NS_HELP ] = 'Template:Boilerplate help';
dictates that the boilerplate text for pages in the main namespace should be
loaded from Template:Boilerplate, while pages in the Help namespace will be
preloaded from Template:Boilerplate_help. Other namespaces have no boilerplate
configured.
== 5. Feedback ==
Please submit comments, suggestions and bug reports to <[email protected]>.
== 6. Change Log ==
17/12/2006
Version 1.0
* Initial release
31/12/2006
Version 1.1
* Trim preloaded text
* Fix newlines in <nopreload></nopreload> tags
13/03/2008
Version 1.1.1
* Add description message for [[Special:Version]]
\ No newline at end of file
This diff is collapsed.
<?php
/**
* Extension allows preloading of custom content into all edit forms
* when creating an article
*
* Also adds a new tag <nopreload> which is used to mark sections which
* shouldn't be preloaded, ever; has no effect on the rendering of pages
*
* @file
* @ingroup Extensions
* @author Rob Church <[email protected]>
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
exit( 1 );
}
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'Preloader',
'author' => 'Rob Church',
'version' => '1.1.1',
'url' => 'https://www.mediawiki.org/wiki/Extension:Preloader',
'descriptionmsg' => 'preloader-desc',
);
$wgExtensionMessagesFiles['Preloader'] = dirname(__FILE__) . '/Preloader.i18n.php';
/**
* Sources of preloaded content for each namespace
*/
$wgPreloaderSource[ NS_MAIN ] = 'Template:Preload';
$wgHooks['EditFormPreloadText'][] = 'Preloader::mainHook';
$wgHooks['ParserFirstCallInit'][] = 'Preloader::setParserHook';
class Preloader {
public static function setParserHook( $parser ) {
$parser->setHook( 'nopreload', array( __CLASS__, 'parserHook' ) );
return true;
}
/** Hook function for the preloading */
public static function mainHook( &$text, &$title ) {
$src = self::preloadSource( $title->getNamespace() );
if( $src ) {
$stx = self::sourceText( $src );
if( $stx )
$text = $stx;
}
return true;
}
/** Hook function for the parser */
public static function parserHook( $input, $args, &$parser ) {
$output = $parser->parse( $input, $parser->getTitle(), $parser->getOptions(), false, false );
return $output->getText();
}
/**
* Determine what page should be used as the source of preloaded text
* for a given namespace and return the title (in text form)
*
* @param $namespace Namespace to check for
* @return mixed
*/
static function preloadSource( $namespace ) {
global $wgPreloaderSource;
if( isset( $wgPreloaderSource[ $namespace ] ) ) {
return $wgPreloaderSource[ $namespace ];
} else {
return false;
}
}
/**
* Grab the current text of a given page if it exists
*
* @param $page Text form of the page title
* @return mixed
*/
static function sourceText( $page ) {
$title = Title::newFromText( $page );
if( $title && $title->exists() ) {
$revision = Revision::newFromTitle( $title );
return self::transform( $revision->getText() );
} else {
return false;
}
}
/**
* Remove <nopreload> sections from the text and trim whitespace
*
* @param $text
* @return string
*/
static function transform( $text ) {
return trim( preg_replace( '/<nopreload>.*<\/nopreload>/s', '', $text ) );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment