Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/140975

Change subject: Allow transcluding {{special:Random}} to show a random article.
......................................................................

Allow transcluding {{special:Random}} to show a random article.

User can then make pages that show a random article using syntax
like {{Special:Random}}, {{Special:Random/User}} or even
{{Special:Random|noShowTitle=true}}.

Downside to this is it requires messing with $wgParser global.

See also Id9ce987ad which addresses some performance concerns.

Change-Id: I77cd9945aa4a84e59c33b1402cc83039e0aa0eab
---
M includes/specials/SpecialRandompage.php
1 file changed, 18 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/75/140975/1

diff --git a/includes/specials/SpecialRandompage.php 
b/includes/specials/SpecialRandompage.php
index 24b363d..cf1d2e6 100644
--- a/includes/specials/SpecialRandompage.php
+++ b/includes/specials/SpecialRandompage.php
@@ -27,7 +27,7 @@
  *
  * @ingroup SpecialPage
  */
-class RandomPage extends SpecialPage {
+class RandomPage extends IncludableSpecialPage {
        private $namespaces; // namespaces to select pages from
        protected $isRedir = false; // should the result be a redirect?
        protected $extra = array(); // Extra SQL statements
@@ -54,7 +54,7 @@
        }
 
        public function execute( $par ) {
-               global $wgContLang;
+               global $wgContLang, $wgParser;
 
                if ( $par ) {
                        $this->setNamespace( $wgContLang->getNsIndex( $par ) );
@@ -71,10 +71,22 @@
                        return;
                }
 
-               $redirectParam = $this->isRedirect() ? array( 'redirect' => 
'no' ) : array();
-               $query = array_merge( $this->getRequest()->getValues(), 
$redirectParam );
-               unset( $query['title'] );
-               $this->getOutput()->redirect( $title->getFullURL( $query ) );
+               if ( $this->including() ) {
+                       // eww icky globals
+                       $oldParser = $wgParser;
+                       $wgParser = new Parser;
+                       $text = '{{:' . $title->getPrefixedDBKey() . '}}';
+                       if ( !$this->getRequest()->getBool( 'noShowTitle', 
false ) ) {
+                               $text = '=' . wfEscapeWikiText( 
$title->getPrefixedText() ) . "=\n" . $text;
+                       }
+                       $this->getOutput()->addWikiTextTitleTidy( $text, 
$oldParser->getTitle(), false );
+                       $wgParser = $oldParser;
+               } else {
+                       $redirectParam = $this->isRedirect() ? array( 
'redirect' => 'no' ) : array();
+                       $query = array_merge( $this->getRequest()->getValues(), 
$redirectParam );
+                       unset( $query['title'] );
+                       $this->getOutput()->redirect( $title->getFullURL( 
$query ) );
+               }
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/140975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77cd9945aa4a84e59c33b1402cc83039e0aa0eab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to