From 6429096574f4aadb76d1a2f160322c518b0dd370 Mon Sep 17 00:00:00 2001 From: X! Date: Sat, 4 Oct 2008 15:27:39 +0000 Subject: [PATCH] Implement a configurable per-namespace and per-page header, similar to the editnotice. *MediaWiki:Pageheader-# for whole namespace *MediaWiki:Pagenumber-#-PAGENAME for one page. *Can be disabled using __NOHEADER__ --- RELEASE-NOTES | 4 ++++ includes/Article.php | 27 ++++++++++++++++++++++++++- includes/MagicWord.php | 1 + languages/messages/MessagesEn.php | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 5cf945e970..bbfd5e3928 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -146,6 +146,10 @@ The following extensions are migrated into MediaWiki 1.14: $wgExternalLinkTarget * api.php now sends "Retry-After" and "X-Database-Lag" HTTP headers if the maxlag check fails, just like index.php does +* Configurable per-namespace and per-page header, + respectively MediaWiki:Pageheader-# where # is the namespace number, and + MediaWiki:Pagenumber-#-PAGENAME where # is the page's namespace number and + PAGENAME is the page name minus the namespace prefix. Can be disabled with the new magic word __NOHEADER__ === Bug fixes in 1.14 === diff --git a/includes/Article.php b/includes/Article.php index e389de3bab..88a7bfa33f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -796,6 +796,32 @@ class Article { $wasRedirected = true; } } + + # Optional notices on a per-namespace and per-page basis + $mw = MagicWord::get( 'noheader' ); + $ignoreheader = false; + $text = $this->getContent(); + if( $mw->match( $text ) ) { + $ignoreheader = true; + } + $pageheader_ns = 'pageheader-'.$this->mTitle->getNamespace(); + $pageheader_page = $pageheader_ns.'-'.$this->mTitle->getDBkey(); + if ( !wfEmptyMsg( $pageheader_ns, wfMsgForContent( $pageheader_ns ) ) && !$ignoreheader ) { + $wgOut->addWikiText( wfMsgForContent( $pageheader_ns ) ); + } + + if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) && !$ignoreheader ) { + $parts = explode( '/', $this->mTitle->getDBkey() ); + $pageheader_base = $pageheader_ns; + while ( count( $parts ) > 0 ) { + $pageheader_base .= '-'.array_shift( $parts ); + if ( !wfEmptyMsg( $pageheader_base, wfMsgForContent( $pageheader_base ) ) ) { + $wgOut->addWikiText( wfMsgForContent( $pageheader_base ) ); + } + } + } else if ( !wfEmptyMsg( $pageheader_page, wfMsgForContent( $pageheader_page ) ) && !$ignoreheader ) { + $wgOut->addWikiText( wfMsgForContent( $pageheader_page ) ); + } $outputDone = false; wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$pcache ) ); @@ -835,7 +861,6 @@ class Article { $wgOut->addHtml( '' ); } } - $text = $this->getContent(); if ( $text === false ) { # Failed to load, replace text with error message $t = $this->mTitle->getPrefixedText(); diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 594b2f443d..3f0888d4d3 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -160,6 +160,7 @@ class MagicWord { 'index', 'noindex', 'staticredirect', + 'noheader', ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index df95fd25fa..300c52bf1c 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -221,6 +221,7 @@ $magicWords = array( 'forcetoc' => array( 0, '__FORCETOC__' ), 'toc' => array( 0, '__TOC__' ), 'noeditsection' => array( 0, '__NOEDITSECTION__' ), + 'noheader' => array( 0, '__NOHEADER__' ), 'currentmonth' => array( 1, 'CURRENTMONTH' ), 'currentmonthname' => array( 1, 'CURRENTMONTHNAME' ), 'currentmonthnamegen' => array( 1, 'CURRENTMONTHNAMEGEN' ), -- 2.20.1