MediaWiki  1.23.2
ORMTable.php
Go to the documentation of this file.
1 <?php
31 class ORMTable extends DBAccessBase implements IORMTable {
40  protected static $instanceCache = array();
41 
47  protected $tableName;
48 
54  protected $fields = array();
55 
61  protected $fieldPrefix = '';
62 
68  protected $rowClass = 'ORMRow';
69 
75  protected $defaults = array();
76 
85  protected $readDb = DB_SLAVE;
86 
98  public function __construct( $tableName = '', array $fields = array(),
99  array $defaults = array(), $rowClass = null, $fieldPrefix = ''
100  ) {
101  $this->tableName = $tableName;
102  $this->fields = $fields;
103  $this->defaults = $defaults;
104 
105  if ( is_string( $rowClass ) ) {
106  $this->rowClass = $rowClass;
107  }
108 
109  $this->fieldPrefix = $fieldPrefix;
110  }
111 
120  public function getName() {
121  if ( $this->tableName === '' ) {
122  throw new MWException( 'The table name needs to be set' );
123  }
124 
125  return $this->tableName;
126  }
127 
135  protected function getFieldPrefix() {
136  return $this->fieldPrefix;
137  }
138 
146  public function getRowClass() {
147  return $this->rowClass;
148  }
149 
158  public function getFields() {
159  if ( $this->fields === array() ) {
160  throw new MWException( 'The table needs to have one or more fields' );
161  }
162 
163  return $this->fields;
164  }
165 
174  public function getDefaults() {
175  return $this->defaults;
176  }
177 
187  public function getSummaryFields() {
188  return array();
189  }
190 
204  public function select( $fields = null, array $conditions = array(),
205  array $options = array(), $functionName = null
206  ) {
207  $res = $this->rawSelect( $fields, $conditions, $options, $functionName );
208 
209  return new ORMResult( $this, $res );
210  }
211 
226  public function selectObjects( $fields = null, array $conditions = array(),
227  array $options = array(), $functionName = null
228  ) {
229  $result = $this->selectFields( $fields, $conditions, $options, false, $functionName );
230 
231  $objects = array();
232 
233  foreach ( $result as $record ) {
234  $objects[] = $this->newRow( $record );
235  }
236 
237  return $objects;
238  }
239 
253  public function rawSelect( $fields = null, array $conditions = array(),
254  array $options = array(), $functionName = null
255  ) {
256  if ( is_null( $fields ) ) {
257  $fields = array_keys( $this->getFields() );
258  } else {
259  $fields = (array)$fields;
260  }
261 
262  $dbr = $this->getReadDbConnection();
263  $result = $dbr->select(
264  $this->getName(),
265  $this->getPrefixedFields( $fields ),
266  $this->getPrefixedValues( $conditions ),
267  is_null( $functionName ) ? __METHOD__ : $functionName,
268  $options
269  );
270 
271  /* @var Exception $error */
272  $error = null;
273 
274  if ( $result === false ) {
275  // Database connection was in "ignoreErrors" mode. We don't like that.
276  // So, we emulate the DBQueryError that should have been thrown.
277  $error = new DBQueryError(
278  $dbr,
279  $dbr->lastError(),
280  $dbr->lastErrno(),
281  $dbr->lastQuery(),
282  is_null( $functionName ) ? __METHOD__ : $functionName
283  );
284  }
285 
286  $this->releaseConnection( $dbr );
287 
288  if ( $error ) {
289  // Note: construct the error before releasing the connection,
290  // but throw it after.
291  throw $error;
292  }
293 
294  return $result;
295  }
296 
319  public function selectFields( $fields = null, array $conditions = array(),
320  array $options = array(), $collapse = true, $functionName = null
321  ) {
322  $objects = array();
323 
324  $result = $this->rawSelect( $fields, $conditions, $options, $functionName );
325 
326  foreach ( $result as $record ) {
327  $objects[] = $this->getFieldsFromDBResult( $record );
328  }
329 
330  if ( $collapse ) {
331  if ( count( $fields ) === 1 ) {
332  $objects = array_map( 'array_shift', $objects );
333  } elseif ( count( $fields ) === 2 ) {
334  $o = array();
335 
336  foreach ( $objects as $object ) {
337  $o[array_shift( $object )] = array_shift( $object );
338  }
339 
340  $objects = $o;
341  }
342  }
343 
344  return $objects;
345  }
346 
360  public function selectRow( $fields = null, array $conditions = array(),
361  array $options = array(), $functionName = null
362  ) {
363  $options['LIMIT'] = 1;
364 
365  $objects = $this->select( $fields, $conditions, $options, $functionName );
366 
367  return ( !$objects || $objects->isEmpty() ) ? false : $objects->current();
368  }
369 
383  public function rawSelectRow( array $fields, array $conditions = array(),
384  array $options = array(), $functionName = null
385  ) {
386  $dbr = $this->getReadDbConnection();
387 
388  $result = $dbr->selectRow(
389  $this->getName(),
390  $fields,
391  $conditions,
392  is_null( $functionName ) ? __METHOD__ : $functionName,
393  $options
394  );
395 
396  $this->releaseConnection( $dbr );
397 
398  return $result;
399  }
400 
418  public function selectFieldsRow( $fields = null, array $conditions = array(),
419  array $options = array(), $collapse = true, $functionName = null
420  ) {
421  $options['LIMIT'] = 1;
422 
423  $objects = $this->selectFields( $fields, $conditions, $options, $collapse, $functionName );
424 
425  return empty( $objects ) ? false : $objects[0];
426  }
427 
438  public function has( array $conditions = array() ) {
439  return $this->selectRow( array( 'id' ), $conditions ) !== false;
440  }
441 
449  public function exists() {
450  $dbr = $this->getReadDbConnection();
451  $exists = $dbr->tableExists( $this->getName() );
452  $this->releaseConnection( $dbr );
453 
454  return $exists;
455  }
456 
471  public function count( array $conditions = array(), array $options = array() ) {
472  $res = $this->rawSelectRow(
473  array( 'rowcount' => 'COUNT(*)' ),
474  $this->getPrefixedValues( $conditions ),
475  $options,
476  __METHOD__
477  );
478 
479  return $res->rowcount;
480  }
481 
492  public function delete( array $conditions, $functionName = null ) {
493  $dbw = $this->getWriteDbConnection();
494 
495  $result = $dbw->delete(
496  $this->getName(),
497  $conditions === array() ? '*' : $this->getPrefixedValues( $conditions ),
498  is_null( $functionName ) ? __METHOD__ : $functionName
499  ) !== false; // DatabaseBase::delete does not always return true for success as documented...
500 
501  $this->releaseConnection( $dbw );
502 
503  return $result;
504  }
505 
516  public function getAPIParams( $requireParams = false, $setDefaults = false ) {
517  $typeMap = array(
518  'id' => 'integer',
519  'int' => 'integer',
520  'float' => 'NULL',
521  'str' => 'string',
522  'bool' => 'integer',
523  'array' => 'string',
524  'blob' => 'string',
525  );
526 
527  $params = array();
528  $defaults = $this->getDefaults();
529 
530  foreach ( $this->getFields() as $field => $type ) {
531  if ( $field == 'id' ) {
532  continue;
533  }
534 
535  $hasDefault = array_key_exists( $field, $defaults );
536 
537  $params[$field] = array(
538  ApiBase::PARAM_TYPE => $typeMap[$type],
539  ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault
540  );
541 
542  if ( $type == 'array' ) {
543  $params[$field][ApiBase::PARAM_ISMULTI] = true;
544  }
545 
546  if ( $setDefaults && $hasDefault ) {
547  $default = is_array( $defaults[$field] )
548  ? implode( '|', $defaults[$field] )
549  : $defaults[$field];
550  $params[$field][ApiBase::PARAM_DFLT] = $default;
551  }
552  }
553 
554  return $params;
555  }
556 
566  public function getFieldDescriptions() {
567  return array();
568  }
569 
577  public function getReadDb() {
578  return $this->readDb;
579  }
580 
589  public function setReadDb( $db ) {
590  $this->readDb = $db;
591  }
592 
601  public function getTargetWiki() {
602  return $this->wiki;
603  }
604 
613  public function setTargetWiki( $wiki ) {
614  $this->wiki = $wiki;
615  }
616 
627  public function getReadDbConnection() {
628  return $this->getConnection( $this->getReadDb(), array() );
629  }
630 
641  public function getWriteDbConnection() {
642  return $this->getConnection( DB_MASTER, array() );
643  }
644 
655  // @codingStandardsIgnoreStart Suppress "useless method overriding" sniffer warning
656  public function releaseConnection( DatabaseBase $db ) {
657  parent::releaseConnection( $db ); // just make it public
658  }
659  // @codingStandardsIgnoreEnd
660 
673  public function update( array $values, array $conditions = array() ) {
674  $dbw = $this->getWriteDbConnection();
675 
676  $result = $dbw->update(
677  $this->getName(),
678  $this->getPrefixedValues( $values ),
679  $this->getPrefixedValues( $conditions ),
680  __METHOD__
681  ) !== false; // DatabaseBase::update does not always return true for success as documented...
682 
683  $this->releaseConnection( $dbw );
684 
685  return $result;
686  }
687 
696  public function updateSummaryFields( $summaryFields = null, array $conditions = array() ) {
697  $slave = $this->getReadDb();
698  $this->setReadDb( DB_MASTER );
699 
703  foreach ( $this->select( null, $conditions ) as $item ) {
704  $item->loadSummaryFields( $summaryFields );
705  $item->setSummaryMode( true );
706  $item->save();
707  }
708 
709  $this->setReadDb( $slave );
710  }
711 
723  public function getPrefixedValues( array $values ) {
724  $prefixedValues = array();
725 
726  foreach ( $values as $field => $value ) {
727  if ( is_integer( $field ) ) {
728  if ( is_array( $value ) ) {
729  $field = $value[0];
730  $value = $value[1];
731  } else {
732  $value = explode( ' ', $value, 2 );
733  $value[0] = $this->getPrefixedField( $value[0] );
734  $prefixedValues[] = implode( ' ', $value );
735  continue;
736  }
737  }
738 
739  $prefixedValues[$this->getPrefixedField( $field )] = $value;
740  }
741 
742  return $prefixedValues;
743  }
744 
755  public function getPrefixedFields( array $fields ) {
756  foreach ( $fields as &$field ) {
757  $field = $this->getPrefixedField( $field );
758  }
759 
760  return $fields;
761  }
762 
772  public function getPrefixedField( $field ) {
773  return $this->getFieldPrefix() . $field;
774  }
775 
785  public function unprefixFieldNames( array $fieldNames ) {
786  return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
787  }
788 
798  public function unprefixFieldName( $fieldName ) {
799  return substr( $fieldName, strlen( $this->getFieldPrefix() ) );
800  }
801 
810  public static function singleton() {
811  $class = get_called_class();
812 
813  if ( !array_key_exists( $class, self::$instanceCache ) ) {
814  self::$instanceCache[$class] = new $class;
815  }
816 
817  return self::$instanceCache[$class];
818  }
819 
831  public function getFieldsFromDBResult( stdClass $result ) {
832  $result = (array)$result;
833 
834  $rawFields = array_combine(
835  $this->unprefixFieldNames( array_keys( $result ) ),
836  array_values( $result )
837  );
838 
839  $fieldDefinitions = $this->getFields();
840  $fields = array();
841 
842  foreach ( $rawFields as $name => $value ) {
843  if ( array_key_exists( $name, $fieldDefinitions ) ) {
844  switch ( $fieldDefinitions[$name] ) {
845  case 'int':
846  $value = (int)$value;
847  break;
848  case 'float':
849  $value = (float)$value;
850  break;
851  case 'bool':
852  if ( is_string( $value ) ) {
853  $value = $value !== '0';
854  } elseif ( is_int( $value ) ) {
855  $value = $value !== 0;
856  }
857  break;
858  case 'array':
859  if ( is_string( $value ) ) {
860  $value = unserialize( $value );
861  }
862 
863  if ( !is_array( $value ) ) {
864  $value = array();
865  }
866  break;
867  case 'blob':
868  if ( is_string( $value ) ) {
869  $value = unserialize( $value );
870  }
871  break;
872  case 'id':
873  if ( is_string( $value ) ) {
874  $value = (int)$value;
875  }
876  break;
877  }
878 
879  $fields[$name] = $value;
880  } else {
881  throw new MWException( 'Attempted to set unknown field ' . $name );
882  }
883  }
884 
885  return $fields;
886  }
887 
898  public function newFromDBResult( stdClass $result ) {
900  }
901 
911  public function newRowFromDBResult( stdClass $result ) {
912  return $this->newRow( $this->getFieldsFromDBResult( $result ) );
913  }
914 
926  public function newFromArray( array $data, $loadDefaults = false ) {
927  return static::newRow( $data, $loadDefaults );
928  }
929 
940  public function newRow( array $fields, $loadDefaults = false ) {
941  $class = $this->getRowClass();
942 
943  return new $class( $this, $fields, $loadDefaults );
944  }
945 
953  public function getFieldNames() {
954  return array_keys( $this->getFields() );
955  }
956 
966  public function canHaveField( $name ) {
967  return array_key_exists( $name, $this->getFields() );
968  }
969 
980  public function updateRow( IORMRow $row, $functionName = null ) {
981  $dbw = $this->getWriteDbConnection();
982 
983  $success = $dbw->update(
984  $this->getName(),
985  $this->getWriteValues( $row ),
986  $this->getPrefixedValues( array( 'id' => $row->getId() ) ),
987  is_null( $functionName ) ? __METHOD__ : $functionName
988  );
989 
990  $this->releaseConnection( $dbw );
991 
992  // DatabaseBase::update does not always return true for success as documented...
993  return $success !== false;
994  }
995 
1007  public function insertRow( IORMRow $row, $functionName = null, array $options = null ) {
1008  $dbw = $this->getWriteDbConnection();
1009 
1010  $success = $dbw->insert(
1011  $this->getName(),
1012  $this->getWriteValues( $row ),
1013  is_null( $functionName ) ? __METHOD__ : $functionName,
1014  $options
1015  );
1016 
1017  // DatabaseBase::insert does not always return true for success as documented...
1018  $success = $success !== false;
1019 
1020  if ( $success ) {
1021  $row->setField( 'id', $dbw->insertId() );
1022  }
1023 
1024  $this->releaseConnection( $dbw );
1025 
1026  return $success;
1027  }
1028 
1038  protected function getWriteValues( IORMRow $row ) {
1039  $values = array();
1040 
1041  $rowFields = $row->getFields();
1042 
1043  foreach ( $this->getFields() as $name => $type ) {
1044  if ( array_key_exists( $name, $rowFields ) ) {
1045  $value = $rowFields[$name];
1046 
1047  switch ( $type ) {
1048  case 'array':
1049  $value = (array)$value;
1050  // fall-through!
1051  case 'blob':
1052  $value = serialize( $value );
1053  // fall-through!
1054  }
1055 
1056  $values[$this->getPrefixedField( $name )] = $value;
1057  }
1058  }
1059 
1060  return $values;
1061  }
1062 
1073  public function removeRow( IORMRow $row, $functionName = null ) {
1074  $success = $this->delete(
1075  array( 'id' => $row->getId() ),
1076  is_null( $functionName ) ? __METHOD__ : $functionName
1077  );
1078 
1079  // DatabaseBase::delete does not always return true for success as documented...
1080  return $success !== false;
1081  }
1082 
1095  public function addToField( array $conditions, $field, $amount ) {
1096  if ( !array_key_exists( $field, $this->fields ) ) {
1097  throw new MWException( 'Unknown field "' . $field . '" provided' );
1098  }
1099 
1100  if ( $amount == 0 ) {
1101  return true;
1102  }
1103 
1104  $absoluteAmount = abs( $amount );
1105  $isNegative = $amount < 0;
1106 
1107  $fullField = $this->getPrefixedField( $field );
1108 
1109  $dbw = $this->getWriteDbConnection();
1110 
1111  $success = $dbw->update(
1112  $this->getName(),
1113  array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
1114  $this->getPrefixedValues( $conditions ),
1115  __METHOD__
1116  ) !== false; // DatabaseBase::update does not always return true for success as documented...
1117 
1118  $this->releaseConnection( $dbw );
1119 
1120  return $success;
1121  }
1122 }
ORMResult
Definition: ORMResult.php:32
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
ORMTable\getWriteDbConnection
getWriteDbConnection()
Get the database type used for read operations.
Definition: ORMTable.php:635
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
IORMRow
Definition: IORMRow.php:34
ORMTable\selectFields
selectFields( $fields=null, array $conditions=array(), array $options=array(), $collapse=true, $functionName=null)
Selects the the specified fields of the records matching the provided conditions and returns them as ...
Definition: ORMTable.php:313
ORMTable\newRowFromDBResult
newRowFromDBResult(stdClass $result)
Get a new instance of the class from a database result.
Definition: ORMTable.php:905
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
Definition: ApiBase.php:62
ORMTable\setReadDb
setReadDb( $db)
Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer...
Definition: ORMTable.php:583
ORMTable\getPrefixedValues
getPrefixedValues(array $values)
Takes in an associative array with field names as keys and their values as value.
Definition: ORMTable.php:717
ORMTable\count
count(array $conditions=array(), array $options=array())
Returns the amount of matching records.
Definition: ORMTable.php:465
ORMTable\rawSelectRow
rawSelectRow(array $fields, array $conditions=array(), array $options=array(), $functionName=null)
Selects the the specified fields of the records matching the provided conditions.
Definition: ORMTable.php:377
ORMTable\unprefixFieldNames
unprefixFieldNames(array $fieldNames)
Takes an array of field names with prefix and returns the unprefixed equivalent.
Definition: ORMTable.php:779
ORMTable
Definition: ORMTable.php:31
ORMTable\select
select( $fields=null, array $conditions=array(), array $options=array(), $functionName=null)
Selects the the specified fields of the records matching the provided conditions and returns them as ...
Definition: ORMTable.php:198
ORMTable\getPrefixedField
getPrefixedField( $field)
Takes in a field and returns an it's prefixed version, ready for db usage.
Definition: ORMTable.php:766
ORMTable\getSummaryFields
getSummaryFields()
Returns a list of the summary fields.
Definition: ORMTable.php:181
ORMTable\getTargetWiki
getTargetWiki()
Get the ID of the any foreign wiki to use as a target for database operations.
Definition: ORMTable.php:595
ORMTable\getFieldsFromDBResult
getFieldsFromDBResult(stdClass $result)
Get an array with fields from a database result, that can be fed directly to the constructor or to se...
Definition: ORMTable.php:825
ORMTable\$fieldPrefix
string $fieldPrefix
Definition: ORMTable.php:58
wiki
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
Definition: maintenance.txt:1
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ORMTable\newFromDBResult
newFromDBResult(stdClass $result)
Definition: ORMTable.php:892
IORMRow\getFields
getFields()
Return the names and values of the fields.
ORMTable\canHaveField
canHaveField( $name)
Gets if the object can take a certain field.
Definition: ORMTable.php:960
$params
$params
Definition: styleTest.css.php:40
ORMTable\getName
getName()
Definition: ORMTable.php:114
ORMTable\updateRow
updateRow(IORMRow $row, $functionName=null)
Updates the provided row in the database.
Definition: ORMTable.php:974
ORMTable\getDefaults
getDefaults()
Returns a list of default field values.
Definition: ORMTable.php:168
IORMTable
Definition: IORMTable.php:30
ORMTable\newFromArray
newFromArray(array $data, $loadDefaults=false)
Definition: ORMTable.php:920
ORMTable\__construct
__construct( $tableName='', array $fields=array(), array $defaults=array(), $rowClass=null, $fieldPrefix='')
Constructor.
Definition: ORMTable.php:92
ORMTable\releaseConnection
releaseConnection(DatabaseBase $db)
Releases the lease on the given database connection.
Definition: ORMTable.php:650
$dbr
$dbr
Definition: testCompression.php:48
ORMTable\updateSummaryFields
updateSummaryFields( $summaryFields=null, array $conditions=array())
Computes the values of the summary fields of the objects matching the provided conditions.
Definition: ORMTable.php:690
ORMTable\$instanceCache
static $instanceCache
Definition: ORMTable.php:40
ORMTable\$tableName
string $tableName
Definition: ORMTable.php:46
$success
$success
Definition: Utf8Test.php:91
MWException
MediaWiki exception.
Definition: MWException.php:26
IORMRow\setField
setField( $name, $value)
Sets the value of a field.
DBQueryError
Definition: DatabaseError.php:306
tableName
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
ORMTable\removeRow
removeRow(IORMRow $row, $functionName=null)
Removes the provided row from the database.
Definition: ORMTable.php:1067
ORMTable\getFieldPrefix
getFieldPrefix()
Gets the db field prefix.
Definition: ORMTable.php:129
ORMTable\getReadDb
getReadDb()
Get the database ID used for read operations.
Definition: ORMTable.php:571
ORMTable\update
update(array $values, array $conditions=array())
Update the records matching the provided conditions by setting the fields that are keys in the $value...
Definition: ORMTable.php:667
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ORMTable\selectObjects
selectObjects( $fields=null, array $conditions=array(), array $options=array(), $functionName=null)
Selects the the specified fields of the records matching the provided conditions and returns them as ...
Definition: ORMTable.php:220
ORMTable\$rowClass
string $rowClass
Definition: ORMTable.php:64
ORMTable\getWriteValues
getWriteValues(IORMRow $row)
Gets the fields => values to write to the table.
Definition: ORMTable.php:1032
DBAccessBase\$wiki
string bool $wiki
$wiki The target wiki's name.
Definition: DBAccessBase.php:34
ORMTable\getReadDbConnection
getReadDbConnection()
Get the database type used for read operations.
Definition: ORMTable.php:621
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
ORMTable\getPrefixedFields
getPrefixedFields(array $fields)
Takes in a field or array of fields and returns an array with their prefixed versions,...
Definition: ORMTable.php:749
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
DBAccessBase
Definition: DBAccessBase.php:30
$value
$value
Definition: styleTest.css.php:45
ORMTable\selectRow
selectRow( $fields=null, array $conditions=array(), array $options=array(), $functionName=null)
Selects the the specified fields of the first matching record.
Definition: ORMTable.php:354
ORMTable\getFields
getFields()
Definition: ORMTable.php:152
DatabaseBase
Database abstraction object.
Definition: Database.php:219
ORMTable\$defaults
array $defaults
Definition: ORMTable.php:70
ORMTable\newRow
newRow(array $fields, $loadDefaults=false)
Get a new instance of the class from an array.
Definition: ORMTable.php:934
ORMTable\has
has(array $conditions=array())
Returns if there is at least one record matching the provided conditions.
Definition: ORMTable.php:432
ORMTable\$readDb
integer $readDb
ID of the database connection to use for read operations.
Definition: ORMTable.php:79
ORMTable\exists
exists()
Checks if the table exists.
Definition: ORMTable.php:443
ORMTable\getFieldNames
getFieldNames()
Return the names of the fields.
Definition: ORMTable.php:947
ORMTable\getFieldDescriptions
getFieldDescriptions()
Returns an array with the fields and their descriptions.
Definition: ORMTable.php:560
ORMTable\unprefixFieldName
unprefixFieldName( $fieldName)
Takes a field name with prefix and returns the unprefixed equivalent.
Definition: ORMTable.php:792
ORMTable\rawSelect
rawSelect( $fields=null, array $conditions=array(), array $options=array(), $functionName=null)
Do the actual select.
Definition: ORMTable.php:247
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
ORMTable\getAPIParams
getAPIParams( $requireParams=false, $setDefaults=false)
Get API parameters for the fields supported by this object.
Definition: ORMTable.php:510
IORMRow\getId
getId()
Returns the objects database id.
ORMTable\setTargetWiki
setTargetWiki( $wiki)
Set the ID of the any foreign wiki to use as a target for database operations.
Definition: ORMTable.php:607
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
ORMTable\insertRow
insertRow(IORMRow $row, $functionName=null, array $options=null)
Inserts the provided row into the database.
Definition: ORMTable.php:1001
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ORMTable\getRowClass
getRowClass()
Definition: ORMTable.php:140
DBAccessBase\getConnection
getConnection( $id, $groups=array())
Returns a database connection.
Definition: DBAccessBase.php:57
ORMTable\selectFieldsRow
selectFieldsRow( $fields=null, array $conditions=array(), array $options=array(), $collapse=true, $functionName=null)
Selects the the specified fields of the first record matching the provided conditions and returns it ...
Definition: ORMTable.php:412
$error
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
Definition: hooks.txt:2573
ORMTable\$fields
string[] $fields
Definition: ORMTable.php:52
$res
$res
Definition: database.txt:21
ORMTable\addToField
addToField(array $conditions, $field, $amount)
Add an amount (can be negative) to the specified field (needs to be numeric).
Definition: ORMTable.php:1089
ORMTable\singleton
static singleton()
Get an instance of this class.
Definition: ORMTable.php:804
$type
$type
Definition: testCompression.php:46