* Use local context instead of global variables
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 8 Sep 2011 17:34:24 +0000 (17:34 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Thu, 8 Sep 2011 17:34:24 +0000 (17:34 +0000)
* Call Linker methods statically
* Fixed call to non-existing method Linker::makeImageLinkObj()

includes/specials/SpecialGlobalFileUsage.php

index 4c25eb6..97aa441 100644 (file)
@@ -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<p>" . Xml::checkLabel( wfMsg( 'globalfileusage-filterlocal' ),
                                        'filterlocal', 'mw-filterlocal', $this->filterLocal ) . '</p>';
 
-               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</form>";
 
-               $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( '<div id="mw-globalfileusage-result">' );
+               $out->addHtml( '<div id="mw-globalfileusage-result">' );
                foreach ( $query->getSingleResult() as $wiki => $result ) {
-                       $wgOut->addHtml(
+                       $out->addHtml(
                                        '<h2>' . wfMsgExt(
                                                'globalfileusage-on-wiki', 'parseinline',
                                                $targetName, WikiMap::getWikiName( $wiki ) )
                                        . "</h2><ul>\n" );
                        foreach ( $result as $item ) {
-                               $wgOut->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
+                               $out->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" );
                        }
-                       $wgOut->addHtml( "</ul>\n" );
+                       $out->addHtml( "</ul>\n" );
                }
-               $wgOut->addHtml( '</div>' );
+               $out->addHtml( '</div>' );
 
                // 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 );
        }