Index: branches/pageoutput/includes/SpecialPageFactory.php |
— | — | @@ -435,6 +435,7 @@ |
436 | 436 | |
437 | 437 | // Page exists, set the context |
438 | 438 | $page->setContext( $context ); |
| 439 | + $page->mParameter = $par; // FormSpecialPage uses setParameter for a separate purpose so we can't use that here |
439 | 440 | |
440 | 441 | if ( !$including ) { |
441 | 442 | // Redirect to canonical alias for GET commands |
Index: branches/pageoutput/includes/specials/SpecialHistory.php |
— | — | @@ -26,22 +26,17 @@ |
27 | 27 | * |
28 | 28 | * @ingroup SpecialPage |
29 | 29 | */ |
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? |
31 | 31 | |
32 | 32 | function __construct() { |
33 | 33 | parent::__construct( 'History' ); |
34 | 34 | } |
35 | 35 | |
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(); |
46 | 41 | } |
47 | 42 | |
48 | 43 | } |
Index: branches/pageoutput/includes/SpecialPage.php |
— | — | @@ -23,6 +23,15 @@ |
24 | 24 | */ |
25 | 25 | |
26 | 26 | /** |
| 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 | +/** |
27 | 36 | * Parent special page class, also static functions for handling the special |
28 | 37 | * page list. |
29 | 38 | * @ingroup SpecialPage |
— | — | @@ -33,6 +42,15 @@ |
34 | 43 | // Also used for the default <h1> heading, @see getDescription() |
35 | 44 | protected $mName; |
36 | 45 | |
| 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 | + |
37 | 55 | // The local name of this special page |
38 | 56 | private $mLocalName; |
39 | 57 | |
— | — | @@ -530,19 +548,35 @@ |
531 | 549 | $this->setHeaders(); |
532 | 550 | |
533 | 551 | 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 ); |
538 | 566 | } |
539 | | - $this->outputHeader(); |
540 | | - call_user_func( $func, $par, $this ); |
541 | 567 | } else { |
542 | 568 | $this->displayRestrictionError(); |
543 | 569 | } |
544 | 570 | } |
545 | 571 | |
546 | 572 | /** |
| 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 | + /** |
547 | 581 | * Outputs a summary message on top of special pages |
548 | 582 | * Per default the message key is the canonical name of the special page |
549 | 583 | * May be overriden, i.e. by extensions to stick with the naming conventions |
— | — | @@ -590,6 +624,39 @@ |
591 | 625 | } |
592 | 626 | |
593 | 627 | /** |
| 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 | + /** |
594 | 661 | * Sets the context this SpecialPage is executed in |
595 | 662 | * |
596 | 663 | * @param $context IContextSource |