Jeroen De Dauw has submitted this change and it was merged.
Change subject: Use BeforePageDisplay hook to set the header ExportRDF <link>
......................................................................
Use BeforePageDisplay hook to set the header ExportRDF <link>
I'd failed to understand why ExportRDF was set apart from
the header (using ParserTextProcessor), this is corrected now.
Lately someone juggled with the RL and unstyled content
have seem to appear therefore always load 'ext.smw.style'.
Change-Id: I5266b89c2880cfb261a0c50e596098c9714e0c6c
---
M SemanticMediaWiki.hooks.php
M includes/ParserTextProcessor.php
M includes/Setup.php
M tests/phpunit/includes/HooksTest.php
M tests/phpunit/includes/ParserTextProcessorTest.php
5 files changed, 52 insertions(+), 45 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 14ad262..7a7767f 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -678,4 +678,34 @@
return true;
}
+
+ /**
+ * Hook: Add changes to the output page, e.g. adding of CSS or
JavaScript
+ *
+ * @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
+ *
+ * @since 1.9
+ *
+ * @param OutputPage $outputPage
+ * @param Skin $skin
+ *
+ * @return boolean
+ */
+ public static function onBeforePageDisplay( OutputPage &$outputPage,
Skin &$skin ) {
+ $title = $outputPage->getTitle();
+
+ // Add style resources to avoid unstyled content
+ $outputPage->addModules( array( 'ext.smw.style' ) );
+
+ // Add export link to the head
+ if ( $title instanceof Title && !$title->isSpecialPage() ) {
+ $linkarr['rel'] = 'ExportRDF';
+ $linkarr['type'] = 'application/rdf+xml';
+ $linkarr['title'] = $title->getPrefixedText();
+ $linkarr['href'] = SpecialPage::getTitleFor(
'ExportRDF', $title->getPrefixedText() )->getLocalUrl( 'xmlmime=rdf' );
+ $outputPage->addLink( $linkarr );
+ }
+
+ return true;
+ }
}
diff --git a/includes/ParserTextProcessor.php b/includes/ParserTextProcessor.php
index 771dab3..d6df79b 100644
--- a/includes/ParserTextProcessor.php
+++ b/includes/ParserTextProcessor.php
@@ -130,9 +130,6 @@
$text
);
- // Add RDF link to the HTML header.
- $this->parserData->getOutput()->addHeadItem( "\t\t" .
$this->getRDFUrl( $title ) . "\n" );
-
// Update ParserOutput
$this->parserData->getOutput()->addModules( $this->getModules()
);
$this->parserData->updateOutput();
@@ -221,24 +218,6 @@
\]\] # End of link
/xu';
}
- }
-
- /**
- * Returns ExportRDF URL
- *
- * @since 1.9
- *
- * @param Title $title
- *
- * @return string
- */
- protected function getRDFUrl( Title $title ) {
- return Html::element( 'link', array(
- 'type' => 'application/rdf+xml',
- 'title' => $title->getPrefixedText(),
- 'href' => SpecialPage::getTitleFor( 'ExportRDF',
$title->getPrefixedText() )->getLocalUrl( 'xmlmime=rdf' )
- )
- );
}
/**
diff --git a/includes/Setup.php b/includes/Setup.php
index eeda4a4..a1d1077 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -92,6 +92,8 @@
// User preference
$wgHooks['GetPreferences'][] = 'SMWHooks::onGetPreferences';
+ // Add changes to the output page
+ $wgHooks['BeforePageDisplay'][] = 'SMWHooks::onBeforePageDisplay';
// ResourceLoader
$wgHooks['ResourceLoaderGetConfigVars'][] =
'SMWHooks::onResourceLoaderGetConfigVars';
diff --git a/tests/phpunit/includes/HooksTest.php
b/tests/phpunit/includes/HooksTest.php
index e2401e5..dd373df 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -502,4 +502,24 @@
$this->assertTrue( $skip );
}
}
+
+ /**
+ * @test SMWHooks::onBeforePageDisplay
+ *
+ * @since 1.9
+ */
+ public function testOnBeforePageDisplay() {
+ $context = new \RequestContext();
+ $context->setTitle( $this->getTitle() );
+ $context->setLanguage( \Language::factory( 'en' ) );
+
+ $skin = new \SkinTemplate();
+ $skin->setContext( $context );
+
+ $outputPage = new \OutputPage( $context );
+
+ $result = SMWHooks::onBeforePageDisplay( $outputPage, $skin );
+ $this->assertTrue( $result );
+ }
+
}
diff --git a/tests/phpunit/includes/ParserTextProcessorTest.php
b/tests/phpunit/includes/ParserTextProcessorTest.php
index 4dc5a1c..671442b 100644
--- a/tests/phpunit/includes/ParserTextProcessorTest.php
+++ b/tests/phpunit/includes/ParserTextProcessorTest.php
@@ -240,30 +240,6 @@
}
/**
- * @test ParserTextProcessor::getRDFUrl
- *
- * @since 1.9
- */
- public function testGetRDFUrl() {
- $reflection = new ReflectionClass( $this->getClass() );
-
- $parserOutput = $this->getParserOutput();
- $title = $this->getTitle();
- $instance = $this->getInstance( $title, $parserOutput );
-
- // Make protected method accessible
- $method = $reflection->getMethod( 'getRDFUrl' );
- $method->setAccessible( true );
-
- // Invoke the instance
- $result = $method->invoke( $instance, $title );
-
- // Doing a lazy check, the url has to contain the title text
- $this->assertInternalType( 'string', $result );
- $this->assertContains( 'title="' . $title->getText() . '"',
$result );
- }
-
- /**
* @test ParserTextProcessor::stripMagicWords
* @dataProvider getMagicWordDataProvider
*
--
To view, visit https://gerrit.wikimedia.org/r/63273
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5266b89c2880cfb261a0c50e596098c9714e0c6c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits