From d636fac2d8416fa8dcd5610bd2c932ab6bc147e1 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Thu, 11 Aug 2011 17:21:31 +0000 Subject: [PATCH] Allow extensions to add pages with non-wikitext display by adding two new hooks (generalizing the code already used for CSS/JS pages). --- docs/hooks.txt | 10 ++++++++++ includes/Article.php | 3 +++ includes/EditPage.php | 29 +++++++++++++++++------------ includes/Title.php | 11 +++++++++++ includes/WikiPage.php | 3 +-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 73008333fc..6df106a259 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -545,6 +545,11 @@ viewing. follwed an redirect $article: target article (object) +'ArticleViewCustom': allows to output the text of the article in a different format than wikitext +$text: text of the page +$title: title of the page +$output: reference to $wgOut + 'AuthPluginAutoCreate': Called when creating a local account for an user logged in from an external authentication method $user: User object created locally @@ -1755,6 +1760,11 @@ $title: The title in question. $title: Title object that is being checked $result: Boolean; whether MediaWiki currently thinks this is a CSS/JS page. Hooks may change this value to override the return value of Title::isCssOrJsPage() +'TitleIsWikitextPage': Called when determining if a page is a wikitext or should +be handled by seperate handler (via ArticleViewCustom) +$title: Title object that is being checked +$result: Boolean; whether MediaWiki currently thinks this is a wikitext page. Hooks may change this value to override the return value of Title::isWikitextPage() + 'TitleMoveComplete': after moving an article (title) $old: old title $nt: new title diff --git a/includes/Article.php b/includes/Article.php index a120355032..2691fa34cd 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -510,6 +510,9 @@ class Article extends Page { wfDebug( __METHOD__ . ": showing CSS/JS source\n" ); $this->showCssOrJsPage(); $outputDone = true; + } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) { + # Allow extensions do their own custom view for certain pages + $outputDone = true; } else { $rt = Title::newFromRedirectArray( $text ); if ( $rt ) { diff --git a/includes/EditPage.php b/includes/EditPage.php index a14871e21d..bf79b09660 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2019,25 +2019,30 @@ HTML return $parsedNote; } - # don't parse user css/js, show message about preview + # don't parse non-wikitext pages, show message about preview # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago? - if ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) { - $level = 'user'; - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + if ( $this->isCssJsSubpage || !$this->mTitle->isWikitextPage() ) { + if( $this->mTitle->isCssJsSubpage() ) { + $level = 'user'; + } elseif( $this->mTitle->isCssOrJsPage() ) { $level = 'site'; + } else { + $level = false; } # Used messages to make sure grep find them: # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview - if (preg_match( "/\\.css$/", $this->mTitle->getText() ) ) { - $previewtext = "
\n" . wfMsg( "{$level}csspreview" ) . "\n
"; - $class = "mw-code mw-css"; - } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) { - $previewtext = "
\n" . wfMsg( "{$level}jspreview" ) . "\n
"; - $class = "mw-code mw-js"; - } else { - throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' ); + if( $level ) { + if (preg_match( "/\\.css$/", $this->mTitle->getText() ) ) { + $previewtext = "
\n" . wfMsg( "{$level}csspreview" ) . "\n
"; + $class = "mw-code mw-css"; + } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) { + $previewtext = "
\n" . wfMsg( "{$level}jspreview" ) . "\n
"; + $class = "mw-code mw-js"; + } else { + throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' ); + } } $parserOptions->setTidy( true ); diff --git a/includes/Title.php b/includes/Title.php index 405d420390..ed6e735b51 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1942,6 +1942,17 @@ class Title { ); } + /** + * Does that page contain wikitext, or it is JS, CSS or whatever? + * + * @return Bool + */ + public function isWikitextPage() { + $retval = !$this->isCssOrJsPage() && !$this->isCssJsSubpage(); + wfRunHooks( 'TitleIsWikitextPage', array( $this, &$retval ) ); + return $retval; + } + /** * Could this page contain custom CSS or JavaScript, based * on the title? diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 9a49e9e05c..47632c05de 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -716,8 +716,7 @@ class WikiPage extends Page { && $user->getStubThreshold() == 0 && $this->exists() && empty( $oldid ) - && !$this->mTitle->isCssOrJsPage() - && !$this->mTitle->isCssJsSubpage(); + && $this->mTitle->isWikitextPage(); } /** -- 2.20.1