r11107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11106‎ | r11107 | r11108 >
Date:23:18, 23 September 2005
Author:avar
Status:old
Tags:
Comment:
* An example parser hook and includable special page
Modified paths:
  • /trunk/extensions/examples (added) (history)
  • /trunk/extensions/examples/Parser_hook.php (added) (history)
  • /trunk/extensions/examples/SpecialIncludable.php (added) (history)

Diff [purge]

Index: trunk/extensions/examples/Parser_hook.php
@@ -0,0 +1,37 @@
 2+<?php
 3+if (!defined('MEDIAWIKI')) die();
 4+/**
 5+ * A parser hook example, use it on a page like
 6+ * <hook arg1="foo" arg2="bar" ...>input</hook>
 7+ *
 8+ * @package MediaWiki
 9+ * @subpackage Extensions
 10+ *
 11+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 12+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+ */
 14+
 15+$wgExtensionFunctions[] = 'wfParserHook';
 16+$wgExtensionCredits['parserhook'][] = array(
 17+ 'name' => 'Parser hook',
 18+ 'description' => 'a sample parser hook',
 19+ 'author' => 'Ævar Arnfjörð Bjarmason'
 20+);
 21+
 22+function wfParserHook() {
 23+ global $wgParser;
 24+
 25+ $wgParser->setHook( 'hook' , 'wfParserHookParse' );
 26+}
 27+
 28+/**
 29+ * @param string $in The input passed to <hook>
 30+ * @param array $argv The attributes of the <hook> element in array form
 31+ */
 32+function wfParserHookParse( $in, $argv ) {
 33+ if ( ! count( $argv ) )
 34+ return $in;
 35+ else
 36+ return '<pre>' . $in . "\n" . print_r( $argv, true ) . '</pre>';
 37+}
 38+
Property changes on: trunk/extensions/examples/Parser_hook.php
___________________________________________________________________
Added: svn:keywords
139 + Author Date Id Revision
Added: svn:eol-style
240 + native
Index: trunk/extensions/examples/SpecialIncludable.php
@@ -0,0 +1,55 @@
 2+<?php
 3+if (!defined('MEDIAWIKI')) die();
 4+/**
 5+ * A Special Page sample that can be included on a wikipage like
 6+ * {{Special:Inc}} as well as being accessed on [[Special:Inc]]
 7+ *
 8+ * @package MediaWiki
 9+ * @subpackage Extensions
 10+ *
 11+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 12+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+ */
 14+
 15+$wgExtensionFunctions[] = 'wfIncludable';
 16+$wgExtensionCredits['specialpage'][] = array(
 17+ 'name' => 'Includable',
 18+ 'description' => 'a sample includable Special Page',
 19+ 'author' => 'Ævar Arnfjörð Bjarmason'
 20+);
 21+
 22+
 23+function wfIncludable() {
 24+ global $IP, $wgMessageCache;
 25+
 26+ $wgMessageCache->addMessage( 'includable', 'Includable' );
 27+
 28+ require_once "$IP/includes/SpecialPage.php";
 29+ class SpecialIncludable extends SpecialPage {
 30+ /**
 31+ * Constructor
 32+ */
 33+ function SpecialIncludable() {
 34+ SpecialPage::SpecialPage( 'Includable' );
 35+ $this->includable( true );
 36+ }
 37+
 38+ /**
 39+ * main()
 40+ */
 41+ function execute( $par = null ) {
 42+ global $wgOut;
 43+
 44+ if ( $this->including() )
 45+ $out = "I'm being included";
 46+ else {
 47+ $out = "I'm being viewed as a Special Page";
 48+ $this->setHeaders();
 49+ }
 50+
 51+ $wgOut->addHtml( $out );
 52+ }
 53+ }
 54+
 55+ SpecialPage::addPage( new SpecialIncludable );
 56+}
Property changes on: trunk/extensions/examples/SpecialIncludable.php
___________________________________________________________________
Added: svn:keywords
157 + Author Date Id Revision
Added: svn:eol-style
258 + native

Status & tagging log