MediaWiki  REL1_22
DeleteLogFormatter.php
Go to the documentation of this file.
00001 <?php
00031 class DeleteLogFormatter extends LogFormatter {
00032     protected function getMessageKey() {
00033         $key = parent::getMessageKey();
00034         if ( in_array( $this->entry->getSubtype(), array( 'event', 'revision' ) ) ) {
00035             if ( count( $this->getMessageParameters() ) < 5 ) {
00036                 return "$key-legacy";
00037             }
00038         }
00039         return $key;
00040     }
00041 
00042     protected function getMessageParameters() {
00043         if ( isset( $this->parsedParametersDeleteLog ) ) {
00044             return $this->parsedParametersDeleteLog;
00045         }
00046 
00047         $params = parent::getMessageParameters();
00048         $subtype = $this->entry->getSubtype();
00049         if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
00050             // $params[3] here is 'revision' for page revisions, 'oldimage' for file versions, or a comma-separated list of log_ids for log entries.
00051             // $subtype here is 'revision' for page revisions and file versions, or 'event' for log entries.
00052             if (
00053                 ( $subtype === 'event' && count( $params ) === 6 ) ||
00054                 ( $subtype === 'revision' && isset( $params[3] ) && ( $params[3] === 'revision' || $params[3] === 'oldimage' ) )
00055             ) {
00056                 $paramStart = $subtype === 'revision' ? 4 : 3;
00057 
00058                 $old = $this->parseBitField( $params[$paramStart + 1] );
00059                 $new = $this->parseBitField( $params[$paramStart + 2] );
00060                 list( $hid, $unhid, $extra ) = RevisionDeleter::getChanges( $new, $old );
00061                 $changes = array();
00062                 foreach ( $hid as $v ) {
00063                     $changes[] = $this->msg( "$v-hid" )->plain();
00064                 }
00065                 foreach ( $unhid as $v ) {
00066                     $changes[] = $this->msg( "$v-unhid" )->plain();
00067                 }
00068                 foreach ( $extra as $v ) {
00069                     $changes[] = $this->msg( $v )->plain();
00070                 }
00071                 $changeText = $this->context->getLanguage()->listToText( $changes );
00072 
00073                 $newParams = array_slice( $params, 0, 3 );
00074                 $newParams[3] = $changeText;
00075                 $count = count( explode( ',', $params[$paramStart] ) );
00076                 $newParams[4] = $this->context->getLanguage()->formatNum( $count );
00077                 return $this->parsedParametersDeleteLog = $newParams;
00078             } else {
00079                 return $this->parsedParametersDeleteLog = array_slice( $params, 0, 3 );
00080             }
00081         }
00082 
00083         return $this->parsedParametersDeleteLog = $params;
00084     }
00085 
00086     protected function parseBitField( $string ) {
00087         // Input is like ofield=2134 or just the number
00088         if ( strpos( $string, 'field=' ) === 1 ) {
00089             list( , $field ) = explode( '=', $string );
00090             return (int)$field;
00091         } else {
00092             return (int)$string;
00093         }
00094     }
00095 
00096     public function getActionLinks() {
00097         $user = $this->context->getUser();
00098         if ( !$user->isAllowed( 'deletedhistory' ) || $this->entry->isDeleted( LogPage::DELETED_ACTION ) ) {
00099             return '';
00100         }
00101 
00102         switch ( $this->entry->getSubtype() ) {
00103         case 'delete': // Show undelete link
00104             if ( $user->isAllowed( 'undelete' ) ) {
00105                 $message = 'undeletelink';
00106             } else {
00107                 $message = 'undeleteviewlink';
00108             }
00109             $revert = Linker::linkKnown(
00110                 SpecialPage::getTitleFor( 'Undelete' ),
00111                 $this->msg( $message )->escaped(),
00112                 array(),
00113                 array( 'target' => $this->entry->getTarget()->getPrefixedDBkey() )
00114             );
00115             return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
00116 
00117         case 'revision': // If an edit was hidden from a page give a review link to the history
00118             $params = $this->extractParameters();
00119             if ( !isset( $params[3] ) || !isset( $params[4] ) ) {
00120                 return '';
00121             }
00122 
00123             // Different revision types use different URL params...
00124             $key = $params[3];
00125             // This is a CSV of the IDs
00126             $ids = explode( ',', $params[4] );
00127 
00128             $links = array();
00129 
00130             // If there's only one item, we can show a diff link
00131             if ( count( $ids ) == 1 ) {
00132                 // Live revision diffs...
00133                 if ( $key == 'oldid' || $key == 'revision' ) {
00134                     $links[] = Linker::linkKnown(
00135                         $this->entry->getTarget(),
00136                         $this->msg( 'diff' )->escaped(),
00137                         array(),
00138                         array(
00139                             'diff' => intval( $ids[0] ),
00140                             'unhide' => 1
00141                         )
00142                     );
00143                 // Deleted revision diffs...
00144                 } elseif ( $key == 'artimestamp' || $key == 'archive' ) {
00145                     $links[] = Linker::linkKnown(
00146                         SpecialPage::getTitleFor( 'Undelete' ),
00147                         $this->msg( 'diff' )->escaped(),
00148                         array(),
00149                         array(
00150                             'target' => $this->entry->getTarget()->getPrefixedDBkey(),
00151                             'diff' => 'prev',
00152                             'timestamp' => $ids[0]
00153                         )
00154                     );
00155                 }
00156             }
00157 
00158             // View/modify link...
00159             $links[] = Linker::linkKnown(
00160                 SpecialPage::getTitleFor( 'Revisiondelete' ),
00161                 $this->msg( 'revdel-restore' )->escaped(),
00162                 array(),
00163                 array(
00164                     'target' => $this->entry->getTarget()->getPrefixedText(),
00165                     'type' => $key,
00166                     'ids' => implode( ',', $ids ),
00167                 )
00168             );
00169 
00170             return $this->msg( 'parentheses' )->rawParams(
00171                 $this->context->getLanguage()->pipeList( $links ) )->escaped();
00172 
00173         case 'event': // Hidden log items, give review link
00174             $params = $this->extractParameters();
00175             if ( !isset( $params[3] ) ) {
00176                 return '';
00177             }
00178             // This is a CSV of the IDs
00179             $query = $params[3];
00180             // Link to each hidden object ID, $params[1] is the url param
00181             $revert = Linker::linkKnown(
00182                 SpecialPage::getTitleFor( 'Revisiondelete' ),
00183                 $this->msg( 'revdel-restore' )->escaped(),
00184                 array(),
00185                 array(
00186                     'target' => $this->entry->getTarget()->getPrefixedText(),
00187                     'type' => 'logging',
00188                     'ids' => $query
00189                 )
00190             );
00191             return $this->msg( 'parentheses' )->rawParams( $revert )->escaped();
00192         default:
00193             return '';
00194         }
00195     }
00196 }