MediaWiki  1.28.1
Go to the documentation of this file.
1 <?php
15  private $title1;
20  private $title2;
25  private $the_properties;
27  protected function setUp() {
28  global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
30  parent::setUp();
32  $wgExtraNamespaces[12312] = 'Dummy';
33  $wgExtraNamespaces[12313] = 'Dummy_talk';
35  $wgNamespaceContentModels[12312] = 'DUMMY';
36  $wgContentHandlers['DUMMY'] = 'DummyContentHandlerForTesting';
38  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
39  $wgContLang->resetNamespaces(); # reset namespace cache
41  if ( !$this->the_properties ) {
42  $this->the_properties = [
43  "property1" => "value1",
44  "property2" => "value2",
45  "property3" => "value3",
46  "property4" => "value4"
47  ];
48  }
50  if ( !$this->title1 ) {
51  $page = $this->createPage(
52  'PagePropsTest_page_1',
53  "just a dummy page",
55  );
56  $this->title1 = $page->getTitle();
57  $page1ID = $this->title1->getArticleID();
58  $this->setProperties( $page1ID, $this->the_properties );
59  }
61  if ( !$this->title2 ) {
62  $page = $this->createPage(
63  'PagePropsTest_page_2',
64  "just a dummy page",
66  );
67  $this->title2 = $page->getTitle();
68  $page2ID = $this->title2->getArticleID();
69  $this->setProperties( $page2ID, $this->the_properties );
70  }
71  }
73  protected function tearDown() {
74  global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang;
76  parent::tearDown();
78  unset( $wgExtraNamespaces[12312] );
79  unset( $wgExtraNamespaces[12313] );
81  unset( $wgNamespaceContentModels[12312] );
82  unset( $wgContentHandlers['DUMMY'] );
84  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
85  $wgContLang->resetNamespaces(); # reset namespace cache
86  }
93  $pageProps = PageProps::getInstance();
94  $page1ID = $this->title1->getArticleID();
95  $result = $pageProps->getProperties( $this->title1, "property1" );
96  $this->assertArrayHasKey( $page1ID, $result, "Found property" );
97  $this->assertEquals( $result[$page1ID], "value1", "Get property" );
98  }
105  $pageProps = PageProps::getInstance();
106  $page1ID = $this->title1->getArticleID();
107  $page2ID = $this->title2->getArticleID();
108  $titles = [
111  ];
112  $result = $pageProps->getProperties( $titles, "property1" );
113  $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
114  $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
115  $this->assertEquals( $result[$page1ID], "value1", "Get property page 1" );
116  $this->assertEquals( $result[$page2ID], "value1", "Get property page 2" );
117  }
124  $pageProps = PageProps::getInstance();
125  $page1ID = $this->title1->getArticleID();
126  $page2ID = $this->title2->getArticleID();
127  $titles = [
130  ];
131  $properties = [
132  "property1",
133  "property2"
134  ];
135  $result = $pageProps->getProperties( $titles, $properties );
136  $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
137  $this->assertArrayHasKey( "property1", $result[$page1ID], "Found page 1 property 1" );
138  $this->assertArrayHasKey( "property2", $result[$page1ID], "Found page 1 property 2" );
139  $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
140  $this->assertArrayHasKey( "property1", $result[$page2ID], "Found page 2 property 1" );
141  $this->assertArrayHasKey( "property2", $result[$page2ID], "Found page 2 property 2" );
142  $this->assertEquals( $result[$page1ID]["property1"], "value1", "Get page 1 property 1" );
143  $this->assertEquals( $result[$page1ID]["property2"], "value2", "Get page 1 property 2" );
144  $this->assertEquals( $result[$page2ID]["property1"], "value1", "Get page 2 property 1" );
145  $this->assertEquals( $result[$page2ID]["property2"], "value2", "Get page 2 property 2" );
146  }
159  public function testGetAllProperties() {
160  $pageProps = PageProps::getInstance();
161  $page1ID = $this->title1->getArticleID();
162  $result = $pageProps->getAllProperties( $this->title1 );
163  $this->assertArrayHasKey( $page1ID, $result, "Found properties" );
164  $properties = $result[$page1ID];
165  $patched = array_replace_recursive( $properties, $this->the_properties );
166  $this->assertEquals( $patched, $properties, "Get all properties" );
167  }
174  $pageProps = PageProps::getInstance();
175  $page1ID = $this->title1->getArticleID();
176  $page2ID = $this->title2->getArticleID();
177  $titles = [
180  ];
181  $result = $pageProps->getAllProperties( $titles );
182  $this->assertArrayHasKey( $page1ID, $result, "Found page 1 properties" );
183  $this->assertArrayHasKey( $page2ID, $result, "Found page 2 properties" );
184  $properties1 = $result[$page1ID];
185  $patched = array_replace_recursive( $properties1, $this->the_properties );
186  $this->assertEquals( $patched, $properties1, "Get all properties page 1" );
187  $properties2 = $result[$page2ID];
188  $patched = array_replace_recursive( $properties2, $this->the_properties );
189  $this->assertEquals( $patched, $properties2, "Get all properties page 2" );
190  }
198  public function testSingleCache() {
199  $pageProps = PageProps::getInstance();
200  $page1ID = $this->title1->getArticleID();
201  $value1 = $pageProps->getProperties( $this->title1, "property1" );
202  $this->setProperty( $page1ID, "property1", "another value" );
203  $value2 = $pageProps->getProperties( $this->title1, "property1" );
204  $this->assertEquals( $value1, $value2, "Single cache" );
205  }
213  public function testMultiCache() {
214  $pageProps = PageProps::getInstance();
215  $page1ID = $this->title1->getArticleID();
216  $properties1 = $pageProps->getAllProperties( $this->title1 );
217  $this->setProperty( $page1ID, "property1", "another value" );
218  $properties2 = $pageProps->getAllProperties( $this->title1 );
219  $this->assertEquals( $properties1, $properties2, "Multi Cache" );
220  }
230  public function testClearCache() {
231  $pageProps = PageProps::getInstance();
232  $page1ID = $this->title1->getArticleID();
233  $pageProps->getProperties( $this->title1, "property1" );
234  $new_value = "another value";
235  $this->setProperty( $page1ID, "property1", $new_value );
236  $pageProps->getAllProperties( $this->title1 );
237  $result = $pageProps->getProperties( $this->title1, "property1" );
238  $this->assertArrayHasKey( $page1ID, $result, "Found property" );
239  $this->assertEquals( $result[$page1ID], "another value", "Clear cache" );
240  }
242  protected function createPage( $page, $text, $model = null ) {
243  if ( is_string( $page ) ) {
244  if ( !preg_match( '/:/', $page ) &&
245  ( $model === null || $model === CONTENT_MODEL_WIKITEXT )
246  ) {
247  $ns = $this->getDefaultWikitextNS();
248  $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page;
249  }
252  }
254  if ( $page instanceof Title ) {
255  $page = new WikiPage( $page );
256  }
258  if ( $page->exists() ) {
259  $page->doDeleteArticle( "done" );
260  }
262  $content = ContentHandler::makeContent( $text, $page->getTitle(), $model );
263  $page->doEditContent( $content, "testing", EDIT_NEW );
265  return $page;
266  }
268  protected function setProperties( $pageID, $properties ) {
270  $rows = [];
272  foreach ( $properties as $propertyName => $propertyValue ) {
274  $row = [
275  'pp_page' => $pageID,
276  'pp_propname' => $propertyName,
277  'pp_value' => $propertyValue
278  ];
280  $rows[] = $row;
281  }
283  $dbw = wfGetDB( DB_MASTER );
284  $dbw->replace(
285  'page_props',
286  [
287  [
288  'pp_page',
289  'pp_propname'
290  ]
291  ],
292  $rows,
293  __METHOD__
294  );
295  }
297  protected function setProperty( $pageID, $propertyName, $propertyValue ) {
299  $properties = [];
300  $properties[$propertyName] = $propertyValue;
302  $this->setProperties( $pageID, $properties );
304  }
305 }
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
Definition: Defines.php:239
Test getting all properties from multiple pages.
createPage($page, $text, $model=null)
Database ^— tell jenkins this test needs the database.
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
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
Test getting multiple properties from multiple pages.
when a variable name is used in a function
Definition: design.txt:93
Test getting a single property from multiple pages.
Definition: defines.php:23
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
Returns the ID of a namespace that defaults to Wikitext.
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
Test that getting all properties clears the single properties that have been cached by getting a prop...
Test getting a single property from a single page.
static getCanonicalName($index)
Returns the canonical (English) name for a given index.
Test getting all properties from a single page.
setProperty($pageID, $propertyName, $propertyValue)
Base class that store and restore the Language objects.
static makeContent($text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Test caching when retrieving single properties by getting a property, saving a new value for the prop...
Class representing a MediaWiki article and history.
Definition: WikiPage.php:32
Additional namespaces.
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
Test caching when retrieving all properties by getting all properties, saving a new value for a prope...
static getInstance()
Definition: PageProps.php:67
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
const EDIT_NEW
Definition: Defines.php:146
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 called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1046
Plugins for page content model handling.
setProperties($pageID, $properties)
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
static getCanonicalNamespaces($rebuild=false)
Returns array of all defined namespaces with their canonical (English) names.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491