id int64 0 1.29M | original_id stringlengths 32 32 | swhid stringlengths 100 170 | sha1 stringlengths 40 40 | repo_name stringlengths 2 45 | repo_group stringclasses 12
values | filepath stringlengths 5 153 | name stringlengths 1 14.9k | type stringclasses 3
values | code stringlengths 7 2.12M |
|---|---|---|---|---|---|---|---|---|---|
3,200 | 1445acf11ae446a3efc1f2b83cdb975c | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=1-18/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage | type | # Class for the MediaWiki login page
class MediaWikiLoginPage:
def __init__(self, mw_page):
self.mw_page = mw_page
def mediawiki_login_button(self):
return self.mw_page.get_by_role("link", name="Log in")
def mediawiki_username_input(self, username):
return self.mw_page.get_by_rol... |
3,201 | 9ade43fc9db16e318eadff8cde2dc2fc | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=5-6/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage::__init__(self, mw_page) | function | def __init__(self, mw_page):
self.mw_page = mw_page |
3,202 | 1db45da72aa4d141da164e0980947b6c | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=11-12/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage::mediawiki_username_input(self, username) | function | def mediawiki_username_input(self, username):
return self.mw_page.get_by_role("textbox", name="Username").fill(username) |
3,203 | 1b0bcbddb702403b03619f140dc752cd | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=17-18/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage::mediawiki_login(self) | function | def mediawiki_login(self):
return self.mw_page.get_by_role("button", name="Log in") |
3,204 | b21265cb518b0faaf75cc654a1103346 | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=14-15/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage::mediawiki_password_input(self, password) | function | def mediawiki_password_input(self, password):
return self.mw_page.get_by_role("textbox", name="Password").fill(password) |
3,205 | aeceb08b13a8ee289b090d4751091d40 | swh:1:cnt:b4b7b0d67b2ce49efa9736e46d1f0bac1dcdce8b;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=8-9/ | f79095728dd259ebaf171866d9596545e74a8a09 | xlabe2etests | analytics | pageobjects/media_wiki_login_page.py | MediaWikiLoginPage::mediawiki_login_button(self) | function | def mediawiki_login_button(self):
return self.mw_page.get_by_role("link", name="Log in") |
3,206 | f5343e87eb911b291a2b599ebecc4d01 | swh:1:cnt:44dc0e2ac8e41dba5f43b1848b35a63ec4fe6177;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=21-81/ | ec1f311f2f9a723e07e641965e9448684bcd5685 | xlabe2etests | analytics | tests/test_create_and_delete_exp_loggedin_user_mwloggedin.py | test_create_and_delete_exp_logged_in_users_activated(playwright, setup) | function | def test_create_and_delete_exp_logged_in_users_activated(playwright, setup):
# Class objects
homepage = HomePage(setup)
createexp = CreateNewExperiment(setup)
expName, machineReadableName = create_new_experiment(createexp, homepage, testdata['data'])
# confirm the new created exp
if homepage.l... |
3,207 | bc6675934db52ac1f02c53cbbf8f9ad7 | swh:1:cnt:0badd2e00bcdfc202abc8f8f10b4b14b971bca5a;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=19-90/ | 8138ea2b654499dc5131ea53f1f3c62890a86b4e | xlabe2etests | analytics | tests/test_create_and_delete_exp_loggedin_user_mwloggedin_activated.py | test_create_and_delete_exp_logged_in_users_activated(playwright, setup) | function | def test_create_and_delete_exp_logged_in_users_activated(playwright, setup):
# Class objects
homepage = HomePage(setup)
createexp = CreateNewExperiment(setup)
expName, machineReadableName = create_new_experiment(createexp, homepage, testdata['data'])
# confirm the new created exp
if homepage.... |
3,208 | 2c1e4fdf3e829ccd56001b045e316483 | swh:1:cnt:012bd0e430808d37778a977c4eb0ae269025d216;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=18-72/ | 33aab4c953d6d508b9600dd7d907cb95926d1aaf | xlabe2etests | analytics | tests/test_create_and_delete_exp_loggedin_user_mwloggedout.py | test_create_and_delete_exp_logged_out_user_activated(playwright, setup ) | function | def test_create_and_delete_exp_logged_out_user_activated(playwright, setup ):
# Class objects
homepage = HomePage(setup)
createexp = CreateNewExperiment(setup)
expName, machineReadableName = create_new_experiment(createexp, homepage, testdata['data'])
# confirm the new created exp
if homepage... |
3,209 | 8f5d002eab1c51e16597fefa2a81c652 | swh:1:cnt:c86c1cf27d0062a55cc89481ce4db8d82f8c18e4;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=18-87/ | 8d39b513f69bdd136d579d0daad8694033e21e79 | xlabe2etests | analytics | tests/test_create_and_delete_exp_loggedin_user_mwloggedout_activated.py | test_create_and_delete_exp_logged_out_users(playwright, setup ) | function | def test_create_and_delete_exp_logged_out_users(playwright, setup ):
# Class objects
homepage = HomePage(setup)
createexp = CreateNewExperiment(setup)
expName, machineReadableName = create_new_experiment(createexp, homepage, testdata['data'])
# confirm the new created exp
if homepage.last_pag... |
3,210 | 5fe96cb7abad588d27fdb9b554f45362 | swh:1:cnt:d6a3575ca2f3d78ba821bd41069eca098999a37f;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=11-146/ | 6204cf8e796a347ab34bfd916fc8c5a356bbe41d | xlabe2etests | analytics | tests/test_validate_ui_texts.py | test_text_strings_on_ui(playwright, setup) | function | def test_text_strings_on_ui(playwright, setup):
# Class objects
homepage = HomePage(setup)
createexp = CreateNewExperiment(setup)
# validating text strings on UI
expect(homepage.help_hyperlink()).to_be_visible()
expect(homepage.logout_hyperlink()).to_be_visible()
expect(homepage.xlab_... |
3,211 | a47544debf85599f6d5c0bf4685dac76 | swh:1:cnt:917ae426502a22452240f901c78116e77be9cabf;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=5-14/ | bf423e03328baa97763a6d40b98152bd49827119 | xlabe2etests | analytics | utils/api_base.py | ApiUtils | type | class ApiUtils:
def api_xlab_exp(self, playwright: Playwright):
base_url_ = "http://localhost"
api_context = playwright.request.new_context(base_url=base_url_)
response = api_context.get("/api/v1/experiments")
assert response.ok, f"API call failed: {response.status} {response.text()... |
3,212 | 6645eb43b9632194da2cdd9d3e413aff | swh:1:cnt:917ae426502a22452240f901c78116e77be9cabf;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=7-14/ | bf423e03328baa97763a6d40b98152bd49827119 | xlabe2etests | analytics | utils/api_base.py | ApiUtils::api_xlab_exp(self, playwright: Playwright) | function | def api_xlab_exp(self, playwright: Playwright):
base_url_ = "http://localhost"
api_context = playwright.request.new_context(base_url=base_url_)
response = api_context.get("/api/v1/experiments")
assert response.ok, f"API call failed: {response.status} {response.text()}"
data = res... |
3,213 | 82083e431c77fd7f46239623c12bda99 | swh:1:cnt:7fe188af79a02f19de018315f07e8fd2bd046f91;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=15-52/ | 7b2c415364a9282e71db4469dc8f3eb6a94db6a8 | xlabe2etests | analytics | utils/create_new_experiment.py | create_new_experiment(createexp, homepage, testdata) | function | def create_new_experiment(createexp, homepage, testdata):
expName = testdata['experiment_name']
machineReadableName = testdata['machine_readable_name']
experimentDesc = testdata['experiment_desc']
OkrToUse = testdata['okr_to_use']
phabricatorTask = testdata['task']
team = testdata['team']
co... |
3,214 | e2103447bee824d3d452541e3278efc0 | swh:1:cnt:0f71a618b43ce08154ccc9f3b5f766b3388cb2c5;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=6-19/ | eb30814965fa4c79ff047da809d12570f86f57a0 | xlabe2etests | analytics | utils/data_functions.py | load_json(filename) | function | def load_json(filename):
"""
Load and return data from a JSON file.
Args:
filepath (str): Path to the JSON file.
Returns:
dict or list: Parsed JSON content.
"""
current_dir = os.path.dirname(__file__) # directory of the script using this
file_path = os.pa... |
3,215 | 85139f6011144039386e8c58268fde71 | swh:1:cnt:39a0bb4e0285a65629240e880657418a1373f6c2;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=4-17/ | b16f5bb2e2d302a99185240d2886606ff1e0b541 | xlabe2etests | analytics | utils/dates_to_use.py | get_date_(temporal) | function | def get_date_(temporal):
""" Get the date 3 days out from the current day """
if temporal == "start_date":
current_date_start = date.today()
three_days_after = current_date_start + timedelta(days=3)
formatted_date_3_days_after = three_days_after.strftime("%Y-%m-%d")
return format... |
3,216 | 78bc0ad1421080c52ddfd2902441e199 | swh:1:cnt:4bcf93a04b6b738b4cf91f32a13d5609b1479279;origin=https://gitlab.wikimedia.org/repos/data-engineering/xlabe2etests.git;lines=4-18/ | 846419d457ccd6f13ca3368f2700f291e99e12ec | xlabe2etests | analytics | utils/mediawiki.py | mediawiki_not_logged_in(isLoggedIn) | function | def mediawiki_not_logged_in(isLoggedIn):
if isLoggedIn == "false":
# Navigate to the target page
mw_page = context.new_page()
mw_page.goto("http://localhost:8080/wiki/Main_Page")
# Wait for the page to load completely
mw_page.wait_for_load_state("load")
# Evaluate ... |
3,217 | f4dbeb80ebeade2351fc53253c577657 | swh:1:cnt:f2e06392989da1f9f47d2b848a6357c7ecf9d852;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=11-28/ | b9756318f870631bebd2f0bd4034c084cc0e8cbc | apps-android-wikipedia | apps | build-all.py | run_make_release(*args) | function | def run_make_release(*args):
"""Run make-release.py with the given arguments"""
cmd = [sys.executable, 'scripts/make-release.py'] + list(args)
print(f"Building with arguments: {' '.join(args)}")
try:
result = subprocess.run(cmd, check=True)
print(f"Build completed successfully:... |
3,218 | f607d890605293fbea0937f964410450 | swh:1:cnt:f2e06392989da1f9f47d2b848a6357c7ecf9d852;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=30-70/ | b9756318f870631bebd2f0bd4034c084cc0e8cbc | apps-android-wikipedia | apps | build-all.py | main() | function | def main():
"""Main build process"""
print("Starting build-all process...")
print("This will build multiple release variants sequentially.")
print(f"Platform: {platform.system()} {platform.release()}")
print()
# Check if we're in the right directory
if not os.path.exists('scripts/make-r... |
3,219 | 5e7b0b05c800ac07b1aa06aad21faa95 | swh:1:cnt:94f1c98ec2665035385f64b3694e043419f54cad;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=30-42/ | 1abaa2f02fac77222ad02c27d6c6375aca90afd3 | apps-android-wikipedia | apps | upload-all.py | upload_apks(name, pattern, upload_path) | function | def upload_apks(name, pattern, upload_path):
"""Upload APK files matching the pattern to the specified path"""
files = glob.glob(pattern)
if files:
try:
subprocess.run(['scp'] + files + [upload_path], check=True)
return True
except subprocess.CalledProcessError as e:
... |
3,220 | 2e123ddea565e320feffadba17df2050 | swh:1:cnt:94f1c98ec2665035385f64b3694e043419f54cad;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=45-56/ | 1abaa2f02fac77222ad02c27d6c6375aca90afd3 | apps-android-wikipedia | apps | upload-all.py | main() | function | def main():
upload_count = 0
for config in UPLOAD_CONFIGS:
if upload_apks(config['name'], config['pattern'], config['path']):
upload_count += 1
if upload_count == 0:
print("No APK files found to upload.")
sys.exit(1)
print(f"\n✓ {upload_count} uploads completed suc... |
3,221 | 5add4a7710f5c42f455690461b94a15a | swh:1:cnt:4522879ea4b9091eadbfd9a6d8fb4d58dd5fd691;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=28-37/ | 3809810eb64fc64b3fe6caf3b4bfd83c89725a62 | apps-android-wikipedia | apps | scripts/bump-version-code.py | set_version_code(data) | function | def set_version_code(data):
"""
Utility function to set new versionCode
"""
match = version_code_pattern.search(data)
if not match:
raise ValueError('Version code not found')
version_code = int(match.group('value'))
next_version_code = r'\g<key> {}'.format(version_code + 1)
retur... |
3,222 | 36a2ee36f6853f8f788c2340675e022f | swh:1:cnt:4522879ea4b9091eadbfd9a6d8fb4d58dd5fd691;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=68-96/ | 3809810eb64fc64b3fe6caf3b4bfd83c89725a62 | apps-android-wikipedia | apps | scripts/bump-version-code.py | bump(file_path) | function | def bump(file_path):
transform_file(file_path, set_version_code)
# Change to the project directory
os.chdir(path_prefix)
# Checkout main branch
run_git_command('checkout', 'main')
# Try to delete existing branch
try:
run_git_command('branch', '-D', VERSION_CODE_BRANCH)
except ... |
3,223 | ab07ab69242f7006b1582b32936e1435 | swh:1:cnt:4522879ea4b9091eadbfd9a6d8fb4d58dd5fd691;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=40-49/ | 3809810eb64fc64b3fe6caf3b4bfd83c89725a62 | apps-android-wikipedia | apps | scripts/bump-version-code.py | run_git_command(*args, cwd=None) | function | def run_git_command(*args, cwd=None):
"""
Run a git command with the given arguments in a cross-platform way.
"""
cmd = ['git'] + list(args)
try:
result = subprocess.run(cmd, cwd=cwd, check=True, capture_output=True, text=True)
return result.stdout.strip()
except subprocess.Calle... |
3,224 | 53997e0ee57ac6630177909d5b840043 | swh:1:cnt:4522879ea4b9091eadbfd9a6d8fb4d58dd5fd691;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=52-65/ | 3809810eb64fc64b3fe6caf3b4bfd83c89725a62 | apps-android-wikipedia | apps | scripts/bump-version-code.py | transform_file(file_path, *funcs) | function | def transform_file(file_path, *funcs):
"""
Transforms the file given in file_path by passing it
serially through all the functions in *func and then
writing it back out to file_path
"""
with open(file_path, 'r+') as f:
data = f.read()
f.seek(0)
for func in funcs:
... |
3,225 | d0320a3c890850cf2f250ca3b4967027 | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=18-32/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | fetch_color_data(url, description) | function | # Fetch and return color data from URL with error handling
def fetch_color_data(url, description):
print(f"fetching {description}")
print(f"Making request to: {url}")
try:
response = requests.get(url)
if response.status_code == 200:
print("Request successful!")
return... |
3,226 | 3a6a8c236b7bbba54d49cd7bc853608d | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=106-128/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | generate_wikipedia_color_class(base_colors, file_path) | function | def generate_wikipedia_color_class(base_colors, file_path):
if not base_colors:
print("Warning: No base colors to generate class")
return False
content = ["package org.wikipedia.compose.theme\n\n",
"import androidx.compose.runtime.Immutable\n"
"import androidx.comp... |
3,227 | a0785342047e2289869b6a11709e1dce | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=81-104/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | generate_compose_raw_color_file(colors_dict, file_path) | function | # colors_dict: the processed codex colors with { name: value } format
# file_path: path where you want to save the file
def generate_compose_raw_color_file(colors_dict, file_path):
if not colors_dict:
print("Warning: No raw colors to generate class")
return False
content = ["package org.wikiped... |
3,228 | e2d786ac6c250c60560aa9139f176287 | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=63-70/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | convert_hex_to_kotlin_color(hex_color) | function | # takes in #f8f9fa and converts to 0xFFf8f9fa
# handles 3 digit css color as well
def convert_hex_to_kotlin_color(hex_color):
hex_color = hex_color.lstrip("#")
# handle 3-digit CSS color
if len(hex_color) == 3:
hex_color = ''.join([char * 2 for char in hex_color])
return f"0xFF{hex_color}" |
3,229 | 7e21799d04f7465da9a3019f0f44c516 | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=34-61/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | extract_colors(color_data, token_type, dark_mode = False) | function | # color_data: the codex json response
# token_type: one of the above token types (theme, base, component, mode)
# dark mode tokens consist of two types base and mode, 3rd parameter dark_mode handles this edge case
def extract_colors(color_data, token_type, dark_mode = False):
results = {}
color_section = color_... |
3,230 | b998a13ee1c0d9b1c98c4e7a40b57a70 | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=72-78/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | to_camel_case(text) | function | def to_camel_case(text):
# Split on both single and double dashes
parts = re.split(r'-+', text)
if not parts:
return text
# First part will be lowercase, rest are capitalized
return parts[0].lower() + ''.join(word.capitalize() for word in parts[1:] if word) |
3,231 | e8fd6a20cec294e38cc10800eee4465a | swh:1:cnt:09138040b3f7aad742d3f56047a94d9afa5c1f8e;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=130-148/ | 5efb8bf6d8a23e24d8b32b334af43ef698836af3 | apps-android-wikipedia | apps | scripts/generate-codex-colors.py | append_color_tokens(colors, file_path, mode_name) | function | # Append light or dark color tokens to the file
def append_color_tokens(colors, file_path, mode_name):
if not colors:
print(f"Warning: No {mode_name} colors to append")
return False
content = [f"\nval {mode_name}Colors = WikipediaColor(\n"]
for name, original_value_name in sorted(colors.ite... |
3,232 | 26984775e5866142a20168a1a1f5df89 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=148-149/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | existing_values_directories(res_dir: Path) | function | def existing_values_directories(res_dir: Path) -> set[str]:
return {path.name for path in res_dir.iterdir() if path.is_dir() and path.name.startswith("values")} |
3,233 | 696082ed37a73eb612ac064b92a79d8e | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=124-127/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | fetch_json(api_url: str, params: dict[str, str]) | function | def fetch_json(api_url: str, params: dict[str, str]) -> dict:
request = Request(f"{api_url}?{urlencode(params)}", headers=headers)
with urlopen(request) as response:
return json.load(response) |
3,234 | 1130a438bce69dab05127a600cc0b13f | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=196-200/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | msg_key_to_resource_name(msg_key: str) | function | def msg_key_to_resource_name(msg_key: str) -> str:
resource_name = re.sub(r"[^a-z0-9_]", "_", msg_key.lower().replace("-", "_"))
if not re.match(r"^[a-z_]", resource_name):
resource_name = f"topic_{resource_name}"
return resource_name |
3,235 | 579248d42ef4fec948ad7de761ec1e13 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=235-249/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | build_xml(msg_keys: Iterable[str], localized_messages: dict[str, str], language_code: str) | function | def build_xml(msg_keys: Iterable[str], localized_messages: dict[str, str], language_code: str) -> str:
lines = [
'<?xml version="1.0" encoding="utf-8"?>',
'<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">',
f' <!-- Generated by scripts/generate_... |
3,236 | 81914b2883235b81c3d615af0234e33b | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=260-270/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | resolve_target_languages(args: argparse.Namespace) | function | def resolve_target_languages(args: argparse.Namespace) -> list[str]:
if args.languages:
return args.languages
existing_dirs = existing_values_directories(args.res_dir)
resolved = []
for language_code in fetch_available_language_codes(args.languages_api_url):
values_dir = to_android_valu... |
3,237 | 60d7321b7d60a8ec32c158349faa0792 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=91-121/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | parse_args() | function | def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Generate localized onboarding topic string resources from MediaWiki allmessages."
)
parser.add_argument(
"languages",
nargs="*",
help="Optional MediaWiki language codes to generate explicit... |
3,238 | 3dcc452e7bc5a5f5a083c70f6a10455e | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=130-145/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | fetch_available_language_codes(api_url: str) | function | def fetch_available_language_codes(api_url: str) -> list[str]:
payload = fetch_json(
api_url,
{
"action": "query",
"format": "json",
"meta": "siteinfo",
"formatversion": "2",
"siprop": "languages|languagevariants",
"siinlanguage... |
3,239 | 7bfbeff643e50255e0d3ad1b9a87bf59 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=152-193/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | fetch_messages(api_url: str, language_code: str, msg_keys: Iterable[str]) | function | def fetch_messages(api_url: str, language_code: str, msg_keys: Iterable[str]) -> dict[str, str]:
payload = fetch_json(
api_url,
{
"format": "json",
"formatversion": "2",
"errorformat": "html",
"errorsuselocal": "1",
"action": "query",
... |
3,240 | 63caceeb9fdf8a1b39448f5512cc9946 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=203-232/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | to_android_values_dir(language_code: str) | function | def to_android_values_dir(language_code: str) -> str:
normalized = language_code.replace("_", "-")
override = LANGUAGE_DIR_OVERRIDES.get(normalized.lower())
if override:
return override
if normalized == "en":
return "values"
parts = [part for part in normalized.split("-") if part]
... |
3,241 | d0e66c28d7661b10f77c7bbbd0836ca3 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=252-257/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | write_output(xml_text: str, res_dir: Path, language_code: str) | function | def write_output(xml_text: str, res_dir: Path, language_code: str) -> Path:
values_dir = res_dir / to_android_values_dir(language_code)
values_dir.mkdir(parents=True, exist_ok=True)
output_file = values_dir / "strings_topics.xml"
output_file.write_text(xml_text, encoding="utf-8")
return output_file |
3,242 | 68c11afe457edb332497a73344ca5c28 | swh:1:cnt:7d934d674a1c0236d32e9f5ef4a63b79ac56223f;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=273-293/ | 39ce849622d6094438fbee75a3fee4c9dcc327a8 | apps-android-wikipedia | apps | scripts/generate_topic_strings.py | main() | function | def main() -> int:
args = parse_args()
target_languages = resolve_target_languages(args)
if args.stdout and len(target_languages) != 1:
raise ValueError("--stdout can only be used with a single language code")
if not target_languages:
raise ValueError("No matching Android values director... |
3,243 | ceb9662cd69df1cb2a892d6c875ca916 | swh:1:cnt:88ad27d31ac7c65db4963bed76b63afdc4d36dc9;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=28-39/ | 53d5de02736dcf56fc931d345beead25f04af58d | apps-android-wikipedia | apps | scripts/generate_wiki_languages.py | add_lang(key, bcp47key, local_name, eng_name, rank) | function | def add_lang(key, bcp47key, local_name, eng_name, rank):
rank_pos = 0
# Automatically keep the arrays sorted by rank
for index, item in enumerate(lang_rank):
rank_pos = index
if (rank > item):
break
lang_keys.insert(rank_pos, key)
lang_bcp47_keys.insert(rank_pos, bcp47key... |
3,244 | daab1320fed2a221f5f6e2970de5932b | swh:1:cnt:88ad27d31ac7c65db4963bed76b63afdc4d36dc9;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=41-44/ | 53d5de02736dcf56fc931d345beead25f04af58d | apps-android-wikipedia | apps | scripts/generate_wiki_languages.py | add_variant(lang_code_variants) | function | def add_variant(lang_code_variants):
# use comma to separate values, and the first item is the key
print("Variants " + lang_code_variants)
lang_variants.append(lang_code_variants) |
3,245 | 11ab58bcaa4b71a67361c1a5f7b907d4 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=55-57/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | get_output_apk_file_name(flavor, build_type='release') | function | def get_output_apk_file_name(flavor, build_type='release'):
build_type_lower = build_type.lower()
return f'app/build/outputs/apk/{flavor}/{build_type_lower}/app-{flavor}-{build_type_lower}.apk' |
3,246 | 72c71cd0c95b1021a02718f70963fba1 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=64-71/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | verify_apk_exists(apk_path) | function | def verify_apk_exists(apk_path):
"""Verify that the APK file exists and is readable"""
full_path = os.path.join(PATH_PREFIX, apk_path)
if not os.path.exists(full_path):
sys.exit(f"APK file not found: {full_path}")
if not os.path.isfile(full_path):
sys.exit(f"APK path is not a file: {full... |
3,247 | 039491cb04ac1b6b210696cc9079f4ff | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=81-89/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | grep_from_build_file(property_name, regex) | function | def grep_from_build_file(property_name, regex):
build_gradle_file_name = 'app/build.gradle'
with open(build_gradle_file_name, "r") as build_file:
for line in build_file:
found = re.search(regex, line)
if found:
res = found.groups()[0]
return res
... |
3,248 | 6b6c6c942fb9e086a7bd1c36e37bab47 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=96-135/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | get_version_name_from_apk(apk_file) | function | def get_version_name_from_apk(apk_file):
# Verify APK exists first
full_apk_path = verify_apk_exists(apk_file)
android_home = get_android_home()
# Find the build-tools directory
build_tools_path = os.path.join(android_home, 'build-tools')
if not os.path.exists(build_tools_path):
sys.ex... |
3,249 | 3cba8b8a67339c3809a5f70e3ec1a29c | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=158-167/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | find_output_apk_for(label, version_code) | function | def find_output_apk_for(label, version_code):
folder_path = 'releases'
file_pattern = '%s/wikipedia-%s-%s-*.apk' % (folder_path, version_code, label)
apk_files = glob.glob(file_pattern)
if len(apk_files) == 1:
return apk_files[0]
elif len(apk_files) == 0:
sys.exit("Did not find apk f... |
3,250 | 366a0171baf19bdb9427f8492a7c7ac4 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=278-296/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | kill_gradle_daemons() | function | def kill_gradle_daemons():
"""Kill any running Gradle daemons to release file locks"""
try:
print("Attempting to stop Gradle daemons...")
# Use platform-specific gradlew command
gradlew_cmd = 'gradlew.bat' if platform.system() == 'Windows' else './gradlew'
result = subprocess.run... |
3,251 | b251832ab9de7a6545222922d3fb263f | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=341-361/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | force_clear_build_directory() | function | def force_clear_build_directory():
"""Force clear the entire build directory on Windows"""
try:
build_dir = os.path.join(PATH_PREFIX, 'app', 'build')
if os.path.exists(build_dir):
print(f"Force clearing build directory: {build_dir}")
time.sleep(2)
... |
3,252 | 27bbdb16523d7803dea4167d6452eb14 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=45-52/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | git_tag_and_push(target, version_name, push=False) | function | def git_tag_and_push(target, version_name, push=False):
"""Creates an annotated git tag for this release and optionally pushes it"""
tag_name = target + '/' + version_name
subprocess.run(['git', 'tag', '-a', tag_name, '-m', target], check=True)
if push:
print('pushing tag ' + tag_name)
... |
3,253 | 62c9c8ad737c12ab8bec06c728ce3009 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=59-61/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | get_output_bundle_file_name(flavor, build_type='release') | function | def get_output_bundle_file_name(flavor, build_type='release'):
# Bundle file naming: flavor is title case, build type in path is title case but in filename is lowercase
return f'app/build/outputs/bundle/{flavor}{build_type.title()}/app-{flavor}-{build_type.lower()}.aab' |
3,254 | ceae9e80d53fbcb59a89df72c0503a22 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=74-78/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | get_android_home() | function | def get_android_home():
android_home = os.environ.get('ANDROID_HOME')
if not android_home:
sys.exit('$ANDROID_HOME not set')
return android_home |
3,255 | a0fcf2f32fae30fbfc20196635d757d7 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=92-93/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | get_version_code_from_build_file() | function | def get_version_code_from_build_file():
return grep_from_build_file('versionCode', r'versionCode\s+(\S+)') |
3,256 | 22755a9b344fc66307560cf8353ae52f | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=138-156/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | copy_build_artifact(artifact_type, flavor, version_name, build_type='release') | function | def copy_build_artifact(artifact_type, flavor, version_name, build_type='release'):
"""Copy APK or AAB artifact to releases folder"""
folder_path = os.path.join(PATH_PREFIX, 'releases')
os.makedirs(folder_path, exist_ok=True)
if artifact_type == 'apk':
build_suffix = '' if build_type.lower(... |
3,257 | 7d56b94a3f690de3081db34a9c85f7ba | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=169-275/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | try_clean_gradle_build(flavors, custom_channel, build_type, task_type='assemble', max_retries=3, skip_clean=False) | function | def try_clean_gradle_build(flavors, custom_channel, build_type, task_type='assemble', max_retries=3, skip_clean=False):
"""
Try to build with retries for Windows file locking issues
Args:
flavors: List of flavors to build
custom_channel: Custom channel name
build_type: Build typ... |
3,258 | b3ccd4e445c65d02a0cb818ef259473f | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=299-338/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | clear_lint_cache() | function | def clear_lint_cache():
"""Clear Android Lint cache to resolve file locking issues"""
try:
# Multiple possible lint cache locations
lint_cache_locations = [
os.path.join(PATH_PREFIX, 'app', 'build', 'intermediates', 'lint-cache'),
os.path.join(PATH_PREFIX, 'app', 'build',... |
3,259 | 304411c5f950781d8bf1c7edc7b876f5 | swh:1:cnt:8e15ca81f51f99f358f775acb35d786e670dc475;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=364-460/ | a307a50c4346c25077f5b024020a5f0019a5e310 | apps-android-wikipedia | apps | scripts/make-release.py | main() | function | def main():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument('--alpha',
help='Step 1: Alpha for testing.',
action='store_true')
group.add_argument('--beta',
help='Step 1: Google Play B... |
3,260 | df54754229be9ad8294e5f1076cb8ca7 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=24-29/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | Wiki | type | # Represents a single wiki, along with arbitrary properties of that wiki
# Simple data container object
class Wiki(object):
def __init__(self, lang):
self.lang = lang
self.props = {} |
3,261 | 32820b75eebb133446caa80638fb387c | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=32-51/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | WikiList | type | # Represents a list of wikis plus their properties.
# Encapsulates rendering code as well
class WikiList(object):
def __init__(self, wikis):
self.wikis = wikis
self.template_env = Environment(loader=FileSystemLoader(
os.path.join(os.path.dirname(os.path.realpath(__file__)), u"templates")... |
3,262 | 574256477f2bbdd940058e9bbe8a3051 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=27-29/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | Wiki::__init__(self, lang) | function | def __init__(self, lang):
self.lang = lang
self.props = {} |
3,263 | 37d3908273eece7868807ccbe21fcfd6 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=61-90/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | list_from_sitematrix() | function | def list_from_sitematrix():
QUERY_SITEMATRIX = 'https://www.mediawiki.org/w/api.php?action=sitematrix' \
'&format=json&formatversion=2&smtype=language&smstate=all'
print(u"Fetching languages...")
data = json.loads(requests.get(QUERY_SITEMATRIX, headers=headers).text)
wikis = []
for key, va... |
3,264 | f9609e768611aa82948866364414920d | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=35-39/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | WikiList::__init__(self, wikis) | function | def __init__(self, wikis):
self.wikis = wikis
self.template_env = Environment(loader=FileSystemLoader(
os.path.join(os.path.dirname(os.path.realpath(__file__)), u"templates")
)) |
3,265 | a5d1554cda3d01854b159648cf00128c | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=107-129/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | postprocess_wikis(wiki_list) | function | # Apply manual tweaks to the list of wikis after they're populated.
def postprocess_wikis(wiki_list):
# Add Simplified and Traditional Chinese dialects.
chineseWiki = next((wiki for wiki in wiki_list.wikis if wiki.lang == CHINESE_WIKI_LANG), None)
chineseWikiIndex = wiki_list.wikis.index(chineseWiki)
s... |
3,266 | 3ac8701bf4e878c6492b76ade0e8d93f | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=153-164/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | populate_main_pages(wikis) | function | # Populates data on names of main page in each wiki
def populate_main_pages(wikis):
for wiki in wikis.wikis:
print(u"Fetching Main Page for %s" % wiki.lang)
url = u"https://%s.wikipedia.org/w/api.php" % wiki.lang + \
u"?action=query&meta=siteinfo&format=json&siprop=general|specialpagea... |
3,267 | 68ccd040b07c06b9c183808a96b45acc | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=170-172/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | render_template::_actual_render(wikis) | function | def _actual_render(wikis):
wikis.render(template, filename, **kwargs)
return wikis |
3,268 | a0ef6e0316d3bcebd376db33948100d1 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=176-180/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | chain(*funcs) | function | # Kinda like reduce(), but special cases first function
def chain(*funcs):
res = funcs[0]()
for func in funcs[1:]:
res = func(res) |
3,269 | 37154ca85f3416f2eaacc442c534451e | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=54-58/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | build_wiki(lang, english_name, local_name) | function | def build_wiki(lang, english_name, local_name):
wiki = Wiki(lang)
wiki.props["english_name"] = english_name
wiki.props["local_name"] = local_name
return wiki |
3,270 | 897ef7648c90704bae493d8371c2ca18 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=41-51/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | WikiList::render(self, template, class_name, **kwargs) | function | def render(self, template, class_name, **kwargs):
data = {
u"class_name": class_name,
u"wikis": self.wikis
}
data.update(kwargs)
rendered = self.template_env.get_template(template).render(**data)
out = codecs.open(u"../app/src/main/java/org/wikipedia/stati... |
3,271 | 584154d4ae6c71e0cd66d54639a4dfac | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=93-95/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | filter_supported_wikis(wikis) | function | # Remove unsupported wikis.
def filter_supported_wikis(wikis):
return [wiki for wiki in wikis if wiki.lang not in OSTRICH_WIKIS] |
3,272 | 92dc5a6fa48286f61400cf507d8c488a | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=98-104/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | preprocess_wikis(wikis) | function | # Apply manual tweaks to the list of wikis before they're populated.
def preprocess_wikis(wikis):
# Add TestWiki.
wikis.append(build_wiki(lang="test", english_name="Test", local_name="Test"))
wikis.append(build_wiki(lang="test2", english_name="Test2", local_name="Test2"))
return wikis |
3,273 | 66ccb558adf9e4e1b9691841c5f13186 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=132-150/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | populate_aliases(wikis) | function | # Populate the aliases for "Special:" and "File:" in all wikis
def populate_aliases(wikis):
for wiki in wikis.wikis:
print(u"Fetching namespace strings for %s" % wiki.lang)
url = u"https://%s.wikipedia.org/w/api.php" % wiki.lang + \
u"?action=query&meta=siteinfo&format=json&siprop=name... |
3,274 | 81ff78e540a3301e98ac4c7c820d5487 | swh:1:cnt:6d4583d599548fce42171467781f737c5651a546;origin=https://github.com/wikimedia/apps-android-wikipedia;lines=167-173/ | eab4cbd669e396e999d2793c935913a46b014f64 | apps-android-wikipedia | apps | scripts/make-templates.py | render_template(template, filename, **kwargs) | function | # Returns a function that renders a particular template when passed
# a WikiList object
def render_template(template, filename, **kwargs):
def _actual_render(wikis):
wikis.render(template, filename, **kwargs)
return wikis
return _actual_render |
3,275 | db5fde77744a2f46b7319eb6c7e76f6e | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=43-500/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll | type | /**
* Maintenance script that replaces text in pages
*
* @ingroup Maintenance
* @SuppressWarnings(StaticAccess)
* @SuppressWarnings(LongVariable)
*/
class ReplaceAll extends Maintenance {
private User $user;
/** @var string[] */
private array $target;
/** @var string[] */
private array $replacement;
/** @va... |
3,276 | a4fc5c131600cf030f9d44ccceb378a2 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=199-209/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::listNamespaces() | function | private function listNamespaces(): void {
$this->output( "Index\tNamespace\n" );
$nsList = $this->getServiceContainer()->getNamespaceInfo()->getCanonicalNamespaces();
ksort( $nsList );
foreach ( $nsList as $int => $val ) {
if ( $val == '' ) {
$val = '(main)';
}
$this->output( " $int\t$val\n" );
}... |
3,277 | 93b7c95541dc98d98238eff3eb54cee7 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=391-413/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::localSetup() | function | private function localSetup(): bool {
if ( $this->getOption( 'listns' ) ) {
$this->listNamespaces();
return false;
}
if ( $this->getOption( 'show-file-format' ) ) {
$this->showFileFormat();
return false;
}
$this->user = $this->getUser();
if ( !$this->getReplacements() ) {
$this->target = $thi... |
3,278 | 1e1ed2547d8efaf5d63f213f55a93afe | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=299-335/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::listTitles(
array $titles,
string $target,
string $replacement,
bool $regex,
bool $rename
) | function | /**
* @param Title[] $titles
* @param string $target
* @param string $replacement
* @param bool $regex
* @param bool $rename
*/
private function listTitles(
array $titles,
string $target,
string $replacement,
bool $regex,
bool $rename
): void {
$skippedTitles = [];
foreach ( $titles as $pref... |
3,279 | 27a30f6dcbe1958049e69dfc4dd0b3ba | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=415-499/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::execute() | function | /**
* @inheritDoc
*/
public function execute() {
$this->botEdit = false;
if ( !$this->localSetup() ) {
return;
}
if ( $this->namespaces === [] ) {
$this->fatalError( 'No matching namespaces.' );
}
$services = $this->getServiceContainer();
$hookHelper = new HookHelper( $services->getHookContai... |
3,280 | 4c468751a4483708dc847616c60503d7 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=67-110/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::__construct() | function | public function __construct() {
parent::__construct();
$this->addDescription( 'CLI utility to replace text wherever it is ' .
'found in the wiki.' );
$this->addArg( 'target', 'Target text to find.', false );
$this->addArg( 'replace', 'Text to replace.', false );
$this->addOption( 'dry-run', 'Only find th... |
3,281 | 64578f110b759405da906465d4ee89b0 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=140-149/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getReplacement() | function | /**
* @return string[]
*/
private function getReplacement(): array {
$ret = $this->getArg( 1 );
if ( $ret === null ) {
$this->fatalError( 'You have to specify replacement text.' );
}
return [ $ret ];
} |
3,282 | 61fcd85b9f4cb8bbba779a0a00d00035 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=112-127/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getUser() | function | private function getUser(): User {
$userReplacing = $this->getOption( 'user', 1 );
$userFactory = $this->getServiceContainer()->getUserFactory();
$user = is_numeric( $userReplacing ) ?
$userFactory->newFromId( $userReplacing ) :
$userFactory->newFromName( $userReplacing );
if ( !$user instanceof User ) ... |
3,283 | 2ad6884cf2b89304ae56312805ad8ff2 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=235-269/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getNamespaces() | function | /**
* @return int[]
*/
private function getNamespaces(): array {
$nsall = $this->getOption( 'nsall' );
$ns = $this->getOption( 'ns' );
if ( !$nsall && !$ns ) {
$namespaces = [ NS_MAIN ];
} else {
$canonical = $this->getServiceContainer()->getNamespaceInfo()->getCanonicalNamespaces();
$canonical[NS... |
3,284 | e48755265cf43937d186e337059cb0cd | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=295-297/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getRename() | function | private function getRename(): bool {
return $this->hasOption( 'rename' );
} |
3,285 | 4810c7c416fc4f4c6ec742c4fec9b335 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=279-286/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getPageLimit() | function | private function getPageLimit(): int {
$pageLimit = (int)$this->getOption( 'pageLimit' );
if ( $pageLimit < 1 ) {
$pageLimit = $this->getServiceContainer()
->getMainConfig()->get( 'ReplaceTextResultsLimit' );
}
return $pageLimit;
} |
3,286 | 9dcb4455cdae180f0a8408eae42f41fd | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=182-185/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::shouldContinueByDefault() | function | private function shouldContinueByDefault(): bool {
$this->defaultContinue ??= (bool)$this->getOption( 'yes' );
return $this->defaultContinue;
} |
3,287 | 4af7ba1b7826c5e860129476402bb4e8 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=187-197/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getSummary( string $target, string $replacement ) | function | private function getSummary( string $target, string $replacement ): string {
if ( $this->getOption( 'summary' ) !== null ) {
$msg = str_replace( [ '%f', '%r' ],
[ $target, $replacement ],
$this->getOption( 'summary' ) );
} else {
$msg = wfMessage( 'replacetext_editsummary', $target, $replacement )
... |
3,288 | 67d4f06f699ac210fd0611f790d5333b | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=379-389/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getReply( string $question ) | function | private function getReply( string $question ): bool {
$reply = '';
if ( $this->shouldContinueByDefault() ) {
return true;
}
while ( $reply !== 'y' && $reply !== 'n' ) {
$reply = $this->readconsole( "$question (Y/N) " );
$reply = substr( strtolower( $reply ), 0, 1 );
}
return $reply === 'y';
} |
3,289 | 59498c5545a00a21a308900cb9291006 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=271-273/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getCategory() | function | private function getCategory(): ?string {
return $this->getOption( 'category' );
} |
3,290 | b5f2c3c2b058b29c74ccde4de974d494 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=337-377/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::replaceTitles(
array $titles,
string $target,
string $replacement,
bool $useRegex,
bool $rename
) | function | /**
* @param Title[] $titles
* @param string $target
* @param string $replacement
* @param bool $useRegex
* @param bool $rename
*/
private function replaceTitles(
array $titles,
string $target,
string $replacement,
bool $useRegex,
bool $rename
): void {
foreach ( $titles as $title ) {
$para... |
3,291 | b27b5fcf30617bd10820c62925e3717c | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=129-138/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getTarget() | function | /**
* @return string[]
*/
private function getTarget(): array {
$ret = $this->getArg( 0 );
if ( $ret === null ) {
$this->fatalError( 'You have to specify a target.' );
}
return [ $ret ];
} |
3,292 | 0f896c19a4a2d84881d7512727485258 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=151-180/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getReplacements() | function | private function getReplacements(): bool {
$file = $this->getOption( 'replacements' );
if ( !$file ) {
return false;
}
if ( !is_readable( $file ) ) {
throw new MWException( 'File does not exist or is not readable: '
. "$file\n" );
}
$handle = fopen( $file, 'r' );
if ( $handle === false ) {
... |
3,293 | fd24351be04bd4730ac4aee263836b19 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=211-233/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::showFileFormat() | function | private function showFileFormat(): void {
$text = <<<EOF
The format of the replacements file is tab separated with three fields.
Any line that does not have a tab is ignored and can be considered a comment.
Fields are:
1. String to search for.
2. String to replace found text with.
3. (optional) The presence of ... |
3,294 | 8587712defd41092e63533d0c1b453d0 | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=275-277/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::getPrefix() | function | private function getPrefix(): ?string {
return $this->getOption( 'prefix' );
} |
3,295 | caebea0734ccbbfec1c3b23e207421ff | swh:1:cnt:3f601b06683f745d1aa66f8348f0efe44f70aba0;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=288-293/ | 8ca4e8dcbce7157249fecdf6735e415b46b86be7 | ReplaceText | bundled | maintenance/replaceAll.php | ReplaceAll::useRegex() | function | /**
* @return bool[]
*/
private function useRegex(): array {
return [ (bool)$this->getOption( 'regex' ) ];
} |
3,296 | 125f08d2d3bae65f3f266f4781c88d14 | swh:1:cnt:56909118e37a6417eaba7d90f1997f9d8060778f;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=4-8/ | 0100f42c2f4bbf97991f6157db3e6454a783f438 | ReplaceText | bundled | resources/ext.ReplaceText.js | invertSelections | function | function invertSelections() {
$( '.oo-ui-inputWidget-input[type=checkbox]' ).each( ( _i, checkbox ) => {
checkbox.checked = !checkbox.checked;
} );
} |
3,297 | daea04f5be3504857dcfcbd12cb0c718 | swh:1:cnt:56909118e37a6417eaba7d90f1997f9d8060778f;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=21-26/ | 0100f42c2f4bbf97991f6157db3e6454a783f438 | ReplaceText | bundled | resources/ext.ReplaceText.js | visibleCodePointLimit::updateCount | function | function updateCount() {
const value = textInputWidget.getValue();
const remaining = limit - codePointLength( value );
const label = remaining > 99 ? '' : mw.language.convertNumber( remaining );
textInputWidget.setLabel( label );
} |
3,298 | ebff51e5385849c731007b767a9247b0 | swh:1:cnt:56909118e37a6417eaba7d90f1997f9d8060778f;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=10-30/ | 0100f42c2f4bbf97991f6157db3e6454a783f438 | ReplaceText | bundled | resources/ext.ReplaceText.js | visibleCodePointLimit | function | /**
* Add a visible codepoint (character) limit label to a TextInputWidget.
*
* Uses jQuery#codePointLimit to enforce the limit.
*
* @param {OO.ui.TextInputWidget} textInputWidget Text input widget
*/
function visibleCodePointLimit( textInputWidget ) {
const limit = +textInputWidget.$input.attr( 'maxleng... |
3,299 | 6f8694cd02ee98a018dc649f844b4d7d | swh:1:cnt:0bbd39f9fe2dc6b3827b5ef96e27e5e6c36cdffa;origin=https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText.git;lines=10-30/ | 9e1aca7476a17a9cb799c1d9a0a9910fd4900a49 | ReplaceText | bundled | src/AdminLinksHooks.php | AdminLinksHooks | type | class AdminLinksHooks implements AdminLinksHook {
/**
* Implements AdminLinks hook from Extension:Admin_Links.
*/
public function onAdminLinks( ALTree &$adminLinksTree ) {
$generalSection = $adminLinksTree->getSection( wfMessage( 'adminlinks_general' )->text() );
if ( !$generalSection ) {
return;
}
$... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.