r92354 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92353‎ | r92354 | r92355 >
Date:13:36, 16 July 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use local context instead of global variables
* Call Linker methods statically
* Changed some messages to replace parameters before parsing where possible
* Changed usage of OutputPage::addWikiMsgArray() with third parameter to wfMessage()
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -574,47 +574,42 @@
575575 */
576576 class SpecialUndelete extends SpecialPage {
577577 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mFilename;
578 - var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken, $mRequest;
 578+ var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken;
579579
580580 /**
581581 * @var Title
582582 */
583583 var $mTargetObj;
584584
585 - function __construct( $request = null ) {
 585+ function __construct() {
586586 parent::__construct( 'Undelete', 'deletedhistory' );
587 -
588 - if ( $request === null ) {
589 - global $wgRequest;
590 - $this->mRequest = $wgRequest;
591 - } else {
592 - $this->mRequest = $request;
593 - }
594587 }
595588
596589 function loadRequest() {
597 - global $wgUser;
598 - $this->mAction = $this->mRequest->getVal( 'action' );
599 - $this->mTarget = $this->mRequest->getVal( 'target' );
600 - $this->mSearchPrefix = $this->mRequest->getText( 'prefix' );
601 - $time = $this->mRequest->getVal( 'timestamp' );
 590+ $request = $this->getRequest();
 591+ $user = $this->getUser();
 592+
 593+ $this->mAction = $request->getVal( 'action' );
 594+ $this->mTarget = $request->getVal( 'target' );
 595+ $this->mSearchPrefix = $request->getText( 'prefix' );
 596+ $time = $request->getVal( 'timestamp' );
602597 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
603 - $this->mFilename = $this->mRequest->getVal( 'file' );
 598+ $this->mFilename = $request->getVal( 'file' );
604599
605 - $posted = $this->mRequest->wasPosted() &&
606 - $wgUser->matchEditToken( $this->mRequest->getVal( 'wpEditToken' ) );
607 - $this->mRestore = $this->mRequest->getCheck( 'restore' ) && $posted;
608 - $this->mInvert = $this->mRequest->getCheck( 'invert' ) && $posted;
609 - $this->mPreview = $this->mRequest->getCheck( 'preview' ) && $posted;
610 - $this->mDiff = $this->mRequest->getCheck( 'diff' );
611 - $this->mComment = $this->mRequest->getText( 'wpComment' );
612 - $this->mUnsuppress = $this->mRequest->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
613 - $this->mToken = $this->mRequest->getVal( 'token' );
 600+ $posted = $request->wasPosted() &&
 601+ $user->matchEditToken( $request->getVal( 'wpEditToken' ) );
 602+ $this->mRestore = $request->getCheck( 'restore' ) && $posted;
 603+ $this->mInvert = $request->getCheck( 'invert' ) && $posted;
 604+ $this->mPreview = $request->getCheck( 'preview' ) && $posted;
 605+ $this->mDiff = $request->getCheck( 'diff' );
 606+ $this->mComment = $request->getText( 'wpComment' );
 607+ $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $user->isAllowed( 'suppressrevision' );
 608+ $this->mToken = $request->getVal( 'token' );
614609
615 - if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
 610+ if ( $user->isAllowed( 'undelete' ) && !$user->isBlocked() ) {
616611 $this->mAllowed = true; // user can restore
617612 $this->mCanView = true; // user can view content
618 - } elseif ( $wgUser->isAllowed( 'deletedtext' ) ) {
 613+ } elseif ( $user->isAllowed( 'deletedtext' ) ) {
619614 $this->mAllowed = false; // user cannot restore
620615 $this->mCanView = true; // user can view content
621616 } else { // user can only view the list of revisions
@@ -627,7 +622,7 @@
628623 if( $this->mRestore || $this->mInvert ) {
629624 $timestamps = array();
630625 $this->mFileVersions = array();
631 - foreach( $this->mRequest->getValues() as $key => $val ) {
 626+ foreach( $request->getValues() as $key => $val ) {
632627 $matches = array();
633628 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
634629 array_push( $timestamps, $matches[1] );
@@ -643,10 +638,8 @@
644639 }
645640
646641 function execute( $par ) {
647 - global $wgOut, $wgUser;
648 -
649642 $this->setHeaders();
650 - if ( !$this->userCanExecute( $wgUser ) ) {
 643+ if ( !$this->userCanExecute( $this->getUser() ) ) {
651644 $this->displayRestrictionError();
652645 return;
653646 }
@@ -654,10 +647,12 @@
655648
656649 $this->loadRequest();
657650
 651+ $out = $this->getOutput();
 652+
658653 if ( $this->mAllowed ) {
659 - $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
 654+ $out->setPageTitle( wfMsg( 'undeletepage' ) );
660655 } else {
661 - $wgOut->setPageTitle( wfMsg( 'viewdeletedpage' ) );
 656+ $out->setPageTitle( wfMsg( 'viewdeletedpage' ) );
662657 }
663658
664659 if( $par != '' ) {
@@ -672,7 +667,7 @@
673668
674669 if( is_null( $this->mTargetObj ) ) {
675670 # Not all users can just browse every deleted page from the list
676 - if( $wgUser->isAllowed( 'browsearchive' ) ) {
 671+ if( $this->getUser()->isAllowed( 'browsearchive' ) ) {
677672 $this->showSearchForm();
678673
679674 # List undeletable articles
@@ -681,7 +676,7 @@
682677 $this->showList( $result );
683678 }
684679 } else {
685 - $wgOut->addWikiMsg( 'undelete-header' );
 680+ $out->addWikiMsg( 'undelete-header' );
686681 }
687682 return;
688683 }
@@ -692,16 +687,16 @@
693688 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename );
694689 // Check if user is allowed to see this file
695690 if ( !$file->exists() ) {
696 - $wgOut->addWikiMsg( 'filedelete-nofile', $this->mFilename );
 691+ $out->addWikiMsg( 'filedelete-nofile', $this->mFilename );
697692 return;
698693 } elseif( !$file->userCan( File::DELETED_FILE ) ) {
699694 if( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
700 - $wgOut->permissionRequired( 'suppressrevision' );
 695+ $out->permissionRequired( 'suppressrevision' );
701696 } else {
702 - $wgOut->permissionRequired( 'deletedtext' );
 697+ $out->permissionRequired( 'deletedtext' );
703698 }
704699 return false;
705 - } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFilename ) ) {
 700+ } elseif ( !$this->getUser()->matchEditToken( $this->mToken, $this->mFilename ) ) {
706701 $this->showFileConfirmationForm( $this->mFilename );
707702 return false;
708703 } else {
@@ -711,7 +706,7 @@
712707 if( $this->mRestore && $this->mAction == 'submit' ) {
713708 global $wgUploadMaintenance;
714709 if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
715 - $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
 710+ $out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
716711 return;
717712 }
718713 return $this->undelete();
@@ -723,10 +718,11 @@
724719 }
725720
726721 function showSearchForm() {
727 - global $wgOut, $wgScript;
728 - $wgOut->addWikiMsg( 'undelete-header' );
 722+ global $wgScript;
729723
730 - $wgOut->addHTML(
 724+ $this->getOutput()->addWikiMsg( 'undelete-header' );
 725+
 726+ $this->getOutput()->addHTML(
731727 Xml::openElement( 'form', array(
732728 'method' => 'get',
733729 'action' => $wgScript ) ) .
@@ -749,21 +745,20 @@
750746 * @return bool
751747 */
752748 private function showList( $result ) {
753 - global $wgLang, $wgOut;
 749+ $out = $this->getOutput();
754750
755751 if( $result->numRows() == 0 ) {
756 - $wgOut->addWikiMsg( 'undelete-no-results' );
 752+ $out->addWikiMsg( 'undelete-no-results' );
757753 return;
758754 }
759755
760 - $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
 756+ $out->addWikiMsg( 'undeletepagetext', $this->getLang()->formatNum( $result->numRows() ) );
761757
762 - $sk = $this->getSkin();
763758 $undelete = $this->getTitle();
764 - $wgOut->addHTML( "<ul>\n" );
 759+ $out->addHTML( "<ul>\n" );
765760 foreach ( $result as $row ) {
766761 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
767 - $link = $sk->linkKnown(
 762+ $link = Linker::linkKnown(
768763 $undelete,
769764 htmlspecialchars( $title->getPrefixedText() ),
770765 array(),
@@ -771,20 +766,18 @@
772767 );
773768 $revs = wfMsgExt( 'undeleterevisions',
774769 array( 'parseinline' ),
775 - $wgLang->formatNum( $row->count ) );
776 - $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
 770+ $this->getLang()->formatNum( $row->count ) );
 771+ $out->addHTML( "<li>{$link} ({$revs})</li>\n" );
777772 }
778773 $result->free();
779 - $wgOut->addHTML( "</ul>\n" );
 774+ $out->addHTML( "</ul>\n" );
780775
781776 return true;
782777 }
783778
784779 private function showRevision( $timestamp ) {
785 - global $wgLang, $wgUser, $wgOut;
 780+ $out = $this->getOutput();
786781
787 - $skin = $this->getSkin();
788 -
789782 if( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
790783 return 0;
791784 }
@@ -794,81 +787,81 @@
795788 $rev = $archive->getRevision( $timestamp );
796789
797790 if( !$rev ) {
798 - $wgOut->addWikiMsg( 'undeleterevision-missing' );
 791+ $out->addWikiMsg( 'undeleterevision-missing' );
799792 return;
800793 }
801794
802795 if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
803796 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
804 - $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
 797+ $out->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
805798 return;
806799 } else {
807 - $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
808 - $wgOut->addHTML( '<br />' );
 800+ $out->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
 801+ $out->addHTML( '<br />' );
809802 // and we are allowed to see...
810803 }
811804 }
812805
813 - $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
 806+ $out->setPageTitle( wfMsg( 'undeletepage' ) );
814807
815 - $link = $skin->linkKnown(
816 - $this->getTitle( $this->mTargetObj->getPrefixedDBkey() ),
817 - htmlspecialchars( $this->mTargetObj->getPrefixedText() )
818 - );
819 -
820808 if( $this->mDiff ) {
821809 $previousRev = $archive->getPreviousRevision( $timestamp );
822810 if( $previousRev ) {
823811 $this->showDiff( $previousRev, $rev );
824 - if( $wgUser->getOption( 'diffonly' ) ) {
 812+ if( $this->getUser()->getOption( 'diffonly' ) ) {
825813 return;
826814 } else {
827 - $wgOut->addHTML( '<hr />' );
 815+ $out->addHTML( '<hr />' );
828816 }
829817 } else {
830 - $wgOut->addWikiMsg( 'undelete-nodiff' );
 818+ $out->addWikiMsg( 'undelete-nodiff' );
831819 }
832820 }
833821
 822+ $link = Linker::linkKnown(
 823+ $this->getTitle( $this->mTargetObj->getPrefixedDBkey() ),
 824+ htmlspecialchars( $this->mTargetObj->getPrefixedText() )
 825+ );
 826+
834827 // date and time are separate parameters to facilitate localisation.
835828 // $time is kept for backward compat reasons.
836 - $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
837 - $d = htmlspecialchars( $wgLang->date( $timestamp, true ) );
838 - $t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
839 - $user = $skin->revUserTools( $rev );
 829+ $time = $this->getLang()->timeAndDate( $timestamp, true );
 830+ $d = $this->getLang()->date( $timestamp, true );
 831+ $t = $this->getLang()->time( $timestamp, true );
 832+ $user = Linker::revUserTools( $rev );
840833
841834 if( $this->mPreview ) {
842835 $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
843836 } else {
844837 $openDiv = '<div id="mw-undelete-revision">';
845838 }
846 - $wgOut->addHTML( $openDiv );
 839+ $out->addHTML( $openDiv );
847840
848841 // Revision delete links
849842 if ( !$this->mDiff ) {
850843 $revdel = $this->revDeleteLink( $rev );
851844 if ( $revdel ) {
852 - $wgOut->addHTML( $revdel );
 845+ $out->addHTML( $revdel );
853846 }
854847 }
855848
856 - $wgOut->addWikiMsgArray( 'undelete-revision', array( $link, $time, $user, $d, $t ), array( 'replaceafter' ) );
857 - $wgOut->addHTML( '</div>' );
 849+ $out->addHTML( wfMessage( 'undelete-revision' )->rawParams( $link )->params(
 850+ $time )->rawParams( $user )->params( $d, $t )->parse() . '</div>' );
858851 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
859852
860853 if( $this->mPreview ) {
861854 // Hide [edit]s
862 - $popts = $wgOut->parserOptions();
 855+ $popts = $out->parserOptions();
863856 $popts->setEditSection( false );
864 - $wgOut->parserOptions( $popts );
865 - $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
 857+ $out->parserOptions( $popts );
 858+ $out->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
866859 }
867860
868 - $wgOut->addHTML(
 861+ $out->addHTML(
869862 Xml::element( 'textarea', array(
870863 'readonly' => 'readonly',
871 - 'cols' => intval( $wgUser->getOption( 'cols' ) ),
872 - 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
 864+ 'cols' => intval( $this->getUser()->getOption( 'cols' ) ),
 865+ 'rows' => intval( $this->getUser()->getOption( 'rows' ) ) ),
873866 $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
874867 Xml::openElement( 'div' ) .
875868 Xml::openElement( 'form', array(
@@ -885,7 +878,7 @@
886879 Xml::element( 'input', array(
887880 'type' => 'hidden',
888881 'name' => 'wpEditToken',
889 - 'value' => $wgUser->editToken() ) ) .
 882+ 'value' => $this->getUser()->editToken() ) ) .
890883 Xml::element( 'input', array(
891884 'type' => 'submit',
892885 'name' => 'preview',
@@ -910,12 +903,10 @@
911904 * @return string HTML fragment
912905 */
913906 function revDeleteLink( $rev ) {
914 - global $wgUser;
915 - $canHide = $wgUser->isAllowed( 'deleterevision' );
916 - if( $canHide || ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
917 - $skin = $this->getSkin();
 907+ $canHide = $this->getUser()->isAllowed( 'deleterevision' );
 908+ if( $canHide || ( $rev->getVisibility() && $this->getUser()->isAllowed( 'deletedhistory' ) ) ) {
918909 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
919 - $revdlink = $skin->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
 910+ $revdlink = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
920911 } else {
921912 if ( $rev->getId() ) {
922913 // RevDelete links using revision ID are stable across
@@ -934,7 +925,7 @@
935926 'ids' => $rev->getTimestamp()
936927 );
937928 }
938 - return $skin->revDeleteLink( $query,
 929+ return Linker::revDeleteLink( $query,
939930 $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
940931 }
941932 } else {
@@ -951,11 +942,9 @@
952943 * @return String: HTML
953944 */
954945 function showDiff( $previousRev, $currentRev ) {
955 - global $wgOut;
956 -
957946 $diffEngine = new DifferenceEngine( $previousRev->getTitle() );
958947 $diffEngine->showDiffStyle();
959 - $wgOut->addHTML(
 948+ $this->getOutput()->addHTML(
960949 "<div>" .
961950 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
962951 "<col class='diff-marker' />" .
@@ -983,8 +972,6 @@
984973 * @return string
985974 */
986975 private function diffHeader( $rev, $prefix ) {
987 - global $wgUser, $wgLang;
988 - $sk = $this->getSkin();
989976 $isDeleted = !( $rev->getId() && $rev->getTitle() );
990977 if( $isDeleted ) {
991978 /// @todo FIXME: $rev->getTitle() is null for deleted revs...?
@@ -1002,23 +989,24 @@
1003990 $del = $this->revDeleteLink( $rev );
1004991 return
1005992 '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
1006 - $sk->link(
 993+ Linker::link(
1007994 $targetPage,
1008 - wfMsgHtml(
 995+ wfMsgExt(
1009996 'revisionasof',
1010 - htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
1011 - htmlspecialchars( $wgLang->date( $rev->getTimestamp(), true ) ),
1012 - htmlspecialchars( $wgLang->time( $rev->getTimestamp(), true ) )
 997+ array( 'escape' ),
 998+ $this->getLang()->timeanddate( $rev->getTimestamp(), true ),
 999+ $this->getLang()->date( $rev->getTimestamp(), true ),
 1000+ $this->getLang()->time( $rev->getTimestamp(), true )
10131001 ),
10141002 array(),
10151003 $targetQuery
10161004 ) .
10171005 '</strong></div>' .
10181006 '<div id="mw-diff-'.$prefix.'title2">' .
1019 - $sk->revUserTools( $rev ) . '<br />' .
 1007+ Linker::revUserTools( $rev ) . '<br />' .
10201008 '</div>' .
10211009 '<div id="mw-diff-'.$prefix.'title3">' .
1022 - $sk->revComment( $rev ) . $del . '<br />' .
 1010+ Linker::revComment( $rev ) . $del . '<br />' .
10231011 '</div>';
10241012 }
10251013
@@ -1026,19 +1014,18 @@
10271015 * Show a form confirming whether a tokenless user really wants to see a file
10281016 */
10291017 private function showFileConfirmationForm( $key ) {
1030 - global $wgOut, $wgUser, $wgLang;
10311018 $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename );
1032 - $wgOut->addWikiMsg( 'undelete-show-file-confirm',
 1019+ $this->getOutput()->addWikiMsg( 'undelete-show-file-confirm',
10331020 $this->mTargetObj->getText(),
1034 - $wgLang->date( $file->getTimestamp() ),
1035 - $wgLang->time( $file->getTimestamp() ) );
1036 - $wgOut->addHTML(
 1021+ $this->getLang()->date( $file->getTimestamp() ),
 1022+ $this->getLang()->time( $file->getTimestamp() ) );
 1023+ $this->getOutput()->addHTML(
10371024 Xml::openElement( 'form', array(
10381025 'method' => 'POST',
10391026 'action' => $this->getTitle()->getLocalURL(
10401027 'target=' . urlencode( $this->mTarget ) .
10411028 '&file=' . urlencode( $key ) .
1042 - '&token=' . urlencode( $wgUser->editToken( $key ) ) )
 1029+ '&token=' . urlencode( $this->getUser()->editToken( $key ) ) )
10431030 )
10441031 ) .
10451032 Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
@@ -1050,16 +1037,16 @@
10511038 * Show a deleted file version requested by the visitor.
10521039 */
10531040 private function showFile( $key ) {
1054 - global $wgOut, $wgRequest;
1055 - $wgOut->disable();
 1041+ $this->getOutput()->disable();
10561042
10571043 # We mustn't allow the output to be Squid cached, otherwise
10581044 # if an admin previews a deleted image, and it's cached, then
10591045 # a user without appropriate permissions can toddle off and
10601046 # nab the image, and Squid will serve it
1061 - $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1062 - $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1063 - $wgRequest->response()->header( 'Pragma: no-cache' );
 1047+ $response = $this->getRequest()->response();
 1048+ $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
 1049+ $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
 1050+ $response->header( 'Pragma: no-cache' );
10641051
10651052 global $IP;
10661053 require_once( "$IP/includes/StreamFile.php" );
@@ -1069,16 +1056,14 @@
10701057 }
10711058
10721059 private function showHistory() {
1073 - global $wgUser, $wgOut;
1074 -
1075 - $sk = $wgUser->getSkin();
 1060+ $out = $this->getOutput();
10761061 if( $this->mAllowed ) {
1077 - $wgOut->addModules( 'mediawiki.special.undelete' );
1078 - $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
 1062+ $out->addModules( 'mediawiki.special.undelete' );
 1063+ $out->setPageTitle( wfMsg( 'undeletepage' ) );
10791064 } else {
1080 - $wgOut->setPageTitle( wfMsg( 'viewdeletedpage' ) );
 1065+ $out->setPageTitle( wfMsg( 'viewdeletedpage' ) );
10811066 }
1082 - $wgOut->wrapWikiMsg(
 1067+ $out->wrapWikiMsg(
10831068 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
10841069 array( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() )
10851070 );
@@ -1088,18 +1073,18 @@
10891074 /*
10901075 $text = $archive->getLastRevisionText();
10911076 if( is_null( $text ) ) {
1092 - $wgOut->addWikiMsg( 'nohistory' );
 1077+ $out->addWikiMsg( 'nohistory' );
10931078 return;
10941079 }
10951080 */
1096 - $wgOut->addHTML( '<div class="mw-undelete-history">' );
 1081+ $out->addHTML( '<div class="mw-undelete-history">' );
10971082 if ( $this->mAllowed ) {
1098 - $wgOut->addWikiMsg( 'undeletehistory' );
1099 - $wgOut->addWikiMsg( 'undeleterevdel' );
 1083+ $out->addWikiMsg( 'undeletehistory' );
 1084+ $out->addWikiMsg( 'undeleterevdel' );
11001085 } else {
1101 - $wgOut->addWikiMsg( 'undeletehistorynoadmin' );
 1086+ $out->addWikiMsg( 'undeletehistorynoadmin' );
11021087 }
1103 - $wgOut->addHTML( '</div>' );
 1088+ $out->addHTML( '</div>' );
11041089
11051090 # List all stored revisions
11061091 $revisions = $archive->listRevisions();
@@ -1132,22 +1117,22 @@
11331118 $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) );
11341119 # Start the form here
11351120 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
1136 - $wgOut->addHTML( $top );
 1121+ $out->addHTML( $top );
11371122 }
11381123
11391124 # Show relevant lines from the deletion log:
1140 - $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
1141 - LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
 1125+ $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
 1126+ LogEventsList::showLogExtract( $out, 'delete', $this->mTargetObj->getPrefixedText() );
11421127 # Show relevant lines from the suppression log:
1143 - if( $wgUser->isAllowed( 'suppressionlog' ) ) {
1144 - $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
1145 - LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
 1128+ if( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
 1129+ $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
 1130+ LogEventsList::showLogExtract( $out, 'suppress', $this->mTargetObj->getPrefixedText() );
11461131 }
11471132
11481133 if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
11491134 # Format the user-visible controls (comment field, submission button)
11501135 # in a nice little table
1151 - if( $wgUser->isAllowed( 'suppressrevision' ) ) {
 1136+ if( $this->getUser()->isAllowed( 'suppressrevision' ) ) {
11521137 $unsuppressBox =
11531138 "<tr>
11541139 <td>&#160;</td>
@@ -1186,51 +1171,49 @@
11871172 Xml::closeElement( 'table' ) .
11881173 Xml::closeElement( 'fieldset' );
11891174
1190 - $wgOut->addHTML( $table );
 1175+ $out->addHTML( $table );
11911176 }
11921177
1193 - $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
 1178+ $out->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
11941179
11951180 if( $haveRevisions ) {
11961181 # The page's stored (deleted) history:
1197 - $wgOut->addHTML( '<ul>' );
 1182+ $out->addHTML( '<ul>' );
11981183 $remaining = $revisions->numRows();
11991184 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
12001185
12011186 foreach ( $revisions as $row ) {
12021187 $remaining--;
1203 - $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
 1188+ $out->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining ) );
12041189 }
12051190 $revisions->free();
1206 - $wgOut->addHTML( '</ul>' );
 1191+ $out->addHTML( '</ul>' );
12071192 } else {
1208 - $wgOut->addWikiMsg( 'nohistory' );
 1193+ $out->addWikiMsg( 'nohistory' );
12091194 }
12101195
12111196 if( $haveFiles ) {
1212 - $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1213 - $wgOut->addHTML( '<ul>' );
 1197+ $out->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
 1198+ $out->addHTML( '<ul>' );
12141199 foreach ( $files as $row ) {
1215 - $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
 1200+ $out->addHTML( $this->formatFileRow( $row ) );
12161201 }
12171202 $files->free();
1218 - $wgOut->addHTML( '</ul>' );
 1203+ $out->addHTML( '</ul>' );
12191204 }
12201205
12211206 if ( $this->mAllowed ) {
12221207 # Slip in the hidden controls here
12231208 $misc = Html::hidden( 'target', $this->mTarget );
1224 - $misc .= Html::hidden( 'wpEditToken', $wgUser->editToken() );
 1209+ $misc .= Html::hidden( 'wpEditToken', $this->getUser()->editToken() );
12251210 $misc .= Xml::closeElement( 'form' );
1226 - $wgOut->addHTML( $misc );
 1211+ $out->addHTML( $misc );
12271212 }
12281213
12291214 return true;
12301215 }
12311216
1232 - private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
1233 - global $wgLang;
1234 -
 1217+ private function formatRevisionRow( $row, $earliestLiveTime, $remaining ) {
12351218 $rev = Revision::newFromArchiveRow( $row,
12361219 array( 'page' => $this->mTargetObj->getArticleId() ) );
12371220 $stxt = '';
@@ -1254,11 +1237,11 @@
12551238 $titleObj = $this->getTitle();
12561239 # Last link
12571240 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
1258 - $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
 1241+ $pageLink = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
12591242 $last = wfMsgHtml( 'diff' );
12601243 } elseif( $remaining > 0 || ( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
1261 - $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1262 - $last = $sk->linkKnown(
 1244+ $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
 1245+ $last = Linker::linkKnown(
12631246 $titleObj,
12641247 wfMsgHtml( 'diff' ),
12651248 array(),
@@ -1269,63 +1252,61 @@
12701253 )
12711254 );
12721255 } else {
1273 - $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
 1256+ $pageLink = $this->getPageLink( $rev, $titleObj, $ts );
12741257 $last = wfMsgHtml( 'diff' );
12751258 }
12761259 } else {
1277 - $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
 1260+ $pageLink = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
12781261 $last = wfMsgHtml( 'diff' );
12791262 }
12801263 // User links
1281 - $userLink = $sk->revUserTools( $rev );
 1264+ $userLink = Linker::revUserTools( $rev );
12821265 // Revision text size
12831266 $size = $row->ar_len;
12841267 if( !is_null( $size ) ) {
1285 - $stxt = $sk->formatRevisionSize( $size );
 1268+ $stxt = Linker::formatRevisionSize( $size );
12861269 }
12871270 // Edit summary
1288 - $comment = $sk->revComment( $rev );
 1271+ $comment = Linker::revComment( $rev );
12891272 // Revision delete links
12901273 $revdlink = $this->revDeleteLink( $rev );
12911274 return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
12921275 }
12931276
1294 - private function formatFileRow( $row, $sk ) {
1295 - global $wgUser, $wgLang;
1296 -
 1277+ private function formatFileRow( $row ) {
12971278 $file = ArchivedFile::newFromRow( $row );
12981279
12991280 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
13001281 if( $this->mAllowed && $row->fa_storage_key ) {
13011282 $checkBox = Xml::check( 'fileid' . $row->fa_id );
13021283 $key = urlencode( $row->fa_storage_key );
1303 - $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key, $sk );
 1284+ $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key );
13041285 } else {
13051286 $checkBox = '';
1306 - $pageLink = $wgLang->timeanddate( $ts, true );
 1287+ $pageLink = $this->getLang()->timeanddate( $ts, true );
13071288 }
1308 - $userLink = $this->getFileUser( $file, $sk );
 1289+ $userLink = $this->getFileUser( $file );
13091290 $data =
13101291 wfMsg( 'widthheight',
1311 - $wgLang->formatNum( $row->fa_width ),
1312 - $wgLang->formatNum( $row->fa_height ) ) .
 1292+ $this->getLang()->formatNum( $row->fa_width ),
 1293+ $this->getLang()->formatNum( $row->fa_height ) ) .
13131294 ' (' .
1314 - wfMsg( 'nbytes', $wgLang->formatNum( $row->fa_size ) ) .
 1295+ wfMsg( 'nbytes', $this->getLang()->formatNum( $row->fa_size ) ) .
13151296 ')';
13161297 $data = htmlspecialchars( $data );
1317 - $comment = $this->getFileComment( $file, $sk );
 1298+ $comment = $this->getFileComment( $file );
13181299 // Add show/hide deletion links if available
1319 - $canHide = $wgUser->isAllowed( 'deleterevision' );
1320 - if( $canHide || ( $file->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
 1300+ $canHide = $this->getUser()->isAllowed( 'deleterevision' );
 1301+ if( $canHide || ( $file->getVisibility() && $this->getUser()->isAllowed( 'deletedhistory' ) ) ) {
13211302 if( !$file->userCan( File::DELETED_RESTRICTED ) ) {
1322 - $revdlink = $sk->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
 1303+ $revdlink = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
13231304 } else {
13241305 $query = array(
13251306 'type' => 'filearchive',
13261307 'target' => $this->mTargetObj->getPrefixedDBkey(),
13271308 'ids' => $row->fa_id
13281309 );
1329 - $revdlink = $sk->revDeleteLink( $query,
 1310+ $revdlink = Linker::revDeleteLink( $query,
13301311 $file->isDeleted( File::DELETED_RESTRICTED ), $canHide );
13311312 }
13321313 } else {
@@ -1338,18 +1319,15 @@
13391320 * Fetch revision text link if it's available to all users
13401321 *
13411322 * @param $rev Revision
1342 - * @param $sk Skin
13431323 * @return string
13441324 */
1345 - function getPageLink( $rev, $titleObj, $ts, $sk ) {
1346 - global $wgLang;
 1325+ function getPageLink( $rev, $titleObj, $ts ) {
 1326+ $time = htmlspecialchars( $this->getLang()->timeanddate( $ts, true ) );
13471327
1348 - $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1349 -
13501328 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
13511329 return '<span class="history-deleted">' . $time . '</span>';
13521330 } else {
1353 - $link = $sk->linkKnown(
 1331+ $link = Linker::linkKnown(
13541332 $titleObj,
13551333 $time,
13561334 array(),
@@ -1369,23 +1347,20 @@
13701348 * Fetch image view link if it's available to all users
13711349 *
13721350 * @param $file File
1373 - * @param $sk Skin
13741351 * @return String: HTML fragment
13751352 */
1376 - function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
1377 - global $wgLang, $wgUser;
1378 -
 1353+ function getFileLink( $file, $titleObj, $ts, $key ) {
13791354 if( !$file->userCan( File::DELETED_FILE ) ) {
1380 - return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
 1355+ return '<span class="history-deleted">' . $this->getLang()->timeanddate( $ts, true ) . '</span>';
13811356 } else {
1382 - $link = $sk->linkKnown(
 1357+ $link = Linker::linkKnown(
13831358 $titleObj,
1384 - $wgLang->timeanddate( $ts, true ),
 1359+ $this->getLang()->timeanddate( $ts, true ),
13851360 array(),
13861361 array(
13871362 'target' => $this->mTargetObj->getPrefixedText(),
13881363 'file' => $key,
1389 - 'token' => $wgUser->editToken( $key )
 1364+ 'token' => $this->getUser()->editToken( $key )
13901365 )
13911366 );
13921367 if( $file->isDeleted( File::DELETED_FILE ) ) {
@@ -1399,15 +1374,14 @@
14001375 * Fetch file's user id if it's available to this user
14011376 *
14021377 * @param $file File
1403 - * @param $sk Skin
14041378 * @return String: HTML fragment
14051379 */
1406 - function getFileUser( $file, $sk ) {
 1380+ function getFileUser( $file ) {
14071381 if( !$file->userCan( File::DELETED_USER ) ) {
14081382 return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
14091383 } else {
1410 - $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
1411 - $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
 1384+ $link = Linker::userLink( $file->getRawUser(), $file->getRawUserText() ) .
 1385+ Linker::userToolLinks( $file->getRawUser(), $file->getRawUserText() );
14121386 if( $file->isDeleted( File::DELETED_USER ) ) {
14131387 $link = '<span class="history-deleted">' . $link . '</span>';
14141388 }
@@ -1419,15 +1393,14 @@
14201394 * Fetch file upload comment if it's available to this user
14211395 *
14221396 * @param $file File
1423 - * @param $sk Skin
14241397 * @return String: HTML fragment
14251398 */
1426 - function getFileComment( $file, $sk ) {
 1399+ function getFileComment( $file ) {
14271400 if( !$file->userCan( File::DELETED_COMMENT ) ) {
14281401 return '<span class="history-deleted"><span class="comment">' .
14291402 wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
14301403 } else {
1431 - $link = $sk->commentBlock( $file->getRawDescription() );
 1404+ $link = Linker::commentBlock( $file->getRawDescription() );
14321405 if( $file->isDeleted( File::DELETED_COMMENT ) ) {
14331406 $link = '<span class="history-deleted">' . $link . '</span>';
14341407 }
@@ -1436,11 +1409,10 @@
14371410 }
14381411
14391412 function undelete() {
1440 - global $wgOut, $wgUser;
14411413 if ( wfReadOnly() ) {
1442 - $wgOut->readOnlyPage();
1443 - return;
 1414+ throw new ReadOnlyError;
14441415 }
 1416+
14451417 if( !is_null( $this->mTargetObj ) ) {
14461418 $archive = new PageArchive( $this->mTargetObj );
14471419 wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
@@ -1454,24 +1426,23 @@
14551427 if ( $ok[1] ) { // Undeleted file count
14561428 wfRunHooks( 'FileUndeleteComplete', array(
14571429 $this->mTargetObj, $this->mFileVersions,
1458 - $wgUser, $this->mComment ) );
 1430+ $this->getUser(), $this->mComment ) );
14591431 }
14601432
1461 - $skin = $wgUser->getSkin();
1462 - $link = $skin->linkKnown( $this->mTargetObj );
1463 - $wgOut->addWikiMsgArray( 'undeletedpage', array( $link ), array( 'replaceafter' ) );
 1433+ $link = Linker::linkKnown( $this->mTargetObj );
 1434+ $this->getOutput()->addHTML( wfMessage( 'undeletedpage' )->rawParams( $link )->parse() );
14641435 } else {
1465 - $wgOut->showFatalError( wfMsg( 'cannotundelete' ) );
1466 - $wgOut->addWikiMsg( 'undeleterevdel' );
 1436+ $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
 1437+ $this->getOutput()->addWikiMsg( 'undeleterevdel' );
14671438 }
14681439
14691440 // Show file deletion warnings and errors
14701441 $status = $archive->getFileStatus();
14711442 if( $status && !$status->isGood() ) {
1472 - $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
 1443+ $this->getOutput()->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
14731444 }
14741445 } else {
1475 - $wgOut->showFatalError( wfMsg( 'cannotundelete' ) );
 1446+ $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
14761447 }
14771448 return false;
14781449 }

Comments

#Comment by Aaron Schulz (talk | contribs)   20:41, 2 August 2011

'revisionasof' is now parsed. Will that break existing messages on wikis?

#Comment by Aaron Schulz (talk | contribs)   20:44, 2 August 2011

Nevermind, just does 'escape'.

Status & tagging log