/** * @dataProvider getEntityIdFromOutputPageProvider */ public function testGetEntityIdFromOutputPage($expected, OutputPage $out, $isEntityContentModel) { $entityContentFactory = $this->getMockBuilder('Wikibase\\Repo\\Content\\EntityContentFactory')->disableOriginalConstructor()->getMock(); $entityContentFactory->expects($this->once())->method('isEntityContentModel')->with('bar')->will($this->returnValue($isEntityContentModel)); $outputPageEntityIdReader = new OutputPageEntityIdReader($entityContentFactory, new BasicEntityIdParser()); $this->assertEquals($expected, $outputPageEntityIdReader->getEntityIdFromOutputPage($out)); }
/** * Used to append a css class to the body, so the page can be identified as Wikibase item page. * @see http://www.mediawiki.org/wiki/Manual:Hooks/OutputPageBodyAttributes * * @since 0.1 * * @param OutputPage $out * @param Skin $sk * @param array $bodyAttrs * * @return bool */ public static function onOutputPageBodyAttributes(OutputPage $out, Skin $sk, array &$bodyAttrs) { $wikibaseRepo = WikibaseRepo::getDefaultInstance(); $outputPageEntityIdReader = new OutputPageEntityIdReader($wikibaseRepo->getEntityContentFactory(), $wikibaseRepo->getEntityIdParser()); $entityId = $outputPageEntityIdReader->getEntityIdFromOutputPage($out); if ($entityId === null) { return true; } // TODO: preg_replace kind of ridiculous here, should probably change the ENTITY_TYPE constants instead $entityType = preg_replace('/^wikibase-/i', '', $entityId->getEntityType()); // add class to body so it's clear this is a wb item: $bodyAttrs['class'] .= ' wb-entitypage wb-' . $entityType . 'page'; // add another class with the ID of the item: $bodyAttrs['class'] .= ' wb-' . $entityType . 'page-' . $entityId->getSerialization(); if ($sk->getRequest()->getCheck('diff')) { $bodyAttrs['class'] .= ' wb-diffpage'; } if ($out->getRevisionId() !== $out->getTitle()->getLatestRevID()) { $bodyAttrs['class'] .= ' wb-oldrevpage'; } return true; }