r94259 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94258‎ | r94259 | r94260 >
Date:17:21, 11 August 2011
Author:vasilievvv
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -545,6 +545,11 @@
546546 follwed an redirect
547547 $article: target article (object)
548548
 549+'ArticleViewCustom': allows to output the text of the article in a different format than wikitext
 550+$text: text of the page
 551+$title: title of the page
 552+$output: reference to $wgOut
 553+
549554 'AuthPluginAutoCreate': Called when creating a local account for an user logged
550555 in from an external authentication method
551556 $user: User object created locally
@@ -1755,6 +1760,11 @@
17561761 $title: Title object that is being checked
17571762 $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()
17581763
 1764+'TitleIsWikitextPage': Called when determining if a page is a wikitext or should
 1765+be handled by seperate handler (via ArticleViewCustom)
 1766+$title: Title object that is being checked
 1767+$result: Boolean; whether MediaWiki currently thinks this is a wikitext page. Hooks may change this value to override the return value of Title::isWikitextPage()
 1768+
17591769 'TitleMoveComplete': after moving an article (title)
17601770 $old: old title
17611771 $nt: new title
Index: trunk/phase3/includes/Article.php
@@ -510,6 +510,9 @@
511511 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
512512 $this->showCssOrJsPage();
513513 $outputDone = true;
 514+ } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
 515+ # Allow extensions do their own custom view for certain pages
 516+ $outputDone = true;
514517 } else {
515518 $rt = Title::newFromRedirectArray( $text );
516519 if ( $rt ) {
Index: trunk/phase3/includes/EditPage.php
@@ -2019,25 +2019,30 @@
20202020 return $parsedNote;
20212021 }
20222022
2023 - # don't parse user css/js, show message about preview
 2023+ # don't parse non-wikitext pages, show message about preview
20242024 # 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?
20252025
2026 - if ( $this->isCssJsSubpage || $this->mTitle->isCssOrJsPage() ) {
2027 - $level = 'user';
2028 - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
 2026+ if ( $this->isCssJsSubpage || !$this->mTitle->isWikitextPage() ) {
 2027+ if( $this->mTitle->isCssJsSubpage() ) {
 2028+ $level = 'user';
 2029+ } elseif( $this->mTitle->isCssOrJsPage() ) {
20292030 $level = 'site';
 2031+ } else {
 2032+ $level = false;
20302033 }
20312034
20322035 # Used messages to make sure grep find them:
20332036 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2034 - if (preg_match( "/\\.css$/", $this->mTitle->getText() ) ) {
2035 - $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
2036 - $class = "mw-code mw-css";
2037 - } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
2038 - $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
2039 - $class = "mw-code mw-js";
2040 - } else {
2041 - throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
 2037+ if( $level ) {
 2038+ if (preg_match( "/\\.css$/", $this->mTitle->getText() ) ) {
 2039+ $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
 2040+ $class = "mw-code mw-css";
 2041+ } elseif (preg_match( "/\\.js$/", $this->mTitle->getText() ) ) {
 2042+ $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
 2043+ $class = "mw-code mw-js";
 2044+ } else {
 2045+ throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
 2046+ }
20422047 }
20432048
20442049 $parserOptions->setTidy( true );
Index: trunk/phase3/includes/Title.php
@@ -1943,6 +1943,17 @@
19441944 }
19451945
19461946 /**
 1947+ * Does that page contain wikitext, or it is JS, CSS or whatever?
 1948+ *
 1949+ * @return Bool
 1950+ */
 1951+ public function isWikitextPage() {
 1952+ $retval = !$this->isCssOrJsPage() && !$this->isCssJsSubpage();
 1953+ wfRunHooks( 'TitleIsWikitextPage', array( $this, &$retval ) );
 1954+ return $retval;
 1955+ }
 1956+
 1957+ /**
19471958 * Could this page contain custom CSS or JavaScript, based
19481959 * on the title?
19491960 *
Index: trunk/phase3/includes/WikiPage.php
@@ -716,8 +716,7 @@
717717 && $user->getStubThreshold() == 0
718718 && $this->exists()
719719 && empty( $oldid )
720 - && !$this->mTitle->isCssOrJsPage()
721 - && !$this->mTitle->isCssJsSubpage();
 720+ && $this->mTitle->isWikitextPage();
722721 }
723722
724723 /**

Status & tagging log