r85306 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85305‎ | r85306 | r85307 >
Date:02:00, 4 April 2011
Author:dantman
Status:ok
Tags:
Comment:
Update special pages which use $wgUser->getSkin(); inside their constructor:
- Use the Linker:: properly
- Don't use $wgOut, $wgUser, $wgRequest
- Don't fetch the skin early
Modified paths:
  • /trunk/phase3/includes/specials/SpecialListgrouprights.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSpecialpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWhatlinkshere.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialSpecialpages.php
@@ -33,11 +33,11 @@
3434 }
3535
3636 function execute( $par ) {
37 - global $wgOut;
 37+ $out = $this->getOutput();
3838 $this->setHeaders();
3939 $this->outputHeader();
40 - $wgOut->allowClickjacking();
41 - $wgOut->addModuleStyles( 'mediawiki.special' );
 40+ $out->allowClickjacking();
 41+ $out->addModuleStyles( 'mediawiki.special' );
4242
4343 $groups = $this->getPageGroups();
4444
@@ -88,9 +88,9 @@
8989 }
9090
9191 private function outputPageList( $groups ) {
92 - global $wgUser, $wgOut, $wgMiserMode;
 92+ global $wgMiserMode;
 93+ $out = $this->getOutput();
9394
94 - $sk = $wgUser->getSkin();
9595 $includesRestrictedPages = false;
9696 $includesCachedPages = false;
9797
@@ -99,8 +99,8 @@
100100 $total = count( $sortedPages );
101101 $count = 0;
102102
103 - $wgOut->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
104 - $wgOut->addHTML(
 103+ $out->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
 104+ $out->addHTML(
105105 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) ."\n" .
106106 Html::openElement( 'tr' ) . "\n" .
107107 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
@@ -119,20 +119,20 @@
120120 $pageClasses[] = 'mw-specialpagerestricted';
121121 }
122122
123 - $link = $sk->linkKnown( $title , htmlspecialchars( $desc ) );
124 - $wgOut->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
 123+ $link = Linker::linkKnown( $title , htmlspecialchars( $desc ) );
 124+ $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
125125
126126 # Split up the larger groups
127127 $count++;
128128 if( $total > 3 && $count == $middle ) {
129 - $wgOut->addHTML(
 129+ $out->addHTML(
130130 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
131131 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
132132 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
133133 );
134134 }
135135 }
136 - $wgOut->addHTML(
 136+ $out->addHTML(
137137 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
138138 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
139139 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
@@ -140,7 +140,7 @@
141141 }
142142
143143 if ( $includesRestrictedPages || $includesCachedPages ) {
144 - $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
 144+ $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
145145 }
146146 }
147147 }
Index: trunk/phase3/includes/specials/SpecialWhatlinkshere.php
@@ -31,20 +31,15 @@
3232 // Stored objects
3333 protected $opts, $target, $selfTitle;
3434
35 - // Stored globals
36 - protected $skin;
37 -
3835 protected $limits = array( 20, 50, 100, 250, 500 );
3936
4037 public function __construct() {
4138 parent::__construct( 'Whatlinkshere' );
42 - global $wgUser;
43 - $this->skin = $wgUser->getSkin();
4439 }
4540
4641 function execute( $par ) {
47 - global $wgOut, $wgRequest;
48 -
 42+ $out = $this->getOutput();
 43+
4944 $this->setHeaders();
5045
5146 $opts = new FormOptions();
@@ -59,7 +54,7 @@
6055 $opts->add( 'hidelinks', false );
6156 $opts->add( 'hideimages', false );
6257
63 - $opts->fetchValuesFromRequest( $wgRequest );
 58+ $opts->fetchValuesFromRequest( $this->getRequest() );
6459 $opts->validateIntBounds( 'limit', 0, 5000 );
6560
6661 // Give precedence to subpage syntax
@@ -72,17 +67,17 @@
7368
7469 $this->target = Title::newFromURL( $opts->getValue( 'target' ) );
7570 if( !$this->target ) {
76 - $wgOut->addHTML( $this->whatlinkshereForm() );
 71+ $out->addHTML( $this->whatlinkshereForm() );
7772 return;
7873 }
7974
80 - $this->skin->setRelevantTitle( $this->target );
 75+ $this->getSkin()->setRelevantTitle( $this->target );
8176
8277
8378 $this->selfTitle = $this->getTitle( $this->target->getPrefixedDBkey() );
8479
85 - $wgOut->setPageTitle( wfMsg( 'whatlinkshere-title', $this->target->getPrefixedText() ) );
86 - $wgOut->setSubtitle( wfMsg( 'whatlinkshere-backlink', $this->skin->link( $this->target, $this->target->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
 80+ $out->setPageTitle( wfMsg( 'whatlinkshere-title', $this->target->getPrefixedText() ) );
 81+ $out->setSubtitle( wfMsg( 'whatlinkshere-backlink', Linker::link( $this->target, $this->target->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
8782
8883 $this->showIndirectLinks( 0, $this->target, $opts->getValue( 'limit' ),
8984 $opts->getValue( 'from' ), $opts->getValue( 'back' ) );
@@ -97,7 +92,8 @@
9893 * @private
9994 */
10095 function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) {
101 - global $wgOut, $wgMaxRedirectLinksRetrieved;
 96+ global $wgMaxRedirectLinksRetrieved;
 97+ $out = $this->getOutput();
10298 $dbr = wfGetDB( DB_SLAVE );
10399 $options = array();
104100
@@ -174,14 +170,14 @@
175171
176172 if( ( !$fetchlinks || !$dbr->numRows($plRes) ) && ( $hidetrans || !$dbr->numRows($tlRes) ) && ( $hideimages || !$dbr->numRows($ilRes) ) ) {
177173 if ( 0 == $level ) {
178 - $wgOut->addHTML( $this->whatlinkshereForm() );
 174+ $out->addHTML( $this->whatlinkshereForm() );
179175
180176 // Show filters only if there are links
181177 if( $hidelinks || $hidetrans || $hideredirs || $hideimages )
182 - $wgOut->addHTML( $this->getFilterPanel() );
 178+ $out->addHTML( $this->getFilterPanel() );
183179
184180 $errMsg = is_int($namespace) ? 'nolinkshere-ns' : 'nolinkshere';
185 - $wgOut->addWikiMsg( $errMsg, $this->target->getPrefixedText() );
 181+ $out->addWikiMsg( $errMsg, $this->target->getPrefixedText() );
186182 }
187183 return;
188184 }
@@ -231,31 +227,31 @@
232228 $prevId = $from;
233229
234230 if ( $level == 0 ) {
235 - $wgOut->addHTML( $this->whatlinkshereForm() );
236 - $wgOut->addHTML( $this->getFilterPanel() );
237 - $wgOut->addWikiMsg( 'linkshere', $this->target->getPrefixedText() );
 231+ $out->addHTML( $this->whatlinkshereForm() );
 232+ $out->addHTML( $this->getFilterPanel() );
 233+ $out->addWikiMsg( 'linkshere', $this->target->getPrefixedText() );
238234
239235 $prevnext = $this->getPrevNext( $prevId, $nextId );
240 - $wgOut->addHTML( $prevnext );
 236+ $out->addHTML( $prevnext );
241237 }
242238
243 - $wgOut->addHTML( $this->listStart( $level ) );
 239+ $out->addHTML( $this->listStart( $level ) );
244240 foreach ( $rows as $row ) {
245241 $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
246242
247243 if ( $row->page_is_redirect && $level < 2 ) {
248 - $wgOut->addHTML( $this->listItem( $row, $nt, true ) );
 244+ $out->addHTML( $this->listItem( $row, $nt, true ) );
249245 $this->showIndirectLinks( $level + 1, $nt, $wgMaxRedirectLinksRetrieved );
250 - $wgOut->addHTML( Xml::closeElement( 'li' ) );
 246+ $out->addHTML( Xml::closeElement( 'li' ) );
251247 } else {
252 - $wgOut->addHTML( $this->listItem( $row, $nt ) );
 248+ $out->addHTML( $this->listItem( $row, $nt ) );
253249 }
254250 }
255251
256 - $wgOut->addHTML( $this->listEnd() );
 252+ $out->addHTML( $this->listEnd() );
257253
258254 if( $level == 0 ) {
259 - $wgOut->addHTML( $prevnext );
 255+ $out->addHTML( $prevnext );
260256 }
261257 }
262258
@@ -281,7 +277,7 @@
282278 $query = array();
283279 }
284280
285 - $link = $this->skin->linkKnown(
 281+ $link = Linker::linkKnown(
286282 $nt,
287283 null,
288284 array(),
@@ -320,7 +316,7 @@
321317 if ( $title === null )
322318 $title = $this->getTitle();
323319
324 - return $this->skin->linkKnown(
 320+ return Linker::linkKnown(
325321 $title,
326322 $text,
327323 array(),
@@ -329,7 +325,7 @@
330326 }
331327
332328 function makeSelfLink( $text, $query ) {
333 - return $this->skin->linkKnown(
 329+ return Linker::linkKnown(
334330 $this->selfTitle,
335331 $text,
336332 array(),
Index: trunk/phase3/includes/specials/SpecialListgrouprights.php
@@ -30,30 +30,27 @@
3131 */
3232 class SpecialListGroupRights extends SpecialPage {
3333
34 - var $skin;
35 -
3634 /**
3735 * Constructor
3836 */
3937 function __construct() {
40 - global $wgUser;
4138 parent::__construct( 'Listgrouprights' );
42 - $this->skin = $wgUser->getSkin();
4339 }
4440
4541 /**
4642 * Show the special page
4743 */
4844 public function execute( $par ) {
49 - global $wgOut, $wgImplicitGroups;
 45+ global $wgImplicitGroups;
5046 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
5147 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
 48+ $out = $this->getOutput();
5249
5350 $this->setHeaders();
5451 $this->outputHeader();
55 - $wgOut->addModuleStyles( 'mediawiki.special' );
 52+ $out->addModuleStyles( 'mediawiki.special' );
5653
57 - $wgOut->addHTML(
 54+ $out->addHTML(
5855 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
5956 '<tr>' .
6057 Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
@@ -91,7 +88,7 @@
9289 // Do not make a link for the generic * group
9390 $grouppage = htmlspecialchars( $groupnameLocalized );
9491 } else {
95 - $grouppage = $this->skin->link(
 92+ $grouppage = Linker::link(
9693 Title::newFromText( $grouppageLocalized ),
9794 htmlspecialchars( $groupnameLocalized )
9895 );
@@ -99,7 +96,7 @@
10097
10198 if ( $group === 'user' ) {
10299 // Link to Special:listusers for implicit group 'user'
103 - $grouplink = '<br />' . $this->skin->link(
 100+ $grouplink = '<br />' . Linker::link(
104101 SpecialPage::getTitleFor( 'Listusers' ),
105102 wfMsgHtml( 'listgrouprights-members' ),
106103 array(),
@@ -107,7 +104,7 @@
108105 array( 'known', 'noclasses' )
109106 );
110107 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
111 - $grouplink = '<br />' . $this->skin->link(
 108+ $grouplink = '<br />' . Linker::link(
112109 SpecialPage::getTitleFor( 'Listusers' ),
113110 wfMsgHtml( 'listgrouprights-members' ),
114111 array(),
@@ -126,7 +123,7 @@
127124 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
128125
129126 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
130 - $wgOut->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
 127+ $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
131128 "
132129 <td>$grouppage$grouplink</td>
133130 <td>" .
@@ -135,10 +132,10 @@
136133 '
137134 ) );
138135 }
139 - $wgOut->addHTML(
 136+ $out->addHTML(
140137 Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
141138 );
142 - $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
 139+ $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
143140 }
144141
145142 /**

Status & tagging log