createCheckIndex.php

Go to the documentation of this file.
00001 <?php
00012 // Standard boilerplate to define $IP
00013 if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
00014     $IP = getenv( 'MW_INSTALL_PATH' );
00015 } else {
00016     $dir = __DIR__;
00017     $IP = "$dir/../../..";
00018 }
00019 require_once "$IP/maintenance/Maintenance.php";
00020 
00021 class CreateCheckIndex extends Maintenance {
00022     public function __construct() {
00023         parent::__construct();
00024         $this->mDescription = 'Creates serialised database of messages that need ' .
00025             'checking for problems.';
00026         $this->addOption(
00027             'group',
00028             '(optional) Comma separated list of group IDs to process (can use * as wildcard). ' .
00029             'Default: "*"',
00030             false, /*required*/
00031             true /*has arg*/
00032         );
00033     }
00034 
00035     public function execute() {
00036         $codes = Language::fetchLanguageNames( false );
00037 
00038         // Exclude the documentation language code
00039         global $wgTranslateDocumentationLanguageCode;
00040         if ( $wgTranslateDocumentationLanguageCode ) {
00041             unset( $codes[$wgTranslateDocumentationLanguageCode] );
00042         }
00043 
00044         $reqGroups = $this->getOption( 'group' );
00045         if ( $reqGroups ) {
00046             $reqGroups = explode( ',', $reqGroups );
00047             $reqGroups = array_map( 'trim', $reqGroups );
00048             $reqGroups = MessageGroups::expandWildcards( $reqGroups );
00049         }
00050 
00051         $verbose = isset( $options['verbose'] );
00052 
00053         $groups = MessageGroups::singleton()->getGroups();
00054 
00056         foreach ( $groups as $g ) {
00057             $id = $g->getId();
00058             $sourceLanguage = $g->getSourceLanguage();
00059 
00060             // Skip groups that are not requested
00061             if ( $reqGroups && !in_array( $id, $reqGroups ) ) {
00062                 unset( $g );
00063                 continue;
00064             }
00065 
00066             $checker = $g->getChecker();
00067             if ( !$checker ) {
00068                 unset( $g );
00069                 continue;
00070             }
00071 
00072             // Initialise messages, using unique definitions if appropriate
00073             $collection = $g->initCollection( $sourceLanguage, true );
00074             if ( !count( $collection ) ) {
00075                 continue;
00076             }
00077 
00078             $this->output( "Working with $id: ", $id );
00079 
00080             // Skip source language code
00081             $langCodes = $codes;
00082             unset( $langCodes[$sourceLanguage] );
00083 
00084             $langCodes = array_keys( $langCodes );
00085             sort( $langCodes );
00086 
00087             foreach ( $langCodes as $code ) {
00088                 $this->output( "$code ", $id );
00089 
00090                 $problematic = array();
00091 
00092                 $collection->resetForNewLanguage( $code );
00093                 $collection->loadTranslations();
00094 
00095                 global $wgContLang;
00096 
00097                 foreach ( $collection as $key => $message ) {
00098                     $prob = $checker->checkMessageFast( $message, $code );
00099                     if ( $prob ) {
00100 
00101                         if ( $verbose ) {
00102                             // Print it
00103                             $nsText = $wgContLang->getNsText( $g->namespaces[0] );
00104                             $this->output( "# [[$nsText:$key/$code]]\n" );
00105                         }
00106 
00107                         // Add it to the array
00108                         $problematic[] = array( $g->namespaces[0], "$key/$code" );
00109                     }
00110                 }
00111 
00112                 self::tagFuzzy( $problematic );
00113             }
00114         }
00115     }
00116 
00117     static function tagFuzzy( $problematic ) {
00118         if ( !count( $problematic ) ) {
00119             return;
00120         }
00121 
00122         $db = wfGetDB( DB_MASTER );
00123         foreach ( $problematic as $p ) {
00124             $title = Title::makeTitleSafe( $p[0], $p[1] );
00125             $titleText = $title->getDBKey();
00126             $res = $db->select( 'page', array( 'page_id', 'page_latest' ),
00127                 array( 'page_namespace' => $p[0], 'page_title' => $titleText ), __METHOD__ );
00128 
00129             $inserts = array();
00130             foreach ( $res as $r ) {
00131                 $inserts = array(
00132                     'rt_page' => $r->page_id,
00133                     'rt_revision' => $r->page_latest,
00134                     'rt_type' => RevTag::getType( 'fuzzy' )
00135                 );
00136             }
00137             $db->replace( 'revtag', 'rt_type_page_revision', $inserts, __METHOD__ );
00138         }
00139     }
00140 }
00141 
00142 $maintClass = 'CreateCheckIndex';
00143 require_once RUN_MAINTENANCE_IF_MAIN;
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3