http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94259

Revision: 94259
Author:   vasilievvv
Date:     2011-08-11 17:21:31 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
Allow extensions to add pages with non-wikitext display by adding two new
hooks (generalizing the code already used for CSS/JS pages).

Modified Paths:
--------------
    trunk/phase3/docs/hooks.txt
    trunk/phase3/includes/Article.php
    trunk/phase3/includes/EditPage.php
    trunk/phase3/includes/Title.php
    trunk/phase3/includes/WikiPage.php

Modified: trunk/phase3/docs/hooks.txt
===================================================================
--- trunk/phase3/docs/hooks.txt 2011-08-11 17:20:20 UTC (rev 94258)
+++ trunk/phase3/docs/hooks.txt 2011-08-11 17:21:31 UTC (rev 94259)
@@ -545,6 +545,11 @@
 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: 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

Modified: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php   2011-08-11 17:20:20 UTC (rev 94258)
+++ trunk/phase3/includes/Article.php   2011-08-11 17:21:31 UTC (rev 94259)
@@ -510,6 +510,9 @@
                                                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 ) {

Modified: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php  2011-08-11 17:20:20 UTC (rev 94258)
+++ trunk/phase3/includes/EditPage.php  2011-08-11 17:21:31 UTC (rev 94259)
@@ -2019,25 +2019,30 @@
                        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 );

Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php     2011-08-11 17:20:20 UTC (rev 94258)
+++ trunk/phase3/includes/Title.php     2011-08-11 17:21:31 UTC (rev 94259)
@@ -1943,6 +1943,17 @@
        }
 
        /**
+        * 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?
         *

Modified: trunk/phase3/includes/WikiPage.php
===================================================================
--- trunk/phase3/includes/WikiPage.php  2011-08-11 17:20:20 UTC (rev 94258)
+++ trunk/phase3/includes/WikiPage.php  2011-08-11 17:21:31 UTC (rev 94259)
@@ -716,8 +716,7 @@
                        && $user->getStubThreshold() == 0
                        && $this->exists()
                        && empty( $oldid )
-                       && !$this->mTitle->isCssOrJsPage()
-                       && !$this->mTitle->isCssJsSubpage();
+                       && $this->mTitle->isWikitextPage();
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to