UpdatedDefinitionAid.php

Go to the documentation of this file.
00001 <?php
00018 class UpdatedDefinitionAid extends TranslationAid {
00019     public function getData() {
00020         $db = wfGetDB( DB_MASTER );
00021         $conds = array(
00022             'rt_page' => $this->handle->getTitle()->getArticleID(),
00023             'rt_type' => RevTag::getType( 'tp:transver' ),
00024         );
00025         $options = array(
00026             'ORDER BY' => 'rt_revision DESC',
00027         );
00028 
00029         $translationRevision = $db->selectField( 'revtag', 'rt_value', $conds, __METHOD__, $options );
00030         if ( $translationRevision === false ) {
00031             throw new TranslationHelperException( "No definition revision recorded" );
00032         }
00033 
00034         $definitionTitle = Title::makeTitleSafe(
00035             $this->handle->getTitle()->getNamespace(),
00036             $this->handle->getKey() . '/' . $this->group->getSourceLanguage()
00037         );
00038 
00039         if ( !$definitionTitle || !$definitionTitle->exists() ) {
00040             throw new TranslationHelperException( "Definition page doesn't exist" );
00041         }
00042 
00043         // Using newFromId instead of newFromTitle, because the page might have been renamed
00044         $oldrev = Revision::newFromId( $translationRevision );
00045         if ( !$oldrev ) {
00046             throw new TranslationHelperException( "Old definition version doesn't exist anymore" );
00047         }
00048 
00049         $oldtext = $oldrev->getText();
00050         $newtext = $this->getDefinition();
00051 
00052         if ( $oldtext === $newtext ) {
00053             throw new TranslationHelperException( "No changes" );
00054         }
00055 
00056         $diff = new DifferenceEngine;
00057         if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) {
00058             $diff->setTextLanguage( $this->group->getSourceLanguage() );
00059         }
00060         $diff->setText( $oldtext, $newtext );
00061         $diff->setReducedLineNumbers();
00062         $diff->showDiffStyle();
00063 
00064         $html = $diff->getDiff(
00065             $this->context->msg( 'tpt-diff-old' )->escaped(),
00066             $this->context->msg( 'tpt-diff-new' )->escaped()
00067         );
00068 
00069         return array(
00070             'value_old' => $oldtext,
00071             'value_new' => $newtext,
00072             'revisionid_old' => $oldrev->getId(),
00073             'revisionid_new' => $definitionTitle->getLatestRevId(),
00074             'language' => $this->group->getSourceLanguage(),
00075             'html' => $html,
00076         );
00077     }
00078 }
Generated on Tue Oct 29 00:00:25 2013 for MediaWiki Translate Extension by  doxygen 1.6.3