* Added $wgResourceLoaderDebug, a default fallback for debug mode which can be overri...
[lhc/web/wiklou.git] / includes / ImagePage.php
index bd9b281..91fd25d 100644 (file)
@@ -61,13 +61,22 @@ class ImagePage extends Article {
 
        public function view() {
                global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
+
+               $diff = $wgRequest->getVal( 'diff' );
+               $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
+
+               if ( $this->mTitle->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) {
+                       return parent::view();
+               }
+                       
                $this->loadFile();
 
                if ( $this->mTitle->getNamespace() == NS_FILE && $this->img->getRedirected() ) {
-                       if ( $this->mTitle->getDBkey() == $this->img->getName() ) {
+                       if ( $this->mTitle->getDBkey() == $this->img->getName() || isset( $diff ) ) {
                                // mTitle is the same as the redirect target so ask Article
                                // to perform the redirect for us.
-                               return Article::view();
+                               $wgRequest->setVal( 'diffonly', 'true' );
+                               return parent::view();
                        } else {
                                // mTitle is not the same as the redirect target so it is 
                                // probably the redirect page itself. Fake the redirect symbol
@@ -79,12 +88,6 @@ class ImagePage extends Article {
                        }
                }
 
-               $diff = $wgRequest->getVal( 'diff' );
-               $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
-
-               if ( $this->mTitle->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) )
-                       return Article::view();
-                       
                $this->showRedirectedFromHeader();
 
                if ( $wgShowEXIF && $this->displayImg->exists() ) {
@@ -103,7 +106,7 @@ class ImagePage extends Article {
 
                # No need to display noarticletext, we use our own message, output in openShowImage()
                if ( $this->getID() ) {
-                       Article::view();
+                       parent::view();
                } else {
                        # Just need to set the right headers
                        $wgOut->setArticleFlag( true );
@@ -140,15 +143,19 @@ class ImagePage extends Article {
                        $wgOut->addHTML( $html );
 
                if ( $showmeta ) {
-                       global $wgStylePath, $wgStyleVersion;
                        $expand = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-expand' ) ) );
                        $collapse = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
                        $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
                        $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
-                       $wgOut->addScriptFile( 'metadata.js' );
+                       $wgOut->addModules( array( 'mediawiki.legacy.metadata' ) );
                        $wgOut->addHTML(
                                "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
                }
+               
+               $css = $this->repo->getDescriptionStylesheetUrl();
+               if ( $css ) {
+                       $wgOut->addStyle( $css );
+               }
        }
        
        public function getRedirectTarget() {
@@ -226,8 +233,8 @@ class ImagePage extends Article {
        /**
         * Create the TOC
         *
-        * @param bool $metadata Whether or not to show the metadata link
-        * @return string
+        * @param $metadata Boolean: whether or not to show the metadata link
+        * @return String
         */
        protected function showTOC( $metadata ) {
                $r = array(
@@ -249,8 +256,8 @@ class ImagePage extends Article {
         *
         * FIXME: bad interface, see note on MediaHandler::formatMetadata().
         *
-        * @param array $exif The array containing the EXIF data
-        * @return string
+        * @param $metadata Array: the array containing the EXIF data
+        * @return String
         */
        protected function makeMetadataTable( $metadata ) {
                $r = "<div class=\"mw-imagepage-section-metadata\">";
@@ -320,9 +327,9 @@ class ImagePage extends Article {
                        } else {
                                $params = array( 'page' => $page );
                        }
-                       $width_orig = $this->displayImg->getWidth();
+                       $width_orig = $this->displayImg->getWidth( $page );
                        $width = $width_orig;
-                       $height_orig = $this->displayImg->getHeight();
+                       $height_orig = $this->displayImg->getHeight( $page );
                        $height = $height_orig;
                        $mime = $this->displayImg->getMimeType();
                        $showLink = false;
@@ -430,7 +437,6 @@ class ImagePage extends Article {
                                                'onchange' => 'document.pageselector.submit();',
                                        );
 
-                                       $option = array();
                                        for ( $i = 1; $i <= $count; $i++ ) {
                                                $options[] = Xml::option( $wgLang->formatNum( $i ), $i, $i == $page );
                                        }
@@ -523,7 +529,6 @@ EOT
                $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
                $repo = $this->img->getRepo()->getDisplayName();
 
-               $msg = '';
                if ( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-'  ) {
                        $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
                } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
@@ -626,9 +631,7 @@ EOT
                );
                $count = $dbr->numRows( $res );
                if ( $count == 0 ) {
-                       $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
-                       $wgOut->addWikiMsg( 'nolinkstoimage' );
-                       $wgOut->addHTML( "</div>\n" );
+                       $wgOut->wrapWikiMsg( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), 'nolinkstoimage' );
                        return;
                }
                
@@ -643,30 +646,40 @@ EOT
                        );
                }
 
-               $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
+               $wgOut->addHTML( Html::openElement( 'ul', array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" );
                $sk = $wgUser->getSkin();
                $count = 0;
+               $elements = array();
                while ( $s = $res->fetchObject() ) {
                        $count++;
                        if ( $count <= $limit ) {
                                // We have not yet reached the extra one that tells us there is more to fetch
-                               $link = $sk->link(
-                                       Title::makeTitle( $s->page_namespace, $s->page_title ),
-                                       null,
-                                       array(),
-                                       array(),
-                                       array( 'known', 'noclasses' )
-                               );
-                               $wgOut->addHTML( "<li>{$link}</li>\n" );
+                               $elements[] =  $s;
                        }
                }
-               $wgOut->addHTML( "</ul>\n" );
+
+               // Sort the list by namespace:title
+               usort ( $elements, array( $this, 'compare' ) );
+
+               // Create links for every element
+               foreach( $elements as $element ) {    
+                       $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
+                       $wgOut->addHTML( Html::rawElement(
+                                               'li',
+                                               array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
+                                               $link
+                                       ) . "\n"
+                       );
+
+               };
+               $wgOut->addHTML( Html::closeElement( 'ul' ) . "\n" );
                $res->free();
 
                // Add a links to [[Special:Whatlinkshere]]
-               if ( $count > $limit )
+               if ( $count > $limit ) {
                        $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() );
-               $wgOut->addHTML( "</div>\n" );
+               }
+               $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" );
        }
        
        protected function imageRedirects() {
@@ -745,7 +758,7 @@ EOT
                $this->loadFile();
                if ( !$this->img->exists() || !$this->img->isLocal() || $this->img->getRedirected() ) {
                        // Standard article deletion
-                       Article::delete();
+                       parent::delete();
                        return;
                }
                $deleter = new FileDeleteForm( $this->img );
@@ -793,6 +806,22 @@ EOT
                $wgOut->addWikiText( $description );
        }
 
+
+       /**
+        * Callback for usort() to do link sorts by (namespace, title)
+        * Function copied from Title::compare()
+        * 
+        * @param $a object page to compare with
+        * @param $b object page to compare with
+        * @return Integer: result of string comparison, or namespace comparison
+        */
+       protected function compare( $a, $b ) {
+               if ( $a->page_namespace == $b->page_namespace ) {
+                       return strcmp( $a->page_title, $b->page_title );
+               } else {
+                       return $a->page_namespace - $b->page_namespace;
+               }
+       }
 }
 
 /**
@@ -848,7 +877,7 @@ class ImageHistoryList {
        }
 
        public function imageHistoryLine( $iscur, $file ) {
-               global $wgUser, $wgLang, $wgContLang, $wgTitle;
+               global $wgUser, $wgLang;
 
                $timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
                $img = $iscur ? $file->getName() : $file->getArchiveName();
@@ -857,7 +886,7 @@ class ImageHistoryList {
                $description = $file->getDescription();
 
                $local = $this->current->isLocal();
-               $row = $css = $selected = '';
+               $row = $selected = '';
 
                // Deletion link
                if ( $local && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ) {
@@ -886,7 +915,7 @@ class ImageHistoryList {
                                        list( $ts, $name ) = explode( '!', $img, 2 );
                                        $query = array(
                                                'type'   => 'oldimage',
-                                               'target' => $wgTitle->getPrefixedText(),
+                                               'target' => $this->title->getPrefixedText(),
                                                'ids'    => $ts,
                                        );
                                        $del = $this->skin->revDeleteLink( $query,
@@ -936,7 +965,7 @@ class ImageHistoryList {
                                $wgLang->timeAndDate( $timestamp, true ),
                                array(),
                                array(
-                                       'target' => $wgTitle->getPrefixedText(),
+                                       'target' => $this->title->getPrefixedText(),
                                        'file' => $img,
                                        'token' => $wgUser->editToken( $img )
                                ),