Merge "Revert "Adding ability of jQuery badge to display the number zero if requested.""
[lhc/web/wiklou.git] / includes / Title.php
index 00fdc3a..896218b 100644 (file)
@@ -675,6 +675,7 @@ class Title {
        /**
         * Get the page's content model id, see the CONTENT_MODEL_XXX constants.
         *
+        * @throws MWException
         * @return String: Content model id
         */
        public function getContentModel() {
@@ -908,7 +909,7 @@ class Title {
 
        /**
         * Is this the mainpage?
-        * @note Title::newFromText seams to be sufficiently optimized by the title
+        * @note Title::newFromText seems to be sufficiently optimized by the title
         * cache that we don't need to over-optimize by doing direct comparisons and
         * acidentally creating new bugs where $title->equals( Title::newFromText() )
         * ends up reporting something differently than $title->isMainPage();
@@ -2972,6 +2973,7 @@ class Title {
         * What is the page_latest field for this page?
         *
         * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
+        * @throws MWException
         * @return Int or 0 if the page doesn't exist
         */
        public function getLatestRevID( $flags = 0 ) {
@@ -3695,8 +3697,8 @@ class Title {
                }
 
                # Update watchlists
-               $oldnamespace = $this->getNamespace() & ~1;
-               $newnamespace = $nt->getNamespace() & ~1;
+               $oldnamespace = MWNamespace::getSubject( $this->getNamespace() );
+               $newnamespace = MWNamespace::getSubject( $nt->getNamespace() );
                $oldtitle = $this->getDBkey();
                $newtitle = $nt->getDBkey();
 
@@ -3816,6 +3818,7 @@ class Title {
                        $newid = $redirectArticle->insertOn( $dbw );
                        if ( $newid ) { // sanity
                                $redirectRevision = new Revision( array(
+                                       'title'   => $this, // for determining the default content model
                                        'page'    => $newid,
                                        'comment' => $comment,
                                        'content'    => $redirectContent ) );
@@ -3980,7 +3983,7 @@ class Title {
                $content = $rev->getContent();
                # Does the redirect point to the source?
                # Or is it a broken self-redirect, usually caused by namespace collisions?
-               $redirTitle = $content->getRedirectTarget();
+               $redirTitle = $content ? $content->getRedirectTarget() : null;
 
                if ( $redirTitle ) {
                        if ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
@@ -4701,8 +4704,6 @@ class Title {
                $contentHandler = ContentHandler::getForTitle( $this );
                $pageLang = $contentHandler->getPageLanguage( $this );
 
-               // Hook at the end because we don't want to override the above stuff
-               wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) );
                return wfGetLangObj( $pageLang );
        }
 
@@ -4734,4 +4735,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;
+       }
 }