Allow extensions to add pages with non-wikitext display by adding two new
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 11 Aug 2011 17:21:31 +0000 (17:21 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 11 Aug 2011 17:21:31 +0000 (17:21 +0000)
hooks (generalizing the code already used for CSS/JS pages).

docs/hooks.txt
includes/Article.php
includes/EditPage.php
includes/Title.php
includes/WikiPage.php

index 7300833..6df106a 100644 (file)
@@ -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
index a120355..2691fa3 100644 (file)
@@ -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 ) {
index a14871e..bf79b09 100644 (file)
@@ -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 = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
-                               $class = "mw-code mw-css";
-                       } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
-                               $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
-                               $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 = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
+                                       $class = "mw-code mw-css";
+                               } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
+                                       $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
+                                       $class = "mw-code mw-js";
+                               } else {
+                                       throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
+                               }
                        }
 
                        $parserOptions->setTidy( true );
index 405d420..ed6e735 100644 (file)
@@ -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?
index 9a49e9e..47632c0 100644 (file)
@@ -716,8 +716,7 @@ class WikiPage extends Page {
                        && $user->getStubThreshold() == 0
                        && $this->exists()
                        && empty( $oldid )
-                       && !$this->mTitle->isCssOrJsPage()
-                       && !$this->mTitle->isCssJsSubpage();
+                       && $this->mTitle->isWikitextPage();
        }
 
        /**