r68821 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68820‎ | r68821 | r68822 >
Date:08:25, 1 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Update examples from stone age
Modified paths:
  • /trunk/extensions/examples/Content_action.php (modified) (history)
  • /trunk/extensions/examples/FourFileTemplate/MyExtension.php (modified) (history)
  • /trunk/extensions/examples/FourFileTemplate/MyExtension_body.php (modified) (history)
  • /trunk/extensions/examples/Parser_function.php (modified) (history)
  • /trunk/extensions/examples/Parser_hook.php (modified) (history)
  • /trunk/extensions/examples/SpecialIncludable.php (modified) (history)
  • /trunk/extensions/examples/Variable_hook.php (modified) (history)

Diff [purge]

Index: trunk/extensions/examples/Parser_hook.php
@@ -8,11 +8,11 @@
99 * @ingroup Extensions
1010 *
1111 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 12+ * @author Niklas Laxström
1213 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
1314 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1415 */
1516
16 -$wgExtensionFunctions[] = 'wfParserHook';
1717 $wgExtensionCredits['parserhook'][] = array(
1818 'path' => __FILE__,
1919 'name' => 'Parser hook',
@@ -20,20 +20,22 @@
2121 'author' => 'Ævar Arnfjörð Bjarmason'
2222 );
2323
24 -function wfParserHook() {
25 - global $wgParser;
26 -
27 - $wgParser->setHook( 'hook' , 'wfParserHookParse' );
 24+$wgHooks['ParserFirstCallInit'][] = 'wfParserHook';
 25+
 26+function wfParserHook( $parser ) {
 27+ $parser->setHook( 'hook' , 'wfParserHookParse' );
 28+ return true;
2829 }
2930
3031 /**
3132 * @param string $in The input passed to <hook>
3233 * @param array $argv The attributes of the <hook> element in array form
3334 */
34 -function wfParserHookParse( $in, $argv ) {
35 - if ( ! count( $argv ) )
36 - return $in;
37 - else
38 - return '<pre>' . $in . "\n" . print_r( $argv, true ) . '</pre>';
 35+function wfParserHookParse( $data, $params, $parser ) {
 36+ if ( !count( $params ) ) {
 37+ return $data;
 38+ } else {
 39+ return '<pre>' . $data . "\n" . print_r( $params, true ) . '</pre>';
 40+ }
3941 }
4042
Index: trunk/extensions/examples/FourFileTemplate/MyExtension_body.php
@@ -1,6 +1,5 @@
22 <?php
3 -class MyExtension extends SpecialPage
4 -{
 3+class MyExtension extends SpecialPage {
54 function MyExtension() {
65 parent::__construct( "MyExtension" );
76 }
@@ -10,8 +9,6 @@
1110
1211 $this->setHeaders();
1312
14 - wfLoadExtensionMessages( 'MyExtension' );
15 -
1613 # Get request data from, e.g.
1714 $param = $wgRequest->getText( 'param' );
1815
Index: trunk/extensions/examples/FourFileTemplate/MyExtension.php
@@ -12,6 +12,7 @@
1313 'path' => __FILE__,
1414 'name' => 'MyExtensionName',
1515 'version' => '0.1',
 16+ // You can use array for multiple authors
1617 'author' => 'MyExtensionAuthor',
1718 'url' => 'http://www.mediawiki.org/wiki/Extension:MyExtension',
1819 'descriptionmsg' => 'myextension-desc',
Index: trunk/extensions/examples/Parser_function.php
@@ -15,14 +15,14 @@
1616 }
1717
1818 # Define a setup function
19 -$wgExtensionFunctions[] = 'wfExampleParserFunction_Setup';
 19+$wgHooks['ParserFirstCallInit'][] = 'wfExampleParserFunction_Setup';
2020 # Add a hook to initialise the magic word
21 -$wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic';
 21+$wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic';
2222
23 -function wfExampleParserFunction_Setup() {
24 - global $wgParser;
 23+function wfExampleParserFunction_Setup( $parser ) {
2524 # Set a function hook associating the "example" magic word with our function
26 - $wgParser->setFunctionHook( 'example', 'wfExampleParserFunction_Render' );
 25+ $parser->setFunctionHook( 'example', 'wfExampleParserFunction_Render' );
 26+ return true;
2727 }
2828
2929 function wfExampleParserFunction_Magic( &$magicWords, $langCode ) {
Index: trunk/extensions/examples/SpecialIncludable.php
@@ -2,56 +2,51 @@
33 if ( !defined( 'MEDIAWIKI' ) ) die();
44 /**
55 * A Special Page sample that can be included on a wikipage like
6 - * {{Special:Inc}} as well as being accessed on [[Special:Inc]]
 6+ * {{Special:Includable}} as well as being accessed on [[Special:Includable]]
77 *
88 * @file
99 * @ingroup Extensions
1010 *
1111 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 12+ * @author Niklas Laxström
1213 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
1314 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1415 */
1516
16 -$wgExtensionFunctions[] = 'wfIncludable';
1717 $wgExtensionCredits['specialpage'][] = array(
1818 'path' => __FILE__,
1919 'name' => 'Includable',
2020 'description' => 'a sample includable Special Page',
2121 'author' => 'Ævar Arnfjörð Bjarmason'
2222 );
23 -
2423
25 -function wfIncludable() {
26 - global $IP, $wgMessageCache;
 24+$wgSpecialPages['Includable'] = 'SpecialIncludable';
2725
28 - $wgMessageCache->addMessage( 'includable', 'Includable' );
29 -
30 - require_once "$IP/includes/SpecialPage.php";
31 - class SpecialIncludable extends SpecialPage {
32 - /**
33 - * Constructor
34 - */
35 - function SpecialIncludable() {
36 - SpecialPage::SpecialPage( 'Includable' );
37 - $this->includable( true );
38 - }
 26+// See FourFileTemplate how to do i18n
 27+//$wgExtensionMessagesFiles['Includable'] = dirname( __FILE__ ) . '/Includable.i18n.php';
3928
40 - /**
41 - * main()
42 - */
43 - function execute( $par = null ) {
44 - global $wgOut;
45 -
46 - if ( $this->including() )
47 - $out = "I'm being included";
48 - else {
49 - $out = "I'm being viewed as a Special Page";
50 - $this->setHeaders();
51 - }
 29+class SpecialIncludable extends SpecialPage {
 30+ /**
 31+ * Constructor
 32+ */
 33+ function SpecialIncludable() {
 34+ parent::__construct( 'Includable' );
 35+ $this->includable( true );
 36+ }
5237
53 - $wgOut->addHTML( $out );
 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();
5449 }
 50+
 51+ $wgOut->addWikiText( $out );
5552 }
56 -
57 - SpecialPage::addPage( new SpecialIncludable );
58 -}
 53+}
\ No newline at end of file
Index: trunk/extensions/examples/Variable_hook.php
@@ -28,15 +28,15 @@
2929 }
3030
3131 function wfVariableHookRaw( &$raw ) {
32 - $raw['example'] = array( 0, 'EXAMPLE' ); ;
 32+ $raw['example'] = array( 0, 'EXAMPLE' );
3333
3434 return true;
3535 }
3636
3737 function wfVariableHookSwitch( &$parser, &$varCache, &$index, &$ret ) {
38 - if ( $index === 'example' )
 38+ if ( $index === 'example' ) {
3939 $ret = $varCache[$index] = wfVariableHookRet();
40 -
 40+ }
4141 return true;
4242 }
4343
Index: trunk/extensions/examples/Content_action.php
@@ -19,6 +19,8 @@
2020
2121 function wfAddaction() {
2222 global $wgHooks, $wgMessageCache;
 23+ // This is not the proper way to do i18n
 24+ // See FourFileTemplate how to do i18n
2325 $wgMessageCache->addMessage( 'myact', 'My action' );
2426 $wgHooks['SkinTemplateContentActions'][] = 'wfAddactionContentHook';
2527 $wgHooks['UnknownAction'][] = 'wfAddactActionHook';
@@ -31,7 +33,7 @@
3234
3335 if ( $wgTitle->getNamespace() != NS_SPECIAL ) {
3436 $content_actions['myact'] = array(
35 - 'class' => $action == 'myact' ? 'selected' : false,
 37+ 'class' => $action === 'myact' ? 'selected' : false,
3638 'text' => wfMsg( 'myact' ),
3739 'href' => $wgTitle->getLocalUrl( 'action=myact' )
3840 );
@@ -45,8 +47,9 @@
4648
4749 $title = $wgArticle->getTitle();
4850
49 - if ( $action == 'myact' )
50 - $wgOut->addHTML( 'The page name is ' . $title->getText() . ' and you are ' . $wgArticle->getUserText() );
 51+ if ( $action === 'myact' ) {
 52+ $wgOut->addWikiText( 'The page name is ' . $title->getText() . ' and you are ' . $wgArticle->getUserText() );
 53+ }
5154
5255 return false;
5356 }

Status & tagging log