summaryrefslogtreecommitdiff
path: root/includes/content/JavaScriptContent.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /includes/content/JavaScriptContent.php
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'includes/content/JavaScriptContent.php')
-rw-r--r--includes/content/JavaScriptContent.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/includes/content/JavaScriptContent.php b/includes/content/JavaScriptContent.php
index c0194c2e..6d236560 100644
--- a/includes/content/JavaScriptContent.php
+++ b/includes/content/JavaScriptContent.php
@@ -33,6 +33,11 @@
class JavaScriptContent extends TextContent {
/**
+ * @var bool|Title|null
+ */
+ private $redirectTarget = false;
+
+ /**
* @param string $text JavaScript code.
* @param string $modelId the content model name
*/
@@ -73,4 +78,46 @@ class JavaScriptContent extends TextContent {
return $html;
}
+ /**
+ * If this page is a redirect, return the content
+ * if it should redirect to $target instead
+ *
+ * @param Title $target
+ * @return JavaScriptContent
+ */
+ public function updateRedirect( Title $target ) {
+ if ( !$this->isRedirect() ) {
+ return $this;
+ }
+
+ return $this->getContentHandler()->makeRedirectContent( $target );
+ }
+
+ /**
+ * @return Title|null
+ */
+ public function getRedirectTarget() {
+ if ( $this->redirectTarget !== false ) {
+ return $this->redirectTarget;
+ }
+ $this->redirectTarget = null;
+ $text = $this->getNativeData();
+ if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
+ // Extract the title from the url
+ preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches );
+ if ( isset( $matches[1] ) ) {
+ $title = Title::newFromText( $matches[1] );
+ if ( $title ) {
+ // Have a title, check that the current content equals what
+ // the redirect content should be
+ if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
+ $this->redirectTarget = $title;
+ }
+ }
+ }
+ }
+
+ return $this->redirectTarget;
+ }
+
}