diff --git a/400_xowa/src/gplx/langs/phps/utls/Php_utl_.java b/400_xowa/src/gplx/langs/phps/utls/Php_utl_.java index 807d62c9b..acf3eb116 100644 --- a/400_xowa/src/gplx/langs/phps/utls/Php_utl_.java +++ b/400_xowa/src/gplx/langs/phps/utls/Php_utl_.java @@ -20,4 +20,19 @@ public class Php_utl_ { public static boolean Empty(byte[] v) {return v == null || v.length == 0;} public static boolean Empty(boolean v) {return v == false;} public static boolean Is_set(byte[] v) {return v != null;} + public static boolean isnumeric(byte[] src) { + if (src == null) return false; + int len = src.length; + for (int i = 0; i < len; i++) { + byte b = src[i]; + switch (b) { + case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4: + case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9: + break; + default: + return false; + } + } + return true; + } } diff --git a/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray.java b/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray.java index bcff612d5..f56aad958 100644 --- a/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray.java +++ b/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray.java @@ -239,14 +239,31 @@ public class Xomw_MagicWordArray { * * @return array */ - public byte[] matchVariableStartToEnd(byte[] src) { + public void matchVariableStartToEnd(byte[][] rv, byte[] src) { int src_end = src.length; + if (src_end == 0) { + rv[0] = rv[1] = null; + return; + } + + byte[] name = null; + int val_bgn = -1, val_end = -1; // check fwd; EX: "thumb=$1" if (fwd_trie != null) { Object o = fwd_trie.Match_at(trv, src, 0, src_end); if (o != null) { - return ((Xomw_MagicWordSynonym)o).magic_name; + Xomw_MagicWordSynonym syn = ((Xomw_MagicWordSynonym)o); + name = syn.magic_name; + val_bgn = trv.Pos(); + val_end = src_end; + + // if "nil", then must be full match; EX: "thumbx" does not match "thumb" + if (syn.arg1_tid == Xomw_MagicWordSynonym.Arg1__nil + && syn.text_wo_arg1.length != src_end) { + rv[0] = rv[1] = null; + return; + } } } @@ -254,20 +271,15 @@ public class Xomw_MagicWordArray { if (bwd_trie != null) { Object o = bwd_trie.Match_at(trv, src, src_end - 1, -1); if (o != null) { - return ((Xomw_MagicWordSynonym)o).magic_name; + Xomw_MagicWordSynonym syn = ((Xomw_MagicWordSynonym)o); + name = syn.magic_name; + val_bgn = 0; + val_end = src_end - syn.text_wo_arg1.length; } } - return null; -// regexes = this->getVariableStartToEndRegex(); -// foreach (regexes as regex) { -// if (regex !== '') { -// m = []; -// if (preg_match(regex, text, m)) { -// return this->parseMatch(m); -// } -// } -// } -// return [ false, false ]; + + rv[0] = name; + rv[1] = val_end - val_bgn == 0 ? Bry_.Empty : Bry_.Mid(src, val_bgn, val_end); } // /** diff --git a/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray__tst.java b/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray__tst.java index f8801566b..218618889 100644 --- a/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray__tst.java +++ b/400_xowa/src/gplx/xowa/mws/Xomw_MagicWordArray__tst.java @@ -20,27 +20,30 @@ import org.junit.*; import gplx.core.tests.*; public class Xomw_MagicWordArray__tst { private final Xomw_MagicWordArray__fxt fxt = new Xomw_MagicWordArray__fxt(); @Test public void Nil() { - fxt.Init__word(Bool_.Y, "nil", "nil"); - fxt.Init__ary("nil"); - fxt.Test__matchVariableStartToEnd("nil", "nil", "nila"); + fxt.Init__word(Bool_.Y, "img_nil", "nil"); + fxt.Init__ary("img_nil"); + fxt.Test__matchVariableStartToEnd("nil", "img_nil", ""); + fxt.Test__matchVariableStartToEnd("nila", null, null); } @Test public void Bgn() { - fxt.Init__word(Bool_.Y, "bgn", "bgn$1"); - fxt.Init__ary("bgn"); - fxt.Test__matchVariableStartToEnd("bgn", "bgn", "bgna"); + fxt.Init__word(Bool_.Y, "img_bgn", "bgn$1"); + fxt.Init__ary("img_bgn"); + fxt.Test__matchVariableStartToEnd("bgna", "img_bgn", "a"); + fxt.Test__matchVariableStartToEnd("bgn", "img_bgn", ""); } @Test public void End() { - fxt.Init__word(Bool_.Y, "end", "$1end"); - fxt.Init__ary("end"); - fxt.Test__matchVariableStartToEnd("end", "end", "aend"); + fxt.Init__word(Bool_.Y, "img_end", "$1end"); + fxt.Init__ary("img_end"); + fxt.Test__matchVariableStartToEnd("aend", "img_end", "a"); + fxt.Test__matchVariableStartToEnd("end", "img_end", ""); } @Test public void Smoke() { fxt.Init__word(Bool_.Y, "img_upright", "upright", "upright=$1", "upright $1"); fxt.Init__word(Bool_.Y, "img_width", "$1px"); fxt.Init__ary("img_upright", "img_width"); - fxt.Test__matchVariableStartToEnd("img_upright", "upright", "upright=123", "upright 123"); - fxt.Test__matchVariableStartToEnd("img_width", "123px"); + fxt.Test__matchVariableStartToEnd("upright=123", "img_upright", "123"); + fxt.Test__matchVariableStartToEnd("123px", "img_width", "123"); } } class Xomw_MagicWordArray__fxt { @@ -52,11 +55,10 @@ class Xomw_MagicWordArray__fxt { public void Init__ary(String... words) { magic_word_ary = new Xomw_MagicWordArray(magic_word_mgr, Bry_.Ary(words)); } - public void Test__matchVariableStartToEnd(String expd_str, String... vals) { - byte[] expd = Bry_.new_u8(expd_str); - for (String val : vals) { - byte[] actl = magic_word_ary.matchVariableStartToEnd(Bry_.new_u8(val)); - Gftest.Eq__bry(expd, actl, val); - } + public void Test__matchVariableStartToEnd(String src, String expd_name, String expd_val) { + byte[][] rv = new byte[2][]; + magic_word_ary.matchVariableStartToEnd(rv, Bry_.new_u8(src)); + Gftest.Eq__str(expd_name, rv[0], expd_name); + Gftest.Eq__str(expd_val , rv[1], expd_val); } } diff --git a/400_xowa/src/gplx/xowa/mws/Xomw_linker.java b/400_xowa/src/gplx/xowa/mws/Xomw_linker.java index e7be6e93b..32ef448de 100644 --- a/400_xowa/src/gplx/xowa/mws/Xomw_linker.java +++ b/400_xowa/src/gplx/xowa/mws/Xomw_linker.java @@ -20,6 +20,7 @@ import gplx.core.btries.*; import gplx.langs.htmls.*; import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*; import gplx.xowa.mws.parsers.*; import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.media.*; +import gplx.xowa.mws.parsers.lnkis.*; import gplx.langs.phps.utls.*; /* TODO.XO * P8: wfMessage @@ -92,7 +93,7 @@ public class Xomw_linker { // @param int|null width_option Used by the parser to remember the user preference thumbnailsize // @since 1.20 // @return String HTML for an image, with links, wrappers, etc. - public void Make_image_link(Bry_bfr bfr, Xomw_parser parser, Xoa_ttl title, Xomw_File file, Xomw_img_prms frame_params, Xomw_mda_prms handler_params, Object time, byte[] query, Object widthOption) { + public void makeImageLink(Bry_bfr bfr, Xomw_parser parser, Xoa_ttl title, Xomw_File file, Xomw_params_frame frame_params, Xomw_params_handler handler_params, Object time, byte[] query, Object widthOption) { // XO.MW.HOOK:ImageBeforeProduceHTML if (file != null && !file.allowInlineDisplay()) { @@ -176,11 +177,12 @@ public class Xomw_linker { // If a thumbnail width has not been provided, it is set // to the default user option as specified in Language*.php if (frame_params.align == Bry_.Empty) { -// frame_params.align = $parser->getTargetLanguage()->alignEnd(); + frame_params.align = parser.Env().Lang__align_end; } bfr.Add(prefix); this.Make_thumb_link2(bfr, title, file, frame_params, handler_params, time, query); bfr.Add(postfix); + return; } if (file != null && frame_params.frameless != null) { @@ -197,7 +199,7 @@ public class Xomw_linker { if (file != null && handler_params.width != -1) { // Create a resized image, without the additional thumbnail features // $thumb = $file->transform(handler_params); - thumb = new Xomw_mto(file.getUrl()); + thumb = new Xomw_mto(file.getUrl(), file.getWidth(), file.getHeight()); } else { thumb = null; @@ -216,7 +218,7 @@ public class Xomw_linker { params_list.valign = frame_params.valign; params_list.img_cls = frame_params.cls; if (frame_params.border != null) { - params_list.img_cls = Xomw_img_prms.Cls_add(params_list.img_cls, Img_class__thumbborder); + params_list.img_cls = Xomw_params_frame.Cls_add(params_list.img_cls, Img_class__thumbborder); } // $params = self::getImageLinkMTOParams(frame_params, $query, $parser) + $params; @@ -245,7 +247,7 @@ public class Xomw_linker { // @param Parser|null $parser // @return array // XO.MW:SYNC:1.29; DATE:2017-02-03 - public void Get_image_link_mto_params(Xomw_mto_params mto_params, Xomw_img_prms frame_params, byte[] query, Xomw_parser parser) { + public void Get_image_link_mto_params(Xomw_mto_params mto_params, Xomw_params_frame frame_params, byte[] query, Xomw_parser parser) { if (Php_utl_.Is_set(frame_params.link_url) && frame_params.link_url != Bry_.Empty) { mto_params.custom_url_link = frame_params.link_url; if (Php_utl_.Is_set(frame_params.link_target)) { @@ -271,8 +273,8 @@ public class Xomw_linker { } } - public void Make_thumb_link2(Bry_bfr bfr, Xoa_ttl title, Xomw_File file, Xomw_img_prms frame_params, Xomw_mda_prms handler_params, Object time, byte[] query) { - boolean exists = false; // = $file && $file->exists(); + public void Make_thumb_link2(Bry_bfr bfr, Xoa_ttl title, Xomw_File file, Xomw_params_frame frame_params, Xomw_params_handler handler_params, Object time, byte[] query) { + boolean exists = true; // = $file && $file->exists(); int page = handler_params.page; if (frame_params.align == null) { @@ -317,7 +319,7 @@ public class Xomw_linker { else if (frame_params.framed != null) { // Use image dimensions, don't scale // thumb = $file->getUnscaledThumb(handler_params); - thumb = new Xomw_mto(file.getUrl()); + thumb = new Xomw_mto(file.getUrl(), file.getWidth(), file.getHeight()); no_scale = true; } else { @@ -328,10 +330,11 @@ public class Xomw_linker { handler_params.width = src_width; } // thumb = $file->transform(handler_params); + thumb = new Xomw_mto(file.getUrl(), file.getWidth(), file.getHeight()); } if (thumb != null) { -// outer_width = thumb->getWidth() + 2; + outer_width = thumb.getWidth() + 2; } else { outer_width = handler_params.width + 2; @@ -373,7 +376,7 @@ public class Xomw_linker { mto_params.Clear(); mto_params.alt = frame_params.alt; mto_params.title = frame_params.title; - mto_params.img_cls = Xomw_img_prms.Cls_add(frame_params.cls, Img_class__thumbimage); + mto_params.img_cls = Xomw_params_frame.Cls_add(frame_params.cls, Img_class__thumbimage); Get_image_link_mto_params(mto_params, frame_params, query, null); thumb.To_html(bfr, tmp, mto_params); if (frame_params.framed != null) { @@ -388,7 +391,8 @@ public class Xomw_linker { , Bry_.Empty); // env.Message_mgr().Get_by_str("thumbnail-more").text(); byte[] zoom_anch = tmp.To_bry_and_clear(); - html_utl.Raw_element(bfr, Gfh_tag_.Bry__div, tmp_attribs.Clear().Add(Gfh_atr_.Bry__class, Class__magnify), zoom_anch); + html_utl.Raw_element(tmp, Gfh_tag_.Bry__div, tmp_attribs.Clear().Add(Gfh_atr_.Bry__class, Class__magnify), zoom_anch); + zoom_icon = tmp.To_bry_and_clear(); } } bfr.Add_str_a7("
").Add(zoom_icon).Add(frame_params.caption).Add_str_a7("
"); diff --git a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_File.java b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_File.java index 980e2b277..ff0871d6e 100644 --- a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_File.java +++ b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_File.java @@ -18,6 +18,7 @@ along with this program. If not, see . package gplx.xowa.mws.filerepo.file; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.filerepo.*; import gplx.xowa.mws.media.*; import gplx.langs.phps.utls.*; +import gplx.xowa.mws.parsers.*; /* TODO.XO: * P8: normalizeExtension * P8: normalizeTitle @@ -442,9 +443,10 @@ public class Xomw_File { * @return int|boolean */ // @dflt: page = 1 - public int getWidth(int page) { + @gplx.Virtual public int getWidth(int page) { return -1; } + public int getWidth() {return this.getWidth(1);} /** * Return the height of the image. Returns false if the height is unknown @@ -460,6 +462,7 @@ public class Xomw_File { public int getHeight(int page) { return -1; } + public int getHeight() {return this.getHeight(1);} // /** // * Return the smallest bucket from wgThumbnailBuckets which is at least @@ -680,18 +683,19 @@ public class Xomw_File { // public function getSize() { // return false; // } -// -// /** -// * Returns the MIME type of the file. -// * Overridden by LocalFile, UnregisteredLocalFile -// * STUB -// * -// * @return String -// */ -// function getMimeType() { -// return 'unknown/unknown'; -// } -// + + /** + * Returns the MIME type of the file. + * Overridden by LocalFile, UnregisteredLocalFile + * STUB + * + * @return String + */ + @gplx.Virtual public byte[] getMimeType() { + return Mime_type__unknown; + } + private static final byte[] Mime_type__unknown = Bry_.new_a7("unknown/unknown"); + // /** // * Return the type of the media in the file. // * Use the value returned by this function with the MEDIATYPE_xxx constants. @@ -1347,9 +1351,9 @@ public class Xomw_File { * @return MediaHandler|boolean Registered MediaHandler for file's MIME type * or false if none found */ - public Xomw_MediaHandler getHandler() { + public Xomw_MediaHandler getHandler(Xomw_parser_env env) { if (this.handler == null) { -// this.handler = MediaHandler::getHandler(this.getMimeType()); + this.handler = env.MediaHandlerFactory().getHandler(this.getMimeType()); } return this.handler; diff --git a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_LocalFile.java b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_LocalFile.java index 38c0ca77c..97e47a641 100644 --- a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_LocalFile.java +++ b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_LocalFile.java @@ -34,10 +34,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // /** @var String MEDIATYPE_xxx (bitmap, drawing, audio...) */ // protected media_type; -// -// /** @var String MIME type, determined by MimeMagic::guessMimeType */ -// protected mime; -// + + /** @var String MIME type, determined by MimeMagic::guessMimeType */ + private byte[] mime; + // /** @var int Size in bytes (loadFromXxx) */ // protected size; // @@ -132,9 +132,9 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return LocalFile // */ // static function newFromRow( row, repo ) { -// title = Title::makeTitle( NS_FILE, row->img_name ); +// title = Title::makeTitle( NS_FILE, row.img_name ); // file = new self( title, repo ); -// file->loadFromRow( row ); +// file.loadFromRow( row ); // // return file; // } @@ -149,14 +149,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean|LocalFile // */ // static function newFromKey( sha1, repo, timestamp = false ) { -// dbr = repo->getReplicaDB(); +// dbr = repo.getReplicaDB(); // // conds = [ 'img_sha1' => sha1 ]; // if ( timestamp ) { -// conds['img_timestamp'] = dbr->timestamp( timestamp ); +// conds['img_timestamp'] = dbr.timestamp( timestamp ); // } // -// row = dbr->selectRow( 'image', self::selectFields(), conds, __METHOD__ ); +// row = dbr.selectRow( 'image', self::selectFields(), conds, __METHOD__ ); // if ( row ) { // return self::newFromRow( row, repo ); // } else { @@ -187,9 +187,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // ]; // } - public Xomw_LocalFile(byte[] title, Xomw_FileRepo repo, int w, int h) {super(title, repo); + public Xomw_LocalFile(byte[] title, Xomw_FileRepo repo, int w, int h, byte[] mime) {super(title, repo); this.width = w; this.height = h; + this.mime = mime; } // /** // * Constructor. @@ -200,14 +201,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // function __construct( title, repo ) { // parent::__construct( title, repo ); // -// this->metadata = ''; -// this->historyLine = 0; -// this->historyRes = null; -// this->dataLoaded = false; -// this->extraDataLoaded = false; +// this.metadata = ''; +// this.historyLine = 0; +// this.historyRes = null; +// this.dataLoaded = false; +// this.extraDataLoaded = false; // -// this->assertRepoDefined(); -// this->assertTitleDefined(); +// this.assertRepoDefined(); +// this.assertTitleDefined(); // } // // /** @@ -216,43 +217,43 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return String|boolean // */ // function getCacheKey() { -// return this->repo->getSharedCacheKey( 'file', sha1( this->getName() ) ); +// return this.repo.getSharedCacheKey( 'file', sha1( this.getName() ) ); // } // // /** // * Try to load file metadata from memcached, falling back to the database // */ // private function loadFromCache() { -// this->dataLoaded = false; -// this->extraDataLoaded = false; +// this.dataLoaded = false; +// this.extraDataLoaded = false; // -// key = this->getCacheKey(); +// key = this.getCacheKey(); // if ( !key ) { -// this->loadFromDB( self::READ_NORMAL ); +// this.loadFromDB( self::READ_NORMAL ); // // return; // } // // cache = ObjectCache::getMainWANInstance(); -// cachedValues = cache->getWithSetCallback( +// cachedValues = cache.getWithSetCallback( // key, // cache::TTL_WEEK, // function ( oldValue, &ttl, array &setOpts ) use ( cache ) { -// setOpts += Database::getCacheSetOptions( this->repo->getReplicaDB() ); +// setOpts += Database::getCacheSetOptions( this.repo.getReplicaDB() ); // -// this->loadFromDB( self::READ_NORMAL ); +// this.loadFromDB( self::READ_NORMAL ); // -// fields = this->getCacheFields( '' ); -// cacheVal['fileExists'] = this->fileExists; -// if ( this->fileExists ) { +// fields = this.getCacheFields( '' ); +// cacheVal['fileExists'] = this.fileExists; +// if ( this.fileExists ) { // foreach ( fields as field ) { -// cacheVal[field] = this->field; +// cacheVal[field] = this.field; // } // } // // Strip off excessive entries from the subset of fields that can become large. // // If the cache value gets to large it will not fit in memcached and nothing will // // get cached at all, causing master queries for any file access. -// foreach ( this->getLazyCacheFields( '' ) as field ) { +// foreach ( this.getLazyCacheFields( '' ) as field ) { // if ( isset( cacheVal[field] ) // && strlen( cacheVal[field] ) > 100 * 1024 // ) { @@ -260,8 +261,8 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // } // } // -// if ( this->fileExists ) { -// ttl = cache->adaptiveTTL( wfTimestamp( TS_UNIX, this->timestamp ), ttl ); +// if ( this.fileExists ) { +// ttl = cache.adaptiveTTL( wfTimestamp( TS_UNIX, this.timestamp ), ttl ); // } else { // ttl = cache::TTL_DAY; // } @@ -271,15 +272,15 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // [ 'version' => self::VERSION ] // ); // -// this->fileExists = cachedValues['fileExists']; -// if ( this->fileExists ) { -// this->setProps( cachedValues ); +// this.fileExists = cachedValues['fileExists']; +// if ( this.fileExists ) { +// this.setProps( cachedValues ); // } // -// this->dataLoaded = true; -// this->extraDataLoaded = true; -// foreach ( this->getLazyCacheFields( '' ) as field ) { -// this->extraDataLoaded = this->extraDataLoaded && isset( cachedValues[field] ); +// this.dataLoaded = true; +// this.extraDataLoaded = true; +// foreach ( this.getLazyCacheFields( '' ) as field ) { +// this.extraDataLoaded = this.extraDataLoaded && isset( cachedValues[field] ); // } // } // @@ -287,14 +288,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * Purge the file Object/metadata cache // */ // public function invalidateCache() { -// key = this->getCacheKey(); +// key = this.getCacheKey(); // if ( !key ) { // return; // } // -// this->repo->getMasterDB()->onTransactionPreCommitOrIdle( +// this.repo.getMasterDB().onTransactionPreCommitOrIdle( // function () use ( key ) { -// ObjectCache::getMainWANInstance()->delete( key ); +// ObjectCache::getMainWANInstance().delete( key ); // }, // __METHOD__ // ); @@ -304,8 +305,8 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * Load metadata from the file itself // */ // function loadFromFile() { -// props = this->repo->getFileProps( this->getVirtualUrl() ); -// this->setProps( props ); +// props = this.repo.getFileProps( this.getVirtualUrl() ); +// this.setProps( props ); // } // // /** @@ -364,20 +365,20 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // fname = get_class( this ) . '::' . __FUNCTION__; // // # Unconditionally set loaded=true, we don't want the accessors constantly rechecking -// this->dataLoaded = true; -// this->extraDataLoaded = true; +// this.dataLoaded = true; +// this.extraDataLoaded = true; // // dbr = ( flags & self::READ_LATEST ) -// ? this->repo->getMasterDB() -// : this->repo->getReplicaDB(); +// ? this.repo.getMasterDB() +// : this.repo.getReplicaDB(); // -// row = dbr->selectRow( 'image', this->getCacheFields( 'img_' ), -// [ 'img_name' => this->getName() ], fname ); +// row = dbr.selectRow( 'image', this.getCacheFields( 'img_' ), +// [ 'img_name' => this.getName() ], fname ); // // if ( row ) { -// this->loadFromRow( row ); +// this.loadFromRow( row ); // } else { -// this->fileExists = false; +// this.fileExists = false; // } // } // @@ -389,19 +390,19 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // fname = get_class( this ) . '::' . __FUNCTION__; // // # Unconditionally set loaded=true, we don't want the accessors constantly rechecking -// this->extraDataLoaded = true; +// this.extraDataLoaded = true; // -// fieldMap = this->loadFieldsWithTimestamp( this->repo->getReplicaDB(), fname ); +// fieldMap = this.loadFieldsWithTimestamp( this.repo.getReplicaDB(), fname ); // if ( !fieldMap ) { -// fieldMap = this->loadFieldsWithTimestamp( this->repo->getMasterDB(), fname ); +// fieldMap = this.loadFieldsWithTimestamp( this.repo.getMasterDB(), fname ); // } // // if ( fieldMap ) { // foreach ( fieldMap as name => value ) { -// this->name = value; +// this.name = value; // } // } else { -// throw new MWException( "Could not find data for image '{this->getName()}'." ); +// throw new MWException( "Could not find data for image '{this.getName()}'." ); // } // } // @@ -413,20 +414,20 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // private function loadFieldsWithTimestamp( dbr, fname ) { // fieldMap = false; // -// row = dbr->selectRow( 'image', this->getLazyCacheFields( 'img_' ), [ -// 'img_name' => this->getName(), -// 'img_timestamp' => dbr->timestamp( this->getTimestamp() ) +// row = dbr.selectRow( 'image', this.getLazyCacheFields( 'img_' ), [ +// 'img_name' => this.getName(), +// 'img_timestamp' => dbr.timestamp( this.getTimestamp() ) // ], fname ); // if ( row ) { -// fieldMap = this->unprefixRow( row, 'img_' ); +// fieldMap = this.unprefixRow( row, 'img_' ); // } else { // # File may have been uploaded over in the meantime; check the old versions -// row = dbr->selectRow( 'oldimage', this->getLazyCacheFields( 'oi_' ), [ -// 'oi_name' => this->getName(), -// 'oi_timestamp' => dbr->timestamp( this->getTimestamp() ) +// row = dbr.selectRow( 'oldimage', this.getLazyCacheFields( 'oi_' ), [ +// 'oi_name' => this.getName(), +// 'oi_timestamp' => dbr.timestamp( this.getTimestamp() ) // ], fname ); // if ( row ) { -// fieldMap = this->unprefixRow( row, 'oi_' ); +// fieldMap = this.unprefixRow( row, 'oi_' ); // } // } // @@ -465,11 +466,11 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return array // */ // function decodeRow( row, prefix = 'img_' ) { -// decoded = this->unprefixRow( row, prefix ); +// decoded = this.unprefixRow( row, prefix ); // // decoded['timestamp'] = wfTimestamp( TS_MW, decoded['timestamp'] ); // -// decoded['metadata'] = this->repo->getReplicaDB()->decodeBlob( decoded['metadata'] ); +// decoded['metadata'] = this.repo.getReplicaDB().decodeBlob( decoded['metadata'] ); // // if ( empty( decoded['major_mime'] ) ) { // decoded['mime'] = 'unknown/unknown'; @@ -501,17 +502,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param String prefix // */ // function loadFromRow( row, prefix = 'img_' ) { -// this->dataLoaded = true; -// this->extraDataLoaded = true; +// this.dataLoaded = true; +// this.extraDataLoaded = true; // -// array = this->decodeRow( row, prefix ); +// array = this.decodeRow( row, prefix ); // // foreach ( array as name => value ) { -// this->name = value; +// this.name = value; // } // -// this->fileExists = true; -// this->maybeUpgradeRow(); +// this.fileExists = true; +// this.maybeUpgradeRow(); // } // // /** @@ -519,17 +520,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param int flags // */ // function load( flags = 0 ) { -// if ( !this->dataLoaded ) { +// if ( !this.dataLoaded ) { // if ( flags & self::READ_LATEST ) { -// this->loadFromDB( flags ); +// this.loadFromDB( flags ); // } else { -// this->loadFromCache(); +// this.loadFromCache(); // } // } // -// if ( ( flags & self::LOAD_ALL ) && !this->extraDataLoaded ) { +// if ( ( flags & self::LOAD_ALL ) && !this.extraDataLoaded ) { // // @note: loads on name/timestamp to reduce race condition problems -// this->loadExtraFromDB(); +// this.loadExtraFromDB(); // } // } // @@ -539,17 +540,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // function maybeUpgradeRow() { // global wgUpdateCompatibleMetadata; // -// if ( wfReadOnly() || this->upgrading ) { +// if ( wfReadOnly() || this.upgrading ) { // return; // } // // upgrade = false; -// if ( is_null( this->media_type ) || this->mime == 'image/svg' ) { +// if ( is_null( this.media_type ) || this.mime == 'image/svg' ) { // upgrade = true; // } else { -// handler = this->getHandler(); +// handler = this.getHandler(); // if ( handler ) { -// validity = handler->isMetadataValid( this, this->getMetadata() ); +// validity = handler.isMetadataValid( this, this.getMetadata() ); // if ( validity === MediaHandler::METADATA_BAD ) { // upgrade = true; // } elseif ( validity === MediaHandler::METADATA_COMPATIBLE ) { @@ -559,12 +560,12 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // } // // if ( upgrade ) { -// this->upgrading = true; +// this.upgrading = true; // // Defer updates unless in auto-commit CLI mode // DeferredUpdates::addCallableUpdate( function() { -// this->upgrading = false; // avoid duplicate updates +// this.upgrading = false; // avoid duplicate updates // try { -// this->upgradeRow(); +// this.upgradeRow(); // } catch ( LocalFileLockError e ) { // // let the other process handle it (or do it next time) // } @@ -576,55 +577,55 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean Whether upgradeRow() ran for this Object // */ // function getUpgraded() { -// return this->upgraded; +// return this.upgraded; // } // // /** // * Fix assorted version-related problems with the image row by reloading it from the file // */ // function upgradeRow() { -// this->synchronized(); // begin +// this.synchronized(); // begin // -// this->loadFromFile(); +// this.loadFromFile(); // // # Don't destroy file info of missing files -// if ( !this->fileExists ) { -// this->unlock(); +// if ( !this.fileExists ) { +// this.unlock(); // wfDebug( __METHOD__ . ": file does not exist, aborting\n" ); // // return; // } // -// dbw = this->repo->getMasterDB(); -// list( major, minor ) = self::splitMime( this->mime ); +// dbw = this.repo.getMasterDB(); +// list( major, minor ) = self::splitMime( this.mime ); // // if ( wfReadOnly() ) { -// this->unlock(); +// this.unlock(); // // return; // } -// wfDebug( __METHOD__ . ': upgrading ' . this->getName() . " to the current schema\n" ); +// wfDebug( __METHOD__ . ': upgrading ' . this.getName() . " to the current schema\n" ); // -// dbw->update( 'image', +// dbw.update( 'image', // [ -// 'img_size' => this->size, // sanity -// 'img_width' => this->width, -// 'img_height' => this->height, -// 'img_bits' => this->bits, -// 'img_media_type' => this->media_type, +// 'img_size' => this.size, // sanity +// 'img_width' => this.width, +// 'img_height' => this.height, +// 'img_bits' => this.bits, +// 'img_media_type' => this.media_type, // 'img_major_mime' => major, // 'img_minor_mime' => minor, -// 'img_metadata' => dbw->encodeBlob( this->metadata ), -// 'img_sha1' => this->sha1, +// 'img_metadata' => dbw.encodeBlob( this.metadata ), +// 'img_sha1' => this.sha1, // ], -// [ 'img_name' => this->getName() ], +// [ 'img_name' => this.getName() ], // __METHOD__ // ); // -// this->invalidateCache(); +// this.invalidateCache(); // -// this->unlock(); // done -// this->upgraded = true; // avoid rework/retries +// this.unlock(); // done +// this.upgraded = true; // avoid rework/retries // } // // /** @@ -633,27 +634,27 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * All fields *must* be set in info except for getLazyCacheFields(). // * // * If 'mime' is given, it will be split into major_mime/minor_mime. -// * If major_mime/minor_mime are given, this->mime will also be set. +// * If major_mime/minor_mime are given, this.mime will also be set. // * // * @param array info // */ // function setProps( info ) { -// this->dataLoaded = true; -// fields = this->getCacheFields( '' ); +// this.dataLoaded = true; +// fields = this.getCacheFields( '' ); // fields[] = 'fileExists'; // // foreach ( fields as field ) { // if ( isset( info[field] ) ) { -// this->field = info[field]; +// this.field = info[field]; // } // } // // // Fix up mime fields // if ( isset( info['major_mime'] ) ) { -// this->mime = "{info['major_mime']}/{info['minor_mime']}"; +// this.mime = "{info['major_mime']}/{info['minor_mime']}"; // } elseif ( isset( info['mime'] ) ) { -// this->mime = info['mime']; -// list( this->major_mime, this->minor_mime ) = self::splitMime( this->mime ); +// this.mime = info['mime']; +// list( this.major_mime, this.minor_mime ) = self::splitMime( this.mime ); // } // } // @@ -669,29 +670,29 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean // */ // function isMissing() { -// if ( this->missing === null ) { -// list( fileExists ) = this->repo->fileExists( this->getVirtualUrl() ); -// this->missing = !fileExists; +// if ( this.missing === null ) { +// list( fileExists ) = this.repo.fileExists( this.getVirtualUrl() ); +// this.missing = !fileExists; // } // -// return this->missing; +// return this.missing; // } + + /** + * Return the width of the image + * + * @param int page + * @return int + */ + @Override public int getWidth(int page) { +// this.load(); // -// /** -// * Return the width of the image -// * -// * @param int page -// * @return int -// */ -// public function getWidth( page = 1 ) { -// this->load(); -// -// if ( this->isMultipage() ) { -// handler = this->getHandler(); +// if ( this.isMultipage() ) { +// handler = this.getHandler(); // if ( !handler ) { // return 0; // } -// dim = handler->getPageDimensions( this, page ); +// dim = handler.getPageDimensions( this, page ); // if ( dim ) { // return dim['width']; // } else { @@ -700,10 +701,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // return 0; // } // } else { -// return this->width; + return this.width; // } -// } -// + } + // /** // * Return the height of the image // * @@ -711,14 +712,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return int // */ // public function getHeight( page = 1 ) { -// this->load(); +// this.load(); // -// if ( this->isMultipage() ) { -// handler = this->getHandler(); +// if ( this.isMultipage() ) { +// handler = this.getHandler(); // if ( !handler ) { // return 0; // } -// dim = handler->getPageDimensions( this, page ); +// dim = handler.getPageDimensions( this, page ); // if ( dim ) { // return dim['height']; // } else { @@ -727,7 +728,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // return 0; // } // } else { -// return this->height; +// return this.height; // } // } // @@ -738,12 +739,12 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return int|String // */ // function getUser( type = 'text' ) { -// this->load(); +// this.load(); // // if ( type == 'text' ) { -// return this->user_text; +// return this.user_text; // } else { // id -// return (int)this->user; +// return (int)this.user; // } // } // @@ -755,10 +756,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @since 1.27 // */ // public function getDescriptionShortUrl() { -// pageId = this->title->getArticleID(); +// pageId = this.title.getArticleID(); // // if ( pageId !== null ) { -// url = this->repo->makeUrl( [ 'curid' => pageId ] ); +// url = this.repo.makeUrl( [ 'curid' => pageId ] ); // if ( url !== false ) { // return url; // } @@ -771,17 +772,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return String // */ // function getMetadata() { -// this->load( self::LOAD_ALL ); // large metadata is loaded in another step -// return this->metadata; +// this.load( self::LOAD_ALL ); // large metadata is loaded in another step +// return this.metadata; // } // // /** // * @return int // */ // function getBitDepth() { -// this->load(); +// this.load(); // -// return (int)this->bits; +// return (int)this.bits; // } // // /** @@ -789,30 +790,30 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return int // */ // public function getSize() { -// this->load(); +// this.load(); // -// return this->size; +// return this.size; // } -// -// /** -// * Returns the MIME type of the file. -// * @return String -// */ -// function getMimeType() { -// this->load(); -// -// return this->mime; -// } -// + + /** + * Returns the MIME type of the file. + * @return String + */ + @Override public byte[] getMimeType() { + // this.load(); + + return this.mime; + } + // /** // * Returns the type of the media in the file. // * Use the value returned by this function with the MEDIATYPE_xxx constants. // * @return String // */ // function getMediaType() { -// this->load(); +// this.load(); // -// return this->media_type; +// return this.media_type; // } // // /** canRender inherited */ @@ -826,9 +827,9 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean Whether file exist on disk. // */ // public function exists() { -// this->load(); +// this.load(); // -// return this->fileExists; +// return this.fileExists; // } // // /** getTransformScript inherited */ @@ -848,15 +849,15 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // function getThumbnails( archiveName = false ) { // if ( archiveName ) { -// dir = this->getArchiveThumbPath( archiveName ); +// dir = this.getArchiveThumbPath( archiveName ); // } else { -// dir = this->getThumbPath(); +// dir = this.getThumbPath(); // } // -// backend = this->repo->getBackend(); +// backend = this.repo.getBackend(); // files = [ dir ]; // try { -// iterator = backend->getFileList( [ 'dir' => dir ] ); +// iterator = backend.getFileList( [ 'dir' => dir ] ); // foreach ( iterator as file ) { // files[] = file; // } @@ -870,7 +871,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * Refresh metadata in memcached, but don't touch thumbnails or CDN // */ // function purgeMetadataCache() { -// this->invalidateCache(); +// this.invalidateCache(); // } // // /** @@ -882,14 +883,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // function purgeCache( options = [] ) { // // Refresh metadata cache -// this->purgeMetadataCache(); +// this.purgeMetadataCache(); // // // Delete thumbnails -// this->purgeThumbnails( options ); +// this.purgeThumbnails( options ); // // // Purge CDN cache for this file // DeferredUpdates::addUpdate( -// new CdnCacheUpdate( [ this->getUrl() ] ), +// new CdnCacheUpdate( [ this.getUrl() ] ), // DeferredUpdates::PRESEND // ); // } @@ -900,19 +901,19 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // function purgeOldThumbnails( archiveName ) { // // Get a list of old thumbnails and URLs -// files = this->getThumbnails( archiveName ); +// files = this.getThumbnails( archiveName ); // // // Purge any custom thumbnail caches // Hooks::run( 'LocalFilePurgeThumbnails', [ this, archiveName ] ); // // // Delete thumbnails // dir = array_shift( files ); -// this->purgeThumbList( dir, files ); +// this.purgeThumbList( dir, files ); // // // Purge the CDN // urls = []; // foreach ( files as file ) { -// urls[] = this->getArchiveThumbUrl( archiveName, file ); +// urls[] = this.getArchiveThumbUrl( archiveName, file ); // } // DeferredUpdates::addUpdate( new CdnCacheUpdate( urls ), DeferredUpdates::PRESEND ); // } @@ -922,19 +923,19 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param array options // */ // public function purgeThumbnails( options = [] ) { -// files = this->getThumbnails(); +// files = this.getThumbnails(); // // Always purge all files from CDN regardless of handler filters // urls = []; // foreach ( files as file ) { -// urls[] = this->getThumbUrl( file ); +// urls[] = this.getThumbUrl( file ); // } // array_shift( urls ); // don't purge directory // // // Give media handler a chance to filter the file purge list // if ( !empty( options['forThumbRefresh'] ) ) { -// handler = this->getHandler(); +// handler = this.getHandler(); // if ( handler ) { -// handler->filterThumbnailPurgeList( files, options ); +// handler.filterThumbnailPurgeList( files, options ); // } // } // @@ -943,7 +944,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // // Delete thumbnails // dir = array_shift( files ); -// this->purgeThumbList( dir, files ); +// this.purgeThumbList( dir, files ); // // // Purge the CDN // DeferredUpdates::addUpdate( new CdnCacheUpdate( urls ), DeferredUpdates::PRESEND ); @@ -963,16 +964,16 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // rsort( sizes ); // // foreach ( sizes as size ) { -// if ( this->isVectorized() || this->getWidth() > size ) { +// if ( this.isVectorized() || this.getWidth() > size ) { // jobs[] = new ThumbnailRenderJob( -// this->getTitle(), +// this.getTitle(), // [ 'transformParams' => [ 'width' => size ] ] // ); // } // } // // if ( jobs ) { -// JobQueueGroup::singleton()->lazyPush( jobs ); +// JobQueueGroup::singleton().lazyPush( jobs ); // } // } // @@ -992,7 +993,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // foreach ( files as file ) { // # Check that the super file name is part of the thumb name // # This is a basic sanity check to avoid erasing unrelated directories -// if ( strpos( file, this->getName() ) !== false +// if ( strpos( file, this.getName() ) !== false // || strpos( file, "-thumbnail" ) !== false // "short" thumb name // ) { // purgeList[] = "{dir}/{file}"; @@ -1000,9 +1001,9 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // } // // # Delete the thumbnails -// this->repo->quickPurgeBatch( purgeList ); +// this.repo.quickPurgeBatch( purgeList ); // # Clear out the thumbnail directory if empty -// this->repo->quickCleanDir( dir ); +// this.repo.quickCleanDir( dir ); // } // // /** purgeDescription inherited */ @@ -1016,19 +1017,19 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return OldLocalFile[] // */ // function getHistory( limit = null, start = null, end = null, inc = true ) { -// dbr = this->repo->getReplicaDB(); +// dbr = this.repo.getReplicaDB(); // tables = [ 'oldimage' ]; // fields = OldLocalFile::selectFields(); // conds = opts = join_conds = []; // eq = inc ? '=' : ''; -// conds[] = "oi_name = " . dbr->addQuotes( this->title->getDBkey() ); +// conds[] = "oi_name = " . dbr.addQuotes( this.title.getDBkey() ); // // if ( start ) { -// conds[] = "oi_timestamp addQuotes( dbr->timestamp( start ) ); +// conds[] = "oi_timestamp addQuotes( dbr->timestamp( end ) ); +// conds[] = "oi_timestamp >eq " . dbr.addQuotes( dbr.timestamp( end ) ); // } // // if ( limit ) { @@ -1043,11 +1044,11 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // Hooks::run( 'LocalFile::getHistory', [ &this, &tables, &fields, // &conds, &opts, &join_conds ] ); // -// res = dbr->select( tables, fields, conds, __METHOD__, opts, join_conds ); +// res = dbr.select( tables, fields, conds, __METHOD__, opts, join_conds ); // r = []; // // foreach ( res as row ) { -// r[] = this->repo->newFileFromRow( row ); +// r[] = this.repo.newFileFromRow( row ); // } // // if ( order == 'ASC' ) { @@ -1060,7 +1061,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // /** // * Returns the history of this file, line by line. // * starts with current version, then old versions. -// * uses this->historyLine to check which line to return: +// * uses this.historyLine to check which line to return: // * 0 return line for current version // * 1 query for old versions, return first one // * 2, ... return next old version from above query @@ -1070,45 +1071,45 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // # Polymorphic function name to distinguish foreign and local fetches // fname = get_class( this ) . '::' . __FUNCTION__; // -// dbr = this->repo->getReplicaDB(); +// dbr = this.repo.getReplicaDB(); // -// if ( this->historyLine == 0 ) { // called for the first time, return line from cur -// this->historyRes = dbr->select( 'image', +// if ( this.historyLine == 0 ) { // called for the first time, return line from cur +// this.historyRes = dbr.select( 'image', // [ // '*', // "'' AS oi_archive_name", // '0 as oi_deleted', // 'img_sha1' // ], -// [ 'img_name' => this->title->getDBkey() ], +// [ 'img_name' => this.title.getDBkey() ], // fname // ); // -// if ( 0 == dbr->numRows( this->historyRes ) ) { -// this->historyRes = null; +// if ( 0 == dbr.numRows( this.historyRes ) ) { +// this.historyRes = null; // // return false; // } -// } elseif ( this->historyLine == 1 ) { -// this->historyRes = dbr->select( 'oldimage', '*', -// [ 'oi_name' => this->title->getDBkey() ], +// } elseif ( this.historyLine == 1 ) { +// this.historyRes = dbr.select( 'oldimage', '*', +// [ 'oi_name' => this.title.getDBkey() ], // fname, // [ 'ORDER BY' => 'oi_timestamp DESC' ] // ); // } -// this->historyLine++; +// this.historyLine++; // -// return dbr->fetchObject( this->historyRes ); +// return dbr.fetchObject( this.historyRes ); // } // // /** // * Reset the history pointer to the first element of the history // */ // public function resetHistory() { -// this->historyLine = 0; +// this.historyLine = 0; // -// if ( !is_null( this->historyRes ) ) { -// this->historyRes = null; +// if ( !is_null( this.historyRes ) ) { +// this.historyRes = null; // } // } // @@ -1147,26 +1148,26 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // ) { // global wgContLang; // -// if ( this->getRepo()->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// if ( this.getRepo().getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // -// srcPath = ( src instanceof FSFile ) ? src->getPath() : src; +// srcPath = ( src instanceof FSFile ) ? src.getPath() : src; // if ( !props ) { -// if ( this->repo->isVirtualUrl( srcPath ) +// if ( this.repo.isVirtualUrl( srcPath ) // || FileBackend::isStoragePath( srcPath ) // ) { -// props = this->repo->getFileProps( srcPath ); +// props = this.repo.getFileProps( srcPath ); // } else { // mwProps = new MWFileProps( MimeMagic::singleton() ); -// props = mwProps->getPropsFromPath( srcPath, true ); +// props = mwProps.getPropsFromPath( srcPath, true ); // } // } // // options = []; // handler = MediaHandler::getHandler( props['mime'] ); // if ( handler ) { -// options['headers'] = handler->getStreamHeaders( props['metadata'] ); +// options['headers'] = handler.getStreamHeaders( props['metadata'] ); // } else { // options['headers'] = []; // } @@ -1176,24 +1177,24 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // // Truncate nicely or the DB will do it for us // // non-nicely (dangling multi-byte chars, non-truncated version in cache). -// comment = wgContLang->truncate( comment, 255 ); -// this->synchronized(); // begin -// status = this->publish( src, flags, options ); +// comment = wgContLang.truncate( comment, 255 ); +// this.synchronized(); // begin +// status = this.publish( src, flags, options ); // -// if ( status->successCount >= 2 ) { +// if ( status.successCount >= 2 ) { // // There will be a copy+(one of move,copy,store). // // The first succeeding does not commit us to updating the DB // // since it simply copied the current version to a timestamped file name. // // It is only *preferable* to avoid leaving such files orphaned. // // Once the second operation goes through, then the current version was // // updated and we must therefore update the DB too. -// oldver = status->value; -// if ( !this->recordUpload2( oldver, comment, pageText, props, timestamp, user, tags ) ) { -// status->fatal( 'filenotfound', srcPath ); +// oldver = status.value; +// if ( !this.recordUpload2( oldver, comment, pageText, props, timestamp, user, tags ) ) { +// status.fatal( 'filenotfound', srcPath ); // } // } // -// this->unlock(); // done +// this.unlock(); // done // // return status; // } @@ -1219,12 +1220,12 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // pageText = SpecialUpload::getInitialPageText( desc, license, copyStatus, source ); // -// if ( !this->recordUpload2( oldver, desc, pageText, false, timestamp, user ) ) { +// if ( !this.recordUpload2( oldver, desc, pageText, false, timestamp, user ) ) { // return false; // } // // if ( watch ) { -// user->addWatch( this->getTitle() ); +// user.addWatch( this.getTitle() ); // } // // return true; @@ -1249,65 +1250,65 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // user = wgUser; // } // -// dbw = this->repo->getMasterDB(); +// dbw = this.repo.getMasterDB(); // // # Imports or such might force a certain timestamp; otherwise we generate // # it and can fudge it slightly to keep (name,timestamp) unique on re-upload. // if ( timestamp === false ) { -// timestamp = dbw->timestamp(); +// timestamp = dbw.timestamp(); // allowTimeKludge = true; // } else { // allowTimeKludge = false; // } // -// props = props ?: this->repo->getFileProps( this->getVirtualUrl() ); +// props = props ?: this.repo.getFileProps( this.getVirtualUrl() ); // props['description'] = comment; -// props['user'] = user->getId(); -// props['user_text'] = user->getName(); -// props['timestamp'] = wfTimestamp( TS_MW, timestamp ); // DB -> TS_MW -// this->setProps( props ); +// props['user'] = user.getId(); +// props['user_text'] = user.getName(); +// props['timestamp'] = wfTimestamp( TS_MW, timestamp ); // DB . TS_MW +// this.setProps( props ); // // # Fail now if the file isn't there -// if ( !this->fileExists ) { -// wfDebug( __METHOD__ . ": File " . this->getRel() . " went missing!\n" ); +// if ( !this.fileExists ) { +// wfDebug( __METHOD__ . ": File " . this.getRel() . " went missing!\n" ); // // return false; // } // -// dbw->startAtomic( __METHOD__ ); +// dbw.startAtomic( __METHOD__ ); // // # Test to see if the row exists using INSERT IGNORE // # This avoids race conditions by locking the row until the commit, and also // # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition. -// dbw->insert( 'image', +// dbw.insert( 'image', // [ -// 'img_name' => this->getName(), -// 'img_size' => this->size, -// 'img_width' => intval( this->width ), -// 'img_height' => intval( this->height ), -// 'img_bits' => this->bits, -// 'img_media_type' => this->media_type, -// 'img_major_mime' => this->major_mime, -// 'img_minor_mime' => this->minor_mime, +// 'img_name' => this.getName(), +// 'img_size' => this.size, +// 'img_width' => intval( this.width ), +// 'img_height' => intval( this.height ), +// 'img_bits' => this.bits, +// 'img_media_type' => this.media_type, +// 'img_major_mime' => this.major_mime, +// 'img_minor_mime' => this.minor_mime, // 'img_timestamp' => timestamp, // 'img_description' => comment, -// 'img_user' => user->getId(), -// 'img_user_text' => user->getName(), -// 'img_metadata' => dbw->encodeBlob( this->metadata ), -// 'img_sha1' => this->sha1 +// 'img_user' => user.getId(), +// 'img_user_text' => user.getName(), +// 'img_metadata' => dbw.encodeBlob( this.metadata ), +// 'img_sha1' => this.sha1 // ], // __METHOD__, // 'IGNORE' // ); // -// reupload = ( dbw->affectedRows() == 0 ); +// reupload = ( dbw.affectedRows() == 0 ); // if ( reupload ) { // if ( allowTimeKludge ) { // # Use LOCK IN SHARE MODE to ignore any transaction snapshotting -// ltimestamp = dbw->selectField( +// ltimestamp = dbw.selectField( // 'image', // 'img_timestamp', -// [ 'img_name' => this->getName() ], +// [ 'img_name' => this.getName() ], // __METHOD__, // [ 'LOCK IN SHARE MODE' ] // ); @@ -1316,8 +1317,8 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // # TODO: the image/oldimage tables should be like page/revision with an ID field // if ( lUnixtime && wfTimestamp( TS_UNIX, timestamp ) <= lUnixtime ) { // sleep( 1 ); // fast enough re-uploads would go far in the future otherwise -// timestamp = dbw->timestamp( lUnixtime + 1 ); -// this->timestamp = wfTimestamp( TS_MW, timestamp ); // DB -> TS_MW +// timestamp = dbw.timestamp( lUnixtime + 1 ); +// this.timestamp = wfTimestamp( TS_MW, timestamp ); // DB . TS_MW // } // } // @@ -1327,10 +1328,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // # an image that's not fixable by user operations. // # Collision, this is an update of a file // # Insert previous contents into oldimage -// dbw->insertSelect( 'oldimage', 'image', +// dbw.insertSelect( 'oldimage', 'image', // [ // 'oi_name' => 'img_name', -// 'oi_archive_name' => dbw->addQuotes( oldver ), +// 'oi_archive_name' => dbw.addQuotes( oldver ), // 'oi_size' => 'img_size', // 'oi_width' => 'img_width', // 'oi_height' => 'img_height', @@ -1345,48 +1346,48 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // 'oi_minor_mime' => 'img_minor_mime', // 'oi_sha1' => 'img_sha1' // ], -// [ 'img_name' => this->getName() ], +// [ 'img_name' => this.getName() ], // __METHOD__ // ); // // # Update the current image row -// dbw->update( 'image', +// dbw.update( 'image', // [ -// 'img_size' => this->size, -// 'img_width' => intval( this->width ), -// 'img_height' => intval( this->height ), -// 'img_bits' => this->bits, -// 'img_media_type' => this->media_type, -// 'img_major_mime' => this->major_mime, -// 'img_minor_mime' => this->minor_mime, +// 'img_size' => this.size, +// 'img_width' => intval( this.width ), +// 'img_height' => intval( this.height ), +// 'img_bits' => this.bits, +// 'img_media_type' => this.media_type, +// 'img_major_mime' => this.major_mime, +// 'img_minor_mime' => this.minor_mime, // 'img_timestamp' => timestamp, // 'img_description' => comment, -// 'img_user' => user->getId(), -// 'img_user_text' => user->getName(), -// 'img_metadata' => dbw->encodeBlob( this->metadata ), -// 'img_sha1' => this->sha1 +// 'img_user' => user.getId(), +// 'img_user_text' => user.getName(), +// 'img_metadata' => dbw.encodeBlob( this.metadata ), +// 'img_sha1' => this.sha1 // ], -// [ 'img_name' => this->getName() ], +// [ 'img_name' => this.getName() ], // __METHOD__ // ); // } // -// descTitle = this->getTitle(); -// descId = descTitle->getArticleID(); +// descTitle = this.getTitle(); +// descId = descTitle.getArticleID(); // wikiPage = new WikiFilePage( descTitle ); -// wikiPage->setFile( this ); +// wikiPage.setFile( this ); // // // Add the log entry... // logEntry = new ManualLogEntry( 'upload', reupload ? 'overwrite' : 'upload' ); -// logEntry->setTimestamp( this->timestamp ); -// logEntry->setPerformer( user ); -// logEntry->setComment( comment ); -// logEntry->setTarget( descTitle ); +// logEntry.setTimestamp( this.timestamp ); +// logEntry.setPerformer( user ); +// logEntry.setComment( comment ); +// logEntry.setTarget( descTitle ); // // Allow people using the api to associate log entries with the upload. // // Log has a timestamp, but sometimes different from upload timestamp. -// logEntry->setParameters( +// logEntry.setParameters( // [ -// 'img_sha1' => this->sha1, +// 'img_sha1' => this.sha1, // 'img_timestamp' => timestamp, // ] // ); @@ -1396,13 +1397,13 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // so we later modify the log entry. // // For a similar reason, we avoid making an RC entry // // now and wait until the page exists. -// logId = logEntry->insert(); +// logId = logEntry.insert(); // -// if ( descTitle->exists() ) { +// if ( descTitle.exists() ) { // // Use own context to get the action text in content language // formatter = LogFormatter::newFromEntry( logEntry ); -// formatter->setContext( RequestContext::newExtraneousContext( descTitle ) ); -// editSummary = formatter->getPlainActionText(); +// formatter.setContext( RequestContext::newExtraneousContext( descTitle ) ); +// editSummary = formatter.getPlainActionText(); // // nullRevision = Revision::newNullRevision( // dbw, @@ -1412,14 +1413,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // user // ); // if ( nullRevision ) { -// nullRevision->insertOn( dbw ); +// nullRevision.insertOn( dbw ); // Hooks::run( // 'NewRevisionFromEditComplete', -// [ wikiPage, nullRevision, nullRevision->getParentId(), user ] +// [ wikiPage, nullRevision, nullRevision.getParentId(), user ] // ); -// wikiPage->updateRevisionOn( dbw, nullRevision ); +// wikiPage.updateRevisionOn( dbw, nullRevision ); // // Associate null revision id -// logEntry->setAssociatedRevId( nullRevision->getId() ); +// logEntry.setAssociatedRevId( nullRevision.getId() ); // } // // newPageContent = null; @@ -1430,7 +1431,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // # Defer purges, page creation, and link updates in case they error out. // # The most important thing is that files and the DB registry stay synced. -// dbw->endAtomic( __METHOD__ ); +// dbw.endAtomic( __METHOD__ ); // // # Do some cache purges after final commit so that: // # a) Changes are more likely to be seen post-purge @@ -1444,14 +1445,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // logEntry, logId, descId, tags // ) { // # Update memcache after the commit -// this->invalidateCache(); +// this.invalidateCache(); // // updateLogPage = false; // if ( newPageContent ) { // # New file page; create the description page. // # There's already a log entry, so don't make a second RC entry // # CDN and file cache for the description page are purged by doEditContent. -// status = wikiPage->doEditContent( +// status = wikiPage.doEditContent( // newPageContent, // comment, // EDIT_NEW | EDIT_SUPPRESS_RC, @@ -1459,47 +1460,47 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // user // ); // -// if ( isset( status->value['revision'] ) ) { +// if ( isset( status.value['revision'] ) ) { // /** @var rev Revision */ -// rev = status->value['revision']; +// rev = status.value['revision']; // // Associate new page revision id -// logEntry->setAssociatedRevId( rev->getId() ); +// logEntry.setAssociatedRevId( rev.getId() ); // } // // This relies on the resetArticleID() call in WikiPage::insertOn(), // // which is triggered on descTitle by doEditContent() above. -// if ( isset( status->value['revision'] ) ) { +// if ( isset( status.value['revision'] ) ) { // /** @var rev Revision */ -// rev = status->value['revision']; -// updateLogPage = rev->getPage(); +// rev = status.value['revision']; +// updateLogPage = rev.getPage(); // } // } else { // # Existing file page: invalidate description page cache -// wikiPage->getTitle()->invalidateCache(); -// wikiPage->getTitle()->purgeSquid(); +// wikiPage.getTitle().invalidateCache(); +// wikiPage.getTitle().purgeSquid(); // # Allow the new file version to be patrolled from the page footer // Article::purgePatrolFooterCache( descId ); // } // -// # Update associated rev id. This should be done by logEntry->insert() earlier, +// # Update associated rev id. This should be done by logEntry.insert() earlier, // # but setAssociatedRevId() wasn't called at that point yet... -// logParams = logEntry->getParameters(); -// logParams['associated_rev_id'] = logEntry->getAssociatedRevId(); +// logParams = logEntry.getParameters(); +// logParams['associated_rev_id'] = logEntry.getAssociatedRevId(); // update = [ 'log_params' => LogEntryBase::makeParamBlob( logParams ) ]; // if ( updateLogPage ) { // # Also log page, in case where we just created it above // update['log_page'] = updateLogPage; // } -// this->getRepo()->getMasterDB()->update( +// this.getRepo().getMasterDB().update( // 'logging', // update, // [ 'log_id' => logId ], // __METHOD__ // ); -// this->getRepo()->getMasterDB()->insert( +// this.getRepo().getMasterDB().insert( // 'log_search', // [ // 'ls_field' => 'associated_rev_id', -// 'ls_value' => logEntry->getAssociatedRevId(), +// 'ls_value' => logEntry.getAssociatedRevId(), // 'ls_log_id' => logId, // ], // __METHOD__ @@ -1507,32 +1508,32 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // # Add change tags, if any // if ( tags ) { -// logEntry->setTags( tags ); +// logEntry.setTags( tags ); // } // // # Uploads can be patrolled -// logEntry->setIsPatrollable( true ); +// logEntry.setIsPatrollable( true ); // // # Now that the log entry is up-to-date, make an RC entry. -// logEntry->publish( logId ); +// logEntry.publish( logId ); // // # Run hook for other updates (typically more cache purging) // Hooks::run( 'FileUpload', [ this, reupload, !newPageContent ] ); // // if ( reupload ) { // # Delete old thumbnails -// this->purgeThumbnails(); +// this.purgeThumbnails(); // # Remove the old file from the CDN cache // DeferredUpdates::addUpdate( -// new CdnCacheUpdate( [ this->getUrl() ] ), +// new CdnCacheUpdate( [ this.getUrl() ] ), // DeferredUpdates::PRESEND // ); // } else { // # Update backlink pages pointing to this title if created -// LinksUpdate::queueRecursiveJobsForTable( this->getTitle(), 'imagelinks' ); +// LinksUpdate::queueRecursiveJobsForTable( this.getTitle(), 'imagelinks' ); // } // -// this->prerenderThumbnails(); +// this.prerenderThumbnails(); // } // ), // DeferredUpdates::PRESEND @@ -1544,7 +1545,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // } // // # Invalidate cache for all pages using this file -// DeferredUpdates::addUpdate( new HTMLCacheUpdate( this->getTitle(), 'imagelinks' ) ); +// DeferredUpdates::addUpdate( new HTMLCacheUpdate( this.getTitle(), 'imagelinks' ) ); // // return true; // } @@ -1565,7 +1566,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * archive name, or an empty String if it was a new file. // */ // function publish( src, flags = 0, array options = [] ) { -// return this->publishTo( src, this->getRel(), flags, options ); +// return this.publishTo( src, this.getRel(), flags, options ); // } // // /** @@ -1584,45 +1585,45 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * archive name, or an empty String if it was a new file. // */ // function publishTo( src, dstRel, flags = 0, array options = [] ) { -// srcPath = ( src instanceof FSFile ) ? src->getPath() : src; +// srcPath = ( src instanceof FSFile ) ? src.getPath() : src; // -// repo = this->getRepo(); -// if ( repo->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// repo = this.getRepo(); +// if ( repo.getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // -// this->synchronized(); // begin +// this.synchronized(); // begin // -// archiveName = wfTimestamp( TS_MW ) . '!' . this->getName(); -// archiveRel = 'archive/' . this->getHashPath() . archiveName; +// archiveName = wfTimestamp( TS_MW ) . '!' . this.getName(); +// archiveRel = 'archive/' . this.getHashPath() . archiveName; // -// if ( repo->hasSha1Storage() ) { -// sha1 = repo->isVirtualUrl( srcPath ) -// ? repo->getFileSha1( srcPath ) +// if ( repo.hasSha1Storage() ) { +// sha1 = repo.isVirtualUrl( srcPath ) +// ? repo.getFileSha1( srcPath ) // : FSFile::getSha1Base36FromPath( srcPath ); // /** @var FileBackendDBRepoWrapper wrapperBackend */ -// wrapperBackend = repo->getBackend(); -// dst = wrapperBackend->getPathForSHA1( sha1 ); -// status = repo->quickImport( src, dst ); +// wrapperBackend = repo.getBackend(); +// dst = wrapperBackend.getPathForSHA1( sha1 ); +// status = repo.quickImport( src, dst ); // if ( flags & File::DELETE_SOURCE ) { // unlink( srcPath ); // } // -// if ( this->exists() ) { -// status->value = archiveName; +// if ( this.exists() ) { +// status.value = archiveName; // } // } else { // flags = flags & File::DELETE_SOURCE ? LocalRepo::DELETE_SOURCE : 0; -// status = repo->publish( srcPath, dstRel, archiveRel, flags, options ); +// status = repo.publish( srcPath, dstRel, archiveRel, flags, options ); // -// if ( status->value == 'new' ) { -// status->value = ''; +// if ( status.value == 'new' ) { +// status.value = ''; // } else { -// status->value = archiveName; +// status.value = archiveName; // } // } // -// this->unlock(); // done +// this.unlock(); // done // // return status; // } @@ -1645,46 +1646,46 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // function move( target ) { -// if ( this->getRepo()->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// if ( this.getRepo().getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // -// wfDebugLog( 'imagemove', "Got request to move {this->name} to " . target->getText() ); +// wfDebugLog( 'imagemove', "Got request to move {this.name} to " . target.getText() ); // batch = new LocalFileMoveBatch( this, target ); // -// this->synchronized(); // begin -// batch->addCurrent(); -// archiveNames = batch->addOlds(); -// status = batch->execute(); -// this->unlock(); // done +// this.synchronized(); // begin +// batch.addCurrent(); +// archiveNames = batch.addOlds(); +// status = batch.execute(); +// this.unlock(); // done // -// wfDebugLog( 'imagemove', "Finished moving {this->name}" ); +// wfDebugLog( 'imagemove', "Finished moving {this.name}" ); // // // Purge the source and target files... -// oldTitleFile = wfLocalFile( this->title ); +// oldTitleFile = wfLocalFile( this.title ); // newTitleFile = wfLocalFile( target ); // // To avoid slow purges in the transaction, move them outside... // DeferredUpdates::addUpdate( // new AutoCommitUpdate( -// this->getRepo()->getMasterDB(), +// this.getRepo().getMasterDB(), // __METHOD__, // function () use ( oldTitleFile, newTitleFile, archiveNames ) { -// oldTitleFile->purgeEverything(); +// oldTitleFile.purgeEverything(); // foreach ( archiveNames as archiveName ) { -// oldTitleFile->purgeOldThumbnails( archiveName ); +// oldTitleFile.purgeOldThumbnails( archiveName ); // } -// newTitleFile->purgeEverything(); +// newTitleFile.purgeEverything(); // } // ), // DeferredUpdates::PRESEND // ); // -// if ( status->isOK() ) { +// if ( status.isOK() ) { // // Now switch the Object -// this->title = target; +// this.title = target; // // Force regeneration of the name and hashpath -// unset( this->name ); -// unset( this->hashPath ); +// unset( this.name ); +// unset( this.hashPath ); // } // // return status; @@ -1704,32 +1705,32 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // function delete( reason, suppress = false, user = null ) { -// if ( this->getRepo()->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// if ( this.getRepo().getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // // batch = new LocalFileDeleteBatch( this, reason, suppress, user ); // -// this->synchronized(); // begin -// batch->addCurrent(); +// this.synchronized(); // begin +// batch.addCurrent(); // // Get old version relative paths -// archiveNames = batch->addOlds(); -// status = batch->execute(); -// this->unlock(); // done +// archiveNames = batch.addOlds(); +// status = batch.execute(); +// this.unlock(); // done // -// if ( status->isOK() ) { +// if ( status.isOK() ) { // DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => -1 ] ) ); // } // // // To avoid slow purges in the transaction, move them outside... // DeferredUpdates::addUpdate( // new AutoCommitUpdate( -// this->getRepo()->getMasterDB(), +// this.getRepo().getMasterDB(), // __METHOD__, // function () use ( archiveNames ) { -// this->purgeEverything(); +// this.purgeEverything(); // foreach ( archiveNames as archiveName ) { -// this->purgeOldThumbnails( archiveName ); +// this.purgeOldThumbnails( archiveName ); // } // } // ), @@ -1739,7 +1740,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // Purge the CDN // purgeUrls = []; // foreach ( archiveNames as archiveName ) { -// purgeUrls[] = this->getArchiveUrl( archiveName ); +// purgeUrls[] = this.getArchiveUrl( archiveName ); // } // DeferredUpdates::addUpdate( new CdnCacheUpdate( purgeUrls ), DeferredUpdates::PRESEND ); // @@ -1762,24 +1763,24 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // function deleteOld( archiveName, reason, suppress = false, user = null ) { -// if ( this->getRepo()->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// if ( this.getRepo().getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // // batch = new LocalFileDeleteBatch( this, reason, suppress, user ); // -// this->synchronized(); // begin -// batch->addOld( archiveName ); -// status = batch->execute(); -// this->unlock(); // done +// this.synchronized(); // begin +// batch.addOld( archiveName ); +// status = batch.execute(); +// this.unlock(); // done // -// this->purgeOldThumbnails( archiveName ); -// if ( status->isOK() ) { -// this->purgeDescription(); +// this.purgeOldThumbnails( archiveName ); +// if ( status.isOK() ) { +// this.purgeDescription(); // } // // DeferredUpdates::addUpdate( -// new CdnCacheUpdate( [ this->getArchiveUrl( archiveName ) ] ), +// new CdnCacheUpdate( [ this.getArchiveUrl( archiveName ) ] ), // DeferredUpdates::PRESEND // ); // @@ -1798,26 +1799,26 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // function restore( versions = [], unsuppress = false ) { -// if ( this->getRepo()->getReadOnlyReason() !== false ) { -// return this->readOnlyFatalStatus(); +// if ( this.getRepo().getReadOnlyReason() !== false ) { +// return this.readOnlyFatalStatus(); // } // // batch = new LocalFileRestoreBatch( this, unsuppress ); // -// this->synchronized(); // begin +// this.synchronized(); // begin // if ( !versions ) { -// batch->addAll(); +// batch.addAll(); // } else { -// batch->addIds( versions ); +// batch.addIds( versions ); // } -// status = batch->execute(); -// if ( status->isGood() ) { -// cleanupStatus = batch->cleanup(); -// cleanupStatus->successCount = 0; -// cleanupStatus->failCount = 0; -// status->merge( cleanupStatus ); +// status = batch.execute(); +// if ( status.isGood() ) { +// cleanupStatus = batch.cleanup(); +// cleanupStatus.successCount = 0; +// cleanupStatus.failCount = 0; +// status.merge( cleanupStatus ); // } -// this->unlock(); // done +// this.unlock(); // done // // return status; // } @@ -1832,7 +1833,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return String // */ // function getDescriptionUrl() { -// return this->title->getLocalURL(); +// return this.title.getLocalURL(); // } // // /** @@ -1844,17 +1845,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean|mixed // */ // function getDescriptionText( lang = null ) { -// revision = Revision::newFromTitle( this->title, false, Revision::READ_NORMAL ); +// revision = Revision::newFromTitle( this.title, false, Revision::READ_NORMAL ); // if ( !revision ) { // return false; // } -// content = revision->getContent(); +// content = revision.getContent(); // if ( !content ) { // return false; // } -// pout = content->getParserOutput( this->title, null, new ParserOptions( null, lang ) ); +// pout = content.getParserOutput( this.title, null, new ParserOptions( null, lang ) ); // -// return pout->getText(); +// return pout.getText(); // } // // /** @@ -1863,15 +1864,15 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return String // */ // function getDescription( audience = self::FOR_PUBLIC, User user = null ) { -// this->load(); -// if ( audience == self::FOR_PUBLIC && this->isDeleted( self::DELETED_COMMENT ) ) { +// this.load(); +// if ( audience == self::FOR_PUBLIC && this.isDeleted( self::DELETED_COMMENT ) ) { // return ''; // } elseif ( audience == self::FOR_THIS_USER -// && !this->userCan( self::DELETED_COMMENT, user ) +// && !this.userCan( self::DELETED_COMMENT, user ) // ) { // return ''; // } else { -// return this->description; +// return this.description; // } // } // @@ -1879,9 +1880,9 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean|String // */ // function getTimestamp() { -// this->load(); +// this.load(); // -// return this->timestamp; +// return this.timestamp; // } // // /** @@ -1891,52 +1892,52 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // The DB lookup might return false, e.g. if the file was just deleted, or the shared DB repo // // itself gets it from elsewhere. To avoid repeating the DB lookups in such a case, we // // need to differentiate between null (uninitialized) and false (failed to load). -// if ( this->descriptionTouched === null ) { +// if ( this.descriptionTouched === null ) { // cond = [ -// 'page_namespace' => this->title->getNamespace(), -// 'page_title' => this->title->getDBkey() +// 'page_namespace' => this.title.getNamespace(), +// 'page_title' => this.title.getDBkey() // ]; -// touched = this->repo->getReplicaDB()->selectField( 'page', 'page_touched', cond, __METHOD__ ); -// this->descriptionTouched = touched ? wfTimestamp( TS_MW, touched ) : false; +// touched = this.repo.getReplicaDB().selectField( 'page', 'page_touched', cond, __METHOD__ ); +// this.descriptionTouched = touched ? wfTimestamp( TS_MW, touched ) : false; // } // -// return this->descriptionTouched; +// return this.descriptionTouched; // } // // /** // * @return String // */ // function getSha1() { -// this->load(); +// this.load(); // // Initialise now if necessary -// if ( this->sha1 == '' && this->fileExists ) { -// this->synchronized(); // begin +// if ( this.sha1 == '' && this.fileExists ) { +// this.synchronized(); // begin // -// this->sha1 = this->repo->getFileSha1( this->getPath() ); -// if ( !wfReadOnly() && strval( this->sha1 ) != '' ) { -// dbw = this->repo->getMasterDB(); -// dbw->update( 'image', -// [ 'img_sha1' => this->sha1 ], -// [ 'img_name' => this->getName() ], +// this.sha1 = this.repo.getFileSha1( this.getPath() ); +// if ( !wfReadOnly() && strval( this.sha1 ) != '' ) { +// dbw = this.repo.getMasterDB(); +// dbw.update( 'image', +// [ 'img_sha1' => this.sha1 ], +// [ 'img_name' => this.getName() ], // __METHOD__ ); -// this->invalidateCache(); +// this.invalidateCache(); // } // -// this->unlock(); // done +// this.unlock(); // done // } // -// return this->sha1; +// return this.sha1; // } // // /** // * @return boolean Whether to cache in RepoGroup (this avoids OOMs) // */ // function isCacheable() { -// this->load(); +// this.load(); // // // If extra data (metadata) was not loaded then it must have been large -// return this->extraDataLoaded -// && strlen( serialize( this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN; +// return this.extraDataLoaded +// && strlen( serialize( this.metadata ) ) <= self::CACHE_FIELD_MAX_LEN; // } // // /** @@ -1944,8 +1945,8 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @since 1.28 // */ // public function acquireFileLock() { -// return this->getRepo()->getBackend()->lockFiles( -// [ this->getPath() ], LockManager::LOCK_EX, 10 +// return this.getRepo().getBackend().lockFiles( +// [ this.getPath() ], LockManager::LOCK_EX, 10 // ); // } // @@ -1954,8 +1955,8 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @since 1.28 // */ // public function releaseFileLock() { -// return this->getRepo()->getBackend()->unlockFiles( -// [ this->getPath() ], LockManager::LOCK_EX +// return this.getRepo().getBackend().unlockFiles( +// [ this.getPath() ], LockManager::LOCK_EX // ); // } // @@ -1969,40 +1970,40 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return boolean Whether the file synchronized owns/spawned the DB transaction // */ // public function synchronized() { -// if ( !this->locked ) { +// if ( !this.locked ) { // logger = LoggerFactory::getInstance( 'LocalFile' ); // -// dbw = this->repo->getMasterDB(); -// makesTransaction = !dbw->trxLevel(); -// dbw->startAtomic( self::ATOMIC_SECTION_LOCK ); +// dbw = this.repo.getMasterDB(); +// makesTransaction = !dbw.trxLevel(); +// dbw.startAtomic( self::ATOMIC_SECTION_LOCK ); // // Bug 54736: use simple synchronized to handle when the file does not exist. // // SELECT FOR UPDATE prevents changes, not other SELECTs with FOR UPDATE. // // Also, that would cause contention on INSERT of similarly named rows. -// status = this->acquireFileLock(); // represents all versions of the file -// if ( !status->isGood() ) { -// dbw->endAtomic( self::ATOMIC_SECTION_LOCK ); -// logger->warning( "Failed to synchronized '{file}'", [ 'file' => this->name ] ); +// status = this.acquireFileLock(); // represents all versions of the file +// if ( !status.isGood() ) { +// dbw.endAtomic( self::ATOMIC_SECTION_LOCK ); +// logger.warning( "Failed to synchronized '{file}'", [ 'file' => this.name ] ); // // throw new LocalFileLockError( status ); // } // // Release the synchronized *after* commit to avoid row-level contention. // // Make sure it triggers on rollback() as well as commit() (T132921). -// dbw->onTransactionResolution( +// dbw.onTransactionResolution( // function () use ( logger ) { -// status = this->releaseFileLock(); -// if ( !status->isGood() ) { -// logger->error( "Failed to unlock '{file}'", [ 'file' => this->name ] ); +// status = this.releaseFileLock(); +// if ( !status.isGood() ) { +// logger.error( "Failed to unlock '{file}'", [ 'file' => this.name ] ); // } // }, // __METHOD__ // ); // // Callers might care if the SELECT snapshot is safely fresh -// this->lockedOwnTrx = makesTransaction; +// this.lockedOwnTrx = makesTransaction; // } // -// this->locked++; +// this.locked++; // -// return this->lockedOwnTrx; +// return this.lockedOwnTrx; // } // // /** @@ -2014,12 +2015,12 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * may happen immediately or at some point after calling this // */ // public function unlock() { -// if ( this->locked ) { -// --this->locked; -// if ( !this->locked ) { -// dbw = this->repo->getMasterDB(); -// dbw->endAtomic( self::ATOMIC_SECTION_LOCK ); -// this->lockedOwnTrx = false; +// if ( this.locked ) { +// --this.locked; +// if ( !this.locked ) { +// dbw = this.repo.getMasterDB(); +// dbw.endAtomic( self::ATOMIC_SECTION_LOCK ); +// this.lockedOwnTrx = false; // } // } // } @@ -2028,15 +2029,15 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // protected function readOnlyFatalStatus() { -// return this->getRepo()->newFatal( 'filereadonlyerror', this->getName(), -// this->getRepo()->getName(), this->getRepo()->getReadOnlyReason() ); +// return this.getRepo().newFatal( 'filereadonlyerror', this.getName(), +// this.getRepo().getName(), this.getRepo().getReadOnlyReason() ); // } // // /** // * Clean up any dangling locks // */ // function __destruct() { -// this->unlock(); +// this.unlock(); // } // } // LocalFile class // @@ -2078,28 +2079,28 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param User|null user // */ // function __construct( File file, reason = '', suppress = false, user = null ) { -// this->file = file; -// this->reason = reason; -// this->suppress = suppress; +// this.file = file; +// this.reason = reason; +// this.suppress = suppress; // if ( user ) { -// this->user = user; +// this.user = user; // } else { // global wgUser; -// this->user = wgUser; +// this.user = wgUser; // } -// this->status = file->repo->newGood(); +// this.status = file.repo.newGood(); // } // // public function addCurrent() { -// this->srcRels['.'] = this->file->getRel(); +// this.srcRels['.'] = this.file.getRel(); // } // // /** // * @param String oldName // */ // public function addOld( oldName ) { -// this->srcRels[oldName] = this->file->getArchiveRel( oldName ); -// this->archiveUrls[] = this->file->getArchiveUrl( oldName ); +// this.srcRels[oldName] = this.file.getArchiveRel( oldName ); +// this.archiveUrls[] = this.file.getArchiveUrl( oldName ); // } // // /** @@ -2109,16 +2110,16 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // public function addOlds() { // archiveNames = []; // -// dbw = this->file->repo->getMasterDB(); -// result = dbw->select( 'oldimage', +// dbw = this.file.repo.getMasterDB(); +// result = dbw.select( 'oldimage', // [ 'oi_archive_name' ], -// [ 'oi_name' => this->file->getName() ], +// [ 'oi_name' => this.file.getName() ], // __METHOD__ // ); // // foreach ( result as row ) { -// this->addOld( row->oi_archive_name ); -// archiveNames[] = row->oi_archive_name; +// this.addOld( row.oi_archive_name ); +// archiveNames[] = row.oi_archive_name; // } // // return archiveNames; @@ -2128,11 +2129,11 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return array // */ // protected function getOldRels() { -// if ( !isset( this->srcRels['.'] ) ) { -// oldRels =& this->srcRels; +// if ( !isset( this.srcRels['.'] ) ) { +// oldRels =& this.srcRels; // deleteCurrent = false; // } else { -// oldRels = this->srcRels; +// oldRels = this.srcRels; // unset( oldRels['.'] ); // deleteCurrent = true; // } @@ -2145,53 +2146,53 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // protected function getHashes() { // hashes = []; -// list( oldRels, deleteCurrent ) = this->getOldRels(); +// list( oldRels, deleteCurrent ) = this.getOldRels(); // // if ( deleteCurrent ) { -// hashes['.'] = this->file->getSha1(); +// hashes['.'] = this.file.getSha1(); // } // // if ( count( oldRels ) ) { -// dbw = this->file->repo->getMasterDB(); -// res = dbw->select( +// dbw = this.file.repo.getMasterDB(); +// res = dbw.select( // 'oldimage', // [ 'oi_archive_name', 'oi_sha1' ], // [ 'oi_archive_name' => array_keys( oldRels ), -// 'oi_name' => this->file->getName() ], // performance +// 'oi_name' => this.file.getName() ], // performance // __METHOD__ // ); // // foreach ( res as row ) { -// if ( rtrim( row->oi_sha1, "\0" ) === '' ) { +// if ( rtrim( row.oi_sha1, "\0" ) === '' ) { // // Get the hash from the file -// oldUrl = this->file->getArchiveVirtualUrl( row->oi_archive_name ); -// props = this->file->repo->getFileProps( oldUrl ); +// oldUrl = this.file.getArchiveVirtualUrl( row.oi_archive_name ); +// props = this.file.repo.getFileProps( oldUrl ); // // if ( props['fileExists'] ) { // // Upgrade the oldimage row -// dbw->update( 'oldimage', +// dbw.update( 'oldimage', // [ 'oi_sha1' => props['sha1'] ], -// [ 'oi_name' => this->file->getName(), 'oi_archive_name' => row->oi_archive_name ], +// [ 'oi_name' => this.file.getName(), 'oi_archive_name' => row.oi_archive_name ], // __METHOD__ ); -// hashes[row->oi_archive_name] = props['sha1']; +// hashes[row.oi_archive_name] = props['sha1']; // } else { -// hashes[row->oi_archive_name] = false; +// hashes[row.oi_archive_name] = false; // } // } else { -// hashes[row->oi_archive_name] = row->oi_sha1; +// hashes[row.oi_archive_name] = row.oi_sha1; // } // } // } // -// missing = array_diff_key( this->srcRels, hashes ); +// missing = array_diff_key( this.srcRels, hashes ); // // foreach ( missing as name => rel ) { -// this->status->error( 'filedelete-old-unregistered', name ); +// this.status.error( 'filedelete-old-unregistered', name ); // } // // foreach ( hashes as name => hash ) { // if ( !hash ) { -// this->status->error( 'filedelete-missing', this->srcRels[name] ); +// this.status.error( 'filedelete-missing', this.srcRels[name] ); // unset( hashes[name] ); // } // } @@ -2201,38 +2202,38 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // protected function doDBInserts() { // now = time(); -// dbw = this->file->repo->getMasterDB(); -// encTimestamp = dbw->addQuotes( dbw->timestamp( now ) ); -// encUserId = dbw->addQuotes( this->user->getId() ); -// encReason = dbw->addQuotes( this->reason ); -// encGroup = dbw->addQuotes( 'deleted' ); -// ext = this->file->getExtension(); +// dbw = this.file.repo.getMasterDB(); +// encTimestamp = dbw.addQuotes( dbw.timestamp( now ) ); +// encUserId = dbw.addQuotes( this.user.getId() ); +// encReason = dbw.addQuotes( this.reason ); +// encGroup = dbw.addQuotes( 'deleted' ); +// ext = this.file.getExtension(); // dotExt = ext === '' ? '' : ".ext"; -// encExt = dbw->addQuotes( dotExt ); -// list( oldRels, deleteCurrent ) = this->getOldRels(); +// encExt = dbw.addQuotes( dotExt ); +// list( oldRels, deleteCurrent ) = this.getOldRels(); // // // Bitfields to further suppress the content -// if ( this->suppress ) { +// if ( this.suppress ) { // bitfield = Revision::SUPPRESSED_ALL; // } else { // bitfield = 'oi_deleted'; // } // // if ( deleteCurrent ) { -// dbw->insertSelect( +// dbw.insertSelect( // 'filearchive', // 'image', // [ // 'fa_storage_group' => encGroup, -// 'fa_storage_key' => dbw->conditional( +// 'fa_storage_key' => dbw.conditional( // [ 'img_sha1' => '' ], -// dbw->addQuotes( '' ), -// dbw->buildConcat( [ "img_sha1", encExt ] ) +// dbw.addQuotes( '' ), +// dbw.buildConcat( [ "img_sha1", encExt ] ) // ), // 'fa_deleted_user' => encUserId, // 'fa_deleted_timestamp' => encTimestamp, // 'fa_deleted_reason' => encReason, -// 'fa_deleted' => this->suppress ? bitfield : 0, +// 'fa_deleted' => this.suppress ? bitfield : 0, // 'fa_name' => 'img_name', // 'fa_archive_name' => 'NULL', // 'fa_size' => 'img_size', @@ -2249,17 +2250,17 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // 'fa_timestamp' => 'img_timestamp', // 'fa_sha1' => 'img_sha1' // ], -// [ 'img_name' => this->file->getName() ], +// [ 'img_name' => this.file.getName() ], // __METHOD__ // ); // } // // if ( count( oldRels ) ) { -// res = dbw->select( +// res = dbw.select( // 'oldimage', // OldLocalFile::selectFields(), // [ -// 'oi_name' => this->file->getName(), +// 'oi_name' => this.file.getName(), // 'oi_archive_name' => array_keys( oldRels ) // ], // __METHOD__, @@ -2270,50 +2271,50 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // rowsInsert[] = [ // // Deletion-specific fields // 'fa_storage_group' => 'deleted', -// 'fa_storage_key' => ( row->oi_sha1 === '' ) +// 'fa_storage_key' => ( row.oi_sha1 === '' ) // ? '' -// : "{row->oi_sha1}{dotExt}", -// 'fa_deleted_user' => this->user->getId(), -// 'fa_deleted_timestamp' => dbw->timestamp( now ), -// 'fa_deleted_reason' => this->reason, +// : "{row.oi_sha1}{dotExt}", +// 'fa_deleted_user' => this.user.getId(), +// 'fa_deleted_timestamp' => dbw.timestamp( now ), +// 'fa_deleted_reason' => this.reason, // // Counterpart fields -// 'fa_deleted' => this->suppress ? bitfield : row->oi_deleted, -// 'fa_name' => row->oi_name, -// 'fa_archive_name' => row->oi_archive_name, -// 'fa_size' => row->oi_size, -// 'fa_width' => row->oi_width, -// 'fa_height' => row->oi_height, -// 'fa_metadata' => row->oi_metadata, -// 'fa_bits' => row->oi_bits, -// 'fa_media_type' => row->oi_media_type, -// 'fa_major_mime' => row->oi_major_mime, -// 'fa_minor_mime' => row->oi_minor_mime, -// 'fa_description' => row->oi_description, -// 'fa_user' => row->oi_user, -// 'fa_user_text' => row->oi_user_text, -// 'fa_timestamp' => row->oi_timestamp, -// 'fa_sha1' => row->oi_sha1 +// 'fa_deleted' => this.suppress ? bitfield : row.oi_deleted, +// 'fa_name' => row.oi_name, +// 'fa_archive_name' => row.oi_archive_name, +// 'fa_size' => row.oi_size, +// 'fa_width' => row.oi_width, +// 'fa_height' => row.oi_height, +// 'fa_metadata' => row.oi_metadata, +// 'fa_bits' => row.oi_bits, +// 'fa_media_type' => row.oi_media_type, +// 'fa_major_mime' => row.oi_major_mime, +// 'fa_minor_mime' => row.oi_minor_mime, +// 'fa_description' => row.oi_description, +// 'fa_user' => row.oi_user, +// 'fa_user_text' => row.oi_user_text, +// 'fa_timestamp' => row.oi_timestamp, +// 'fa_sha1' => row.oi_sha1 // ]; // } // -// dbw->insert( 'filearchive', rowsInsert, __METHOD__ ); +// dbw.insert( 'filearchive', rowsInsert, __METHOD__ ); // } // } // // function doDBDeletes() { -// dbw = this->file->repo->getMasterDB(); -// list( oldRels, deleteCurrent ) = this->getOldRels(); +// dbw = this.file.repo.getMasterDB(); +// list( oldRels, deleteCurrent ) = this.getOldRels(); // // if ( count( oldRels ) ) { -// dbw->delete( 'oldimage', +// dbw.delete( 'oldimage', // [ -// 'oi_name' => this->file->getName(), +// 'oi_name' => this.file.getName(), // 'oi_archive_name' => array_keys( oldRels ) // ], __METHOD__ ); // } // // if ( deleteCurrent ) { -// dbw->delete( 'image', [ 'img_name' => this->file->getName() ], __METHOD__ ); +// dbw.delete( 'image', [ 'img_name' => this.file.getName() ], __METHOD__ ); // } // } // @@ -2322,58 +2323,58 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // public function execute() { -// repo = this->file->getRepo(); -// this->file->synchronized(); +// repo = this.file.getRepo(); +// this.file.synchronized(); // // // Prepare deletion batch -// hashes = this->getHashes(); -// this->deletionBatch = []; -// ext = this->file->getExtension(); +// hashes = this.getHashes(); +// this.deletionBatch = []; +// ext = this.file.getExtension(); // dotExt = ext === '' ? '' : ".ext"; // -// foreach ( this->srcRels as name => srcRel ) { +// foreach ( this.srcRels as name => srcRel ) { // // Skip files that have no hash (e.g. missing DB record, or sha1 field and file source) // if ( isset( hashes[name] ) ) { // hash = hashes[name]; // key = hash . dotExt; -// dstRel = repo->getDeletedHashPath( key ) . key; -// this->deletionBatch[name] = [ srcRel, dstRel ]; +// dstRel = repo.getDeletedHashPath( key ) . key; +// this.deletionBatch[name] = [ srcRel, dstRel ]; // } // } // -// if ( !repo->hasSha1Storage() ) { +// if ( !repo.hasSha1Storage() ) { // // Removes non-existent file from the batch, so we don't get errors. // // This also handles files in the 'deleted' zone deleted via revision deletion. -// checkStatus = this->removeNonexistentFiles( this->deletionBatch ); -// if ( !checkStatus->isGood() ) { -// this->status->merge( checkStatus ); -// return this->status; +// checkStatus = this.removeNonexistentFiles( this.deletionBatch ); +// if ( !checkStatus.isGood() ) { +// this.status.merge( checkStatus ); +// return this.status; // } -// this->deletionBatch = checkStatus->value; +// this.deletionBatch = checkStatus.value; // // // Execute the file deletion batch -// status = this->file->repo->deleteBatch( this->deletionBatch ); -// if ( !status->isGood() ) { -// this->status->merge( status ); +// status = this.file.repo.deleteBatch( this.deletionBatch ); +// if ( !status.isGood() ) { +// this.status.merge( status ); // } // } // -// if ( !this->status->isOK() ) { +// if ( !this.status.isOK() ) { // // Critical file deletion error; abort -// this->file->unlock(); +// this.file.unlock(); // -// return this->status; +// return this.status; // } // // // Copy the image/oldimage rows to filearchive -// this->doDBInserts(); +// this.doDBInserts(); // // Delete image/oldimage rows -// this->doDBDeletes(); +// this.doDBDeletes(); // // // Commit and return -// this->file->unlock(); +// this.file.unlock(); // -// return this->status; +// return this.status; // } // // /** @@ -2386,13 +2387,13 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // foreach ( batch as batchItem ) { // list( src, ) = batchItem; -// files[src] = this->file->repo->getVirtualUrl( 'public' ) . '/' . rawurlencode( src ); +// files[src] = this.file.repo.getVirtualUrl( 'public' ) . '/' . rawurlencode( src ); // } // -// result = this->file->repo->fileExistsBatch( files ); +// result = this.file.repo.fileExistsBatch( files ); // if ( in_array( null, result, true ) ) { // return Status::newFatal( 'backend-fail-@gplx.Internal protected', -// this->file->repo->getBackend()->getName() ); +// this.file.repo.getBackend().getName() ); // } // // foreach ( batch as batchItem ) { @@ -2432,10 +2433,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param boolean unsuppress // */ // function __construct( File file, unsuppress = false ) { -// this->file = file; -// this->cleanupBatch = this->ids = []; -// this->ids = []; -// this->unsuppress = unsuppress; +// this.file = file; +// this.cleanupBatch = this.ids = []; +// this.ids = []; +// this.unsuppress = unsuppress; // } // // /** @@ -2443,7 +2444,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param int fa_id // */ // public function addId( fa_id ) { -// this->ids[] = fa_id; +// this.ids[] = fa_id; // } // // /** @@ -2451,14 +2452,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param int[] ids // */ // public function addIds( ids ) { -// this->ids = array_merge( this->ids, ids ); +// this.ids = array_merge( this.ids, ids ); // } // // /** // * Add all revisions of the file // */ // public function addAll() { -// this->all = true; +// this.all = true; // } // // /** @@ -2473,19 +2474,19 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // /** @var Language */ // global wgLang; // -// repo = this->file->getRepo(); -// if ( !this->all && !this->ids ) { +// repo = this.file.getRepo(); +// if ( !this.all && !this.ids ) { // // Do nothing -// return repo->newGood(); +// return repo.newGood(); // } // -// lockOwnsTrx = this->file->synchronized(); +// lockOwnsTrx = this.file.synchronized(); // -// dbw = this->file->repo->getMasterDB(); -// status = this->file->repo->newGood(); +// dbw = this.file.repo.getMasterDB(); +// status = this.file.repo.newGood(); // -// exists = (boolean)dbw->selectField( 'image', '1', -// [ 'img_name' => this->file->getName() ], +// exists = (boolean)dbw.selectField( 'image', '1', +// [ 'img_name' => this.file.getName() ], // __METHOD__, // // The synchronized() should already prevents changes, but this still may need // // to bypass any transaction snapshot. However, if synchronized() started the @@ -2495,13 +2496,13 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // // Fetch all or selected archived revisions for the file, // // sorted from the most recent to the oldest. -// conditions = [ 'fa_name' => this->file->getName() ]; +// conditions = [ 'fa_name' => this.file.getName() ]; // -// if ( !this->all ) { -// conditions['fa_id'] = this->ids; +// if ( !this.all ) { +// conditions['fa_id'] = this.ids; // } // -// result = dbw->select( +// result = dbw.select( // 'filearchive', // ArchivedFile::selectFields(), // conditions, @@ -2518,30 +2519,30 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // archiveNames = []; // // foreach ( result as row ) { -// idsPresent[] = row->fa_id; +// idsPresent[] = row.fa_id; // -// if ( row->fa_name != this->file->getName() ) { -// status->error( 'undelete-filename-mismatch', wgLang->timeanddate( row->fa_timestamp ) ); -// status->failCount++; +// if ( row.fa_name != this.file.getName() ) { +// status.error( 'undelete-filename-mismatch', wgLang.timeanddate( row.fa_timestamp ) ); +// status.failCount++; // continue; // } // -// if ( row->fa_storage_key == '' ) { +// if ( row.fa_storage_key == '' ) { // // Revision was missing pre-deletion -// status->error( 'undelete-bad-store-key', wgLang->timeanddate( row->fa_timestamp ) ); -// status->failCount++; +// status.error( 'undelete-bad-store-key', wgLang.timeanddate( row.fa_timestamp ) ); +// status.failCount++; // continue; // } // -// deletedRel = repo->getDeletedHashPath( row->fa_storage_key ) . -// row->fa_storage_key; -// deletedUrl = repo->getVirtualUrl() . '/deleted/' . deletedRel; +// deletedRel = repo.getDeletedHashPath( row.fa_storage_key ) . +// row.fa_storage_key; +// deletedUrl = repo.getVirtualUrl() . '/deleted/' . deletedRel; // -// if ( isset( row->fa_sha1 ) ) { -// sha1 = row->fa_sha1; +// if ( isset( row.fa_sha1 ) ) { +// sha1 = row.fa_sha1; // } else { // // old row, populate from key -// sha1 = LocalRepo::getHashFromKey( row->fa_storage_key ); +// sha1 = LocalRepo::getHashFromKey( row.fa_storage_key ); // } // // # Fix leading zero @@ -2549,93 +2550,93 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // sha1 = substr( sha1, 1 ); // } // -// if ( is_null( row->fa_major_mime ) || row->fa_major_mime == 'unknown' -// || is_null( row->fa_minor_mime ) || row->fa_minor_mime == 'unknown' -// || is_null( row->fa_media_type ) || row->fa_media_type == 'UNKNOWN' -// || is_null( row->fa_metadata ) +// if ( is_null( row.fa_major_mime ) || row.fa_major_mime == 'unknown' +// || is_null( row.fa_minor_mime ) || row.fa_minor_mime == 'unknown' +// || is_null( row.fa_media_type ) || row.fa_media_type == 'UNKNOWN' +// || is_null( row.fa_metadata ) // ) { // // Refresh our metadata // // Required for a new current revision; nice for older ones too. :) -// props = RepoGroup::singleton()->getFileProps( deletedUrl ); +// props = RepoGroup::singleton().getFileProps( deletedUrl ); // } else { // props = [ -// 'minor_mime' => row->fa_minor_mime, -// 'major_mime' => row->fa_major_mime, -// 'media_type' => row->fa_media_type, -// 'metadata' => row->fa_metadata +// 'minor_mime' => row.fa_minor_mime, +// 'major_mime' => row.fa_major_mime, +// 'media_type' => row.fa_media_type, +// 'metadata' => row.fa_metadata // ]; // } // // if ( first && !exists ) { // // This revision will be published as the new current version -// destRel = this->file->getRel(); +// destRel = this.file.getRel(); // insertCurrent = [ -// 'img_name' => row->fa_name, -// 'img_size' => row->fa_size, -// 'img_width' => row->fa_width, -// 'img_height' => row->fa_height, +// 'img_name' => row.fa_name, +// 'img_size' => row.fa_size, +// 'img_width' => row.fa_width, +// 'img_height' => row.fa_height, // 'img_metadata' => props['metadata'], -// 'img_bits' => row->fa_bits, +// 'img_bits' => row.fa_bits, // 'img_media_type' => props['media_type'], // 'img_major_mime' => props['major_mime'], // 'img_minor_mime' => props['minor_mime'], -// 'img_description' => row->fa_description, -// 'img_user' => row->fa_user, -// 'img_user_text' => row->fa_user_text, -// 'img_timestamp' => row->fa_timestamp, +// 'img_description' => row.fa_description, +// 'img_user' => row.fa_user, +// 'img_user_text' => row.fa_user_text, +// 'img_timestamp' => row.fa_timestamp, // 'img_sha1' => sha1 // ]; // // // The live (current) version cannot be hidden! -// if ( !this->unsuppress && row->fa_deleted ) { -// status->fatal( 'undeleterevdel' ); -// this->file->unlock(); +// if ( !this.unsuppress && row.fa_deleted ) { +// status.fatal( 'undeleterevdel' ); +// this.file.unlock(); // return status; // } // } else { -// archiveName = row->fa_archive_name; +// archiveName = row.fa_archive_name; // // if ( archiveName == '' ) { // // This was originally a current version; we // // have to devise a new archive name for it. // // Format is ! -// timestamp = wfTimestamp( TS_UNIX, row->fa_deleted_timestamp ); +// timestamp = wfTimestamp( TS_UNIX, row.fa_deleted_timestamp ); // // do { -// archiveName = wfTimestamp( TS_MW, timestamp ) . '!' . row->fa_name; +// archiveName = wfTimestamp( TS_MW, timestamp ) . '!' . row.fa_name; // timestamp++; // } while ( isset( archiveNames[archiveName] ) ); // } // // archiveNames[archiveName] = true; -// destRel = this->file->getArchiveRel( archiveName ); +// destRel = this.file.getArchiveRel( archiveName ); // insertBatch[] = [ -// 'oi_name' => row->fa_name, +// 'oi_name' => row.fa_name, // 'oi_archive_name' => archiveName, -// 'oi_size' => row->fa_size, -// 'oi_width' => row->fa_width, -// 'oi_height' => row->fa_height, -// 'oi_bits' => row->fa_bits, -// 'oi_description' => row->fa_description, -// 'oi_user' => row->fa_user, -// 'oi_user_text' => row->fa_user_text, -// 'oi_timestamp' => row->fa_timestamp, +// 'oi_size' => row.fa_size, +// 'oi_width' => row.fa_width, +// 'oi_height' => row.fa_height, +// 'oi_bits' => row.fa_bits, +// 'oi_description' => row.fa_description, +// 'oi_user' => row.fa_user, +// 'oi_user_text' => row.fa_user_text, +// 'oi_timestamp' => row.fa_timestamp, // 'oi_metadata' => props['metadata'], // 'oi_media_type' => props['media_type'], // 'oi_major_mime' => props['major_mime'], // 'oi_minor_mime' => props['minor_mime'], -// 'oi_deleted' => this->unsuppress ? 0 : row->fa_deleted, +// 'oi_deleted' => this.unsuppress ? 0 : row.fa_deleted, // 'oi_sha1' => sha1 ]; // } // -// deleteIds[] = row->fa_id; +// deleteIds[] = row.fa_id; // -// if ( !this->unsuppress && row->fa_deleted & File::DELETED_FILE ) { +// if ( !this.unsuppress && row.fa_deleted & File::DELETED_FILE ) { // // private files can stay where they are -// status->successCount++; +// status.successCount++; // } else { // storeBatch[] = [ deletedUrl, 'public', destRel ]; -// this->cleanupBatch[] = row->fa_storage_key; +// this.cleanupBatch[] = row.fa_storage_key; // } // // first = false; @@ -2644,32 +2645,32 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // unset( result ); // // // Add a warning to the status Object for missing IDs -// missingIds = array_diff( this->ids, idsPresent ); +// missingIds = array_diff( this.ids, idsPresent ); // // foreach ( missingIds as id ) { -// status->error( 'undelete-missing-filearchive', id ); +// status.error( 'undelete-missing-filearchive', id ); // } // -// if ( !repo->hasSha1Storage() ) { +// if ( !repo.hasSha1Storage() ) { // // Remove missing files from batch, so we don't get errors when undeleting them -// checkStatus = this->removeNonexistentFiles( storeBatch ); -// if ( !checkStatus->isGood() ) { -// status->merge( checkStatus ); +// checkStatus = this.removeNonexistentFiles( storeBatch ); +// if ( !checkStatus.isGood() ) { +// status.merge( checkStatus ); // return status; // } -// storeBatch = checkStatus->value; +// storeBatch = checkStatus.value; // // // Run the store batch // // Use the OVERWRITE_SAME flag to smooth over a common error -// storeStatus = this->file->repo->storeBatch( storeBatch, FileRepo::OVERWRITE_SAME ); -// status->merge( storeStatus ); +// storeStatus = this.file.repo.storeBatch( storeBatch, FileRepo::OVERWRITE_SAME ); +// status.merge( storeStatus ); // -// if ( !status->isGood() ) { +// if ( !status.isGood() ) { // // Even if some files could be copied, fail entirely as that is the // // easiest thing to do without data loss -// this->cleanupFailedBatch( storeStatus, storeBatch ); -// status->setOK( false ); -// this->file->unlock(); +// this.cleanupFailedBatch( storeStatus, storeBatch ); +// status.setOK( false ); +// this.file.unlock(); // // return status; // } @@ -2682,34 +2683,34 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // public zone. // // This is not ideal, which is why it's important to synchronized the image row. // if ( insertCurrent ) { -// dbw->insert( 'image', insertCurrent, __METHOD__ ); +// dbw.insert( 'image', insertCurrent, __METHOD__ ); // } // // if ( insertBatch ) { -// dbw->insert( 'oldimage', insertBatch, __METHOD__ ); +// dbw.insert( 'oldimage', insertBatch, __METHOD__ ); // } // // if ( deleteIds ) { -// dbw->delete( 'filearchive', +// dbw.delete( 'filearchive', // [ 'fa_id' => deleteIds ], // __METHOD__ ); // } // // // If store batch is empty (all files are missing), deletion is to be considered successful -// if ( status->successCount > 0 || !storeBatch || repo->hasSha1Storage() ) { +// if ( status.successCount > 0 || !storeBatch || repo.hasSha1Storage() ) { // if ( !exists ) { -// wfDebug( __METHOD__ . " restored {status->successCount} items, creating a new current\n" ); +// wfDebug( __METHOD__ . " restored {status.successCount} items, creating a new current\n" ); // // DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => 1 ] ) ); // -// this->file->purgeEverything(); +// this.file.purgeEverything(); // } else { -// wfDebug( __METHOD__ . " restored {status->successCount} as archived versions\n" ); -// this->file->purgeDescription(); +// wfDebug( __METHOD__ . " restored {status.successCount} as archived versions\n" ); +// this.file.purgeDescription(); // } // } // -// this->file->unlock(); +// this.file.unlock(); // // return status; // } @@ -2725,10 +2726,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // files[file[0]] = file[0]; // } // -// result = this->file->repo->fileExistsBatch( files ); +// result = this.file.repo.fileExistsBatch( files ); // if ( in_array( null, result, true ) ) { // return Status::newFatal( 'backend-fail-@gplx.Internal protected', -// this->file->repo->getBackend()->getName() ); +// this.file.repo.getBackend().getName() ); // } // // foreach ( triplets as file ) { @@ -2747,14 +2748,14 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // protected function removeNonexistentFromCleanup( batch ) { // files = newBatch = []; -// repo = this->file->repo; +// repo = this.file.repo; // // foreach ( batch as file ) { -// files[file] = repo->getVirtualUrl( 'deleted' ) . '/' . -// rawurlencode( repo->getDeletedHashPath( file ) . file ); +// files[file] = repo.getVirtualUrl( 'deleted' ) . '/' . +// rawurlencode( repo.getDeletedHashPath( file ) . file ); // } // -// result = repo->fileExistsBatch( files ); +// result = repo.fileExistsBatch( files ); // // foreach ( batch as file ) { // if ( result[file] ) { @@ -2771,13 +2772,13 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // public function cleanup() { -// if ( !this->cleanupBatch ) { -// return this->file->repo->newGood(); +// if ( !this.cleanupBatch ) { +// return this.file.repo.newGood(); // } // -// this->cleanupBatch = this->removeNonexistentFromCleanup( this->cleanupBatch ); +// this.cleanupBatch = this.removeNonexistentFromCleanup( this.cleanupBatch ); // -// status = this->file->repo->cleanupDeletedBatch( this->cleanupBatch ); +// status = this.file.repo.cleanupDeletedBatch( this.cleanupBatch ); // // return status; // } @@ -2792,7 +2793,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // protected function cleanupFailedBatch( storeStatus, storeBatch ) { // cleanupBatch = []; // -// foreach ( storeStatus->success as i => success ) { +// foreach ( storeStatus.success as i => success ) { // // Check if this item of the batch was successfully copied // if ( success ) { // // Item was successfully copied and needs to be removed again @@ -2800,7 +2801,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // cleanupBatch[] = [ storeBatch[i][1], storeBatch[i][2] ]; // } // } -// this->file->repo->cleanupBatch( cleanupBatch ); +// this.file.repo.cleanupBatch( cleanupBatch ); // } // } // @@ -2833,22 +2834,22 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @param Title target // */ // function __construct( File file, Title target ) { -// this->file = file; -// this->target = target; -// this->oldHash = this->file->repo->getHashPath( this->file->getName() ); -// this->newHash = this->file->repo->getHashPath( this->target->getDBkey() ); -// this->oldName = this->file->getName(); -// this->newName = this->file->repo->getNameFromTitle( this->target ); -// this->oldRel = this->oldHash . this->oldName; -// this->newRel = this->newHash . this->newName; -// this->db = file->getRepo()->getMasterDB(); +// this.file = file; +// this.target = target; +// this.oldHash = this.file.repo.getHashPath( this.file.getName() ); +// this.newHash = this.file.repo.getHashPath( this.target.getDBkey() ); +// this.oldName = this.file.getName(); +// this.newName = this.file.repo.getNameFromTitle( this.target ); +// this.oldRel = this.oldHash . this.oldName; +// this.newRel = this.newHash . this.newName; +// this.db = file.getRepo().getMasterDB(); // } // // /** // * Add the current image to the batch // */ // public function addCurrent() { -// this->cur = [ this->oldRel, this->newRel ]; +// this.cur = [ this.oldRel, this.newRel ]; // } // // /** @@ -2857,20 +2858,20 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // */ // public function addOlds() { // archiveBase = 'archive'; -// this->olds = []; -// this->oldCount = 0; +// this.olds = []; +// this.oldCount = 0; // archiveNames = []; // -// result = this->db->select( 'oldimage', +// result = this.db.select( 'oldimage', // [ 'oi_archive_name', 'oi_deleted' ], -// [ 'oi_name' => this->oldName ], +// [ 'oi_name' => this.oldName ], // __METHOD__, // [ 'LOCK IN SHARE MODE' ] // ignore snapshot // ); // // foreach ( result as row ) { -// archiveNames[] = row->oi_archive_name; -// oldName = row->oi_archive_name; +// archiveNames[] = row.oi_archive_name; +// oldName = row.oi_archive_name; // bits = explode( '!', oldName, 2 ); // // if ( count( bits ) != 2 ) { @@ -2880,21 +2881,21 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // // list( timestamp, filename ) = bits; // -// if ( this->oldName != filename ) { +// if ( this.oldName != filename ) { // wfDebug( "Old file name doesn't match: 'oldName' \n" ); // continue; // } // -// this->oldCount++; +// this.oldCount++; // // // Do we want to add those to oldCount? -// if ( row->oi_deleted & File::DELETED_FILE ) { +// if ( row.oi_deleted & File::DELETED_FILE ) { // continue; // } // -// this->olds[] = [ -// "{archiveBase}/{this->oldHash}{oldName}", -// "{archiveBase}/{this->newHash}{timestamp}!{this->newName}" +// this.olds[] = [ +// "{archiveBase}/{this.oldHash}{oldName}", +// "{archiveBase}/{this.newHash}{timestamp}!{this.newName}" // ]; // } // @@ -2906,67 +2907,67 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // public function execute() { -// repo = this->file->repo; -// status = repo->newGood(); -// destFile = wfLocalFile( this->target ); +// repo = this.file.repo; +// status = repo.newGood(); +// destFile = wfLocalFile( this.target ); // -// this->file->synchronized(); // begin -// destFile->synchronized(); // quickly fail if destination is not available +// this.file.synchronized(); // begin +// destFile.synchronized(); // quickly fail if destination is not available // -// triplets = this->getMoveTriplets(); -// checkStatus = this->removeNonexistentFiles( triplets ); -// if ( !checkStatus->isGood() ) { -// destFile->unlock(); -// this->file->unlock(); -// status->merge( checkStatus ); // couldn't talk to file backend +// triplets = this.getMoveTriplets(); +// checkStatus = this.removeNonexistentFiles( triplets ); +// if ( !checkStatus.isGood() ) { +// destFile.unlock(); +// this.file.unlock(); +// status.merge( checkStatus ); // couldn't talk to file backend // return status; // } -// triplets = checkStatus->value; +// triplets = checkStatus.value; // // // Verify the file versions metadata in the DB. -// statusDb = this->verifyDBUpdates(); -// if ( !statusDb->isGood() ) { -// destFile->unlock(); -// this->file->unlock(); -// statusDb->setOK( false ); +// statusDb = this.verifyDBUpdates(); +// if ( !statusDb.isGood() ) { +// destFile.unlock(); +// this.file.unlock(); +// statusDb.setOK( false ); // // return statusDb; // } // -// if ( !repo->hasSha1Storage() ) { +// if ( !repo.hasSha1Storage() ) { // // Copy the files into their new location. // // If a prior process fataled copying or cleaning up files we tolerate any // // of the existing files if they are identical to the ones being stored. -// statusMove = repo->storeBatch( triplets, FileRepo::OVERWRITE_SAME ); -// wfDebugLog( 'imagemove', "Moved files for {this->file->getName()}: " . -// "{statusMove->successCount} successes, {statusMove->failCount} failures" ); -// if ( !statusMove->isGood() ) { +// statusMove = repo.storeBatch( triplets, FileRepo::OVERWRITE_SAME ); +// wfDebugLog( 'imagemove', "Moved files for {this.file.getName()}: " . +// "{statusMove.successCount} successes, {statusMove.failCount} failures" ); +// if ( !statusMove.isGood() ) { // // Delete any files copied over (while the destination is still locked) -// this->cleanupTarget( triplets ); -// destFile->unlock(); -// this->file->unlock(); +// this.cleanupTarget( triplets ); +// destFile.unlock(); +// this.file.unlock(); // wfDebugLog( 'imagemove', "Error in moving files: " -// . statusMove->getWikiText( false, false, 'en' ) ); -// statusMove->setOK( false ); +// . statusMove.getWikiText( false, false, 'en' ) ); +// statusMove.setOK( false ); // // return statusMove; // } -// status->merge( statusMove ); +// status.merge( statusMove ); // } // // // Rename the file versions metadata in the DB. -// this->doDBUpdates(); +// this.doDBUpdates(); // -// wfDebugLog( 'imagemove', "Renamed {this->file->getName()} in database: " . -// "{statusDb->successCount} successes, {statusDb->failCount} failures" ); +// wfDebugLog( 'imagemove', "Renamed {this.file.getName()} in database: " . +// "{statusDb.successCount} successes, {statusDb.failCount} failures" ); // -// destFile->unlock(); -// this->file->unlock(); // done +// destFile.unlock(); +// this.file.unlock(); // done // // // Everything went ok, remove the source files -// this->cleanupSource( triplets ); +// this.cleanupSource( triplets ); // -// status->merge( statusDb ); +// status.merge( statusDb ); // // return status; // } @@ -2978,37 +2979,37 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return Status // */ // protected function verifyDBUpdates() { -// repo = this->file->repo; -// status = repo->newGood(); -// dbw = this->db; +// repo = this.file.repo; +// status = repo.newGood(); +// dbw = this.db; // -// hasCurrent = dbw->selectField( +// hasCurrent = dbw.selectField( // 'image', // '1', -// [ 'img_name' => this->oldName ], +// [ 'img_name' => this.oldName ], // __METHOD__, // [ 'FOR UPDATE' ] // ); -// oldRowCount = dbw->selectField( +// oldRowCount = dbw.selectField( // 'oldimage', // 'COUNT(*)', -// [ 'oi_name' => this->oldName ], +// [ 'oi_name' => this.oldName ], // __METHOD__, // [ 'FOR UPDATE' ] // ); // // if ( hasCurrent ) { -// status->successCount++; +// status.successCount++; // } else { -// status->failCount++; +// status.failCount++; // } -// status->successCount += oldRowCount; +// status.successCount += oldRowCount; // // Bug 34934: oldCount is based on files that actually exist. // // There may be more DB rows than such files, in which case affected // // can be greater than total. We use max() to avoid negatives here. -// status->failCount += max( 0, this->oldCount - oldRowCount ); -// if ( status->failCount ) { -// status->error( 'imageinvalidfilename' ); +// status.failCount += max( 0, this.oldCount - oldRowCount ); +// if ( status.failCount ) { +// status.error( 'imageinvalidfilename' ); // } // // return status; @@ -3019,24 +3020,24 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * many rows where updated. // */ // protected function doDBUpdates() { -// dbw = this->db; +// dbw = this.db; // // // Update current image -// dbw->update( +// dbw.update( // 'image', -// [ 'img_name' => this->newName ], -// [ 'img_name' => this->oldName ], +// [ 'img_name' => this.newName ], +// [ 'img_name' => this.oldName ], // __METHOD__ // ); // // Update old images -// dbw->update( +// dbw.update( // 'oldimage', // [ -// 'oi_name' => this->newName, -// 'oi_archive_name = ' . dbw->strreplace( 'oi_archive_name', -// dbw->addQuotes( this->oldName ), dbw->addQuotes( this->newName ) ), +// 'oi_name' => this.newName, +// 'oi_archive_name = ' . dbw.strreplace( 'oi_archive_name', +// dbw.addQuotes( this.oldName ), dbw.addQuotes( this.newName ) ), // ], -// [ 'oi_name' => this->oldName ], +// [ 'oi_name' => this.oldName ], // __METHOD__ // ); // } @@ -3046,16 +3047,16 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // * @return array // */ // protected function getMoveTriplets() { -// moves = array_merge( [ this->cur ], this->olds ); +// moves = array_merge( [ this.cur ], this.olds ); // triplets = []; // The format is: (srcUrl, destZone, destUrl) // // foreach ( moves as move ) { // // move: (oldRelativePath, newRelativePath) -// srcUrl = this->file->repo->getVirtualUrl() . '/public/' . rawurlencode( move[0] ); +// srcUrl = this.file.repo.getVirtualUrl() . '/public/' . rawurlencode( move[0] ); // triplets[] = [ srcUrl, 'public', move[1] ]; // wfDebugLog( // 'imagemove', -// "Generated move triplet for {this->file->getName()}: {srcUrl} :: public :: {move[1]}" +// "Generated move triplet for {this.file.getName()}: {srcUrl} :: public :: {move[1]}" // ); // } // @@ -3074,10 +3075,10 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // files[file[0]] = file[0]; // } // -// result = this->file->repo->fileExistsBatch( files ); +// result = this.file.repo.fileExistsBatch( files ); // if ( in_array( null, result, true ) ) { // return Status::newFatal( 'backend-fail-@gplx.Internal protected', -// this->file->repo->getBackend()->getName() ); +// this.file.repo.getBackend().getName() ); // } // // filteredTriplets = []; @@ -3105,7 +3106,7 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // pairs[] = [ triplet[1], triplet[2] ]; // } // -// this->file->repo->cleanupBatch( pairs ); +// this.file.repo.cleanupBatch( pairs ); // } // // /** @@ -3120,6 +3121,6 @@ public class Xomw_LocalFile extends Xomw_File {// static final VERSION = 10; // // files[] = triplet[0]; // } // -// this->file->repo->cleanupBatch( files ); +// this.file.repo.cleanupBatch( files ); // } } diff --git a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_file_finder__mock.java b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_file_finder__mock.java index de52f2b46..2e4d7a151 100644 --- a/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_file_finder__mock.java +++ b/400_xowa/src/gplx/xowa/mws/filerepo/file/Xomw_file_finder__mock.java @@ -21,8 +21,8 @@ public class Xomw_file_finder__mock implements Xomw_file_finder { public Xomw_File Find_file(Xoa_ttl ttl) { return (Xomw_File)hash.Get_by(ttl.Page_db_as_str()); } - public void Add(String title, Xomw_FileRepo repo, int w, int h) { - Xomw_LocalFile file = new Xomw_LocalFile(Bry_.new_u8(title), repo, w, h); - hash.Add(title, file); + public void Add(String title, Xomw_FileRepo repo, int w, int h, byte[] mime) { + Xomw_LocalFile file = new Xomw_LocalFile(Bry_.new_u8(title), repo, w, h, mime); + hash.Add_if_dupe_use_nth(title, file); } } diff --git a/400_xowa/src/gplx/xowa/mws/media/Xomw_ImageHandler.java b/400_xowa/src/gplx/xowa/mws/media/Xomw_ImageHandler.java index a0a3d04a1..576875562 100644 --- a/400_xowa/src/gplx/xowa/mws/media/Xomw_ImageHandler.java +++ b/400_xowa/src/gplx/xowa/mws/media/Xomw_ImageHandler.java @@ -16,8 +16,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -import gplx.xowa.mws.filerepo.file.*; -public class Xomw_ImageHandler extends Xomw_MediaHandler { public Xomw_ImageHandler(byte[] key) {super(key);} +import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.parsers.lnkis.*; +// MEMORY:only one instance per wiki +public class Xomw_ImageHandler extends Xomw_MediaHandler { private final Xomw_param_map paramMap = new Xomw_param_map(); + public Xomw_ImageHandler(byte[] key) {super(key); + paramMap.Add(Xomw_param_itm.Mw__img_width, Xomw_param_map.Type__handler, Xomw_param_itm.Name_bry__width); + } /** * @param File file * @return boolean @@ -26,22 +30,24 @@ public class Xomw_ImageHandler extends Xomw_MediaHandler { public Xomw_ImageHand return (file.getWidth(1) != -1 && file.getHeight(1) != -1); } -// public function getParamMap() { -// return [ 'img_width' => 'width' ]; -// } -// -// public function validateParam(name, value) { -// if (in_array(name, [ 'width', 'height' ])) { -// if (value <= 0) { -// return false; -// } else { -// return true; -// } -// } else { -// return false; -// } -// } -// + @Override public Xomw_param_map getParamMap() { + return paramMap; + } + + @Override public boolean validateParam(int name_uid, byte[] val_bry, int val_int) { + if (name_uid == Xomw_param_itm.Name__width || name_uid == Xomw_param_itm.Name__height) { + if (val_int <= 0) { + return false; + } + else { + return true; + } + } + else { + return false; + } + } + // public function makeParamString(params) { // if (isset(params['physicalWidth'])) { // width = params['physicalWidth']; diff --git a/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandler.java b/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandler.java index 4fffb940b..317320774 100644 --- a/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandler.java +++ b/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandler.java @@ -17,7 +17,8 @@ along with this program. If not, see . */ package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.filerepo.file.*; -public class Xomw_MediaHandler { +import gplx.xowa.mws.parsers.lnkis.*; +public abstract class Xomw_MediaHandler { public byte[] Key() {return key;} private byte[] key; public Xomw_MediaHandler(byte[] key) { this.key = key; @@ -42,23 +43,23 @@ public class Xomw_MediaHandler { // return MediaWikiServices::getInstance() // ->getMediaHandlerFactory()->getHandler($type); // } -// -// /** -// * Get an associative array mapping magic word IDs to parameter names. -// * Will be used by the parser to identify parameters. -// */ -// abstract public function getParamMap(); -// -// /** -// * Validate a thumbnail parameter at parse time. -// * Return true to accept the parameter, and false to reject it. -// * If you return false, the parser will do something quiet and forgiving. -// * -// * @param String $name -// * @param mixed $value -// */ -// abstract public function validateParam($name, $value); -// + + /** + * Get an associative array mapping magic word IDs to parameter names. + * Will be used by the parser to identify parameters. + */ + public abstract Xomw_param_map getParamMap(); + + /** + * Validate a thumbnail parameter at parse time. + * Return true to accept the parameter, and false to reject it. + * If you return false, the parser will do something quiet and forgiving. + * + * @param String $name + * @param mixed $value + */ + public abstract boolean validateParam(int name_uid, byte[] val_bry, int val_int); + // /** // * Merge a parameter array into a String appropriate for inclusion in filenames // * diff --git a/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandlerFactory.java b/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandlerFactory.java index 2750cc967..bbb565978 100644 --- a/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandlerFactory.java +++ b/400_xowa/src/gplx/xowa/mws/media/Xomw_MediaHandlerFactory.java @@ -16,15 +16,16 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; +// XO.MW:MW has registry and instance cache; XO only has instance +// XO.MW:SYNC:1.29; DATE:2017-02-05 public class Xomw_MediaHandlerFactory { -// /** -// * Default, MediaWiki core media handlers -// * -// * @var array -// */ -// private static $coreHandlers = [ + private final Hash_adp_bry handlers = Hash_adp_bry.cs(); + + // XO.MW:SYNC:1.29; DATE:2017-02-05 + public Xomw_MediaHandlerFactory() { + // Default, MediaWiki core media handlers // 'image/jpeg' => JpegHandler::class, -// 'image/png' => PNGHandler::class, + handlers.Add(Mime__image__png, new Xomw_ImageHandler(Mime__image__png)); // PngHandler // 'image/gif' => GIFHandler::class, // 'image/tiff' => TiffHandler::class, // 'image/webp' => WebPHandler::class, @@ -36,55 +37,27 @@ public class Xomw_MediaHandlerFactory { // 'image/vnd.djvu' => DjVuHandler::class, // official // 'image/x.djvu' => DjVuHandler::class, // compat // 'image/x-djvu' => DjVuHandler::class, // compat -// ]; -// -// /** -// * @var array -// */ -// private $registry; -// -// /** -// * Instance cache of MediaHandler objects by mimetype -// * -// * @var MediaHandler[] -// */ -// private $handlers; -// -// public function __construct( array $registry ) { -// $this->registry = $registry + self::$coreHandlers; -// } -// -// protected function getHandlerClass( $type ) { -// if ( isset( $this->registry[$type] ) ) { -// return $this->registry[$type]; -// } else { -// return false; -// } -// } -// -// /** -// * @param String $type mimetype -// * @return boolean|MediaHandler -// */ -// public function getHandler( $type ) { -// if ( isset( $this->handlers[$type] ) ) { -// return $this->handlers[$type]; -// } -// -// $class = $this->getHandlerClass( $type ); -// if ( $class !== false ) { -// /** @var MediaHandler $handler */ -// $handler = new $class; -// if ( !$handler->isEnabled() ) { -// wfDebug( __METHOD__ . ": $class is not enabled\n" ); -// $handler = false; -// } -// } else { -// wfDebug( __METHOD__ . ": no handler found for $type.\n" ); -// $handler = false; -// } -// -// $this->handlers[$type] = $handler; -// return $handler; -// } + + } + + // XO.MW:SYNC:1.29; DATE:2017-02-05 + public Xomw_MediaHandler getHandler(byte[] type) { + return (Xomw_MediaHandler)handlers.Get_by(type); + } + + public static byte[] + Mime__image__jpeg = Bry_.new_a7("image/jpeg") + , Mime__image__png = Bry_.new_a7("image/png") + , Mime__image__gif = Bry_.new_a7("image/gif") + , Mime__image__tiff = Bry_.new_a7("image/tiff") + , Mime__image__webp = Bry_.new_a7("image/webp") + , Mime__image__x_ms_bmp = Bry_.new_a7("image/x-ms-bmp") + , Mime__image__x_bmp = Bry_.new_a7("image/x-bmp") + , Mime__image__x_xcf = Bry_.new_a7("image/x-xcf") + , Mime__image__svg_xml = Bry_.new_a7("image/svg+xml") + , Mime__image__svg = Bry_.new_a7("image/svg") + , Mime__image__vnd_djvu = Bry_.new_a7("image/vnd.djvu") + , Mime__image__x_djvu_dot = Bry_.new_a7("image/x.djvu") + , Mime__image__x_djvu_dash = Bry_.new_a7("image/x-djvu") + ; } diff --git a/400_xowa/src/gplx/xowa/mws/media/Xomw_mto.java b/400_xowa/src/gplx/xowa/mws/media/Xomw_mto.java index 369966b3d..c26a33866 100644 --- a/400_xowa/src/gplx/xowa/mws/media/Xomw_mto.java +++ b/400_xowa/src/gplx/xowa/mws/media/Xomw_mto.java @@ -22,8 +22,23 @@ public class Xomw_mto { private int width = -1, height = -1; public byte[] url; private final List_adp attribs = List_adp_.New(), link_attribs = List_adp_.New(); - public Xomw_mto(byte[] url) { + public Xomw_mto(byte[] url, int width, int height) { this.url = url; + this.width = width; + this.height = height; + } + /** + * @return int Width of the output box + */ + public int getWidth() { + return this.width; + } + + /** + * @return int Height of the output box + */ + public int getHeight() { + return this.height; } // Return HTML tag for the thumbnail, will include @@ -87,7 +102,7 @@ public class Xomw_mto { // link_attribs.Add_many(Gfh_atr_.Bry__title, Php_utl_.Empty(options_title) ? title.Get_full_text() : options_title); } else if (!Php_utl_.Empty(options.desc_link)) { -// link_attribs = $this->getDescLinkAttribs( +// link_attribs = this.getDescLinkAttribs( // empty(options['title']) ? null : options['title'], // $query // ); @@ -122,7 +137,7 @@ public class Xomw_mto { // Additional densities for responsive images, if specified. // If any of these urls is the same as src url, it'll be excluded. -// $responsiveUrls = array_diff($this->responsiveUrls, [ $this->url ]); +// $responsiveUrls = array_diff(this.responsiveUrls, [ this.url ]); // if (!Php_utl_.Empty($responsiveUrls)) { // $attribs['srcset'] = Html::srcSet($responsiveUrls); // } diff --git a/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_ctx.java b/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_ctx.java index 3afa3dbd2..b77a6ca92 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_ctx.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_ctx.java @@ -16,8 +16,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.mws.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; +import gplx.xowa.mws.parsers.lnkis.*; public class Xomw_parser_ctx { public Xoa_ttl Page_title() {return page_title;} private Xoa_ttl page_title; + public Xomw_image_params Lnki_wkr__make_image__img_params = new Xomw_image_params(); + public byte[][] Lnki_wkr__make_image__match_magic_word = new byte[2][]; + public int[] Lnki_wkr__make_image__img_size = new int[2]; public void Init_by_page(Xoa_ttl page_title) { this.page_title = page_title; diff --git a/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_env.java b/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_env.java index 3357b1e96..498a3fd74 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_env.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/Xomw_parser_env.java @@ -16,11 +16,13 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.mws.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -import gplx.xowa.mws.filerepo.file.*; +import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.media.*; public class Xomw_parser_env { + public byte[] Lang__align_end = Bry_.new_a7("right"); public Xomw_MagicWordMgr Magic_word_mgr() {return magic_word_mgr;} private final Xomw_MagicWordMgr magic_word_mgr = new Xomw_MagicWordMgr(); public Xomw_message_mgr Message_mgr() {return message_mgr;} private final Xomw_message_mgr message_mgr = new Xomw_message_mgr(); public Xomw_file_finder File_finder() {return file_finder;} private Xomw_file_finder file_finder = new Xomw_file_finder__noop(); + public Xomw_MediaHandlerFactory MediaHandlerFactory() {return mediaHandlerFactory;} private final Xomw_MediaHandlerFactory mediaHandlerFactory = new Xomw_MediaHandlerFactory(); public Xomw_parser_env File_finder_(Xomw_file_finder v) {file_finder = v; return this;} } diff --git a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_itm.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_image_params.java similarity index 55% rename from 400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_itm.java rename to 400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_image_params.java index 01265ffb8..0a1068624 100644 --- a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_itm.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_image_params.java @@ -15,24 +15,8 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package gplx.xowa.mws.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -public class Xomw_prm_itm { - public int type = 0; - public int name_type = 1; - public byte[] name = null; - public byte[] val = null; - - public static final int - Type__handler = 0 - ; - public static final int - Name__width = 0 - , Name__manual_thumb = 0 - , Name__alt = 1 - , Name__class = 2 - , Name__link = 3 - , Name__frameless = 4 - , Name__framed = 5 - , Name__thumbnail = 6 - ; +package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; +public class Xomw_image_params { + public Xomw_param_map paramMap = null; + public Xomw_MagicWordArray mwArray = null; } diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr.java index 834f8bc0a..7bdd4e1ce 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr.java @@ -377,7 +377,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them bfr.Add(prefix); // Armor_links(Make_image(bfr, nt, text, holders)) - Make_image(pctx, bfr, nt, text, holders); + this.makeImage(pctx, bfr, nt, text, holders); bfr.Add(trail); continue; } @@ -443,7 +443,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls } } } - public void Make_image(Xomw_parser_ctx pctx, Bry_bfr bfr, Xoa_ttl title, byte[] link_args, Xomw_link_holders holders) { + public void makeImage(Xomw_parser_ctx pctx, Bry_bfr bfr, Xoa_ttl title, byte[] options_at_link, Xomw_link_holders holders) { // Check if the options text is of the form "options|alt text" // Options are: // * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang @@ -471,78 +471,78 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // * text-bottom // Protect LanguageConverter markup when splitting into parts - byte[][] parts = Xomw_string_utils.Delimiter_explode(tmp_list, trv, link_args); + byte[][] parts = Xomw_string_utils.Delimiter_explode(tmp_list, trv, options_at_link); // Give extensions a chance to select the file revision for us // $options = []; byte[] desc_query = null; - // MW.HOOK:BeforeParserFetchFileAndTitle + // XO.MW.HOOK:BeforeParserFetchFileAndTitle // Fetch and register the file (file title may be different via hooks) - Xomw_File file = fetchFileAndTitle(title, null); // list($file, $title) = $this->fetchFileAndTitle($title, $options); + Xomw_File file = fetchFileAndTitle(title, null); // Get parameter map - Xomw_MediaHandler handler2 = file == null ? null : file.getHandler(); + Xomw_MediaHandler handler = file == null ? null : file.getHandler(env); - Xomw_image_params tmp_img_params = new Xomw_image_params(); - this.getImageParams(tmp_img_params, handler2); + Xomw_image_params tmp_img_params = pctx.Lnki_wkr__make_image__img_params; + this.getImageParams(tmp_img_params, handler); Xomw_param_map paramMap = tmp_img_params.paramMap; Xomw_MagicWordArray mwArray = tmp_img_params.mwArray; - // XO.MW.UNSUPPORTED.TrackingCategory: - //if (!$file) { - // $this->addTrackingCategory('broken-file-category'); - //} + // XO.MW.UNSUPPORTED.TrackingCategory: if (!$file) $this->addTrackingCategory('broken-file-category'); // Process the input parameters byte[] caption = Bry_.Empty; // XO.MW: $params = [ 'frame' => [], 'handler' => [], 'horizAlign' => [], 'vertAlign' => [] ]; -// Xomw_prm_mgr param_map = new Xomw_prm_mgr(); -// Xomw_prm_mgr param_mgr = new Xomw_prm_mgr(); - Xomw_img_prms frame = new Xomw_img_prms(); - Xomw_mda_prms handler = new Xomw_mda_prms(); + Xomw_params_frame frameParams = paramMap.Frame.Clear(); + Xomw_params_handler handlerParams = paramMap.Handler.Clear(); +// Xomw_params_horizAlign horizAlignParams = paramMap.HorizAlign.Clear(); +// Xomw_params_vertAlign vertAlignParams = paramMap.VertAlign.Clear(); boolean seen_format = false; int parts_len = parts.length; for (int i = 0; i < parts_len; i++) { - byte[] part = parts[i]; part = Bry_.Trim(part); - byte[] magic_name = mwArray.matchVariableStartToEnd(part); + byte[][] tmp_match_word = pctx.Lnki_wkr__make_image__match_magic_word; + mwArray.matchVariableStartToEnd(tmp_match_word, part); + byte[] magic_name = tmp_match_word[0]; + byte[] val = tmp_match_word[1]; boolean validated = false; - Xomw_param_itm prm_itm = paramMap.Get_by(magic_name); - if (prm_itm != null) { - int prm_type = -1; - int paramNameType = prm_itm.name_type; + Xomw_param_itm param_item = paramMap.Get_by(magic_name); + if (param_item != null) { + int typeUid = param_item.type_uid; + int paramNameUid = param_item.name_uid; // Special case; width and height come in one variable together - if (prm_type == Xomw_prm_itm.Type__handler && paramNameType == Xomw_prm_itm.Name__width) { -// $parsedWidthParam = $this->parseWidthParam($value); -// if (isset($parsedWidthParam['width'])) { -// $width = $parsedWidthParam['width']; -// if ($handler->validateParam('width', $width)) { -// $params[$type]['width'] = $width; -// validated = true; -// } -// } -// if (isset($parsedWidthParam['height'])) { -// $height = $parsedWidthParam['height']; -// if ($handler->validateParam('height', $height)) { -// $params[$type]['height'] = $height; -// validated = true; -// } -// } + if (typeUid == Xomw_param_map.Type__handler && paramNameUid == Xomw_param_itm.Name__width) { + int[] tmp_img_size = pctx.Lnki_wkr__make_image__img_size; + this.parseWidthParam(tmp_img_size, val); + int parsedW = tmp_img_size[0]; + int parsedH = tmp_img_size[1]; + if (parsedW != 0) { + if (handler.validateParam(Xomw_param_itm.Name__width, null, parsedW)) { + paramMap.Set(typeUid, Xomw_param_itm.Name__width, null, parsedW); + validated = true; + } + } + if (parsedH != 0) { + if (handler.validateParam(Xomw_param_itm.Name__height, null, parsedH)) { + paramMap.Set(typeUid, Xomw_param_itm.Name__height, null, parsedH); + validated = true; + } + } // else no validation -- T15436 } else { - if (prm_type == Xomw_prm_itm.Type__handler) { + if (typeUid == Xomw_param_map.Type__handler) { // Validate handler parameter // validated = $handler->validateParam($paramName, $value); } else { // Validate @gplx.Internal protected parameters - switch (paramNameType) { + switch (paramNameUid) { case Xomw_param_itm.Name__manual_thumb: case Xomw_param_itm.Name__alt: case Xomw_param_itm.Name__class: @@ -586,17 +586,16 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // use first appearing option, discard others. validated = !seen_format; seen_format = true; - frame.thumbnail = Bry_.Empty; break; default: // Most other things appear to be empty or numeric... - // validated = ($value === false || is_numeric(trim($value))); + validated = (val == null || Php_utl_.isnumeric(Bry_.Trim(val))); break; } } - } - if (validated) { - // $params[$type][$paramName] = $value; + if (validated) { + paramMap.Set(typeUid, paramNameUid, val, -1); + } } } if (!validated) { @@ -605,22 +604,22 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls } // Process alignment parameters - Xomw_param_itm tmp = paramMap.Get_by(Xomw_prm_mgr.Name__horiz_align); + Xomw_param_itm tmp = paramMap.Get_by(Xomw_param_map.Type__horizAlign); if (tmp != null) { -// frame.align = tmp.val; +// frameParams.align = tmp.val; } - tmp = paramMap.Get_by(Xomw_prm_mgr.Name__vert_align); + tmp = paramMap.Get_by(Xomw_param_map.Type__vertAlign); if (tmp != null) { -// frame.valign = tmp.val; +// frameParams.valign = tmp.val; } - frame.caption = caption; + frameParams.caption = caption; boolean image_is_framed - = frame.frame != null - || frame.framed != null - || frame.thumbnail != null - || frame.manual_thumb != null + = frameParams.frame != null + || frameParams.framed != null + || frameParams.thumbnail != null + || frameParams.manual_thumb != null ; // Will the image be presented in a frame, with the caption below? @@ -639,28 +638,28 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // plicit caption= parameter and preserving the old magic unnamed para- // meter for BC; ... if (image_is_framed) { // Framed image - if (caption == Bry_.Empty && frame.alt == null) { + if (caption == Bry_.Empty && frameParams.alt == null) { // No caption or alt text, add the filename as the alt text so // that screen readers at least get some description of the image - frame.alt = title.Get_text(); + frameParams.alt = title.Get_text(); } // Do not set $params['frame']['title'] because tooltips don't make sense // for framed images } else { // Inline image - if (frame.alt == null) { + if (frameParams.alt == null) { // No alt text, use the "caption" for the alt text if (caption != Bry_.Empty) { -// frame.alt = $this->stripAltText(caption, $holders); +// frameParams.alt = $this->stripAltText(caption, $holders); } else { // No caption, fall back to using the filename for the // alt text - frame.alt = title.Get_text(); + frameParams.alt = title.Get_text(); } } // Use the "caption" for the tooltip text -// frame.title = $this->stripAltText(caption, $holders); +// frameParams.title = $this->stripAltText(caption, $holders); } // MW.HOOK:ParserMakeImageParams @@ -669,7 +668,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // byte[] time = options.time; Object time = null; // options = $this->mOptions->getThumbSize() - linker.Make_image_link(bfr, parser, title, file, frame, handler, time, desc_query, null); + linker.makeImageLink(bfr, parser, title, file, frameParams, handlerParams, time, desc_query, null); // Give the handler a chance to modify the parser Object // if (handler != null) { @@ -697,25 +696,26 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls private static Xomw_param_list[] internalParamNames; private static Xomw_param_map internalParamMap; + private void getImageParams(Xomw_image_params rv, Xomw_MediaHandler handler) { byte[] handlerClass = handler == null ? Bry_.Empty : handler.Key(); rv.paramMap = (Xomw_param_map)mImageParams.Get_by(handlerClass); + // NOTE: lazy-init; code below can be inefficent if (rv.paramMap == null) { // Initialise static lists if (internalParamNames == null) { internalParamNames = new Xomw_param_list[] - { Xomw_param_list.New("horizAlign", "left", "right", "center", "none") - , Xomw_param_list.New("vertAlign", "baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom") - , Xomw_param_list.New("frame", "thumbnail", "manual_thumb", "framed", "frameless", "upright", "border", "link", "alt", "class") + { Xomw_param_list.New(Xomw_param_map.Type__horizAlign, "horizAlign", "left", "right", "center", "none") + , Xomw_param_list.New(Xomw_param_map.Type__vertAlign , "vertAlign", "baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom") + , Xomw_param_list.New(Xomw_param_map.Type__frame , "frame", "thumbnail", "manual_thumb", "framed", "frameless", "upright", "border", "link", "alt", "class") }; internalParamMap = new Xomw_param_map(); byte[] bry_img = Bry_.new_a7("img_"); for (Xomw_param_list param_list : internalParamNames) { - byte[] type = param_list.type; for (byte[] name : param_list.names) { byte[] magic_name = Bry_.Add(bry_img, Bry_.Replace(name, Byte_ascii.Dash, Byte_ascii.Underline)); - internalParamMap.Add(magic_name, type, name); + internalParamMap.Add(magic_name, param_list.type_uid, name); } } } @@ -723,10 +723,12 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // Add handler params Xomw_param_map paramMap = internalParamMap.Clone(); if (handler != null) { -// $handlerParamMap = $handler->getParamMap(); -// foreach ($handlerParamMap as $magic => $paramName) { -// $paramMap[$magic] = [ 'handler', $paramName ]; -// } + Xomw_param_map handlerParamMap = handler.getParamMap(); + int handlerParamMapLen = handlerParamMap.Len(); + for (int i = 0; i < handlerParamMapLen; i++) { + Xomw_param_itm itm = (Xomw_param_itm)handlerParamMap.Get_at(i); + paramMap.Add(itm.magic, itm.type_uid, itm.name); + } } this.mImageParams.Add(handlerClass, paramMap); rv.paramMap = paramMap; @@ -738,6 +740,35 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls rv.mwArray = (Xomw_MagicWordArray)mImageParamsMagicArray.Get_by(handlerClass); } } + // Parsed a width param of imagelink like 300px or 200x300px + // XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0 + public void parseWidthParam(int[] img_size, byte[] src) { + img_size[0] = img_size[1] = -1; + if (src == Bry_.Empty) { + return; + } + // (T15500) In both cases (width/height and width only), + // permit trailing "px" for backward compatibility. + int src_bgn = 0; + int src_end = src.length; + // XO: "px" is optional; if exists at end, ignore it + if (Bry_.Has_at_end(src, Bry__px)) { + src_end -= 2; + } + + // XO.MW: if ( preg_match( '/^([0-9]*)x([0-9]*)\s*(?:px)?\s*$/', $value, $m ) ) { + int w_bgn = 0; + int w_end = Bry_find_.Find_fwd_while_num(src, src_bgn, src_end); + int h_bgn = -1; + int h_end = -1; + if (w_end < src_end && src[w_end] == Byte_ascii.Ltr_x) { + h_bgn = w_end + 1; + h_end = Bry_find_.Find_fwd_while_num(src, h_bgn, src_end); + } + img_size[0] = Bry_.To_int_or(src, w_bgn, w_end, 0); + img_size[1] = Bry_.To_int_or(src, h_bgn, h_end, 0); + } + private static final byte[] Bry__px = Bry_.new_a7("px"); /** * Fetch a file and its title and register a reference to it. @@ -826,7 +857,3 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls // pipe -> \\| // other chars... -> (.*) } -class Xomw_image_params { - public Xomw_param_map paramMap = null; - public Xomw_MagicWordArray mwArray = null; -} diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__file__tst.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__file__tst.java index 6abdcbd51..ecb3e4def 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__file__tst.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__file__tst.java @@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; -import org.junit.*; +import org.junit.*; import gplx.core.tests.*; import gplx.xowa.mws.filerepo.*; import gplx.xowa.mws.filerepo.file.*; public class Xomw_lnki_wkr__file__tst { private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt(); @Before public void init() { @@ -27,6 +27,72 @@ public class Xomw_lnki_wkr__file__tst { fxt.Test__to_html("[[File:A.png]]", "A.png"); } @Test public void Thumb() { - fxt.Test__to_html("[[File:A.png|thumb]]", "
A.png"); + fxt.Test__to_html("[[File:A.png|thumb]]", "
A.png
"); + } + @Test public void Size() { + fxt.Test__to_html("[[File:A.png|123x456px]]", "A.png"); + } + @Test public void Test__parseWidthParam() { + int[] img_size = new int[2]; + // WxHpx + fxt.Test__parseWidthParam(img_size, "12x34px" , 12, 34); + // WxH + fxt.Test__parseWidthParam(img_size, "12x34" , 12, 34); + // Wpx + fxt.Test__parseWidthParam(img_size, "12px" , 12, 0); + // W + fxt.Test__parseWidthParam(img_size, "12" , 12, 0); + // 12x + fxt.Test__parseWidthParam(img_size, "12x" , 12, 0); + // x34 + fxt.Test__parseWidthParam(img_size, "x34" , 0, 34); + } +} +class Xomw_lnki_wkr__fxt { + private final Xomw_lnki_wkr wkr; + private final Xomw_parser_ctx pctx; + private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr(); + private final Xomw_file_finder__mock file_finder = new Xomw_file_finder__mock(); + private final Xomw_FileRepo repo = new Xomw_FileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb")); + private boolean apos = true; + public Xomw_lnki_wkr__fxt() { + Xoae_app app = Xoa_app_fxt.Make__app__edit(); + Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); + Xomw_parser parser = new Xomw_parser(); + wkr = parser.Lnki_wkr(); + + // env + parser.Env().File_finder_(file_finder); + parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_thumbnail"), Bool_.Y, Bry_.Ary("thumb")); + parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_width"), Bool_.Y, Bry_.Ary("$1px")); + parser.Init_by_wiki(wiki); + + // ctx + pctx = new Xomw_parser_ctx(); + pctx.Init_by_page(wiki.Ttl_parse(Bry_.new_a7("Page_1"))); + } + public void Clear() { + wkr.Clear_state(); + } + public void Init__file(String title, int w, int h) { + file_finder.Add(title, repo, w, h, gplx.xowa.files.Xof_ext_.Mime_type__ary[gplx.xowa.files.Xof_ext_.Id_png]); + } + public void Test__parse(String src_str, String expd) { + byte[] src_bry = Bry_.new_u8(src_str); + wkr.Replace_internal_links(pctx, pbfr.Init(src_bry)); + if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); + Gftest.Eq__ary__lines(expd, pbfr.Rslt().To_str_and_clear(), src_str); + } + public void Test__to_html(String src_str, String expd) { + byte[] src_bry = Bry_.new_u8(src_str); + wkr.Replace_internal_links(pctx, pbfr.Init(src_bry)); + wkr.Replace_link_holders(pctx, pbfr); + if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); + Gftest.Eq__ary__lines(expd, pbfr.Rslt().To_str_and_clear(), src_str); + } + public void Test__parseWidthParam(int[] img_size, String src_str, int expd_w, int expd_h) { + wkr.parseWidthParam(img_size, Bry_.new_u8(src_str)); + Gftest.Eq__int(expd_w, img_size[0], "w"); + Gftest.Eq__int(expd_h, img_size[1], "h"); } } diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__text__tst.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__text__tst.java index 4a57dbbcc..426a54261 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__text__tst.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_lnki_wkr__text__tst.java @@ -27,45 +27,3 @@ public class Xomw_lnki_wkr__text__tst { @Test public void Html__text() {fxt.Test__to_html("[[A]]" , "A");} @Test public void Html__capt() {fxt.Test__to_html("[[A|a]]" , "a");} } -class Xomw_lnki_wkr__fxt { - private final Xomw_lnki_wkr wkr; - private final Xomw_parser_ctx pctx; - private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr(); - private final Xomw_file_finder__mock file_finder = new Xomw_file_finder__mock(); - private final Xomw_FileRepo repo = new Xomw_FileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb")); - private boolean apos = true; - public Xomw_lnki_wkr__fxt() { - Xoae_app app = Xoa_app_fxt.Make__app__edit(); - Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); - Xomw_parser parser = new Xomw_parser(); - wkr = parser.Lnki_wkr(); - - // env - parser.Env().File_finder_(file_finder); - parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_thumbnail"), Bool_.Y, Bry_.Ary("thumb")); - parser.Init_by_wiki(wiki); - - // ctx - pctx = new Xomw_parser_ctx(); - pctx.Init_by_page(wiki.Ttl_parse(Bry_.new_a7("Page_1"))); - } - public void Clear() { - wkr.Clear_state(); - } - public void Init__file(String title, int w, int h) { - file_finder.Add(title, repo, w, h); - } - public void Test__parse(String src_str, String expd) { - byte[] src_bry = Bry_.new_u8(src_str); - wkr.Replace_internal_links(pctx, pbfr.Init(src_bry)); - if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); - Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str); - } - public void Test__to_html(String src_str, String expd) { - byte[] src_bry = Bry_.new_u8(src_str); - wkr.Replace_internal_links(pctx, pbfr.Init(src_bry)); - wkr.Replace_link_holders(pctx, pbfr); - if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); - Tfds.Eq_str_lines(expd, pbfr.Rslt().To_str_and_clear(), src_str); - } -} diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_itm.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_itm.java index 21c4a2462..7e9fb8e1d 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_itm.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_itm.java @@ -18,25 +18,40 @@ along with this program. If not, see . package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; public class Xomw_param_itm { public final byte[] magic; - public final byte[] type; + public final int type_uid; public final byte[] name; - public final int name_type; - public Xomw_param_itm(byte[] magic, byte[] type, byte[] name) { + public final int name_uid; + public Xomw_param_itm(byte[] magic, int type_uid, byte[] name) { this.magic = magic; - this.type = type; + this.type_uid = type_uid; this.name = name; - this.name_type = name_types.Get_as_int_or(name, -1); + this.name_uid = name_uids.Get_as_int_or(name, -1); } public static final int Name__width = 0 - , Name__manual_thumb = 1 - , Name__alt = 2 - , Name__class = 3 - , Name__link = 4 - , Name__frameless = 5 - , Name__framed = 6 - , Name__thumbnail = 7 + , Name__height = 1 + , Name__manual_thumb = 2 + , Name__alt = 3 + , Name__class = 4 + , Name__link = 5 + , Name__frameless = 6 + , Name__framed = 7 + , Name__thumbnail = 8 + ; + private static final Hash_adp_bry name_uids = Hash_adp_bry.cs() + .Add_str_int("width" , Name__width) + .Add_str_int("manual_thumb" , Name__manual_thumb) + .Add_str_int("alt" , Name__alt) + .Add_str_int("class" , Name__class) + .Add_str_int("link" , Name__link) + .Add_str_int("frameless" , Name__frameless) + .Add_str_int("framed" , Name__framed) + .Add_str_int("thumbnail" , Name__thumbnail) + ; + public static final byte[] + Mw__img_width = Bry_.new_a7("img_width") + ; + public static final byte[] + Name_bry__width = Bry_.new_a7("width") ; - private static final Hash_adp_bry name_types = Hash_adp_bry.cs() - .Add_str_int("thumbnail", Name__thumbnail); } diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_map.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_map.java index 8125db02c..efc8c95f4 100644 --- a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_map.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_param_map.java @@ -18,12 +18,24 @@ along with this program. If not, see . package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; public class Xomw_param_map { private final Ordered_hash hash = Ordered_hash_.New_bry(); + public final Xomw_params_frame Frame = new Xomw_params_frame(); + public final Xomw_params_handler Handler = new Xomw_params_handler(); + public final Xomw_params_horizAlign HorizAlign = new Xomw_params_horizAlign(); + public final Xomw_params_vertAlign VertAlign = new Xomw_params_vertAlign(); + public int Len() {return hash.Len();} + public Xomw_param_itm Get_at(int i) {return (Xomw_param_itm)hash.Get_at(i);} public Xomw_param_itm Get_by(byte[] name) { return (Xomw_param_itm)hash.Get_by(name); } public Xomw_param_itm Get_by(int name_type) { return null; } + public void Set(int type, int paramNameUid, byte[] paramBry, int paramInt) { + switch (type) { + case Type__frame: Frame.Set(paramNameUid, paramBry, paramInt); break; + case Type__handler: Handler.Set(paramNameUid, paramBry, paramInt); break; + } + } public byte[][] Keys() { int len = hash.Len(); byte[][] rv = new byte[len][]; @@ -32,8 +44,8 @@ public class Xomw_param_map { } return rv; } - public void Add(byte[] magic, byte[] type, byte[] name) { - Xomw_param_itm itm = new Xomw_param_itm(magic, type, name); + public void Add(byte[] magic, int type_uid, byte[] name) { + Xomw_param_itm itm = new Xomw_param_itm(magic, type_uid, name); hash.Add(magic, itm); } public Xomw_param_map Clone() { @@ -41,17 +53,23 @@ public class Xomw_param_map { int len = hash.Len(); for (int i = 0; i < len; i++) { Xomw_param_itm itm = (Xomw_param_itm)hash.Get_at(i); - rv.Add(itm.magic, itm.type, itm.name); + rv.Add(itm.magic, itm.type_uid, itm.name); } + rv.Frame.Copy_to(this.Frame); + rv.Handler.Copy_to(this.Handler); return rv; } + + public static final int Type__horizAlign = 0, Type__vertAlign = 1, Type__frame = 2, Type__handler = 3; } class Xomw_param_list { + public int type_uid; public byte[] type; public byte[][] names; - public static Xomw_param_list New(String type, String... names) { + public static Xomw_param_list New(int type_uid, String type, String... names) { Xomw_param_list rv = new Xomw_param_list(); + rv.type_uid = type_uid; rv.type = Bry_.new_u8(type); rv.names = Bry_.Ary(names); return rv; diff --git a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_img_prms.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_frame.java similarity index 61% rename from 400_xowa/src/gplx/xowa/mws/htmls/Xomw_img_prms.java rename to 400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_frame.java index 79f48e4d6..78909e8de 100644 --- a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_img_prms.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_frame.java @@ -15,8 +15,8 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package gplx.xowa.mws.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -public class Xomw_img_prms { +package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; +public class Xomw_params_frame { public byte[] align = null; public byte[] valign = null; public byte[] caption = null; @@ -35,11 +35,37 @@ public class Xomw_img_prms { public byte[] no_link = null; public byte[] border = null; public double upright = -1; - public void Clear() { + public void Set(int uid, byte[] val_bry, int val_int) { + switch (uid) { + case Xomw_param_itm.Name__thumbnail: thumbnail = val_bry; break; + } + } + public Xomw_params_frame Clear() { align = valign = caption = frame = framed = frameless = thumbnail = manual_thumb = alt = title = cls = img_cls = link_title = link_url = link_target = no_link = null; upright = -1; + return this; + } + public void Copy_to(Xomw_params_frame src) { + this.align = src.align; + this.valign = src.valign; + this.caption = src.caption; + this.frame = src.frame; + this.framed = src.framed; + this.frameless = src.frameless; + this.thumbnail = src.thumbnail; + this.manual_thumb = src.manual_thumb; + this.alt = src.alt; + this.title = src.title; + this.cls = src.cls; + this.img_cls = src.img_cls; + this.link_title = src.link_title; + this.link_url = src.link_url; + this.link_target = src.link_target; + this.no_link = src.no_link; + this.border = src.border; + this.upright = src.upright; } public static byte[] Cls_add(byte[] lhs, byte[] rhs) { return Bry_.Len_eq_0(lhs) ? rhs : Bry_.Add(lhs, Byte_ascii.Space_bry, rhs); diff --git a/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_handler.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_handler.java new file mode 100644 index 000000000..f91d868f9 --- /dev/null +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_handler.java @@ -0,0 +1,39 @@ +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012 gnosygnu@gmail.com + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; +public class Xomw_params_handler { + public int width = -1; + public int height = -1; + public int page = -1; + public Xomw_params_handler Clear() { + width = height = page = -1; + return this; + } + public void Copy_to(Xomw_params_handler src) { + this.width = src.width; + this.height = src.height; + this.page = src.page; + } + public void Set(int uid, byte[] val_bry, int val_int) { + switch (uid) { + case Xomw_param_itm.Name__width: width = val_int; break; + case Xomw_param_itm.Name__height: height = val_int; break; + default: throw Err_.new_unhandled_default(uid); + } + } +} diff --git a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_mda_prms.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_horizAlign.java similarity index 75% rename from 400_xowa/src/gplx/xowa/mws/htmls/Xomw_mda_prms.java rename to 400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_horizAlign.java index 40c67030a..82f8174ca 100644 --- a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_mda_prms.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_horizAlign.java @@ -15,9 +15,9 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package gplx.xowa.mws.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -public class Xomw_mda_prms { - public int width = -1; - public int height = -1; - public int page = -1; +package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; +public class Xomw_params_horizAlign { + public Xomw_params_horizAlign Clear() { + return this; + } } diff --git a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_mgr.java b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_vertAlign.java similarity index 66% rename from 400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_mgr.java rename to 400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_vertAlign.java index 9630ae74a..d2ccc6735 100644 --- a/400_xowa/src/gplx/xowa/mws/htmls/Xomw_prm_mgr.java +++ b/400_xowa/src/gplx/xowa/mws/parsers/lnkis/Xomw_params_vertAlign.java @@ -15,16 +15,9 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -package gplx.xowa.mws.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; -public class Xomw_prm_mgr { - public Xomw_prm_itm Get_or_null(int name_type) { - return null; +package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; +public class Xomw_params_vertAlign { + public Xomw_params_vertAlign Clear() { + return this; } - public Xomw_prm_itm Get_or_null(byte[] key) { - return null; - } - public static final int - Name__horiz_align = 0 - , Name__vert_align = 1 - ; }