From 66dc87919476afd9dd52f0eb729a9c4d0a8d3ca1 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 18 Mar 2010 16:41:53 +0000 Subject: [PATCH] Refactor MergeHistory to subclass SpecialPage. Ohai unloved code :) --- includes/AutoLoader.php | 1 + includes/SpecialPage.php | 2 +- includes/specials/SpecialMergeHistory.php | 43 +++++++++-------------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 4f5a9c1852..01b0d9383f 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -560,6 +560,7 @@ $wgAutoloadLocalClasses = array( 'SpecialExport' => 'includes/specials/SpecialExport.php', 'SpecialImport' => 'includes/specials/SpecialImport.php', 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', + 'SpecialMergeHistory' => 'includes/specials/SpecialMergeHistory.php', 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php', 'SpecialPreferences' => 'includes/specials/SpecialPreferences.php', 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 670d43964c..91764441e8 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -168,7 +168,7 @@ class SpecialPage { 'Import' => 'SpecialImport', 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ), 'Whatlinkshere' => 'SpecialWhatlinkshere', - 'MergeHistory' => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ), + 'MergeHistory' => 'SpecialMergeHistory', # Other 'Booksources' => 'SpecialBookSources', diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 1b4ef30c6a..e2ed38c3e4 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -3,32 +3,18 @@ * Special page allowing users with the appropriate permissions to * merge article histories, with some restrictions * - * @file * @ingroup SpecialPage */ - -/** - * Constructor - */ -function wfSpecialMergehistory( $par ) { - global $wgRequest; - - $form = new MergehistoryForm( $wgRequest, $par ); - $form->execute(); -} - -/** - * The HTML form for Special:MergeHistory, which allows users with the appropriate - * permissions to view and restore deleted content. - * @ingroup SpecialPage - */ -class MergehistoryForm { +class SpecialMergeHistory extends SpecialPage { var $mAction, $mTarget, $mDest, $mTimestamp, $mTargetID, $mDestID, $mComment; var $mTargetObj, $mDestObj; - function MergehistoryForm( $request, $par = "" ) { - global $wgUser; + public function __construct() { + parent::__construct( 'MergeHistory', 'mergehistory' ); + } + private function loadRequestParams( $request ) { + global $wgUser; $this->mAction = $request->getVal( 'action' ); $this->mTarget = $request->getVal( 'target' ); $this->mDest = $request->getVal( 'dest' ); @@ -51,7 +37,6 @@ class MergehistoryForm { $this->mTargetObj = null; $this->mDestObj = null; } - $this->preCacheMessages(); } @@ -66,8 +51,15 @@ class MergehistoryForm { } } - function execute() { - global $wgOut; + function execute( $par = '' ) { + global $wgOut, $wgRequest, $wgUser; + + if( !$wgUser->isAllowed( 'mergehistory' ) ) { + $wgOut->permissionRequired( 'mergehistory' ); + return; + } + + $this->loadRequestParams( $wgRequest ); $wgOut->setPagetitle( wfMsgHtml( "mergehistory" ) ); @@ -122,8 +114,7 @@ class MergehistoryForm { '
' . Xml::element( 'legend', array(), wfMsg( 'mergehistory-box' ) ) . - Xml::hidden( 'title', - SpecialPage::getTitleFor( 'Mergehistory' )->getPrefixedDbKey() ) . + Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . Xml::hidden( 'submitted', '1' ) . Xml::hidden( 'mergepoint', $this->mTimestamp ) . Xml::openElement( 'table' ) . @@ -154,7 +145,7 @@ class MergehistoryForm { $revisions = new MergeHistoryPager( $this, array(), $this->mTargetObj, $this->mDestObj ); $haveRevisions = $revisions && $revisions->getNumRows() > 0; - $titleObj = SpecialPage::getTitleFor( "Mergehistory" ); + $titleObj = $this->getTitle(); $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) ); # Start the form here $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'merge' ) ); -- 2.20.1