From 7f2155fa9e020c63a4c5b67218cbbe1eb16ab729 Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Tue, 13 Jun 2006 11:37:09 +0000 Subject: [PATCH] Bug 6031 (feature request for __NOGALLERY__ on category pages) fixed --- includes/Article.php | 3 +-- includes/CategoryPage.php | 5 +++++ includes/MagicWord.php | 1 + includes/OutputPage.php | 2 ++ includes/Parser.php | 16 +++++++++++++++- languages/Language.php | 1 + 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 2b3149311a..d3c9ca294f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -863,7 +863,6 @@ class Article { $wgOut->addPrimaryWikiText( $text, $this ); } else { # Display content, don't attempt to save to parser cache - # Don't show section-edit links on old revisions... this way lies madness. if( !$this->isCurrent() ) { $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false ); @@ -881,7 +880,7 @@ class Article { if( empty( $t ) ) { $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); } - + # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page if( $ns == NS_USER_TALK && User::isIP( $this->mTitle->getText() ) ) { diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 790838f6dd..a27e6cd7b5 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -40,7 +40,12 @@ class CategoryPage extends Article { global $wgOut, $wgRequest; $from = $wgRequest->getVal( 'from' ); $until = $wgRequest->getVal( 'until' ); + + global $wgCategoryMagicGallery; + $cmg = $wgCategoryMagicGallery; + $wgCategoryMagicGallery = !$wgOut->mNoGallery; $wgOut->addHTML( $this->doCategoryMagic( $from, $until ) ); + $wgCategoryMagicGallery = $cmg; } /** diff --git a/includes/MagicWord.php b/includes/MagicWord.php index a68407c735..b5a58c2eda 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -94,6 +94,7 @@ $magicWords = array( 'MAG_LANGUAGE', 'MAG_CONTENTLANGUAGE', 'MAG_PAGESINNAMESPACE', + 'MAG_NOGALLERY', ); if ( ! defined( 'MEDIAWIKI_INSTALL' ) ) wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index b717292d51..0dd85267c6 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -327,6 +327,7 @@ class OutputPage { $this->addParserOutputNoText( $parserOutput ); $text = $parserOutput->getText(); + $this->mNoGallery = $parserOutput->getNoGallery(); wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) ); $parserOutput->setText( $text ); $this->addHTML( $parserOutput->getText() ); @@ -380,6 +381,7 @@ class OutputPage { $this->addCategoryLinks( $parserOutput->getCategories() ); $this->addKeywords( $parserOutput ); $this->mNewSectionLink = $parserOutput->getNewSection(); + $this->mNoGallery = $parserOutput->getNoGallery(); $text = $parserOutput->getText(); wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) ); $this->addHTML( $text ); diff --git a/includes/Parser.php b/includes/Parser.php index 82e22117ef..ed808d96fa 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -843,6 +843,7 @@ class Parser $text = preg_replace( '/(^|\n)-----*/', '\\1
', $text ); $text = $this->stripToc( $text ); + $this->stripNoGallery( $text ); $text = $this->doHeadings( $text ); if($this->mOptions->getUseDynamicDates()) { $df =& DateFormatter::getInstance(); @@ -3172,6 +3173,16 @@ class Parser } } + /** + * Detect __NOGALLERY__ magic word and set a placeholder + */ + function stripNoGallery( &$text ) { + # if the string __NOGALLERY__ (not case-sensitive) occurs in the HTML, + # do not add TOC + $mw = MagicWord::get( MAG_NOGALLERY ); + $this->mOutput->mNoGallery = $mw->matchAndRemove( $text ) ; + } + /** * Detect __TOC__ magic word and set a placeholder */ @@ -4424,7 +4435,8 @@ class ParserOutput $mExternalLinks, # External link URLs, in the key only $mHTMLtitle, # Display HTML title $mSubtitle, # Additional subtitle - $mNewSection; # Show a new section link? + $mNewSection, # Show a new section link? + $mNoGallery; # No gallery on category page? (__NOGALLERY__) function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(), $containsOldMagic = false, $titletext = '' ) @@ -4443,6 +4455,7 @@ class ParserOutput $this->mHTMLtitle = "" ; $this->mSubtitle = "" ; $this->mNewSection = false; + $this->mNoGallery = false; } function getText() { return $this->mText; } @@ -4455,6 +4468,7 @@ class ParserOutput function &getTemplates() { return $this->mTemplates; } function &getImages() { return $this->mImages; } function &getExternalLinks() { return $this->mExternalLinks; } + function getNoGallery() { return $this->mNoGallery; } function containsOldMagic() { return $this->mContainsOldMagic; } function setText( $text ) { return wfSetVar( $this->mText, $text ); } diff --git a/languages/Language.php b/languages/Language.php index 30d9044c81..9d8c159d94 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -213,6 +213,7 @@ $wgLanguageNamesEn =& $wgLanguageNames; # ID CASE SYNONYMS MAG_REDIRECT => array( 0, '#REDIRECT' ), MAG_NOTOC => array( 0, '__NOTOC__' ), + MAG_NOGALLERY => array( 0, '__NOGALLERY__' ), MAG_FORCETOC => array( 0, '__FORCETOC__' ), MAG_TOC => array( 0, '__TOC__' ), MAG_NOEDITSECTION => array( 0, '__NOEDITSECTION__' ), -- 2.20.1