http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68821

Revision: 68821
Author:   nikerabbit
Date:     2010-07-01 08:25:04 +0000 (Thu, 01 Jul 2010)

Log Message:
-----------
Update examples from stone age

Modified Paths:
--------------
    trunk/extensions/examples/Content_action.php
    trunk/extensions/examples/FourFileTemplate/MyExtension.php
    trunk/extensions/examples/FourFileTemplate/MyExtension_body.php
    trunk/extensions/examples/Parser_function.php
    trunk/extensions/examples/Parser_hook.php
    trunk/extensions/examples/SpecialIncludable.php
    trunk/extensions/examples/Variable_hook.php

Modified: trunk/extensions/examples/Content_action.php
===================================================================
--- trunk/extensions/examples/Content_action.php        2010-07-01 08:05:49 UTC 
(rev 68820)
+++ trunk/extensions/examples/Content_action.php        2010-07-01 08:25:04 UTC 
(rev 68821)
@@ -19,6 +19,8 @@
 
 function wfAddaction() {
        global $wgHooks, $wgMessageCache;
+       // This is not the proper way to do i18n
+       // See FourFileTemplate how to do i18n
        $wgMessageCache->addMessage( 'myact', 'My action' );
        $wgHooks['SkinTemplateContentActions'][] = 'wfAddactionContentHook';
        $wgHooks['UnknownAction'][] = 'wfAddactActionHook';
@@ -31,7 +33,7 @@
 
        if ( $wgTitle->getNamespace() != NS_SPECIAL ) {
                $content_actions['myact'] = array(
-                       'class' => $action == 'myact' ? 'selected' : false,
+                       'class' => $action === 'myact' ? 'selected' : false,
                        'text' => wfMsg( 'myact' ),
                        'href' => $wgTitle->getLocalUrl( 'action=myact' )
                );
@@ -45,8 +47,9 @@
        
        $title = $wgArticle->getTitle();
        
-       if ( $action == 'myact' )
-               $wgOut->addHTML( 'The page name is ' . $title->getText() . ' 
and you are ' . $wgArticle->getUserText() );
+       if ( $action === 'myact' ) {
+               $wgOut->addWikiText( 'The page name is ' . $title->getText() . 
' and you are ' . $wgArticle->getUserText() );
+       }
 
        return false;
 }

Modified: trunk/extensions/examples/FourFileTemplate/MyExtension.php
===================================================================
--- trunk/extensions/examples/FourFileTemplate/MyExtension.php  2010-07-01 
08:05:49 UTC (rev 68820)
+++ trunk/extensions/examples/FourFileTemplate/MyExtension.php  2010-07-01 
08:25:04 UTC (rev 68821)
@@ -12,6 +12,7 @@
        'path' => __FILE__,
        'name' => 'MyExtensionName',
        'version' => '0.1',
+       // You can use array for multiple authors
        'author' => 'MyExtensionAuthor',
        'url' => 'http://www.mediawiki.org/wiki/Extension:MyExtension',
        'descriptionmsg' => 'myextension-desc',

Modified: trunk/extensions/examples/FourFileTemplate/MyExtension_body.php
===================================================================
--- trunk/extensions/examples/FourFileTemplate/MyExtension_body.php     
2010-07-01 08:05:49 UTC (rev 68820)
+++ trunk/extensions/examples/FourFileTemplate/MyExtension_body.php     
2010-07-01 08:25:04 UTC (rev 68821)
@@ -1,6 +1,5 @@
 <?php
-class MyExtension extends SpecialPage
-{
+class MyExtension extends SpecialPage {
        function MyExtension() {
                parent::__construct( "MyExtension" );
        }
@@ -10,8 +9,6 @@
 
                $this->setHeaders();
 
-               wfLoadExtensionMessages( 'MyExtension' );
-
                # Get request data from, e.g.
                $param = $wgRequest->getText( 'param' );
 

Modified: trunk/extensions/examples/Parser_function.php
===================================================================
--- trunk/extensions/examples/Parser_function.php       2010-07-01 08:05:49 UTC 
(rev 68820)
+++ trunk/extensions/examples/Parser_function.php       2010-07-01 08:25:04 UTC 
(rev 68821)
@@ -15,14 +15,14 @@
 }
 
 # Define a setup function
-$wgExtensionFunctions[] = 'wfExampleParserFunction_Setup';
+$wgHooks['ParserFirstCallInit'][] = 'wfExampleParserFunction_Setup';
 # Add a hook to initialise the magic word
-$wgHooks['LanguageGetMagic'][]       = 'wfExampleParserFunction_Magic';
+$wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic';
 
-function wfExampleParserFunction_Setup() {
-       global $wgParser;
+function wfExampleParserFunction_Setup( $parser ) {
        # Set a function hook associating the "example" magic word with our 
function
-       $wgParser->setFunctionHook( 'example', 'wfExampleParserFunction_Render' 
);
+       $parser->setFunctionHook( 'example', 'wfExampleParserFunction_Render' );
+       return true;
 }
 
 function wfExampleParserFunction_Magic( &$magicWords, $langCode ) {

Modified: trunk/extensions/examples/Parser_hook.php
===================================================================
--- trunk/extensions/examples/Parser_hook.php   2010-07-01 08:05:49 UTC (rev 
68820)
+++ trunk/extensions/examples/Parser_hook.php   2010-07-01 08:25:04 UTC (rev 
68821)
@@ -8,11 +8,11 @@
  * @ingroup Extensions
  *
  * @author Ævar Arnfjörð Bjarmason <ava...@gmail.com>
+ * @author Niklas Laxström
  * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
 
-$wgExtensionFunctions[] = 'wfParserHook';
 $wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'Parser hook',
@@ -20,20 +20,22 @@
        'author' => 'Ævar Arnfjörð Bjarmason'
 );
 
-function wfParserHook() {
-       global $wgParser;
-       
-       $wgParser->setHook( 'hook' , 'wfParserHookParse' );
+$wgHooks['ParserFirstCallInit'][] = 'wfParserHook';
+
+function wfParserHook( $parser ) {
+       $parser->setHook( 'hook' , 'wfParserHookParse' );
+       return true;
 }
 
 /**
  * @param string $in The input passed to <hook>
  * @param array $argv The attributes of the <hook> element in array form
  */
-function wfParserHookParse( $in, $argv ) {
-       if ( ! count( $argv ) )
-               return $in;
-       else
-               return '<pre>' . $in . "\n" . print_r( $argv, true ) . '</pre>';
+function wfParserHookParse( $data, $params, $parser ) {
+       if ( !count( $params ) ) {
+               return $data;
+       } else {
+               return '<pre>' . $data . "\n" . print_r( $params, true ) . 
'</pre>';
+       }
 }
 

Modified: trunk/extensions/examples/SpecialIncludable.php
===================================================================
--- trunk/extensions/examples/SpecialIncludable.php     2010-07-01 08:05:49 UTC 
(rev 68820)
+++ trunk/extensions/examples/SpecialIncludable.php     2010-07-01 08:25:04 UTC 
(rev 68821)
@@ -2,56 +2,51 @@
 if ( !defined( 'MEDIAWIKI' ) ) die();
 /**
  * A Special Page sample that can be included on a wikipage like
- * {{Special:Inc}} as well as being accessed on [[Special:Inc]]
+ * {{Special:Includable}} as well as being accessed on [[Special:Includable]]
  *
  * @file
  * @ingroup Extensions
  *
  * @author Ævar Arnfjörð Bjarmason <ava...@gmail.com>
+ * @author Niklas Laxström
  * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
 
-$wgExtensionFunctions[] = 'wfIncludable';
 $wgExtensionCredits['specialpage'][] = array(
        'path' => __FILE__,
        'name' => 'Includable',
        'description' => 'a sample includable Special Page',
        'author' => 'Ævar Arnfjörð Bjarmason'
 );
-       
 
-function wfIncludable() {
-       global $IP, $wgMessageCache;
+$wgSpecialPages['Includable'] = 'SpecialIncludable';
 
-       $wgMessageCache->addMessage( 'includable', 'Includable' );
-       
-       require_once "$IP/includes/SpecialPage.php";
-       class SpecialIncludable extends SpecialPage {
-               /**
-                * Constructor
-                */
-               function SpecialIncludable() {
-                       SpecialPage::SpecialPage( 'Includable' );
-                       $this->includable( true );
-               }
+// See FourFileTemplate how to do i18n
+//$wgExtensionMessagesFiles['Includable'] = dirname( __FILE__ ) . 
'/Includable.i18n.php';
 
-               /**
-                * main()
-                */
-               function execute( $par = null ) {
-                       global $wgOut;
-                       
-                       if ( $this->including() )
-                               $out = "I'm being included";
-                       else {
-                               $out = "I'm being viewed as a Special Page";
-                               $this->setHeaders();
-                       }
+class SpecialIncludable extends SpecialPage {
+       /**
+               * Constructor
+               */
+       function SpecialIncludable() {
+               parent::__construct( 'Includable' );
+               $this->includable( true );
+       }
 
-                       $wgOut->addHTML( $out );
+       /**
+               * main()
+               */
+       function execute( $par = null ) {
+               global $wgOut;
+               
+               if ( $this->including() )
+                       $out = "I'm being included";
+               else {
+                       $out = "I'm being viewed as a Special Page";
+                       $this->setHeaders();
                }
+
+               $wgOut->addWikiText( $out );
        }
-       
-       SpecialPage::addPage( new SpecialIncludable );
-}
+}
\ No newline at end of file

Modified: trunk/extensions/examples/Variable_hook.php
===================================================================
--- trunk/extensions/examples/Variable_hook.php 2010-07-01 08:05:49 UTC (rev 
68820)
+++ trunk/extensions/examples/Variable_hook.php 2010-07-01 08:25:04 UTC (rev 
68821)
@@ -28,15 +28,15 @@
 }
 
 function wfVariableHookRaw( &$raw ) {
-       $raw['example'] = array( 0, 'EXAMPLE' ); ;
+       $raw['example'] = array( 0, 'EXAMPLE' );
 
        return true;
 }
 
 function wfVariableHookSwitch( &$parser, &$varCache, &$index, &$ret ) {
-       if ( $index === 'example' )
+       if ( $index === 'example' ) {
                $ret = $varCache[$index] = wfVariableHookRet();
-       
+       }
        return true;
 }
 



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to