r98683 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98682‎ | r98683 | r98684 >
Date:16:15, 2 October 2011
Author:dantman
Status:deferred
Tags:
Comment:
Implement getParameter and targetable special pages.
Modified paths:
  • /branches/pageoutput/includes/SpecialPage.php (modified) (history)
  • /branches/pageoutput/includes/SpecialPageFactory.php (modified) (history)
  • /branches/pageoutput/includes/specials/SpecialHistory.php (modified) (history)

Diff [purge]

Index: branches/pageoutput/includes/SpecialPageFactory.php
@@ -435,6 +435,7 @@
436436
437437 // Page exists, set the context
438438 $page->setContext( $context );
 439+ $page->mParameter = $par; // FormSpecialPage uses setParameter for a separate purpose so we can't use that here
439440
440441 if ( !$including ) {
441442 // Redirect to canonical alias for GET commands
Index: branches/pageoutput/includes/specials/SpecialHistory.php
@@ -26,22 +26,17 @@
2727 *
2828 * @ingroup SpecialPage
2929 */
30 -class SpecialHistory extends UnlistedSpecialPage { // XXX: Should this be listed or unlisted?
 30+class SpecialHistory extends UnlistedSpecialPage implements SpecialTitleTarget { // XXX: Should this be listed or unlisted?
3131
3232 function __construct() {
3333 parent::__construct( 'History' );
3434 }
3535
36 - function execute( $par ) {
37 - $title = Title::newFromText( $par );
38 - if ( $title ) {
39 - $context = new DerivativeContext( $this->getContext() );
40 - $context->setTitle( $title );
41 - $history = new HistoryPage( $context );
42 - $history->history();
43 - }
44 -
45 -
 36+ function executeWithTarget() {
 37+ $context = new DerivativeContext( $this->getContext() );
 38+ $context->setTitle( $this->target() );
 39+ $history = new HistoryPage( $context );
 40+ $history->history();
4641 }
4742
4843 }
Index: branches/pageoutput/includes/SpecialPage.php
@@ -23,6 +23,15 @@
2424 */
2525
2626 /**
 27+ * interface hints for the return type for target();
 28+ */
 29+interface SpecialTargeted {
 30+ public function executeWithTarget();
 31+}
 32+interface SpecialTitleTarget extends SpecialTargeted { public function target(); }
 33+interface SpecialUserTarget extends SpecialTargeted { public function target(); }
 34+
 35+/**
2736 * Parent special page class, also static functions for handling the special
2837 * page list.
2938 * @ingroup SpecialPage
@@ -33,6 +42,15 @@
3443 // Also used for the default <h1> heading, @see getDescription()
3544 protected $mName;
3645
 46+ // The $par parameter text after the /
 47+ // @hack This is not protected because it's set from SpecialPageFactory and
 48+ // we can't have a setParameter method do this because FormSpecialPage
 49+ // already abused that for a different purpose.
 50+ var $mParameter;
 51+
 52+ // The special page's primary target if any
 53+ private $mTargetParameter;
 54+
3755 // The local name of this special page
3856 private $mLocalName;
3957
@@ -530,19 +548,35 @@
531549 $this->setHeaders();
532550
533551 if ( $this->userCanExecute( $this->getUser() ) ) {
534 - $func = $this->mFunction;
535 - // only load file if the function does not exist
536 - if( !is_callable($func) && $this->mFile ) {
537 - require_once( $this->mFile );
 552+ if ( $this instanceof SpecialTargeted ) {
 553+ if ( $this->target() ) {
 554+ $this->executeWithTarget();
 555+ } else {
 556+ $this->executeWithoutTarget();
 557+ }
 558+ } else {
 559+ $func = $this->mFunction;
 560+ // only load file if the function does not exist
 561+ if( !is_callable($func) && $this->mFile ) {
 562+ require_once( $this->mFile );
 563+ }
 564+ $this->outputHeader();
 565+ call_user_func( $func, $par, $this );
538566 }
539 - $this->outputHeader();
540 - call_user_func( $func, $par, $this );
541567 } else {
542568 $this->displayRestrictionError();
543569 }
544570 }
545571
546572 /**
 573+ * Executed for a targeted special page when there is no target.
 574+ * By default outputs a form that can take a target as input.
 575+ */
 576+ function executeWithoutTarget() {
 577+ // @todo
 578+ }
 579+
 580+ /**
547581 * Outputs a summary message on top of special pages
548582 * Per default the message key is the canonical name of the special page
549583 * May be overriden, i.e. by extensions to stick with the naming conventions
@@ -590,6 +624,39 @@
591625 }
592626
593627 /**
 628+ * Get the text from the special page title passed after the /
 629+ * @return String
 630+ */
 631+ function getParameter() {
 632+ return $this->mParameter;
 633+ }
 634+
 635+ /**
 636+ * Get the target.
 637+ * This may be from the parameter or from the target in the request
 638+ * @note This cannot be getTarget because SpecialEmailUser has a static with that name
 639+ */
 640+ public function target() {
 641+ if ( is_null( $this->mTargetParameter ) ) {
 642+ $par = $this->getParameter();
 643+ if ( !is_null( $par ) ) {
 644+ return $par;
 645+ }
 646+ $target = $this->getRequest()->getVal( 'target', null );
 647+
 648+ if ( $this instanceof SpecialTitleTarget ) {
 649+ $target = Title::newFromURL( $target );
 650+ } elseif ( $this instanceof SpecialUserTarget ) {
 651+ $target = User::newFromName( $target );
 652+ }
 653+
 654+ $this->mTargetParameter = $target;
 655+ }
 656+
 657+ return $this->mTargetParameter;
 658+ }
 659+
 660+ /**
594661 * Sets the context this SpecialPage is executed in
595662 *
596663 * @param $context IContextSource

Status & tagging log