{"id":15134658,"url":"https://github.com/svick/linq-to-wiki","last_synced_at":"2025-10-23T11:30:39.648Z","repository":{"id":137592667,"uuid":"2696568","full_name":"svick/LINQ-to-Wiki","owner":"svick","description":".Net library to access MediaWiki API","archived":false,"fork":false,"pushed_at":"2017-07-11T12:25:52.000Z","size":6015,"stargazers_count":99,"open_issues_count":14,"forks_count":25,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-07T15:13:57.090Z","etag":null,"topics":["codegen","linq","mediawiki","mediawiki-api","wiki","wikipedia"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.txt","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-11-02T17:15:06.000Z","updated_at":"2024-08-12T19:20:23.000Z","dependencies_parsed_at":"2023-06-03T03:30:11.936Z","dependency_job_id":null,"html_url":"https://github.com/svick/LINQ-to-Wiki","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svick%2FLINQ-to-Wiki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svick%2FLINQ-to-Wiki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svick%2FLINQ-to-Wiki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svick%2FLINQ-to-Wiki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svick","download_url":"https://codeload.github.com/svick/LINQ-to-Wiki/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237811568,"owners_count":19370151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codegen","linq","mediawiki","mediawiki-api","wiki","wikipedia"],"created_at":"2024-09-26T05:23:29.194Z","updated_at":"2025-10-23T11:30:39.160Z","avatar_url":"https://github.com/svick.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"LinqToWiki\n==========\n\nLinqToWiki is a library for accessing sites running [MediaWiki](http://www.mediawiki.org/)\n(including [Wikipedia](http://en.wikipedia.org/)) through the [MediaWiki API](https://www.mediawiki.org/wiki/API)\nfrom .Net languages like C# and VB.NET.\n\nIt can be used to do almost anything that can be done from the web interface and more,\nincluding things like editing articles, listing articles in categories, listing all kinds of links on a page\nand much more.\nQuerying the various lists available can be done using LINQ queries,\nwhich then get translated into efficient API requests.\n\nThe library is strongly-typed, which means it should be hard to make invalid requests\nand it also makes it easy to discover available methods and properties though IntelliSense.\n\nBecause the API can vary from wiki to wiki,\n[it's necessary to configure the library thorough an automatically generated assembly](#generating-configuration-for-a-wiki).\n\n- [Downloads](#downloads)\n- [Usage](#usage)\n- [Generating configuration for a wiki](#generating-configuration-for-a-wiki)\n- [Developer documentation](#developer-documentation)\n\nDownloads\n---------\n\n- Add the package [LinqToWiki](https://nuget.org/packages/LinqToWiki) to your project through [NuGet](https://nuget.org/); or\n- Download [LinqToWiki](http://ltw.svick.org/LinqToWiki-enwiki-20130211.zip) (11 February 2013)\n\nUsage\n-----\n\n### Simple example\n\nFor example, to edit the [Sandbox](http://en.wikipedia.org/wiki/Wikipedia:Sandbox) on the English Wikipedia anonymously, you can use the following:\n\n```C#\nvar wiki = new Wiki(\"TheNameOfMyBot/1.0 (http://website, myemail@site)\", \"en.wikipedia.org\");\n\n// get edit token, necessary to edit pages\nvar token = wiki.tokens(new[] { tokenstype.edit }).edittoken;\n\n// create new section called \"Hello\" on the page \"Wikipedia:Sandbox\"\nwiki.edit(\n    token: token, title: \"Wikipedia:Sandbox\", section: \"new\", sectiontitle: \"Hello\", text: \"Hello world!\");\n```\n\nAs you can see, in methods like this, you should use named parameters,\nbecause the `edit()` method has lots of them, and you probably don't need them all.\n\nThe code looks more convoluted than necessary (can't the library get the token for me?),\nbut that's because it's all generated automatically.\n\n### Queries\n\nWhere LINQ to Wiki really shines, though, are queries:\nIf you wanted to get the names of all pages in [Category:Mammals of Indonesia](http://en.wikipedia.org/wiki/Category:Mammals_of_Indonesia),\nyou can do:\n\n```C#\nvar pages = (from cm in wiki.Query.categorymembers()\n             where cm.title == \"Category:Mammals of Indonesia\"\n             select cm.title)\n            .ToEnumerable();\n```\n\n```\nList of mammals of Indonesia\nMammals of Borneo\nAgile gibbon\nAndrew's Hill Rat\nAnoa\n…\n```\n\nThe call to `ToEnumerable()` (or, alternatively, `ToList()`) is necessary,\nso that LINQ to Wiki methods don't get mixed up with LINQ to Objects methods, but the result is now an ordinary `IEnumerable\u003cstring\u003e`.\n\nWell, actually, you want the list sorted backwards (maybe you want to know whether there are any Indonesiam mammals whose name starts with *Z*):\n\n```C#\nvar pages = (from cm in wiki.Query.categorymembers()\n              where cm.title == \"Category:Mammals of Indonesia\"\n              orderby cm descending \n              select cm.title)\n    .ToEnumerable();\n```\n\n```\nWild water buffalo\nWild boar\nWhitish Dwarf Squirrel\nWhitehead's Woolly Bat\nWhite-thighed surili\n…\n```\n\nHmm, no luck with the *Z*. Okay, can I get the first section of those articles?\nThis is where things start to get more comlicated. If you were using the API directly,\nyou would have to use [generators](http://www.mediawiki.org/wiki/API:Query#Generators).\nLINQ to Wiki can handle that for you, but since generators are quite powerful,\nyou have to do something like this:\n\n```C#\nvar pages = (from cm in wiki.Query.categorymembers()\n             where cm.title == \"Category:Mammals of Indonesia\"\n             orderby cm descending\n             select cm)\n    .Pages\n    .Select(\n        page =\u003e\n        new\n        {\n            title = page.info.title,\n            text = page.revisions()\n                .Where(r =\u003e r.section == \"0\")\n                .Select(r =\u003e r.value)\n                .FirstOrDefault()\n        })\n    .ToEnumerable();\n```\n\n```\nWild water buffalo\n{{About|the wild species|the domestic livestock varieties descended from it|water buffalo}}\n\n{{Taxobox|…}}\n\nThe '''wild water buffalo''' (''Bubalus arnee''), also called '''Asian buffalo''' and '''Asiatic buffalo''',\nis a large [[bovinae|bovine]] native to [[Southeast Asia]].  …\n```\n\nThis deserves some explanation. When you use `Pages` to access more information about the pages in some list,\nyou then call `Select()` to choose what exactly do you want to know.\nIn that `Select()`, you can use `info` for basic information about the page, like its name, ID or whether you are watching it.\nThen there are several lists, including `revisions()`.\nYou can again use LINQ methods to alter this part of the query.\nFor example,\nI want only the first section (`Where(r =\u003e r.section == \"0\")`),\nI want to select the text of the revision (here called “value”, `Select(r =\u003e r.value)`)\nand only for the first (latest) revision (`FirstOrDefault()`).\n\nFor examples of almost all methods in LINQ to Wiki,\nhave a look at [the LinqToWiki.Samples project](https://github.com/svick/LINQ-to-Wiki/blob/master/LinqToWiki.Samples/Program.cs).\n\nGenerating configuration for a wiki\n-----------------------------------\n\nTo generate a configuration assembly for a certain wiki, you can use the `linqtowiki-codegen` command-line application\n(see [the LinqToWiki.Codegen.App project](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Codegen.App)).\nIf you run it without parameters, it will show you basic usage, along with some examples:\n\n```\nUsage:    linqtowiki-codegen url-to-api [namespace [output-name]] [-d output-directory] [-p props-file-path]\nExamples: linqtowiki-codegen en.wikipedia.org LinqToWiki.Enwiki linqtowiki-enwiki -d C:\\Temp -p props-defaults-sample.xml\n          linqtowiki-codegen https://en.wikipedia.org/w/api.php\n```\n\nThe application retrieves information about the API from the API itself,\nusing the URL you gave as a first parameter.\nThis requires information about properties of results of the API,\nthat was not previously available from the API, and was added there because of this library.\nThis was done quite recently (on 12 June 2012),\nso it's not available in the most recent public version of MediaWiki (1.19.1)\nbut it is available in the version currently in use on Wikipedia (1.20wmf7).\n\nIf you don't have recent enough version of MediaWiki,\nyou can use a workaround: get the necessary information from a file.\nThe file looks almost the same as an API response in XML format that would contain the information.\nThere is [a sample of the file](https://github.com/svick/LINQ-to-Wiki/blob/master/LinqToWiki.Codegen.App/props-defaults-sample.xml)\navailable, which will most likely work for you out of the box.\n\nYou don't have to generate a separate assembly for each wiki,\nif the methods you want to use look the same on all of them.\nIn that case, don't forget to specify which wiki do you want to use\nin the constructor of the `Wiki` class.\n\nIf you want to access multiple wikis with different configuration assemblies\nfrom one program, you can, if you generate each of them into a different namespace\n(the default namespace is `LinqToWiki.Generated`).\n\nIf you want to do something more complicated regarding generating the configuration assemblies\n(for example, create a bunch of C# files that you can modify by hand and then compile into a configuration assembly),\nyou can use [the LinqToWiki.Codegen library](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Codegen) directly from your own application.\n\nDeveloper documentation\n-----------------------\n\nIf you want to modify this code (patches are welcome) or just have a look at the implementation,\nhere is a short overview of the projects (more details are in the project directories):\n\n* [LinqToWiki.Core](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Core)\n – The core of the library. This project is referenced by all other projects and contains types necessary for acessing the API, processing LINQ expressions, etc.\n* [LinqToWiki.Codegen](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Codegen)\n – Handles generating code using Roslyn.\n* [LinqToWiki.Codegen.App](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Codegen.App)\n – The `linqtowiki-codegen` command-line application, see [above](#generating-configuration-for-a-wiki). \n* [LinqToWiki.Samples](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.Samples)\n – Samples of code that uses this library.\n* [LinqToWiki.ManuallyGenerated](https://github.com/svick/LINQ-to-Wiki/tree/master/LinqToWiki.ManuallyGenerated)\n – A manually written configuration assembly. You could use this as a template for your own configuration assembly, but otherwise it's mostly useless.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvick%2Flinq-to-wiki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvick%2Flinq-to-wiki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvick%2Flinq-to-wiki/lists"}