From: Jack Phoenix Date: Tue, 22 Mar 2011 20:23:52 +0000 (+0000) Subject: coding style tweaks, doc updates, marked some public functions as such X-Git-Tag: 1.31.0-rc.0~31245 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=3b5750adb4c8bb376a7db5c471890b991060d03f coding style tweaks, doc updates, marked some public functions as such --- diff --git a/includes/Cookie.php b/includes/Cookie.php index 6d3cfd83af..10d95a7883 100644 --- a/includes/Cookie.php +++ b/includes/Cookie.php @@ -42,7 +42,7 @@ class Cookie { if ( isset( $attr['path'] ) ) { $this->path = $attr['path']; } else { - $this->path = "/"; + $this->path = '/'; } if ( isset( $attr['domain'] ) ) { @@ -50,7 +50,7 @@ class Cookie { $this->domain = $attr['domain']; } } else { - throw new MWException( "You must specify a domain." ); + throw new MWException( 'You must specify a domain.' ); } } @@ -68,7 +68,7 @@ class Cookie { */ public static function validateCookieDomain( $domain, $originDomain = null ) { // Don't allow a trailing dot - if ( substr( $domain, -1 ) == "." ) { + if ( substr( $domain, -1 ) == '.' ) { return false; } @@ -96,20 +96,20 @@ class Cookie { || ( count( $dc ) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) { return false; } - if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == "" ) ) + if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == '' ) ) && preg_match( '/(com|net|org|gov|edu)\...$/', $domain ) ) { return false; } } if ( $originDomain != null ) { - if ( substr( $domain, 0, 1 ) != "." && $domain != $originDomain ) { + if ( substr( $domain, 0, 1 ) != '.' && $domain != $originDomain ) { return false; } - if ( substr( $domain, 0, 1 ) == "." + if ( substr( $domain, 0, 1 ) == '.' && substr_compare( $originDomain, $domain, -strlen( $domain ), - strlen( $domain ), TRUE ) != 0 ) { + strlen( $domain ), true ) != 0 ) { return false; } } @@ -125,12 +125,12 @@ class Cookie { * @return String */ public function serializeToHttpRequest( $path, $domain ) { - $ret = ""; + $ret = ''; if ( $this->canServeDomain( $domain ) && $this->canServePath( $path ) && $this->isUnExpired() ) { - $ret = $this->name . "=" . $this->value; + $ret = $this->name . '=' . $this->value; } return $ret; @@ -139,9 +139,9 @@ class Cookie { protected function canServeDomain( $domain ) { if ( $domain == $this->domain || ( strlen( $domain ) > strlen( $this->domain ) - && substr( $this->domain, 0, 1 ) == "." + && substr( $this->domain, 0, 1 ) == '.' && substr_compare( $domain, $this->domain, -strlen( $this->domain ), - strlen( $this->domain ), TRUE ) == 0 ) ) { + strlen( $this->domain ), true ) == 0 ) ) { return true; } @@ -199,7 +199,7 @@ class CookieJar { } } - return implode( "; ", $cookies ); + return implode( '; ', $cookies ); } /** @@ -209,20 +209,20 @@ class CookieJar { * @param $domain String: cookie's domain */ public function parseCookieResponseHeader ( $cookie, $domain ) { - $len = strlen( "Set-Cookie:" ); + $len = strlen( 'Set-Cookie:' ); - if ( substr_compare( "Set-Cookie:", $cookie, 0, $len, TRUE ) === 0 ) { + if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true ) === 0 ) { $cookie = substr( $cookie, $len ); } - $bit = array_map( 'trim', explode( ";", $cookie ) ); + $bit = array_map( 'trim', explode( ';', $cookie ) ); if ( count( $bit ) >= 1 ) { - list( $name, $value ) = explode( "=", array_shift( $bit ), 2 ); + list( $name, $value ) = explode( '=', array_shift( $bit ), 2 ); $attr = array(); foreach ( $bit as $piece ) { - $parts = explode( "=", $piece ); + $parts = explode( '=', $piece ); if ( count( $parts ) > 1 ) { $attr[strtolower( $parts[0] )] = $parts[1]; } else { diff --git a/includes/Interwiki.php b/includes/Interwiki.php index 05412f0fd7..036cbe38de 100644 --- a/includes/Interwiki.php +++ b/includes/Interwiki.php @@ -143,7 +143,7 @@ class Interwiki { global $wgMemc, $wgInterwikiExpiry; $iwData = false; - if ( !wfRunHooks('InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) { + if ( !wfRunHooks( 'InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) { return Interwiki::loadFromArray( $iwData ); } diff --git a/includes/MWFunction.php b/includes/MWFunction.php index 1aad9754ca..53ce446ed8 100644 --- a/includes/MWFunction.php +++ b/includes/MWFunction.php @@ -19,52 +19,46 @@ */ class MWFunction { - + protected static function cleanCallback( $callback ) { - if( is_string( $callback ) ) { if ( strpos( $callback, '::' ) !== false ) { - //PHP 5.1 cannot use call_user_func( 'Class::Method' ) - //It can only handle only call_user_func( array( 'Class', 'Method' ) ) + // PHP 5.1 cannot use call_user_func( 'Class::Method' ) + // It can only handle only call_user_func( array( 'Class', 'Method' ) ) $callback = explode( '::', $callback, 2); } } - + if( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' ) { - throw new MWException( 'MWFunction cannot call self::method() or parent::method()' ); - } - + // Run autoloader (workaround for call_user_func_array bug: http://bugs.php.net/bug.php?id=51329) is_callable( $callback ); - + return $callback; } - + public static function call( $callback ) { $callback = self::cleanCallback( $callback ); - + $args = func_get_args(); - + return call_user_func_array( 'call_user_func', $args ); - } - + public static function callArray( $callback, $argsarams ) { - $callback = self::cleanCallback( $callback ); return call_user_func_array( $callback, $argsarams ); - } - + public static function newObj( $class, $args = array() ) { if( !count( $args ) ) { return new $class; } - $ref = new ReflectionClass($class); - return $ref->newInstanceArgs($args); + $ref = new ReflectionClass( $class ); + return $ref->newInstanceArgs( $args ); } } diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index 236e437099..ba11e3e643 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -15,7 +15,7 @@ class PrefixSearch { * @param $namespaces Array: used if query is not explicitely prefixed * @return Array of strings */ - public static function titleSearch( $search, $limit, $namespaces=array() ) { + public static function titleSearch( $search, $limit, $namespaces = array() ) { $search = trim( $search ); if( $search == '' ) { return array(); // Return empty result @@ -26,8 +26,9 @@ class PrefixSearch { $title = Title::newFromText( $search ); if( $title && $title->getInterwiki() == '' ) { $ns = array($title->getNamespace()); - if($ns[0] == NS_MAIN) + if( $ns[0] == NS_MAIN ) { $ns = $namespaces; // no explicit prefix, use default namespaces + } return self::searchBackend( $ns, $title->getText(), $limit ); } @@ -38,13 +39,12 @@ class PrefixSearch { && $title->getNamespace() != NS_MAIN && $title->getInterwiki() == '' ) { return self::searchBackend( - array($title->getNamespace()), '', $limit ); + array( $title->getNamespace() ), '', $limit ); } return self::searchBackend( $namespaces, $search, $limit ); } - /** * Do a prefix search of titles and return a list of matching page names. * @param $namespaces Array @@ -53,10 +53,10 @@ class PrefixSearch { * @return Array of strings */ protected static function searchBackend( $namespaces, $search, $limit ) { - if( count($namespaces) == 1 ){ + if( count( $namespaces ) == 1 ) { $ns = $namespaces[0]; if( $ns == NS_MEDIA ) { - $namespaces = array(NS_FILE); + $namespaces = array( NS_FILE ); } elseif( $ns == NS_SPECIAL ) { return self::specialSearch( $search, $limit ); } @@ -135,12 +135,13 @@ class PrefixSearch { * @return Array of title strings */ protected static function defaultSearchBackend( $namespaces, $search, $limit ) { - $ns = array_shift($namespaces); // support only one namespace - if( in_array(NS_MAIN,$namespaces)) + $ns = array_shift( $namespaces ); // support only one namespace + if( in_array( NS_MAIN, $namespaces ) ) { $ns = NS_MAIN; // if searching on many always default to main + } // Prepare nested request - $req = new FauxRequest(array ( + $req = new FauxRequest( array( 'action' => 'query', 'list' => 'allpages', 'apnamespace' => $ns, @@ -149,7 +150,7 @@ class PrefixSearch { )); // Execute - $module = new ApiMain($req); + $module = new ApiMain( $req ); $module->execute(); // Get resulting data @@ -157,7 +158,7 @@ class PrefixSearch { // Reformat useful data for future printing by JSON engine $srchres = array (); - foreach ((array)$data['query']['allpages'] as $pageinfo) { + foreach ( (array)$data['query']['allpages'] as $pageinfo ) { // Note: this data will no be printable by the xml engine // because it does not support lists of unnamed items $srchres[] = $pageinfo['title']; @@ -172,18 +173,19 @@ class PrefixSearch { * @param $namespaces Array * @return Array (default: contains only NS_MAIN) */ - protected static function validateNamespaces($namespaces){ + protected static function validateNamespaces( $namespaces ) { global $wgContLang; // We will look at each given namespace against wgContLang namespaces $validNamespaces = $wgContLang->getNamespaces(); - if( is_array($namespaces) && count($namespaces)>0 ){ + if( is_array( $namespaces ) && count( $namespaces ) > 0 ) { $valid = array(); - foreach ($namespaces as $ns){ - if( is_numeric($ns) && array_key_exists($ns, $validNamespaces) ) + foreach ( $namespaces as $ns ) { + if( is_numeric( $ns ) && array_key_exists( $ns, $validNamespaces ) ) { $valid[] = $ns; + } } - if( count($valid) > 0 ) { + if( count( $valid ) > 0 ) { return $valid; } } diff --git a/includes/ZhClient.php b/includes/ZhClient.php index a04220c6a1..5404b696fb 100644 --- a/includes/ZhClient.php +++ b/includes/ZhClient.php @@ -2,7 +2,6 @@ /** * Client for querying zhdaemon - * */ class ZhClient { var $mHost, $mPort, $mFP, $mConnected; @@ -12,7 +11,7 @@ class ZhClient { * * @access private */ - function __construct($host, $port) { + function __construct( $host, $port ) { $this->mHost = $host; $this->mPort = $port; $this->mConnected = $this->connect(); @@ -33,7 +32,7 @@ class ZhClient { function connect() { wfSuppressWarnings(); $errno = $errstr = ''; - $this->mFP = fsockopen($this->mHost, $this->mPort, $errno, $errstr, 30); + $this->mFP = fsockopen( $this->mHost, $this->mPort, $errno, $errstr, 30 ); wfRestoreWarnings(); if ( !$this->mFP ) { return false; @@ -46,30 +45,30 @@ class ZhClient { * * @access private */ - function query($request) { + function query( $request ) { if ( !$this->mConnected ) { return false; } - fwrite($this->mFP, $request); + fwrite( $this->mFP, $request ); - $result=fgets($this->mFP, 1024); + $result = fgets( $this->mFP, 1024 ); - list($status, $len) = explode(" ", $result); - if($status == 'ERROR') { - //$len is actually the error code... + list( $status, $len ) = explode( ' ', $result ); + if( $status == 'ERROR' ) { + // $len is actually the error code... print "zhdaemon error $len
\n"; return false; } - $bytesread=0; - $data=''; - while(!feof($this->mFP) && $bytesread<$len) { - $str= fread($this->mFP, $len-$bytesread); - $bytesread += strlen($str); + $bytesread = 0; + $data = ''; + while( !feof( $this->mFP ) && $bytesread < $len ) { + $str = fread( $this->mFP, $len - $bytesread ); + $bytesread += strlen( $str ); $data .= $str; } - //data should be of length $len. otherwise something is wrong - if ( strlen($data) != $len ) { + // data should be of length $len. otherwise something is wrong + if ( strlen( $data ) != $len ) { return false; } return $data; @@ -78,14 +77,14 @@ class ZhClient { /** * Convert the input to a different language variant * - * @param $text string: input text - * @param $tolang string: language variant + * @param $text String: input text + * @param $tolang String: language variant * @return string the converted text */ - function convert($text, $tolang) { - $len = strlen($text); + function convert( $text, $tolang ) { + $len = strlen( $text ); $q = "CONV $tolang $len\n$text"; - $result = $this->query($q); + $result = $this->query( $q ); if ( !$result ) { $result = $text; } @@ -95,39 +94,39 @@ class ZhClient { /** * Convert the input to all possible variants * - * @param $text string: input text + * @param $text String: input text * @return array langcode => converted_string */ - function convertToAllVariants($text) { - $len = strlen($text); + function convertToAllVariants( $text ) { + $len = strlen( $text ); $q = "CONV ALL $len\n$text"; - $result = $this->query($q); + $result = $this->query( $q ); if ( !$result ) { return false; } - list($infoline, $data) = explode('|', $result, 2); - $info = explode(";", $infoline); + list( $infoline, $data ) = explode( '|', $result, 2 ); + $info = explode( ';', $infoline ); $ret = array(); - $i=0; - foreach($info as $variant) { - list($code, $len) = explode(' ', $variant); - $ret[strtolower($code)] = substr($data, $i, $len); - $i+=$len; + $i = 0; + foreach( $info as $variant ) { + list( $code, $len ) = explode( ' ', $variant ); + $ret[strtolower( $code )] = substr( $data, $i, $len ); + $i += $len; } return $ret; } /** * Perform word segmentation * - * @param $text string: input text + * @param $text String: input text * @return string segmented text */ - function segment($text) { - $len = strlen($text); + function segment( $text ) { + $len = strlen( $text ); $q = "SEG $len\n$text"; - $result = $this->query($q); - if ( !$result ) {// fallback to character based segmentation - $result = $this->segment($text); + $result = $this->query( $q ); + if ( !$result ) { // fallback to character based segmentation + $result = $this->segment( $text ); } return $result; } @@ -136,6 +135,6 @@ class ZhClient { * Close the connection */ function close() { - fclose($this->mFP); + fclose( $this->mFP ); } } diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index 5ce148cd6a..1f6e6286c2 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -37,6 +37,7 @@ class SpecialMergeHistory extends SpecialPage { private function loadRequestParams( $request ) { global $wgUser; + $this->mAction = $request->getVal( 'action' ); $this->mTarget = $request->getVal( 'target' ); $this->mDest = $request->getVal( 'dest' ); @@ -45,7 +46,7 @@ class SpecialMergeHistory extends SpecialPage { $this->mTargetID = intval( $request->getVal( 'targetID' ) ); $this->mDestID = intval( $request->getVal( 'destID' ) ); $this->mTimestamp = $request->getVal( 'mergepoint' ); - if( !preg_match("/[0-9]{14}/",$this->mTimestamp) ) { + if( !preg_match( '/[0-9]{14}/', $this->mTimestamp ) ) { $this->mTimestamp = ''; } $this->mComment = $request->getText( 'wpComment' ); @@ -73,7 +74,7 @@ class SpecialMergeHistory extends SpecialPage { } } - function execute( $par ) { + public function execute( $par ) { global $wgOut, $wgRequest, $wgUser; if ( wfReadOnly() ) { @@ -91,7 +92,7 @@ class SpecialMergeHistory extends SpecialPage { $this->setHeaders(); $this->outputHeader(); - if( $this->mTargetID && $this->mDestID && $this->mAction=="submit" && $this->mMerge ) { + if( $this->mTargetID && $this->mDestID && $this->mAction == 'submit' && $this->mMerge ) { return $this->merge(); } @@ -109,7 +110,7 @@ class SpecialMergeHistory extends SpecialPage { ); } - if ( !$this->mDestObj instanceof Title) { + if ( !$this->mDestObj instanceof Title ) { $errors[] = wfMsgExt( 'mergehistory-invalid-destination', array( 'parse' ) ); } elseif( !$this->mDestObj->exists() ) { $errors[] = wfMsgExt( 'mergehistory-no-destination', array( 'parse' ), @@ -146,18 +147,19 @@ class SpecialMergeHistory extends SpecialPage { Html::hidden( 'submitted', '1' ) . Html::hidden( 'mergepoint', $this->mTimestamp ) . Xml::openElement( 'table' ) . - " - ".Xml::label( wfMsg( 'mergehistory-from' ), 'target' )." - ".Xml::input( 'target', 30, $this->mTarget, array('id'=>'target') )." + ' + ' . Xml::label( wfMsg( 'mergehistory-from' ), 'target' ) . ' + ' . Xml::input( 'target', 30, $this->mTarget, array( 'id' => 'target' ) ) . ' - ".Xml::label( wfMsg( 'mergehistory-into' ), 'dest' )." - ".Xml::input( 'dest', 30, $this->mDest, array('id'=>'dest') )." - " . + ' . Xml::label( wfMsg( 'mergehistory-into' ), 'dest' ) . ' + ' . Xml::input( 'dest', 30, $this->mDest, array( 'id' => 'dest' ) ) . ' + ' . Xml::submitButton( wfMsg( 'mergehistory-go' ) ) . - "" . + '' . Xml::closeElement( 'table' ) . '' . - '' ); + '' + ); } private function showHistory() { @@ -165,18 +167,27 @@ class SpecialMergeHistory extends SpecialPage { $this->sk = $wgUser->getSkin(); - $wgOut->setPagetitle( wfMsg( "mergehistory" ) ); + $wgOut->setPageTitle( wfMsg( 'mergehistory' ) ); $this->showMergeForm(); # List all stored revisions - $revisions = new MergeHistoryPager( $this, array(), $this->mTargetObj, $this->mDestObj ); + $revisions = new MergeHistoryPager( + $this, array(), $this->mTargetObj, $this->mDestObj + ); $haveRevisions = $revisions && $revisions->getNumRows() > 0; $titleObj = $this->getTitle(); $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) ); # Start the form here - $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'merge' ) ); + $top = Xml::openElement( + 'form', + array( + 'method' => 'post', + 'action' => $action, + 'id' => 'merge' + ) + ); $wgOut->addHTML( $top ); if( $haveRevisions ) { @@ -184,43 +195,46 @@ class SpecialMergeHistory extends SpecialPage { # in a nice little table $table = Xml::openElement( 'fieldset' ) . - wfMsgExt( 'mergehistory-merge', array('parseinline'), + wfMsgExt( 'mergehistory-merge', array( 'parseinline' ), $this->mTargetObj->getPrefixedText(), $this->mDestObj->getPrefixedText() ) . Xml::openElement( 'table', array( 'id' => 'mw-mergehistory-table' ) ) . - " - " . + ' + ' . Xml::label( wfMsg( 'mergehistory-reason' ), 'wpComment' ) . - " - " . - Xml::input( 'wpComment', 50, $this->mComment, array('id' => 'wpComment') ) . - " + ' + ' . + Xml::input( 'wpComment', 50, $this->mComment, array( 'id' => 'wpComment' ) ) . + '   - " . + ' . Xml::submitButton( wfMsg( 'mergehistory-submit' ), array( 'name' => 'merge', 'id' => 'mw-merge-submit' ) ) . - " - " . + ' + ' . Xml::closeElement( 'table' ) . Xml::closeElement( 'fieldset' ); $wgOut->addHTML( $table ); } - $wgOut->addHTML( "

" . wfMsgHtml( "mergehistory-list" ) . "

\n" ); + $wgOut->addHTML( + '

' . + wfMsgHtml( 'mergehistory-list' ) . "

\n" + ); if( $haveRevisions ) { $wgOut->addHTML( $revisions->getNavigationBar() ); - $wgOut->addHTML( "' ); $wgOut->addHTML( $revisions->getNavigationBar() ); } else { - $wgOut->addWikiMsg( "mergehistory-empty" ); + $wgOut->addWikiMsg( 'mergehistory-empty' ); } # Show relevant lines from the deletion log: - $wgOut->addHTML( "

" . htmlspecialchars( LogPage::logName( 'merge' ) ) . "

\n" ); + $wgOut->addHTML( '

' . htmlspecialchars( LogPage::logName( 'merge' ) ) . "

\n" ); LogEventsList::showLogExtract( $wgOut, 'merge', $this->mTargetObj->getPrefixedText() ); # When we submit, go by page ID to avoid some nasty but unlikely collisions. @@ -245,7 +259,7 @@ class SpecialMergeHistory extends SpecialPage { $last = $this->message['last']; $ts = wfTimestamp( TS_MW, $row->rev_timestamp ); - $checkBox = Xml::radio( "mergepoint", $ts, false ); + $checkBox = Xml::radio( 'mergepoint', $ts, false ); $pageLink = $this->sk->linkKnown( $rev->getTitle(), @@ -258,9 +272,9 @@ class SpecialMergeHistory extends SpecialPage { } # Last link - if( !$rev->userCan( Revision::DELETED_TEXT ) ) + if( !$rev->userCan( Revision::DELETED_TEXT ) ) { $last = $this->message['last']; - else if( isset($this->prevId[$row->rev_id]) ) + } elseif( isset( $this->prevId[$row->rev_id] ) ) { $last = $this->sk->linkKnown( $rev->getTitle(), $this->message['last'], @@ -270,10 +284,12 @@ class SpecialMergeHistory extends SpecialPage { 'oldid' => $this->prevId[$row->rev_id] ) ); + } $userLink = $this->sk->revUserTools( $rev ); - if(!is_null($size = $row->rev_len)) { + $size = $row->rev_len; + if( !is_null( $size ) ) { $stxt = $this->sk->formatRevisionSize( $size ); } $comment = $this->sk->revComment( $rev ); @@ -288,8 +304,9 @@ class SpecialMergeHistory extends SpecialPage { function getPageLink( $row, $titleObj, $ts, $target ) { global $wgLang; - if( !$this->userCan($row, Revision::DELETED_TEXT) ) { - return '' . $wgLang->timeanddate( $ts, true ) . ''; + if( !$this->userCan( $row, Revision::DELETED_TEXT ) ) { + return '' . + $wgLang->timeanddate( $ts, true ) . ''; } else { $link = $this->sk->linkKnown( $titleObj, @@ -300,8 +317,9 @@ class SpecialMergeHistory extends SpecialPage { 'timestamp' => $ts ) ); - if( $this->isDeleted($row, Revision::DELETED_TEXT) ) + if( $this->isDeleted( $row, Revision::DELETED_TEXT ) ) { $link = '' . $link . ''; + } return $link; } } @@ -313,63 +331,80 @@ class SpecialMergeHistory extends SpecialPage { # keep it consistent... $targetTitle = Title::newFromID( $this->mTargetID ); $destTitle = Title::newFromID( $this->mDestID ); - if( is_null($targetTitle) || is_null($destTitle) ) + if( is_null( $targetTitle ) || is_null( $destTitle ) ) { return false; // validate these - if( $targetTitle->getArticleId() == $destTitle->getArticleId() ) + } + if( $targetTitle->getArticleId() == $destTitle->getArticleId() ) { return false; + } # Verify that this timestamp is valid # Must be older than the destination page $dbw = wfGetDB( DB_MASTER ); # Get timestamp into DB format - $this->mTimestamp = $this->mTimestamp ? $dbw->timestamp($this->mTimestamp) : ''; + $this->mTimestamp = $this->mTimestamp ? $dbw->timestamp( $this->mTimestamp ) : ''; # Max timestamp should be min of destination page - $maxtimestamp = $dbw->selectField( 'revision', 'MIN(rev_timestamp)', - array('rev_page' => $this->mDestID ), - __METHOD__ ); + $maxtimestamp = $dbw->selectField( + 'revision', + 'MIN(rev_timestamp)', + array( 'rev_page' => $this->mDestID ), + __METHOD__ + ); # Destination page must exist with revisions if( !$maxtimestamp ) { - $wgOut->addWikiMsg('mergehistory-fail'); + $wgOut->addWikiMsg( 'mergehistory-fail' ); return false; } # Get the latest timestamp of the source - $lasttimestamp = $dbw->selectField( array('page','revision'), + $lasttimestamp = $dbw->selectField( + array( 'page', 'revision' ), 'rev_timestamp', - array('page_id' => $this->mTargetID, 'page_latest = rev_id' ), - __METHOD__ ); + array( 'page_id' => $this->mTargetID, 'page_latest = rev_id' ), + __METHOD__ + ); # $this->mTimestamp must be older than $maxtimestamp if( $this->mTimestamp >= $maxtimestamp ) { - $wgOut->addWikiMsg('mergehistory-fail'); + $wgOut->addWikiMsg( 'mergehistory-fail' ); return false; } # Update the revisions if( $this->mTimestamp ) { $timewhere = "rev_timestamp <= {$this->mTimestamp}"; - $TimestampLimit = wfTimestamp(TS_MW,$this->mTimestamp); + $timestampLimit = wfTimestamp( TS_MW, $this->mTimestamp ); } else { $timewhere = "rev_timestamp <= {$maxtimestamp}"; - $TimestampLimit = wfTimestamp(TS_MW,$lasttimestamp); + $timestampLimit = wfTimestamp( TS_MW, $lasttimestamp ); } # Do the moving... - $dbw->update( 'revision', + $dbw->update( + 'revision', array( 'rev_page' => $this->mDestID ), - array( 'rev_page' => $this->mTargetID, - $timewhere ), - __METHOD__ ); + array( 'rev_page' => $this->mTargetID, $timewhere ), + __METHOD__ + ); $count = $dbw->affectedRows(); # Make the source page a redirect if no revisions are left - $haveRevisions = $dbw->selectField( 'revision', + $haveRevisions = $dbw->selectField( + 'revision', 'rev_timestamp', array( 'rev_page' => $this->mTargetID ), __METHOD__, - array( 'FOR UPDATE' ) ); + array( 'FOR UPDATE' ) + ); if( !$haveRevisions ) { if( $this->mComment ) { - $comment = wfMsgForContent( 'mergehistory-comment', $targetTitle->getPrefixedText(), - $destTitle->getPrefixedText(), $this->mComment ); + $comment = wfMsgForContent( + 'mergehistory-comment', + $targetTitle->getPrefixedText(), + $destTitle->getPrefixedText(), + $this->mComment + ); } else { - $comment = wfMsgForContent( 'mergehistory-autocomment', $targetTitle->getPrefixedText(), - $destTitle->getPrefixedText() ); + $comment = wfMsgForContent( + 'mergehistory-autocomment', + $targetTitle->getPrefixedText(), + $destTitle->getPrefixedText() + ); } $mwRedir = MagicWord::get( 'redirect' ); $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $destTitle->getPrefixedText() . "]]\n"; @@ -389,22 +424,26 @@ class SpecialMergeHistory extends SpecialPage { 'pl_from' => $this->mDestID, 'pl_namespace' => $destTitle->getNamespace(), 'pl_title' => $destTitle->getDBkey() ), - __METHOD__ ); + __METHOD__ + ); } else { $targetTitle->invalidateCache(); // update histories } $destTitle->invalidateCache(); // update histories # Check if this did anything if( !$count ) { - $wgOut->addWikiMsg('mergehistory-fail'); + $wgOut->addWikiMsg( 'mergehistory-fail' ); return false; } # Update our logs $log = new LogPage( 'merge' ); - $log->addEntry( 'merge', $targetTitle, $this->mComment, - array($destTitle->getPrefixedText(),$TimestampLimit) ); + $log->addEntry( + 'merge', $targetTitle, $this->mComment, + array( $destTitle->getPrefixedText(), $timestampLimit ) + ); - $wgOut->addHTML( wfMsgExt( 'mergehistory-success', array('parseinline'), + $wgOut->addHTML( + wfMsgExt( 'mergehistory-success', array('parseinline'), $targetTitle->getPrefixedText(), $destTitle->getPrefixedText(), $count ) ); wfRunHooks( 'ArticleMergeComplete', array( $targetTitle, $destTitle ) ); @@ -423,9 +462,12 @@ class MergeHistoryPager extends ReverseChronologicalPager { $this->articleID = $source->getArticleID(); $dbr = wfGetDB( DB_SLAVE ); - $maxtimestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', - array('rev_page' => $dest->getArticleID() ), - __METHOD__ ); + $maxtimestamp = $dbr->selectField( + 'revision', + 'MIN(rev_timestamp)', + array( 'rev_page' => $dest->getArticleID() ), + __METHOD__ + ); $this->maxTimestamp = $maxtimestamp; parent::__construct(); @@ -442,11 +484,12 @@ class MergeHistoryPager extends ReverseChronologicalPager { $batch->addObj( Title::makeTitleSafe( NS_USER, $row->rev_user_text ) ); $batch->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->rev_user_text ) ); - $rev_id = isset($rev_id) ? $rev_id : $row->rev_id; - if( $rev_id > $row->rev_id ) + $rev_id = isset( $rev_id ) ? $rev_id : $row->rev_id; + if( $rev_id > $row->rev_id ) { $this->mForm->prevId[$rev_id] = $row->rev_id; - else if( $rev_id < $row->rev_id ) + } elseif( $rev_id < $row->rev_id ) { $this->mForm->prevId[$row->rev_id] = $rev_id; + } $rev_id = $row->rev_id; } @@ -468,9 +511,12 @@ class MergeHistoryPager extends ReverseChronologicalPager { $conds[] = 'page_id = rev_page'; $conds[] = "rev_timestamp < {$this->maxTimestamp}"; return array( - 'tables' => array('revision','page'), - 'fields' => array( 'rev_minor_edit', 'rev_timestamp', 'rev_user', 'rev_user_text', 'rev_comment', - 'rev_id', 'rev_page', 'rev_parent_id', 'rev_text_id', 'rev_len', 'rev_deleted' ), + 'tables' => array( 'revision', 'page' ), + 'fields' => array( + 'rev_minor_edit', 'rev_timestamp', 'rev_user', 'rev_user_text', + 'rev_comment', 'rev_id', 'rev_page', 'rev_parent_id', + 'rev_text_id', 'rev_len', 'rev_deleted' + ), 'conds' => $conds ); } diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 21a1df4e05..387622e438 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -35,7 +35,12 @@ class LanguageConverter { var $mTables; // 'bidirectional' 'unidirectional' 'disable' for each variant var $mManualLevel; + + /** + * @var String: memcached key name + */ var $mCacheKey; + var $mLangObj; var $mFlags; var $mDescCodeSep = ':', $mDescVarSep = ';'; @@ -52,17 +57,15 @@ class LanguageConverter { /** * Constructor * - * @param $langobj Language The Language Object + * @param $langobj Language: the Language Object * @param $maincode String: the main language code of this language * @param $variants Array: the supported variants of this language * @param $variantfallbacks Array: the fallback language of each variant * @param $flags Array: defining the custom strings that maps to the flags * @param $manualLevel Array: limit for supported variants */ - public function __construct( $langobj, $maincode, - $variants = array(), - $variantfallbacks = array(), - $flags = array(), + public function __construct( $langobj, $maincode, $variants = array(), + $variantfallbacks = array(), $flags = array(), $manualLevel = array() ) { global $wgDisabledVariants, $wgLanguageNames; $this->mLangObj = $langobj; @@ -82,7 +85,7 @@ class LanguageConverter { 'D' => 'D', // convert description (subclass implement) '-' => '-', // remove convert (not implement) 'H' => 'H', // add rule for convert code - // (but no display in placed code ) + // (but no display in placed code) 'N' => 'N' // current variant name ); $this->mFlags = array_merge( $defaultflags, $flags ); @@ -143,9 +146,7 @@ class LanguageConverter { if ( $wgUser->isLoggedIn() && !$req ) { $req = $this->getUserVariant(); - } - - elseif ( !$req ) { + } elseif ( !$req ) { $req = $this->getHeaderVariant(); } @@ -189,8 +190,7 @@ class LanguageConverter { * @return Mixed: returns the variant if it is valid, null otherwise */ protected function validateVariant( $variant = null ) { - if ( $variant !== null && - in_array( $variant, $this->mVariants ) ) { + if ( $variant !== null && in_array( $variant, $this->mVariants ) ) { return $variant; } return null; @@ -227,17 +227,18 @@ class LanguageConverter { global $wgUser; // memoizing this function wreaks havoc on parserTest.php - /* if ( $this->mUserVariant ) { */ - /* return $this->mUserVariant; */ - /* } */ + /* + if ( $this->mUserVariant ) { + return $this->mUserVariant; + } + */ - // get language variant preference from logged in users + // Get language variant preference from logged in users // Don't call this on stub objects because that causes infinite // recursion during initialisation if ( $wgUser->isLoggedIn() ) { $ret = $wgUser->getOption( 'variant' ); - } - else { + } else { // figure out user lang without constructing wgLang to avoid // infinite recursion $ret = $wgUser->getOption( 'language' ); @@ -259,13 +260,13 @@ class LanguageConverter { } // see if some supported language variant is set in the - // http header. + // HTTP header. $languages = array_keys( $wgRequest->getAcceptLang() ); if ( empty( $languages ) ) { return null; } - $fallback_languages = array(); + $fallbackLanguages = array(); foreach ( $languages as $language ) { $this->mHeaderVariant = $this->validateVariant( $language ); if ( $this->mHeaderVariant ) { @@ -277,18 +278,17 @@ class LanguageConverter { // them later. $fallbacks = $this->getVariantFallbacks( $language ); if ( is_string( $fallbacks ) ) { - $fallback_languages[] = $fallbacks; + $fallbackLanguages[] = $fallbacks; } elseif ( is_array( $fallbacks ) ) { - $fallback_languages = - array_merge( $fallback_languages, - $fallbacks ); + $fallbackLanguages = + array_merge( $fallbackLanguages, $fallbacks ); } } if ( !$this->mHeaderVariant ) { // process fallback languages now - $fallback_languages = array_unique( $fallback_languages ); - foreach ( $fallback_languages as $language ) { + $fallback_languages = array_unique( $fallbackLanguages ); + foreach ( $fallbackLanguages as $language ) { $this->mHeaderVariant = $this->validateVariant( $language ); if ( $this->mHeaderVariant ) { break; @@ -323,9 +323,9 @@ class LanguageConverter { } /* we convert everything except: - 1. html markups (anything between < and >) - 2. html entities - 3. place holders created by the parser + 1. HTML markups (anything between < and >) + 2. HTML entities + 3. placeholders created by the parser */ global $wgParser; if ( isset( $wgParser ) && $wgParser->UniqPrefix() != '' ) { @@ -334,7 +334,7 @@ class LanguageConverter { $marker = ''; } - // this one is needed when the text is inside an html markup + // this one is needed when the text is inside an HTML markup $htmlfix = '|<[^>]+$|^[^<>]*>'; // disable convert to variants between tags @@ -372,7 +372,7 @@ class LanguageConverter { // Translate any alt or title attributes inside the matched element if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element, - $elementMatches ) ) + $elementMatches ) ) { $attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] ); $changed = false; @@ -517,8 +517,8 @@ class LanguageConverter { * Auto convert a Title object to a readable string in the * preferred variant. * - *@param $title Object: a object of Title - *@return String: converted title text + * @param $title Object: a object of Title + * @return String: converted title text */ public function convertTitle( $title ) { $variant = $this->getPreferredVariant(); @@ -571,7 +571,9 @@ class LanguageConverter { */ public function convertTo( $text, $variant ) { global $wgDisableLangConversion; - if ( $wgDisableLangConversion ) return $text; + if ( $wgDisableLangConversion ) { + return $text; + } return $this->recursiveConvertTopLevel( $text, $variant ); } @@ -687,10 +689,9 @@ class LanguageConverter { } /** - * If a language supports multiple variants, it is - * possible that non-existing link in one variant - * actually exists in another variant. This function - * tries to find it. See e.g. LanguageZh.php + * If a language supports multiple variants, it is possible that + * non-existing link in one variant actually exists in another variant. + * This function tries to find it. See e.g. LanguageZh.php * * @param $link String: the name of the link * @param $nt Mixed: the title object of the link @@ -764,7 +765,7 @@ class LanguageConverter { */ public function getExtraHashOptions() { $variant = $this->getPreferredVariant(); - return '!' . $variant ; + return '!' . $variant; } /** @@ -781,8 +782,9 @@ class LanguageConverter { /** * Load conversion tables either from the cache or the disk. * @private + * @param $fromCache Boolean: load from memcached? Defaults to true. */ - function loadTables( $fromcache = true ) { + function loadTables( $fromCache = true ) { if ( $this->mTablesLoaded ) { return; } @@ -790,7 +792,7 @@ class LanguageConverter { wfProfileIn( __METHOD__ ); $this->mTablesLoaded = true; $this->mTables = false; - if ( $fromcache ) { + if ( $fromCache ) { wfProfileIn( __METHOD__ . '-cache' ); $this->mTables = $wgMemc->get( $this->mCacheKey ); wfProfileOut( __METHOD__ . '-cache' ); @@ -799,8 +801,8 @@ class LanguageConverter { || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) { wfProfileIn( __METHOD__ . '-recache' ); // not in cache, or we need a fresh reload. - // we will first load the default tables - // then update them using things in MediaWiki:Zhconversiontable/* + // We will first load the default tables + // then update them using things in MediaWiki:Conversiontable/* $this->loadDefaultTables(); foreach ( $this->mVariants as $var ) { $cached = $this->parseCachedTable( $var ); @@ -817,8 +819,7 @@ class LanguageConverter { } /** - * Hook for post processig after conversion tables are loaded. - * + * Hook for post processing after conversion tables are loaded. */ function postLoadTables() { } @@ -835,7 +836,6 @@ class LanguageConverter { $this->loadTables( false ); } - /** * Parse the conversion table stored in the cache. * @@ -846,9 +846,12 @@ class LanguageConverter { * ... * }- * - * To make the tables more manageable, subpages are allowed - * and will be parsed recursively if $recursive == true. + * To make the tables more manageable, subpages are allowed + * and will be parsed recursively if $recursive == true. * + * @param $code String: language code + * @param $subpage String: subpage name + * @param $recursive Boolean: parse subpages recursively? Defaults to true. */ function parseCachedTable( $code, $subpage = '', $recursive = true ) { static $parsed = array(); @@ -869,8 +872,10 @@ class LanguageConverter { $txt = '<Conversiontable>'; } } else { - $title = Title::makeTitleSafe( NS_MEDIAWIKI, - "Conversiontable/$code" ); + $title = Title::makeTitleSafe( + NS_MEDIAWIKI, + "Conversiontable/$code" + ); if ( $title && $title->exists() ) { $article = new Article( $title ); $txt = $article->getContents(); @@ -880,7 +885,7 @@ class LanguageConverter { } // get all subpage links of the form - // [[MediaWiki:conversiontable/zh-xx/...|...]] + // [[MediaWiki:Conversiontable/zh-xx/...|...]] $linkhead = $this->mLangObj->getNsText( NS_MEDIAWIKI ) . ':Conversiontable'; $subs = StringUtils::explode( '[[', $txt ); @@ -919,8 +924,9 @@ class LanguageConverter { $table = StringUtils::explode( ';', $stripped ); foreach ( $table as $t ) { $m = explode( '=>', $t, 3 ); - if ( count( $m ) != 2 ) + if ( count( $m ) != 2 ) { continue; + } // trim any trailling comments starting with '//' $tt = explode( '//', $m[1], 2 ); $ret[trim( $m[0] )] = trim( $tt[0] ); @@ -949,7 +955,7 @@ class LanguageConverter { * various functions in the Parser. * * @param $text String: text to be tagged for no conversion - * @param $noParse Unused (?) + * @param $noParse Boolean: unused * @return String: the tagged text */ public function markNoConversion( $text, $noParse = false ) { @@ -972,11 +978,22 @@ class LanguageConverter { /** * Hook to refresh the cache of conversion tables when - * MediaWiki:conversiontable* is updated. + * MediaWiki:Conversiontable* is updated. * @private + * + * @param $article Object: Article object + * @param $user Object: User object for the current user + * @param $text String: article text (?) + * @param $summary String: edit summary of the edit + * @param $isMinor Boolean: was the edit marked as minor? + * @param $isWatch Boolean: did the user watch this page or not? + * @param $section Unused + * @param $flags Bitfield + * @param $revision Object: new Revision object or null + * @return Boolean: true */ - function OnArticleSaveComplete( $article, $user, $text, $summary, $isminor, - $iswatch, $section, $flags, $revision ) { + function OnArticleSaveComplete( $article, $user, $text, $summary, $isMinor, + $isWatch, $section, $flags, $revision ) { $titleobj = $article->getTitle(); if ( $titleobj->getNamespace() == NS_MEDIAWIKI ) { $title = $titleobj->getDBkey(); @@ -993,7 +1010,11 @@ class LanguageConverter { /** * Armour rendered math against conversion. - * Escape special chars in parsed math text.(in most cases are img elements) + * Escape special chars in parsed math text. (in most cases are img elements) + * + * @param $text String: text to armour against conversion + * @return String: armoured text where { and } have been converted to + * { and } */ public function armourMath( $text ) { // convert '-{' and '}-' to '-{' and '}-' to prevent @@ -1295,7 +1316,7 @@ class ConverterRule { } $vmarked[] = $v; } - /*for unidirectional array fill to convert tables */ + /* for unidirectional array fill to convert tables */ if ( ( $manLevel[$v] == 'bidirectional' || $manLevel[$v] == 'unidirectional' ) && isset( $unidtable[$v] ) ) { @@ -1310,9 +1331,9 @@ class ConverterRule { /** * Parse rules and flags. - * @public + * @param $variant String: variant language code */ - function parse( $variant = NULL ) { + public function parse( $variant = null ) { if ( !$variant ) { $variant = $this->mConverter->getPreferredVariant(); } @@ -1415,58 +1436,52 @@ class ConverterRule { } /** - * @public + * @todo FIXME: code this function :) */ - function hasRules() { + public function hasRules() { // TODO: } /** * Get display text on markup -{...}- - * @public */ - function getDisplay() { + public function getDisplay() { return $this->mRuleDisplay; } /** * Get converted title. - * @public */ - function getTitle() { + public function getTitle() { return $this->mRuleTitle; } /** * Return how deal with conversion rules. - * @public */ - function getRulesAction() { + public function getRulesAction() { return $this->mRulesAction; } /** - * Get conversion table. ( bidirectional and unidirectional - * conversion table ) - * @public + * Get conversion table. (bidirectional and unidirectional + * conversion table) */ - function getConvTable() { + public function getConvTable() { return $this->mConvTable; } /** * Get conversion rules string. - * @public */ - function getRules() { + public function getRules() { return $this->mRules; } /** * Get conversion flags. - * @public */ - function getFlags() { + public function getFlags() { return $this->mFlags; } }