includes/log.php
changeset 912 95d0d8596c87
parent 909 94c1ff984286
child 913 3ec535acd11e
equal deleted inserted replaced
911:facff435cdaa 912:95d0d8596c87
   162    * @param int Offset, defaults to 0
   162    * @param int Offset, defaults to 0
   163    * @param int Page size, if 0 (default) returns entire table (danger Will Robinson!)
   163    * @param int Page size, if 0 (default) returns entire table (danger Will Robinson!)
   164    * @return array
   164    * @return array
   165    */
   165    */
   166   
   166   
   167   public function get_data($offset, $page_size)
   167   public function get_data($offset = 0, $page_size = 0)
   168   {
   168   {
   169     global $db, $session, $paths, $session, $plugins; // Common objects
   169     global $db, $session, $paths, $session, $plugins; // Common objects
   170     $sql = $this->build_sql($offset, $page_size);
   170     $sql = $this->build_sql($offset, $page_size);
   171     if ( !$db->sql_query($sql) )
   171     if ( !$db->sql_query($sql) )
   172       $db->_die();
   172       $db->_die();
   268   }
   268   }
   269   
   269   
   270   /**
   270   /**
   271    * Formats a result row into pretty HTML.
   271    * Formats a result row into pretty HTML.
   272    * @param array dataset from LogDisplay::get_data()
   272    * @param array dataset from LogDisplay::get_data()
       
   273    * @param bool If true (default), shows action buttons.
       
   274    * @param bool If true (default), shows page title; good for integrated displays
   273    * @static
   275    * @static
   274    * @return string
   276    * @return string
   275    */
   277    */
   276   
   278   
   277   public static function render_row($row)
   279   public static function render_row($row, $show_buttons = true, $show_pagetitle = true)
   278   {
   280   {
   279     global $db, $session, $paths, $session, $plugins; // Common objects
   281     global $db, $session, $paths, $session, $plugins; // Common objects
   280     global $lang;
   282     global $lang;
   281     
   283     
   282     $html = '';
   284     $html = '';
   283     
   285     
   284     $pagekey = ( isset($paths->nslist[$row['namespace']]) ) ? $paths->nslist[$row['namespace']] . $row['page_id'] : $row['namespace'] . ':' . $row['page_id'];
   286     $pagekey = ( isset($paths->nslist[$row['namespace']]) ) ? $paths->nslist[$row['namespace']] . $row['page_id'] : $row['namespace'] . ':' . $row['page_id'];
   285     $pagekey = sanitize_page_id($pagekey);
   287     $pagekey = sanitize_page_id($pagekey);
   286     
   288     
   287     // diff button
   289     // diff button
   288     if ( $row['action'] == 'edit' && !empty($row['parent_revid']) )
   290     if ( $show_buttons )
   289     {
   291     {
       
   292       if ( $row['action'] == 'edit' && !empty($row['parent_revid']) )
       
   293       {
       
   294         $html .= '(';
       
   295         if ( isPage($pagekey) )
       
   296         {
       
   297           $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=diff&diff1={$row['parent_revid']}&diff2={$row['log_id']}", true) . '">';
       
   298         }
       
   299         $html .= $lang->get('pagetools_rc_btn_diff');
       
   300         if ( isPage($pagekey) )
       
   301         {
       
   302           $html .= '</a>';
       
   303         }
       
   304         if ( $row['parent_revid'] > 0 && isPage($pagekey) )
       
   305         {
       
   306           $html .= ', <a href="' . makeUrlNS($row['namespace'], $row['page_id'], false, true) . '#do:edit;rev:' . $row['parent_revid'] . '">' . $lang->get('pagetools_rc_btn_undo') . '</a>';
       
   307         }
       
   308         $html .= ') ';
       
   309       }
       
   310       else if ( $row['action'] != 'edit' && ( isPage($pagekey) || $row['action'] == 'delete' ) )
       
   311       {
       
   312         $html .= '(';
       
   313         $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=rollback&id={$row['log_id']}", true). '">' . $lang->get('pagetools_rc_btn_undo') . '</a>';
       
   314         $html .= ') ';
       
   315       }
       
   316       
       
   317       // hist button
   290       $html .= '(';
   318       $html .= '(';
   291       if ( isPage($pagekey) )
   319       if ( isPage($pagekey) )
   292       {
   320       {
   293         $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=diff&diff1={$row['parent_revid']}&diff2={$row['log_id']}", true) . '">';
   321         $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=history", true) . '">';
   294       }
   322       }
   295       $html .= $lang->get('pagetools_rc_btn_diff');
   323       $html .= $lang->get('pagetools_rc_btn_hist');
   296       if ( isPage($pagekey) )
   324       if ( isPage($pagekey) )
   297       {
   325       {
   298         $html .= '</a>';
   326         $html .= '</a>';
   299       }
   327       }
   300       if ( $row['parent_revid'] > 0 && isPage($pagekey) )
   328       $html .= ') . . ';
   301       {
   329     }
   302         $html .= ', <a href="' . makeUrlNS($row['namespace'], $row['page_id'], false, true) . '#do:edit;rev:' . $row['parent_revid'] . '">' . $lang->get('pagetools_rc_btn_undo') . '</a>';
   330     
   303       }
   331     if ( $show_pagetitle )
   304       $html .= ') ';
   332     {
   305     }
   333       // new page?
   306     
   334       if ( $row['action'] == 'edit' && empty($row['parent_revid']) )
   307     // hist button
   335       {
   308     $html .= '(';
   336         $html .= '<b>N</b> ';
   309     if ( isPage($pagekey) )
   337       }
   310     {
   338       // minor edit?
   311       $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id'], "do=history", true) . '">';
   339       if ( $row['action'] == 'edit' && $row['minor_edit'] )
   312     }
   340       {
   313     $html .= $lang->get('pagetools_rc_btn_hist');
   341         $html .= '<b>m</b> ';
   314     if ( isPage($pagekey) )
   342       }
   315     {
   343       
   316       $html .= '</a>';
   344       // link to the page
   317     }
   345       $cls = ( isPage($pagekey) ) ? '' : ' class="wikilink-nonexistent"';
   318     $html .= ') . . ';
   346       $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id']) . '"' . $cls . '>' . htmlspecialchars(get_page_title_ns($row['page_id'], $row['namespace'])) . '</a>; ';
   319     
   347     }
   320     // new page?
       
   321     if ( $row['action'] == 'edit' && empty($row['parent_revid']) )
       
   322     {
       
   323       $html .= '<b>N</b> ';
       
   324     }
       
   325     // minor edit?
       
   326     if ( $row['action'] == 'edit' && $row['minor_edit'] )
       
   327     {
       
   328       $html .= '<b>m</b> ';
       
   329     }
       
   330     
       
   331     // link to the page
       
   332     $cls = ( isPage($pagekey) ) ? '' : ' class="wikilink-nonexistent"';
       
   333     $html .= '<a href="' . makeUrlNS($row['namespace'], $row['page_id']) . '"' . $cls . '>' . htmlspecialchars(get_page_title_ns($row['page_id'], $row['namespace'])) . '</a>; ';
       
   334     
   348     
   335     // date
   349     // date
   336     $today = time() - ( time() % 86400 );
   350     $today = time() - ( time() % 86400 );
   337     $date = MemberlistFormatter::format_date($row['time_id']) . ' ';
   351     $date = MemberlistFormatter::format_date($row['time_id']) . ' ';
   338     $date .= date('h:i:s', $row['time_id']);
   352     $date .= date('h:i:s', $row['time_id']);
   393           break;
   407           break;
   394         case 'prot':
   408         case 'prot':
   395         case 'unprot':
   409         case 'unprot':
   396         case 'semiprot':
   410         case 'semiprot':
   397         case 'delete':
   411         case 'delete':
       
   412         case 'reupload':
   398           $stringmap = array(
   413           $stringmap = array(
   399             'prot' => 'log_action_protect_full',
   414             'prot' => 'log_action_protect_full',
   400             'unprot' => 'log_action_protect_none',
   415             'unprot' => 'log_action_protect_none',
   401             'semiprot' => 'log_action_protect_semi',
   416             'semiprot' => 'log_action_protect_semi',
   402             'delete' => 'log_action_delete'
   417             'delete' => 'log_action_delete',
       
   418             'reupload' => 'log_action_reupload'
   403           );
   419           );
   404         
   420         
   405         if ( $row['edit_summary'] === '__REVERSION__' )
   421         if ( $row['edit_summary'] === '__REVERSION__' )
   406            $reason = '<span style="color: #808080;">' . $lang->get('log_msg_reversion') . '</span>';
   422           $reason = '<span style="color: #808080;">' . $lang->get('log_msg_reversion') . '</span>';
       
   423         else if ( $row['action'] == 'reupload' && $row['edit_summary'] === '__ROLLBACK__' )
       
   424           $reason = '<span style="color: #808080;">' . $lang->get('log_msg_file_restored') . '</span>';
   407         else
   425         else
   408           $reason = ( !empty($row['edit_summary']) ) ? htmlspecialchars($row['edit_summary']) : '<span style="color: #808080;">' . $lang->get('log_msg_no_reason_provided') . '</span>';
   426           $reason = ( !empty($row['edit_summary']) ) ? htmlspecialchars($row['edit_summary']) : '<span style="color: #808080;">' . $lang->get('log_msg_no_reason_provided') . '</span>';
   409         
   427         
   410         $html .= $lang->get($stringmap[$row['action']], array('reason' => $reason));
   428         $html .= $lang->get($stringmap[$row['action']], array('reason' => $reason));
   411       }
   429       }