From: Alexandre Emsenhuber Date: Thu, 8 Sep 2011 17:34:24 +0000 (+0000) Subject: * Use local context instead of global variables X-Git-Tag: 1.31.0-rc.0~27787 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=6417fea85daa2b53b702a6807dfee6c21782d34f;p=lhc%2Fweb%2Fwiklou.git * Use local context instead of global variables * Call Linker methods statically * Fixed call to non-existing method Linker::makeImageLinkObj() --- diff --git a/includes/specials/SpecialGlobalFileUsage.php b/includes/specials/SpecialGlobalFileUsage.php index 4c25eb6937..97aa4413f1 100644 --- a/includes/specials/SpecialGlobalFileUsage.php +++ b/includes/specials/SpecialGlobalFileUsage.php @@ -13,39 +13,34 @@ class SpecialGlobalFileUsage extends SpecialPage { * Entry point */ public function execute( $par ) { - global $wgOut, $wgRequest; - - $target = $par ? $par : $wgRequest->getVal( 'target' ); + $request = $this->getRequest(); + $target = $par ? $par : $request->getVal( 'target' ); $this->target = Title::makeTitleSafe( NS_FILE, $target ); - $this->filterLocal = $wgRequest->getCheck( 'filterlocal' ); + $this->filterLocal = $request->getCheck( 'filterlocal' ); $this->setHeaders(); $this->showForm(); - if ( is_null( $this->target ) ) { - $wgOut->setPageTitle( wfMsg( 'globalfileusage' ) ); - return; + if ( !is_null( $this->target ) ) { + $this->getOutput()->setPageTitle( wfMsg( 'globalfileusage-for', $this->target->getPrefixedText() ) ); + $this->showResult(); } - - $wgOut->setPageTitle( wfMsg( 'globalfileusage-for', $this->target->getPrefixedText() ) ); - - $this->showResult(); } /** * Shows the search form */ private function showForm() { - global $wgScript, $wgOut, $wgRequest; + global $wgScript, $wgContLang; /* Build form */ $html = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . "\n"; // Name of SpecialPage $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n"; // Limit - $html .= Html::hidden( 'limit', $wgRequest->getInt( 'limit', 50 ) ); + $html .= Html::hidden( 'limit', $this->getRequest()->getInt( 'limit', 50 ) ); // Input box with target prefilled if available $formContent = "\t" . Xml::input( 'target', 40, is_null( $this->target ) ? '' : $this->target->getText() ) @@ -58,50 +53,46 @@ class SpecialGlobalFileUsage extends SpecialPage { . "\n\t

" . Xml::checkLabel( wfMsg( 'globalfileusage-filterlocal' ), 'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '

'; - if ( !is_null( $this->target ) && wfFindFile( $this->target ) ) { - // Show the image if it exists - global $wgUser, $wgContLang; - $skin = $wgUser->getSkin(); - - $html .= $skin->makeImageLinkObj( $this->target, - $this->target->getPrefixedText(), - /* $alt */ '', /* $align */ $wgContLang->alignEnd(), - /* $handlerParams */ array(), /* $framed */ false, - /* $thumb */ true ); + if ( !is_null( $this->target ) ) { + $file = wfFindFile( $this->target ); + if ( $file !== null ) { + // Show the image if it exists + $html .= Linker::makeImageLink2( $this->target, $file, + array( 'align' => $this->getLang()->alignEnd(), 'thumbnail' => true ) ); + } } // Wrap the entire form in a nice fieldset $html .= Xml::fieldSet( wfMsg( 'globalfileusage-text' ), $formContent ) . "\n"; - $wgOut->addHtml( $html ); + $this->getOutput()->addHtml( $html ); } /** - * Creates as queryer and executes it based on $wgRequest + * Creates as queryer and executes it based on the WebRequest object */ private function showResult() { - global $wgRequest; - + $request = $this->getRequest(); $query = new GlobalUsageQuery( $this->target ); - // Extract params from $wgRequest - if ( $wgRequest->getText( 'from' ) ) { - $query->setOffset( $wgRequest->getText( 'from' ) ); - } elseif ( $wgRequest->getText( 'to' ) ) { - $query->setOffset( $wgRequest->getText( 'to' ), true ); + // Extract params from the WebRequest object + if ( $request->getText( 'from' ) ) { + $query->setOffset( $request->getText( 'from' ) ); + } elseif ( $request->getText( 'to' ) ) { + $query->setOffset( $request->getText( 'to' ), true ); } - $query->setLimit( $wgRequest->getInt( 'limit', 50 ) ); + $query->setLimit( $request->getInt( 'limit', 50 ) ); $query->filterLocal( $this->filterLocal ); // Perform query $query->searchFile(); // Show result - global $wgOut; + $out = $this->getOutput(); // Don't show form element if there is no data if ( $query->count() == 0 ) { - $wgOut->addWikiMsg( 'globalfileusage-no-results', $this->target->getPrefixedText() ); + $out->addWikiMsg( 'globalfileusage-no-results', $this->target->getPrefixedText() ); return; } @@ -110,24 +101,24 @@ class SpecialGlobalFileUsage extends SpecialPage { $targetName = $this->target->getText(); // Top navbar - $wgOut->addHtml( $navbar ); + $out->addHtml( $navbar ); - $wgOut->addHtml( '
' ); + $out->addHtml( '
' ); foreach ( $query->getSingleResult() as $wiki => $result ) { - $wgOut->addHtml( + $out->addHtml( '

' . wfMsgExt( 'globalfileusage-on-wiki', 'parseinline', $targetName, WikiMap::getWikiName( $wiki ) ) . "

    \n" ); foreach ( $result as $item ) { - $wgOut->addHtml( "\t
  • " . self::formatItem( $item ) . "
  • \n" ); + $out->addHtml( "\t
  • " . self::formatItem( $item ) . "
  • \n" ); } - $wgOut->addHtml( "
\n" ); + $out->addHtml( "\n" ); } - $wgOut->addHtml( '
' ); + $out->addHtml( '
' ); // Bottom navbar - $wgOut->addHtml( $navbar ); + $out->addHtml( $navbar ); } /** @@ -153,13 +144,10 @@ class SpecialGlobalFileUsage extends SpecialPage { * @return string Navbar HTML */ protected function getNavBar( $query ) { - global $wgLang, $wgUser; - - $skin = $wgUser->getSkin(); - + $lang = $this->getLang(); $target = $this->target->getText(); $limit = $query->getLimit(); - $fmtLimit = $wgLang->formatNum( $limit ); + $fmtLimit = $lang->formatNum( $limit ); # Find out which strings are for the prev and which for the next links $offset = $query->getOffsetString(); @@ -188,7 +176,7 @@ class SpecialGlobalFileUsage extends SpecialPage { $q = array( 'limit' => $limit, 'to' => $to, 'target' => $target ); if ( $this->filterLocal ) $q['filterlocal'] = '1'; - $plink = $skin->link( $title, $prev, $attr, $q ); + $plink = Linker::link( $title, $prev, $attr, $q ); } else { $plink = $prev; } @@ -199,7 +187,7 @@ class SpecialGlobalFileUsage extends SpecialPage { $q = array( 'limit' => $limit, 'from' => $from, 'target' => $target ); if ( $this->filterLocal ) $q['filterlocal'] = '1'; - $nlink = $skin->link( $title, $next, $attr, $q ); + $nlink = Linker::link( $title, $next, $attr, $q ); } else { $nlink = $next; } @@ -207,7 +195,7 @@ class SpecialGlobalFileUsage extends SpecialPage { # Make links to set number of items per page $numLinks = array(); foreach ( array( 20, 50, 100, 250, 500 ) as $num ) { - $fmtLimit = $wgLang->formatNum( $num ); + $fmtLimit = $lang->formatNum( $num ); $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target ); if ( $this->filterLocal ) @@ -215,9 +203,9 @@ class SpecialGlobalFileUsage extends SpecialPage { $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num ); $attr = array( 'title' => $lTitle, 'class' => 'mw-numlink' ); - $numLinks[] = $skin->link( $title, $fmtLimit, $attr, $q ); + $numLinks[] = Linker::link( $title, $fmtLimit, $attr, $q ); } - $nums = $wgLang->pipeList( $numLinks ); + $nums = $lang->pipeList( $numLinks ); return wfMsgHtml( 'viewprevnext', $plink, $nlink, $nums ); }