From 7288e70f4774fd45ea763d3b91db041a275b1e27 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Fri, 30 Nov 2012 12:18:43 -0800 Subject: [PATCH] Refactor edit notice rendering so that it's not baked into EditPage * Move edit notice rendering to Title class * Use new getEditNotices method in EditPage This opens the door for alternative editors (such as the VisualEditor) to use the same notice systems already in use. Change-Id: Ib0e40714f5433f4d75c54a3c3d60b1590fded7f1 --- includes/EditPage.php | 26 ++------------------------ includes/Title.php | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 5ab5adc923..f80da0fff0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2194,30 +2194,8 @@ class EditPage { $wgOut->addWikiMsg( 'talkpagetext' ); } - # Optional notices on a per-namespace and per-page basis - $editnotice_ns = 'editnotice-' . $this->mTitle->getNamespace(); - $editnotice_ns_message = wfMessage( $editnotice_ns ); - if ( $editnotice_ns_message->exists() ) { - $wgOut->addWikiText( $editnotice_ns_message->plain() ); - } - if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) { - $parts = explode( '/', $this->mTitle->getDBkey() ); - $editnotice_base = $editnotice_ns; - while ( count( $parts ) > 0 ) { - $editnotice_base .= '-' . array_shift( $parts ); - $editnotice_base_msg = wfMessage( $editnotice_base ); - if ( $editnotice_base_msg->exists() ) { - $wgOut->addWikiText( $editnotice_base_msg->plain() ); - } - } - } else { - # Even if there are no subpages in namespace, we still don't want / in MW ns. - $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle->getDBkey() ); - $editnoticeMsg = wfMessage( $editnoticeText ); - if ( $editnoticeMsg->exists() ) { - $wgOut->addWikiText( $editnoticeMsg->plain() ); - } - } + // Add edit notices + $wgOut->addHTML( implode( "\n", $this->mTitle->getEditNotices() ) ); if ( $this->isConflict ) { $wgOut->wrapWikiMsg( "
\n$1\n
", 'explainconflict' ); diff --git a/includes/Title.php b/includes/Title.php index 9e42a1bb01..6cd8ee583d 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4733,4 +4733,43 @@ class Title { $pageLang = $contentHandler->getPageViewLanguage( $this ); return $pageLang; } + + /** + * Get a list of rendered edit notices for this page. + * + * Array is keyed by the original message key, and values are rendered using parseAsBlock, so + * they will already be wrapped in paragraphs. + * + * @since 1.21 + * @return Array + */ + public function getEditNotices() { + $notices = array(); + + # Optional notices on a per-namespace and per-page basis + $editnotice_ns = 'editnotice-' . $this->getNamespace(); + $editnotice_ns_message = wfMessage( $editnotice_ns ); + if ( $editnotice_ns_message->exists() ) { + $notices[$editnotice_ns] = $editnotice_ns_message->parseAsBlock(); + } + if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) { + $parts = explode( '/', $this->getDBkey() ); + $editnotice_base = $editnotice_ns; + while ( count( $parts ) > 0 ) { + $editnotice_base .= '-' . array_shift( $parts ); + $editnotice_base_msg = wfMessage( $editnotice_base ); + if ( $editnotice_base_msg->exists() ) { + $notices[$editnotice_base] = $editnotice_base_msg->parseAsBlock(); + } + } + } else { + # Even if there are no subpages in namespace, we still don't want / in MW ns. + $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() ); + $editnoticeMsg = wfMessage( $editnoticeText ); + if ( $editnoticeMsg->exists() ) { + $notices[$editnoticeText] = $editnoticeMsg->parseAsBlock(); + } + } + return $notices; + } } -- 2.20.1