Index: trunk/extensions/examples/Parser_hook.php |
— | — | @@ -8,11 +8,11 @@ |
9 | 9 | * @ingroup Extensions |
10 | 10 | * |
11 | 11 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 12 | + * @author Niklas Laxström |
12 | 13 | * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason |
13 | 14 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
14 | 15 | */ |
15 | 16 | |
16 | | -$wgExtensionFunctions[] = 'wfParserHook'; |
17 | 17 | $wgExtensionCredits['parserhook'][] = array( |
18 | 18 | 'path' => __FILE__, |
19 | 19 | 'name' => 'Parser hook', |
— | — | @@ -20,20 +20,22 @@ |
21 | 21 | 'author' => 'Ævar Arnfjörð Bjarmason' |
22 | 22 | ); |
23 | 23 | |
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; |
28 | 29 | } |
29 | 30 | |
30 | 31 | /** |
31 | 32 | * @param string $in The input passed to <hook> |
32 | 33 | * @param array $argv The attributes of the <hook> element in array form |
33 | 34 | */ |
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 | + } |
39 | 41 | } |
40 | 42 | |
Index: trunk/extensions/examples/FourFileTemplate/MyExtension_body.php |
— | — | @@ -1,6 +1,5 @@ |
2 | 2 | <?php |
3 | | -class MyExtension extends SpecialPage |
4 | | -{ |
| 3 | +class MyExtension extends SpecialPage { |
5 | 4 | function MyExtension() { |
6 | 5 | parent::__construct( "MyExtension" ); |
7 | 6 | } |
— | — | @@ -10,8 +9,6 @@ |
11 | 10 | |
12 | 11 | $this->setHeaders(); |
13 | 12 | |
14 | | - wfLoadExtensionMessages( 'MyExtension' ); |
15 | | - |
16 | 13 | # Get request data from, e.g. |
17 | 14 | $param = $wgRequest->getText( 'param' ); |
18 | 15 | |
Index: trunk/extensions/examples/FourFileTemplate/MyExtension.php |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | 'path' => __FILE__, |
14 | 14 | 'name' => 'MyExtensionName', |
15 | 15 | 'version' => '0.1', |
| 16 | + // You can use array for multiple authors |
16 | 17 | 'author' => 'MyExtensionAuthor', |
17 | 18 | 'url' => 'http://www.mediawiki.org/wiki/Extension:MyExtension', |
18 | 19 | 'descriptionmsg' => 'myextension-desc', |
Index: trunk/extensions/examples/Parser_function.php |
— | — | @@ -15,14 +15,14 @@ |
16 | 16 | } |
17 | 17 | |
18 | 18 | # Define a setup function |
19 | | -$wgExtensionFunctions[] = 'wfExampleParserFunction_Setup'; |
| 19 | +$wgHooks['ParserFirstCallInit'][] = 'wfExampleParserFunction_Setup'; |
20 | 20 | # Add a hook to initialise the magic word |
21 | | -$wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic'; |
| 21 | +$wgHooks['LanguageGetMagic'][] = 'wfExampleParserFunction_Magic'; |
22 | 22 | |
23 | | -function wfExampleParserFunction_Setup() { |
24 | | - global $wgParser; |
| 23 | +function wfExampleParserFunction_Setup( $parser ) { |
25 | 24 | # 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; |
27 | 27 | } |
28 | 28 | |
29 | 29 | function wfExampleParserFunction_Magic( &$magicWords, $langCode ) { |
Index: trunk/extensions/examples/SpecialIncludable.php |
— | — | @@ -2,56 +2,51 @@ |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 4 | /** |
5 | 5 | * 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]] |
7 | 7 | * |
8 | 8 | * @file |
9 | 9 | * @ingroup Extensions |
10 | 10 | * |
11 | 11 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 12 | + * @author Niklas Laxström |
12 | 13 | * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason |
13 | 14 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
14 | 15 | */ |
15 | 16 | |
16 | | -$wgExtensionFunctions[] = 'wfIncludable'; |
17 | 17 | $wgExtensionCredits['specialpage'][] = array( |
18 | 18 | 'path' => __FILE__, |
19 | 19 | 'name' => 'Includable', |
20 | 20 | 'description' => 'a sample includable Special Page', |
21 | 21 | 'author' => 'Ævar Arnfjörð Bjarmason' |
22 | 22 | ); |
23 | | - |
24 | 23 | |
25 | | -function wfIncludable() { |
26 | | - global $IP, $wgMessageCache; |
| 24 | +$wgSpecialPages['Includable'] = 'SpecialIncludable'; |
27 | 25 | |
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'; |
39 | 28 | |
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 | + } |
52 | 37 | |
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(); |
54 | 49 | } |
| 50 | + |
| 51 | + $wgOut->addWikiText( $out ); |
55 | 52 | } |
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 @@ |
29 | 29 | } |
30 | 30 | |
31 | 31 | function wfVariableHookRaw( &$raw ) { |
32 | | - $raw['example'] = array( 0, 'EXAMPLE' ); ; |
| 32 | + $raw['example'] = array( 0, 'EXAMPLE' ); |
33 | 33 | |
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | |
37 | 37 | function wfVariableHookSwitch( &$parser, &$varCache, &$index, &$ret ) { |
38 | | - if ( $index === 'example' ) |
| 38 | + if ( $index === 'example' ) { |
39 | 39 | $ret = $varCache[$index] = wfVariableHookRet(); |
40 | | - |
| 40 | + } |
41 | 41 | return true; |
42 | 42 | } |
43 | 43 | |
Index: trunk/extensions/examples/Content_action.php |
— | — | @@ -19,6 +19,8 @@ |
20 | 20 | |
21 | 21 | function wfAddaction() { |
22 | 22 | global $wgHooks, $wgMessageCache; |
| 23 | + // This is not the proper way to do i18n |
| 24 | + // See FourFileTemplate how to do i18n |
23 | 25 | $wgMessageCache->addMessage( 'myact', 'My action' ); |
24 | 26 | $wgHooks['SkinTemplateContentActions'][] = 'wfAddactionContentHook'; |
25 | 27 | $wgHooks['UnknownAction'][] = 'wfAddactActionHook'; |
— | — | @@ -31,7 +33,7 @@ |
32 | 34 | |
33 | 35 | if ( $wgTitle->getNamespace() != NS_SPECIAL ) { |
34 | 36 | $content_actions['myact'] = array( |
35 | | - 'class' => $action == 'myact' ? 'selected' : false, |
| 37 | + 'class' => $action === 'myact' ? 'selected' : false, |
36 | 38 | 'text' => wfMsg( 'myact' ), |
37 | 39 | 'href' => $wgTitle->getLocalUrl( 'action=myact' ) |
38 | 40 | ); |
— | — | @@ -45,8 +47,9 @@ |
46 | 48 | |
47 | 49 | $title = $wgArticle->getTitle(); |
48 | 50 | |
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 | + } |
51 | 54 | |
52 | 55 | return false; |
53 | 56 | } |