MediaWiki  1.28.1
TagHooksTest.php
Go to the documentation of this file.
1 <?php
2 
8  public static function provideValidNames() {
9  return [
10  [ 'foo' ],
11  [ 'foo-bar' ],
12  [ 'foo_bar' ],
13  [ 'FOO-BAR' ],
14  [ 'foo bar' ]
15  ];
16  }
17 
18  public static function provideBadNames() {
19  return [ [ "foo<bar" ], [ "foo>bar" ], [ "foo\nbar" ], [ "foo\rbar" ] ];
20  }
21 
26  public function testTagHooks( $tag ) {
27  global $wgParserConf, $wgContLang;
28  $parser = new Parser( $wgParserConf );
29 
30  $parser->setHook( $tag, [ $this, 'tagCallback' ] );
31  $parserOutput = $parser->parse(
32  "Foo<$tag>Bar</$tag>Baz",
33  Title::newFromText( 'Test' ),
34  ParserOptions::newFromUserAndLang( new User, $wgContLang )
35  );
36  $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
37 
38  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
39  }
40 
46  public function testBadTagHooks( $tag ) {
47  global $wgParserConf, $wgContLang;
48  $parser = new Parser( $wgParserConf );
49 
50  $parser->setHook( $tag, [ $this, 'tagCallback' ] );
51  $parser->parse(
52  "Foo<$tag>Bar</$tag>Baz",
53  Title::newFromText( 'Test' ),
54  ParserOptions::newFromUserAndLang( new User, $wgContLang )
55  );
56  $this->fail( 'Exception not thrown.' );
57  }
58 
63  public function testFunctionTagHooks( $tag ) {
64  global $wgParserConf, $wgContLang;
65  $parser = new Parser( $wgParserConf );
66 
67  $parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
68  $parserOutput = $parser->parse(
69  "Foo<$tag>Bar</$tag>Baz",
70  Title::newFromText( 'Test' ),
71  ParserOptions::newFromUserAndLang( new User, $wgContLang )
72  );
73  $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText() );
74 
75  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
76  }
77 
83  public function testBadFunctionTagHooks( $tag ) {
84  global $wgParserConf, $wgContLang;
85  $parser = new Parser( $wgParserConf );
86 
87  $parser->setFunctionTagHook(
88  $tag,
89  [ $this, 'functionTagCallback' ],
91  );
92  $parser->parse(
93  "Foo<$tag>Bar</$tag>Baz",
94  Title::newFromText( 'Test' ),
95  ParserOptions::newFromUserAndLang( new User, $wgContLang )
96  );
97  $this->fail( 'Exception not thrown.' );
98  }
99 
100  function tagCallback( $text, $params, $parser ) {
101  return str_rot13( $text );
102  }
103 
104  function functionTagCallback( &$parser, $frame, $code, $attribs ) {
105  return str_rot13( $code );
106  }
107 }
#define the
table suitable for use with IDatabase::select()
testTagHooks($tag)
provideValidNames Parser::setHook
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
testFunctionTagHooks($tag)
provideValidNames Parser::setFunctionTagHook
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:262
testBadTagHooks($tag)
provideBadNames MWException Parser::setHook
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
testBadFunctionTagHooks($tag)
provideBadNames MWException Parser::setFunctionTagHook
magic word & $parser
Definition: hooks.txt:2487
static provideValidNames()
Definition: TagHooksTest.php:8
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
Definition: hooks.txt:1046
$params
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1936
Database Parser.
Definition: TagHooksTest.php:7
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books $tag
Definition: hooks.txt:1007
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:802
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static provideBadNames()
const SFH_OBJECT_ARGS
Definition: Parser.php:86
tagCallback($text, $params, $parser)
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
functionTagCallback(&$parser, $frame, $code, $attribs)