r111054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111053‎ | r111054 | r111055 >
Date:18:10, 9 February 2012
Author:awjrichards
Status:deferred (Comments)
Tags:nodeploy 
Comment:
Import of 'Example' extension that can be used to serve as a base from which to build extensions and/or be used to help teach newbies about Mediawiki extension development.
Modified paths:
  • /trunk/extensions/Example (added) (history)
  • /trunk/extensions/Example/Example.body.php (added) (history)
  • /trunk/extensions/Example/Example.i18n.php (added) (history)
  • /trunk/extensions/Example/Example.php (added) (history)
  • /trunk/extensions/Example/README (added) (history)

Diff [purge]

Index: trunk/extensions/Example/Example.i18n.php
@@ -0,0 +1,14 @@
 2+<?php
 3+
 4+// initialize the messages variable
 5+$messages = array();
 6+
 7+// English
 8+$messages[ 'en' ] = array(
 9+ 'example-example' => 'This is an example!',
 10+);
 11+
 12+// Message documentation for translators
 13+$messages[ 'qqq' ] = array(
 14+ 'example-example' => 'This is just an example message. Nothing special.',
 15+);
Index: trunk/extensions/Example/Example.php
@@ -0,0 +1,42 @@
 2+<?php
 3+/**
 4+ * This is an example extension. It doesn't actually do anything useful, but
 5+ * can be copied to provide the basis for your own extension.
 6+ */
 7+
 8+/**
 9+ * Prevent a user from accessing this file directly and provide a helpful
 10+ * message explaining how to install this extension.
 11+ */
 12+if ( !defined( 'MEDIAWIKI' ) ) {
 13+ if ( !defined( 'MEDIAWIKI' ) ) {
 14+ echo <<<EOT
 15+To install the Example extension, put the following line in your
 16+LocalSettings.php file:
 17+require_once( "\$IP/extensions/Example/Example.php" );
 18+EOT;
 19+ exit( 1 );
 20+ }
 21+}
 22+
 23+// Extension credits that will show up on Special:Version
 24+$wgExtensionCredits[ 'other' ][] = array(
 25+ 'path' => __FILE__,
 26+ 'name' => 'Example',
 27+ 'author' =>'Your Name Here',
 28+ 'url' => 'https://www.mediawiki.org/wiki/Extension:Example',
 29+ 'description' => 'This extension is an example extension',
 30+ 'version' => 1.0,
 31+);
 32+
 33+// Find the full directory path of this extension
 34+$current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
 35+
 36+// Autoload this extension's classes
 37+$wgAutoloadClasses[ 'Example' ] = $current_dir . 'Example.body.php';
 38+
 39+// Add the i18n message file
 40+$wgExtensionMessagesFiles[ 'Example' ] = $current_dir . 'Example.i18n.php';
 41+
 42+// Tell MediaWiki about the special page
 43+$wgSpecialPages[ 'Example' ] = 'SpecialExample';
\ No newline at end of file
Index: trunk/extensions/Example/Example.body.php
@@ -0,0 +1,17 @@
 2+<?php
 3+
 4+class SpecialExample extends SpecialPage {
 5+
 6+ function __construct() {
 7+ parent::__construct( 'Example' );
 8+ }
 9+
 10+ /**
 11+ * Make your magic happen!
 12+ */
 13+ function execute( $par ) {
 14+ global $wgOut;
 15+
 16+ $wgOut->addWikimsg( 'example-example' );
 17+ }
 18+}
Index: trunk/extensions/Example/README
@@ -0,0 +1,7 @@
 2+This is an example extension. It doesn't really do anything on its own. It is
 3+intended to provide a sample layout of a MediaWiki extension which a developer
 4+can copy and use as a base for their own extension.
 5+
 6+If you are checking this our from SVN and intend to copy it, please use:
 7+ svn export /path/to/this/extension /path/to/new/extension
 8+to create a clean copy without any extra SVN cruft.

Comments

#Comment by Nikerabbit (talk | contribs)   07:59, 10 February 2012

Should use descriptionmsg instead. Don't we have example extensions somewhere already?

Oh and global $wgOut is bad nowdays :)

+require_once( "\$IP/extensions/Example/Example.php" );

Just use single quotes here? Do we really need to print installation instructions like that?

#Comment by Awjrichards (talk | contribs)   10:49, 10 February 2012

Heh, all of this is news to me. Perhaps the documentation on mediawiki.org should be updated to reflect this? What's used instead of global $wgOut these days? I guess my life in fundraising has kept me in the dark ages about MW development :p

#Comment by Johnduhart (talk | contribs)   11:10, 10 February 2012

$this->getOutput() gets an OutputPage instance.

Take a look at ContextSource for more functions like this.

Status & tagging log