Index: trunk/phase3/includes/specials/SpecialUndelete.php |
— | — | @@ -1,24 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Special page allowing users with the appropriate permissions to view |
6 | | - * and restore deleted content |
7 | | - * |
8 | | - * @file |
9 | | - * @ingroup SpecialPage |
10 | | - */ |
11 | | - |
12 | | -/** |
13 | | - * Constructor |
14 | | - */ |
15 | | -function wfSpecialUndelete( $par ) { |
16 | | - global $wgRequest; |
17 | | - |
18 | | - $form = new UndeleteForm( $wgRequest, $par ); |
19 | | - $form->execute(); |
20 | | -} |
21 | | - |
22 | | -/** |
23 | 5 | * Used to show archived pages and eventually restore them. |
24 | 6 | * @ingroup SpecialPage |
25 | 7 | */ |
— | — | @@ -28,7 +10,7 @@ |
29 | 11 | |
30 | 12 | function __construct( $title ) { |
31 | 13 | if( is_null( $title ) ) { |
32 | | - throw new MWException( 'Archiver() given a null title.'); |
| 14 | + throw new MWException( __METHOD__ . ' given a null title.' ); |
33 | 15 | } |
34 | 16 | $this->title = $title; |
35 | 17 | } |
— | — | @@ -286,7 +268,7 @@ |
287 | 269 | array( 'ar_text', 'ar_flags', 'ar_text_id' ), |
288 | 270 | array( 'ar_namespace' => $this->title->getNamespace(), |
289 | 271 | 'ar_title' => $this->title->getDBkey() ), |
290 | | - 'PageArchive::getLastRevisionText', |
| 272 | + __METHOD__, |
291 | 273 | array( 'ORDER BY' => 'ar_timestamp DESC' ) ); |
292 | 274 | if( $row ) { |
293 | 275 | return $this->getTextFromRow( $row ); |
— | — | @@ -496,12 +478,12 @@ |
497 | 479 | } |
498 | 480 | // Insert one revision at a time...maintaining deletion status |
499 | 481 | // unless we are specifically removing all restrictions... |
500 | | - $revision = Revision::newFromArchiveRow( $row, |
501 | | - array( |
502 | | - 'page' => $pageId, |
| 482 | + $revision = Revision::newFromArchiveRow( $row, |
| 483 | + array( |
| 484 | + 'page' => $pageId, |
503 | 485 | 'deleted' => $unsuppress ? 0 : $row->ar_deleted |
504 | 486 | ) ); |
505 | | - |
| 487 | + |
506 | 488 | $revision->insertOn( $dbw ); |
507 | 489 | $restored++; |
508 | 490 | |
— | — | @@ -514,7 +496,7 @@ |
515 | 497 | 'ar_title' => $this->title->getDBkey(), |
516 | 498 | $oldones ), |
517 | 499 | __METHOD__ ); |
518 | | - |
| 500 | + |
519 | 501 | // Was anything restored at all? |
520 | 502 | if( $restored == 0 ) |
521 | 503 | return 0; |
— | — | @@ -551,36 +533,45 @@ |
552 | 534 | } |
553 | 535 | |
554 | 536 | /** |
555 | | - * The HTML form for Special:Undelete, which allows users with the appropriate |
556 | | - * permissions to view and restore deleted content. |
| 537 | + * Special page allowing users with the appropriate permissions to view |
| 538 | + * and restore deleted content. |
| 539 | + * |
557 | 540 | * @ingroup SpecialPage |
558 | 541 | */ |
559 | | -class UndeleteForm { |
| 542 | +class UndeleteForm extends SpecialPage { |
560 | 543 | var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj; |
561 | | - var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken; |
| 544 | + var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken, $mRequest; |
562 | 545 | |
563 | | - function UndeleteForm( $request, $par = "" ) { |
| 546 | + function __construct( $request = null ) { |
| 547 | + parent::__construct( 'Undelete', 'deletedhistory' ); |
| 548 | + |
| 549 | + if ( $request === null ) { |
| 550 | + global $wgRequest; |
| 551 | + $this->mRequest = $wgRequest; |
| 552 | + } else { |
| 553 | + $this->mRequest = $request; |
| 554 | + } |
| 555 | + } |
| 556 | + |
| 557 | + function loadRequest() { |
564 | 558 | global $wgUser; |
565 | | - $this->mAction = $request->getVal( 'action' ); |
566 | | - $this->mTarget = $request->getVal( 'target' ); |
567 | | - $this->mSearchPrefix = $request->getText( 'prefix' ); |
568 | | - $time = $request->getVal( 'timestamp' ); |
| 559 | + $this->mAction = $this->mRequest->getVal( 'action' ); |
| 560 | + $this->mTarget = $this->mRequest->getVal( 'target' ); |
| 561 | + $this->mSearchPrefix = $this->mRequest->getText( 'prefix' ); |
| 562 | + $time = $this->mRequest->getVal( 'timestamp' ); |
569 | 563 | $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : ''; |
570 | | - $this->mFile = $request->getVal( 'file' ); |
| 564 | + $this->mFile = $this->mRequest->getVal( 'file' ); |
571 | 565 | |
572 | | - $posted = $request->wasPosted() && |
573 | | - $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ); |
574 | | - $this->mRestore = $request->getCheck( 'restore' ) && $posted; |
575 | | - $this->mInvert = $request->getCheck( 'invert' ) && $posted; |
576 | | - $this->mPreview = $request->getCheck( 'preview' ) && $posted; |
577 | | - $this->mDiff = $request->getCheck( 'diff' ); |
578 | | - $this->mComment = $request->getText( 'wpComment' ); |
579 | | - $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); |
580 | | - $this->mToken = $request->getVal( 'token' ); |
| 566 | + $posted = $this->mRequest->wasPosted() && |
| 567 | + $wgUser->matchEditToken( $this->mRequest->getVal( 'wpEditToken' ) ); |
| 568 | + $this->mRestore = $this->mRequest->getCheck( 'restore' ) && $posted; |
| 569 | + $this->mInvert = $this->mRequest->getCheck( 'invert' ) && $posted; |
| 570 | + $this->mPreview = $this->mRequest->getCheck( 'preview' ) && $posted; |
| 571 | + $this->mDiff = $this->mRequest->getCheck( 'diff' ); |
| 572 | + $this->mComment = $this->mRequest->getText( 'wpComment' ); |
| 573 | + $this->mUnsuppress = $this->mRequest->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); |
| 574 | + $this->mToken = $this->mRequest->getVal( 'token' ); |
581 | 575 | |
582 | | - if( $par != "" ) { |
583 | | - $this->mTarget = $par; |
584 | | - } |
585 | 576 | if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) { |
586 | 577 | $this->mAllowed = true; // user can restore |
587 | 578 | $this->mCanView = true; // user can view content |
— | — | @@ -593,11 +584,7 @@ |
594 | 585 | $this->mTimestamp = ''; |
595 | 586 | $this->mRestore = false; |
596 | 587 | } |
597 | | - if ( $this->mTarget !== "" ) { |
598 | | - $this->mTargetObj = Title::newFromURL( $this->mTarget ); |
599 | | - } else { |
600 | | - $this->mTargetObj = null; |
601 | | - } |
| 588 | + |
602 | 589 | if( $this->mRestore || $this->mInvert ) { |
603 | 590 | $timestamps = array(); |
604 | 591 | $this->mFileVersions = array(); |
— | — | @@ -616,14 +603,33 @@ |
617 | 604 | } |
618 | 605 | } |
619 | 606 | |
620 | | - function execute() { |
| 607 | + function execute( $par ) { |
621 | 608 | global $wgOut, $wgUser; |
| 609 | + |
| 610 | + $this->setHeaders(); |
| 611 | + if ( !$this->userCanExecute( $wgUser ) ) { |
| 612 | + $this->displayRestrictionError(); |
| 613 | + return; |
| 614 | + } |
| 615 | + $this->outputHeader(); |
| 616 | + |
| 617 | + $this->loadRequest(); |
| 618 | + |
622 | 619 | if ( $this->mAllowed ) { |
623 | 620 | $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); |
624 | 621 | } else { |
625 | 622 | $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) ); |
626 | 623 | } |
627 | 624 | |
| 625 | + if( $par != '' ) { |
| 626 | + $this->mTarget = $par; |
| 627 | + } |
| 628 | + if ( $this->mTarget !== '' ) { |
| 629 | + $this->mTargetObj = Title::newFromURL( $this->mTarget ); |
| 630 | + } else { |
| 631 | + $this->mTargetObj = null; |
| 632 | + } |
| 633 | + |
628 | 634 | if( is_null( $this->mTargetObj ) ) { |
629 | 635 | # Not all users can just browse every deleted page from the list |
630 | 636 | if( $wgUser->isAllowed( 'browsearchive' ) ) { |
— | — | @@ -686,7 +692,7 @@ |
687 | 693 | 'action' => $wgScript ) ) . |
688 | 694 | Xml::fieldset( wfMsg( 'undelete-search-box' ) ) . |
689 | 695 | Xml::hidden( 'title', |
690 | | - SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) . |
| 696 | + $this->getTitle()->getPrefixedDbKey() ) . |
691 | 697 | Xml::inputLabel( wfMsg( 'undelete-search-prefix' ), |
692 | 698 | 'prefix', 'prefix', 20, |
693 | 699 | $this->mSearchPrefix ) . ' ' . |
— | — | @@ -708,7 +714,7 @@ |
709 | 715 | $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) ); |
710 | 716 | |
711 | 717 | $sk = $wgUser->getSkin(); |
712 | | - $undelete = SpecialPage::getTitleFor( 'Undelete' ); |
| 718 | + $undelete = $this->getTitle(); |
713 | 719 | $wgOut->addHTML( "<ul>\n" ); |
714 | 720 | while( $row = $result->fetchObject() ) { |
715 | 721 | $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title ); |
— | — | @@ -731,7 +737,7 @@ |
732 | 738 | |
733 | 739 | private function showRevision( $timestamp ) { |
734 | 740 | global $wgLang, $wgUser, $wgOut; |
735 | | - $self = SpecialPage::getTitleFor( 'Undelete' ); |
| 741 | + |
736 | 742 | $skin = $wgUser->getSkin(); |
737 | 743 | |
738 | 744 | if(!preg_match("/[0-9]{14}/",$timestamp)) return 0; |
— | — | @@ -758,7 +764,7 @@ |
759 | 765 | $wgOut->setPageTitle( wfMsg( 'undeletepage' ) ); |
760 | 766 | |
761 | 767 | $link = $skin->linkKnown( |
762 | | - SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ), |
| 768 | + $this->getTitle( $this->mTargetObj->getPrefixedDBkey() ), |
763 | 769 | htmlspecialchars( $this->mTargetObj->getPrefixedText() ) |
764 | 770 | ); |
765 | 771 | |
— | — | @@ -829,7 +835,7 @@ |
830 | 836 | Xml::openElement( 'div' ) . |
831 | 837 | Xml::openElement( 'form', array( |
832 | 838 | 'method' => 'post', |
833 | | - 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) . |
| 839 | + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ) ) ) . |
834 | 840 | Xml::element( 'input', array( |
835 | 841 | 'type' => 'hidden', |
836 | 842 | 'name' => 'target', |
— | — | @@ -895,7 +901,7 @@ |
896 | 902 | $isDeleted = !( $rev->getId() && $rev->getTitle() ); |
897 | 903 | if( $isDeleted ) { |
898 | 904 | /// @todo Fixme: $rev->getTitle() is null for deleted revs...? |
899 | | - $targetPage = SpecialPage::getTitleFor( 'Undelete' ); |
| 905 | + $targetPage = $this->getTitle(); |
900 | 906 | $targetQuery = array( |
901 | 907 | 'target' => $this->mTargetObj->getPrefixedText(), |
902 | 908 | 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() ) |
— | — | @@ -912,7 +918,7 @@ |
913 | 919 | if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) { |
914 | 920 | $del .= $sk->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops |
915 | 921 | } else { |
916 | | - $query = array( |
| 922 | + $query = array( |
917 | 923 | 'type' => 'archive', |
918 | 924 | 'target' => $this->mTargetObj->getPrefixedDbkey(), |
919 | 925 | 'ids' => $rev->getTimestamp() |
— | — | @@ -955,10 +961,10 @@ |
956 | 962 | $this->mTargetObj->getText(), |
957 | 963 | $wgLang->date( $file->getTimestamp() ), |
958 | 964 | $wgLang->time( $file->getTimestamp() ) ); |
959 | | - $wgOut->addHTML( |
960 | | - Xml::openElement( 'form', array( |
| 965 | + $wgOut->addHTML( |
| 966 | + Xml::openElement( 'form', array( |
961 | 967 | 'method' => 'POST', |
962 | | - 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl( |
| 968 | + 'action' => $this->getTitle()->getLocalUrl( |
963 | 969 | 'target=' . urlencode( $this->mTarget ) . |
964 | 970 | '&file=' . urlencode( $key ) . |
965 | 971 | '&token=' . urlencode( $wgUser->editToken( $key ) ) ) |
— | — | @@ -986,7 +992,7 @@ |
987 | 993 | |
988 | 994 | global $IP; |
989 | 995 | require_once( "$IP/includes/StreamFile.php" ); |
990 | | - $repo = RepoGroup::singleton()->getLocalRepo(); |
| 996 | + $repo = RepoGroup::singleton()->getLocalRepo(); |
991 | 997 | $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key; |
992 | 998 | wfStreamFile( $path ); |
993 | 999 | } |
— | — | @@ -1048,8 +1054,7 @@ |
1049 | 1055 | } |
1050 | 1056 | |
1051 | 1057 | if ( $this->mAllowed ) { |
1052 | | - $titleObj = SpecialPage::getTitleFor( "Undelete" ); |
1053 | | - $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) ); |
| 1058 | + $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ); |
1054 | 1059 | # Start the form here |
1055 | 1060 | $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) ); |
1056 | 1061 | $wgOut->addHTML( $top ); |
— | — | @@ -1153,7 +1158,7 @@ |
1154 | 1159 | private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) { |
1155 | 1160 | global $wgUser, $wgLang; |
1156 | 1161 | |
1157 | | - $rev = Revision::newFromArchiveRow( $row, |
| 1162 | + $rev = Revision::newFromArchiveRow( $row, |
1158 | 1163 | array( 'page' => $this->mTargetObj->getArticleId() ) ); |
1159 | 1164 | $stxt = ''; |
1160 | 1165 | $ts = wfTimestamp( TS_MW, $row->ar_timestamp ); |
— | — | @@ -1173,7 +1178,7 @@ |
1174 | 1179 | } |
1175 | 1180 | // Build page & diff links... |
1176 | 1181 | if( $this->mCanView ) { |
1177 | | - $titleObj = SpecialPage::getTitleFor( "Undelete" ); |
| 1182 | + $titleObj = $this->getTitle(); |
1178 | 1183 | # Last link |
1179 | 1184 | if( !$rev->userCan( Revision::DELETED_TEXT ) ) { |
1180 | 1185 | $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) ); |
— | — | @@ -1236,13 +1241,12 @@ |
1237 | 1242 | $checkBox = Xml::check( "fileid" . $row->fa_id ); |
1238 | 1243 | $key = urlencode( $row->fa_storage_key ); |
1239 | 1244 | $target = urlencode( $this->mTarget ); |
1240 | | - $titleObj = SpecialPage::getTitleFor( "Undelete" ); |
1241 | | - $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk ); |
| 1245 | + $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key, $sk ); |
1242 | 1246 | } else { |
1243 | 1247 | $checkBox = ''; |
1244 | 1248 | $pageLink = $wgLang->timeanddate( $ts, true ); |
1245 | 1249 | } |
1246 | | - $userLink = $this->getFileUser( $file, $sk ); |
| 1250 | + $userLink = $this->getFileUser( $file, $sk ); |
1247 | 1251 | $data = |
1248 | 1252 | wfMsg( 'widthheight', |
1249 | 1253 | $wgLang->formatNum( $row->fa_width ), |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -171,7 +171,7 @@ |
172 | 172 | # Page tools |
173 | 173 | 'Export' => 'SpecialExport', |
174 | 174 | 'Import' => 'SpecialImport', |
175 | | - 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ), |
| 175 | + 'Undelete' => 'UndeleteForm', |
176 | 176 | 'Whatlinkshere' => 'SpecialWhatlinkshere', |
177 | 177 | 'MergeHistory' => 'SpecialMergeHistory', |
178 | 178 | |