Refactor edit notice rendering so that it's not baked into EditPage
authorTrevor Parscal <tparscal@wikimedia.org>
Fri, 30 Nov 2012 20:18:43 +0000 (12:18 -0800)
committerTrevor Parscal <tparscal@wikimedia.org>
Fri, 30 Nov 2012 20:18:43 +0000 (12:18 -0800)
* 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
includes/Title.php

index 5ab5adc..f80da0f 100644 (file)
@@ -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( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
index 9e42a1b..6cd8ee5 100644 (file)
@@ -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;
+       }
 }