(bug 973) quickie brake for images with many many uses
[lhc/web/wiklou.git] / includes / ImagePage.php
index 1a3b938..139f024 100644 (file)
@@ -80,10 +80,10 @@ class ImagePage extends Article {
                        } else {
                                $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
                        }
+                       $wgOut->addHTML( $s );
                        if($this->img->fromSharedDirectory) {
-                               $s.="<div class=\"sharedUploadNotice\">".wfMsg("sharedupload")."</div>";
+                               $wgOut->addWikiText("<div class=\"sharedUploadNotice\">".wfMsg("sharedupload")."</div>");
                        }
-                       $wgOut->addHTML( $s );
                }
        }
        
@@ -105,17 +105,18 @@ class ImagePage extends Article {
                $line = $this->img->nextHistoryLine();
 
                if ( $line ) {
-                       $s = $sk->beginImageHistoryList() .
-                               $sk->imageHistoryLine( true, $line->img_timestamp,
+                       $list =& new ImageHistoryList( $sk );
+                       $s = $list->beginImageHistoryList() .
+                               $list->imageHistoryLine( true, $line->img_timestamp,
                                        $this->mTitle->getDBkey(),  $line->img_user,
                                        $line->img_user_text, $line->img_size, $line->img_description );
 
                        while ( $line = $this->img->nextHistoryLine() ) {
-                               $s .= $sk->imageHistoryLine( false, $line->img_timestamp,
+                               $s .= $list->imageHistoryLine( false, $line->img_timestamp,
                                $line->oi_archive_name, $line->img_user,
                                $line->img_user_text, $line->img_size, $line->img_description );
                        }
-                       $s .= $sk->endImageHistoryList();
+                       $s .= $list->endImageHistoryList();
                } else { $s=''; }
                $wgOut->addHTML( $s );
        }
@@ -131,7 +132,8 @@ class ImagePage extends Article {
                $imagelinks = $dbr->tableName( 'imagelinks' );
                
                $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
-                 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id";
+                 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id"
+                 . " LIMIT 500"; # quickie emergency brake
                $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
 
                if ( 0 == $dbr->numRows( $res ) ) {
@@ -370,5 +372,79 @@ class ImagePage extends Article {
        }
 }
 
+class ImageHistoryList {
+       function ImageHistoryList( &$skin ) {
+               $this->skin =& $skin;
+       }
+       
+       function beginImageHistoryList() {
+               $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
+                 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
+               return $s;
+       }
+
+       function endImageHistoryList() {
+               $s = "</ul>\n";
+               return $s;
+       }
+
+       function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
+               global $wgUser, $wgLang, $wgContLang, $wgTitle;
+
+               $datetime = $wgLang->timeanddate( $timestamp, true );
+               $del = wfMsg( 'deleteimg' );
+               $delall = wfMsg( 'deleteimgcompletely' );
+               $cur = wfMsg( 'cur' );
+
+               if ( $iscur ) {
+                       $url = Image::wfImageUrl( $img );
+                       $rlink = $cur;
+                       if ( $wgUser->isAllowed('delete') ) {
+                               $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
+                                 '&action=delete' );
+                               $style = $this->skin->getInternalLinkAttributes( $link, $delall );
+
+                               $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
+                       } else {
+                               $dlink = $del;
+                       }
+               } else {
+                       $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
+                       if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
+                               $rlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+                                          wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
+                                          urlencode( $img ) );
+                               $dlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+                                          $del, 'action=delete&oldimage=' . urlencode( $img ) );
+                       } else {
+                               # Having live active links for non-logged in users
+                               # means that bots and spiders crawling our site can
+                               # inadvertently change content. Baaaad idea.
+                               $rlink = wfMsg( 'revertimg' );
+                               $dlink = $del;
+                       }
+               }
+               if ( 0 == $user ) {
+                       $userlink = $usertext;
+               } else {
+                       $userlink = $this->skin->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
+                                      ':'.$usertext, $usertext );
+               }
+               $nbytes = wfMsg( 'nbytes', $size );
+               $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
+
+               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
+                 . " . . {$userlink} ({$nbytes})";
+
+               if ( '' != $description && '*' != $description ) {
+                       $sk=$wgUser->getSkin();
+                       $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
+               }
+               $s .= "</li>\n";
+               return $s;
+       }
+
+}
+
 
 ?>