* Add ot=raw to Special:Allmessages
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 11 Nov 2007 14:52:31 +0000 (14:52 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sun, 11 Nov 2007 14:52:31 +0000 (14:52 +0000)
* Handle invalid titles correctly in Special:Randomincategory

RELEASE-NOTES
includes/SpecialAllmessages.php
includes/SpecialRandomincategory.php

index 089e798..e93411e 100644 (file)
@@ -59,6 +59,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   and Special:Mytalk
 * Add special page for getting random page from category
 * Add link on Special:Randomincategory to sidebar
+* Add ot=raw to Special:Allmessages
 
 === Bug fixes in 1.12 ===
 
index 4ba01e2..d8b6acc 100644 (file)
@@ -45,9 +45,12 @@ function wfSpecialAllmessages() {
        wfProfileIn( __METHOD__ . '-output' );
        if ( $ot == 'php' ) {
                $navText .= makePhp( $messages );
-               $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
+               $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a> | <a href="' . $wgTitle->escapeLocalUrl( 'ot=raw' ) . '">Raw</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
+       } else if ( $ot == 'raw' ) {
+               $wgOut->disable();
+               echo makeRaw( $messages );
        } else {
-               $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML' );
+               $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML |  <a href="' . $wgTitle->escapeLocalUrl( 'ot=raw' ) . '">Raw</a>' );
                $wgOut->addWikiText( $navText );
                $wgOut->addHTML( makeHTMLText( $messages ) );
        }
@@ -56,6 +59,18 @@ function wfSpecialAllmessages() {
        wfProfileOut( __METHOD__ );
 }
 
+function makeRaw( $messages ) {
+       global $wgLang;
+       $lang = $wgLang->getCode();
+       $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
+       $txt .= "<messages lang=\"$lang\">\n";
+       foreach( $messages as $key => $m ) {
+               $txt .= "\t<message name=\"$key\">" . htmlspecialchars( "{$m['msg']}" ) . "</message>\n";
+       }
+       $txt .= "</messages>";
+       return $txt;
+}
+
 /**
  * Create the messages array, formatted in PHP to copy to language files.
  * @param $messages Messages array.
index ba5ebe3..2461ef3 100644 (file)
@@ -26,7 +26,10 @@ function wfSpecialRandomincategory( $par = null ) {
        }
 
        $rnd = new RandomPageInCategory();
-       $rnd->setCategory( $par );
+       if( !$rnd->setCategory( $par ) ) {
+               $wgOut->addHTML( RandomPageInCategory::getForm( $par ) );
+               return;
+       }
 
        $title = $rnd->getRandomTitle();
 
@@ -54,7 +57,12 @@ class RandomPageInCategory {
        }
        public function setCategory ( $cat ) {
                $category = Title::makeTitleSafe( NS_CATEGORY, $cat );
+               //Invalid title
+               if( !$category ) {
+                       return false;
+               }
                $this->category = $category->getDBKey();
+               return false;
        }
 
        /**